MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / gui_input

Method gui_input

scene/gui/spin_box.cpp:239–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237}
238
239void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
240 ERR_FAIL_COND(p_event.is_null());
241
242 if (!is_editable()) {
243 return;
244 }
245
246 Ref<InputEventMouse> me = p_event;
247 Ref<InputEventMouseButton> mb = p_event;
248 Ref<InputEventMouseMotion> mm = p_event;
249
250 double step = get_step();
251 Vector2 mpos;
252 bool mouse_on_up_button = false;
253 bool mouse_on_down_button = false;
254 if (mb.is_valid() || mm.is_valid()) {
255 Rect2 up_button_rc = Rect2(sizing_cache.buttons_left, 0, sizing_cache.buttons_width, sizing_cache.button_up_height);
256 Rect2 down_button_rc = Rect2(sizing_cache.buttons_left, sizing_cache.second_button_top, sizing_cache.buttons_width, sizing_cache.button_down_height);
257
258 mpos = me->get_position();
259
260 mouse_on_up_button = up_button_rc.has_point(mpos);
261 mouse_on_down_button = down_button_rc.has_point(mpos);
262 }
263
264 if (mb.is_valid() && mb->is_pressed()) {
265 switch (mb->get_button_index()) {
266 case MouseButton::LEFT: {
267 accepted = true;
268 line_edit->grab_focus();
269
270 if (mouse_on_up_button || mouse_on_down_button) {
271 // Arrow button is being pressed. Snap the value to next step.
272 double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
273 temp_step = Math::snapped(temp_step, get_step());
274 double new_value = _calc_value(get_value(), temp_step);
275 if ((mouse_on_up_button && new_value <= get_value() + CMP_EPSILON) || (!mouse_on_up_button && new_value >= get_value() - CMP_EPSILON)) {
276 new_value = _calc_value(get_value() + (mouse_on_up_button ? temp_step : -temp_step), temp_step);
277 }
278 set_value(new_value);
279 }
280 state_cache.up_button_pressed = mouse_on_up_button;
281 state_cache.down_button_pressed = mouse_on_down_button;
282 queue_redraw();
283
284 range_click_timer->set_wait_time(0.6);
285 range_click_timer->set_one_shot(true);
286 range_click_timer->start();
287
288 drag.allowed = true;
289 drag.capture_pos = mb->get_position();
290 } break;
291 case MouseButton::RIGHT: {
292 line_edit->grab_focus();
293 if (mouse_on_up_button || mouse_on_down_button) {
294 set_value(mouse_on_up_button ? get_max() : get_min());
295 }
296 } break;

Callers

nothing calls this directly

Calls 15

powFunction · 0.85
SIGNFunction · 0.85
CLAMPFunction · 0.85
get_button_indexMethod · 0.80
set_wait_timeMethod · 0.80
get_factorMethod · 0.80
get_relativeMethod · 0.80
set_mouse_modeMethod · 0.80
Rect2Class · 0.50
absFunction · 0.50
is_nullMethod · 0.45

Tested by

no test coverage detected