entry_vector4.vala 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2012-2025 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. using Gtk;
  6. namespace Crown
  7. {
  8. public class EntryVector4 : Gtk.Box
  9. {
  10. // Data
  11. public bool _stop_emit;
  12. // Widgets
  13. public EntryDouble _x;
  14. public EntryDouble _y;
  15. public EntryDouble _z;
  16. public EntryDouble _w;
  17. public Gtk.Label _x_label;
  18. public Gtk.Label _y_label;
  19. public Gtk.Label _z_label;
  20. public Gtk.Label _w_label;
  21. public Gtk.Box _x_box;
  22. public Gtk.Box _y_box;
  23. public Gtk.Box _z_box;
  24. public Gtk.Box _w_box;
  25. public Vector4 value
  26. {
  27. get
  28. {
  29. return Vector4(_x.value, _y.value, _z.value, _w.value);
  30. }
  31. set
  32. {
  33. _stop_emit = true;
  34. Vector4 val = (Vector4)value;
  35. _x.value = val.x;
  36. _y.value = val.y;
  37. _z.value = val.z;
  38. _w.value = val.w;
  39. _stop_emit = false;
  40. }
  41. }
  42. // Signals
  43. public signal void value_changed();
  44. public EntryVector4(Vector4 xyz, Vector4 min, Vector4 max, string preview_fmt = "%.4g")
  45. {
  46. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 4);
  47. // Data
  48. _stop_emit = false;
  49. // Widgets
  50. _x = new EntryDouble(xyz.x, min.x, max.x, preview_fmt);
  51. _y = new EntryDouble(xyz.y, min.y, max.y, preview_fmt);
  52. _z = new EntryDouble(xyz.z, min.z, max.z, preview_fmt);
  53. _w = new EntryDouble(xyz.w, min.w, max.w, preview_fmt);
  54. _x.value_changed.connect(on_value_changed);
  55. _y.value_changed.connect(on_value_changed);
  56. _z.value_changed.connect(on_value_changed);
  57. _w.value_changed.connect(on_value_changed);
  58. _x_label = new Gtk.Label("X");
  59. _x_label.get_style_context().add_class("axis");
  60. _x_label.get_style_context().add_class("x");
  61. _y_label = new Gtk.Label("Y");
  62. _y_label.get_style_context().add_class("axis");
  63. _y_label.get_style_context().add_class("y");
  64. _z_label = new Gtk.Label("Z");
  65. _z_label.get_style_context().add_class("axis");
  66. _z_label.get_style_context().add_class("z");
  67. _w_label = new Gtk.Label("Z");
  68. _w_label.get_style_context().add_class("axis");
  69. _w_label.get_style_context().add_class("w");
  70. _x_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  71. _x_box.pack_start(_x_label, false);
  72. _x_box.pack_start(_x, true);
  73. _y_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  74. _y_box.pack_start(_y_label, false);
  75. _y_box.pack_start(_y, true);
  76. _z_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  77. _z_box.pack_start(_z_label, false);
  78. _z_box.pack_start(_z, true);
  79. _w_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  80. _w_box.pack_start(_w_label, false);
  81. _w_box.pack_start(_w, true);
  82. this.pack_start(_x_box, true);
  83. this.pack_start(_y_box, true);
  84. this.pack_start(_z_box, true);
  85. this.pack_start(_w_box, true);
  86. }
  87. private void on_value_changed()
  88. {
  89. if (!_stop_emit)
  90. value_changed();
  91. }
  92. }
  93. } /* namespace Crown */