2
0

input_vector4.vala 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 InputVector4 : InputField
  8. {
  9. public bool _stop_emit;
  10. public InputDouble _x;
  11. public InputDouble _y;
  12. public InputDouble _z;
  13. public InputDouble _w;
  14. public Gtk.Box _box;
  15. public override void set_inconsistent(bool inconsistent)
  16. {
  17. }
  18. public override bool is_inconsistent()
  19. {
  20. return false;
  21. }
  22. public override GLib.Value union_value()
  23. {
  24. return this.value;
  25. }
  26. public override void set_union_value(GLib.Value v)
  27. {
  28. this.value = (Vector4)v;
  29. }
  30. public Vector4 value
  31. {
  32. get
  33. {
  34. return Vector4(_x.value, _y.value, _z.value, _w.value);
  35. }
  36. set
  37. {
  38. _stop_emit = true;
  39. Vector4 val = (Vector4)value;
  40. _x.value = val.x;
  41. _y.value = val.y;
  42. _z.value = val.z;
  43. _w.value = val.w;
  44. _stop_emit = false;
  45. }
  46. }
  47. public InputVector4(Vector4 xyz, Vector4 min, Vector4 max, int preview_decimals = 4)
  48. {
  49. // Data
  50. _stop_emit = false;
  51. // Widgets
  52. _x = new InputDouble(xyz.x, min.x, max.x, preview_decimals);
  53. _x.get_style_context().add_class("axis");
  54. _x.get_style_context().add_class("x");
  55. _y = new InputDouble(xyz.y, min.y, max.y, preview_decimals);
  56. _y.get_style_context().add_class("axis");
  57. _y.get_style_context().add_class("y");
  58. _z = new InputDouble(xyz.z, min.z, max.z, preview_decimals);
  59. _z.get_style_context().add_class("axis");
  60. _z.get_style_context().add_class("z");
  61. _w = new InputDouble(xyz.w, min.w, max.w, preview_decimals);
  62. _w.get_style_context().add_class("axis");
  63. _w.get_style_context().add_class("w");
  64. _x.value_changed.connect(on_value_changed);
  65. _y.value_changed.connect(on_value_changed);
  66. _z.value_changed.connect(on_value_changed);
  67. _w.value_changed.connect(on_value_changed);
  68. _box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 4);
  69. _box.pack_start(_x, true);
  70. _box.pack_start(_y, true);
  71. _box.pack_start(_z, true);
  72. _box.pack_start(_w, true);
  73. this.add(_box);
  74. }
  75. public void on_value_changed()
  76. {
  77. if (!_stop_emit)
  78. value_changed(this);
  79. }
  80. }
  81. } /* namespace Crown */