spin_button_vector3.vala 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2012-2017 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. */
  5. using Gtk;
  6. namespace Crown
  7. {
  8. /// <summary>
  9. /// Vector3 spin button.
  10. /// </summary>
  11. public class SpinButtonVector3 : Gtk.Box
  12. {
  13. // Data
  14. private bool _stop_emit;
  15. // Widgets
  16. private SpinButtonDouble _x;
  17. private SpinButtonDouble _y;
  18. private SpinButtonDouble _z;
  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 SpinButtonVector3(Vector3 xyz, Vector3 min, Vector3 max)
  38. {
  39. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 0);
  40. // Data
  41. _stop_emit = false;
  42. // Widgets
  43. _x = new SpinButtonDouble(xyz.x, min.x, max.x);
  44. _y = new SpinButtonDouble(xyz.y, min.y, max.y);
  45. _z = new SpinButtonDouble(xyz.z, min.z, max.z);
  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. add(_x);
  50. add(_y);
  51. add(_z);
  52. }
  53. private void on_value_changed()
  54. {
  55. if (!_stop_emit)
  56. value_changed();
  57. }
  58. }
  59. }