]> git.scottworley.com Git - batteryviewer/blame - chart.c
Charts have points
[batteryviewer] / chart.c
CommitLineData
5a945372
SW
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
12typedef struct _BVChartPrivate BVChartPrivate;
13
14struct _BVChartPrivate {
27db65e2
SW
15 GArray *points;
16};
17
18struct BVChartPoint {
19 float x, y;
5a945372
SW
20};
21
22G_DEFINE_TYPE_WITH_CODE(BVChart, bv_chart, GTK_TYPE_DRAWING_AREA,
23 G_ADD_PRIVATE(BVChart))
24
25static void bv_chart_class_init(BVChartClass *klass __attribute__((unused))) {}
26
27static void bv_chart_init(BVChart *chart) {
28 gtk_widget_set_has_window(GTK_WIDGET(chart), FALSE);
27db65e2
SW
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));
5a945372
SW
34}
35
36GtkWidget *bv_chart_new() {
37 return GTK_WIDGET(g_object_new(bv_chart_get_type(), NULL));
38}
27db65e2
SW
39
40void 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}