summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-18 02:53:39 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-18 02:53:39 -0300
commit42bf41416b7d336f1ad190bcdc96f71038ce995e (patch)
treeab9a3115440f5a519131dd6385bcfd64099b9202 /gui
parent31d2267bdf9741e1a3519d5c961dcc2ea4b356d3 (diff)
downloadeeshow-42bf41416b7d336f1ad190bcdc96f71038ce995e.tar.gz
eeshow-42bf41416b7d336f1ad190bcdc96f71038ce995e.tar.bz2
eeshow-42bf41416b7d336f1ad190bcdc96f71038ce995e.zip
eeshow/gui/gui.c: move progress bar handling to progress.c
Diffstat (limited to 'gui')
-rw-r--r--gui/common.h7
-rw-r--r--gui/gui.c75
-rw-r--r--gui/progress.c99
3 files changed, 107 insertions, 74 deletions
diff --git a/gui/common.h b/gui/common.h
index 6602be9..f7b405b 100644
--- a/gui/common.h
+++ b/gui/common.h
@@ -99,4 +99,11 @@ struct gui_ctx {
unsigned progress_scale;/* right-shift by this value */
};
+
+
+void redraw(const struct gui_ctx *ctx);
+
+void setup_progress_bar(struct gui_ctx *ctx, GtkWidget *window);
+void progress_update(struct gui_ctx *ctx);
+
#endif /* !GUI_COMMON_H */
diff --git a/gui/gui.c b/gui/gui.c
index d20928c..bf2d30f 100644
--- a/gui/gui.c
+++ b/gui/gui.c
@@ -51,7 +51,7 @@
/* ----- Helper functions -------------------------------------------------- */
-static void redraw(const struct gui_ctx *ctx)
+void redraw(const struct gui_ctx *ctx)
{
gtk_widget_queue_draw(ctx->da);
}
@@ -998,79 +998,6 @@ static bool hover_glabel(void *user, bool on)
}
-/* ----- Progress bar ------------------------------------------------------ */
-
-
-#define PROGRESS_BAR_HEIGHT 10
-
-
-static void progress_draw_event(GtkWidget *widget, cairo_t *cr,
- gpointer user_data)
-{
- GtkAllocation alloc;
- struct gui_ctx *ctx = user_data;
- unsigned w, x;
-
- x = ctx->progress >> ctx->progress_scale;
- if (!x) {
- /* @@@ needed ? Gtk seems to always clear the the surface. */
- cairo_set_source_rgb(cr, 1, 1, 1);
- cairo_paint(cr);
- }
-
- gtk_widget_get_allocation(ctx->da, &alloc);
- w = ctx->hist_size >> ctx->progress_scale;
-
- cairo_save(cr);
- cairo_translate(cr,
- (alloc.width - w) / 2, (alloc.height - PROGRESS_BAR_HEIGHT) / 2);
-
- cairo_set_source_rgb(cr, 0, 0.7, 0);
- cairo_set_line_width(cr, 0);
- cairo_rectangle(cr, 0, 0, x, PROGRESS_BAR_HEIGHT);
- cairo_fill(cr);
-
- cairo_set_source_rgb(cr, 0, 0, 0);
- cairo_set_line_width(cr, 2);
- cairo_rectangle(cr, 0, 0, w, PROGRESS_BAR_HEIGHT);
- cairo_stroke(cr);
-
- cairo_restore(cr);
-}
-
-
-static void setup_progress_bar(struct gui_ctx *ctx, GtkWidget *window)
-{
- GtkAllocation alloc;
-
- gtk_widget_get_allocation(ctx->da, &alloc);
-
- ctx->progress_scale = 0;
- while ((ctx->hist_size >> ctx->progress_scale) > alloc.width)
- ctx->progress_scale++;
- ctx->progress = 0;
-
- g_signal_connect(G_OBJECT(ctx->da), "draw",
- G_CALLBACK(progress_draw_event), ctx);
-
- redraw(ctx);
- gtk_main_iteration_do(0);
-}
-
-
-static void progress_update(struct gui_ctx *ctx)
-{
- unsigned mask = (1 << ctx->progress_scale) - 1;
-
- ctx->progress++;
- if ((ctx->progress & mask) != mask)
- return;
-
- redraw(ctx);
- gtk_main_iteration_do(0);
-}
-
-
/* ----- Initialization ---------------------------------------------------- */
diff --git a/gui/progress.c b/gui/progress.c
new file mode 100644
index 0000000..b7f1d39
--- /dev/null
+++ b/gui/progress.c
@@ -0,0 +1,99 @@
+/*
+ * gui/progress.c - Progress bar
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+/*
+ * Resources:
+ *
+ * http://zetcode.com/gfx/cairo/cairobackends/
+ * https://developer.gnome.org/gtk3/stable/gtk-migrating-2-to-3.html
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include <cairo/cairo.h>
+#include <gtk/gtk.h>
+
+#include "gui/common.h"
+
+
+#define PROGRESS_BAR_HEIGHT 10
+
+
+static void progress_draw_event(GtkWidget *widget, cairo_t *cr,
+ gpointer user_data)
+{
+ GtkAllocation alloc;
+ struct gui_ctx *ctx = user_data;
+ unsigned w, x;
+
+ x = ctx->progress >> ctx->progress_scale;
+ if (!x) {
+ /* @@@ needed ? Gtk seems to always clear the the surface. */
+ cairo_set_source_rgb(cr, 1, 1, 1);
+ cairo_paint(cr);
+ }
+
+ gtk_widget_get_allocation(ctx->da, &alloc);
+ w = ctx->hist_size >> ctx->progress_scale;
+
+ cairo_save(cr);
+ cairo_translate(cr,
+ (alloc.width - w) / 2, (alloc.height - PROGRESS_BAR_HEIGHT) / 2);
+
+ cairo_set_source_rgb(cr, 0, 0.7, 0);
+ cairo_set_line_width(cr, 0);
+ cairo_rectangle(cr, 0, 0, x, PROGRESS_BAR_HEIGHT);
+ cairo_fill(cr);
+
+ cairo_set_source_rgb(cr, 0, 0, 0);
+ cairo_set_line_width(cr, 2);
+ cairo_rectangle(cr, 0, 0, w, PROGRESS_BAR_HEIGHT);
+ cairo_stroke(cr);
+
+ cairo_restore(cr);
+}
+
+
+void setup_progress_bar(struct gui_ctx *ctx, GtkWidget *window)
+{
+ GtkAllocation alloc;
+
+ gtk_widget_get_allocation(ctx->da, &alloc);
+
+ ctx->progress_scale = 0;
+ while ((ctx->hist_size >> ctx->progress_scale) > alloc.width)
+ ctx->progress_scale++;
+ ctx->progress = 0;
+
+ g_signal_connect(G_OBJECT(ctx->da), "draw",
+ G_CALLBACK(progress_draw_event), ctx);
+
+ redraw(ctx);
+ gtk_main_iteration_do(0);
+}
+
+
+void progress_update(struct gui_ctx *ctx)
+{
+ unsigned mask = (1 << ctx->progress_scale) - 1;
+
+ ctx->progress++;
+ if ((ctx->progress & mask) != mask)
+ return;
+
+ redraw(ctx);
+ gtk_main_iteration_do(0);
+}