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

Method gui_input

editor/scene/gradient_editor_plugin.cpp:245–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243}
244
245void GradientEdit::gui_input(const Ref<InputEvent> &p_event) {
246 ERR_FAIL_COND(p_event.is_null());
247
248 Ref<InputEventKey> k = p_event;
249
250 if (k.is_valid() && k->is_pressed() && k->get_keycode() == Key::KEY_DELETE && selected_index != -1) {
251 if (grabbing == GRAB_ADD) {
252 gradient->remove_point(selected_index); // Point is temporary, so remove directly from gradient.
253 set_selected_index(-1);
254 } else {
255 remove_point(selected_index);
256 }
257 grabbing = GRAB_NONE;
258 hovered_index = -1;
259 accept_event();
260 }
261
262 Ref<InputEventMouseButton> mb = p_event;
263
264 if (mb.is_valid() && mb->is_pressed()) {
265 float adjusted_mb_x = mb->get_position().x - handle_width / 2;
266 bool should_snap = snap_enabled || mb->is_ctrl_pressed();
267
268 // Delete point or move it to old position on middle or right click.
269 if (mb->get_button_index() == MouseButton::RIGHT || mb->get_button_index() == MouseButton::MIDDLE) {
270 if (grabbing == GRAB_MOVE && mb->get_button_index() == MouseButton::RIGHT) {
271 gradient->set_offset(selected_index, pre_grab_offset);
272 set_selected_index(pre_grab_index);
273 } else {
274 int point_to_remove = _get_point_at(adjusted_mb_x);
275 if (point_to_remove == -1) {
276 set_selected_index(-1); // Nothing on the place of the click, just deselect any handle.
277 } else {
278 if (grabbing == GRAB_ADD) {
279 gradient->remove_point(point_to_remove); // Point is temporary, so remove directly from gradient.
280 set_selected_index(-1);
281 } else {
282 remove_point(point_to_remove);
283 }
284 hovered_index = -1;
285 }
286 }
287 grabbing = GRAB_NONE;
288 accept_event();
289 }
290
291 // Select point.
292 if (mb->get_button_index() == MouseButton::LEFT) {
293 int total_w = _get_gradient_rect_width();
294
295 // Check if color picker was clicked or gradient was double-clicked.
296 if (adjusted_mb_x > total_w + draw_spacing) {
297 if (!mb->is_double_click()) {
298 _show_color_picker();
299 }
300 accept_event();
301 return;
302 } else if (mb->is_double_click()) {

Callers

nothing calls this directly

Calls 15

CLAMPFunction · 0.85
MINFunction · 0.85
get_button_indexMethod · 0.80
is_double_clickMethod · 0.80
is_alt_pressedMethod · 0.80
get_color_at_offsetMethod · 0.80
is_shift_pressedMethod · 0.80
absFunction · 0.50
is_nullMethod · 0.45
is_validMethod · 0.45
is_pressedMethod · 0.45
get_keycodeMethod · 0.45

Tested by

no test coverage detected