Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_gesture_ops.c
| Show First 20 Lines • Show All 878 Lines • ▼ Show 20 Lines | |||||
| int WM_gesture_straightline_active_side_invoke(bContext *C, wmOperator *op, const wmEvent *event) | int WM_gesture_straightline_active_side_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| WM_gesture_straightline_invoke(C, op, event); | WM_gesture_straightline_invoke(C, op, event); | ||||
| wmGesture *gesture = op->customdata; | wmGesture *gesture = op->customdata; | ||||
| gesture->draw_active_side = true; | gesture->draw_active_side = true; | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| #define STRAIGHTLINE_SNAP_DEG 15.0f | |||||
| static void wm_gesture_straightline_do_angle_snap(rcti *rect) | |||||
| { | |||||
| const float line_start[2] = {rect->xmin, rect->ymin}; | |||||
| const float line_end[2] = {rect->xmax, rect->ymax}; | |||||
| const float x_axis[2] = {1.0f, 0.0f}; | |||||
| float line_direction[2]; | |||||
| sub_v2_v2v2(line_direction, line_end, line_start); | |||||
| const float line_length = normalize_v2(line_direction); | |||||
| const float angle = angle_signed_v2v2(x_axis, line_direction); | |||||
| const float angle_deg = RAD2DEG(angle) + (STRAIGHTLINE_SNAP_DEG / 2.0f); | |||||
| const float angle_snapped_deg = -floorf(angle_deg / STRAIGHTLINE_SNAP_DEG) * | |||||
| STRAIGHTLINE_SNAP_DEG; | |||||
| const float angle_snapped = DEG2RAD(angle_snapped_deg); | |||||
| float line_snapped_end[2]; | |||||
| rotate_v2_v2fl(line_snapped_end, x_axis, angle_snapped); | |||||
| mul_v2_fl(line_snapped_end, line_length); | |||||
| add_v2_v2(line_snapped_end, line_start); | |||||
| rect->xmax = (int)line_snapped_end[0]; | |||||
| rect->ymax = (int)line_snapped_end[1]; | |||||
| } | |||||
| /** | /** | ||||
| * This modal callback calls exec once per mouse move event while the gesture is active with the | * This modal callback calls exec once per mouse move event while the gesture is active with the | ||||
| * updated line start and end values, so it can be used for tools that have a real time preview | * updated line start and end values, so it can be used for tools that have a real time preview | ||||
| * (like a gradient updating in real time over the mesh). | * (like a gradient updating in real time over the mesh). | ||||
| */ | */ | ||||
| int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *event) | int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| wmGesture *gesture = op->customdata; | wmGesture *gesture = op->customdata; | ||||
| Show All 12 Lines | else if (gesture->move) { | ||||
| gesture_straightline_apply(C, op); | 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); | ||||
| } | } | ||||
| if (gesture->use_snap) { | |||||
| wm_gesture_straightline_do_angle_snap(rect); | |||||
| } | |||||
| 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: | case GESTURE_MODAL_MOVE: | ||||
| gesture->move = !gesture->move; | gesture->move = !gesture->move; | ||||
| break; | 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_SNAP: | |||||
| /* Toggle snapping on/off. */ | |||||
| gesture->use_snap = !gesture->use_snap; | |||||
| break; | |||||
| case GESTURE_MODAL_SELECT: | case GESTURE_MODAL_SELECT: | ||||
| if (gesture_straightline_apply(C, op)) { | if (gesture_straightline_apply(C, op)) { | ||||
| gesture_modal_end(C, op); | gesture_modal_end(C, op); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| gesture_modal_end(C, op); | gesture_modal_end(C, op); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| Show All 30 Lines | else if (gesture->move) { | ||||
| (event->x - gesture->winrct.xmin) - rect->xmax, | (event->x - gesture->winrct.xmin) - rect->xmax, | ||||
| (event->y - gesture->winrct.ymin) - rect->ymax); | (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; | ||||
| } | } | ||||
| if (gesture->use_snap) { | |||||
| wm_gesture_straightline_do_angle_snap(rect); | |||||
| } | |||||
| 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: | case GESTURE_MODAL_MOVE: | ||||
| gesture->move = !gesture->move; | gesture->move = !gesture->move; | ||||
| break; | 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_SNAP: | |||||
| /* Toggle snapping on/off. */ | |||||
| gesture->use_snap = !gesture->use_snap; | |||||
| break; | |||||
| case GESTURE_MODAL_SELECT: | case GESTURE_MODAL_SELECT: | ||||
| case GESTURE_MODAL_DESELECT: | case GESTURE_MODAL_DESELECT: | ||||
| case GESTURE_MODAL_IN: | case GESTURE_MODAL_IN: | ||||
| case GESTURE_MODAL_OUT: | case GESTURE_MODAL_OUT: | ||||
| if (gesture->wait_for_input) { | if (gesture->wait_for_input) { | ||||
| gesture->modal_state = event->val; | gesture->modal_state = event->val; | ||||
| } | } | ||||
| if (gesture_straightline_apply(C, op)) { | if (gesture_straightline_apply(C, op)) { | ||||
| ▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines | |||||