Page MenuHome

Initial step for new modal op info API: Get shortcuts from modal keymap.
ClosedPublic

Authored by Bastien Montagne (mont29) on Sep 9 2014, 11:55 AM.

Details

Summary

First step for T37699.

note I hacked a bit around RNA enumitems system, to put shorter names into the 'tooltip' part... :|

Only Walk mode use it here, as a demo.

Diff Detail

Repository
rB Blender

Event Timeline

Bastien Montagne (mont29) retitled this revision from to Initial step for new modal op info API: Get shortcuts from modal keymap..Sep 9 2014, 11:55 AM
Bastien Montagne (mont29) updated this object.
Bastien Montagne (mont29) updated this revision to Diff 2557.

Updated against latest master...

Campbell Barton (campbellbarton) requested changes to this revision.
Campbell Barton (campbellbarton) added inline comments.
source/blender/editors/space_view3d/view3d_walk.c
348–388 ↗(On Diff #3392)

While having lower level functions like WM_modalkeymap_operator_items_to_string is good, this ends up being a bit verbose/boiler plate. It might be good to have something a bit higher level here.


A function that advances the string and adds the description text with the modal keymap.

eg, str += WM_modalkeymap_operator_items_to_string(str, WALK_MODAL_CONFIRM, "confirm", ... length info);


another alternative could be to use an array to cut down on repeating id's

char key_table[WALK_MODAL_MAX][SHORTCUT_LENGTH];
/* could make this into a macro... */
 WM_modalkeymap_operator_items_to_string(op->type, WALK_MODAL_DECELERATE, key_table[WALK_MODAL_DECELERATE], SHORTCUT_LENGTH, true);

if we accept some slightly odd string usage we could even do this...

#define WM_MODALKEY(id) \
    WM_modalkeymap_operator_items_to_string_buf(op->type, id, &str_p)

char str_buf[SHORTCUT_LENGTH * WALK_MODAL_MAX];
char *str_p = str_buf;
BLI_snprintf(header, HEADER_LENGTH, IFACE_(
        "%s: confirm, %s: cancel, "
        "%s: gravity (%s), "
        "%s|%s|%s|%s: move around, "
        "%s: fast, %s: slow, "
        "%s|%s: up and down, %s: teleport, %s: jump, "
        "%s: increase speed, %s: decrease speed"),
        WM_MODALKEY(WALK_MODAL_CONFIRM),
        WM_MODALKEY(WALK_MODAL_CANCEL),
        ...
        );

Its a bit odd, but can be done so much less boiler plate then the alternatives. that it may be worth it.

source/blender/windowmanager/intern/wm_keymap.c
909

BLI_strcpy_rlen seems a bit overkill here, could just do...

if (p != buf) *p++ = ' ';
1048

again, for single chars str[totlen++] = '/'

This revision now requires changes to proceed.Mar 26 2015, 9:12 PM
Bastien Montagne (mont29) updated this revision to Diff 4274.

Updated patch and addressed points/suggestions from review.

This revision is now accepted and ready to land.Jul 3 2015, 2:25 PM
This revision was automatically updated to reflect the committed changes.