cleanup code
git-svn-id: http://tint2.googlecode.com/svn/trunk@56 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
@@ -41,45 +41,51 @@ static char buf_time[40];
|
||||
static char buf_date[40];
|
||||
|
||||
|
||||
void init_clock(Clock *clock, Area *parent)
|
||||
void init_clock()
|
||||
{
|
||||
Panel *panel = (Panel *)parent;
|
||||
int time_height, time_height_ink, date_height, date_height_ink;
|
||||
Panel *panel;
|
||||
Clock *clock;
|
||||
int i, time_height, time_height_ink, date_height, date_height_ink;
|
||||
|
||||
clock->area.parent = parent;
|
||||
clock->area.panel = panel;
|
||||
if (!time1_format) return;
|
||||
for (i=0 ; i < nb_panel ; i++) {
|
||||
panel = &panel1[i];
|
||||
clock = &panel->clock;
|
||||
|
||||
clock->area._draw_foreground = draw_foreground_clock;
|
||||
clock->area._resize = resize_clock;
|
||||
clock->area.parent = panel;
|
||||
clock->area.panel = panel;
|
||||
if (!clock->area.visible) return;
|
||||
|
||||
if (strchr(time1_format, 'S') == NULL) time_precision = 60;
|
||||
else time_precision = 1;
|
||||
clock->area._draw_foreground = draw_foreground_clock;
|
||||
clock->area._resize = resize_clock;
|
||||
|
||||
// update clock to force update (-time_precision)
|
||||
struct timeval stv;
|
||||
gettimeofday(&stv, 0);
|
||||
time_clock.tv_sec = stv.tv_sec - time_precision;
|
||||
time_clock.tv_sec -= time_clock.tv_sec % time_precision;
|
||||
if (strchr(time1_format, 'S') == NULL) time_precision = 60;
|
||||
else time_precision = 1;
|
||||
|
||||
clock->area.posy = parent->pix.border.width + parent->paddingy;
|
||||
clock->area.height = parent->height - (2 * clock->area.posy);
|
||||
clock->area.resize = 1;
|
||||
clock->area.redraw = 1;
|
||||
// update clock to force update (-time_precision)
|
||||
struct timeval stv;
|
||||
gettimeofday(&stv, 0);
|
||||
time_clock.tv_sec = stv.tv_sec - time_precision;
|
||||
time_clock.tv_sec -= time_clock.tv_sec % time_precision;
|
||||
|
||||
strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec));
|
||||
if (time2_format)
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec));
|
||||
clock->area.posy = panel->area.pix.border.width + panel->area.paddingy;
|
||||
clock->area.height = panel->area.height - (2 * clock->area.posy);
|
||||
clock->area.resize = 1;
|
||||
clock->area.redraw = 1;
|
||||
|
||||
get_text_size(time1_font_desc, &time_height_ink, &time_height, parent->height, buf_time, strlen(buf_time));
|
||||
clock->time1_posy = (clock->area.height - time_height) / 2;
|
||||
strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec));
|
||||
if (time2_format)
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec));
|
||||
|
||||
if (time2_format) {
|
||||
get_text_size(time2_font_desc, &date_height_ink, &date_height, parent->height, buf_date, strlen(buf_date));
|
||||
get_text_size(time1_font_desc, &time_height_ink, &time_height, panel->area.height, buf_time, strlen(buf_time));
|
||||
clock->time1_posy = (clock->area.height - time_height) / 2;
|
||||
|
||||
clock->time1_posy -= ((date_height_ink + 2) / 2);
|
||||
clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2;
|
||||
}
|
||||
if (time2_format) {
|
||||
get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date));
|
||||
|
||||
clock->time1_posy -= ((date_height_ink + 2) / 2);
|
||||
clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user