mp3splt-gtk: src/drawing_helper.c Source File

mp3splt-gtk 0.9.3.1519

Loading...
Searching...
No Matches
drawing_helper.c
1/**********************************************************
2 *
3 * mp3splt-gtk -- utility based on mp3splt,
4 * for mp3/ogg splitting without decoding
5 *
6 * Copyright: (C) 2005-2014 Alexandru Munteanu
7 * Contact: m@ioalex.net
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 * USA.
29 *
30 *********************************************************/
31
32#include "drawing_helper.h"
33
34void dh_set_color(cairo_t *cairo, GdkColor *color)
35{
36 GdkRGBA rgba_color;
37 rgba_color.red = ((double) color->red) / 65535.0;
38 rgba_color.green = ((double) color->green) / 65535.0;
39 rgba_color.blue = ((double) color->blue) / 65535.0;
40 rgba_color.alpha = 1.0;
41 gdk_cairo_set_source_rgba(cairo, &rgba_color);
42}
43
44void dh_set_white_color(cairo_t *cairo_surface)
45{
46 GdkColor color;
47 color.red = 255 * 255;color.green = 255 * 255;color.blue = 255 * 255;
48 dh_set_color(cairo_surface, &color);
49}
50
51void dh_set_red_color(cairo_t *cairo_surface)
52{
53 GdkColor color;
54 color.red = 255 * 255;color.green = 0 * 255;color.blue = 0 * 255;
55 dh_set_color(cairo_surface, &color);
56}
57
58void dh_draw_rectangle(cairo_t *cairo, gboolean filled, gint x, gint y,
59 gint width, gint height)
60{
61 cairo_rectangle(cairo, x, y, width, height);
62
63 if (filled)
64 {
65 cairo_fill(cairo);
66 }
67
68 cairo_stroke(cairo);
69}
70
71void dh_draw_arc(cairo_t *cairo, gboolean filled, gint x, gint y,
72 double radius, double angle1, double angle2)
73{
74 cairo_arc(cairo, x, y, radius, angle1, angle2);
75
76 if (filled)
77 {
78 cairo_fill(cairo);
79 }
80
81 cairo_stroke(cairo);
82}
83
84void dh_draw_text(cairo_t *cairo, const gchar *text, gint x, gint y)
85{
86 dh_draw_text_with_size(cairo, text, x, y, 11.0);
87}
88
89void dh_draw_text_with_size(cairo_t *cairo, const gchar *text, gint x, gint y,
90 gdouble font_size)
91{
92 cairo_select_font_face(cairo, "Sans 11", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
93 cairo_set_font_size(cairo, font_size);
94
95 cairo_move_to(cairo, x, y + 13);
96 cairo_show_text(cairo, text);
97}
98
99void dh_draw_line_with_width(cairo_t *cairo, gint x1, gint y1, gint x2, gint y2,
100 gboolean line_is_dashed, gboolean stroke, double line_width)
101{
102 double dashes[] = { 1.0, 3.0 };
103 if (line_is_dashed)
104 {
105 cairo_set_dash(cairo, dashes, 2, -50.0);
106 }
107 else
108 {
109 cairo_set_dash(cairo, dashes, 0, 0.0);
110 }
111
112 cairo_set_line_width(cairo, line_width);
113 cairo_set_line_cap(cairo, CAIRO_LINE_CAP_ROUND);
114 cairo_move_to(cairo, x1, y1);
115 cairo_line_to(cairo, x2, y2);
116
117 if (stroke)
118 {
119 cairo_stroke(cairo);
120 }
121}
122
123void dh_draw_line(cairo_t *cairo, gint x1, gint y1, gint x2, gint y2,
124 gboolean line_is_dashed, gboolean stroke)
125{
126 dh_draw_line_with_width(cairo, x1, y1, x2, y2, line_is_dashed, stroke, 1.2);
127}
128
129void draw_point(cairo_t *cairo, gint x, gint y)
130{
131 dh_draw_line(cairo, x, y, x, y, FALSE, FALSE);
132}
133
134