]> git.scottworley.com Git - batteryviewer/commitdiff
Start on chart GTK widget
authorScott Worley <scottworley@scottworley.com>
Thu, 23 Feb 2023 05:44:03 +0000 (21:44 -0800)
committerScott Worley <scottworley@scottworley.com>
Thu, 23 Feb 2023 06:13:55 +0000 (22:13 -0800)
Makefile
batteryviewer.c
chart.c [new file with mode: 0644]
chart.h [new file with mode: 0644]

index 8bc7dbb6309d20e968689a825a804fc5fc27c235..ffbff75892df37379fd37c8aea41a8b636244476 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,8 @@ bindir = $(exec_prefix)/bin
 INSTALL = install -D
 INSTALL_PROGRAM = $(INSTALL)
 
 INSTALL = install -D
 INSTALL_PROGRAM = $(INSTALL)
 
-batteryviewer: batteryviewer.c
-       gcc $(shell pkg-config --cflags gtk+-3.0) -o $@ $(CFLAGS) $< $(shell pkg-config --libs gtk+-3.0)
+batteryviewer: batteryviewer.c chart.c
+       gcc $(shell pkg-config --cflags gtk+-3.0) -o $@ $(CFLAGS) $^ $(shell pkg-config --libs gtk+-3.0)
 
 all: batteryviewer
 
 
 all: batteryviewer
 
index 3b5add9a9d90b78f2a4ff569166d355b685341b5..abc510691971f55cbc670229ea22af54e3aed714 100644 (file)
@@ -1,10 +1,6 @@
+#include "chart.h"
 #include <gtk/gtk.h>
 
 #include <gtk/gtk.h>
 
-static void print_hello(GtkWidget *widget __attribute__((unused)),
-                        gpointer data __attribute__((unused))) {
-  g_print("Hello World\n");
-}
-
 static void activate(GtkApplication *app,
                      gpointer user_data __attribute__((unused))) {
 
 static void activate(GtkApplication *app,
                      gpointer user_data __attribute__((unused))) {
 
@@ -12,14 +8,11 @@ static void activate(GtkApplication *app,
   gtk_window_set_title(GTK_WINDOW(window), "Window");
   gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
 
   gtk_window_set_title(GTK_WINDOW(window), "Window");
   gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
 
-  GtkWidget *button_box = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
-  gtk_container_add(GTK_CONTAINER(window), button_box);
+  GtkWidget *chart_box = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
+  gtk_container_add(GTK_CONTAINER(window), chart_box);
 
 
-  GtkWidget *button = gtk_button_new_with_label("Hello World");
-  g_signal_connect(button, "clicked", G_CALLBACK(print_hello), NULL);
-  g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy),
-                           window);
-  gtk_container_add(GTK_CONTAINER(button_box), button);
+  GtkWidget *chart = bv_chart_new();
+  gtk_container_add(GTK_CONTAINER(chart_box), chart);
 
   gtk_widget_show_all(window);
 }
 
   gtk_widget_show_all(window);
 }
diff --git a/chart.c b/chart.c
new file mode 100644 (file)
index 0000000..3efd454
--- /dev/null
+++ b/chart.c
@@ -0,0 +1,29 @@
+/*
+ * h/t https://ptomato.name/advanced-gtk-techniques/html/custom-container.html
+ * for examples of how to make GTK widgets
+ */
+
+#include "chart.h"
+#include <gtk/gtk.h>
+
+#define BV_CHART_PRIVATE(obj)                                                  \
+  (G_TYPE_INSTANCE_GET_PRIVATE((obj), BV_CHART_TYPE, BVChartPrivate))
+
+typedef struct _BVChartPrivate BVChartPrivate;
+
+struct _BVChartPrivate {
+  int temp;
+};
+
+G_DEFINE_TYPE_WITH_CODE(BVChart, bv_chart, GTK_TYPE_DRAWING_AREA,
+                        G_ADD_PRIVATE(BVChart))
+
+static void bv_chart_class_init(BVChartClass *klass __attribute__((unused))) {}
+
+static void bv_chart_init(BVChart *chart) {
+  gtk_widget_set_has_window(GTK_WIDGET(chart), FALSE);
+}
+
+GtkWidget *bv_chart_new() {
+  return GTK_WIDGET(g_object_new(bv_chart_get_type(), NULL));
+}
diff --git a/chart.h b/chart.h
new file mode 100644 (file)
index 0000000..7cda505
--- /dev/null
+++ b/chart.h
@@ -0,0 +1,39 @@
+#ifndef BV_CHART_H
+#define BV_CHART_H
+
+/*
+ * h/t https://ptomato.name/advanced-gtk-techniques/html/custom-container.html
+ * for examples of how to make GTK widgets
+ */
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define BV_CHART_TYPE (bv_chart_get_type())
+#define BV_CHART(obj)                                                          \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), BV_CHART_TYPE, BVChart))
+#define BV_CHART_CLASS(klass)                                                  \
+  (G_TYPE_CHECK_CLASS_CAST((klass), BV_CHART_TYPE, BVChartClass))
+#define BV_IS_CHART(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), BV_CHART_TYPE))
+#define BV_IS_CHART_CLASS(klass)                                               \
+  (G_TYPE_CHECK_CLASS_TYPE((klass), BV_CHART_TYPE))
+
+typedef struct _BVChart BVChart;
+typedef struct _BVChartClass BVChartClass;
+
+struct _BVChart {
+  GtkDrawingArea parent_instance;
+};
+
+struct _BVChartClass {
+  GtkDrawingAreaClass parent_class;
+};
+
+GType bv_chart_get_type(void) G_GNUC_CONST;
+GtkWidget *bv_chart_new(void);
+
+G_END_DECLS
+
+#endif /* BV_CHART_H */