Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_gesture_ops.c
| Show All 23 Lines | |||||
| * Operators themselves are defined elsewhere. | * Operators themselves are defined elsewhere. | ||||
| * | * | ||||
| * - Keymaps are in ``wm_operators.c``. | * - Keymaps are in ``wm_operators.c``. | ||||
| * - Property definitions are in ``wm_operator_props.c``. | * - Property definitions are in ``wm_operator_props.c``. | ||||
| */ | */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_scene_types.h" | |||||
| #include "DNA_windowmanager_types.h" | #include "DNA_windowmanager_types.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_rect.h" | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "wm.h" | #include "wm.h" | ||||
| #include "wm_event_system.h" | #include "wm_event_system.h" | ||||
| ▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| wmGesture *gesture = op->customdata; | wmGesture *gesture = op->customdata; | ||||
| rcti *rect = gesture->customdata; | rcti *rect = gesture->customdata; | ||||
| if (event->type == MOUSEMOVE) { | if (event->type == MOUSEMOVE) { | ||||
| if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->is_active == false) { | if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->is_active == false) { | ||||
| rect->xmin = rect->xmax = event->x - gesture->winrct.xmin; | rect->xmin = rect->xmax = event->x - gesture->winrct.xmin; | ||||
| rect->ymin = rect->ymax = event->y - gesture->winrct.ymin; | rect->ymin = rect->ymax = event->y - gesture->winrct.ymin; | ||||
campbellbarton: Prefer the order of these checks be swapped, so the move case is checked first, using `else { .. | |||||
| } | } | ||||
| else if (gesture->move) { | |||||
| BLI_rcti_translate(rect, | |||||
| (event->x - gesture->winrct.xmin) - rect->xmax, | |||||
| (event->y - gesture->winrct.ymin) - rect->ymax); | |||||
| } | |||||
| else { | else { | ||||
| rect->xmax = event->x - gesture->winrct.xmin; | rect->xmax = event->x - gesture->winrct.xmin; | ||||
| rect->ymax = event->y - gesture->winrct.ymin; | rect->ymax = event->y - gesture->winrct.ymin; | ||||
| } | } | ||||
Done Inline ActionsSuggest to calculate the offset, then use BLI_rcti_translate campbellbarton: Suggest to calculate the offset, then use `BLI_rcti_translate` | |||||
Done Inline ActionsI get what you mean, but don't know how to do it. Translate is a relative function, do I not need to store atleast the coordinates of the beginning of the move operation? erik85: I get what you mean, but don't know how to do it. Translate is a relative function, do I not… | |||||
| gesture_box_apply_rect(op); | gesture_box_apply_rect(op); | ||||
| wm_gesture_tag_redraw(win); | wm_gesture_tag_redraw(win); | ||||
| } | } | ||||
| else if (event->type == EVT_MODAL_MAP) { | else if (event->type == EVT_MODAL_MAP) { | ||||
| switch (event->val) { | switch (event->val) { | ||||
| case GESTURE_MODAL_MOVE: | |||||
| gesture->move = !gesture->move; | |||||
| break; | |||||
| case GESTURE_MODAL_BEGIN: | case GESTURE_MODAL_BEGIN: | ||||
| if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->is_active == false) { | if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->is_active == false) { | ||||
| gesture->is_active = true; | gesture->is_active = true; | ||||
| wm_gesture_tag_redraw(win); | wm_gesture_tag_redraw(win); | ||||
| } | } | ||||
| break; | break; | ||||
| case GESTURE_MODAL_SELECT: | case GESTURE_MODAL_SELECT: | ||||
| case GESTURE_MODAL_DESELECT: | case GESTURE_MODAL_DESELECT: | ||||
| ▲ Show 20 Lines • Show All 417 Lines • ▼ Show 20 Lines | static int gesture_lasso_apply(bContext *C, wmOperator *op) | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event) | int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| wmGesture *gesture = op->customdata; | wmGesture *gesture = op->customdata; | ||||
| switch (event->type) { | switch (event->type) { | ||||
| case EVT_MODAL_MAP: | |||||
| switch (event->val) { | |||||
| case GESTURE_MODAL_MOVE: | |||||
| gesture->move = !gesture->move; | |||||
| break; | |||||
| } | |||||
| case MOUSEMOVE: | case MOUSEMOVE: | ||||
| case INBETWEEN_MOUSEMOVE: | case INBETWEEN_MOUSEMOVE: | ||||
| wm_gesture_tag_redraw(CTX_wm_window(C)); | wm_gesture_tag_redraw(CTX_wm_window(C)); | ||||
| if (gesture->points == gesture->points_alloc) { | if (gesture->points == gesture->points_alloc) { | ||||
| gesture->points_alloc *= 2; | gesture->points_alloc *= 2; | ||||
| gesture->customdata = MEM_reallocN(gesture->customdata, | gesture->customdata = MEM_reallocN(gesture->customdata, | ||||
| sizeof(short[2]) * gesture->points_alloc); | sizeof(short[2]) * gesture->points_alloc); | ||||
| } | } | ||||
| { | { | ||||
| int x, y; | int x, y; | ||||
| short *lasso = gesture->customdata; | short *lasso = gesture->customdata; | ||||
| lasso += (2 * gesture->points - 2); | lasso += (2 * gesture->points - 2); | ||||
| x = (event->x - gesture->winrct.xmin - lasso[0]); | x = (event->x - gesture->winrct.xmin - lasso[0]); | ||||
| y = (event->y - gesture->winrct.ymin - lasso[1]); | y = (event->y - gesture->winrct.ymin - lasso[1]); | ||||
| /* move the lasso */ | |||||
| if (gesture->move) { | |||||
| for (int i = 0; i < gesture->points; i++) { | |||||
| lasso[0 - (i * 2)] += x; | |||||
| lasso[1 - (i * 2)] += y; | |||||
| } | |||||
| } | |||||
| /* make a simple distance check to get a smoother lasso | /* make a simple distance check to get a smoother lasso | ||||
| * add only when at least 2 pixels between this and previous location */ | * add only when at least 2 pixels between this and previous location */ | ||||
Not Done Inline ActionsThis distance, being always unscaled pixels, should mean that this lasso smoothing will be different when using a high-dpi displays. harley: This distance, being always unscaled pixels, should mean that this lasso smoothing will be… | |||||
| if ((x * x + y * y) > 4) { | else if ((x * x + y * y) > (2 * UI_DPI_FAC) ^ 2) { | ||||
| lasso += 2; | lasso += 2; | ||||
Done Inline ActionsThis seems unnecessarily confusing, it can be written as. for (int i = 0; i < gesture->points; i++) {
lasso[(i * 2)] += x;
lasso[(i * 2) + 1] += y;
}campbellbarton: This seems unnecessarily confusing, it can be written as.
```
for (int i = 0; i < gesture… | |||||
| lasso[0] = event->x - gesture->winrct.xmin; | lasso[0] = event->x - gesture->winrct.xmin; | ||||
| lasso[1] = event->y - gesture->winrct.ymin; | lasso[1] = event->y - gesture->winrct.ymin; | ||||
| gesture->points++; | gesture->points++; | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case LEFTMOUSE: | case LEFTMOUSE: | ||||
| ▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| rcti *rect = gesture->customdata; | rcti *rect = gesture->customdata; | ||||
| if (event->type == MOUSEMOVE) { | if (event->type == MOUSEMOVE) { | ||||
| if (gesture->is_active == false) { | if (gesture->is_active == false) { | ||||
| rect->xmin = rect->xmax = event->x - gesture->winrct.xmin; | rect->xmin = rect->xmax = event->x - gesture->winrct.xmin; | ||||
| rect->ymin = rect->ymax = event->y - gesture->winrct.ymin; | rect->ymin = rect->ymax = event->y - gesture->winrct.ymin; | ||||
| } | } | ||||
| else if (gesture->move) { | |||||
| BLI_rcti_translate(rect, | |||||
| (event->x - gesture->winrct.xmin) - rect->xmax, | |||||
| (event->y - gesture->winrct.ymin) - rect->ymax); | |||||
| gesture_straightline_apply(C, op); | |||||
| } | |||||
| else { | else { | ||||
| rect->xmax = event->x - gesture->winrct.xmin; | rect->xmax = event->x - gesture->winrct.xmin; | ||||
| rect->ymax = event->y - gesture->winrct.ymin; | rect->ymax = event->y - gesture->winrct.ymin; | ||||
| gesture_straightline_apply(C, op); | gesture_straightline_apply(C, op); | ||||
| } | } | ||||
| wm_gesture_tag_redraw(win); | wm_gesture_tag_redraw(win); | ||||
| } | } | ||||
| else if (event->type == EVT_MODAL_MAP) { | else if (event->type == EVT_MODAL_MAP) { | ||||
| switch (event->val) { | switch (event->val) { | ||||
| case GESTURE_MODAL_MOVE: | |||||
| gesture->move = !gesture->move; | |||||
| break; | |||||
| case GESTURE_MODAL_BEGIN: | case GESTURE_MODAL_BEGIN: | ||||
| if (gesture->is_active == false) { | if (gesture->is_active == false) { | ||||
| gesture->is_active = true; | gesture->is_active = true; | ||||
| wm_gesture_tag_redraw(win); | wm_gesture_tag_redraw(win); | ||||
| } | } | ||||
| break; | break; | ||||
| case GESTURE_MODAL_SELECT: | case GESTURE_MODAL_SELECT: | ||||
| if (gesture_straightline_apply(C, op)) { | if (gesture_straightline_apply(C, op)) { | ||||
| Show All 26 Lines | int WM_gesture_straightline_oneshot_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| rcti *rect = gesture->customdata; | rcti *rect = gesture->customdata; | ||||
| if (event->type == MOUSEMOVE) { | if (event->type == MOUSEMOVE) { | ||||
| if (gesture->is_active == false) { | if (gesture->is_active == false) { | ||||
| rect->xmin = rect->xmax = event->x - gesture->winrct.xmin; | rect->xmin = rect->xmax = event->x - gesture->winrct.xmin; | ||||
| rect->ymin = rect->ymax = event->y - gesture->winrct.ymin; | rect->ymin = rect->ymax = event->y - gesture->winrct.ymin; | ||||
| } | } | ||||
| else if (gesture->move) { | |||||
| BLI_rcti_translate(rect, | |||||
| (event->x - gesture->winrct.xmin) - rect->xmax, | |||||
| (event->y - gesture->winrct.ymin) - rect->ymax); | |||||
| } | |||||
| else { | else { | ||||
| rect->xmax = event->x - gesture->winrct.xmin; | rect->xmax = event->x - gesture->winrct.xmin; | ||||
| rect->ymax = event->y - gesture->winrct.ymin; | rect->ymax = event->y - gesture->winrct.ymin; | ||||
| } | } | ||||
| wm_gesture_tag_redraw(win); | wm_gesture_tag_redraw(win); | ||||
| } | } | ||||
| else if (event->type == EVT_MODAL_MAP) { | else if (event->type == EVT_MODAL_MAP) { | ||||
| switch (event->val) { | switch (event->val) { | ||||
| case GESTURE_MODAL_MOVE: | |||||
| gesture->move = !gesture->move; | |||||
| break; | |||||
| case GESTURE_MODAL_BEGIN: | case GESTURE_MODAL_BEGIN: | ||||
| if (gesture->is_active == false) { | if (gesture->is_active == false) { | ||||
| gesture->is_active = true; | gesture->is_active = true; | ||||
| wm_gesture_tag_redraw(win); | wm_gesture_tag_redraw(win); | ||||
| } | } | ||||
| break; | break; | ||||
| case GESTURE_MODAL_SELECT: | case GESTURE_MODAL_SELECT: | ||||
| case GESTURE_MODAL_DESELECT: | case GESTURE_MODAL_DESELECT: | ||||
| ▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines | |||||
Prefer the order of these checks be swapped, so the move case is checked first, using else { ... } for the default dragging behavior.