2006-12-03 Dimitris Glezos <dimitris@glezos.com>
[dia.git] / lib / render_pixmap.c
blobc13261f2752271d2373b2d0b7d9d0dc815b2a748
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 /* This renderer is similar to RenderGdk, except that it renders onto
20 * its own little GdkPixmap, doesn't deal with the DDisplay at all, and
21 * uses a 1-1 mapping between points and pixels. It is used for rendering
22 * arrows and lines onto selectors. This way, any change in the arrow
23 * definitions are automatically reflected in the selectors.
27 * 2002-10-06 : Leaved the original comment but removed almost
28 * anything else. The 'RendererPixmap' now uses the DiaGdkRenderer which
29 * is the ported to GObject 'RendererGdk'. No more huge code duplication
30 * but only some renderer parametrization tweaking. --hb
32 #include <config.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <gdk/gdk.h>
38 #include "render_pixmap.h"
39 #include "message.h"
40 #include "diagdkrenderer.h"
42 static Rectangle rect;
43 static real zoom = 1.0;
45 DiaRenderer *
46 new_pixmap_renderer(GdkWindow *window, int width, int height)
48 DiaGdkRenderer *renderer;
49 GdkColor color;
51 rect.left = 0;
52 rect.top = 0;
53 rect.right = width;
54 rect.bottom = height;
56 renderer = g_object_new (DIA_TYPE_GDK_RENDERER, NULL);
57 renderer->transform = dia_transform_new (&rect, &zoom);
58 renderer->pixmap = gdk_pixmap_new(window, width, height, -1);
59 renderer->gc = gdk_gc_new(window);
61 gdk_color_white(gdk_colormap_get_system(), &color);
62 gdk_gc_set_foreground(renderer->gc, &color);
63 gdk_draw_rectangle(renderer->pixmap, renderer->gc, 1,
64 0, 0, width, height);
66 return DIA_RENDERER(renderer);
69 void
70 renderer_pixmap_set_pixmap (DiaRenderer *ren,
71 GdkDrawable *drawable,
72 int xoffset, int yoffset,
73 int width, int height)
75 DiaGdkRenderer *renderer = DIA_GDK_RENDERER (ren);
77 if (renderer->pixmap != NULL)
78 gdk_pixmap_unref(renderer->pixmap);
80 if (renderer->gc != NULL)
81 gdk_gc_unref(renderer->gc);
83 gdk_pixmap_ref(drawable);
84 renderer->pixmap = drawable;
85 renderer->gc = gdk_gc_new(drawable);
87 rect.left = -xoffset;
88 rect.top = -yoffset;
89 rect.right = width;
90 rect.bottom = height;
93 GdkPixmap *
94 renderer_pixmap_get_pixmap (DiaRenderer *ren)
96 DiaGdkRenderer *renderer = DIA_GDK_RENDERER (ren);
98 return renderer->pixmap;