[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3439] trunk/py/scripts/addons/ space_view3d_screencast_keys.py: Screencast Keys Addon

Pablo Vazquez info at venomgfx.com.ar
Fri Jun 1 23:59:07 CEST 2012


Revision: 3439
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3439
Author:   venomgfx
Date:     2012-06-01 21:59:06 +0000 (Fri, 01 Jun 2012)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/py/scripts/addons/space_view3d_screencast_keys.py

Modified: trunk/py/scripts/addons/space_view3d_screencast_keys.py
===================================================================
--- trunk/py/scripts/addons/space_view3d_screencast_keys.py	2012-06-01 21:29:57 UTC (rev 3438)
+++ trunk/py/scripts/addons/space_view3d_screencast_keys.py	2012-06-01 21:59:06 UTC (rev 3439)
@@ -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 @@
                    'func=detail&aid=21612',
     'category': '3D View'}
 
-
 import bgl
 import blf
 import bpy
@@ -72,19 +71,23 @@
 
     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 @@
     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 @@
         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 @@
     # ==========================================
     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 @@
     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 @@
     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 @@
 
     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 @@
             [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 @@
                 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 @@
     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(

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list