コード例 #1
0
    def render(self, origin: bimpy.Vec2, scale: float):
        line_col = im_col32(255, 255, 255)
        half_plane_col = im_col32(180, 238, 180, 50)

        line_col_highlight = im_col32(0, 69, 255)
        half_plane_col_highlight = im_col32(0, 140, 255, 50)

        if not self._lines:
            return

        for index, line in enumerate(self._lines):
            # print(line)
            if index == self._highlight_line_index:
                continue
            if index == self._waitting_draw_line_index:
                continue

            render_line(line, origin, scale, self._axis_limit, line_col,
                        half_plane_col)

        if self._highlight_line_index is not None and self._highlight_line_index != self._waitting_draw_line_index:
            render_line(
                self._lines[self._highlight_line_index],
                origin,
                scale,
                self._axis_limit,
                line_col_highlight,
                half_plane_col_highlight,
            )
コード例 #2
0
    def render(self, origin: bimpy.Vec2, scale: float):
        if not self.if_is_drawing():
            # print('not drawing')
            return

        if self._waitting_draw_line_abc is None or not self._waitting_draw_line_abc.is_valid(
        ):
            # print('line is None or not valid {}'.format(self._waitting_draw_line_abc))
            return

        render_line(
            self._waitting_draw_line_abc,
            origin,
            scale,
            100,
            im_col32(0, 69, 255),
            im_col32(0, 140, 255, 50),
        )
コード例 #3
0
    def render(self, origin: bimpy.Vec2, scale: float):
        if not self._convex_points:
            return

        points_on_canvas = [
            bimpy.Vec2(item.x * scale + origin.x, item.y * -scale + origin.y)
            for item in self._convex_points
        ]

        bimpy.add_convex_poly_filled(points_on_canvas, im_col32(50, 50, 50))
コード例 #4
0
    def render(self, origin: bimpy.Vec2, scale: float):
        points_on_canvas = [
            bimpy.Vec2(item.x * scale + origin.x,
                       item.y * -scale + origin.y)
            for item in self._convex_points
        ]

        for index in range(len(points_on_canvas) - 1):
            bimpy.add_line(
                points_on_canvas[index],
                points_on_canvas[index + 1],
                im_col32(211, 85, 186),
                1.0,
            )
        
        for index in range(len(points_on_canvas)):
            bimpy.add_circle_filled(
                points_on_canvas[index],
                2.0,
                im_col32(204, 50, 153),
                16,
            )
コード例 #5
0
ファイル: canvas.py プロジェクト: Solitry/convex_hull
    def render(self):
        bimpy.set_next_window_pos(bimpy.Vec2(40, 30), bimpy.Condition.FirstUseEver)
        bimpy.set_next_window_size(bimpy.Vec2(681, 700), bimpy.Condition.FirstUseEver)

        if not bimpy.begin('canvas window##canvas'):
            bimpy.end()
            return
        
        if not bimpy.begin_child('canvas##canvas', border=False):
            bimpy.end_child()
            return
        
        canvas_pos = bimpy.get_cursor_screen_pos()
        canvas_size = bimpy.get_content_region_avail()

        bimpy.invisible_button('canvas button##canvas', canvas_size)

        # mouse wheel scroll zoom
        if bimpy.is_item_hovered():
            mouse_wheel_delta = bimpy.get_mouse_wheel_delta()
            if mouse_wheel_delta < 0:
                self._canvas_scale_ratio = min(self._canvas_scale_ratio + self._canvas_scale_ratio_delta,
                                               self._canvas_scale_ratio_max)
            if mouse_wheel_delta > 0:
                self._canvas_scale_ratio = max(self._canvas_scale_ratio - self._canvas_scale_ratio_delta,
                                               self._canvas_scale_ratio_min)

        shift_ratio = 0.5 * (self._canvas_scale_ratio - 1) / self._canvas_scale_ratio
        origin = bimpy.Vec2(
            canvas_pos.x + canvas_size.x * shift_ratio,
            canvas_pos.y + canvas_size.y * (1 - shift_ratio)
        )
        scale = min(canvas_size.x, canvas_size.y) / self._canvas_scale_ratio

        mouse_pos = bimpy.get_mouse_pos()
        relative_pos = Point(
            (mouse_pos.x - origin.x) / scale,
            (mouse_pos.y - origin.y) / -scale,
        )

        # user line draw
        if self.user_line_draw_component.if_is_drawing():
            # print('is_drawing')
            if bimpy.is_item_hovered():
                if not self._drawing_start and bimpy.is_mouse_clicked(0, False):
                    self._drawing_start = True
                    self.user_line_draw_component.set_drawing_start_point(relative_pos)

            if self._drawing_start:
                mouse_down = bimpy.is_mouse_down(0)
                self._drawing_start = mouse_down
                self.user_line_draw_component.set_drawing_end_point(relative_pos, not mouse_down)
        
        # user convex draw
        if self.user_convex_draw_component.if_is_drawing():
            if bimpy.is_item_hovered():
                if bimpy.is_mouse_double_clicked(0):
                    self.user_convex_draw_component.set_user_done()
                elif bimpy.is_mouse_clicked(0, False):
                    self.user_convex_draw_component.set_user_add_point(relative_pos)                
                
                if bimpy.is_mouse_double_clicked(1):
                    self.user_convex_draw_component.set_user_cancel()
                elif bimpy.is_mouse_clicked(1, False):
                    self.user_convex_draw_component.set_user_pop_point()
        
        # draw background
        bimpy.add_rect_filled(
            canvas_pos,
            bimpy.Vec2(canvas_pos.x + canvas_size.x, canvas_size.y + canvas_size.y),
            im_col32(200, 200, 200),
        )

        bimpy.add_rect(
            bimpy.Vec2(origin.x, -scale + origin.y),
            bimpy.Vec2(scale + origin.x, origin.y),
            im_col32(0, 0, 0),
        )

        # draw others
        if self.user_convex_draw_component.if_is_drawing():
            self.user_convex_draw_component.render(origin, scale)
        else:
            self.convex_draw_component.render(origin, scale)

        self.lines_draw_component.render(origin, scale)

        self.user_line_draw_component.render(origin, scale)

        # show mouse pos
        if bimpy.is_mouse_pos_valid(None) and bimpy.is_item_hovered():
            bimpy.add_text_simple(
                bimpy.Vec2(canvas_pos.x + 15, canvas_pos.y + 10),
                im_col32(0, 0, 0),
                'x: {:.6f}  y: {:.6f}'.format(relative_pos.x, relative_pos.y),
            )
        
        # show drawing state
        if self.user_line_draw_component.if_is_drawing():
            bimpy.add_text_simple(
                bimpy.Vec2(canvas_pos.x + 15, canvas_pos.y + 30),
                im_col32(0, 0, 0),
                'drawing line {}'.format(self.user_line_draw_component.get_waitting_draw_line_index()),
            )

        bimpy.end_child()
        bimpy.end()