2
* TICKR - GTK-based Feed Reader - Copyright (C) Emmanuel Thomas-Maurin 2009-2011
3
* <manutm007@gmail.com>
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 3 of the License, or
8
* (at your option) any later version.
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.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
extern FILE *stdout_fp, *stderr_fp;
25
#define TIME_STR "|%c%c:%c%c:%c%c" /* at right = "|00:00:00" */
26
#define TIME_STR_LENGTH 9
28
void display_time(const Params *prm)
30
TickerEnv *env = get_ticker_env();
31
PangoLayout *p_layout;
32
PangoFontDescription *f_des;
33
int layout_width, layout_height;
34
cairo_surface_t *surf_clock;
41
if (prm->clock == 'l' || prm->clock == 'r') {
42
if ((p_layout = pango_layout_new(gtk_widget_get_pango_context(env->win))) == NULL)
44
pango_layout_set_attributes(p_layout, NULL);
45
pango_layout_set_single_paragraph_mode(p_layout, TRUE);
46
f_des = pango_font_description_from_string((const char *)prm->clock_font_n_s);
47
pango_layout_set_font_description(p_layout, f_des);
48
pango_font_description_free(f_des);
51
if (prm->clock == 'l') {
52
str_n_cpy(tmp, ctime(&time2) + 11, 8);
53
str_n_cat(tmp, "|", 1);
54
} else if (prm->clock == 'r') {
55
str_n_cpy(tmp, "|", 1);
56
str_n_cat(tmp, ctime(&time2) + 11, 8);
59
pango_layout_set_text(p_layout, tmp, -1);
60
pango_layout_context_changed(p_layout);
61
pango_layout_get_pixel_size2(p_layout, &layout_width, &layout_height);
63
env->drwa_clock_width = get_clock_width(prm); /* v_diff */
65
* for some fonts like 'impact bold' which give strange things
66
* v_diff = drwa_clock_width - layout_width;
68
gtk_widget_set_size_request(env->drwa_clock, env->drwa_clock_width, env->drwa_height);
69
h_diff = (env->drwa_height - (gint)layout_height) / 2;
71
* create cairo image surface onto which layout will be rendered
73
surf_clock = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
74
env->drwa_clock_width, env->drwa_height);
75
cr = cairo_create(surf_clock);
78
* (are used cairo operators ok ?)
81
cairo_set_source_rgba(cr,
82
(float)prm->clock_bg_color.red / G_MAXUINT16,
83
(float)prm->clock_bg_color.green / G_MAXUINT16,
84
(float)prm->clock_bg_color.blue / G_MAXUINT16,
85
(float)prm->clock_bg_color_alpha / G_MAXUINT16
87
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
90
if (prm->shadow == 'y') {
92
if (prm->shadow_fx < 0)
94
else if (prm->shadow_fx > 10)
97
shadow_k = 1.0 - (float)prm->shadow_fx / 10.0;
98
cairo_set_source_rgba(cr,
99
(float)prm->clock_bg_color.red * shadow_k / G_MAXUINT16,
100
(float)prm->clock_bg_color.green * shadow_k / G_MAXUINT16,
101
(float)prm->clock_bg_color.blue * shadow_k / G_MAXUINT16,
102
(float)prm->clock_bg_color_alpha * shadow_k / G_MAXUINT16);
103
pango_cairo_update_layout(cr, p_layout);
104
cairo_move_to(cr, prm->shadow_offset_x, prm->shadow_offset_y);
105
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
106
pango_cairo_show_layout(cr, p_layout);
109
cairo_set_source_rgba(cr,
110
(float)prm->clock_fg_color.red / G_MAXUINT16,
111
(float)prm->clock_fg_color.green / G_MAXUINT16,
112
(float)prm->clock_fg_color.blue / G_MAXUINT16,
113
(float)prm->clock_fg_color_alpha / G_MAXUINT16);
114
pango_cairo_update_layout(cr, p_layout);
115
cairo_move_to(cr, 0, 0);
116
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
117
pango_cairo_show_layout(cr, p_layout);
119
if (p_layout != NULL)
120
g_object_unref(p_layout);
122
/* draw onto clock area
123
* (we now use cairo instead of deprecated gdk_draw_sth)
125
cr = gdk_cairo_create(GDK_DRAWABLE((env->drwa_clock)->window));
126
cairo_set_source_surface(cr, surf_clock, 0, h_diff);
127
cairo_rectangle(cr, 0, 0, env->drwa_clock_width, env->drwa_height);
128
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
131
cairo_surface_destroy(surf_clock);
135
/* actually clock max width */
136
gint get_clock_width(const Params *prm)
138
static char clock_font_n_s_bak[FONT_MAXLEN + 1] = "";
139
static gint width = 0;
140
PangoLayout *p_layout;
141
PangoFontDescription *f_des;
142
int layout_width, layout_height, layout_max_width = 0;
146
if (prm->clock == 'l' || prm->clock == 'r') {
147
if (strcmp(prm->clock_font_n_s, clock_font_n_s_bak) != 0 || width == 0) {
148
str_n_cpy(clock_font_n_s_bak, prm->clock_font_n_s, FONT_MAXLEN);
150
p_layout = pango_layout_new(gtk_widget_get_pango_context(get_ticker_env()->win));
151
pango_layout_set_attributes(p_layout, NULL);
152
pango_layout_set_single_paragraph_mode(p_layout, TRUE);
153
f_des = pango_font_description_from_string((const char *)prm->clock_font_n_s);
154
pango_layout_set_font_description(p_layout, f_des);
155
pango_font_description_free(f_des);
157
for (i = '0'; i <= '9'; i++) {
158
snprintf(tmp, TIME_STR_LENGTH + 1, TIME_STR, i, i, i, i, i, i);
159
pango_layout_set_text(p_layout, tmp, -1);
160
pango_layout_context_changed(p_layout);
161
pango_layout_get_pixel_size2(p_layout, &layout_width, &layout_height);
162
if (layout_width > layout_max_width)
163
layout_max_width = layout_width;
166
if (p_layout != NULL)
167
g_object_unref(p_layout);
168
width = (gint)layout_max_width;
171
width = 0; /* return 0 although if clock = none, actual widget width = 1 */