File: render_pixmap.c

package info (click to toggle)
dia 0.94.0-7sarge3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 27,804 kB
  • ctags: 11,124
  • sloc: ansic: 110,979; sh: 8,442; xml: 2,988; makefile: 2,431; python: 1,789; cpp: 1,652
file content (99 lines) | stat: -rw-r--r-- 3,044 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Dia -- an diagram creation/manipulation program
 * Copyright (C) 1998 Alexander Larsson
 *
 * This program 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; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/* This renderer is similar to RenderGdk, except that it renders onto
 * its own little GdkPixmap, doesn't deal with the DDisplay at all, and
 * uses a 1-1 mapping between points and pixels.  It is used for rendering
 * arrows and lines onto selectors.  This way, any change in the arrow 
 * definitions are automatically reflected in the selectors.
 */

/*
 * 2002-10-06 : Leaved the original comment but removed almost
 * anything else. The 'RendererPixmap' now uses the DiaGdkRenderer which 
 * is the ported to GObject 'RendererGdk'. No more huge code duplication 
 * but only some renderer parametrization tweaking.                 --hb
 */
#include <config.h>

#include <math.h>
#include <stdlib.h>
#include <gdk/gdk.h>

#include "render_pixmap.h"
#include "message.h"
#include "diagdkrenderer.h"

static Rectangle rect;
static real zoom = 1.0;

DiaRenderer *
new_pixmap_renderer(GdkWindow *window, int width, int height)
{
  DiaGdkRenderer *renderer;
  GdkColor color;

  rect.left = 0;
  rect.top = 0;
  rect.right = width;
  rect.bottom = height;

  renderer = g_object_new (DIA_TYPE_GDK_RENDERER, NULL);
  renderer->transform = dia_transform_new (&rect, &zoom);
  renderer->pixmap = gdk_pixmap_new(window, width, height, -1);
  renderer->gc = gdk_gc_new(window);

  gdk_color_white(gdk_colormap_get_system(), &color);
  gdk_gc_set_foreground(renderer->gc, &color);
  gdk_draw_rectangle(renderer->pixmap, renderer->gc, 1,
		 0, 0, width, height);

  return DIA_RENDERER(renderer);
}

void
renderer_pixmap_set_pixmap (DiaRenderer *ren, 
                            GdkDrawable *drawable,
                            int xoffset, int yoffset, 
                            int width, int height)
{
  DiaGdkRenderer *renderer = DIA_GDK_RENDERER (ren);

  if (renderer->pixmap != NULL)
    gdk_pixmap_unref(renderer->pixmap);

  if (renderer->gc != NULL)
    gdk_gc_unref(renderer->gc);

  gdk_pixmap_ref(drawable);
  renderer->pixmap = drawable;
  renderer->gc = gdk_gc_new(drawable);

  rect.left = -xoffset;
  rect.top = -yoffset;
  rect.right = width;
  rect.bottom = height;
}

GdkPixmap *
renderer_pixmap_get_pixmap (DiaRenderer *ren) 
{
  DiaGdkRenderer *renderer = DIA_GDK_RENDERER (ren);

  return renderer->pixmap;
}