[Sugar-devel] [PATCH] Center the drawing area in the activity canvas

manuel quiñones manuq at laptop.org
Mon Jun 13 23:13:22 EDT 2011


Paint currently shows the drawing area aligned on the top left corner
of the activity canvas.  This is not noticeable if you do a new paint
because the size of the drawing area is set to the canvas size.  But
if you start Paint with a small picture, you can see the issue.  Or if
you use the rotate tool on the whole drawing area.

Here is a demo, rotating the whole drawing area, then cuttng part of
it and opening the cut from the clipboard with Paint:

http://dev.laptop.org/~manuq/paint_centercanvas.gif


El día 13 de junio de 2011 23:56, Manuel Quiñones <manuq at laptop.org> escribió:
> From: Manuel Quiñones <manuel.por.aca at gmail.com>
>
> ---
>  Area.py            |    1 +
>  Desenho.py         |    4 ++--
>  OficinaActivity.py |   22 ++++++++++++++++++++++
>  3 files changed, 25 insertions(+), 2 deletions(-)
>
> diff --git a/Area.py b/Area.py
> index 1fa9ae4..43e1fd0 100644
> --- a/Area.py
> +++ b/Area.py
> @@ -1155,6 +1155,7 @@ class Area(gtk.DrawingArea):
>             self.pixmap_temp.draw_pixbuf(self.gc, temp_pix, 0, 0, 0, 0,
>                 height, width, dither=gtk.gdk.RGB_DITHER_NORMAL,
>                 x_dither=0, y_dither=0)
> +            self.janela.center_area()
>
>         del temp_pix
>
> diff --git a/Desenho.py b/Desenho.py
> index 1d46d4a..6beeb64 100644
> --- a/Desenho.py
> +++ b/Desenho.py
> @@ -589,8 +589,8 @@ class Desenho:
>         if not widget.text_in_progress:
>             widget.text_in_progress = True
>
> -            widget.janela.fixed.move(widget.janela.textview,
> -                int(event.x), int(event.y))
> +            x, y = int(event.x), int(event.y)
> +            widget.janela.move_textview(x, y)
>             widget.janela.textview.show()
>             widget.janela.textview.grab_focus()
>
> diff --git a/OficinaActivity.py b/OficinaActivity.py
> index 86175c2..66e560f 100644
> --- a/OficinaActivity.py
> +++ b/OficinaActivity.py
> @@ -116,6 +116,7 @@ class OficinaActivity(activity.Activity):
>             def size_allocate_cb(widget, allocation):
>                 self.fixed.disconnect(self._setup_handle)
>                 self.area.setup(allocation.width, allocation.height)
> +                self.center_area()
>
>             self.canvas.add_with_viewport(self.fixed)
>             self.disconnect(self._setup_handle)
> @@ -142,6 +143,7 @@ class OficinaActivity(activity.Activity):
>             self.fixed.disconnect(self._setup_handle)
>             self.area.setup(pixbuf.get_width(), pixbuf.get_height())
>             self.area.loadImageFromJournal(pixbuf)
> +            self.center_area()
>
>         self.canvas.add_with_viewport(self.fixed)
>         self.disconnect(self._setup_handle)
> @@ -173,3 +175,23 @@ class OficinaActivity(activity.Activity):
>             gtk.gdk.colormap_get_system(), 0, 0, 0, 0, -1, -1)
>         self.metadata['mime_type'] = 'image/png'
>         pixbuf.save(file_path, 'png', {})
> +
> +    def _get_area_displacement(self):
> +        """Return the point to use as top left corner in order to move
> +        the drawing area and center it on the canvas.
> +
> +        """
> +        canvas_width = self.canvas.allocation.width
> +        canvas_height = self.canvas.allocation.height
> +        area_width, area_height = self.area.get_size_request()
> +        x = (canvas_width - area_width) / 2
> +        y = (canvas_height - area_height) / 2
> +        return x, y
> +
> +    def center_area(self):
> +        x, y = self._get_area_displacement()
> +        self.fixed.move(self.area, x, y)
> +
> +    def move_textview(self, dx, dy):
> +        x, y = self._get_area_displacement()
> +        self.fixed.move(self.textview, x+dx, y+dy)
> --
> 1.7.4.4
>
>


More information about the Sugar-devel mailing list