input_vector2.vala 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2012-2026 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. namespace Crown
  6. {
  7. public class InputVector2 : Gtk.Box
  8. {
  9. public bool _stop_emit;
  10. public InputDouble _x;
  11. public InputDouble _y;
  12. public Vector2 value
  13. {
  14. get
  15. {
  16. return Vector2(_x.value, _y.value);
  17. }
  18. set
  19. {
  20. _stop_emit = true;
  21. Vector2 val = (Vector2)value;
  22. _x.value = val.x;
  23. _y.value = val.y;
  24. _stop_emit = false;
  25. }
  26. }
  27. // Signals
  28. public signal void value_changed();
  29. public InputVector2(Vector2 xyz, Vector2 min, Vector2 max, int preview_decimals = 4)
  30. {
  31. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 4);
  32. // Data
  33. _stop_emit = false;
  34. // Widgets
  35. _x = new InputDouble(xyz.x, min.x, max.x, preview_decimals);
  36. _x.get_style_context().add_class("axis");
  37. _x.get_style_context().add_class("x");
  38. _y = new InputDouble(xyz.y, min.y, max.y, preview_decimals);
  39. _y.get_style_context().add_class("axis");
  40. _y.get_style_context().add_class("y");
  41. _x.value_changed.connect(on_value_changed);
  42. _y.value_changed.connect(on_value_changed);
  43. this.pack_start(_x, true);
  44. this.pack_start(_y, true);
  45. }
  46. public void on_value_changed()
  47. {
  48. if (!_stop_emit)
  49. value_changed();
  50. }
  51. }
  52. } /* namespace Crown */