1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/* $Id$
*
* Jon's Binary Clock, GNOMEified
*
* Jon Anhold <jon@snoopy.net>
*
* Copyright(c) 1999 Jon Anhold, All Rights Reserved.
*
* This program is licensed under the GNU General Public License
*
* See COPYING for license text.
*
*/
#include <config.h>
#include <gnome.h>
#include <time.h>
#include <unistd.h>
#include <applet-widget.h>
#include "jbc-applet.h"
#define CANVAS_WIDTH 82
#define CANVAS_HEIGHT 50
GnomeCanvasItem *item[16];
GdkImlibImage *pix[16], *tpix[2];
struct tm atime;
time_t thetime;
int i;
int d[8];
static int digits[8] = {0, 0, 0, 0, 0, 0};
int blink = 0;
static int panel_size = 48;
static gboolean panel_vertical = FALSE;
static gint
about_jbc ()
{
GtkWidget *about;
const gchar *authors[2];
/* gchar version[32]; */
authors[0] = "Jon Anhold <jon@snoopy.net>";
authors[1] = NULL;
about = gnome_about_new (_("Jon's Binary Clock"),
VERSION,
_("(C) 1999"),
authors,
_("Released under the GNU general public license.\n"
"Displays time in Binary Coded Decimal\n"
"http://snoopy.net/~jon/jbc/."),
NULL);
gtk_widget_show (about);
return TRUE;
}
static gint
do_flicker ()
{
thetime = time (NULL);
localtime_r (&thetime, &atime);
d[0] = atime.tm_hour / 10;
d[1] = atime.tm_hour % 10;
d[3] = atime.tm_min / 10;
d[4] = atime.tm_min % 10;
d[6] = atime.tm_sec / 10;
d[7] = atime.tm_sec % 10;
if (d[7] != digits[7])
{
if (blink == 0)
{
gnome_canvas_item_set (item[2], "image", tpix[0], NULL);
gnome_canvas_item_set (item[5], "image", tpix[0], NULL);
blink = 1;
}
else
{
gnome_canvas_item_set (item[2], "image", tpix[1], NULL);
gnome_canvas_item_set (item[5], "image", tpix[1], NULL);
blink = 0;
}
}
for (i = 0; i < 8; ++i)
{
if (d[i] != digits[i])
{
if (i != 2 || i != 5)
{
gnome_canvas_item_set (item[i], "image", pix[d[i]], NULL);
digits[i] = d[i];
}
}
}
return 1;
}
static void
redo_size (GtkWidget *canvas)
{
int w, h;
double scale_factor;
if (panel_vertical) {
w = panel_size + 2;
h = (CANVAS_HEIGHT*w)/CANVAS_WIDTH;
scale_factor = (double)w / (double)CANVAS_WIDTH;
} else {
h = panel_size + 2;
w = (CANVAS_WIDTH*h)/CANVAS_HEIGHT;
scale_factor = (double)h / (double)CANVAS_HEIGHT;
}
gtk_widget_set_usize (canvas, w, h);
gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (canvas), scale_factor);
gnome_canvas_scroll_to (GNOME_CANVAS (canvas), 0.0, 0.0);
}
static void
change_pixel_size (GtkWidget *applet, int size, GtkWidget *canvas)
{
panel_size = size;
redo_size (canvas);
}
static void
change_orient (GtkWidget *applet, PanelOrientType o, GtkWidget *canvas)
{
if(o == ORIENT_UP ||
o == ORIENT_DOWN)
panel_vertical = FALSE;
else
panel_vertical = TRUE;
redo_size (canvas);
}
int
main (int argc, char **argv)
{
GtkWidget *applet;
GtkWidget *canvas;
int ytmp;
float xtmp = 0.0;
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
textdomain (PACKAGE);
applet_widget_init ("jbc_applet", VERSION, argc, argv, NULL, 0, NULL);
applet = applet_widget_new ("jbc_applet");
if (!applet)
g_error (_("Can't create applet!\n"));
canvas = gnome_canvas_new ();
gtk_widget_set_usize (canvas, CANVAS_WIDTH, CANVAS_HEIGHT);
gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0.0, 0.0, CANVAS_WIDTH, CANVAS_HEIGHT);
gtk_signal_connect (GTK_OBJECT (applet), "change_orient",
GTK_SIGNAL_FUNC (change_orient), canvas);
gtk_signal_connect (GTK_OBJECT (applet), "change_pixel_size",
GTK_SIGNAL_FUNC (change_pixel_size), canvas);
applet_widget_add (APPLET_WIDGET (applet), canvas);
gtk_widget_show (canvas);
gtk_widget_show (applet);
applet_widget_register_stock_callback (APPLET_WIDGET (applet),
"about",
GNOME_STOCK_MENU_ABOUT,
_("About..."),
(AppletCallbackFunc)about_jbc, NULL);
tpix[0] = gdk_imlib_create_image_from_xpm_data (tcolon_xpm);
tpix[1] = gdk_imlib_create_image_from_xpm_data (tbcolon_xpm);
pix[0] = gdk_imlib_create_image_from_xpm_data (t0_xpm);
pix[1] = gdk_imlib_create_image_from_xpm_data (t1_xpm);
pix[2] = gdk_imlib_create_image_from_xpm_data (t2_xpm);
pix[3] = gdk_imlib_create_image_from_xpm_data (t3_xpm);
pix[4] = gdk_imlib_create_image_from_xpm_data (t4_xpm);
pix[5] = gdk_imlib_create_image_from_xpm_data (t5_xpm);
pix[6] = gdk_imlib_create_image_from_xpm_data (t6_xpm);
pix[7] = gdk_imlib_create_image_from_xpm_data (t7_xpm);
pix[8] = gdk_imlib_create_image_from_xpm_data (t8_xpm);
pix[9] = gdk_imlib_create_image_from_xpm_data (t9_xpm);
ytmp = 25;
for (i = 0; i < 8; ++i)
{
if (i == 0)
{
xtmp = 6;
}
else if (i == 2 || i == 3 || i == 5 || i == 6)
{
xtmp = xtmp + 8.5;
}
else
{
xtmp = xtmp + 12;
}
if (i == 2 || i == 5)
{
item[i] = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)),
gnome_canvas_image_get_type (),
"image", tpix[0],
"x", (double) xtmp,
"y", (double) ytmp,
"width", (double) 5,
"height", (double) 50,
NULL);
}
else
{
item[i] = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)),
gnome_canvas_image_get_type (),
"image", pix[0],
"x", (double) xtmp,
"y", (double) ytmp,
"width", (double) 12,
"height", (double) 50,
NULL);
}
}
gtk_timeout_add (250, do_flicker, NULL);
applet_widget_gtk_main ();
return 0;
}
|