import bpy import blf from pathlib import Path from .constants import PICKERS from .core.picker import Picker import json def draw_callback_view(): sp = bpy.context.space_data if not sp or not sp.tree_type == 'RigPickerTree': return ob = bpy.context.object if not ob or ob.type !='ARMATURE' or not ob.data.rig_picker.source: return if ob not in PICKERS: if 'picker' in ob.data.rig_picker: picker_datas = [s.to_dict() for s in ob.data.rig_picker['picker']] else: picker_path = Path(bpy.path.abspath(ob.data.rig_picker.source, library=ob.data.library)) if not picker_path.exists(): print(f'Picker path not exists: {picker_path.resolve()}') return print('Load picker from', picker_path.resolve()) picker_datas = json.loads(picker_path.read_text()) #shapes = [s.to_dict() for s in ob.data.rig_picker['shapes']] PICKERS[ob] = Picker(ob, shapes=picker_datas) picker = PICKERS.get(ob) picker.draw() def draw_callback_px(): sp = bpy.context.space_data if not sp.tree_type == 'RigPickerTree': return ob = bpy.context.object picker = PICKERS.get(ob) if not picker or not picker.tooltip: return text = picker.tooltip #print('Draw text', text) font_id = 0 #blf.dimensions(font_id, text) blf.enable(font_id, blf.SHADOW) #gpu.state.blend_set('ALPHA') # BLF drawing routine blf.position(font_id, picker.tooltip_mouse[0]-5, picker.tooltip_mouse[1]+5, 0) blf.size(font_id, 14) blf.color(font_id, 1, 1, 1, 1) blf.shadow(font_id , 5, 0.0, 0.0, 0.0, 1) blf.shadow_offset(font_id, 2, -2) blf.draw(font_id, text) blf.disable(font_id, blf.SHADOW) #gpu.state.blend_set('NONE') handle_view = None handle_pixel = None def register(): global handle_view global handle_pixel handle_view = bpy.types.SpaceNodeEditor.draw_handler_add(draw_callback_view, (), 'WINDOW', 'POST_VIEW') handle_pixel = bpy.types.SpaceNodeEditor.draw_handler_add(draw_callback_px, (), 'WINDOW', 'POST_PIXEL') def unregister(): global handle_view global handle_pixel bpy.types.SpaceNodeEditor.draw_handler_remove(handle_view, 'WINDOW') bpy.types.SpaceNodeEditor.draw_handler_remove(handle_pixel, 'WINDOW') handle_view = None handle_pixel = None