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
100
101
102
103
|
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* gnomecc-rounded-rect.c: A rectangle with rounded corners
*
* Copyright (C) 2004 Novell Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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
*/
#include <config.h>
#include "gnomecc-rounded-rect.h"
#include "gnomecc-rounded-rect-pixbuf.h"
#include <glib-object.h>
#include <math.h>
struct _GnomeccRoundedRect {
GnomeCanvasRect base;
};
typedef GnomeCanvasRectClass GnomeccRoundedRectClass;
#define GNOMECC_ROUNDED_RECT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNOMECC_TYPE_ROUNDED_RECT, GnomeccRoundedRectClass))
#define GNOMECC_IS_ROUNDED_RECT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNOMECC_TYPE_ROUNDED_RECT))
G_DEFINE_TYPE (GnomeccRoundedRect, gnomecc_rounded_rect, GNOME_TYPE_CANVAS_RECT);
/*************************************************************************
* Adapted from nautilus/libnautilus-private/nautilus-icon-canvas-item.c
*/
/* clear the corners of the selection pixbuf by copying the corners of the passed-in pixbuf */
static void
gnomecc_rounded_rect_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height)
{
static GdkPixbuf *corner_pixbuf = NULL;
GnomeCanvasRE const *re = GNOME_CANVAS_RE (item);
int dest_width, dest_height, src_width, src_height;
int dx, dy;
int corner_size = 5;
double affine[6];
GNOME_CANVAS_ITEM_CLASS (gnomecc_rounded_rect_parent_class)->draw (item, drawable, x, y, width, height);
if (corner_pixbuf == NULL)
corner_pixbuf = gdk_pixbuf_new_from_inline (-1,
gnomecc_rounded_rect_frame, FALSE, NULL);
src_width = gdk_pixbuf_get_width (corner_pixbuf);
src_height = gdk_pixbuf_get_height (corner_pixbuf);
gnome_canvas_item_i2c_affine (item, affine);
dest_width = fabs (re->x2 - re->x1);
dest_height = fabs (re->y2 - re->y1);
dx = affine[4] - x;
dy = affine[5] - y;
/* draw top left corner */
gdk_draw_pixbuf (drawable, NULL, corner_pixbuf,
0, 0,
dx, dy,
corner_size, corner_size,
GDK_RGB_DITHER_NORMAL, 0, 0);
/* draw top right corner */
gdk_draw_pixbuf (drawable, NULL, corner_pixbuf,
src_width - corner_size, 0,
dx + dest_width - corner_size, dy,
corner_size, corner_size,
GDK_RGB_DITHER_NORMAL, 0, 0);
/* draw bottom left corner */
gdk_draw_pixbuf (drawable, NULL, corner_pixbuf,
0, src_height - corner_size,
dx, dy + dest_height - corner_size,
corner_size, corner_size,
GDK_RGB_DITHER_NORMAL, 0, 0);
/* draw bottom right corner */
gdk_draw_pixbuf (drawable, NULL, corner_pixbuf,
src_width - corner_size, src_height - corner_size,
dx + dest_width - corner_size, dy + dest_height - corner_size,
corner_size, corner_size,
GDK_RGB_DITHER_NORMAL, 0, 0);
}
static void
gnomecc_rounded_rect_class_init (GnomeccRoundedRectClass *klass)
{
GnomeCanvasItemClass *item_klass = (GnomeCanvasItemClass *) klass;
item_klass->draw = gnomecc_rounded_rect_draw;
}
static void
gnomecc_rounded_rect_init (GnomeccRoundedRect *rr)
{
}
|