panel: Replace clock widget with recreation of classic theme

This commit is contained in:
K. Lange 2022-11-30 06:14:10 +09:00
parent ace54766fe
commit b10de37762
2 changed files with 38 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

View File

@ -10,34 +10,60 @@
#include <toaru/text.h>
#include <toaru/panel.h>
static struct MenuList * clockmenu;
static sprite_t * watchface = NULL;
static void watch_draw_line(gfx_context_t * ctx, int offset, double r, double a, double b, uint32_t color, float thickness) {
static void watch_draw_line(gfx_context_t * ctx, int offset, double r, double ir, double a, double b, uint32_t color, float thickness) {
double theta = (a / b) * 2.0 * M_PI;
draw_line_aa(ctx,
70 + 4,
70 + 4 + sin(theta) * r,
70 + offset,
70 + offset - cos(theta) * r, color, thickness);
struct gfx_point v = {74.0 + sin(theta) * ir, 70.0 + offset - cos(theta) * ir};
struct gfx_point w = {74.0 + sin(theta) * r, 70.0 + offset - cos(theta) * r};
draw_line_aa_points(ctx,&v,&w,color,thickness);
}
static double tick(double t) {
double ts = t*t;
double tc = ts*t;
return (0.5*tc*ts + -8.0*ts*ts + 20.0*tc + -19.0*ts + 7.5*t);
}
void _menu_draw_MenuEntry_Clock(gfx_context_t * ctx, struct MenuEntry * self, int offset) {
self->offset = offset;
draw_sprite(ctx, watchface, 4, offset);
/* Draw the background */
draw_rounded_rectangle(ctx, 4, offset, 140, 140, 70, rgb(0,0,0));
draw_rounded_rectangle(ctx, 6, offset + 2, 136, 136, 68, rgb(255,255,255));
for (int i = 0; i < 60; ++i) {
watch_draw_line(ctx, offset, 68, i % 5 ? 64 : 60, i, 60, rgb(0,0,0), i % 5 ? 0.5 : 1.0);
}
static const char * digits[] = {"12","1","2","3","4","5","6","7","8","9","10","11"};
tt_set_size(font, 12);
for (int i = 0; i < 12; ++i) {
int w = tt_string_width(font, digits[i]);
double theta = (i / 12.0) * 2.0 * M_PI;
double x = 74.0 + sin(theta) * 50.0;
double y = 70.0 + offset - cos(theta) * 50.0;
int _x = x - w / 2;
int _y = y + 6;
tt_draw_string(ctx, font, _x, _y, digits[i], rgb(0,0,0));
}
struct timeval now;
struct tm * timeinfo;
gettimeofday(&now, NULL);
timeinfo = localtime((time_t *)&now.tv_sec);
double sec = timeinfo->tm_sec + (double)now.tv_usec / 1000000.0;
double sec = timeinfo->tm_sec + tick((double)now.tv_usec / 1000000.0);
double min = timeinfo->tm_min + sec / 60.0;
double hour = (timeinfo->tm_hour % 12) + min / 60.0;
watch_draw_line(ctx, offset, 40, hour, 12, rgb(0,0,0), 2.0);
watch_draw_line(ctx, offset, 60, min, 60, rgb(0,0,0), 1.5);
watch_draw_line(ctx, offset, 65, sec, 60, rgb(240,0,0), 1.0);
watch_draw_line(ctx, offset, 40, 0, hour, 12, rgb(0,0,0), 2.0);
watch_draw_line(ctx, offset, 60, 0, min, 60, rgb(0,0,0), 1.5);
watch_draw_line(ctx, offset, 65, -4, sec, 60, rgb(240,0,0), 1.0);
}
@ -90,8 +116,6 @@ static int widget_update_clock(struct PanelWidget * this, int * force_updates) {
}
struct PanelWidget * widget_init_clock(void) {
watchface = malloc(sizeof(sprite_t));
load_sprite(watchface, "/usr/share/icons/watchface.png");
clockmenu = menu_create();
clockmenu->flags |= MENU_FLAG_BUBBLE_RIGHT;
menu_insert(clockmenu, menu_create_clock());