From 4ecf3b9b085f5e3733a1a913f92e943e370f222c Mon Sep 17 00:00:00 2001 From: pekayatt Date: Wed, 25 Jul 2007 12:27:46 +0000 Subject: New past and copy funcions, improvments on selection func --- diff --git a/Area.py b/Area.py index 62be2c1..96c4f83 100644 --- a/Area.py +++ b/Area.py @@ -112,39 +112,16 @@ class Area(gtk.DrawingArea): self.pixmap = None self.pixmap_temp = None self.pixmap_sel = None + self.pixmap_copy = None self.desenho = [] - self.textos = [] - #self.color_ = 0 - #self.color_line = 0 + self.textos = [] self.estadoTexto = 0 self.janela = janela self.d = Desenho(self) self.line_size = 2 self.brush_shape = 'circle' self.eraser_shape = 'circle' - - #This list must not be used. Using gdk.Color objects. - ''' - colormap = self.get_colormap() - - self.cores = [ - colormap.alloc_color('#ffffff', True, True), # white - colormap.alloc_color('#800000', True, True), # maroon - colormap.alloc_color('#ff0000', True, True), # red - colormap.alloc_color('#808000', True, True), # olive - colormap.alloc_color('#ffff00', True, True), # yellow - colormap.alloc_color('#008000', True, True), # green - colormap.alloc_color('#00ff00', True, True), # lime - colormap.alloc_color('#008080', True, True), # teal - colormap.alloc_color('#00ffff', True, True), # aqua - colormap.alloc_color('#000080', True, True), # navy - colormap.alloc_color('#0000ff', True, True), # blue - colormap.alloc_color('#800080', True, True), # purple - colormap.alloc_color('#ff00ff', True, True), # fuchsia - colormap.alloc_color('#000000', True, True) # black - selection - ] - ''' - + self.font = pango.FontDescription('Sans 9') #self.mensagem = Mensagens(self) #self.mensagem.criaConexao() @@ -195,7 +172,10 @@ class Area(gtk.DrawingArea): black = colormap.alloc_color('#000000', True, True) # black self.gc_selection.set_foreground(black) - print 'configure event' + self.gc_selection1 = widget.window.new_gc() #this make another white line out of the black line + self.gc_selection1.set_line_attributes(1, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) + self.gc_selection1.set_foreground(white) + #print 'configure event' return True @@ -358,6 +338,7 @@ class Area(gtk.DrawingArea): # FIXME: Adicionar cursor formato selecao if self.selmove == False: self.pixmap_temp.draw_drawable(self.gc,self.pixmap, 0 , 0 ,0,0, WIDTH, HEIGHT) + self.pixmap_sel.draw_drawable(self.gc,self.pixmap, 0 , 0 ,0,0, WIDTH, HEIGHT)#avoid blink self.sx = int (event.x) self.sy = int(event.y) self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR)) @@ -534,6 +515,62 @@ class Area(gtk.DrawingArea): # self.undo_times-=1 # print "estourou" + def copy(self): + """ Copy Image. + When the tool selection is working make the change the copy of selectioned area""" + if self.selmove: + + if self.sx > self.oldx: + x = self.oldx + else: + x = self.sx + + if self.sy > self.oldy: + y = self.oldy + else: + y = self.sy + + w = self.sx - self.oldx + if w < 0: + w = - w + + h = self.sy - self.oldy + if h < 0: + h = - h + + self.pixmap_copy = gtk.gdk.Pixmap(self.window, w, h, -1) + self.pixmap_copy.draw_drawable(self.gc, self.pixmap, x, y, 0, 0, w, h) + else : + print "Please select some area first" + self.pixmap_copy == None + + def past(self): + """ Past image. + Past image that is in pixmap_copy""" + if self.pixmap_copy != None : + + + w, h = self.pixmap_copy.get_size() + + #to draw everthing done until this moment + #self.pixmap.draw_drawable(self.gc, self.pixmap_temp, 0,0,0,0, WIDTH, HEIGHT) + + #to get out of sel func + if self.tool == 'marquee-rectangular': + self.pixmap_sel.draw_drawable(self.gc, self.pixmap_copy, 0,0,0,0, w, h) + #self.enableUndo(self) + self.sel_get_out = True + self.selmove = False + + #to draw the new area on screen + self.pixmap.draw_drawable(self.gc, self.pixmap_copy, 0,0,0,0, w, h) + + + self.enableUndo(self) + self.queue_draw() + else : + print "Nothing is copied yet" + def _set_fill_color(self, color): """Set fill color. diff --git a/Desenho.py b/Desenho.py index b564143..84d81af 100644 --- a/Desenho.py +++ b/Desenho.py @@ -357,54 +357,6 @@ class Desenho: self.d.pixmap_temp.draw_polygon(self.d.gc, True, self.points) self.d.pixmap_temp.draw_polygon(self.d.gc_line, False, self.points) - - def selection(self, widget, coords): - """Make a selection. - - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple - - """ - widget.queue_draw() - - if coords[0] > WIDTH: - coords0 = WIDTH - else: - coords0 = coords[0] - - if coords [1] > HEIGHT: - coords1 = HEIGHT - else: - coords1 = coords[1] - - self.d.newx_ = coords0 - self.d.oldx - self.d.newy_ = coords1 - self.d.oldy - - if self.d.newx_ >= 0: - self.d.newx = self.d.oldx - else: - if coords0 > 0: - self.d.newx = coords0 - self.d.newx_ = - self.d.newx_ - 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_ = - 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_rectangle(self.d.gc_selection, False ,self.d.newx,self.d.newy,self.d.newx_,self.d.newy_) - def circle(self, widget, coords): """Draw a circle. @@ -527,6 +479,55 @@ class Desenho: self.d.enableUndo(widget) self.d.queue_draw() + + def selection(self, widget, coords): + """Make a selection. + + Keyword arguments: + self -- Desenho.Desenho instance + widget -- Area object (GtkDrawingArea) + coords -- Two value tuple + + """ + widget.queue_draw() + + if coords[0] > WIDTH: + coords0 = WIDTH + else: + coords0 = coords[0] + + if coords [1] > HEIGHT: + coords1 = HEIGHT + else: + coords1 = coords[1] + + self.d.newx_ = coords0 - self.d.oldx + self.d.newy_ = coords1 - self.d.oldy + + if self.d.newx_ >= 0: + self.d.newx = self.d.oldx + else: + if coords0 > 0: + self.d.newx = coords0 + self.d.newx_ = - self.d.newx_ + 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_ = - 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_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) def moveSelection(self, widget, coords): """Move the selection. @@ -566,8 +567,9 @@ class Desenho: self.d.pixmap_sel.draw_rectangle(self.d.get_style().white_gc, True, x0, x1, w, h) self.d.pixmap_sel.draw_drawable(self.d.gc, self.d.pixmap, x0, x1, coords[0] - w/2, coords[1]- h/2, w, h) - #to draw the selection green line rectangle + #to draw the selection black and white line rectangle self.d.pixmap_sel.draw_rectangle(self.d.gc_selection, False ,coords[0] - w/2, coords[1]- h/2, w, h) + self.d.pixmap_sel.draw_rectangle(self.d.gc_selection1, False ,coords[0] - w/2-1, coords[1]- h/2-1, w+2, h+2) widget.queue_draw() @@ -598,10 +600,6 @@ class Desenho: color -- a color to fill (decimal) ''' -# print 'entering (flood) fill function...' -# print image -# print x,y -# print color, image.get_pixel(x,y) start_color = image.get_pixel(x,y) width, height = self.d.window.get_size() diff --git a/NEWS b/NEWS index dcac8d6..6c484c4 100755 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ 4 === +New past and copy funcions, improvments on selection func (pekayatt) Fixed bug with pixmap_temp New FILL fuction, linked to C module (pekayatt) Color list in Area.py is not used anymore. Toolbox.py now passes a gdk.Color (nathalia.sautchuk, alexandre) diff --git a/eggfill.c b/eggfill.c deleted file mode 100644 index 5f1010a..0000000 --- a/eggfill.c +++ /dev/null @@ -1,193 +0,0 @@ -/* -eggfill.c - -Fill function and queue list - - -Copyright 2007, NATE-LSI-EPUSP - -Oficina is developed in Brazil at Escola Politécnica of -Universidade de São Paulo. NATE is part of LSI (Integrable -Systems Laboratory) and stands for Learning, Work and Entertainment -Research Group. Visit our web page: -www.nate.lsi.usp.br -Suggestions, bugs and doubts, please email oficina@lsi.usp.br - -Oficina is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation version 2 of -the License. - -Oficina is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public -License along with Oficina; if not, write to the -Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -Boston, MA 02110-1301 USA. -The copy of the GNU General Public License is found in the -COPYING file included in the source distribution. - - -Authors: - -Joyce Alessandra Saul (joycealess@gmail.com) -Andre Mossinato (andremossinato@gmail.com) -Nathalia Sautchuk Patrício (nathalia.sautchuk@gmail.com) -Pedro Kayatt (pekayatt@gmail.com) -Rafael Barbolo Lopes (barbolo@gmail.com) -Alexandre A. Gonçalves Martinazzo (alexandremartinazzo@gmail.com) - -*/ -#include -#include "eggfill.h" - -/*for queue*/ -#define front(Q) ( (Q)->Front ) -#define rear(Q) ( (Q)->Rear ) - -struct Node { - ElementType Element; - PtrToNode Next; - }; - -struct QueueL{ - PtrToNode Front; - PtrToNode Rear; - } ; - -/* this queue has a Header that points to the Front and Rear elements */ -/* empty queue: Q->Front = NULL and Q->Rear = NULL */ - -/* check if queue Q is empty */ -int IsEmpty( Queue Q ){ - return ((front(Q)==NULL) && (rear(Q)==NULL)); -} - -Queue CreateQueue( void ){ - Queue Q; - Q = malloc ( sizeof (struct Node)); - - /* check if there is enough space */ - if( Q == NULL ) - printf( "Out of space!!!" ); - - front(Q) = NULL; - rear(Q) = NULL; - - return Q; -} - -void DisposeQueue( Queue Q ){ - MakeEmpty(Q); - free(Q); -} - -void MakeEmpty( Queue Q ){ - if( Q == NULL ) - printf( "Must use CreateQueue first" ); - else - while( !IsEmpty( Q ) ) - Dequeue( Q ); -} - - -void Enqueue( ElementType X, Queue Q ){ - PtrToNode TmpCell; - TmpCell = malloc( sizeof( struct Node ) ); - if( TmpCell == NULL ) - printf( "Out of space!!!" ); - else { - TmpCell->Element = X; - TmpCell->Next = NULL;//rear(Q); - if (IsEmpty(Q)){ - //printf("The Queue is empty\n"); - front(Q)=TmpCell; - } else rear(Q)->Next = TmpCell; - rear(Q) = TmpCell; - } -} - - -//Mostra o Elemento e 1o da Fila -ElementType Front( Queue Q ){ - if (IsEmpty(Q)){ - printf( "Empty queue" ); - return 0; /* Return value used to avoid warning */ - } else { - return front(Q)->Element; - } -} - -void Dequeue( Queue Q ){ - PtrToNode tmpCell; - tmpCell = malloc( sizeof( struct Node ) ); - if( IsEmpty( Q ) ) - printf( "Empty queue" ); - else { - tmpCell=front(Q); - front(Q)=front(Q)->Next; - if (front(Q)==NULL) - rear(Q)=NULL; - free(tmpCell); - } -} /* end of queue*/ - -void fill(GdkDrawable *drawable, GdkGC *gc, int x, int y, int width, int height, int color){ - - int color_start; - - Queue lista_xy; - - lista_xy = CreateQueue(); - - GdkImage *image; - image = gdk_drawable_get_image(drawable,0,0,width,height); - - color_start = gdk_image_get_pixel(image, x, y); - - if (color!=color_start) { - Enqueue(x, lista_xy); - Enqueue(y, lista_xy); - gdk_image_put_pixel(image, x, y, color); - while (!IsEmpty(lista_xy)) { - if (x+1 < width){ - if (gdk_image_get_pixel(image, x+1, y) == color_start){ - gdk_image_put_pixel(image, x+1, y, color); - Enqueue(x+1, lista_xy); - Enqueue(y, lista_xy); - } - } - if (x-1 >= 0){ - if (gdk_image_get_pixel(image, x-1, y) == color_start){ - gdk_image_put_pixel(image, x-1, y, color); - Enqueue(x-1, lista_xy); - Enqueue(y, lista_xy); - } - } - if (y+1 < height){ - if (gdk_image_get_pixel(image, x, y+1) == color_start){ - gdk_image_put_pixel(image, x, y+1, color); - Enqueue(x, lista_xy); - Enqueue(y+1, lista_xy); - } - } - if (y-1 >= 0){ - if (gdk_image_get_pixel(image, x, y-1) == color_start){ - gdk_image_put_pixel(image, x, y-1, color); - Enqueue(x, lista_xy); - Enqueue(y-1, lista_xy); - } - } - x = Front(lista_xy); - Dequeue(lista_xy); - y = Front(lista_xy); - Dequeue(lista_xy); - } - } - - gdk_draw_image(drawable, gc, image, 0,0,0,0,width,height); - -} diff --git a/eggfill.h b/eggfill.h deleted file mode 100644 index 2d1d90a..0000000 --- a/eggfill.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -eggfill.h - -Fill function and queue list - - -Copyright 2007, NATE-LSI-EPUSP - -Oficina is developed in Brazil at Escola Politécnica of -Universidade de São Paulo. NATE is part of LSI (Integrable -Systems Laboratory) and stands for Learning, Work and Entertainment -Research Group. Visit our web page: -www.nate.lsi.usp.br -Suggestions, bugs and doubts, please email oficina@lsi.usp.br - -Oficina is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation version 2 of -the License. - -Oficina is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public -License along with Oficina; if not, write to the -Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -Boston, MA 02110-1301 USA. -The copy of the GNU General Public License is found in the -COPYING file included in the source distribution. - - -Authors: - -Joyce Alessandra Saul (joycealess@gmail.com) -Andre Mossinato (andremossinato@gmail.com) -Nathalia Sautchuk Patrício (nathalia.sautchuk@gmail.com) -Pedro Kayatt (pekayatt@gmail.com) -Rafael Barbolo Lopes (barbolo@gmail.com) -Alexandre A. Gonçalves Martinazzo (alexandremartinazzo@gmail.com) - -*/ -#include -#include -#include - -/*to implement a queue */ -typedef int ElementType; -struct Node; -typedef struct Node *PtrToNode; -typedef PtrToNode List; -typedef PtrToNode Position; -typedef struct QueueL *Queue; -int IsEmpty( Queue Q ); -Queue CreateQueue( void ); -void DisposeQueue( Queue Q ); -void MakeEmpty( Queue Q ); -void Enqueue( ElementType X, Queue Q ); -ElementType Front( Queue Q ); -void Dequeue( Queue Q ); -/*end of queue*/ -void fill(GdkDrawable *drawable, GdkGC *gc, int x, int y, int width, int height, int color); diff --git a/toolbox.py b/toolbox.py index 4e84257..822acdb3 100644 --- a/toolbox.py +++ b/toolbox.py @@ -115,8 +115,8 @@ class DrawEditToolbar(EditToolbar): self.copy.connect('clicked', self._copy_cb) self.paste.connect('clicked', self._paste_cb) - self.copy.hide() - self.paste.hide() +# self.copy.hide() +# self.paste.hide() def _undo_cb(self, widget, data=None): self._activity._area.undo() @@ -125,12 +125,10 @@ class DrawEditToolbar(EditToolbar): self._activity._area.redo() def _copy_cb(self, widget, data=None): - #FIXME: connect to the correct function - pass + self._activity._area.copy() def _paste_cb(self, widget, data=None): - #FIXME: connect to the correct function - pass + self._activity._area.past() class ToolsToolbar(gtk.Toolbar): -- cgit v0.9.1