Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Desenho.py
diff options
context:
space:
mode:
Diffstat (limited to 'Desenho.py')
-rw-r--r--[-rwxr-xr-x]Desenho.py164
1 files changed, 116 insertions, 48 deletions
diff --git a/Desenho.py b/Desenho.py
index 1049e27..3c3c767 100755..100644
--- a/Desenho.py
+++ b/Desenho.py
@@ -87,8 +87,8 @@ class Desenho:
"""
self.d.pixmap_temp.draw_drawable(self.d.gc,self.d.pixmap, 0 , 0 ,0,0, WIDTH, HEIGHT)
self.d.pixmap_temp.draw_line(self.d.gc_line,self.d.oldx,self.d.oldy,coords[0],coords[1])
- self.d.newx = coords[0]
- self.d.newy = coords[1]
+ #self.d.newx = coords[0]
+ #self.d.newy = coords[1]
widget.queue_draw()
def eraser(self, widget, coords, size = 30, shape = 'circle'):
@@ -135,7 +135,7 @@ class Desenho:
self.d.oldy = coords[1]
widget.queue_draw()
- def square(self, widget, coords):
+ def square(self, widget, coords, temp, fill):
"""Draw a square.
Keyword arguments:
@@ -143,9 +143,7 @@ class Desenho:
widget -- Area object (GtkDrawingArea)
coords -- Two value tuple
- """
- widget.queue_draw()
-
+
if coords[0] > WIDTH:
coords0 = WIDTH
else:
@@ -178,13 +176,33 @@ class Desenho:
else:
self.d.newy = 0
self.d.newy_ = self.d.oldy
-
- self.d.pixmap_temp.draw_drawable(self.d.gc,self.d.pixmap, 0 , 0 ,0,0, WIDTH, HEIGHT)
- self.d.pixmap_temp.draw_rectangle(self.d.gc, True ,self.d.newx,self.d.newy,self.d.newx_,self.d.newy_)
- self.d.pixmap_temp.draw_rectangle(self.d.gc_line, False ,self.d.newx,self.d.newy,self.d.newx_,self.d.newy_)
+ """
+ if temp == True:
+ pixmap = self.d.pixmap_temp
+ else:
+ pixmap = self.d.pixmap
+ width, height = self.d.window.get_size()
+
+ dx = math.fabs(coords[0] - self.d.oldx)
+ dy = math.fabs(coords[1] - self.d.oldy)
+
+ if coords[0] < self.d.oldx:
+ x = coords[0]
+ else:
+ x = self.d.oldx
+ if coords[1] < self.d.oldy:
+ y = coords[1]
+ else:
+ y = self.d.oldy
+
+ pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
+ if fill == True:
+ pixmap.draw_rectangle(self.d.gc,True,x,y,dx,dy)
+ pixmap.draw_rectangle(self.d.gc_line,False,x,y,dx,dy)
+ widget.queue_draw()
- def triangle(self, widget, coords, temp):
+ def triangle(self, widget, coords, temp, fill):
"""Draw a triangle.
Keyword arguments:
@@ -201,13 +219,14 @@ class Desenho:
width, height = self.d.window.get_size()
points = [(self.d.oldx,self.d.oldy), (self.d.oldx+int((coords[0]-self.d.oldx)/2),coords[1]), (coords[0],self.d.oldy)]
- pixmap.draw_drawable(self.d.gc, self.d.pixmap, 0, 0, 0, 0, width, height)
- pixmap.draw_polygon(self.d.gc, True, points)
- pixmap.draw_polygon(self.d.gc_line, False, points)
+ pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
+ if fill == True:
+ pixmap.draw_polygon(self.d.gc,True,points)
+ pixmap.draw_polygon(self.d.gc_line,False,points)
widget.queue_draw()
- def trapezoid(self, widget, coords, temp):
+ def trapezoid(self, widget, coords, temp, fill):
"""Draw a trapezoid.
Keyword arguments:
@@ -225,13 +244,14 @@ class Desenho:
dif = int((coords[0] - self.d.oldx)/4)
points = [(self.d.oldx, self.d.oldy), (self.d.oldx+dif, coords[1]), (coords[0]-dif, coords[1]) , (coords[0],self.d.oldy)]
- pixmap.draw_drawable(self.d.gc,self.d.pixmap, 0 , 0 , 0, 0, width, height)
- pixmap.draw_polygon(self.d.gc, True, points)
- pixmap.draw_polygon(self.d.gc_line, False, points)
+ pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
+ if fill == True:
+ pixmap.draw_polygon(self.d.gc, True, points)
+ pixmap.draw_polygon(self.d.gc_line,False,points)
widget.queue_draw()
- def arrow(self, widget, coords, temp):
+ def arrow(self, widget, coords, temp, fill):
"""Draw a arrow.
Keyword arguments:
@@ -255,13 +275,14 @@ class Desenho:
(self.d.oldx+x,self.d.oldy-int(y/3)),\
(self.d.oldx+int(x/6),self.d.oldy-int(y/3)),\
(self.d.oldx+int(x/6),self.d.oldy-y)]
- pixmap.draw_drawable(self.d.gc,self.d.pixmap, 0, 0, 0, 0, width, height)
- pixmap.draw_polygon(self.d.gc, True, points)
- pixmap.draw_polygon(self.d.gc_line, False, points)
+ pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
+ if fill == True:
+ pixmap.draw_polygon(self.d.gc,True,points)
+ pixmap.draw_polygon(self.d.gc_line,False,points)
widget.queue_draw()
- def parallelogram(self, widget, coords, temp):
+ def parallelogram(self, widget, coords, temp, fill):
"""Draw a parallelogram.
Keyword arguments:
@@ -279,12 +300,13 @@ class Desenho:
x = int((coords[0] - self.d.oldx)/4)
points = [(self.d.oldx,self.d.oldy), (coords[0]-x, self.d.oldy), (coords[0],coords[1]), (self.d.oldx+x,coords[1])]
pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
- pixmap.draw_polygon(self.d.gc, True, points)
- pixmap.draw_polygon(self.d.gc_line, False, points)
+ if fill == True:
+ pixmap.draw_polygon(self.d.gc,True,points)
+ pixmap.draw_polygon(self.d.gc_line,False,points)
widget.queue_draw()
- def star(self, widget, coords, temp):
+ def star(self, widget, coords, temp, fill):
"""Draw a arrow.
Keyword arguments:
@@ -312,13 +334,14 @@ class Desenho:
(self.d.oldx-int(x*0.35), self.d.oldy+int(y*0.6)),\
(self.d.oldx-int(x), self.d.oldy+int(y*0.4)),\
(self.d.oldx-int(x*0.25), self.d.oldy+int(y*0.4))]
- pixmap.draw_drawable(self.d.gc,self.d.pixmap, 0 , 0 ,0,0, width, height)
- pixmap.draw_polygon(self.d.gc, True, points)
- pixmap.draw_polygon(self.d.gc_line, False, points)
+ pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
+ if fill == True:
+ pixmap.draw_polygon(self.d.gc,True,points)
+ pixmap.draw_polygon(self.d.gc_line,False,points)
widget.queue_draw()
- def polygon_regular(self, widget, coords, n, temp):
+ def polygon_regular(self, widget, coords, n, temp, fill):
"""Draw polygon with n sides.
Keyword arguments:
@@ -346,13 +369,14 @@ class Desenho:
p.append((self.d.oldx+int(r*math.cos(A)),self.d.oldy+int(r*math.sin(A))))
tp = tuple(p)
- pixmap.draw_drawable(self.d.gc, self.d.pixmap, 0, 0, 0, 0, width, height)
- pixmap.draw_polygon(self.d.gc, True, tp)
- pixmap.draw_polygon(self.d.gc_line, False, tp)
+ pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
+ if fill == True:
+ pixmap.draw_polygon(self.d.gc,True,tp)
+ pixmap.draw_polygon(self.d.gc_line,False,tp)
widget.queue_draw()
- def circle(self, widget, coords):
+ def circle(self, widget, coords, temp, fill):
"""Draw a circle.
Keyword arguments:
@@ -360,9 +384,6 @@ class Desenho:
widget -- Area object (GtkDrawingArea)
coords -- Two value tuple
- """
- widget.queue_draw()
-
if coords[0] > WIDTH:
coords0 = WIDTH
else:
@@ -375,7 +396,6 @@ class Desenho:
self.d.newx_ = coords0 - self.d.oldx
self.d.newy_ = coords1 - self.d.oldy
- #print "coords0", coords0
if self.d.newx_ >= 0:
self.d.newx = self.d.oldx
@@ -386,22 +406,44 @@ class Desenho:
else:
self.d.newx = 0
self.d.newx_ = self.d.oldx
-
+
if self.d.newy_ >= 0:
self.d.newy = self.d.oldy
- else:
- if coords1 > 0:
- self.d.newy = coords1
+ else:
+ if coords1 > 0:
self.d.newy_ = - self.d.newy_
+ self.d.newy = coords1
else:
self.d.newy = 0
self.d.newy_ = self.d.oldy
- self.d.pixmap_temp.draw_drawable(self.d.gc,self.d.pixmap, 0 , 0 ,0,0, WIDTH, HEIGHT)
- self.d.pixmap_temp.draw_arc(self.d.gc, True, self.d.newx, self.d.newy, self.d.newx_,self.d.newy_, 0, 360*64)
- self.d.pixmap_temp.draw_arc(self.d.gc_line, False, self.d.newx, self.d.newy, self.d.newx_, self.d.newy_, 0, 360*64)
+ """
+
+ if temp == True:
+ pixmap = self.d.pixmap_temp
+ else:
+ pixmap = self.d.pixmap
+ width, height = self.d.window.get_size()
+
+ if coords[0] < self.d.oldx:
+ x = coords[0]
+ else:
+ x = self.d.oldx
+ if coords[1] < self.d.oldy:
+ y = coords[1]
+ else:
+ y = self.d.oldy
+
+ dx = math.fabs(coords[0] - self.d.oldx)
+ dy = math.fabs(coords[1] - self.d.oldy)
+
+ pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
+ if fill == True:
+ pixmap.draw_arc(self.d.gc,True,x,y,dx,dy,0,360*64)
+ pixmap.draw_arc(self.d.gc_line,False,x,y,dx,dy,0,360*64)
+ widget.queue_draw()
+
-
def pencil(self, widget, coords):
"""Draw a pencil.
@@ -474,7 +516,7 @@ class Desenho:
self.d.queue_draw()
- def selection(self, widget, coords):
+ def selection(self, widget, coords, temp, fill):
"""Make a selection.
Keyword arguments:
@@ -482,7 +524,7 @@ class Desenho:
widget -- Area object (GtkDrawingArea)
coords -- Two value tuple
- """
+
widget.queue_draw()
if coords[0] > WIDTH:
@@ -522,6 +564,32 @@ class Desenho:
self.d.pixmap_temp.draw_rectangle(self.d.gc_selection, False ,self.d.newx,self.d.newy,self.d.newx_,self.d.newy_)
self.d.pixmap_temp.draw_rectangle(self.d.gc_selection1, False, \
self.d.newx-1,self.d.newy-1,self.d.newx_+2,self.d.newy_+2)
+ """
+
+ if temp == True:
+ pixmap = self.d.pixmap_temp
+ else:
+ pixmap = self.d.pixmap
+ width, height = self.d.window.get_size()
+
+ dx = math.fabs(coords[0] - self.d.oldx)
+ dy = math.fabs(coords[1] - self.d.oldy)
+
+ if coords[0] < self.d.oldx:
+ x = coords[0]
+ else:
+ x = self.d.oldx
+ if coords[1] < self.d.oldy:
+ y = coords[1]
+ else:
+ y = self.d.oldy
+
+ pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
+ if fill == True:
+ pixmap.draw_rectangle(self.d.gc,True,x,y,dx,dy)
+ pixmap.draw_rectangle(self.d.gc_line,False,x,y,dx,dy)
+ widget.queue_draw()
+ return self.d.oldx, self.d.oldy, coords[0], coords[1]
def moveSelection(self, widget, coords):
"""Move the selection.