UI Code Quality: Use derived struct for hot-key buttons
`uiBut` contained a variable that was only used for these hot-key
buttons. This may also help getting rid of the `UI_BUT_IMMEDIATE` flag,
which is also only used for this button type. We are running out of
available bits for flags, so this would be useful.
Continuing the work from 49f088e2d0
. Part of T74432.
This commit is contained in:
@@ -3832,21 +3832,22 @@ static void ui_but_update_ex(uiBut *but, const bool validate)
|
||||
}
|
||||
case UI_BTYPE_HOTKEY_EVENT:
|
||||
if (but->flag & UI_SELECT) {
|
||||
const uiButHotkeyEvent *hotkey_but = (uiButHotkeyEvent *)but;
|
||||
|
||||
if (but->modifier_key) {
|
||||
if (hotkey_but->modifier_key) {
|
||||
char *str = but->drawstr;
|
||||
but->drawstr[0] = '\0';
|
||||
|
||||
if (but->modifier_key & KM_SHIFT) {
|
||||
if (hotkey_but->modifier_key & KM_SHIFT) {
|
||||
str += BLI_strcpy_rlen(str, "Shift ");
|
||||
}
|
||||
if (but->modifier_key & KM_CTRL) {
|
||||
if (hotkey_but->modifier_key & KM_CTRL) {
|
||||
str += BLI_strcpy_rlen(str, "Ctrl ");
|
||||
}
|
||||
if (but->modifier_key & KM_ALT) {
|
||||
if (hotkey_but->modifier_key & KM_ALT) {
|
||||
str += BLI_strcpy_rlen(str, "Alt ");
|
||||
}
|
||||
if (but->modifier_key & KM_OSKEY) {
|
||||
if (hotkey_but->modifier_key & KM_OSKEY) {
|
||||
str += BLI_strcpy_rlen(str, "Cmd ");
|
||||
}
|
||||
|
||||
@@ -3972,6 +3973,10 @@ static void ui_but_alloc_info(const eButType type,
|
||||
alloc_size = sizeof(uiButTreeRow);
|
||||
alloc_str = "uiButTreeRow";
|
||||
break;
|
||||
case UI_BTYPE_HOTKEY_EVENT:
|
||||
alloc_size = sizeof(uiButHotkeyEvent);
|
||||
alloc_str = "uiButHotkeyEvent";
|
||||
break;
|
||||
default:
|
||||
alloc_size = sizeof(uiBut);
|
||||
alloc_str = "uiBut";
|
||||
|
@@ -4501,10 +4501,13 @@ static int ui_do_but_HOTKEYEVT(bContext *C,
|
||||
uiHandleButtonData *data,
|
||||
const wmEvent *event)
|
||||
{
|
||||
uiButHotkeyEvent *hotkey_but = (uiButHotkeyEvent *)but;
|
||||
BLI_assert(but->type == UI_BTYPE_HOTKEY_EVENT);
|
||||
|
||||
if (data->state == BUTTON_STATE_HIGHLIGHT) {
|
||||
if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && event->val == KM_PRESS) {
|
||||
but->drawstr[0] = 0;
|
||||
but->modifier_key = 0;
|
||||
hotkey_but->modifier_key = 0;
|
||||
button_activate_state(C, but, BUTTON_STATE_WAIT_KEY_EVENT);
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
@@ -4538,7 +4541,7 @@ static int ui_do_but_HOTKEYEVT(bContext *C,
|
||||
}
|
||||
|
||||
/* always set */
|
||||
but->modifier_key = event->modifier;
|
||||
hotkey_but->modifier_key = event->modifier;
|
||||
|
||||
ui_but_update(but);
|
||||
ED_region_tag_redraw(data->region);
|
||||
|
@@ -223,7 +223,6 @@ struct uiBut {
|
||||
bool changed;
|
||||
/** so buttons can support unit systems which are not RNA */
|
||||
uchar unit_type;
|
||||
short modifier_key;
|
||||
short iconadd;
|
||||
|
||||
/** #UI_BTYPE_BLOCK data */
|
||||
@@ -375,6 +374,13 @@ typedef struct uiButCurveMapping {
|
||||
eButGradientType gradient_type;
|
||||
} uiButCurveMapping;
|
||||
|
||||
/** Derived struct for #UI_BTYPE_HOTKEY_EVENT. */
|
||||
typedef struct uiButHotkeyEvent {
|
||||
uiBut but;
|
||||
|
||||
short modifier_key;
|
||||
} uiButHotkeyEvent;
|
||||
|
||||
/**
|
||||
* Additional, superimposed icon for a button, invoking an operator.
|
||||
*/
|
||||
|
@@ -961,11 +961,17 @@ static void ui_item_enum_expand_tabs(uiLayout *layout,
|
||||
static void ui_keymap_but_cb(bContext *UNUSED(C), void *but_v, void *UNUSED(key_v))
|
||||
{
|
||||
uiBut *but = but_v;
|
||||
BLI_assert(but->type == UI_BTYPE_HOTKEY_EVENT);
|
||||
const uiButHotkeyEvent *hotkey_but = (uiButHotkeyEvent *)but;
|
||||
|
||||
RNA_int_set(&but->rnapoin, "shift", (but->modifier_key & KM_SHIFT) ? KM_MOD_HELD : KM_NOTHING);
|
||||
RNA_int_set(&but->rnapoin, "ctrl", (but->modifier_key & KM_CTRL) ? KM_MOD_HELD : KM_NOTHING);
|
||||
RNA_int_set(&but->rnapoin, "alt", (but->modifier_key & KM_ALT) ? KM_MOD_HELD : KM_NOTHING);
|
||||
RNA_int_set(&but->rnapoin, "oskey", (but->modifier_key & KM_OSKEY) ? KM_MOD_HELD : KM_NOTHING);
|
||||
RNA_int_set(
|
||||
&but->rnapoin, "shift", (hotkey_but->modifier_key & KM_SHIFT) ? KM_MOD_HELD : KM_NOTHING);
|
||||
RNA_int_set(
|
||||
&but->rnapoin, "ctrl", (hotkey_but->modifier_key & KM_CTRL) ? KM_MOD_HELD : KM_NOTHING);
|
||||
RNA_int_set(
|
||||
&but->rnapoin, "alt", (hotkey_but->modifier_key & KM_ALT) ? KM_MOD_HELD : KM_NOTHING);
|
||||
RNA_int_set(
|
||||
&but->rnapoin, "oskey", (hotkey_but->modifier_key & KM_OSKEY) ? KM_MOD_HELD : KM_NOTHING);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user