input_vector4.vala 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2012-2025 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. namespace Crown
  6. {
  7. public class InputVector4 : InputField, Gtk.Box
  8. {
  9. public bool _stop_emit;
  10. public InputDouble _x;
  11. public InputDouble _y;
  12. public InputDouble _z;
  13. public InputDouble _w;
  14. public void set_inconsistent(bool inconsistent)
  15. {
  16. }
  17. public bool is_inconsistent()
  18. {
  19. return false;
  20. }
  21. public GLib.Value union_value()
  22. {
  23. return this.value;
  24. }
  25. public void set_union_value(GLib.Value v)
  26. {
  27. this.value = (Vector4)v;
  28. }
  29. public Vector4 value
  30. {
  31. get
  32. {
  33. return Vector4(_x.value, _y.value, _z.value, _w.value);
  34. }
  35. set
  36. {
  37. _stop_emit = true;
  38. Vector4 val = (Vector4)value;
  39. _x.value = val.x;
  40. _y.value = val.y;
  41. _z.value = val.z;
  42. _w.value = val.w;
  43. _stop_emit = false;
  44. }
  45. }
  46. public InputVector4(Vector4 xyz, Vector4 min, Vector4 max, int preview_decimals = 4)
  47. {
  48. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 4);
  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. this.pack_start(_x, true);
  69. this.pack_start(_y, true);
  70. this.pack_start(_z, true);
  71. this.pack_start(_w, true);
  72. }
  73. private void on_value_changed()
  74. {
  75. if (!_stop_emit)
  76. value_changed(this);
  77. }
  78. }
  79. } /* namespace Crown */