Guitarix
gx_cairo_callbacks.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3  * Copyright (C) 2011 Pete Shorthose
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  * --------------------------------------------------------------------------
19  *
20  *
21  * This are the cairo callbacks to draw the guitarix UI
22  *
23  *
24  * --------------------------------------------------------------------------
25  */
26 
27 #include "guitarix.h"
28 
29 /* --------------------------- gx_cairo namespace ------------------------ */
30 namespace gx_cairo
31 {
32 
33 static void render (GtkWidget *wi, cairo_t* cr) {
34  GtkAllocation allocation;
35  gtk_widget_get_allocation(wi, &allocation);
36  double rect_width = allocation.width;
37  double rect_height = allocation.height;
38  double x0 = allocation.x;
39  double y0 = allocation.y;
40 
41  cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.0f);
42  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
43  cairo_paint (cr);
44 
45  string path = string(GX_PIXMAPS_DIR) + "/gx_splash.png";
46  cairo_surface_t *image = cairo_image_surface_create_from_png(path.c_str());
47  cairo_rectangle(cr, x0, y0, rect_width, rect_height);
48  cairo_set_source_surface(cr, image, 0, 0);
49  cairo_paint(cr);
50  cairo_surface_destroy (image);
51 }
52 
53 void make_transparency(GtkWidget* wi) {
54 
55  GtkAllocation allocation;
56  gtk_widget_get_allocation(wi, &allocation);
57  // get widget dimension
58  gint rect_width = allocation.width;
59  gint rect_height = allocation.height;
60 
61  // make Image to fake transparency
62  static GdkBitmap* ShapeBitmap = NULL;
63  static cairo_t* cr = NULL;
64 
65  ShapeBitmap = gdk_pixmap_new(NULL, rect_width, rect_height, 1);
66  if (ShapeBitmap) {
67  cr = gdk_cairo_create (ShapeBitmap);
68  if (cairo_status (cr) == CAIRO_STATUS_SUCCESS) {
69  render (wi, cr);
70  cairo_destroy (cr);
71  // make widget invisible
72  gtk_widget_shape_combine_mask (wi, NULL, 0, 0);
73  // set sharp mask to visible part
74  gtk_widget_shape_combine_mask (wi, ShapeBitmap, 0, 0);
75  }
76  g_object_unref(ShapeBitmap);
77  }
78 }
79 
80 gboolean splash_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
81 {
82  cairo_t* cr = NULL;
83  cr = gdk_cairo_create (gtk_widget_get_window(wi));
84  if (!cr) return FALSE;
85 
86  static bool ms = true;
87  if(ms) {
89  ms = false;
90  }
91  render (wi, cr);
92  cairo_destroy (cr);
93  return FALSE;
94 }
95 
96 gboolean rectangle_skin_color_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
97 {
98  cairo_t *cr;
99  /* create a cairo context */
100  cr = gdk_cairo_create(gtk_widget_get_window(wi));
101  GtkAllocation allocation;
102  gtk_widget_get_allocation(wi, &allocation);
103  GdkRegion *region;
104  region = gdk_region_rectangle (&allocation);
105  gdk_region_intersect (region, ev->region);
106  gdk_cairo_region (cr, region);
107  cairo_clip (cr);
108 
109  double x0 = allocation.x+2;
110  double y0 = allocation.y+2;
111  double rect_width = allocation.width-2;
112  double rect_height = allocation.height-2;
113 
114  cairo_rectangle (cr, x0,y0,rect_width,rect_height+1);
115  cairo_set_source_rgb (cr, 0, 0, 0);
116  cairo_fill (cr);
117 
118  cairo_pattern_t*pat =
119  cairo_pattern_create_linear (0, y0, 0, y0+rect_height);
120  //cairo_pattern_create_radial (-50, y0, 5,rect_width-10, rect_height, 20.0);
121  cairo_pattern_add_color_stop_rgba (pat, 0, 0.2, 0.2, 0.3, 0.6);
122  cairo_pattern_add_color_stop_rgba (pat, 1, 0.05, 0.05, 0.05, 0.6);
123  cairo_set_source (cr, pat);
124  cairo_rectangle (cr, x0+1,y0+1,rect_width-2,rect_height-1);
125  cairo_fill (cr);
126 
127  cairo_pattern_destroy (pat);
128  cairo_destroy(cr);
129  gdk_region_destroy (region);
130  return FALSE;
131 
132 }
133 
134 gboolean conv_widget_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
135 {
136  cairo_t *cr;
137  cairo_pattern_t *pat;
138 
139  /* create a cairo context */
140  cr = gdk_cairo_create(gtk_widget_get_window(wi));
141  GtkAllocation allocation;
142  gtk_widget_get_allocation(wi, &allocation);
143  GdkRegion *region;
144  region = gdk_region_rectangle (&allocation);
145  gdk_region_intersect (region, ev->region);
146  gdk_cairo_region (cr, region);
147  cairo_clip (cr);
148 
149  double x0 = allocation.x+5;
150  double y0 = allocation.y+5;
151  double rect_width = allocation.width-10;
152  double rect_height = allocation.height-10;
153  double radius = 36.;
154  double x1,y1;
155  x1=x0+rect_width;
156  y1=y0+rect_height;
157 
158  cairo_move_to (cr, x0, y0 + radius);
159  cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
160  cairo_line_to (cr, x1 - radius, y0);
161  cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
162  cairo_line_to (cr, x1 , y1 - radius);
163  cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
164  cairo_line_to (cr, x0 + radius, y1);
165  cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
166  cairo_close_path (cr);
167 
168  pat = cairo_pattern_create_linear (0, y0, 0, y1);
169  cairo_pattern_add_color_stop_rgba (pat, 1, 0., 0., 0., 0.8);
170  cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 0.4);
171  cairo_set_source (cr, pat);
172  cairo_fill_preserve (cr);
173 
174  cairo_set_source_rgba (cr, 0, 0, 0, 0.8);
175  cairo_set_line_width (cr, 9.0);
176  cairo_stroke (cr);
177 
178  cairo_move_to (cr, x0, y0 + radius);
179  cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
180  cairo_line_to (cr, x1 - radius, y0);
181  cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
182  cairo_line_to (cr, x1 , y1 - radius);
183  cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
184  cairo_line_to (cr, x0 + radius, y1);
185  cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
186  cairo_close_path (cr);
187 
188  cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
189  cairo_set_line_width (cr, 1.0);
190  cairo_stroke (cr);
191 
192  cairo_pattern_destroy (pat);
193  cairo_destroy(cr);
194  gdk_region_destroy (region);
195 
196  return FALSE;
197 }
198 
199 gboolean error_box_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
200 {
201  cairo_t *cr;
202  /* create a cairo context */
203  cr = gdk_cairo_create(gtk_widget_get_window(wi));
204  GtkAllocation allocation;
205  gtk_widget_get_allocation(wi, &allocation);
206  GdkRegion *region;
207  region = gdk_region_rectangle (&allocation);
208  gdk_region_intersect (region, ev->region);
209  gdk_cairo_region (cr, region);
210  cairo_clip (cr);
211 
212  double x0 = allocation.x;
213  double y0 = allocation.y;
214  double rect_width = allocation.width;
215  double rect_height = allocation.height;
216 
217  cairo_rectangle (cr, x0,y0,rect_width,rect_height);
218  cairo_set_source_rgb (cr, 0.22, 0.22, 0.22);
219  // cairo_set_line_width(cr, 2.0);
220  cairo_fill(cr);
221 
222  cairo_destroy(cr);
223  gdk_region_destroy (region);
224 
225  return FALSE;
226 }
227 
228 gboolean start_box_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
229 {
230  cairo_t *cr;
231  /* create a cairo context */
232  cr = gdk_cairo_create(gtk_widget_get_window(wi));
233  GtkAllocation allocation;
234  gtk_widget_get_allocation(wi, &allocation);
235  GdkRegion *region;
236  region = gdk_region_rectangle (&allocation);
237  gdk_region_intersect (region, ev->region);
238  gdk_cairo_region (cr, region);
239  cairo_clip (cr);
240 
241  double x0 = allocation.x+1;
242  double y0 = allocation.y+1;
243  double rect_width = allocation.width-2;
244  double rect_height = allocation.height-2;
245 
246  cairo_rectangle (cr, x0-1,y0-1,rect_width+2,rect_height+2);
247  cairo_set_source_rgb (cr, 0, 0, 0);
248  cairo_set_line_width(cr, 2.0);
249  cairo_stroke(cr);
250 
251  cairo_pattern_t*pat = cairo_pattern_create_linear (x0, y0+rect_height/2,x0, y0);
252  cairo_pattern_set_extend(pat, CAIRO_EXTEND_REFLECT);
253 
254  cairo_pattern_add_color_stop_rgba (pat, 0, 0.1, 0.1, 0.2, 0.6);
255  cairo_pattern_add_color_stop_rgba (pat, 1, 0.05, 0.05, 0.05, 0.6);
256 
257  cairo_set_source (cr, pat);
258  cairo_rectangle (cr, x0+2,y0+2,rect_width-4,rect_height-4);
259  cairo_fill (cr);
260 
261  cairo_rectangle (cr, x0+8,y0+31,rect_width-16,rect_height-75);
262  cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
263  cairo_set_line_width(cr, 2.0);
264  cairo_stroke_preserve(cr);
265  pat = cairo_pattern_create_linear (x0+8, y0+rect_height/2-37,x0, y0);
266  cairo_pattern_set_extend(pat, CAIRO_EXTEND_REFLECT);
267  cairo_pattern_add_color_stop_rgba (pat, 0, 0.2, 0.2, 0.3, 0.6);
268  cairo_pattern_add_color_stop_rgba (pat, 1, 0.05, 0.05, 0.05, 0.6);
269  cairo_set_source (cr, pat);
270  cairo_fill (cr);
271 
272  cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
273  cairo_set_line_width(cr, 2.0);
274  cairo_move_to(cr,x0+rect_width-3, y0+3);
275  cairo_line_to(cr, x0+rect_width-3, y0+rect_height-2);
276  cairo_line_to(cr, x0+2, y0+rect_height-2);
277  cairo_stroke(cr);
278 
279  cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
280  cairo_set_line_width(cr, 2.0);
281  cairo_move_to(cr,x0+3, y0+rect_height-1);
282  cairo_line_to(cr, x0+3, y0+3);
283  cairo_line_to(cr, x0+rect_width-3, y0+3);
284  cairo_stroke(cr);
285 
286  cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
287  cairo_set_line_width(cr, 1.5);
288  cairo_arc (cr, x0+7, y0+7, 1.5, 0, 2*M_PI);
289  cairo_move_to(cr,x0+rect_width-8, y0+7);
290  cairo_arc (cr, x0+rect_width-7, y0+7, 1.5, 0, 2*M_PI);
291  cairo_move_to(cr,x0+rect_width-7, y0+rect_height-6);
292  cairo_arc (cr, x0+rect_width-7, y0+rect_height-6, 1.5, 0, 2*M_PI);
293  cairo_move_to(cr,x0+7, y0+rect_height-6);
294  cairo_arc (cr, x0+7, y0+rect_height-6, 1.5, 0, 2*M_PI);
295  cairo_stroke_preserve(cr);
296  cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
297  cairo_fill (cr);
298 
299  cairo_pattern_destroy (pat);
300  cairo_destroy(cr);
301  gdk_region_destroy (region);
302 
303  return FALSE;
304 }
305 }
gx_cairo::error_box_expose
gboolean error_box_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
Definition: gx_cairo_callbacks.cpp:199
M_PI
#define M_PI
Definition: gx_internal_plugins.h:1170
gx_cairo::splash_expose
gboolean splash_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
Definition: gx_cairo_callbacks.cpp:80
gx_cairo::rectangle_skin_color_expose
gboolean rectangle_skin_color_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
Definition: gx_cairo_callbacks.cpp:96
gx_cairo::start_box_expose
gboolean start_box_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
Definition: gx_cairo_callbacks.cpp:228
gx_cairo::make_transparency
void make_transparency(GtkWidget *wi)
Definition: gx_cairo_callbacks.cpp:53
gx_cairo::conv_widget_expose
gboolean conv_widget_expose(GtkWidget *wi, GdkEventExpose *ev, gpointer user_data)
Definition: gx_cairo_callbacks.cpp:134
guitarix.h
gx_cairo
Definition: gx_cairo_callbacks.h:28