Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Vazquez <venomgfx@gmail.com>2012-06-02 01:59:06 +0400
committerPablo Vazquez <venomgfx@gmail.com>2012-06-02 01:59:06 +0400
commit98281f17e2d5bb07767e81041c454f4d113f6246 (patch)
treefe8479aec186b3a81e01f2e4c95db431784019da /space_view3d_screencast_keys.py
parentef545f4a6397ff6ee84c66b096c80d1aac9fe9b5 (diff)
Screencast Keys Addon
==================== Updated some parts and added some new options: - Individual color (and alpha support) for text/icon and background box - Shadows on text for better readability - Display Last Operator option when box is active - Background Box is now always drawn (less noise) - Option to hide the box when no key is pressed and change its width - Text is drawn on top of the box (used to be below) - Reshuffled the UI a bit This is my first commit on this addon, so any feedback is very welcome. A lot more work is needed in this area we know, but I think in the meantime the changes so far make this addon much more flexible.
Diffstat (limited to 'space_view3d_screencast_keys.py')
-rw-r--r--space_view3d_screencast_keys.py263
1 files changed, 185 insertions, 78 deletions
diff --git a/space_view3d_screencast_keys.py b/space_view3d_screencast_keys.py
index 26047d95..b7f7cfba 100644
--- a/space_view3d_screencast_keys.py
+++ b/space_view3d_screencast_keys.py
@@ -19,10 +19,10 @@
# <pep8 compliant>
bl_info = {
- 'name': 'Screencast Keys',
- 'author': 'Paulo Gomes, Bart Crouch, John E. Herrenyo, Gaia Clary',
- 'version': (1, 5),
- 'blender': (2, 6, 1),
+ 'name': "Screencast Keys",
+ 'author': 'Paulo Gomes, Bart Crouch, John E. Herrenyo, Gaia Clary, Pablo Vazquez',
+ 'version': (1, 6),
+ 'blender': (2, 6, 3),
'location': 'View3D > Properties panel > Screencast Keys',
'warning': '',
'description': 'Display keys pressed in the 3d-view, '\
@@ -33,7 +33,6 @@ bl_info = {
'func=detail&aid=21612',
'category': '3D View'}
-
import bgl
import blf
import bpy
@@ -72,19 +71,23 @@ def draw_callback_px(self, context):
font_size = sc.screencast_keys_font_size
mouse_size = sc.screencast_keys_mouse_size
- link = sc.screencast_keys_link
+ box_draw = sc.screencast_keys_box_draw
pos_x, pos_y = getDisplayLocation(context)
# draw text in the 3d-view
# ========================
blf.size(0, sc.screencast_keys_font_size, 72)
- r, g, b = sc.screencast_keys_color
+ blf.enable(0, blf.SHADOW)
+ blf.shadow_offset(0, 1, -1)
+ blf.shadow(0, 5, 0.0, 0.0, 0.0, 0.8)
+
+ font_color_r, font_color_g, font_color_b, font_color_alpha = sc.screencast_keys_text_color
final = 0
row_count = len(self.key)
keypos_x = pos_x
- if link==True:
- keypos_x += mouse_size * MOUSE_RATIO * 1.3
+ if box_draw==True:
+ keypos_x += mouse_size * MOUSE_RATIO * 1.7
shift = 0
if mouse_size > font_size*row_count:
shift = (mouse_size - font_size*row_count) / 2
@@ -94,13 +97,16 @@ def draw_callback_px(self, context):
alpha = 1.0
for i in range(len(self.key)):
label_time = time.time() - self.time[i]
- if label_time < 2: # only display key-presses of last 2 seconds
-
+ if label_time < 4: # only display key-presses of last 2 seconds
+ if label_time > 3.2:
+ blf.blur(0, 1)
+ if label_time > 3.7:
+ blf.blur(0, 3)
keypos_y = pos_y + shift + font_size*(i+0.1)
blf.position(0, keypos_x, keypos_y , 0)
- alpha = min(1.0, max(0.0, 2 * (2 - label_time)))
- bgl.glColor4f(r, g, b, alpha)
+ alpha = min(1.0, max(0.0, 4 * (4 - label_time)))
+ bgl.glColor4f(font_color_r, font_color_g, font_color_b, font_color_alpha * alpha)
blf.draw(0, self.key[i])
text_width, text_height = getBoundingBox(text_width, text_height,
self.key[i])
@@ -109,6 +115,12 @@ def draw_callback_px(self, context):
else:
break
+ # remove blurriness
+
+ # disable shadows so they don't appear all over blender
+ blf.blur(0,0)
+ blf.disable(0, blf.SHADOW)
+
# get rid of status texts that aren't displayed anymore
self.key = self.key[:final]
self.time = self.time[:final]
@@ -117,7 +129,7 @@ def draw_callback_px(self, context):
# ==========================================
if sc.screencast_keys_mouse == 'icon':
for shape in ["mouse", "left_button", "middle_button", "right_button"]:
- draw_mouse(context, shape, "outline", 0.5)
+ draw_mouse(context, shape, "outline", font_color_alpha * 0.4)
final = 0
for i in range(len(self.mouse)):
@@ -135,35 +147,87 @@ def draw_callback_px(self, context):
self.mouse = self.mouse[:final]
self.mouse_time = self.mouse_time[:final]
- # Draw border (if enabled)
+def draw_callback_px_box(self, context):
+ wm = context.window_manager
+ sc = context.scene
+ if not wm.screencast_keys_keys:
+ return
+
+ font_size = sc.screencast_keys_font_size
+ mouse_size = sc.screencast_keys_mouse_size
+ box_draw = sc.screencast_keys_box_draw
+ pos_x, pos_y = getDisplayLocation(context)
+
+ # get text-width/height to resize the box
# ========================
- if link and row_count > 0:
- padding = 8
- x0 = max(0, pos_x - padding)
- y0 = max(0, pos_y - padding)
- x1 = pos_x + text_width + mouse_size * MOUSE_RATIO * 1.3 + padding
- y1 = pos_y + max(mouse_size, font_size * row_count) + padding
+ blf.size(0, sc.screencast_keys_font_size, 72)
+ box_width, box_height = sc.screencast_keys_box_width,0
+ final = 0
+ row_count = 0
+
+ for i in range(len(self.key)):
+ label_time = time.time() - self.time[i]
+ if label_time < 4.5: # only display key-presses of last 4 seconds
+ box_width, box_height = getBoundingBox(box_width, box_height, self.key[i])
+ row_count += 1
+ final = i + 1
+ else:
+ break
+
+ # Draw border
+ box_color_r, box_color_g, box_color_b, box_color_alpha = sc.screencast_keys_box_color
+
+ if box_draw:
+ padding_x = 16
+ padding_y = 12
+ x0 = max(0, pos_x - padding_x)
+ y0 = max(0, pos_y - padding_y)
+ x1 = pos_x + box_width + mouse_size * MOUSE_RATIO * 1.1 + padding_x
+ y1 = pos_y + max(mouse_size, font_size * row_count) + padding_y
positions = [[x0, y0], [x0, y1], [x1, y1], [x1, y0]]
- settings = [[bgl.GL_QUADS, min(0.2, alpha)], [bgl.GL_LINE_LOOP, alpha]]
+ settings = [[bgl.GL_QUADS, min(0.2, box_color_alpha)], [bgl.GL_LINE_LOOP, min(0.4,box_color_alpha)]]
for mode, box_alpha in settings:
+ if sc.screencast_keys_box_hide:
+ label_time = time.time() - self.time[i]
bgl.glEnable(bgl.GL_BLEND)
bgl.glBegin(mode)
- bgl.glColor4f(r, g, b, box_alpha)
+ bgl.glColor4f(box_color_r, box_color_g, box_color_b, box_color_alpha )
for v1, v2 in positions:
bgl.glVertex2f(v1, v2)
bgl.glEnd()
+ if sc.screencast_keys_show_operator:
+ draw_last_operator(context, pos_x, pos_y)
+
+def draw_last_operator(context, pos_x, pos_y):
+
+ wm = context.window_manager
+ sc = context.scene
+ font_color_r, font_color_g, font_color_b, font_color_alpha = sc.screencast_keys_text_color
+ pos_x, pos_y = getDisplayLocation(context)
+
+ last_operator = wm.operators[-1].bl_label
+
+ blf.enable(0, blf.SHADOW)
+ blf.shadow_offset(0, 1, -1)
+ blf.shadow(0, 5, 0.0, 0.0, 0.0, 0.8)
+ blf.size(0, sc.screencast_keys_font_size, 36)
+ blf.position(0, pos_x - 14, pos_y - 30, 0)
+ bgl.glColor4f(font_color_r, font_color_g, font_color_b, font_color_alpha * 0.8)
+ blf.draw(0, "Last: %s" % (last_operator))
+ blf.disable(0, blf.SHADOW)
+
def draw_mouse(context, shape, style, alpha):
# shape and position
sc = context.scene
mouse_size = sc.screencast_keys_mouse_size
font_size = sc.screencast_keys_font_size
- link = sc.screencast_keys_link
+ box_draw = sc.screencast_keys_box_draw
pos_x, pos_y = getDisplayLocation(context)
- if link:
+ if box_draw:
offset_x = pos_x
else:
offset_x = context.region.width - pos_x - (mouse_size * MOUSE_RATIO)
@@ -177,7 +241,7 @@ def draw_mouse(context, shape, style, alpha):
bgl.glTranslatef(offset_x, offset_y, 0)
# color
- r, g, b = sc.screencast_keys_color
+ r, g, b, a = sc.screencast_keys_text_color
bgl.glEnable(bgl.GL_BLEND)
bgl.glColor4f(r, g, b, alpha)
@@ -226,18 +290,17 @@ def draw_mouse(context, shape, style, alpha):
bgl.glTranslatef(-offset_x, -offset_y, 0)
-
# hardcoded data to draw the graphical represenation of the mouse
def get_shape_data(shape):
data = []
if shape == "mouse":
- data = [[[0.264, 0.002, 0.0],
+ data = [[[0.404, 0.032, 0.0],
[0.096, 0.002, 0.0],
- [0.059, 0.226, 0.0],
- [0.04, 0.313, 0.0]],
- [[0.04, 0.313, 0.0],
- [-0.015, 0.565, 0.0],
- [-0.005, 0.664, 0.0],
+ [0.059, 0.126, 0.0],
+ [0.04, 0.213, 0.0]],
+ [[0.04, 0.213, 0.0],
+ [-0.015, 0.465, 0.0],
+ [-0.005, 0.564, 0.0],
[0.032, 0.87, 0.0]],
[[0.032, 0.87, 0.0],
[0.05, 0.973, 0.0],
@@ -248,13 +311,13 @@ def get_shape_data(shape):
[0.478, 0.973, 0.0],
[0.497, 0.87, 0.0]],
[[0.497, 0.87, 0.0],
- [0.533, 0.664, 0.0],
- [0.544, 0.565, 0.0],
- [0.489, 0.313, 0.0]],
- [[0.489, 0.313, 0.0],
- [0.47, 0.226, 0.0],
+ [0.533, 0.564, 0.0],
+ [0.554, 0.465, 0.0],
+ [0.499, 0.213, 0.0]],
+ [[0.499, 0.213, 0.0],
+ [0.490, 0.126, 0.0],
[0.432, 0.002, 0.0],
- [0.264, 0.002, 0.0]]]
+ [0.404, 0.032, 0.0]]]
elif shape == "left_button":
data = [[[0.154, 0.763, 0.0],
[0.126, 0.755, 0.0],
@@ -495,9 +558,11 @@ class ScreencastKeysStatus(bpy.types.Operator):
self.time = []
self.mouse = []
self.mouse_time = []
+ self._handle = context.region.callback_add(draw_callback_px_box,
+ (self, context), 'POST_PIXEL')
self._handle = context.region.callback_add(draw_callback_px,
(self, context), 'POST_PIXEL')
- self._timer = context.window_manager.event_timer_add(0.05,
+ self._timer = context.window_manager.event_timer_add(0.025,
context.window)
return {'RUNNING_MODAL'}
else:
@@ -519,44 +584,67 @@ def init_properties():
wm = bpy.types.WindowManager
scene.screencast_keys_pos_x = bpy.props.IntProperty(
- name="Pos X",
- description="Margin on the x axis",
- default=5,
+ name="Position X",
+ description="Margin on the X axis",
+ default=3,
min=0,
max=100)
scene.screencast_keys_pos_y = bpy.props.IntProperty(
- name="Pos Y",
- description="Margin on the y axis",
- default=10,
+ name="Position Y",
+ description="Margin on the Y axis",
+ default=9,
min=0,
max=100)
scene.screencast_keys_font_size = bpy.props.IntProperty(
- name="Font",
- description="Fontsize",
- default=20, min=10, max=150)
+ name="Text Size",
+ description="Text size displayed on 3D View",
+ default=24, min=10, max=150)
scene.screencast_keys_mouse_size = bpy.props.IntProperty(
- name="Mouse",
- description="Mousesize",
- default=60, min=10, max=150)
- scene.screencast_keys_color = bpy.props.FloatVectorProperty(
- name="Color",
- description="Font color",
- default=(1.0, 1.0, 1.0),
+ name="Mouse Size",
+ description="Mouse size displayed on 3D View",
+ default=33, min=10, max=150)
+ scene.screencast_keys_text_color = bpy.props.FloatVectorProperty(
+ name="Text / Icon Color",
+ description="Color for the text and mouse icon",
+ default=(1.0, 1.0, 1.0, 1.0),
+ min=0.1,
+ max=1,
+ subtype='COLOR',
+ size=4)
+ scene.screencast_keys_box_color = bpy.props.FloatVectorProperty(
+ name="Box Color",
+ description="Box color",
+ default=(0.0, 0.0, 0.0, 0.3),
min=0,
max=1,
- subtype='COLOR')
+ subtype='COLOR',
+ size=4)
+ scene.screencast_keys_box_width = bpy.props.IntProperty(
+ name="Box Width",
+ description="Box default width (resizes with text if needed)",
+ default=0,
+ min=0,
+ max=1024)
scene.screencast_keys_mouse = bpy.props.EnumProperty(
- items=(("none", "None", "Don't display mouse events"),
- ("icon", "Icon", "Display graphical represenation of "\
+ items=(("none", "No Mouse", "Don't display mouse events"),
+ ("icon", "Icon", "Display graphical representation of "\
"the mouse"),
("text", "Text", "Display mouse events as text lines")),
name="Mouse display",
description="Display mouse events",
- default='text')
- scene.screencast_keys_link = bpy.props.BoolProperty(
- name="Group Mouse & Text",
- description = "Link mouse to text",
+ default='icon')
+ scene.screencast_keys_box_draw = bpy.props.BoolProperty(
+ name="Draw Box",
+ description = "Merge mouse & text inside a box",
+ default = True)
+ scene.screencast_keys_box_hide = bpy.props.BoolProperty(
+ name="Hide Box",
+ description = "Hide the box when no key is pressed",
default = False)
+ scene.screencast_keys_show_operator = bpy.props.BoolProperty(
+ name="Display Last Operator",
+ description = "Display the last operator used",
+ default = True)
# Runstate initially always set to False
# note: it is not stored in the Scene, but in window manager:
@@ -567,7 +655,10 @@ def init_properties():
def clear_properties():
props = ["screencast_keys_keys", "screencast_keys_mouse",
"screencast_keys_font_size", "screencast_keys_mouse_size",
- "screencast_keys_pos_x", "screencast_keys_pos_y", "screencast_keys_link"]
+ "screencast_keys_pos_x", "screencast_keys_pos_y",
+ "screencast_keys_box_draw", "screencast_keys_text_color",
+ "screencast_keys_box_color", "screencast_keys_box_hide",
+ "screencast_keys_box_width", "screencast_keys_show_operator" ]
for p in props:
if bpy.context.window_manager.get(p) != None:
del bpy.context.window_manager[p]
@@ -596,20 +687,36 @@ class OBJECT_PT_keys_status(bpy.types.Panel):
layout.operator("view3d.screencast_keys", text="Stop display",
icon='PAUSE')
- col = layout.column(align=True)
- row = col.row(align=True)
- row.prop(sc, "screencast_keys_pos_x")
- row.prop(sc, "screencast_keys_pos_y")
- row = col.row(align=True)
- row.prop(sc, "screencast_keys_font_size")
- row.prop(sc, "screencast_keys_mouse_size")
- row = col.row(align=True)
- row.prop(sc, "screencast_keys_mouse", text="Mouse")
- row = col.row(align=True)
- row.prop(sc, "screencast_keys_link")
-
- layout.prop(sc, "screencast_keys_color")
-
+ split = layout.split()
+
+ col = split.column()
+ sub = col.column(align=True)
+ sub.label(text="Size:")
+ sub.prop(sc, "screencast_keys_font_size", text="Text")
+ sub.prop(sc, "screencast_keys_mouse_size", text="Mouse")
+
+ col = split.column()
+ sub = col.column(align=True)
+ sub.label(text="Position:")
+ sub.prop(sc, "screencast_keys_pos_x", text="X")
+ sub.prop(sc, "screencast_keys_pos_y", text="Y")
+
+ row = layout.row(align=True)
+ row.prop(sc, "screencast_keys_text_color")
+
+ row = layout.row(align=True)
+ row.prop(sc, "screencast_keys_mouse", text="Show Mouse")
+
+ row = layout.row(align=True)
+ row.prop(sc, "screencast_keys_box_draw")
+ row = layout.row(align=True)
+ row.active = sc.screencast_keys_box_draw
+ row.prop(sc, "screencast_keys_box_color", text="")
+ row.prop(sc, "screencast_keys_box_hide", text="Hide")
+ row = layout.row(align=True)
+ row.prop(sc, "screencast_keys_box_width")
+ row = layout.row(align=True)
+ row.prop(sc, "screencast_keys_show_operator")
classes = [ScreencastKeysStatus,
OBJECT_PT_keys_status]