[Bf-blender-cvs] [1ace327] master: Walk mode: Add modal shortcuts in UI (header help message).

Bastien Montagne noreply at git.blender.org
Fri Jul 3 15:57:36 CEST 2015


Commit: 1ace3272aa4fbde703c975ddec4e1ccf31066da5
Author: Bastien Montagne
Date:   Fri Jul 3 15:54:34 2015 +0200
Branches: master
https://developer.blender.org/rB1ace3272aa4fbde703c975ddec4e1ccf31066da5

Walk mode: Add modal shortcuts in UI (header help message).

===================================================================

M	source/blender/editors/space_view3d/view3d_walk.c
M	source/blender/windowmanager/intern/wm_keymap.c

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c
index 1d5c2a3..a581352 100644
--- a/source/blender/editors/space_view3d/view3d_walk.c
+++ b/source/blender/editors/space_view3d/view3d_walk.c
@@ -52,6 +52,7 @@
 
 #include "PIL_time.h" /* smoothview */
 
+#include "UI_interface.h"
 #include "UI_resources.h"
 
 #include "view3d_intern.h"  /* own include */
@@ -345,27 +346,42 @@ static void drawWalkPixel(const struct bContext *UNUSED(C), ARegion *ar, void *a
 	glEnd();
 }
 
-static void walk_update_header(bContext *C, WalkInfo *walk)
+static void walk_update_header(bContext *C, wmOperator *op, WalkInfo *walk)
 {
-	bool gravity = walk->navigation_mode == WALK_MODE_GRAVITY ||
-	(walk->teleport.state == WALK_TELEPORT_STATE_ON &&
-	 walk->teleport.navigation_mode == WALK_MODE_GRAVITY);
-
-#define HEADER_LENGTH 256
-	char header[HEADER_LENGTH];
-
-	BLI_snprintf(header, HEADER_LENGTH, IFACE_("LMB/Return: confirm, Esc/RMB: cancel, "
-	                                           "Tab: gravity (%s), "
-	                                           "WASD: move around, "
-	                                           "Shift: fast, Alt: slow, "
-	                                           "QE: up and down, MMB/Space: teleport, V: jump, "
-	                                           "Pad +/Wheel Up: increase speed, Pad -/Wheel Down: decrease speed"),
-	             WM_bool_as_string(gravity));
+	const bool gravity = (walk->navigation_mode == WALK_MODE_GRAVITY) ||
+	                     ((walk->teleport.state == WALK_TELEPORT_STATE_ON) &&
+	                      (walk->teleport.navigation_mode == WALK_MODE_GRAVITY));
+	char header[UI_MAX_DRAW_STR];
+	char buf[UI_MAX_DRAW_STR];
+
+	char *p = buf;
+	int available_len = sizeof(buf);
+
+#define WM_MODALKEY(_id) \
+	WM_modalkeymap_operator_items_to_string_buf(op->type, (_id), true, UI_MAX_SHORTCUT_STR, &available_len, &p)
+
+	BLI_snprintf(header, sizeof(header), 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),
+	             WM_MODALKEY(WALK_MODAL_TOGGLE), WM_bool_as_string(gravity),
+	             WM_MODALKEY(WALK_MODAL_DIR_FORWARD), WM_MODALKEY(WALK_MODAL_DIR_LEFT),
+	             WM_MODALKEY(WALK_MODAL_DIR_BACKWARD), WM_MODALKEY(WALK_MODAL_DIR_RIGHT),
+	             WM_MODALKEY(WALK_MODAL_FAST_ENABLE), WM_MODALKEY(WALK_MODAL_SLOW_ENABLE),
+	             WM_MODALKEY(WALK_MODAL_DIR_UP), WM_MODALKEY(WALK_MODAL_DIR_DOWN),
+	             WM_MODALKEY(WALK_MODAL_TELEPORT), WM_MODALKEY(WALK_MODAL_JUMP),
+	             WM_MODALKEY(WALK_MODAL_ACCELERATE), WM_MODALKEY(WALK_MODAL_DECELERATE));
+
+#undef WM_MODALKEY
+
 	ED_area_headerprint(CTX_wm_area(C), header);
-#undef HEADER_LENGTH
 }
 
-static void walk_navigation_mode_set(bContext *C, WalkInfo *walk, eWalkMethod mode)
+static void walk_navigation_mode_set(bContext *C, wmOperator *op, WalkInfo *walk, eWalkMethod mode)
 {
 	if (mode == WALK_MODE_FREE) {
 		walk->navigation_mode = WALK_MODE_FREE;
@@ -376,7 +392,7 @@ static void walk_navigation_mode_set(bContext *C, WalkInfo *walk, eWalkMethod mo
 		walk->gravity_state = WALK_GRAVITY_STATE_START;
 	}
 
-	walk_update_header(C, walk);
+	walk_update_header(C, op, walk);
 }
 
 /**
@@ -510,9 +526,9 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
 	walk->mouse_speed = U.walk_navigation.mouse_speed;
 
 	if ((U.walk_navigation.flag & USER_WALK_GRAVITY))
-		walk_navigation_mode_set(C, walk, WALK_MODE_GRAVITY);
+		walk_navigation_mode_set(C, op, walk, WALK_MODE_GRAVITY);
 	else
-		walk_navigation_mode_set(C, walk, WALK_MODE_FREE);
+		walk_navigation_mode_set(C, op, walk, WALK_MODE_FREE);
 
 	walk->view_height = U.walk_navigation.view_height;
 	walk->jump_height = U.walk_navigation.jump_height;
@@ -633,7 +649,7 @@ static bool wm_event_is_last_mousemove(const wmEvent *event)
 	return true;
 }
 
-static void walkEvent(bContext *C, wmOperator *UNUSED(op), WalkInfo *walk, const wmEvent *event)
+static void walkEvent(bContext *C, wmOperator *op, WalkInfo *walk, const wmEvent *event)
 {
 	if (event->type == TIMER && event->customdata == walk->timer) {
 		walk->redraw = true;
@@ -869,7 +885,7 @@ static void walkEvent(bContext *C, wmOperator *UNUSED(op), WalkInfo *walk, const
 					teleport->duration = U.walk_navigation.teleport_time;
 
 					teleport->navigation_mode = walk->navigation_mode;
-					walk_navigation_mode_set(C, walk, WALK_MODE_FREE);
+					walk_navigation_mode_set(C, op, walk, WALK_MODE_FREE);
 
 					copy_v3_v3(teleport->origin, walk->rv3d->viewinv[3]);
 
@@ -892,10 +908,10 @@ static void walkEvent(bContext *C, wmOperator *UNUSED(op), WalkInfo *walk, const
 
 			case WALK_MODAL_TOGGLE:
 				if (walk->navigation_mode == WALK_MODE_GRAVITY) {
-					walk_navigation_mode_set(C, walk, WALK_MODE_FREE);
+					walk_navigation_mode_set(C, op, walk, WALK_MODE_FREE);
 				}
 				else { /* WALK_MODE_FREE */
-					walk_navigation_mode_set(C, walk, WALK_MODE_GRAVITY);
+					walk_navigation_mode_set(C, op, walk, WALK_MODE_GRAVITY);
 				}
 				break;
 		}
@@ -918,7 +934,7 @@ static float getVelocityZeroTime(const float gravity, const float velocity)
 	return velocity / gravity;
 }
 
-static int walkApply(bContext *C, WalkInfo *walk)
+static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk)
 {
 #define WALK_ROTATE_FAC 2.2f /* more is faster */
 #define WALK_TOP_LIMIT DEG2RADF(85.0f)
@@ -1231,7 +1247,7 @@ static int walkApply(bContext *C, WalkInfo *walk)
 				if (t >= 1.0f) {
 					t = 1.0f;
 					walk->teleport.state = WALK_TELEPORT_STATE_OFF;
-					walk_navigation_mode_set(C, walk, walk->teleport.navigation_mode);
+					walk_navigation_mode_set(C, op, walk, walk->teleport.navigation_mode);
 				}
 
 				mul_v3_v3fl(new_loc, walk->teleport.direction, t);
@@ -1348,7 +1364,7 @@ static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event)
 		}
 	}
 	else if (event->type == TIMER && event->customdata == walk->timer) {
-		walkApply(C, walk);
+		walkApply(C, op, walk);
 	}
 
 	do_draw |= walk->redraw;
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 6676776..29d54f4 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -900,9 +900,10 @@ const char *WM_key_event_string(const short type, const bool compact)
 }
 
 /* TODO: also support (some) value, like e.g. double-click? */
-int WM_keymap_item_raw_to_string(const short shift, const short ctrl, const short alt, const short oskey,
-                                 const short keymodifier, const short type, const bool compact,
-                                 const int len, char *r_str)
+int WM_keymap_item_raw_to_string(
+        const short shift, const short ctrl, const short alt, const short oskey,
+        const short keymodifier, const short type, const bool compact,
+        const int len, char *r_str)
 {
 #define ADD_SEP if (p != buf) *p++ = ' '; (void)0
 
@@ -966,8 +967,8 @@ int WM_keymap_item_raw_to_string(const short shift, const short ctrl, const shor
 
 int WM_keymap_item_to_string(wmKeyMapItem *kmi, const bool compact, const int len, char *r_str)
 {
-	return WM_keymap_item_raw_to_string(kmi->shift, kmi->ctrl, kmi->alt, kmi->oskey,
-	                                    kmi->keymodifier, kmi->type, compact, len, r_str);
+	return WM_keymap_item_raw_to_string(
+	            kmi->shift, kmi->ctrl, kmi->alt, kmi->oskey, kmi->keymodifier, kmi->type, compact, len, r_str);
 }
 
 int WM_modalkeymap_operator_items_to_string(




More information about the Bf-blender-cvs mailing list