]> git.scottworley.com Git - batteryviewer/blob - chart.c
Charts have points
[batteryviewer] / chart.c
1 /*
2 * h/t https://ptomato.name/advanced-gtk-techniques/html/custom-container.html
3 * for examples of how to make GTK widgets
4 */
5
6 #include "chart.h"
7 #include <gtk/gtk.h>
8
9 #define BV_CHART_PRIVATE(obj) \
10 (G_TYPE_INSTANCE_GET_PRIVATE((obj), BV_CHART_TYPE, BVChartPrivate))
11
12 typedef struct _BVChartPrivate BVChartPrivate;
13
14 struct _BVChartPrivate {
15 GArray *points;
16 };
17
18 struct BVChartPoint {
19 float x, y;
20 };
21
22 G_DEFINE_TYPE_WITH_CODE(BVChart, bv_chart, GTK_TYPE_DRAWING_AREA,
23 G_ADD_PRIVATE(BVChart))
24
25 static void bv_chart_class_init(BVChartClass *klass __attribute__((unused))) {}
26
27 static void bv_chart_init(BVChart *chart) {
28 gtk_widget_set_has_window(GTK_WIDGET(chart), FALSE);
29 BVChartPrivate *priv = bv_chart_get_instance_private(chart);
30 gboolean zero_terminated = FALSE;
31 gboolean clear_ = FALSE;
32 priv->points =
33 g_array_new(zero_terminated, clear_, sizeof(struct BVChartPoint));
34 }
35
36 GtkWidget *bv_chart_new() {
37 return GTK_WIDGET(g_object_new(bv_chart_get_type(), NULL));
38 }
39
40 void bv_chart_add_point(BVChart *chart, float x, float y) {
41 BVChartPrivate *priv = bv_chart_get_instance_private(chart);
42 struct BVChartPoint p = {.x = x, .y = y};
43 g_array_append_val(priv->points, p);
44 }