entry_vector3.vala 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2012-2020 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. */
  5. using Gtk;
  6. namespace Crown
  7. {
  8. public class EntryVector3 : Gtk.Box
  9. {
  10. // Data
  11. public bool _stop_emit;
  12. // Widgets
  13. public EntryDouble _x;
  14. public EntryDouble _y;
  15. public EntryDouble _z;
  16. public Gtk.Label _x_label;
  17. public Gtk.Label _y_label;
  18. public Gtk.Label _z_label;
  19. public Vector3 value
  20. {
  21. get
  22. {
  23. return Vector3(_x.value, _y.value, _z.value);
  24. }
  25. set
  26. {
  27. _stop_emit = true;
  28. Vector3 val = (Vector3)value;
  29. _x.value = val.x;
  30. _y.value = val.y;
  31. _z.value = val.z;
  32. _stop_emit = false;
  33. }
  34. }
  35. // Signals
  36. public signal void value_changed();
  37. public EntryVector3(Vector3 xyz, Vector3 min, Vector3 max, string fmt)
  38. {
  39. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 0);
  40. // Data
  41. _stop_emit = false;
  42. // Widgets
  43. _x = new EntryDouble(xyz.x, min.x, max.x, fmt);
  44. _y = new EntryDouble(xyz.y, min.y, max.y, fmt);
  45. _z = new EntryDouble(xyz.z, min.z, max.z, fmt);
  46. _x.value_changed.connect(on_value_changed);
  47. _y.value_changed.connect(on_value_changed);
  48. _z.value_changed.connect(on_value_changed);
  49. _x_label = new Gtk.Label("X");
  50. _x_label.get_style_context().add_class("axis");
  51. _x_label.get_style_context().add_class("x");
  52. _y_label = new Gtk.Label("Y");
  53. _y_label.get_style_context().add_class("axis");
  54. _y_label.get_style_context().add_class("y");
  55. _z_label = new Gtk.Label("Z");
  56. _z_label.get_style_context().add_class("axis");
  57. _z_label.get_style_context().add_class("z");
  58. this.pack_start(_x_label, false);
  59. this.pack_start(_x, true, true);
  60. this.pack_start(_y_label, false);
  61. this.pack_start(_y, true, true);
  62. this.pack_start(_z_label, false);
  63. this.pack_start(_z, true, true);
  64. }
  65. private void on_value_changed()
  66. {
  67. if (!_stop_emit)
  68. value_changed();
  69. }
  70. }
  71. }