~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to tests/testcairo.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* testimage.c
 
2
 * Copyright (C) 2005  Red Hat, Inc.
 
3
 * Based on cairo-demo/X11/cairo-knockout.c
 
4
 *
 
5
 * Author: Owen Taylor
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Library General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Library General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Library General Public
 
18
 * License along with this library; if not, write to the
 
19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#include <math.h>
 
24
 
 
25
#include <gtk/gtk.h>
 
26
 
 
27
static void
 
28
oval_path (cairo_t *cr,
 
29
           double xc, double yc,
 
30
           double xr, double yr)
 
31
{
 
32
  cairo_save (cr);
 
33
 
 
34
  cairo_translate (cr, xc, yc);
 
35
  cairo_scale (cr, 1.0, yr / xr);
 
36
  cairo_move_to (cr, xr, 0.0);
 
37
  cairo_arc (cr,
 
38
             0, 0,
 
39
             xr,
 
40
             0, 2 * G_PI);
 
41
  cairo_close_path (cr);
 
42
 
 
43
  cairo_restore (cr);
 
44
}
 
45
 
 
46
/* Create a path that is a circular oval with radii xr, yr at xc,
 
47
 * yc.
 
48
 */
 
49
/* Fill the given area with checks in the standard style
 
50
 * for showing compositing effects.
 
51
 *
 
52
 * It would make sense to do this as a repeating surface,
 
53
 * but most implementations of RENDER currently have broken
 
54
 * implementations of repeat + transform, even when the
 
55
 * transform is a translation.
 
56
 */
 
57
static void
 
58
fill_checks (cairo_t *cr,
 
59
             int x,     int y,
 
60
             int width, int height)
 
61
{
 
62
  int i, j;
 
63
  
 
64
#define CHECK_SIZE 32
 
65
 
 
66
  cairo_rectangle (cr, x, y, width, height);
 
67
  cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
 
68
  cairo_fill (cr);
 
69
 
 
70
  /* Only works for CHECK_SIZE a power of 2 */
 
71
  j = x & (-CHECK_SIZE);
 
72
  
 
73
  for (; j < height; j += CHECK_SIZE)
 
74
    {
 
75
      i = y & (-CHECK_SIZE);
 
76
      for (; i < width; i += CHECK_SIZE)
 
77
        if ((i / CHECK_SIZE + j / CHECK_SIZE) % 2 == 0)
 
78
          cairo_rectangle (cr, i, j, CHECK_SIZE, CHECK_SIZE);
 
79
    }
 
80
 
 
81
  cairo_set_source_rgb (cr, 0.7, 0.7, 0.7);
 
82
  cairo_fill (cr);
 
83
}
 
84
 
 
85
/* Draw a red, green, and blue circle equally spaced inside
 
86
 * the larger circle of radius r at (xc, yc)
 
87
 */
 
88
static void
 
89
draw_3circles (cairo_t *cr,
 
90
               double xc, double yc,
 
91
               double radius,
 
92
               double alpha)
 
93
{
 
94
  double subradius = radius * (2 / 3. - 0.1);
 
95
    
 
96
  cairo_set_source_rgba (cr, 1., 0., 0., alpha);
 
97
  oval_path (cr,
 
98
             xc + radius / 3. * cos (G_PI * (0.5)),
 
99
             yc - radius / 3. * sin (G_PI * (0.5)),
 
100
             subradius, subradius);
 
101
  cairo_fill (cr);
 
102
    
 
103
  cairo_set_source_rgba (cr, 0., 1., 0., alpha);
 
104
  oval_path (cr,
 
105
             xc + radius / 3. * cos (G_PI * (0.5 + 2/.3)),
 
106
             yc - radius / 3. * sin (G_PI * (0.5 + 2/.3)),
 
107
             subradius, subradius);
 
108
  cairo_fill (cr);
 
109
    
 
110
  cairo_set_source_rgba (cr, 0., 0., 1., alpha);
 
111
  oval_path (cr,
 
112
             xc + radius / 3. * cos (G_PI * (0.5 + 4/.3)),
 
113
             yc - radius / 3. * sin (G_PI * (0.5 + 4/.3)),
 
114
             subradius, subradius);
 
115
  cairo_fill (cr);
 
116
}
 
117
 
 
118
static void
 
119
draw (cairo_t *cr,
 
120
      int      width,
 
121
      int      height)
 
122
{
 
123
  cairo_surface_t *overlay, *punch, *circles;
 
124
  cairo_t *overlay_cr, *punch_cr, *circles_cr;
 
125
 
 
126
  /* Fill the background */
 
127
  double radius = 0.5 * (width < height ? width : height) - 10;
 
128
  double xc = width / 2.;
 
129
  double yc = height / 2.;
 
130
 
 
131
  overlay = cairo_surface_create_similar (cairo_get_target (cr),
 
132
                                          CAIRO_CONTENT_COLOR_ALPHA,
 
133
                                          width, height);
 
134
  if (overlay == NULL)
 
135
    return;
 
136
 
 
137
  punch = cairo_surface_create_similar (cairo_get_target (cr),
 
138
                                        CAIRO_CONTENT_ALPHA,
 
139
                                        width, height);
 
140
  if (punch == NULL)
 
141
    return;
 
142
 
 
143
  circles = cairo_surface_create_similar (cairo_get_target (cr),
 
144
                                          CAIRO_CONTENT_COLOR_ALPHA,
 
145
                                          width, height);
 
146
  if (circles == NULL)
 
147
    return;
 
148
    
 
149
  fill_checks (cr, 0, 0, width, height);
 
150
 
 
151
  /* Draw a black circle on the overlay
 
152
   */
 
153
  overlay_cr = cairo_create (overlay);
 
154
  cairo_set_source_rgb (overlay_cr, 0., 0., 0.);
 
155
  oval_path (overlay_cr, xc, yc, radius, radius);
 
156
  cairo_fill (overlay_cr);
 
157
 
 
158
  /* Draw 3 circles to the punch surface, then cut
 
159
   * that out of the main circle in the overlay
 
160
   */
 
161
  punch_cr = cairo_create (punch);
 
162
  draw_3circles (punch_cr, xc, yc, radius, 1.0);
 
163
  cairo_destroy (punch_cr);
 
164
 
 
165
  cairo_set_operator (overlay_cr, CAIRO_OPERATOR_DEST_OUT);
 
166
  cairo_set_source_surface (overlay_cr, punch, 0, 0);
 
167
  cairo_paint (overlay_cr);
 
168
 
 
169
  /* Now draw the 3 circles in a subgroup again
 
170
   * at half intensity, and use OperatorAdd to join up
 
171
   * without seams.
 
172
   */
 
173
  circles_cr = cairo_create (circles);
 
174
  
 
175
  cairo_set_operator (circles_cr, CAIRO_OPERATOR_OVER);
 
176
  draw_3circles (circles_cr, xc, yc, radius, 0.5);
 
177
  cairo_destroy (circles_cr);
 
178
 
 
179
  cairo_set_operator (overlay_cr, CAIRO_OPERATOR_ADD);
 
180
  cairo_set_source_surface (overlay_cr, circles, 0, 0);
 
181
  cairo_paint (overlay_cr);
 
182
 
 
183
  cairo_destroy (overlay_cr);
 
184
 
 
185
  cairo_set_source_surface (cr, overlay, 0, 0);
 
186
  cairo_paint (cr);
 
187
 
 
188
  cairo_surface_destroy (overlay);
 
189
  cairo_surface_destroy (punch);
 
190
  cairo_surface_destroy (circles);
 
191
}
 
192
 
 
193
static gboolean
 
194
on_expose_event (GtkWidget      *widget,
 
195
                 GdkEventExpose *event,
 
196
                 gpointer        data)
 
197
{
 
198
  cairo_t *cr;
 
199
 
 
200
  cr = gdk_cairo_create (widget->window);
 
201
 
 
202
  draw (cr, widget->allocation.width, widget->allocation.height);
 
203
 
 
204
  cairo_destroy (cr);
 
205
 
 
206
  return FALSE;
 
207
}
 
208
 
 
209
int
 
210
main (int argc, char **argv)
 
211
{
 
212
  GtkWidget *window, *darea;
 
213
 
 
214
  gtk_init (&argc, &argv);
 
215
 
 
216
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
217
  
 
218
  gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
 
219
  gtk_window_set_title (GTK_WINDOW (window), "cairo: Knockout Groups");
 
220
 
 
221
  darea = gtk_drawing_area_new ();
 
222
  gtk_container_add (GTK_CONTAINER (window), darea);
 
223
 
 
224
  g_signal_connect (darea, "expose-event",
 
225
                    G_CALLBACK (on_expose_event), NULL);
 
226
  g_signal_connect (window, "destroy-event",
 
227
                    G_CALLBACK (gtk_main_quit), NULL);
 
228
 
 
229
  gtk_widget_show_all (window);
 
230
  
 
231
  gtk_main ();
 
232
 
 
233
  return 0;
 
234
}