mp3splt-gtk
drawing_helper.c
1 /**********************************************************
2  *
3  * mp3splt-gtk -- utility based on mp3splt,
4  * for mp3/ogg splitting without decoding
5  *
6  * Copyright: (C) 2005-2012 Alexandru Munteanu
7  * Contact: io_fx@yahoo.fr
8  *
9  * http://mp3splt.sourceforge.net/
10  *
11  *********************************************************/
12 
13 /**********************************************************
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28  * USA.
29  *
30  *********************************************************/
31 
32 #include "drawing_helper.h"
33 
34 void dh_set_color(cairo_t *cairo, GdkColor *color)
35 {
36  gdk_cairo_set_source_color(cairo, color);
37 }
38 
39 void dh_set_white_color(cairo_t *cairo_surface)
40 {
41  GdkColor color;
42  color.red = 255 * 255;color.green = 255 * 255;color.blue = 255 * 255;
43  dh_set_color(cairo_surface, &color);
44 }
45 
46 void dh_set_red_color(cairo_t *cairo_surface)
47 {
48  GdkColor color;
49  color.red = 255 * 255;color.green = 0 * 255;color.blue = 0 * 255;
50  dh_set_color(cairo_surface, &color);
51 }
52 
53 void dh_draw_rectangle(cairo_t *cairo, gboolean filled, gint x, gint y,
54  gint width, gint height)
55 {
56  cairo_rectangle(cairo, x, y, width, height);
57 
58  if (filled)
59  {
60  cairo_fill(cairo);
61  }
62 
63  cairo_stroke(cairo);
64 }
65 
66 void dh_draw_arc(cairo_t *cairo, gboolean filled, gint x, gint y,
67  double radius, double angle1, double angle2)
68 {
69  cairo_arc(cairo, x, y, radius, angle1, angle2);
70 
71  if (filled)
72  {
73  cairo_fill(cairo);
74  }
75 
76  cairo_stroke(cairo);
77 }
78 
79 void dh_draw_text(cairo_t *cairo, const gchar *text, gint x, gint y)
80 {
81  dh_draw_text_with_size(cairo, text, x, y, 11.0);
82 }
83 
84 void dh_draw_text_with_size(cairo_t *cairo, const gchar *text, gint x, gint y,
85  gdouble font_size)
86 {
87  cairo_select_font_face(cairo, "Sans 11", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
88  cairo_set_font_size(cairo, font_size);
89 
90  cairo_move_to(cairo, x, y + 13);
91  cairo_show_text(cairo, text);
92 }
93 
94 void dh_draw_line_with_width(cairo_t *cairo, gint x1, gint y1, gint x2, gint y2,
95  gboolean line_is_dashed, gboolean stroke, double line_width)
96 {
97  double dashes[] = { 1.0, 3.0 };
98  if (line_is_dashed)
99  {
100  cairo_set_dash(cairo, dashes, 2, -50.0);
101  }
102  else
103  {
104  cairo_set_dash(cairo, dashes, 0, 0.0);
105  }
106 
107  cairo_set_line_width(cairo, line_width);
108  cairo_set_line_cap(cairo, CAIRO_LINE_CAP_ROUND);
109  cairo_move_to(cairo, x1, y1);
110  cairo_line_to(cairo, x2, y2);
111 
112  if (stroke)
113  {
114  cairo_stroke(cairo);
115  }
116 }
117 
118 void dh_draw_line(cairo_t *cairo, gint x1, gint y1, gint x2, gint y2,
119  gboolean line_is_dashed, gboolean stroke)
120 {
121  dh_draw_line_with_width(cairo, x1, y1, x2, y2, line_is_dashed, stroke, 1.2);
122 }
123 
124 void draw_point(cairo_t *cairo, gint x, gint y)
125 {
126  dh_draw_line(cairo, x, y, x, y, FALSE, FALSE);
127 }
128 
129