示例#1
0
 def __rotate_mask(self, px, py):
     # Rotates the entire mask around the grey axis during drags.
     cx, cy = self.get_center()
     x0, y0 = self.__drag_start_pos
     theta0 = math.atan2(x0-cx, y0-cy)
     theta = math.atan2(px-cx, py-cy)
     dntheta = (theta0 - theta) / (2*math.pi)
     while dntheta <= 0:
         dntheta += 1.0
     if self.__mask_predrag is None:
         self.__mask_predrag = []
         for shape in self.get_mask():
             shape_hcy = [HCYColor(color=c) for c in shape]
             self.__mask_predrag.append(shape_hcy)
     mgr = self.get_color_manager()
     newmask = []
     for shape in self.__mask_predrag:
         shape_rot = []
         for col in shape:
             col_r = HCYColor(color=col)
             h = mgr.distort_hue(col_r.h)
             h += dntheta
             h %= 1.0
             col_r.h = mgr.undistort_hue(h)
             shape_rot.append(col_r)
         newmask.append(shape_rot)
     self.set_mask(newmask)
示例#2
0
 def __rotate_mask(self, px, py):
     # Rotates the entire mask around the grey axis during drags.
     cx, cy = self.get_center()
     x0, y0 = self.__drag_start_pos
     theta0 = math.atan2(x0 - cx, y0 - cy)
     theta = math.atan2(px - cx, py - cy)
     dntheta = (theta0 - theta) / (2 * math.pi)
     while dntheta <= 0:
         dntheta += 1.0
     if self.__mask_predrag is None:
         self.__mask_predrag = []
         for shape in self.get_mask():
             shape_hcy = [HCYColor(color=c) for c in shape]
             self.__mask_predrag.append(shape_hcy)
     mgr = self.get_color_manager()
     newmask = []
     for shape in self.__mask_predrag:
         shape_rot = []
         for col in shape:
             col_r = HCYColor(color=col)
             h = mgr.distort_hue(col_r.h)
             h += dntheta
             h %= 1.0
             col_r.h = mgr.undistort_hue(h)
             shape_rot.append(col_r)
         newmask.append(shape_rot)
     self.set_mask(newmask)
示例#3
0
    def __motion_notify_cb(self, widget, event):
        """Button1 motion handler."""
        pos = event.x, event.y
        if (self.__button_down is not None) and self.__button_down == 1:
            if self.IS_DRAG_SOURCE:
                if not self.__drag_start_color:
                    return False
                start_pos = self.__drag_start_pos
                dx = pos[0] - start_pos[0]
                dy = pos[1] - start_pos[1]
                dist = math.hypot(dx, dy)
                if (dist > self._drag_threshold) and self.__drag_start_color:
                    logger.debug(
                        "Start drag (dist=%0.3f) with colour %r",
                        dist, self.__drag_start_color,
                    )
                    self.__drag_start_color = None
                    self.drag_begin_with_coordinates(
                        targets = Gtk.TargetList.new([
                            Gtk.TargetEntry.new(*e)
                            for e in self._DRAG_TARGETS
                        ]),
                        actions = Gdk.DragAction.MOVE | Gdk.DragAction.COPY,
                        button = 1,
                        event = event,
                        x = event.x,
                        y = event.y,
                    )
                    return True  # a drag was just started
            else:
                # Non-drag-source widgets update the color continuously while
                # the mouse button is held down and the pointer moved.
                color = self.get_color_at_position(event.x, event.y)
                self.set_managed_color(color)

        # Relative chroma/luma/hue bending with other buttons.
        elif ((self.__button_down is not None) and self.ALLOW_HCY_TWEAKING
              and self.__button_down > 1):
            if self.__drag_start_color is None:
                return False
            col = HCYColor(color=self.__drag_start_color)
            alloc = self.get_allocation()
            w, h = alloc.width, alloc.height
            size = max(w, h)
            ex, ey = event.x, event.y
            sx, sy = self.__drag_start_pos
            dx, dy = sx - ex, sy - ey

            # Pick a dimension to tweak
            if event.state & Gdk.ModifierType.SHIFT_MASK:
                bend = "chroma"
                dy = -dy
            elif event.state & Gdk.ModifierType.CONTROL_MASK:
                bend = "hue"
            else:
                bend = "luma"
                dy = -dy

            # Interpretation of dx depends on text direction
            if widget.get_direction() == Gtk.TextDirection.RTL:
                dx = -dx

            # Use the delta with the largest absolute value
            # FIXME: this has some jarring discontinities
            dd = dx if abs(dx) > abs(dy) else dy

            if bend == "chroma":
                c0 = clamp(col.c, 0., 1.)
                p = (c0 * size) - dd
                col.c = clamp(p / size, 0., 1.)
            elif bend == "hue":
                h0 = clamp(col.h, 0., 1.)
                p = (h0 * size) - dd
                h = p / size
                while h < 0:
                    h += 1.0
                col.h = h % 1.0
            else:   # luma
                y0 = clamp(col.y, 0., 1.)
                p = (y0 * size) - dd
                col.y = clamp(p / size, 0., 1.)
            self.set_managed_color(col)

        # Let other registered handlers run, normally.
        return False
示例#4
0
文件: adjbases.py 项目: emfol/mypaint
    def __motion_notify_cb(self, widget, event):
        """Button1 motion handler."""
        pos = event.x, event.y
        if self.__button_down == 1:
            if self.IS_DRAG_SOURCE:
                if not self.__drag_start_pos:
                    return False
                start_pos = self.__drag_start_pos
                dx = pos[0] - start_pos[0]
                dy = pos[1] - start_pos[1]
                dist = math.hypot(dx, dy)
                if (dist > self._drag_threshold) and self.__drag_start_color:
                    logger.debug(
                        "Start drag (dist=%0.3f) with colour %r",
                        dist, self.__drag_start_color,
                    )
                    self.__drag_start_color = None
                    self.drag_begin_with_coordinates(
                        targets = Gtk.TargetList.new([
                            Gtk.TargetEntry.new(*e)
                            for e in self._DRAG_TARGETS
                        ]),
                        actions = Gdk.DragAction.MOVE | Gdk.DragAction.COPY,
                        button = 1,
                        event = event,
                        x = event.x,
                        y = event.y,
                    )
                    return True  # a drag was just started
            else:
                # Non-drag-source widgets update the color continuously while
                # the mouse button is held down and the pointer moved.
                color = self.get_color_at_position(event.x, event.y)
                self.set_managed_color(color)

        # Relative chroma/luma/hue bending with other buttons.
        elif self.ALLOW_HCY_TWEAKING and self.__button_down > 1:
            if self.__drag_start_color is None:
                return False
            col = HCYColor(color=self.__drag_start_color)
            alloc = self.get_allocation()
            w, h = alloc.width, alloc.height
            size = max(w, h)
            ex, ey = event.x, event.y
            sx, sy = self.__drag_start_pos
            dx, dy = sx - ex, sy - ey

            # Pick a dimension to tweak
            if event.state & Gdk.ModifierType.SHIFT_MASK:
                bend = "chroma"
                dy = -dy
            elif event.state & Gdk.ModifierType.CONTROL_MASK:
                bend = "hue"
            else:
                bend = "luma"
                dy = -dy

            # Interpretation of dx depends on text direction
            if widget.get_direction() == Gtk.TextDirection.RTL:
                dx = -dx

            # Use the delta with the largest absolute value
            # FIXME: this has some jarring discontinities
            dd = dx if abs(dx) > abs(dy) else dy

            if bend == "chroma":
                c0 = clamp(col.c, 0., 1.)
                p = (c0 * size) - dd
                col.c = clamp(p / size, 0., 1.)
            elif bend == "hue":
                h0 = clamp(col.h, 0., 1.)
                p = (h0 * size) - dd
                h = p / size
                while h < 0:
                    h += 1.0
                col.h = h % 1.0
            else:   # luma
                y0 = clamp(col.y, 0., 1.)
                p = (y0 * size) - dd
                col.y = clamp(p / size, 0., 1.)
            self.set_managed_color(col)

        # Let other registered handlers run, normally.
        return False
示例#5
0
 def color_at_normalized_polar_pos(self, r, theta):
     col = HCYColor(color=self.get_managed_color())
     col.h = theta
     col.c = r
     return col
示例#6
0
 def color_at_normalized_polar_pos(self, r, theta):
     col = HCYColor(color=self.get_managed_color())
     col.h = theta
     col.c = r
     return col
示例#7
0
 def get_color_for_bar_amount(self, amt):
     col = HCYColor(color=self.get_managed_color())
     col.h = amt
     return col
示例#8
0
文件: sliders.py 项目: briend/mypaint
 def get_color_for_bar_amount(self, amt):
     col = HCYColor(color=self.get_managed_color())
     col.h = amt
     return col