6
def draw_callback_px(self, context):
7
print("mouse points", len(self.mouse_path))
9
font_id = 0 # XXX, need to find out how best to get this.
12
blf.position(font_id, 15, 30, 0)
13
blf.size(font_id, 20, 72)
14
blf.draw(font_id, "Hello Word " + str(len(self.mouse_path)))
16
# 50% alpha, 2 pixel width line
17
bgl.glEnable(bgl.GL_BLEND)
18
bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
21
bgl.glBegin(bgl.GL_LINE_STRIP)
22
for x, y in self.mouse_path:
27
# restore opengl defaults
29
bgl.glDisable(bgl.GL_BLEND)
30
bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
33
class ModalDrawOperator(bpy.types.Operator):
34
'''Draw a line with the mouse'''
35
bl_idname = "view3d.modal_operator"
36
bl_label = "Simple Modal View3D Operator"
38
def modal(self, context, event):
39
context.area.tag_redraw()
41
if event.type == 'MOUSEMOVE':
42
self.mouse_path.append((event.mouse_region_x, event.mouse_region_y))
44
elif event.type == 'LEFTMOUSE':
45
context.region.callback_remove(self._handle)
48
elif event.type in {'RIGHTMOUSE', 'ESC'}:
49
context.region.callback_remove(self._handle)
52
return {'RUNNING_MODAL'}
54
def invoke(self, context, event):
55
if context.area.type == 'VIEW_3D':
56
context.window_manager.modal_handler_add(self)
58
# Add the region OpenGL drawing callback
59
# draw in view space with 'POST_VIEW' and 'PRE_VIEW'
60
self._handle = context.region.callback_add(draw_callback_px, (self, context), 'POST_PIXEL')
64
return {'RUNNING_MODAL'}
66
self.report({'WARNING'}, "View3D not found, cannot run operator")
71
bpy.utils.register_class(ModalDrawOperator)
75
bpy.utils.unregister_class(ModalDrawOperator)
77
if __name__ == "__main__":