input_vector4.vala 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. // Data
  10. public bool _stop_emit;
  11. // Widgets
  12. public InputDouble _x;
  13. public InputDouble _y;
  14. public InputDouble _z;
  15. public InputDouble _w;
  16. public Gtk.Label _x_label;
  17. public Gtk.Label _y_label;
  18. public Gtk.Label _z_label;
  19. public Gtk.Label _w_label;
  20. public Gtk.Box _x_box;
  21. public Gtk.Box _y_box;
  22. public Gtk.Box _z_box;
  23. public Gtk.Box _w_box;
  24. public void set_inconsistent(bool inconsistent)
  25. {
  26. }
  27. public bool is_inconsistent()
  28. {
  29. return false;
  30. }
  31. public GLib.Value union_value()
  32. {
  33. return this.value;
  34. }
  35. public void set_union_value(GLib.Value v)
  36. {
  37. this.value = (Vector4)v;
  38. }
  39. public Vector4 value
  40. {
  41. get
  42. {
  43. return Vector4(_x.value, _y.value, _z.value, _w.value);
  44. }
  45. set
  46. {
  47. _stop_emit = true;
  48. Vector4 val = (Vector4)value;
  49. _x.value = val.x;
  50. _y.value = val.y;
  51. _z.value = val.z;
  52. _w.value = val.w;
  53. _stop_emit = false;
  54. }
  55. }
  56. public InputVector4(Vector4 xyz, Vector4 min, Vector4 max, string preview_fmt = "%.4g")
  57. {
  58. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 4);
  59. // Data
  60. _stop_emit = false;
  61. // Widgets
  62. _x = new InputDouble(xyz.x, min.x, max.x, preview_fmt);
  63. _y = new InputDouble(xyz.y, min.y, max.y, preview_fmt);
  64. _z = new InputDouble(xyz.z, min.z, max.z, preview_fmt);
  65. _w = new InputDouble(xyz.w, min.w, max.w, preview_fmt);
  66. _x.value_changed.connect(on_value_changed);
  67. _y.value_changed.connect(on_value_changed);
  68. _z.value_changed.connect(on_value_changed);
  69. _w.value_changed.connect(on_value_changed);
  70. _x_label = new Gtk.Label("X");
  71. _x_label.get_style_context().add_class("axis");
  72. _x_label.get_style_context().add_class("x");
  73. _y_label = new Gtk.Label("Y");
  74. _y_label.get_style_context().add_class("axis");
  75. _y_label.get_style_context().add_class("y");
  76. _z_label = new Gtk.Label("Z");
  77. _z_label.get_style_context().add_class("axis");
  78. _z_label.get_style_context().add_class("z");
  79. _w_label = new Gtk.Label("Z");
  80. _w_label.get_style_context().add_class("axis");
  81. _w_label.get_style_context().add_class("w");
  82. _x_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  83. _x_box.pack_start(_x_label, false);
  84. _x_box.pack_start(_x, true);
  85. _y_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  86. _y_box.pack_start(_y_label, false);
  87. _y_box.pack_start(_y, true);
  88. _z_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  89. _z_box.pack_start(_z_label, false);
  90. _z_box.pack_start(_z, true);
  91. _w_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  92. _w_box.pack_start(_w_label, false);
  93. _w_box.pack_start(_w, true);
  94. this.pack_start(_x_box, true);
  95. this.pack_start(_y_box, true);
  96. this.pack_start(_z_box, true);
  97. this.pack_start(_w_box, true);
  98. }
  99. private void on_value_changed()
  100. {
  101. if (!_stop_emit)
  102. value_changed(this);
  103. }
  104. }
  105. } /* namespace Crown */