mirror of https://github.com/fairyglade/ly.git
Added a big clock
This commit is contained in:
parent
2ffb86213b
commit
13ca5d4a0a
|
|
@ -6,6 +6,8 @@
|
||||||
# 1 -> CMatrix
|
# 1 -> CMatrix
|
||||||
#animation = 0
|
#animation = 0
|
||||||
|
|
||||||
|
# Whether a big clock should be displayed
|
||||||
|
#clock = true
|
||||||
|
|
||||||
# The character used to mask the password
|
# The character used to mask the password
|
||||||
#asterisk = *
|
#asterisk = *
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,144 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define CLOCK_W 5
|
||||||
|
#define CLOCK_H 5
|
||||||
|
|
||||||
|
// #define X (char) 219 // block char
|
||||||
|
// #define _ (char) 032 // space
|
||||||
|
|
||||||
|
#define X 0x2593
|
||||||
|
#define _ 0x0000
|
||||||
|
|
||||||
|
#if CLOCK_W == 5 && CLOCK_H == 5
|
||||||
|
|
||||||
|
uint32_t CLOCK_0[] = {
|
||||||
|
X,X,X,X,X,
|
||||||
|
X,X,_,X,X,
|
||||||
|
X,X,_,X,X,
|
||||||
|
X,X,_,X,X,
|
||||||
|
X,X,X,X,X
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_1[] = {
|
||||||
|
_,_,_,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
_,_,_,X,X
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_2[] = {
|
||||||
|
X,X,X,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
X,X,X,X,X,
|
||||||
|
X,X,_,_,_,
|
||||||
|
X,X,X,X,X
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_3[] = {
|
||||||
|
X,X,X,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
X,X,X,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
X,X,X,X,X
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_4[] = {
|
||||||
|
X,X,_,X,X,
|
||||||
|
X,X,_,X,X,
|
||||||
|
X,X,X,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
_,_,_,X,X
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_5[] = {
|
||||||
|
X,X,X,X,X,
|
||||||
|
X,X,_,_,_,
|
||||||
|
X,X,X,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
X,X,X,X,X
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_6[] = {
|
||||||
|
X,X,X,X,X,
|
||||||
|
X,X,_,_,_,
|
||||||
|
X,X,X,X,X,
|
||||||
|
X,X,_,X,X,
|
||||||
|
X,X,X,X,X,
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_7[] = {
|
||||||
|
X,X,X,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
_,_,_,X,X
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_8[] = {
|
||||||
|
X,X,X,X,X,
|
||||||
|
X,X,_,X,X,
|
||||||
|
X,X,X,X,X,
|
||||||
|
X,X,_,X,X,
|
||||||
|
X,X,X,X,X
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_9[] = {
|
||||||
|
X,X,X,X,X,
|
||||||
|
X,X,_,X,X,
|
||||||
|
X,X,X,X,X,
|
||||||
|
_,_,_,X,X,
|
||||||
|
X,X,X,X,X
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_S[] = {
|
||||||
|
_,_,_,_,_,
|
||||||
|
_,_,X,_,_,
|
||||||
|
_,_,_,_,_,
|
||||||
|
_,_,X,_,_,
|
||||||
|
_,_,_,_,_
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t CLOCK_E[] = {
|
||||||
|
_,_,_,_,_,
|
||||||
|
_,_,_,_,_,
|
||||||
|
_,_,_,_,_,
|
||||||
|
_,_,_,_,_,
|
||||||
|
_,_,_,_,_
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef X
|
||||||
|
#undef _
|
||||||
|
|
||||||
|
static inline uint32_t* CLOCK_N(char c)
|
||||||
|
{
|
||||||
|
switch(c)
|
||||||
|
{
|
||||||
|
case '0':
|
||||||
|
return CLOCK_0;
|
||||||
|
case '1':
|
||||||
|
return CLOCK_1;
|
||||||
|
case '2':
|
||||||
|
return CLOCK_2;
|
||||||
|
case '3':
|
||||||
|
return CLOCK_3;
|
||||||
|
case '4':
|
||||||
|
return CLOCK_4;
|
||||||
|
case '5':
|
||||||
|
return CLOCK_5;
|
||||||
|
case '6':
|
||||||
|
return CLOCK_6;
|
||||||
|
case '7':
|
||||||
|
return CLOCK_7;
|
||||||
|
case '8':
|
||||||
|
return CLOCK_8;
|
||||||
|
case '9':
|
||||||
|
return CLOCK_9;
|
||||||
|
case ':':
|
||||||
|
return CLOCK_S;
|
||||||
|
default:
|
||||||
|
return CLOCK_E;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -163,6 +163,7 @@ void config_load(const char *cfg_path)
|
||||||
{"bg", &config.bg, config_handle_u8},
|
{"bg", &config.bg, config_handle_u8},
|
||||||
{"blank_box", &config.blank_box, config_handle_bool},
|
{"blank_box", &config.blank_box, config_handle_bool},
|
||||||
{"blank_password", &config.blank_password, config_handle_bool},
|
{"blank_password", &config.blank_password, config_handle_bool},
|
||||||
|
{"clock", &config.clock, config_handle_bool},
|
||||||
{"console_dev", &config.console_dev, config_handle_str},
|
{"console_dev", &config.console_dev, config_handle_str},
|
||||||
{"default_input", &config.default_input, config_handle_u8},
|
{"default_input", &config.default_input, config_handle_u8},
|
||||||
{"fg", &config.fg, config_handle_u8},
|
{"fg", &config.fg, config_handle_u8},
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ struct config
|
||||||
uint8_t bg;
|
uint8_t bg;
|
||||||
bool blank_box;
|
bool blank_box;
|
||||||
bool blank_password;
|
bool blank_password;
|
||||||
|
bool clock;
|
||||||
char* console_dev;
|
char* console_dev;
|
||||||
uint8_t default_input;
|
uint8_t default_input;
|
||||||
uint8_t fg;
|
uint8_t fg;
|
||||||
|
|
|
||||||
72
src/draw.c
72
src/draw.c
|
|
@ -5,6 +5,7 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
|
#include "bigclock.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
@ -14,7 +15,9 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#if defined(__DragonFly__) || defined(__FreeBSD__)
|
#if defined(__DragonFly__) || defined(__FreeBSD__)
|
||||||
#include <sys/kbio.h>
|
#include <sys/kbio.h>
|
||||||
|
|
@ -176,6 +179,75 @@ void draw_box(struct term_buf* buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* get_clock_string()
|
||||||
|
{
|
||||||
|
time_t timer;
|
||||||
|
char* buffer = malloc(6);
|
||||||
|
struct tm* tm_info;
|
||||||
|
|
||||||
|
timer = time(NULL);
|
||||||
|
tm_info = localtime(&timer);
|
||||||
|
|
||||||
|
strftime(buffer, 6, "%H:%M", tm_info);
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern inline uint32_t* CLOCK_N(char c);
|
||||||
|
|
||||||
|
struct tb_cell* clock_cell(char c)
|
||||||
|
{
|
||||||
|
struct tb_cell* cells = malloc(sizeof(struct tb_cell) * CLOCK_W * CLOCK_H);
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
if (config.animate && c == ':' && tv.tv_usec / 500000)
|
||||||
|
c = ' ';
|
||||||
|
uint32_t* clockchars = CLOCK_N(c);
|
||||||
|
|
||||||
|
for (int i = 0; i < CLOCK_W * CLOCK_H; i++)
|
||||||
|
{
|
||||||
|
cells[i].ch = clockchars[i];
|
||||||
|
cells[i].fg = config.fg;
|
||||||
|
cells[i].bg = config.bg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cells;
|
||||||
|
}
|
||||||
|
|
||||||
|
void alpha_blit(struct tb_cell* buf, int x, int y, int w, int h, struct tb_cell* cells)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < h; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < w; j++)
|
||||||
|
{
|
||||||
|
struct tb_cell cell = cells[i * w + j];
|
||||||
|
if (cell.ch)
|
||||||
|
buf[(y + i) * tb_width() + (x + j)] = cell;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_clock(struct term_buf* buf)
|
||||||
|
{
|
||||||
|
if (!config.clock)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int xo = buf->box_x + buf->box_width / 2 - (5 * (CLOCK_W + 1)) / 2;
|
||||||
|
int yo = buf->box_y - CLOCK_H - 2;
|
||||||
|
|
||||||
|
char* clockstr = get_clock_string();
|
||||||
|
struct tb_cell* clockcell;
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
clockcell = clock_cell(clockstr[i]);
|
||||||
|
alpha_blit(tb_cell_buffer(), xo + i * (CLOCK_W + 1), yo, CLOCK_W, CLOCK_H, clockcell);
|
||||||
|
free(clockcell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct tb_cell* strn_cell(char* s, uint16_t len) // throws
|
struct tb_cell* strn_cell(char* s, uint16_t len) // throws
|
||||||
{
|
{
|
||||||
struct tb_cell* cells = malloc((sizeof (struct tb_cell)) * len);
|
struct tb_cell* cells = malloc((sizeof (struct tb_cell)) * len);
|
||||||
|
|
|
||||||
|
|
@ -86,4 +86,6 @@ void animate_init(struct term_buf* buf);
|
||||||
void animate(struct term_buf* buf);
|
void animate(struct term_buf* buf);
|
||||||
bool cascade(struct term_buf* buf, uint8_t* fails);
|
bool cascade(struct term_buf* buf, uint8_t* fails);
|
||||||
|
|
||||||
|
void draw_clock(struct term_buf *buf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,7 @@ int main(int argc, char** argv)
|
||||||
(*input_handles[active_input])(input_structs[active_input], NULL);
|
(*input_handles[active_input])(input_structs[active_input], NULL);
|
||||||
tb_clear();
|
tb_clear();
|
||||||
animate(&buf);
|
animate(&buf);
|
||||||
|
draw_clock(&buf);
|
||||||
draw_box(&buf);
|
draw_box(&buf);
|
||||||
draw_labels(&buf);
|
draw_labels(&buf);
|
||||||
if(!config.hide_f1_commands)
|
if(!config.hide_f1_commands)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue