UI: Automatic X-Ray #109318

Open
Lukas Sneyd wants to merge 20 commits from lcas/blender:automatic-xray into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 94 additions and 0 deletions
Showing only changes of commit 59da79a442 - Show all commits

View File

@ -30,6 +30,7 @@
#include "ED_screen.h"
#include "ED_select_utils.h"
#include "ED_view3d.h"
#include "UI_interface.h"
@ -86,6 +87,18 @@ static void gesture_modal_state_to_operator(wmOperator *op, int modal_state)
}
}
static void gesture_toggle_xray(bContext *C)
{
ToolSettings *ts = CTX_data_tool_settings(C);
wmOperatorType *ot = WM_operatortype_find("VIEW3D_OT_toggle_xray", true);
BLI_assert(ot);
PointerRNA ptr;
WM_operator_properties_create_ptr(&ptr, ot);
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr, NULL);
WM_operator_properties_free(&ptr);
ts->auto_xray_reset ^= true;
}
static int UNUSED_FUNCTION(gesture_modal_state_from_operator)(wmOperator *op)
{
PropertyRNA *prop;
@ -164,9 +177,24 @@ static bool gesture_box_apply(bContext *C, wmOperator *op)
int WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
View3D *v3d = CTX_wm_view3d(C);
const ARegion *region = CTX_wm_region(C);
const bool wait_for_input = !WM_event_is_mouse_drag_or_press(event) &&
RNA_boolean_get(op->ptr, "wait_for_input");
Object *obedit = CTX_data_edit_object(C);
ToolSettings *ts = win->scene->toolsettings;
const bool auto_xray = ts->auto_xray && ts->auto_xray_box ?
obedit ? ts->auto_xray_edit : ts->auto_xray_object :
false;
if (ts->auto_xray_reset) {
ts->auto_xray_reset ^= true;
}
if (v3d && auto_xray) {
if (!XRAY_FLAG_ENABLED(v3d)) {
gesture_toggle_xray(C);
}
}
if (wait_for_input) {
op->customdata = WM_gesture_new(win, region, event, WM_GESTURE_CROSS_RECT);
@ -191,8 +219,11 @@ int WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
View3D *v3d = CTX_wm_view3d(C);
wmGesture *gesture = static_cast<wmGesture *>(op->customdata);
rcti *rect = static_cast<rcti *>(gesture->customdata);
Object *obedit = CTX_data_edit_object(C);
ToolSettings *ts = win->scene->toolsettings;
if (event->type == EVT_MODAL_MAP) {
switch (event->val) {
@ -215,13 +246,22 @@ int WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
gesture->modal_state = event->val;
}
if (gesture_box_apply(C, op)) {
if (ts->auto_xray_reset) {
gesture_toggle_xray(C);
}
gesture_modal_end(C, op);
return OPERATOR_FINISHED;
}
if (ts->auto_xray_reset) {
gesture_toggle_xray(C);
}
gesture_modal_end(C, op);
return OPERATOR_CANCELLED;
}
case GESTURE_MODAL_CANCEL: {
if (ts->auto_xray_reset) {
gesture_toggle_xray(C);
}
gesture_modal_end(C, op);
return OPERATOR_CANCELLED;
}
@ -287,8 +327,24 @@ static void gesture_circle_apply(bContext *C, wmOperator *op);
int WM_gesture_circle_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
View3D *v3d = CTX_wm_view3d(C);
const bool wait_for_input = !WM_event_is_mouse_drag_or_press(event) &&
RNA_boolean_get(op->ptr, "wait_for_input");
Object *obedit = CTX_data_edit_object(C);
ToolSettings *ts = win->scene->toolsettings;
const bool auto_xray = ts->auto_xray && ts->auto_xray_circle ?
obedit ? ts->auto_xray_edit : ts->auto_xray_object :
false;
if (ts->auto_xray_reset) {
ts->auto_xray_reset ^= true;
}
if (v3d && auto_xray) {
if (!XRAY_FLAG_ENABLED(v3d)) {
gesture_toggle_xray(C);
}
}
op->customdata = WM_gesture_new(win, CTX_wm_region(C), event, WM_GESTURE_CIRCLE);
wmGesture *gesture = static_cast<wmGesture *>(op->customdata);
@ -346,10 +402,14 @@ static void gesture_circle_apply(bContext *C, wmOperator *op)
int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
View3D *v3d = CTX_wm_view3d(C);
wmGesture *gesture = static_cast<wmGesture *>(op->customdata);
rcti *rect = static_cast<rcti *>(gesture->customdata);
Object *obedit = CTX_data_edit_object(C);
ToolSettings *ts = win->scene->toolsettings;
if (event->type == MOUSEMOVE) {
rect->xmin = event->xy[0] - gesture->winrct.xmin;
rect->ymin = event->xy[1] - gesture->winrct.ymin;
@ -415,6 +475,9 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
if (is_finished) {
if (ts->auto_xray_reset) {
gesture_toggle_xray(C);
}
gesture_modal_end(C, op);
return OPERATOR_FINISHED; /* use finish or we don't get an undo */
}
@ -477,7 +540,23 @@ void WM_OT_circle_gesture(wmOperatorType *ot)
int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
View3D *v3d = CTX_wm_view3d(C);
PropertyRNA *prop;
Object *obedit = CTX_data_edit_object(C);
ToolSettings *ts = win->scene->toolsettings;
const bool auto_xray = ts->auto_xray && ts->auto_xray_lasso ?
obedit ? ts->auto_xray_edit : ts->auto_xray_object :
false;
if (ts->auto_xray_reset) {
ts->auto_xray_reset ^= true;
}
if (v3d && auto_xray) {
if (!XRAY_FLAG_ENABLED(v3d)) {
gesture_toggle_xray(C);
}
}
op->customdata = WM_gesture_new(win, CTX_wm_region(C), event, WM_GESTURE_LASSO);
@ -517,6 +596,10 @@ static int gesture_lasso_apply(bContext *C, wmOperator *op)
int retval = OPERATOR_FINISHED;
wmGesture *gesture = static_cast<wmGesture *>(op->customdata);
PointerRNA itemptr;
View3D *v3d = CTX_wm_view3d(C);
Object *obedit = CTX_data_edit_object(C);
wmWindow *win = CTX_wm_window(C);
ToolSettings *ts = win->scene->toolsettings;
float loc[2];
int i;
const short *lasso = static_cast<const short int *>(gesture->customdata);
@ -538,12 +621,20 @@ static int gesture_lasso_apply(bContext *C, wmOperator *op)
OPERATOR_RETVAL_CHECK(retval);
}
if (ts->auto_xray_reset) {
gesture_toggle_xray(C);
}
return retval;
}
int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmGesture *gesture = static_cast<wmGesture *>(op->customdata);
View3D *v3d = CTX_wm_view3d(C);
Object *obedit = CTX_data_edit_object(C);
wmWindow *win = CTX_wm_window(C);
ToolSettings *ts = win->scene->toolsettings;
if (event->type == EVT_MODAL_MAP) {
switch (event->val) {
@ -597,6 +688,9 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
break;
}
case EVT_ESCKEY: {
if (ts->auto_xray_reset) {
gesture_toggle_xray(C);
}
gesture_modal_end(C, op);
return OPERATOR_CANCELLED;
}