At the moment, I'm drawing my text in the viewport with this modal operator:
_handle = None
def modal(self, context, event):
context.area.tag_redraw()
if not context.window_manager.show_text.enabled:
return {'CANCELLED'}
return {'PASS_THROUGH'}
@staticmethod
def handle_add(self, context):
VIEW3D_OT_ADH_display_text._handle = bpy.types.SpaceView3D.draw_handler_add(
draw_text_callback,
(self, context),
'WINDOW', 'POST_PIXEL')
@staticmethod
def handle_remove(context):
_handle = VIEW3D_OT_ADH_display_text._handle
if _handle != None:
bpy.types.SpaceView3D.draw_handler_remove(_handle, 'WINDOW')
VIEW3D_OT_ADH_display_text._handle = None
def invoke(self, context, event):
if context.window_manager.show_text.enabled == False:
context.window_manager.show_text.enabled = True
VIEW3D_OT_ADH_display_text.handle_add(self, context)
return {'RUNNING_MODAL'}
else:
context.window_manager.show_text.enabled = False
VIEW3D_OT_ADH_display_text.handle_remove(context)
return {'CANCELLED'}
return {'CANCELLED'}
Is it possible to draw my text without a modal operator, and update it with the following whenever my mesh is updated?
bpy.app.handlers.scene_update_post