|
|
|
|
@ -1,17 +1,149 @@
|
|
|
|
|
#include "segment_renderer.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#define debug(x) printf("DEBUG: %s\n", (x))
|
|
|
|
|
#define SCALE 16
|
|
|
|
|
|
|
|
|
|
extern int windowHeight;
|
|
|
|
|
extern int windowWidth;
|
|
|
|
|
extern char *time_unparse(char *buffer, size_t len, struct timespec *ts);
|
|
|
|
|
|
|
|
|
|
scroller *create_scroller(int c, segment_list sl) {
|
|
|
|
|
//txt funcs
|
|
|
|
|
text *txt_new(char *s, int length) {
|
|
|
|
|
text *t = calloc(1, sizeof(text));
|
|
|
|
|
t->string = calloc(length, sizeof(char));
|
|
|
|
|
t->length = length;
|
|
|
|
|
t->color = WHITE;
|
|
|
|
|
t->font = font;
|
|
|
|
|
txt_set(t, s);
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txt_set(text *t, char *s) {
|
|
|
|
|
memcpy(t->string, s, t->length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txt_free(text *t) {
|
|
|
|
|
free(t->string);
|
|
|
|
|
free(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txt_draw(text *t) {
|
|
|
|
|
DrawTextEx(t->font, t->string, t->pos, t->font.baseSize/SCALE, 1, t->color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txt_print(text *t) {
|
|
|
|
|
//printf("%p\n", t->string);
|
|
|
|
|
printf("%s\n", t->string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txt_color(text *t, Color color) {
|
|
|
|
|
t->color = color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txt_pos(text *t, Vector2 pos) {
|
|
|
|
|
t->pos = pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//left justify a column
|
|
|
|
|
void txt_left(text *t) {
|
|
|
|
|
Vector2 m = MeasureTextEx(t->font, t->string, t->font.baseSize/SCALE, 1);
|
|
|
|
|
t->pos = (Vector2) {
|
|
|
|
|
.x = windowWidth - m.x - 5, //minus 5 pixels so it looks nice
|
|
|
|
|
.y = t->pos.y,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txt_clear(text *t) {
|
|
|
|
|
memset(t->string, 0, t->length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int txt_len(text *t) {
|
|
|
|
|
return strlen(t->string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int txt_width(text *t) {
|
|
|
|
|
Vector2 m = MeasureTextEx(t->font, t->string, t->font.baseSize/SCALE, 1);
|
|
|
|
|
return m.x;
|
|
|
|
|
}
|
|
|
|
|
//text column funcs
|
|
|
|
|
text_column *txtcol_new(int count, int length) {
|
|
|
|
|
text_column *tc = calloc(1, sizeof(text_column));
|
|
|
|
|
tc->count = count;
|
|
|
|
|
tc->pos = (Vector2){0,0};
|
|
|
|
|
tc->column = calloc(tc->count, sizeof(*tc->column));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
tc->column[i] = txt_new("new", length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
text *txtcol_get(text_column *tc, int idx) {
|
|
|
|
|
return tc->column[idx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txtcol_set(text_column *tc, char *txt, int idx) {
|
|
|
|
|
txt_set(tc->column[idx], txt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txtcol_free(text_column *tc) {
|
|
|
|
|
for (int i = 0; i < tc->count; i++) {
|
|
|
|
|
txt_free(tc->column[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(tc->column);
|
|
|
|
|
free(tc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void txtcol_op(text_column *tc, void (*op)(text *)) {
|
|
|
|
|
for (int i = 0; i < tc->count; i++) {
|
|
|
|
|
op(tc->column[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int txtcol_longest(text_column *tc) {
|
|
|
|
|
int longest = 0;
|
|
|
|
|
int longidx, len;
|
|
|
|
|
for (int i = 0; i < tc->count; i++) {
|
|
|
|
|
len = txt_len(tc->column[i]);
|
|
|
|
|
if (longest < len) {
|
|
|
|
|
longest = len;
|
|
|
|
|
longidx = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return longidx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//returns the width of the widest string
|
|
|
|
|
int txtcol_widest(text_column *tc) {
|
|
|
|
|
int widest = 0;
|
|
|
|
|
for (int i = 0; i < tc->count; i++) {
|
|
|
|
|
int width = txt_width(tc->column[i]);
|
|
|
|
|
if (widest < width) {
|
|
|
|
|
widest = width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return widest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//put one column adjacent to another
|
|
|
|
|
void txtcol_adjacent(text_column *tc1, text_column *tc2, int offset) {
|
|
|
|
|
Vector2 m = MeasureTextEx(tc1->column[0]->font, tc1->column[txtcol_longest(tc1)]->string, tc1->column[0]->font.baseSize/SCALE, 1);
|
|
|
|
|
tc2->pos.x = tc1->pos.x + m.x + offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//left justify a txtcol
|
|
|
|
|
|
|
|
|
|
//scroller funcs
|
|
|
|
|
scroller *scroll_new(int c, text_column *tc) {
|
|
|
|
|
scroller *s = calloc(1, sizeof(*s));
|
|
|
|
|
s->sl = sl;
|
|
|
|
|
s->txtcol = tc;
|
|
|
|
|
s->index = 0;
|
|
|
|
|
s->view_index = 0;
|
|
|
|
|
s->count = c;
|
|
|
|
|
s->segs = &sl.segments[s->view_index];
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -21,26 +153,44 @@ void scroll_down(scroller *s) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s->view_index >= s->sl.count - s->count) {
|
|
|
|
|
if (s->view_index >= s->txtcol->count - s->count) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s->view_index++;
|
|
|
|
|
s->segs = &s->sl.segments[s->view_index];
|
|
|
|
|
s->delta_segs = &s->delta_sl.segments[s->view_index];
|
|
|
|
|
//printf("%d %d\n", s->view_index, s->sl.count - s->count);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < s->txtcol->count; i++) {
|
|
|
|
|
text *txt = s->txtcol->column[i];
|
|
|
|
|
txt_pos(txt, (Vector2){txt->pos.x, txt->pos.y - txt->font.baseSize/SCALE});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void scroll_reset(scroller *s) {
|
|
|
|
|
s->index = 0;
|
|
|
|
|
s->view_index = 0;
|
|
|
|
|
s->segs = &s->sl.segments[s->view_index];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < s->txtcol->count; i++) {
|
|
|
|
|
text *txt = s->txtcol->column[i];
|
|
|
|
|
txt_pos(txt, (Vector2){txt->pos.x, i * txt->font.baseSize/SCALE});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//txtcol_op(s->txtcol, txt_clear);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//op(tc->column[i], (Vector2){tc->pos.x, tc->pos.y + i * font.baseSize/SCALE});
|
|
|
|
|
void scroll_draw(scroller *s) {
|
|
|
|
|
for (int i = s->view_index; i < s->count + s->view_index; i++) {
|
|
|
|
|
txt_draw(txtcol_get(s->txtcol, i));
|
|
|
|
|
//txt_print(txtcol_get(s->txtcol, i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void destroy_scroller(scroller *s) {
|
|
|
|
|
free(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//segment renderer funcs
|
|
|
|
|
segment_renderer *create_segment_renderer(segment_list sl, float y, float h) {
|
|
|
|
|
segment_renderer *sr = (segment_renderer *)calloc(1, sizeof(*sr));
|
|
|
|
|
sr->pos = y;
|
|
|
|
|
@ -89,7 +239,7 @@ void render_segments(segment_renderer *sr) {
|
|
|
|
|
DrawTextEx(font, sr->scroller->segs[i].name, (Vector2){10, 30 * i}, (float)font.baseSize/16, 2, WHITE);
|
|
|
|
|
|
|
|
|
|
//if the segment has been splitted upon, display the delta instead
|
|
|
|
|
if (sr->scroller->index <= i) {
|
|
|
|
|
if (sr->scroller->index < i) {
|
|
|
|
|
char *time = time_unparse(sr->strfmt, FMT_SIZE, &sr->scroller->segs[i].realtime);
|
|
|
|
|
Vector2 m = MeasureTextEx(font, time, font.baseSize/16, 2);
|
|
|
|
|
DrawTextEx(font, time, (Vector2){410 - m.x, 30 * i}, (float)font.baseSize/16, 2, WHITE);
|
|
|
|
|
@ -98,6 +248,5 @@ void render_segments(segment_renderer *sr) {
|
|
|
|
|
Vector2 m = MeasureTextEx(font, time, font.baseSize/16, 2);
|
|
|
|
|
DrawTextEx(font, time_unparse(sr->strfmt, FMT_SIZE, &sr->scroller->delta_segs[i].realtime), (Vector2){410 - m.x, 30 * i}, (float)font.baseSize/16, 2, color[sr->scroller->delta_segs[i].positive]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|