User customizable keymap for eyedropper (modal operator)
This commit is contained in:
parent
d787db701a
commit
c1d05faa24
Notes:
blender-bot
2023-02-14 11:35:46 +01:00
Referenced by issue #47960, Texture Paint: Various Shaders aren't Respecting OCIO Colour Space Referenced by issue #47709, ASC CDL: Should permit negative values on offset.
|
@ -34,7 +34,7 @@ KM_HIERARCHY = [
|
|||
('View2D Buttons List', 'EMPTY', 'WINDOW', []), # view 2d with buttons navigation
|
||||
|
||||
('User Interface', 'EMPTY', 'WINDOW', [
|
||||
# empty
|
||||
('Eyedropper Modal Map', 'EMPTY', 'WINDOW', []),
|
||||
]),
|
||||
|
||||
('3D View', 'VIEW_3D', 'WINDOW', [ # view 3d navigation and generic stuff (select, transform)
|
||||
|
|
|
@ -67,6 +67,56 @@
|
|||
#include "ED_screen.h"
|
||||
#include "ED_view3d.h"
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Keymap
|
||||
*/
|
||||
/** \name Modal Keymap
|
||||
* \{ */
|
||||
|
||||
enum {
|
||||
EYE_MODAL_CANCEL = 1, /* XXX actually does same as confirming */
|
||||
EYE_MODAL_SAMPLE_CONFIRM,
|
||||
EYE_MODAL_SAMPLE_BEGIN,
|
||||
EYE_MODAL_SAMPLE_RESET,
|
||||
};
|
||||
|
||||
wmKeyMap *eyedropper_modal_keymap(wmKeyConfig *keyconf)
|
||||
{
|
||||
static EnumPropertyItem modal_items[] = {
|
||||
{EYE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
|
||||
{EYE_MODAL_SAMPLE_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
|
||||
{EYE_MODAL_SAMPLE_BEGIN, "SAMPLE_BEGIN", 0, "Start Sampling", ""},
|
||||
{EYE_MODAL_SAMPLE_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Eyedropper Modal Map");
|
||||
|
||||
/* this function is called for each spacetype, only needs to add map once */
|
||||
if (keymap && keymap->modal_items)
|
||||
return NULL;
|
||||
|
||||
keymap = WM_modalkeymap_add(keyconf, "Eyedropper Modal Map", modal_items);
|
||||
|
||||
/* items for modal map */
|
||||
WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, EYE_MODAL_CANCEL);
|
||||
WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, EYE_MODAL_CANCEL);
|
||||
WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, EYE_MODAL_SAMPLE_CONFIRM);
|
||||
WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, EYE_MODAL_SAMPLE_BEGIN);
|
||||
WM_modalkeymap_add_item(keymap, SPACEKEY, KM_RELEASE, KM_ANY, 0, EYE_MODAL_SAMPLE_RESET);
|
||||
|
||||
/* assign to operators */
|
||||
WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_color");
|
||||
WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_id");
|
||||
WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_depth");
|
||||
|
||||
return keymap;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Utility Functions
|
||||
*/
|
||||
|
@ -273,13 +323,13 @@ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
{
|
||||
Eyedropper *eye = (Eyedropper *)op->customdata;
|
||||
|
||||
switch (event->type) {
|
||||
case ESCKEY:
|
||||
case RIGHTMOUSE:
|
||||
eyedropper_cancel(C, op);
|
||||
return OPERATOR_CANCELLED;
|
||||
case LEFTMOUSE:
|
||||
if (event->val == KM_RELEASE) {
|
||||
/* handle modal keymap */
|
||||
if (event->type == EVT_MODAL_MAP) {
|
||||
switch (event->val) {
|
||||
case EYE_MODAL_CANCEL:
|
||||
eyedropper_cancel(C, op);
|
||||
return OPERATOR_CANCELLED;
|
||||
case EYE_MODAL_SAMPLE_CONFIRM:
|
||||
if (eye->accum_tot == 0) {
|
||||
eyedropper_color_sample(C, eye, event->x, event->y);
|
||||
}
|
||||
|
@ -288,28 +338,25 @@ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
}
|
||||
eyedropper_exit(C, op);
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
else if (event->val == KM_PRESS) {
|
||||
case EYE_MODAL_SAMPLE_BEGIN:
|
||||
/* enable accum and make first sample */
|
||||
eye->accum_start = true;
|
||||
eyedropper_color_sample_accum(C, eye, event->x, event->y);
|
||||
}
|
||||
break;
|
||||
case MOUSEMOVE:
|
||||
if (eye->accum_start) {
|
||||
/* button is pressed so keep sampling */
|
||||
eyedropper_color_sample_accum(C, eye, event->x, event->y);
|
||||
eyedropper_color_set_accum(C, eye);
|
||||
}
|
||||
break;
|
||||
case SPACEKEY:
|
||||
if (event->val == KM_RELEASE) {
|
||||
break;
|
||||
case EYE_MODAL_SAMPLE_RESET:
|
||||
eye->accum_tot = 0;
|
||||
zero_v3(eye->accum_col);
|
||||
eyedropper_color_sample_accum(C, eye, event->x, event->y);
|
||||
eyedropper_color_set_accum(C, eye);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (event->type == MOUSEMOVE) {
|
||||
if (eye->accum_start) {
|
||||
/* button is pressed so keep sampling */
|
||||
eyedropper_color_sample_accum(C, eye, event->x, event->y);
|
||||
eyedropper_color_set_accum(C, eye);
|
||||
}
|
||||
}
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
|
@ -560,13 +607,14 @@ static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
{
|
||||
DataDropper *ddr = (DataDropper *)op->customdata;
|
||||
|
||||
switch (event->type) {
|
||||
case ESCKEY:
|
||||
case RIGHTMOUSE:
|
||||
datadropper_cancel(C, op);
|
||||
return OPERATOR_CANCELLED;
|
||||
case LEFTMOUSE:
|
||||
if (event->val == KM_RELEASE) {
|
||||
/* handle modal keymap */
|
||||
if (event->type == EVT_MODAL_MAP) {
|
||||
switch (event->val) {
|
||||
case EYE_MODAL_CANCEL:
|
||||
datadropper_cancel(C, op);
|
||||
return OPERATOR_CANCELLED;
|
||||
case EYE_MODAL_SAMPLE_CONFIRM:
|
||||
{
|
||||
bool success;
|
||||
|
||||
success = datadropper_id_sample(C, ddr, event->x, event->y);
|
||||
|
@ -580,14 +628,12 @@ static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MOUSEMOVE:
|
||||
{
|
||||
ID *id = NULL;
|
||||
datadropper_id_sample_pt(C, ddr, event->x, event->y, &id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (event->type == MOUSEMOVE) {
|
||||
ID *id = NULL;
|
||||
datadropper_id_sample_pt(C, ddr, event->x, event->y, &id);
|
||||
}
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
|
@ -855,13 +901,13 @@ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
{
|
||||
DepthDropper *ddr = (DepthDropper *)op->customdata;
|
||||
|
||||
switch (event->type) {
|
||||
case ESCKEY:
|
||||
case RIGHTMOUSE:
|
||||
depthdropper_cancel(C, op);
|
||||
return OPERATOR_CANCELLED;
|
||||
case LEFTMOUSE:
|
||||
if (event->val == KM_RELEASE) {
|
||||
/* handle modal keymap */
|
||||
if (event->type == EVT_MODAL_MAP) {
|
||||
switch (event->val) {
|
||||
case EYE_MODAL_CANCEL:
|
||||
depthdropper_cancel(C, op);
|
||||
return OPERATOR_CANCELLED;
|
||||
case EYE_MODAL_SAMPLE_CONFIRM:
|
||||
if (ddr->accum_tot == 0) {
|
||||
depthdropper_depth_sample(C, ddr, event->x, event->y);
|
||||
}
|
||||
|
@ -870,28 +916,25 @@ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
}
|
||||
depthdropper_exit(C, op);
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
else if (event->val == KM_PRESS) {
|
||||
case EYE_MODAL_SAMPLE_BEGIN:
|
||||
/* enable accum and make first sample */
|
||||
ddr->accum_start = true;
|
||||
depthdropper_depth_sample_accum(C, ddr, event->x, event->y);
|
||||
}
|
||||
break;
|
||||
case MOUSEMOVE:
|
||||
if (ddr->accum_start) {
|
||||
/* button is pressed so keep sampling */
|
||||
depthdropper_depth_sample_accum(C, ddr, event->x, event->y);
|
||||
depthdropper_depth_set_accum(C, ddr);
|
||||
}
|
||||
break;
|
||||
case SPACEKEY:
|
||||
if (event->val == KM_RELEASE) {
|
||||
break;
|
||||
case EYE_MODAL_SAMPLE_RESET:
|
||||
ddr->accum_tot = 0;
|
||||
ddr->accum_depth = 0.0f;
|
||||
depthdropper_depth_sample_accum(C, ddr, event->x, event->y);
|
||||
depthdropper_depth_set_accum(C, ddr);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (event->type == MOUSEMOVE) {
|
||||
if (ddr->accum_start) {
|
||||
/* button is pressed so keep sampling */
|
||||
depthdropper_depth_sample_accum(C, ddr, event->x, event->y);
|
||||
depthdropper_depth_set_accum(C, ddr);
|
||||
}
|
||||
}
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
|
|
|
@ -42,6 +42,7 @@ struct ARegion;
|
|||
struct bContext;
|
||||
struct uiHandleButtonData;
|
||||
struct wmEvent;
|
||||
struct wmKeyConfig;
|
||||
struct wmOperatorType;
|
||||
struct wmTimer;
|
||||
struct uiStyle;
|
||||
|
@ -737,6 +738,7 @@ bool ui_but_anim_expression_create(uiBut *but, const char *str);
|
|||
void ui_but_anim_autokey(struct bContext *C, uiBut *but, struct Scene *scene, float cfra);
|
||||
|
||||
/* interface_eyedropper.c */
|
||||
struct wmKeyMap *eyedropper_modal_keymap(struct wmKeyConfig *keyconf);
|
||||
void UI_OT_eyedropper_color(struct wmOperatorType *ot);
|
||||
void UI_OT_eyedropper_id(struct wmOperatorType *ot);
|
||||
void UI_OT_eyedropper_depth(struct wmOperatorType *ot);
|
||||
|
|
|
@ -1117,4 +1117,6 @@ void ED_operatortypes_ui(void)
|
|||
void ED_keymap_ui(wmKeyConfig *keyconf)
|
||||
{
|
||||
WM_keymap_find(keyconf, "User Interface", 0, 0);
|
||||
|
||||
eyedropper_modal_keymap(keyconf);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue