def beamer_mouse_callback(self, event, x, y, flags, param):

        if self.program_stage.current_stage == ProgramStage.INTERNAL_MODE \
                or self.program_stage.current_stage == ProgramStage.EXTERNAL_MODE:

            if event == cv2.EVENT_LBUTTONDOWN or event == cv2.EVENT_RBUTTONDOWN:

                color = BrickColor.BLUE_BRICK
                if event == cv2.EVENT_RBUTTONDOWN:
                    color = BrickColor.RED_BRICK

                # create brick on mouse position
                mouse_brick = Extent.remap_brick(Brick(x, y, Token(BrickShape.SQUARE_BRICK, color)),
                                                 
                    self.extent_tracker.beamer, self.extent_tracker.board
                )

                # check for nearby virtual bricks
                virtual_brick = self.tracker.check_min_distance(mouse_brick, self.tracker.virtual_bricks)

                if virtual_brick:
                    # if mouse brick is on top of other virtual brick, remove that brick
                    self.tracker.remove_external_virtual_brick(virtual_brick)
                else:
                    # otherwise add the mouse brick
                    self.tracker.virtual_bricks.append(mouse_brick)

                # set mouse brick refreshed flag
                TableOutputStream.MOUSE_BRICKS_REFRESHED = True
Esempio n. 2
0
    def brick_would_land_on_ui(self, brick):

        brick_on_beamer = Extent.remap_brick(brick, self.extent_tracker.board,
                                             self.extent_tracker.beamer)
        return self.ui_root.brick_would_land_on_element(brick_on_beamer)
    def render_brick(self, brick, render_target, virtual=False):
        b = Extent.remap_brick(brick, self.extent_tracker.board, self.extent_tracker.beamer)
        pos = (int(b.centroid_x), int(b.centroid_y))
        icon = self.get_brick_icon(brick, virtual)

        ImageHandler.img_on_background(render_target, icon, pos)