app/widgets/gimppreviewrenderer.c simplified drawing code to a point where

2003-09-30  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimppreviewrenderer.c
	* app/widgets/gimppreviewrenderervectors.c: simplified drawing
	code to a point where it becomes readable again. Draw centered
	into the draw_area, using the size of the renderer.
This commit is contained in:
Sven Neumann 2003-09-30 12:06:58 +00:00 committed by Sven Neumann
parent 5df103caca
commit dc7a068fdc
5 changed files with 67 additions and 120 deletions

View File

@ -1,3 +1,10 @@
2003-09-30 Sven Neumann <sven@gimp.org>
* app/widgets/gimppreviewrenderer.c
* app/widgets/gimppreviewrenderervectors.c: simplified drawing
code to a point where it becomes readable again. Draw centered
into the draw_area, using the size of the renderer.
2003-09-30 Michael Natterer <mitch@gimp.org> 2003-09-30 Michael Natterer <mitch@gimp.org>
* app/paint/gimppaintcore-stroke.c: cleanup. * app/paint/gimppaintcore-stroke.c: cleanup.

View File

@ -519,8 +519,6 @@ gimp_preview_renderer_draw (GimpPreviewRenderer *renderer,
const GdkRectangle *draw_area, const GdkRectangle *draw_area,
const GdkRectangle *expose_area) const GdkRectangle *expose_area)
{ {
GdkRectangle border_rect;
g_return_if_fail (GIMP_IS_PREVIEW_RENDERER (renderer)); g_return_if_fail (GIMP_IS_PREVIEW_RENDERER (renderer));
g_return_if_fail (GDK_IS_WINDOW (window)); g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (GTK_IS_WIDGET (widget));
@ -534,20 +532,15 @@ gimp_preview_renderer_draw (GimpPreviewRenderer *renderer,
window, widget, window, widget,
draw_area, expose_area); draw_area, expose_area);
border_rect.x = draw_area->x;
border_rect.y = draw_area->y;
border_rect.width = renderer->width + 2 * renderer->border_width;
border_rect.height = renderer->height + 2 * renderer->border_width;
if (draw_area->width > border_rect.width)
border_rect.x += (draw_area->width - border_rect.width) / 2;
if (draw_area->height > border_rect.height)
border_rect.y += (draw_area->height - border_rect.height) / 2;
if (renderer->border_width > 0) if (renderer->border_width > 0)
{ {
gint i; GdkRectangle rect;
gint i;
rect.width = renderer->width + 2 * renderer->border_width;
rect.height = renderer->height + 2 * renderer->border_width;
rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
if (! renderer->gc) if (! renderer->gc)
renderer->gc = gimp_preview_renderer_create_gc (renderer, renderer->gc = gimp_preview_renderer_create_gc (renderer,
@ -557,10 +550,10 @@ gimp_preview_renderer_draw (GimpPreviewRenderer *renderer,
gdk_draw_rectangle (window, gdk_draw_rectangle (window,
renderer->gc, renderer->gc,
FALSE, FALSE,
border_rect.x + i, rect.x + i,
border_rect.y + i, rect.y + i,
border_rect.width - 2 * i - 1, rect.width - 2 * i - 1,
border_rect.height - 2 * i - 1); rect.height - 2 * i - 1);
} }
} }
@ -585,7 +578,7 @@ gimp_preview_renderer_real_draw (GimpPreviewRenderer *renderer,
const GdkRectangle *draw_area, const GdkRectangle *draw_area,
const GdkRectangle *expose_area) const GdkRectangle *expose_area)
{ {
GdkRectangle buf_rect; GdkRectangle rect;
GdkRectangle render_rect; GdkRectangle render_rect;
if (renderer->needs_render) if (renderer->needs_render)
@ -610,22 +603,19 @@ gimp_preview_renderer_real_draw (GimpPreviewRenderer *renderer,
} }
} }
buf_rect.width = gdk_pixbuf_get_width (renderer->no_preview_pixbuf); rect.width = gdk_pixbuf_get_width (renderer->no_preview_pixbuf);
buf_rect.height = gdk_pixbuf_get_height (renderer->no_preview_pixbuf); rect.height = gdk_pixbuf_get_height (renderer->no_preview_pixbuf);
buf_rect.x = (draw_area->width - buf_rect.width) / 2; rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
buf_rect.y = (draw_area->height - buf_rect.height) / 2; rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
buf_rect.x += draw_area->x; if (gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area,
buf_rect.y += draw_area->y;
if (gdk_rectangle_intersect (&buf_rect, (GdkRectangle *) expose_area,
&render_rect)) &render_rect))
{ {
gdk_draw_pixbuf (GDK_DRAWABLE (window), gdk_draw_pixbuf (GDK_DRAWABLE (window),
widget->style->bg_gc[widget->state], widget->style->bg_gc[widget->state],
renderer->no_preview_pixbuf, renderer->no_preview_pixbuf,
render_rect.x - buf_rect.x, render_rect.x - rect.x,
render_rect.y - buf_rect.y, render_rect.y - rect.y,
render_rect.x, render_rect.x,
render_rect.y, render_rect.y,
render_rect.width, render_rect.width,
@ -636,28 +626,19 @@ gimp_preview_renderer_real_draw (GimpPreviewRenderer *renderer,
} }
else if (renderer->buffer) else if (renderer->buffer)
{ {
buf_rect.x = draw_area->x + renderer->border_width; rect.width = renderer->width;
buf_rect.y = draw_area->y + renderer->border_width; rect.height = renderer->height;
buf_rect.width = renderer->width + 2 * renderer->border_width; rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
buf_rect.height = renderer->height + 2 * renderer->border_width; rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
if (draw_area->width > buf_rect.width) if (gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area,
buf_rect.x += (draw_area->width - buf_rect.width) / 2;
if (draw_area->height > buf_rect.height)
buf_rect.y += (draw_area->height - buf_rect.height) / 2;
buf_rect.width -= 2 * renderer->border_width;
buf_rect.height -= 2 * renderer->border_width;
if (gdk_rectangle_intersect (&buf_rect, (GdkRectangle *) expose_area,
&render_rect)) &render_rect))
{ {
guchar *buf; guchar *buf;
buf = (renderer->buffer + buf = (renderer->buffer +
(render_rect.y - buf_rect.y) * renderer->rowstride + (render_rect.y - rect.y) * renderer->rowstride +
(render_rect.x - buf_rect.x) * renderer->bytes); (render_rect.x - rect.x) * renderer->bytes);
gdk_draw_rgb_image_dithalign (window, gdk_draw_rgb_image_dithalign (window,
widget->style->black_gc, widget->style->black_gc,

View File

@ -102,21 +102,10 @@ gimp_preview_renderer_vectors_draw (GimpPreviewRenderer *renderer,
gboolean closed; gboolean closed;
gdouble xscale, yscale; gdouble xscale, yscale;
rect.x = draw_area->x + renderer->border_width; rect.width = renderer->width;
rect.y = draw_area->y + renderer->border_width; rect.height = renderer->height;
rect.width = draw_area->width - 2 * renderer->border_width; rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
rect.height = draw_area->height - 2 * renderer->border_width; rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
if (rect.width > renderer->width)
{
rect.x += (rect.width - renderer->width) / 2;
rect.width = renderer->width;
}
if (rect.height > renderer->height)
{
rect.y += (rect.height - renderer->height) / 2;
rect.height = renderer->height;
}
if (! gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area, &area)) if (! gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area, &area))
return; return;

View File

@ -519,8 +519,6 @@ gimp_preview_renderer_draw (GimpPreviewRenderer *renderer,
const GdkRectangle *draw_area, const GdkRectangle *draw_area,
const GdkRectangle *expose_area) const GdkRectangle *expose_area)
{ {
GdkRectangle border_rect;
g_return_if_fail (GIMP_IS_PREVIEW_RENDERER (renderer)); g_return_if_fail (GIMP_IS_PREVIEW_RENDERER (renderer));
g_return_if_fail (GDK_IS_WINDOW (window)); g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (GTK_IS_WIDGET (widget));
@ -534,20 +532,15 @@ gimp_preview_renderer_draw (GimpPreviewRenderer *renderer,
window, widget, window, widget,
draw_area, expose_area); draw_area, expose_area);
border_rect.x = draw_area->x;
border_rect.y = draw_area->y;
border_rect.width = renderer->width + 2 * renderer->border_width;
border_rect.height = renderer->height + 2 * renderer->border_width;
if (draw_area->width > border_rect.width)
border_rect.x += (draw_area->width - border_rect.width) / 2;
if (draw_area->height > border_rect.height)
border_rect.y += (draw_area->height - border_rect.height) / 2;
if (renderer->border_width > 0) if (renderer->border_width > 0)
{ {
gint i; GdkRectangle rect;
gint i;
rect.width = renderer->width + 2 * renderer->border_width;
rect.height = renderer->height + 2 * renderer->border_width;
rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
if (! renderer->gc) if (! renderer->gc)
renderer->gc = gimp_preview_renderer_create_gc (renderer, renderer->gc = gimp_preview_renderer_create_gc (renderer,
@ -557,10 +550,10 @@ gimp_preview_renderer_draw (GimpPreviewRenderer *renderer,
gdk_draw_rectangle (window, gdk_draw_rectangle (window,
renderer->gc, renderer->gc,
FALSE, FALSE,
border_rect.x + i, rect.x + i,
border_rect.y + i, rect.y + i,
border_rect.width - 2 * i - 1, rect.width - 2 * i - 1,
border_rect.height - 2 * i - 1); rect.height - 2 * i - 1);
} }
} }
@ -585,7 +578,7 @@ gimp_preview_renderer_real_draw (GimpPreviewRenderer *renderer,
const GdkRectangle *draw_area, const GdkRectangle *draw_area,
const GdkRectangle *expose_area) const GdkRectangle *expose_area)
{ {
GdkRectangle buf_rect; GdkRectangle rect;
GdkRectangle render_rect; GdkRectangle render_rect;
if (renderer->needs_render) if (renderer->needs_render)
@ -610,22 +603,19 @@ gimp_preview_renderer_real_draw (GimpPreviewRenderer *renderer,
} }
} }
buf_rect.width = gdk_pixbuf_get_width (renderer->no_preview_pixbuf); rect.width = gdk_pixbuf_get_width (renderer->no_preview_pixbuf);
buf_rect.height = gdk_pixbuf_get_height (renderer->no_preview_pixbuf); rect.height = gdk_pixbuf_get_height (renderer->no_preview_pixbuf);
buf_rect.x = (draw_area->width - buf_rect.width) / 2; rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
buf_rect.y = (draw_area->height - buf_rect.height) / 2; rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
buf_rect.x += draw_area->x; if (gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area,
buf_rect.y += draw_area->y;
if (gdk_rectangle_intersect (&buf_rect, (GdkRectangle *) expose_area,
&render_rect)) &render_rect))
{ {
gdk_draw_pixbuf (GDK_DRAWABLE (window), gdk_draw_pixbuf (GDK_DRAWABLE (window),
widget->style->bg_gc[widget->state], widget->style->bg_gc[widget->state],
renderer->no_preview_pixbuf, renderer->no_preview_pixbuf,
render_rect.x - buf_rect.x, render_rect.x - rect.x,
render_rect.y - buf_rect.y, render_rect.y - rect.y,
render_rect.x, render_rect.x,
render_rect.y, render_rect.y,
render_rect.width, render_rect.width,
@ -636,28 +626,19 @@ gimp_preview_renderer_real_draw (GimpPreviewRenderer *renderer,
} }
else if (renderer->buffer) else if (renderer->buffer)
{ {
buf_rect.x = draw_area->x + renderer->border_width; rect.width = renderer->width;
buf_rect.y = draw_area->y + renderer->border_width; rect.height = renderer->height;
buf_rect.width = renderer->width + 2 * renderer->border_width; rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
buf_rect.height = renderer->height + 2 * renderer->border_width; rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
if (draw_area->width > buf_rect.width) if (gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area,
buf_rect.x += (draw_area->width - buf_rect.width) / 2;
if (draw_area->height > buf_rect.height)
buf_rect.y += (draw_area->height - buf_rect.height) / 2;
buf_rect.width -= 2 * renderer->border_width;
buf_rect.height -= 2 * renderer->border_width;
if (gdk_rectangle_intersect (&buf_rect, (GdkRectangle *) expose_area,
&render_rect)) &render_rect))
{ {
guchar *buf; guchar *buf;
buf = (renderer->buffer + buf = (renderer->buffer +
(render_rect.y - buf_rect.y) * renderer->rowstride + (render_rect.y - rect.y) * renderer->rowstride +
(render_rect.x - buf_rect.x) * renderer->bytes); (render_rect.x - rect.x) * renderer->bytes);
gdk_draw_rgb_image_dithalign (window, gdk_draw_rgb_image_dithalign (window,
widget->style->black_gc, widget->style->black_gc,

View File

@ -102,21 +102,10 @@ gimp_preview_renderer_vectors_draw (GimpPreviewRenderer *renderer,
gboolean closed; gboolean closed;
gdouble xscale, yscale; gdouble xscale, yscale;
rect.x = draw_area->x + renderer->border_width; rect.width = renderer->width;
rect.y = draw_area->y + renderer->border_width; rect.height = renderer->height;
rect.width = draw_area->width - 2 * renderer->border_width; rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
rect.height = draw_area->height - 2 * renderer->border_width; rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
if (rect.width > renderer->width)
{
rect.x += (rect.width - renderer->width) / 2;
rect.width = renderer->width;
}
if (rect.height > renderer->height)
{
rect.y += (rect.height - renderer->height) / 2;
rect.height = renderer->height;
}
if (! gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area, &area)) if (! gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area, &area))
return; return;