From 10cbb64f9ad54c2a9df35be6129e30a6537c6aa7 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 27 Jul 2018 13:58:49 +0200 Subject: [PATCH] WIP: Water level widget --- data/gwr-window.ui | 11 +++----- src/gwr-water-level.c | 60 +++++++++++++++++++++++++++++++++++++++++++ src/gwr-water-level.h | 13 ++++++++++ src/gwr-window.c | 5 ++-- src/meson.build | 1 + 5 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 src/gwr-water-level.c create mode 100644 src/gwr-water-level.h diff --git a/data/gwr-window.ui b/data/gwr-window.ui index d16cbcf..6760e43 100644 --- a/data/gwr-window.ui +++ b/data/gwr-window.ui @@ -7,18 +7,13 @@ True True - Hello, World! + Water Reminder - - Hello, World! + True - - - - - + \ No newline at end of file diff --git a/src/gwr-water-level.c b/src/gwr-water-level.c new file mode 100644 index 0000000..95d1683 --- /dev/null +++ b/src/gwr-water-level.c @@ -0,0 +1,60 @@ +#include "gwr-water-level.h" + +struct _GwrWaterLevel { + GtkWidget parent_instance; +}; + +G_DEFINE_TYPE(GwrWaterLevel, gwr_water_level, GTK_TYPE_WIDGET) + +static gboolean +gwr_water_level_draw(GtkWidget *widget, cairo_t *cr) +{ + GtkStyleContext *context = gtk_widget_get_style_context(widget); + gint width = gtk_widget_get_allocated_width(widget); + gint height = gtk_widget_get_allocated_height(widget); + GdkRGBA color; + + gtk_render_background(context, cr, 0, 0, width, height); + gtk_render_frame(context, cr, 0, 0, width, height); + + cairo_arc(cr, width / 2.0, height / 2.0, MIN(width, height) / 2.0, 0, 2 * G_PI); + gtk_style_context_get_color(context, gtk_style_context_get_state(context), &color); + gdk_cairo_set_source_rgba(cr, &color); + gdk_cairo_set_source_rgba(cr, &color); + cairo_fill (cr); + + return FALSE; +} + +static void +gwr_water_level_finalize(GObject *gobject) +{ + // Here, you free memory that is associated with your instance. + // + // References to other objects should be freed in dispose instead. + + G_OBJECT_CLASS(gwr_water_level_parent_class)->finalize(gobject); +} + +static void +gwr_water_level_destroy(GtkWidget *widget) +{ + // Here you drop references to other objects. + + GTK_WIDGET_CLASS(gwr_water_level_parent_class)->destroy(widget); +} + +static void +gwr_water_level_class_init(GwrWaterLevelClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + + gobject_class->finalize = gwr_water_level_finalize; + widget_class->destroy = gwr_water_level_destroy; + widget_class->draw = gwr_water_level_draw; +} + + static void +gwr_water_level_init(GwrWaterLevel *self) +{} diff --git a/src/gwr-water-level.h b/src/gwr-water-level.h new file mode 100644 index 0000000..cb7fe4a --- /dev/null +++ b/src/gwr-water-level.h @@ -0,0 +1,13 @@ +#ifndef __GWR_WATER_LEVEL_H__ +# define __GWR_WATER_LEVEL_H__ + +# include + +G_BEGIN_DECLS + +# define GWR_TYPE_WATER_LEVEL (gwr_water_level_get_type()) +G_DECLARE_FINAL_TYPE(GwrWaterLevel, gwr_water_level, GWR, WATER_LEVEL, GtkWidget) + +G_END_DECLS + +#endif /* __GWR_WATER_LEVEL_H__ */ diff --git a/src/gwr-window.c b/src/gwr-window.c index 62c8834..5e9bec1 100644 --- a/src/gwr-window.c +++ b/src/gwr-window.c @@ -18,6 +18,7 @@ #include "gwr-config.h" #include "gwr-window.h" +#include "gwr-water-level.h" struct _GwrWindow { @@ -25,7 +26,7 @@ struct _GwrWindow /* Template widgets */ GtkHeaderBar *header_bar; - GtkLabel *label; + GwrWaterLevel *level; }; G_DEFINE_TYPE (GwrWindow, gwr_window, GTK_TYPE_APPLICATION_WINDOW) @@ -37,7 +38,7 @@ gwr_window_class_init (GwrWindowClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/eu/polonkai/gergely/GnomeWaterReminder/gwr-window.ui"); gtk_widget_class_bind_template_child (widget_class, GwrWindow, header_bar); - gtk_widget_class_bind_template_child (widget_class, GwrWindow, label); + gtk_widget_class_bind_template_child (widget_class, GwrWindow, level); } static void diff --git a/src/meson.build b/src/meson.build index 95a1661..80fe7bc 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,6 +2,7 @@ gwr_sources = [ gwr_resources, 'main.c', 'gwr-window.c', + 'gwr-water-level.c', ] gwr_deps = [