Вы находитесь на странице: 1из 1

# ##### BEGIN GPL LICENSE BLOCK ##### # ##### BEGIN GPL LICENSE BLOCK #####

# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation, # along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
# ##### END GPL LICENSE BLOCK ##### # ##### END GPL LICENSE BLOCK #####

# <pep8 compliant> # <pep8 compliant>

bl_info = { bl_info = {
"name": "Screencast Keys", "name": "Screencast Keys",
"author": "Paulo Gomes, Bart Crouch, John E. Herrenyo, Gaia Clary, Pablo Vazquez", "author": "Paulo Gomes, Bart Crouch, John E. Herrenyo, Gaia Clary, Pablo Vazquez",
"version": (1, 7), "version": (1, 7),
"blender": (2, 66, 0), "blender": (2, 66, 0),
"location": "3D View > Properties Panel > Screencast Keys", "location": "3D View > Properties Panel > Screencast Keys",
"warning": "", "warning": "",
"description": "Display keys pressed in the 3D View, " "description": "Display keys pressed in the 3D View, "
"useful for screencasts.", "useful for screencasts.",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/" "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/"
"Py/Scripts/3D_interaction/Screencast_Key_Status_Tool", "Py/Scripts/3D_interaction/Screencast_Key_Status_Tool",
"tracker_url": "http://projects.blender.org/tracker/index.php?" "tracker_url": "http://projects.blender.org/tracker/index.php?"
"func=detail&aid=21612", "func=detail&aid=21612",
"category": "3D View"} "category": "3D View"}

import bgl import bgl


import blf import blf
import bpy import bpy
import time import time
import datetime import datetime

MOUSE_RATIO = 0.535 MOUSE_RATIO = 0.535

def getDisplayLocation(context): def getDisplayLocation(context):


scene = context.scene scene = context.scene
mouse_size = scene.screencast_keys_mouse_size mouse_size = scene.screencast_keys_mouse_size

pos_x = int( (context.region.width - mouse_size * MOUSE_RATIO) * \ pos_x = int( (context.region.width - mouse_size * MOUSE_RATIO) * \
scene.screencast_keys_pos_x / 100) scene.screencast_keys_pos_x / 100)
pos_y = int( (context.region.height - mouse_size) * pos_y = int( (context.region.height - mouse_size) *
scene.screencast_keys_pos_y / 100) scene.screencast_keys_pos_y / 100)

return(pos_x, pos_y) return(pos_x, pos_y)

def getBoundingBox(current_width, current_height, new_text): def getBoundingBox(current_width, current_height, new_text):


w,h = blf.dimensions(0,new_text) w,h = blf.dimensions(0,new_text)
if w > current_width: if w > current_width:
current_width = w current_width = w
current_height += h current_height += h

return(current_width, current_height) return(current_width, current_height)

def draw_callback_px_text(self, context): def draw_callback_px_text(self, context):


wm = context.window_manager wm = context.window_manager
sc = context.scene sc = context.scene
if not wm.screencast_keys_keys: if not wm.screencast_keys_keys:
return return

font_size = sc.screencast_keys_font_size font_size = sc.screencast_keys_font_size


mouse_size = sc.screencast_keys_mouse_size mouse_size = sc.screencast_keys_mouse_size
box_draw = sc.screencast_keys_box_draw box_draw = sc.screencast_keys_box_draw
pos_x, pos_y = getDisplayLocation(context) pos_x, pos_y = getDisplayLocation(context)
label_time_max = sc.screencast_keys_fade_time label_time_max = sc.screencast_keys_fade_time

# draw text in the 3D View # draw text in the 3D View


blf.size(0, sc.screencast_keys_font_size, 72) blf.size(0, sc.screencast_keys_font_size, 72)
blf.enable(0, blf.SHADOW) blf.enable(0, blf.SHADOW)
blf.shadow_offset(0, 1, -1) blf.shadow_offset(0, 1, -1)
blf.shadow(0, 5, 0.0, 0.0, 0.0, 0.8) 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 font_color_r, font_color_g, font_color_b, font_color_alpha = sc.screencast_keys_text_color
final = 0 final = 0
row_count = len(self.key) row_count = len(self.key)

keypos_x = pos_x keypos_x = pos_x

if sc.screencast_keys_mouse_position == 'left': if sc.screencast_keys_mouse_position == 'left':


keypos_x += mouse_size * MOUSE_RATIO * 1.7 keypos_x += mouse_size * MOUSE_RATIO * 1.7
if sc.screencast_keys_mouse != 'icon': if sc.screencast_keys_mouse != 'icon':
keypos_x -= mouse_size * MOUSE_RATIO keypos_x -= mouse_size * MOUSE_RATIO
if sc.screencast_keys_mouse_position == 'right' and sc.screencast_keys_mouse != 'icon': if sc.screencast_keys_mouse_position == 'right' and sc.screencast_keys_mouse != 'icon':
keypos_x = pos_x keypos_x = pos_x

shift = 0 shift = 0

# we want to make sure we can shift vertically the text if the mouse is big, # we want to make sure we can shift vertically the text if the mouse is big,
# but don't care if aligned to right # but don't care if aligned to right
if mouse_size > font_size*row_count and not sc.screencast_keys_mouse_position == 'right': if mouse_size > font_size*row_count and not sc.screencast_keys_mouse_position == 'right':
shift = (mouse_size - font_size*row_count) / 2 shift = (mouse_size - font_size*row_count) / 2

text_width, text_height = 0,0 text_width, text_height = 0,0


row_count = 0 row_count = 0
alpha = 1.0 alpha = 1.0

for i in range(len(self.key)): for i in range(len(self.key)):


label_time = time.time() - self.time[i] label_time = time.time() - self.time[i]
if label_time < label_time_max: # only display key-presses of last 2 seconds if label_time < label_time_max: # only display key-presses of last 2 seconds
if label_time > (label_time_max / 1.2): if label_time > (label_time_max / 1.2):
blf.blur(0, 1) blf.blur(0, 1)
if label_time > (label_time_max / 1.1): if label_time > (label_time_max / 1.1):
blf.blur(0, 3) blf.blur(0, 3)
keypos_y = pos_y + shift + font_size*(i+0.1) keypos_y = pos_y + shift + font_size*(i+0.1)

blf.position(0, keypos_x, keypos_y , 0) blf.position(0, keypos_x, keypos_y , 0)


alpha = min(1.0, max(0.0, label_time_max * (label_time_max - label_time))) alpha = min(1.0, max(0.0, label_time_max * (label_time_max - label_time)))
bgl.glColor4f(font_color_r, font_color_g, font_color_b, font_color_alpha * alpha) bgl.glColor4f(font_color_r, font_color_g, font_color_b, font_color_alpha * alpha)

Вам также может понравиться