示例#1
0
    def on_touch_down(self, touch): #defines the starting point of a new line
        if self.ui.btnc.state == 'down':
            eraser = Drawable(Rectangle, size = self.zoom, pos=(touch.x, touch.y), color = (1, 1, 1, 0.5))
            eraser.snap(list(eraser.item.pos), self.zoom, self.lat, self.longit)
            eraser.draw(self.canvas)
            check_erase(eraser, self.lines, self.zoom, self.lat, self.longit)
            self.refresh_screen()
        if self.ui.btnline.state == 'down':
            self.coord = [[touch.x, touch.y]]

        if self.ui.btndraw.state == 'down':
            self.polyline = Polyline(self.color)
        else: self.coord = []
        self.old_x, self.old_y = touch.x, touch.y
示例#2
0
 def on_touch_up(self, touch):
     if self.x == 0 or self.y == 0 or [0, 0] in self.coord:
         self.x, self.y = touch.x, touch.y #sets the start point of line
     if self.coord and self.ui.btnline.state == 'down' and self.straight_type == 'single' and touch.y < height-height/12:
         self.coord.append([touch.x, touch.y]) #defines end point of new line
         line = Drawable(Line, color = self.color, points = (self.coord[0][0], self.coord[0][1], self.coord[1][0], self.coord[1][1]), width = 2)
         if not line.snap(self.coord, self.zoom, self.lat, self.longit):
             return
         if not line in self.lines:
             self.lines.append(line)
         self.coord = []
         self.refresh_screen()
     if self.ui.btndraw.state == 'down' and self.polyline != None:
         self.lines.append(self.polyline)
         self.polyline = None
         self.coord = []
         self.drawn_lines = []
         self.refresh_screen()
     self.old_x, self.old_y = touch.x, touch.y
     self.x = self.y = 0 # resets variables for finger lines
示例#3
0
 def on_touch_move(self, touch):
     if self.x == 0 or self.y == 0 or [0, 0] in self.coord:
         self.x, self.y = touch.x, touch.y #sets the start point of line
     if self.ui.btnc.state == 'down':
         self.refresh_screen()
         eraser = Drawable(Rectangle, size = self.zoom, pos=(touch.x, touch.y), color = (1, 1, 1, 0.5))
         eraser.snap(list(eraser.item.pos), self.zoom, self.lat, self.longit)
         eraser.draw(self.canvas)
         check_erase(eraser, self.lines, self.zoom, self.lat, self.longit)
     if self.ui.btnline.state == 'down' or self.ui.btndraw.state == 'down' and touch.y < height-height/12:
         if not self.coord:
             self.coord = [[touch.x, touch.y]] #used as a start point if finger just entered screen
         self.refresh_screen()
         self.canvas.add(Color(*self.color))
         coord_temp = [[self.x, self.y], [touch.x, touch.y]]
         if self.straight_type == 'single' and self.ui.btnline.state == 'down':
             coord_temp[0] = self.coord[0]
             line = Drawable(Line, color = self.color, points = (coord_temp[0][0], coord_temp[0][1], coord_temp[1][0], coord_temp[1][1]), width = 1)
             line.snap(coord_temp, self.zoom, self.lat, self.longit)
             line.draw(self.canvas)
         elif self.ui.btnline.state == 'down':
             if self.x == 0 or self.y == 0 or [0, 0] in self.coord:
                 self.x, self.y = touch.x, touch.y #sets the start point of line
                 return
             line = Drawable(Line, color = self.color, points = (coord_temp[0][0], coord_temp[0][1], coord_temp[1][0], coord_temp[1][1]), width = 2)
             if not line.snap(coord_temp, self.zoom, self.lat, self.longit):
                 return
             if not line in self.lines:
                 self.lines.append(line)
         if self.ui.btndraw.state == 'down' and self.polyline != None:
             self.polyline.add_line(coord_temp[0][0], coord_temp[0][1], coord_temp[1][0], coord_temp[1][1])
             self.drawn_lines.append([Line(points = (coord_temp[0][0], coord_temp[0][1], coord_temp[1][0], coord_temp[1][1])), self.color])
         self.x, self.y = touch.x, touch.y #updates points
          
     if self.ui.btnm.state == 'down':
         if touch.x > width - height/12 or touch.y > height-height/12:
             return
         movex = touch.x - self.old_x
         movey = touch.y - self.old_y
         for line in self.lines:
             line.move(movex, movey)
         for line in range(len(self.drawn_lines)):
             points = (self.drawn_lines[line][0].points[0] + movex, self.drawn_lines[line][0].points[1] + movey, self.drawn_lines[line][0].points[2] + movex, self.drawn_lines[line][0].points[3] + movey)
             self.drawn_lines[line][0] = Line(points = points, width = 1)
         for line in range(len(self.lat)):
             self.lat[line] += movex
         for line in range(len(self.longit)):
             self.longit[line] += movey
         self.refresh_screen()
         self.old_x, self.old_y = touch.x, touch.y
         
         # ensures that their are always grid lines on the screen
         while min(*self.lat) < 0:
             self.lat[self.lat.index(min(*self.lat))] = max(*self.lat) + self.zoom[0]
         while max(*self.lat) > width:
             self.lat[self.lat.index(max(*self.lat))] = min(*self.lat) - self.zoom[0]
         while min(*self.longit) < 0:
             self.longit[self.longit.index(min(*self.longit))] = max(*self.longit) + self.zoom[0]
         while max(*self.longit) > height:
             self.longit[self.longit.index(max(*self.longit))] = min(*self.longit) - self.zoom[0]