Exemplo n.º 1
0
 def handle_add(self, context):
     if ShowHideViewportButton._handle is None:
         ShowHideViewportButton._handle = SpaceView3D.draw_handler_add(
             draw_callback_px, (self, context), 'WINDOW', 'POST_PIXEL')
         ShowHideViewportButton._handle3d = SpaceView3D.draw_handler_add(
             draw_callback_3d, (self, context), 'WINDOW', 'POST_VIEW')
         context.window_manager.measureit_arch_run_opengl = True
Exemplo n.º 2
0
    def ui_start(self):
        # # report something useful to user
        # bpy.context.area.header_text_set("Click & drag to add bricks (+'ALT' to remove). Press 'RETURN' to commit changes")
        # update dpi
        prefs = get_preferences(bpy.context)
        ui_scale = prefs.view.ui_scale
        pixel_size = prefs.system.pixel_size
        self.dpi = int(72 * ui_scale * pixel_size)

        # add callback handlers
        self.cb_pr_handle = SpaceView3D.draw_handler_add(
            self.draw_callback_preview, (bpy.context, ), 'WINDOW', 'PRE_VIEW')
        # self.cb_pv_handle = SpaceView3D.draw_handler_add(self.draw_callback_postview,  (bpy.context, ), 'WINDOW', 'POST_VIEW')
        # self.cb_pp_handle = SpaceView3D.draw_handler_add(self.draw_callback_postpixel, (bpy.context, ), 'WINDOW', 'POST_PIXEL')
        # darken other spaces
        self.spaces = [
            bpy.types.SpaceClipEditor,
            bpy.types.SpaceConsole,
            bpy.types.SpaceDopeSheetEditor,
            bpy.types.SpaceFileBrowser,
            bpy.types.SpaceGraphEditor,
            bpy.types.SpaceImageEditor,
            bpy.types.SpaceInfo,
            bpy.types.SpaceLogicEditor,
            bpy.types.SpaceNLA,
            bpy.types.SpaceNodeEditor,
            bpy.types.SpaceOutliner,
            bpy.types.SpaceProperties,
            bpy.types.SpaceSequenceEditor,
            bpy.types.SpaceTextEditor,
            bpy.types.SpaceTimeline,
            #bpy.types.SpaceUVEditor,       # <- does not exist?
            bpy.types.SpaceUserPreferences,
            #'SpaceView3D',                 # <- specially handled
        ]
        self.areas = ['WINDOW', 'HEADER']
        # ('WINDOW', 'HEADER', 'CHANNELS', 'TEMPORARY', 'UI', 'TOOLS', 'TOOL_PROPS', 'PREVIEW')
        # self.cb_pp_tools   = SpaceView3D.draw_handler_add(self.draw_callback_cover, (bpy.context, ), 'TOOLS',      'POST_PIXEL')
        self.cb_pp_props = SpaceView3D.draw_handler_add(
            self.draw_callback_cover, (bpy.context, ), 'TOOL_PROPS',
            'POST_PIXEL')
        self.cb_pp_ui = SpaceView3D.draw_handler_add(self.draw_callback_cover,
                                                     (bpy.context, ), 'UI',
                                                     'POST_PIXEL')
        self.cb_pp_header = SpaceView3D.draw_handler_add(
            self.draw_callback_cover, (bpy.context, ), 'HEADER', 'POST_PIXEL')
        self.cb_pp_all = [(s, a,
                           s.draw_handler_add(self.draw_callback_cover,
                                              (bpy.context, ), a,
                                              'POST_PIXEL'))
                          for s in self.spaces for a in self.areas]
        self.draw_preview()
        tag_redraw_areas()
Exemplo n.º 3
0
    def execute(self, context):
        def __get_speed(s, c):

            if not speedometre.obj:
                return

            current_pos = speedometre.obj.matrix_world.to_translation()
            distance = current_pos - speedometre.last_pos
            speedometre.last_pos = current_pos
            delta_time = speedometre.delta_time * abs(
                speedometre.current_frame - c.scene.frame_current)
            speedometre.current_frame = c.scene.frame_current
            speedometre.speed = 0.0 if delta_time == 0.0 else distance.length / delta_time

        # Get object
        a_selected = context.selected_objects
        if len(a_selected) == 0:
            raise RuntimeError('No object selected !')
        speedometre.obj = a_selected[0]
        speedometre.current_frame = context.scene.frame_current
        speedometre.delta_time = 1.0 / context.scene.render.fps

        # Set callback
        args = (self, context)
        speedometre.draw_handle = SpaceView3D.draw_handler_add(
            draw_callback_px, args, 'WINDOW', 'POST_PIXEL')

        handlers.frame_change_post.append(__get_speed)
        speedometre.callback.add(len(handlers.frame_change_post) - 1)

        return {'FINISHED'}
Exemplo n.º 4
0
    def __init__(self,
                 toolkit: BlenderToolkit,
                 look_and_feel: Optional[LookAndFeel] = None,
                 font_options: Optional[FontOptions] = None,
                 window_manager: Optional[WindowManager] = None,
                 error_handler: Optional[ErrorHandler] = None) -> None:
        super().__init__(toolkit, look_and_feel, font_options, window_manager,
                         error_handler)

        resolution = Dimension(bge.render.getWindowWidth(),
                               bge.render.getWindowHeight())

        self._resolution = BehaviorSubject(resolution)

        # noinspection PyTypeChecker
        self.window_size = self._resolution.pipe(ops.distinct_until_changed())

        self._shader = cast(GPUShader, gpu.shader.from_builtin("2D_IMAGE"))

        if use_viewport_render:
            # noinspection PyArgumentList
            self._draw_handler = SpaceView3D.draw_handler_add(
                self.process, (), "WINDOW", "POST_PIXEL")
        else:
            self._draw_handler = None

            bge.logic.getCurrentScene().post_draw.append(self.process)

        # noinspection PyTypeChecker
        self._texture = Buffer(bgl.GL_INT, 1)

        bgl.glGenTextures(1, self.texture)
Exemplo n.º 5
0
    def modal_start(self, context):
        '''
        get everything ready to be run as modal tool
        '''
        self.fsm_mode      = 'main'
        self.mode_pos      = (0, 0)
        self.cur_pos       = (0, 0)
        self.is_navigating = False
        self.cb_pv_handle  = SpaceView3D.draw_handler_add(self.draw_callback_postview, (context, ), 'WINDOW', 'POST_VIEW')
        self.cb_pp_handle  = SpaceView3D.draw_handler_add(self.draw_callback_postpixel, (context, ), 'WINDOW', 'POST_PIXEL')
        context.window_manager.modal_handler_add(self)
        #context.area.header_text_set(self.bl_label)

        self.footer = ''
        self.footer_last = ''
        
        self.start(context)
Exemplo n.º 6
0
    def modal_start(self, context):
        '''
        get everything ready to be run as modal tool
        '''
        self.fsm_mode      = 'main'
        self.mode_pos      = (0, 0)
        self.cur_pos       = (0, 0)
        self.is_navigating = False
        self.cb_pv_handle  = SpaceView3D.draw_handler_add(self.draw_callback_postview, (context, ), 'WINDOW', 'POST_VIEW')
        self.cb_pp_handle  = SpaceView3D.draw_handler_add(self.draw_callback_postpixel, (context, ), 'WINDOW', 'POST_PIXEL')
        context.window_manager.modal_handler_add(self)
        #context.area.header_text_set(self.bl_label)

        self.footer = ''
        self.footer_last = ''
        
        self.start(context)
    def handle_add(self, context):
        """Draw Pivot Point Graphic if not diaplayed.

        Takes: self, context
        Draws 7 element Pivot Point Graphic
        Return: Nothing."""
        if PDT_OT_ModalDrawOperator._handle is None:
            PDT_OT_ModalDrawOperator._handle = SpaceView3D.draw_handler_add(
                draw_callback_3d, (self, context), 'WINDOW', 'POST_VIEW')
            context.window_manager.pdt_run_opengl = True
Exemplo n.º 8
0
    def ui_start(self):
        # report something useful to user
        # bpy.context.area.header_text_set('RetopoFlow Mode')

        # add callback handlers
        self.cb_pr_handle = SpaceView3D.draw_handler_add(self.draw_callback_preview,   (bpy.context, ), 'WINDOW', 'PRE_VIEW')
        self.cb_pv_handle = SpaceView3D.draw_handler_add(self.draw_callback_postview,  (bpy.context, ), 'WINDOW', 'POST_VIEW')
        self.cb_pp_handle = SpaceView3D.draw_handler_add(self.draw_callback_postpixel, (bpy.context, ), 'WINDOW', 'POST_PIXEL')
        # darken other spaces
        self.spaces = [
            bpy.types.SpaceClipEditor,
            bpy.types.SpaceConsole,
            bpy.types.SpaceDopeSheetEditor,
            bpy.types.SpaceFileBrowser,
            bpy.types.SpaceGraphEditor,
            bpy.types.SpaceImageEditor,
            bpy.types.SpaceInfo,
            bpy.types.SpaceLogicEditor,
            bpy.types.SpaceNLA,
            bpy.types.SpaceNodeEditor,
            bpy.types.SpaceOutliner,
            bpy.types.SpaceProperties,
            bpy.types.SpaceSequenceEditor,
            bpy.types.SpaceTextEditor,
            bpy.types.SpaceTimeline,
            #bpy.types.SpaceUVEditor,       # <- does not exist?
            bpy.types.SpaceUserPreferences,
            #'SpaceView3D',                 # <- specially handled
            ]
        self.areas = [ 'WINDOW', 'HEADER' ]
        # ('WINDOW', 'HEADER', 'CHANNELS', 'TEMPORARY', 'UI', 'TOOLS', 'TOOL_PROPS', 'PREVIEW')
        self.cb_pp_tools   = SpaceView3D.draw_handler_add(self.draw_callback_cover, (bpy.context, ), 'TOOLS',      'POST_PIXEL')
        self.cb_pp_props   = SpaceView3D.draw_handler_add(self.draw_callback_cover, (bpy.context, ), 'TOOL_PROPS', 'POST_PIXEL')
        self.cb_pp_ui      = SpaceView3D.draw_handler_add(self.draw_callback_cover, (bpy.context, ), 'UI',         'POST_PIXEL')
        self.cb_pp_header  = SpaceView3D.draw_handler_add(self.draw_callback_cover, (bpy.context, ), 'HEADER',     'POST_PIXEL')
        self.cb_pp_all = [
            (s, a, s.draw_handler_add(self.draw_callback_cover, (bpy.context,), a, 'POST_PIXEL'))
            for s in self.spaces
            for a in self.areas
            ]
        self.tag_redraw_all()

        self.blender_op_context = {
            'window': bpy.context.window,
            'area': bpy.context.area,
            'space_data': bpy.context.space_data,
            'region': bpy.context.region,
        }

        self.maximize_area = False

        self.wrap_panels()

        self.rfctx.timer = bpy.context.window_manager.event_timer_add(1.0 / 120, bpy.context.window)

        self.drawing = Drawing.get_instance()
        self.drawing.set_cursor('CROSSHAIR')
Exemplo n.º 9
0
    def ui_start(self):
        # # report something useful to user
        # bpy.context.area.header_text_set("Click & drag to add bricks (+'ALT' to remove). Press 'RETURN' to commit changes")
        # update dpi
        ui_scale = get_preferences().view.ui_scale
        pixel_size = get_preferences().system.pixel_size
        self.dpi = int(72 * ui_scale * pixel_size)

        # add callback handlers
        self.cb_pr_handle = SpaceView3D.draw_handler_add(
            self.draw_callback_preview, (bpy.context, ), "WINDOW", "PRE_VIEW")
        # self.cb_pv_handle = SpaceView3D.draw_handler_add(self.draw_callback_postview,  (bpy.context, ), "WINDOW", "POST_VIEW")
        self.cb_pp_handle = SpaceView3D.draw_handler_add(
            self.draw_callback_postpixel, (bpy.context, ), "WINDOW",
            "POST_PIXEL")
        # darken other spaces
        self.spaces = [
            bpy.types.SpaceClipEditor,
            bpy.types.SpaceConsole,
            bpy.types.SpaceDopeSheetEditor,
            bpy.types.SpaceFileBrowser,
            bpy.types.SpaceGraphEditor,
            bpy.types.SpaceImageEditor,
            bpy.types.SpaceInfo,
            bpy.types.SpaceNLA,
            bpy.types.SpaceNodeEditor,
            bpy.types.SpaceOutliner,
            bpy.types.SpaceProperties,
            bpy.types.SpaceSequenceEditor,
            bpy.types.SpaceTextEditor,
            #"SpaceView3D",                 # <- specially handled
        ]
        if b280():
            self.spaces.append(bpy.types.SpacePreferences)
            self.spaces.append(bpy.types.SpaceUVEditor)
        else:
            self.spaces.append(bpy.types.SpaceUserPreferences)
            self.spaces.append(bpy.types.SpaceLogicEditor)
            self.spaces.append(bpy.types.SpaceTimeline)
        self.areas = ("WINDOW", "HEADER")
        if not b280():
            # ("WINDOW", "HEADER", "CHANNELS", "TEMPORARY", "UI", "TOOLS", "TOOL_PROPS", "PREVIEW")
            self.cb_pp_tools = SpaceView3D.draw_handler_add(
                self.draw_callback_cover, (bpy.context, ), "TOOLS",
                "POST_PIXEL")
            self.cb_pp_props = SpaceView3D.draw_handler_add(
                self.draw_callback_cover, (bpy.context, ), "TOOL_PROPS",
                "POST_PIXEL")
            self.cb_pp_ui = SpaceView3D.draw_handler_add(
                self.draw_callback_cover, (bpy.context, ), "UI", "POST_PIXEL")
            self.cb_pp_header = SpaceView3D.draw_handler_add(
                self.draw_callback_cover, (bpy.context, ), "HEADER",
                "POST_PIXEL")
            self.cb_pp_all = [(s, a,
                               s.draw_handler_add(self.draw_callback_cover,
                                                  (bpy.context, ), a,
                                                  "POST_PIXEL"))
                              for s in self.spaces for a in self.areas]
            self.draw_preview()
        tag_redraw_areas()
Exemplo n.º 10
0
    def handle_add(self, context):
        """Draw Pivot Point Graphic if not displayed.

        Draws 7 element Pivot Point Graphic

        Args:
            context: Blender bpy.context instance.

        Returns:
            Nothing.
        """

        if PDT_OT_ModalDrawOperator._handle is None:
            PDT_OT_ModalDrawOperator._handle = SpaceView3D.draw_handler_add(
                drawCallback3D, (self, context), "WINDOW", "POST_VIEW")
            context.window_manager.pdt_run_opengl = True
Exemplo n.º 11
0
def register():
    import atexit
    # Make sure we only register the callback once
    atexit.unregister(exit.handler)
    atexit.register(exit.handler)

    bpy.app.handlers.load_post.append(load_post.handler)
    bpy.app.handlers.scene_update_post.append(scene_update_post.handler)

    # args: The arguments for the draw_callback function, in our case no arguments
    args = ()
    draw_3dview.handle = SpaceView3D.draw_handler_add(draw_3dview.handler,
                                                      args, 'WINDOW',
                                                      'POST_VIEW')

    args = ()
    draw_imageeditor.handle = SpaceImageEditor.draw_handler_add(
        draw_imageeditor.handler, args, 'WINDOW', 'POST_PIXEL')
Exemplo n.º 12
0
    def invoke(self, context, event):
        wm = context.window_manager
        shading = context.space_data.shading
        hdri = get_hdri(context)
        self.first_mouse_x = event.mouse_x
        if hdri == 'MAT_PREVIEW':
            self.first_value = shading.studiolight_rotate_z
        elif hdri == 'NODE':
            mapping_node_rotation = get_mapping_node_rotation(context)
            if mapping_node_rotation:
                initial_angle = mapping_node_rotation[Z]
                self.first_value = initial_angle

        args = (self, context)
        self._handle = SpaceView3D.draw_handler_add(draw_callback_px, args,
                                                    'WINDOW', 'POST_PIXEL')
        wm.modal_handler_add(self)
        return {'RUNNING_MODAL'}
Exemplo n.º 13
0
 def handle_add(self, context):
     if BRAND_DISPLAY._handler is None:
         BRAND_DISPLAY._handler = SpaceView3D.draw_handler_add(
             self.draw_callback, (context, ), "WINDOW", "POST_PIXEL")
         context.window_manager.brand_run_opengl = True
Exemplo n.º 14
0
 def _set_draw_handler(self):
     # Use memory address to get unique key used in draw handler
     if self.as_pointer() in draw_handler:
         return
     draw_handler[self.as_pointer()] = SpaceView3D.draw_handler_add(
         draw_distance_opengl, (self, bpy.context), 'WINDOW', 'POST_VIEW')
Exemplo n.º 15
0
 def install(cls, context):
     if cls.installed:
         cls.uninstall()
     handler = cls()
     cls.installed = SpaceView3D.draw_handler_add(handler, (context, ),
                                                  "WINDOW", "POST_PIXEL")
Exemplo n.º 16
0
 def handle_add(self, context):
     if ARCHIMESH_OT_HintDisplay._handle is None:
         ARCHIMESH_OT_HintDisplay._handle = SpaceView3D.draw_handler_add(draw_callback_px, (self, context),
                                                                                   'WINDOW',
                                                                                   'POST_PIXEL')
         context.window_manager.archimesh_run_opengl = True
Exemplo n.º 17
0
    def ui_start(self):
        # report something useful to user
        # bpy.context.area.header_text_set('RetopoFlow Mode')

        # add callback handlers
        self.cb_pr_handle = SpaceView3D.draw_handler_add(
            self.draw_callback_preview, (bpy.context, ), 'WINDOW', 'PRE_VIEW')
        self.cb_pv_handle = SpaceView3D.draw_handler_add(
            self.draw_callback_postview, (bpy.context, ), 'WINDOW',
            'POST_VIEW')
        self.cb_pp_handle = SpaceView3D.draw_handler_add(
            self.draw_callback_postpixel, (bpy.context, ), 'WINDOW',
            'POST_PIXEL')
        # darken other spaces
        self.spaces = [
            bpy.types.SpaceClipEditor,
            bpy.types.SpaceConsole,
            bpy.types.SpaceDopeSheetEditor,
            bpy.types.SpaceFileBrowser,
            bpy.types.SpaceGraphEditor,
            bpy.types.SpaceImageEditor,
            bpy.types.SpaceInfo,
            bpy.types.SpaceLogicEditor,
            bpy.types.SpaceNLA,
            bpy.types.SpaceNodeEditor,
            bpy.types.SpaceOutliner,
            bpy.types.SpaceProperties,
            bpy.types.SpaceSequenceEditor,
            bpy.types.SpaceTextEditor,
            bpy.types.SpaceTimeline,
            #bpy.types.SpaceUVEditor,       # <- does not exist?
            bpy.types.SpaceUserPreferences,
            #'SpaceView3D',                 # <- specially handled
        ]
        self.areas = ['WINDOW', 'HEADER']
        # ('WINDOW', 'HEADER', 'CHANNELS', 'TEMPORARY', 'UI', 'TOOLS', 'TOOL_PROPS', 'PREVIEW')
        self.cb_pp_tools = SpaceView3D.draw_handler_add(
            self.draw_callback_cover, (bpy.context, ), 'TOOLS', 'POST_PIXEL')
        self.cb_pp_props = SpaceView3D.draw_handler_add(
            self.draw_callback_cover, (bpy.context, ), 'TOOL_PROPS',
            'POST_PIXEL')
        self.cb_pp_ui = SpaceView3D.draw_handler_add(self.draw_callback_cover,
                                                     (bpy.context, ), 'UI',
                                                     'POST_PIXEL')
        self.cb_pp_header = SpaceView3D.draw_handler_add(
            self.draw_callback_cover, (bpy.context, ), 'HEADER', 'POST_PIXEL')
        self.cb_pp_all = [(s, a,
                           s.draw_handler_add(self.draw_callback_cover,
                                              (bpy.context, ), a,
                                              'POST_PIXEL'))
                          for s in self.spaces for a in self.areas]
        self.tag_redraw_all()

        self.blender_op_context = {
            'window': bpy.context.window,
            'area': bpy.context.area,
            'space_data': bpy.context.space_data,
            'region': bpy.context.region,
        }

        self.maximize_area = False

        self.wrap_panels()

        self.rfctx.timer = bpy.context.window_manager.event_timer_add(
            1.0 / 120, bpy.context.window)

        self.drawing = Drawing.get_instance()
        self.drawing.set_cursor('CROSSHAIR')
Exemplo n.º 18
0
 def handle_add(self, context):
     if AchmRunHintDisplayButton._handle is None:
         AchmRunHintDisplayButton._handle = SpaceView3D.draw_handler_add(
             draw_callback_px, (self, context), 'WINDOW', 'POST_PIXEL')
         context.window_manager.archimesh_run_opengl = True