Cleanup: Use array utility for cursor events

This commit is contained in:
Aaron Carlisle 2021-10-21 15:29:56 -04:00
parent be558d2d97
commit be171b295f
Notes: blender-bot 2023-02-14 08:08:56 +01:00
Referenced by commit d9ebe25a0c, Fix errors in be171b295f
10 changed files with 39 additions and 65 deletions

View File

@ -208,7 +208,7 @@ bool ED_time_scrub_event_in_region(const ARegion *region, const wmEvent *event)
{
rcti rect = region->winrct;
rect.ymin = rect.ymax - UI_TIME_SCRUB_MARGIN_Y;
return BLI_rcti_isect_pt(&rect, event->xy[0], event->xy[1]);
return BLI_rcti_isect_pt_v(&rect, event->xy);
}
void ED_time_scrub_channel_search_draw(const bContext *C, ARegion *region, bDopeSheet *dopesheet)

View File

@ -25,6 +25,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLT_translation.h"
@ -379,8 +380,7 @@ static bool poselib_blend_init_data(bContext *C, wmOperator *op, const wmEvent *
if (pbd->release_confirm_info.use_release_confirm) {
BLI_assert(event != NULL);
pbd->release_confirm_info.drag_start_xy[0] = event->xy[0];
pbd->release_confirm_info.drag_start_xy[1] = event->xy[1];
copy_v2_v2_int(pbd->release_confirm_info.drag_start_xy, event->xy);
pbd->release_confirm_info.init_event_type = WM_userdef_event_type_from_keymap_type(
event->type);
}

View File

@ -2107,7 +2107,7 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (region) {
bool in_bounds = false;
/* Perform bounds check */
in_bounds = BLI_rcti_isect_pt(&region->winrct, event->xy[0], event->xy[1]);
in_bounds = BLI_rcti_isect_pt_v(&region->winrct, event->xy);
if ((in_bounds) && (region->regiontype == RGN_TYPE_WINDOW)) {
tgpf->mouse[0] = event->mval[0];

View File

@ -10648,7 +10648,7 @@ static int ui_handle_menu_event(bContext *C,
menu->menuretval = UI_RETURN_OUT;
}
}
else if (saferct && !BLI_rctf_isect_pt(&saferct->parent, event->xy[0], event->xy[1])) {
else if (saferct && !BLI_rctf_isect_pt_v(&saferct->parent, event->xy)) {
if (block->flag & UI_BLOCK_OUT_1) {
menu->menuretval = UI_RETURN_OK;
}
@ -10944,7 +10944,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle
const double duration = menu->scrolltimer->duration;
float event_xy[2] = {event->xy[0], event->xy[1]};
float event_xy[2] = {UNPACK2(event->xy)};
ui_window_to_block_fl(region, block, &event_xy[0], &event_xy[1]);

View File

@ -29,6 +29,7 @@
#include "DNA_text_types.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_math_base.h"
#include "BLT_translation.h"
@ -2598,14 +2599,12 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
/* compute mouse move distance */
if (tsc->is_first) {
tsc->mval_prev[0] = mval[0];
tsc->mval_prev[1] = mval[1];
copy_v2_v2_int(tsc->mval_prev, mval);
tsc->is_first = false;
}
if (event->type != MOUSEPAN) {
tsc->mval_delta[0] = mval[0] - tsc->mval_prev[0];
tsc->mval_delta[1] = mval[1] - tsc->mval_prev[1];
sub_v2_v2v2_int(tsc->mval_delta, mval, tsc->mval_prev);
}
/* accumulate scroll, in float values for events that give less than one
@ -2757,8 +2756,7 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (event->type == MOUSEPAN) {
text_update_character_width(st);
tsc->mval_prev[0] = event->xy[0];
tsc->mval_prev[1] = event->xy[1];
copy_v2_v2_int(tsc->mval_prev, event->xy);
/* Sensitivity of scroll set to 4pix per line/char */
tsc->mval_delta[0] = (event->xy[0] - event->prev_xy[0]) * st->runtime.cwidth_px / 4;
tsc->mval_delta[1] = (event->xy[1] - event->prev_xy[1]) * st->runtime.lheight_px / 4;

View File

@ -473,12 +473,11 @@ static void viewops_data_create(bContext *C,
vod->init.dist = rv3d->dist;
vod->init.camzoom = rv3d->camzoom;
copy_qt_qt(vod->init.quat, rv3d->viewquat);
vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0];
vod->init.event_xy[1] = vod->prev.event_xy[1] = event->xy[1];
copy_v2_v2_int(vod->init.event_xy, event->xy);
copy_v2_v2_int(vod->prev.event_xy, event->xy);
if (viewops_flag & VIEWOPS_FLAG_USE_MOUSE_INIT) {
vod->init.event_xy_offset[0] = 0;
vod->init.event_xy_offset[1] = 0;
zero_v2_int(vod->init.event_xy_offset);
}
else {
/* Simulate the event starting in the middle of the region. */
@ -548,10 +547,9 @@ static void viewops_data_create(bContext *C,
ED_view3d_win_to_vector(vod->region, (const float[2]){UNPACK2(event->mval)}, vod->init.mousevec);
{
const int event_xy_offset[2] = {
event->xy[0] + vod->init.event_xy_offset[0],
event->xy[1] + vod->init.event_xy_offset[1],
};
int event_xy_offset[2];
add_v2_v2v2_int(event_xy_offset, event->xy, vod->init.event_xy_offset);
/* For rotation with trackball rotation. */
calctrackballvec(&vod->region->winrct, event_xy_offset, vod->init.trackvec);
}
@ -1010,14 +1008,12 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
event_xy[1] = 2 * event->xy[1] - event->prev_xy[1];
}
else {
event_xy[0] = event->prev_xy[0];
event_xy[1] = event->prev_xy[1];
copy_v2_v2_int(event_xy, event->prev_xy);
}
}
else {
/* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */
event_xy[0] = event->prev_xy[0];
event_xy[1] = event->xy[1];
copy_v2_v2_int(event_xy, event->prev_xy);
}
viewrotate_apply(vod, event_xy);

View File

@ -360,8 +360,7 @@ static void slider_update_factor(tSlider *slider, const wmEvent *event)
/* Reduced factor delta in precision mode (shift held). */
slider->raw_factor += slider->precision ? (factor_delta / 8) : factor_delta;
slider->factor = slider->raw_factor;
slider->last_cursor[0] = event->xy[0];
slider->last_cursor[1] = event->xy[1];
copy_v2_v2_int(slider->last_cursor, event->xy);
if (!slider->overshoot) {
slider->factor = clamp_f(slider->factor, 0, 1);
@ -403,8 +402,7 @@ tSlider *ED_slider_create(struct bContext *C)
*/
void ED_slider_init(struct tSlider *slider, const wmEvent *event)
{
slider->last_cursor[0] = event->xy[0];
slider->last_cursor[1] = event->xy[1];
copy_v2_v2_int(slider->last_cursor, event->xy);
}
/**

View File

@ -315,10 +315,8 @@ bool WM_event_drag_test_with_delta(const wmEvent *event, const int drag_delta[2]
bool WM_event_drag_test(const wmEvent *event, const int prev_xy[2])
{
const int drag_delta[2] = {
prev_xy[0] - event->xy[0],
prev_xy[1] - event->xy[1],
};
int drag_delta[2];
sub_v2_v2v2_int(drag_delta, prev_xy, event->xy);
return WM_event_drag_test_with_delta(event, drag_delta);
}

View File

@ -152,13 +152,11 @@ wmEvent *WM_event_add_simulate(wmWindow *win, const wmEvent *event_to_add)
/* Logic for setting previous value is documented on the #wmEvent struct,
* see #wm_event_add_ghostevent for the implementation of logic this follows. */
win->eventstate->xy[0] = event->xy[0];
win->eventstate->xy[1] = event->xy[1];
copy_v2_v2_int(win->eventstate->xy, event->xy);
if (event->type == MOUSEMOVE) {
win->eventstate->prev_xy[0] = event->prev_xy[0] = win->eventstate->xy[0];
win->eventstate->prev_xy[1] = event->prev_xy[1] = win->eventstate->xy[1];
copy_v2_v2_int(win->eventstate->prev_xy, win->eventstate->xy);
copy_v2_v2_int(event->prev_xy, win->eventstate->xy);
}
else if (ISMOUSE_BUTTON(event->type) || ISKEYBOARD(event->type)) {
win->eventstate->prev_val = event->prev_val = win->eventstate->val;
@ -3176,13 +3174,11 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
if (WM_event_drag_test(event, event->prev_click_xy)) {
win->event_queue_check_drag_handled = true;
int x = event->xy[0];
int y = event->xy[1];
int xy[2] = {UNPACK2(event->xy)};
short val = event->val;
short type = event->type;
event->xy[0] = event->prev_click_xy[0];
event->xy[1] = event->prev_click_xy[1];
copy_v2_v2_int(event->xy, event->prev_click_xy);
event->val = KM_CLICK_DRAG;
event->type = event->prev_type;
@ -3192,8 +3188,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
event->val = val;
event->type = type;
event->xy[0] = x;
event->xy[1] = y;
copy_v2_v2_int(event->xy, xy);
win->event_queue_check_click = false;
if (!wm_action_not_handled(action)) {
@ -3238,11 +3233,9 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
else {
/* Position is where the actual click happens, for more
* accurate selecting in case the mouse drifts a little. */
int x = event->xy[0];
int y = event->xy[1];
int xy[2] = {UNPACK2(event->xy)};
event->xy[0] = event->prev_click_xy[0];
event->xy[1] = event->prev_click_xy[1];
copy_v2_v2_int(event->xy, event->prev_click_xy);
event->val = KM_CLICK;
CLOG_INFO(WM_LOG_HANDLERS, 1, "handling CLICK");
@ -3250,8 +3243,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
action |= wm_handlers_do_intern(C, win, event, handlers);
event->val = KM_RELEASE;
event->xy[0] = x;
event->xy[1] = y;
copy_v2_v2_int(event->xy, xy);
}
}
}
@ -3788,8 +3780,7 @@ void wm_event_do_handlers(bContext *C)
}
/* Update previous mouse position for following events to use. */
win->eventstate->prev_xy[0] = event->xy[0];
win->eventstate->prev_xy[1] = event->xy[1];
copy_v2_v2_int(win->eventstate->prev_xy, event->xy);
/* Unlink and free here, blender-quit then frees all. */
BLI_remlink(&win->event_queue, event);
@ -4181,10 +4172,10 @@ wmEventHandler_Keymap *WM_event_add_keymap_handler_priority(ListBase *handlers,
static bool event_or_prev_in_rect(const wmEvent *event, const rcti *rect)
{
if (BLI_rcti_isect_pt(rect, event->xy[0], event->xy[1])) {
if (BLI_rcti_isect_pt_v(rect, event->xy)) {
return true;
}
if (event->type == MOUSEMOVE && BLI_rcti_isect_pt(rect, event->prev_xy[0], event->prev_xy[1])) {
if (event->type == MOUSEMOVE && BLI_rcti_isect_pt_v(rect, event->prev_xy)) {
return true;
}
return false;
@ -4682,8 +4673,7 @@ static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *wi
wmWindow *win_other = WM_window_find_under_cursor(wm, win, win, mval, mval);
if (win_other) {
event->xy[0] = mval[0];
event->xy[1] = mval[1];
copy_v2_v2_int(event->xy, mval);
return win_other;
}
}

View File

@ -2274,11 +2274,8 @@ static void radial_control_set_initial_mouse(RadialControl *rc, const wmEvent *e
float d[2] = {0, 0};
float zoom[2] = {1, 1};
rc->initial_mouse[0] = event->xy[0];
rc->initial_mouse[1] = event->xy[1];
rc->initial_co[0] = event->xy[0];
rc->initial_co[1] = event->xy[1];
copy_v2_v2_int(rc->initial_mouse, event->xy);
copy_v2_v2_int(rc->initial_co, event->xy);
switch (rc->subtype) {
case PROP_NONE:
@ -2954,14 +2951,12 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even
if (!has_numInput) {
if (rc->slow_mode) {
if (rc->subtype == PROP_ANGLE) {
const float position[2] = {event->xy[0], event->xy[1]};
/* calculate the initial angle here first */
delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0];
delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1];
/* precision angle gets calculated from dial and gets added later */
angle_precision = -0.1f * BLI_dial_angle(rc->dial, position);
angle_precision = -0.1f * BLI_dial_angle(rc->dial, event->xy);
}
else {
delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0];
@ -2984,8 +2979,7 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even
}
}
else {
delta[0] = rc->initial_mouse[0] - event->xy[0];
delta[1] = rc->initial_mouse[1] - event->xy[1];
sub_v2_v2v2(delta, rc->initial_mouse, event->xy);
if (rc->zoom_prop) {
RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom);
delta[0] /= zoom[0];