Example #1
0
 def draw_line(self, color, width, points, transient=False):
     if not transient:
         self.scratch.image.draw_line(color, width, points)
         bbox = make_bbox(points)
         w = int(round(width + 0.5))
         return (bbox[0] - w, bbox[1] - w, bbox[2] + w, bbox[3] + w)
     else:
         old_bbox = self.last_rect_bbox
         bbox = make_bbox(points)
         w = int(round(width + 0.5))
         bbox = (bbox[0] - w, bbox[1] - w, bbox[2] + w, bbox[3] + w)
         if old_bbox is not None:
             self.scratch.image.erase(old_bbox)
             total_bbox = combine_bbox(old_bbox, bbox)
         else:
             total_bbox = bbox
         self.scratch.image.draw_line(color, width, points)
         self.last_rect_bbox = bbox
         return total_bbox
Example #2
0
 def draw_selectbox(self, rect):
     x, y, w, h = rect
     x, y, x1, y1 = utils.make_bbox((x, y, x+w, y+h))
     w, h = x1-x, y1-y
     if x+h<self.get_xlim() and y+h<self.get_ylim():
         startx, starty = self.get_img_coord(x, y)
         endx, endy = self.get_img_coord(x+w, y+h)
         px0, py0, px1, py1 = self.get_paper_bbox((startx-1, starty-1, endx+1, endy+1))
         self.invalidate_bbox(utils.combine_bbox(self.selectionrect, (px0, py0, px1, py1)))
         print "setting selectinrect", (px0, py0, px1, py1)
         self.selectionrect = (px0, py0, px1, py1)
Example #3
0
 def draw_ellipse(self, color, bbox, fill=None, transient=False):
     if not transient:
         old_bbox = self.last_rect_bbox
     else:
         old_bbox = self.last_rect_bbox
         bbox = make_bbox(bbox)
         new_bbox = (bbox[0], bbox[1], bbox[2] + 1, bbox[3] + 1)
         if old_bbox is not None:
             self.scratch.image.erase(old_bbox)
             total_bbox = combine_bbox(old_bbox, new_bbox)
         else:
             total_bbox = new_bbox
         self.scratch.image.draw_ellipse(color, bbox, fill)
         self.last_rect_bbox = new_bbox
         return total_bbox
Example #4
0
    def do_button_release_event(self, e):
        print "button release!"
        if e.button in (1,3):
            if self.tool == "brush":
                #print "Getting new brush..."
                bbox = utils.make_bbox((self.lx, self.ly, int(e.x), int(e.y)))

                tmp = self.get_img_bbox(bbox)
                img_bbox = (tmp[0], tmp[1], tmp[2]+1, tmp[3]+1)
                tmp = self.stack.get_layer().image.crop(img_bbox)
                self.brush = PyntBrush(data=tmp, transp_color=self.stack.get_layer().image.transp_color)
                #self.brush = PyntBrush(data=tmp, transp_color=self.stack.palette.bgcolor)

                #self.custom_brush = True
                #bbox = self.stack.clear_scratch()

                self.emit("set-tool", "points")
                #self.set_tool("points")

                bbox = self.get_img_bbox(self.selectionrect)
                self.selectionrect = None


            elif self.tool == "floodfill":

                if self.stack.mode in ("draw_fg", "erase"):
                    color = self.stack.palette.fgcolor
                elif self.stack.mode == "draw_bg":
                    color = self.stack.palette.bgcolor

                self.floodfill(color, (int(e.x), int(e.y)))
                bbox = self.stack.apply_scratch()
            else:
                bbox = self.stack.apply_scratch()

            #self.lx = self.ly = None
            self.stack.mode = None
            #bbox=self.stack.clear_scratch()
            if bbox is not None:
                self.invalidate_img_bbox(bbox)