Skip to content

Commit

Permalink
[Editor] Remove redundant code from EditorSpinSlider
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed Mar 15, 2024
1 parent 89f70e9 commit 56b05a5
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions editor/gui/editor_spin_slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,41 +238,35 @@ void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) {
void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid() && k->is_pressed() && !is_read_only()) {
double step = get_step();
if (step < 1) {
double divisor = 1.0 / get_step();

if (trunc(divisor) == divisor) {
step = 1.0;
}
}

if (k->is_command_or_control_pressed()) {
step *= 100.0;
} else if (k->is_shift_pressed()) {
step *= 10.0;
} else if (k->is_alt_pressed()) {
step *= 0.1;
}

Key code = k->get_keycode();

switch (code) {
case Key::UP:
case Key::DOWN: {
double step = get_step();
if (step < 1) {
double divisor = 1.0 / step;

if (trunc(divisor) == divisor) {
step = 1.0;
}
}

if (k->is_command_or_control_pressed()) {
step *= 100.0;
} else if (k->is_shift_pressed()) {
step *= 10.0;
} else if (k->is_alt_pressed()) {
step *= 0.1;
}

_evaluate_input_text();

double last_value = get_value();
if (code == Key::DOWN) {
step *= -1;
}
set_value(last_value + step);
double new_value = get_value();

double clamp_value = CLAMP(new_value, get_min(), get_max());
if (new_value != clamp_value) {
set_value(clamp_value);
}

value_input_dirty = true;
set_process_internal(true);
Expand Down

0 comments on commit 56b05a5

Please sign in to comment.