コード例 #1
0
ファイル: colorselector.py プロジェクト: guozanhua/nuipaint
class MTColorSelector(MTWidget):
    def __init__(self, **kwargs):
        kwargs.setdefault("canvas", None)
        super(MTColorSelector, self).__init__(**kwargs)
        self.canvas = Observer.get("canvas")
        self.back_color = (0.0, 0.0, 0.0)
        self.parent_win = Observer.get("window")
        self.slider = MTCircularSlider(
            pos=(self.parent_win.width, 0),
            radius=223,
            thickness=20,
            padding=2,
            sweep_angle=85,
            slider_color=(1, 1, 1, 1),
            rotation=-87,
            min=0,
            max=2,
        )
        self.add_widget(self.slider)
        self.slider.set_initial_value(value=50)
        self.current_color = (0, 0, 0, 1)
        self.colorwheel = MTColorCircle(
            pos=(self.parent_win.width - 200, 0), size=(200, 200), win=self.parent_win, canvas=self.canvas
        )
        self.add_widget(self.colorwheel)

        @self.slider.event
        def on_value_change(value=self.slider.slider_color):
            value = rgb_to_hsv(self.slider.slider_color[0], self.slider.slider_color[1], self.slider.slider_color[2])
            h, s, v = value[0], value[1], value[2]
            if self.slider._value <= 1.0:
                s = self.slider._value
            else:
                v = 2 - self.slider._value
            Observer.get("canvas").set_brush_color(hsv_to_rgb(h, s, v))
            self.slider.slider_color = hsv_to_rgb(h, s, v)

    def draw(self):
        set_color(*self.back_color)
        with gx_matrix_identity:
            glTranslated(self.pos[0] + self.size[0], self.pos[1], 0)
            set_color(*self.style.get("bg-color"))
            drawSemiCircle(
                pos=self.pos, inner_radius=180, outer_radius=225, slices=32, loops=1, start_angle=-90, sweep_angle=90
            )
            # set_color(*self.back_color)
            # drawSemiCircle(pos=self.pos, inner_radius=205,outer_radius=220,slices=32,loops=1,start_angle=-23, sweep_angle=20)

    def set_slider_data(self, color, value):
        self.slider.slider_color = color
        self.slider.set_initial_value(value=value)
コード例 #2
0
ファイル: colorselector.py プロジェクト: guozanhua/nuipaint
    def __init__(self, **kwargs):
        kwargs.setdefault("canvas", None)
        super(MTColorSelector, self).__init__(**kwargs)
        self.canvas = Observer.get("canvas")
        self.back_color = (0.0, 0.0, 0.0)
        self.parent_win = Observer.get("window")
        self.slider = MTCircularSlider(
            pos=(self.parent_win.width, 0),
            radius=223,
            thickness=20,
            padding=2,
            sweep_angle=85,
            slider_color=(1, 1, 1, 1),
            rotation=-87,
            min=0,
            max=2,
        )
        self.add_widget(self.slider)
        self.slider.set_initial_value(value=50)
        self.current_color = (0, 0, 0, 1)
        self.colorwheel = MTColorCircle(
            pos=(self.parent_win.width - 200, 0), size=(200, 200), win=self.parent_win, canvas=self.canvas
        )
        self.add_widget(self.colorwheel)

        @self.slider.event
        def on_value_change(value=self.slider.slider_color):
            value = rgb_to_hsv(self.slider.slider_color[0], self.slider.slider_color[1], self.slider.slider_color[2])
            h, s, v = value[0], value[1], value[2]
            if self.slider._value <= 1.0:
                s = self.slider._value
            else:
                v = 2 - self.slider._value
            Observer.get("canvas").set_brush_color(hsv_to_rgb(h, s, v))
            self.slider.slider_color = hsv_to_rgb(h, s, v)