All pastes #163101 Raw Edit

Anonymous

public c v1 · immutable
·published 2006-09-07 04:41 UTC
rendered paste body
#include <stdio.h>#include <dirent.h>#include <ttk.h>#include "izilla.h"#include "menu_bar.h"//Function Prototypesvoid ttk_new_clock_widget(int x, int y, int w, int h, TWidget * menubar);void check_time(TWidget * wid);void ttk_draw_clock_widget(TWidget * wid, ttk_surface srf);void ttk_destroy_clock_widget(TWidget * wid);//Structstypedef struct ttk_clockdata{	struct tm time;} ttk_clockdata;//Function Definitionsvoid ttk_new_clock_widget(int x, int y, int w, int h, TWidget * menubar){	ttk_clockdata * cd;	TWidget * ret = ttk_new_widget(x,y);	time_t rawtime = time();	struct tm * timeinfo = localtime(&rawtime);	ret->w = w;	ret->h = h;	ret->draw = ttk_draw_clock_widget;	ret->timer = check_time;	ret->destroy = ttk_destroy_clock_widget;	cd = ttk_new_clockdata();	ret->data = (void *)cd;	ttk_add_menubar_widget(menubar, ret);}//This checks to see if the time has changed, and if so, will redraw the clock.void check_time(TWidget * wid){	TWidget * menubar = (TWidget *)wid->data2;	ttk_clockdata * cd = (ttk_clockdata *)wid->data;	struct tm * timeinfo = (struct tm *)cd->time;	time_t rawtime = time();	struct tm * check = localtime(&rawtime);	if((check->tm_hour != timeinfo->tm_hour) || (check->tm_min != timeinfo->tm_min))	{		cd->time = check;		ttk_draw_clock_widget(wid, menubar->win->srf);	}}void ttk_draw_clock_widget(TWidget * wid, ttk_surface srf){	char time[5];	TWidget * menubar = (TWidget *)wid->data2;	struct tm * timeinfo = (struct tm *)wid->data;	snprintf(time, 200, "%2d:%02d", timeinfo->tm_hour, timeinfo->tm_min);	int text_height = ttk_text_height(font->f);	int text_width = ttk_text_width(font->f, time);	ttk_blit_image_ex(menubar->win->srf, wid->x, wid->y, wid->w, wid->h, ttk_screen->srf, wid->x, wid->y);	ttk_text(menubar->win->srf, font->f, (wid->x - text_width)/2, (wid->y - text_height)/2,			 ttk_ap_getx("menu-bar.fg")->color, time);}ttk_clockdata ttk_new_clockdata(void){	ttk_clockdata * cd = (ttk_clockdata *)calloc(1, sizeof(ttk_clockdata));	time_t rawtime = time();	struct tm * t = localtime(&rawtime);	cd->time = &t;	return cd;}void ttk_destroy_clock_widget(TWidget * wid){	ttk_free_widget(wid);}