2016-01-28 22:55:45 +10:00

77 lines
1.7 KiB
C

#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "quinn.h"
#include "convertxpm.h"
#include "clock.xpm"
#include "clockicon.xpm"
#define PI 3.14159265
#define arg_sec PI/30
#define arg_hour PI/6
#define arg_min PI/360
void exit_callback(int wh) {
quinn_exit();
exit(0);
}
int main(int argc, char **argv) {
unsigned char *bmp;
unsigned char *icon;
unsigned char *surface;
int x, y;
time_t thetime;
struct tm *time_tm;
double lastminute = 0;
struct window_req_t *req;
int window_handle;
int close_req = 0;
quinn_init();
convert_xpm(clockicon_xpm, &icon);
convert_xpm(clock_xpm, &bmp);
req = (struct window_req_t *)malloc(sizeof(struct window_req_t));
req->x = 100;
req->y = 100;
req->width = 250;
req->height = 250;
req->icon = icon;
strcpy(req->name, "Clock");
window_handle = quinn_req_window(req, exit_callback);
free(req);
surface = quinn_add_surface(window_handle, 0, 0, 250, 250, NULL);
while (1) {
thetime = time(NULL);
time_tm = localtime(&thetime);
if (time_tm->tm_min != lastminute) {
quinn_render(surface, bmp, 250, 250, 0, 0, 250, 250);
quinn_draw_line(surface, 125, 125, (150 * cos(arg_sec * time_tm->tm_min - PI / 2) * 0.6) + 125, (150 * sin(arg_sec * time_tm->tm_min - PI / 2) * 0.6) + 125, 250, 250, 0xff0000);
quinn_draw_line(surface, 125, 125, (150 * cos(arg_hour * time_tm->tm_hour - PI / 2 + arg_min * time_tm->tm_min) * 0.3) + 125, (150 * sin(arg_hour * time_tm->tm_hour - PI / 2 + arg_min * time_tm->tm_min) * 0.3) + 125, 250, 250, 0x00ff00);
lastminute = time_tm->tm_min;
}
quinn_process();
quinn_yield();
}
free(icon);
free(bmp);
quinn_exit();
}