spin_button_vector2.vala 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /// Vector2 spin button.
  10. /// </summary>
  11. public class SpinButtonVector2 : Gtk.Box
  12. {
  13. // Data
  14. private bool _stop_emit;
  15. // Widgets
  16. private SpinButtonDouble _x;
  17. private SpinButtonDouble _y;
  18. public Vector2 value
  19. {
  20. get
  21. {
  22. return Vector2(_x.value, _y.value);
  23. }
  24. set
  25. {
  26. _stop_emit = true;
  27. Vector2 val = (Vector2)value;
  28. _x.value = val.x;
  29. _y.value = val.y;
  30. _stop_emit = false;
  31. }
  32. }
  33. // Signals
  34. public signal void value_changed();
  35. public SpinButtonVector2(Vector2 xyz, Vector2 min, Vector2 max)
  36. {
  37. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 0);
  38. // Data
  39. _stop_emit = false;
  40. // Widgets
  41. _x = new SpinButtonDouble(xyz.x, min.x, max.x);
  42. _y = new SpinButtonDouble(xyz.y, min.y, max.y);
  43. _x.value_changed.connect(on_value_changed);
  44. _y.value_changed.connect(on_value_changed);
  45. add(_x);
  46. add(_y);
  47. }
  48. private void on_value_changed()
  49. {
  50. if (!_stop_emit)
  51. value_changed();
  52. }
  53. }
  54. }