[Bf-extensions-cvs] [ae73138] master: Game Property Visualizer: added back modal method for realtime feedback (Area.tag_draw).

CoDEmanX noreply at git.blender.org
Sun Feb 16 02:48:10 CET 2014


Commit: ae731385d48e578dfd55d78d1169992c0c3026d2
Author: CoDEmanX
Date:   Sun Feb 16 02:39:34 2014 +0100
https://developer.blender.org/rBACae731385d48e578dfd55d78d1169992c0c3026d2

Game Property Visualizer: added back modal method for realtime feedback (Area.tag_draw).

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

M	space_view3d_game_props_visualiser.py

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

diff --git a/space_view3d_game_props_visualiser.py b/space_view3d_game_props_visualiser.py
index 6493585..fed52cd 100644
--- a/space_view3d_game_props_visualiser.py
+++ b/space_view3d_game_props_visualiser.py
@@ -28,7 +28,8 @@ bl_info = {
     "description": "Display the game properties next to selected objects "
                    "in the 3d-view",
     "warning": "Script is returning errors",
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Game_Property_Visualiser",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+        "Scripts/3D_interaction/Game_Property_Visualiser",
     "tracker_url": "https://developer.blender.org/T22607",
     "category": "3D View"}
 
@@ -52,8 +53,8 @@ def calc_callback(self, context):
         return
 
     # get screen information
-    mid_x = context.region.width/2.0
-    mid_y = context.region.height/2.0
+    mid_x = context.region.width / 2.0
+    mid_y = context.region.height / 2.0
     width = context.region.width
     height = context.region.height
 
@@ -61,7 +62,7 @@ def calc_callback(self, context):
     view_mat = context.space_data.region_3d.perspective_matrix
 
     ob_mat = context.active_object.matrix_world
-    total_mat = view_mat*ob_mat
+    total_mat = view_mat * ob_mat
 
     # calculate location info
     texts = []
@@ -76,15 +77,15 @@ def calc_callback(self, context):
         for p in ob.game.properties:
             # d = {'data':p.name+':'+str(p.value)}
             # print (d)
-            locs.append(mathutils.Vector((0,0,0,1)))
+            locs.append(mathutils.Vector((0, 0, 0, 1)))
 
         for loc in locs:
             vec = total_mat * loc # order is important
             # dehomogenise
-            vec = mathutils.Vector((vec[0]/vec[3],vec[1]/vec[3],vec[2]/vec[3]))
-            x = int(mid_x + vec[0]*width/2.0)
-            y = int(mid_y + vec[1]*height/2.0)
-            texts+=[x, y]
+            vec = mathutils.Vector((vec[0]/vec[3], vec[1]/vec[3], vec[2]/vec[3]))
+            x = int(mid_x + vec[0]*width / 2.0)
+            y = int(mid_y + vec[1]*height / 2.0)
+            texts += [x, y]
 
     # store as ID property in mesh
     context.scene['GamePropsVisualizer'] = texts
@@ -110,21 +111,21 @@ def draw_callback(self, context):
     texts = context.scene['GamePropsVisualizer']
 
     # draw
-    i=0
+    i = 0
 
     blf.size(0, 12, 72)
 
 
-    bgl.glColor3f(1.0,1.0,1.0)
+    bgl.glColor3f(1.0, 1.0, 1.0)
     for ob in bpy.context.selected_objects:
         for pi,p in enumerate(ob.game.properties):
-            blf.position(0, texts[i], texts[i+1]-(pi+1)*14, 0)
+            blf.position(0, texts[i], texts[i+1] - (pi+1) * 14, 0)
             if p.type=='FLOAT':
-                t=p.name+':  '+ str('%g'% p.value)
+                t=p.name+':  '+ str('%g' % p.value)
             else:
                 t=p.name+':  '+ str(p.value)
             blf.draw(0, t)
-            i+=2
+            i += 2
 
 
 # operator
@@ -156,22 +157,33 @@ class GamePropertyVisualizer(bpy.types.Operator):
     def poll(cls, context):
         return context.mode != 'EDIT_MESH'
 
-    def execute(self, context):
+    def modal(self, context, event):
+        if not context.scene.display_game_properties:
+            return self.cancel(context)
+        context.area.tag_redraw()
+        return {'PASS_THROUGH'}
+
+    def invoke(self, context, event):
         if context.area.type == 'VIEW_3D':
             if not context.scene.display_game_properties:
                 # operator is called and not running
                 GamePropertyVisualizer.handle_add(self, context)
                 context.scene.display_game_properties = True
+                context.window_manager.modal_handler_add(self)
+                return {'RUNNING_MODAL'}
             else:
                 # operator is called again, stop displaying
-                GamePropertyVisualizer.handle_remove()
-                context.scene.display_game_properties = False
-            context.area.tag_redraw()
-            return {'FINISHED'}
+                return self.cancel(context)
         else:
             self.report({'WARNING'}, "View3D not found, can't run operator")
             return {'CANCELLED'}
 
+    def cancel(self, context):
+        GamePropertyVisualizer.handle_remove()
+        context.scene.display_game_properties = False
+        context.area.tag_redraw()
+        return {'FINISHED'}
+
 
 # defining the panel
 def menu_func(self, context):



More information about the Bf-extensions-cvs mailing list