Seperated chart from box; fixed kkr segfault.

This commit is contained in:
2025-10-18 19:21:22 +02:00
parent c7f218da30
commit 65a1c9f159
8 changed files with 80 additions and 43 deletions

35
box.c
View File

@@ -73,7 +73,6 @@ draw_rectangle(double fx, double fy, double fwidth, double fheight)
static void
draw_chart(struct box *chart, double x, double y, double width, double height)
{
char c = '@';
long int actual_diff;
double diff, price;
enum ui_color color;
@@ -89,23 +88,11 @@ draw_chart(struct box *chart, double x, double y, double width, double height)
actual_diff = 0;
for (size_t i = 0; i < width; i++) {
diff = (double)rand() / RAND_MAX - 0.6;
actual_diff = (size_t)(height + y - price)
- (size_t)(height + y - (price + diff));
price = chart->chart->prices[i];
if (actual_diff > 0) {
color = UI_GREEN;
} else if (actual_diff == 0) {
color = UI_NONE;
} else if (actual_diff < 0) {
color = UI_RED;
}
ui_color_on(color);
ui_char(x + i, height + y - price, c);
ui_color_off(color);
price += diff;
ui_color_on(UI_BLUE);
ui_char(x + i, height + y - price, '@');
ui_color_off(UI_BLUE);
}
}
@@ -163,16 +150,16 @@ draw_container(struct box *b, double x, double y, double width, double height)
struct box *
new_chart_box(void)
new_chart_box(struct chart *chart)
{
struct box *chart = malloc(sizeof(struct box));
struct box *box = malloc(sizeof(struct box));
chart->type = BOX_CHART;
chart->prices = emalloc(sizeof(double) * 100);
chart->fills = 1;
chart->color = UI_NONE;
box->type = BOX_CHART;
box->chart = chart;
box->fills = 1;
box->color = UI_NONE;
return chart;
return box;
}