| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /*
- * Copyright (c) 2012-2025 Daniele Bartolini et al.
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
- namespace Crown
- {
- public class InputQuaternion : InputField, Gtk.Box
- {
- public Quaternion _rotation;
- public InputDouble _x;
- public InputDouble _y;
- public InputDouble _z;
- public void set_inconsistent(bool inconsistent)
- {
- }
- public bool is_inconsistent()
- {
- return false;
- }
- public GLib.Value union_value()
- {
- return this.value;
- }
- public void set_union_value(GLib.Value v)
- {
- this.value = (Quaternion)v;
- }
- public Quaternion value
- {
- get
- {
- return _rotation;
- }
- set
- {
- _rotation = value;
- // Convert to Euler for displaying.
- Vector3 euler = value.to_euler();
- _x.value_changed.disconnect(on_value_changed);
- _y.value_changed.disconnect(on_value_changed);
- _z.value_changed.disconnect(on_value_changed);
- _x.value = MathUtils.deg(euler.x);
- _y.value = MathUtils.deg(euler.y);
- _z.value = MathUtils.deg(euler.z);
- _x.value_changed.connect(on_value_changed);
- _y.value_changed.connect(on_value_changed);
- _z.value_changed.connect(on_value_changed);
- value_changed(this);
- }
- }
- public InputQuaternion(int preview_decimals = 2, int edit_decimals = 3)
- {
- Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 4);
- _rotation = QUATERNION_IDENTITY;
- _x = new InputDouble(0.0, -180.0, 180.0, preview_decimals, edit_decimals);
- _x.get_style_context().add_class("axis");
- _x.get_style_context().add_class("x");
- _y = new InputDouble(0.0, -180.0, 180.0, preview_decimals, edit_decimals);
- _y.get_style_context().add_class("axis");
- _y.get_style_context().add_class("y");
- _z = new InputDouble(0.0, -180.0, 180.0, preview_decimals, edit_decimals);
- _z.get_style_context().add_class("axis");
- _z.get_style_context().add_class("z");
- _x.value_changed.connect(on_value_changed);
- _y.value_changed.connect(on_value_changed);
- _z.value_changed.connect(on_value_changed);
- this.pack_start(_x, true);
- this.pack_start(_y, true);
- this.pack_start(_z, true);
- }
- private void on_value_changed(InputField p)
- {
- double x = MathUtils.rad((double)_x.value);
- double y = MathUtils.rad((double)_y.value);
- double z = MathUtils.rad((double)_z.value);
- Quaternion new_rotation = Quaternion.from_euler(x, y, z);
- if (_rotation != new_rotation) {
- _rotation = new_rotation;
- value_changed(this);
- }
- }
- }
- } /* namespace Crown */
|