Last active
September 8, 2017 18:10
-
-
Save kilon/9babc56820ccf0dff3e107b9179f7d33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import bgl | |
import blf | |
from morpheas import * | |
# this class is defining the action performed when the button is clicked | |
clase AButtonAction: | |
def onLeftClick(morph): | |
print("the button has been clicked") | |
morph.texture = "buttonClickedIcon" | |
def draw_callback_px(self, context): | |
#draw the morphs | |
self.world.draw() | |
class ModalDrawOperator(bpy.types.Operator): | |
"""Draw a line with the mouse""" | |
bl_idname = "view3d.modal_operator" | |
bl_label = "Simple Modal View3D Operator" | |
def __init__(self): | |
self.world = None | |
# create button | |
self.abutton = ButtonMorph(texture="buttonIcon",onLeftClickAction = AButtonAction) | |
self.world.addMorph(self.abutton) | |
def modal(self, context, event): | |
context.area.tag_redraw() | |
self.world.onEvent(event) | |
if self.world.consumedEvent: | |
return {'RUNNING_MODAL'} | |
else: | |
return {'PASS THROUGH'} | |
def invoke(self, context, event): | |
# create the world | |
self.world = World() | |
if context.area.type == 'VIEW_3D': | |
# the arguments we pass the the callback | |
args = (self, context) | |
# Add the region OpenGL drawing callback | |
# draw in view space with 'POST_VIEW' and 'PRE_VIEW' | |
self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL') | |
self.mouse_path = [] | |
context.window_manager.modal_handler_add(self) | |
return {'RUNNING_MODAL'} | |
else: | |
self.report({'WARNING'}, "View3D not found, cannot run operator") | |
return {'CANCELLED'} | |
def register(): | |
bpy.utils.register_class(ModalDrawOperator) | |
def unregister(): | |
bpy.utils.unregister_class(ModalDrawOperator) | |
if __name__ == "__main__": | |
register() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment