entry_vector3.vala 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 EntryVector3 : 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 Gtk.Label _x_label;
  17. public Gtk.Label _y_label;
  18. public Gtk.Label _z_label;
  19. public Gtk.Box _x_box;
  20. public Gtk.Box _y_box;
  21. public Gtk.Box _z_box;
  22. public Vector3 value
  23. {
  24. get
  25. {
  26. return Vector3(_x.value, _y.value, _z.value);
  27. }
  28. set
  29. {
  30. _stop_emit = true;
  31. Vector3 val = (Vector3)value;
  32. _x.value = val.x;
  33. _y.value = val.y;
  34. _z.value = val.z;
  35. _stop_emit = false;
  36. }
  37. }
  38. // Signals
  39. public signal void value_changed();
  40. public EntryVector3(Vector3 xyz, Vector3 min, Vector3 max, string preview_fmt = "%.4g")
  41. {
  42. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 4);
  43. // Data
  44. _stop_emit = false;
  45. // Widgets
  46. _x = new EntryDouble(xyz.x, min.x, max.x, preview_fmt);
  47. _y = new EntryDouble(xyz.y, min.y, max.y, preview_fmt);
  48. _z = new EntryDouble(xyz.z, min.z, max.z, preview_fmt);
  49. _x.value_changed.connect(on_value_changed);
  50. _y.value_changed.connect(on_value_changed);
  51. _z.value_changed.connect(on_value_changed);
  52. _x_label = new Gtk.Label("X");
  53. _x_label.get_style_context().add_class("axis");
  54. _x_label.get_style_context().add_class("x");
  55. _y_label = new Gtk.Label("Y");
  56. _y_label.get_style_context().add_class("axis");
  57. _y_label.get_style_context().add_class("y");
  58. _z_label = new Gtk.Label("Z");
  59. _z_label.get_style_context().add_class("axis");
  60. _z_label.get_style_context().add_class("z");
  61. _x_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  62. _x_box.pack_start(_x_label, false);
  63. _x_box.pack_start(_x, true);
  64. _y_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  65. _y_box.pack_start(_y_label, false);
  66. _y_box.pack_start(_y, true);
  67. _z_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  68. _z_box.pack_start(_z_label, false);
  69. _z_box.pack_start(_z, true);
  70. this.pack_start(_x_box, true);
  71. this.pack_start(_y_box, true);
  72. this.pack_start(_z_box, true);
  73. }
  74. private void on_value_changed()
  75. {
  76. if (!_stop_emit)
  77. value_changed();
  78. }
  79. }
  80. } /* namespace Crown */