aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/unix/progressbar.c
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-09-09 02:30:51 +0200
committerStapleButter <thetotalworm@gmail.com>2017-09-09 02:30:51 +0200
commit70e4841d311d68689724768157cc9cbfbde7a9fc (patch)
treeba9499f77d1258530a7e60aa6e1732c41d98161c /src/libui_sdl/libui/unix/progressbar.c
parent81747d6c34eb159481a6ca3f283d065fa3568617 (diff)
another UI attempt, I guess.
sorry.
Diffstat (limited to 'src/libui_sdl/libui/unix/progressbar.c')
-rw-r--r--src/libui_sdl/libui/unix/progressbar.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/libui_sdl/libui/unix/progressbar.c b/src/libui_sdl/libui/unix/progressbar.c
new file mode 100644
index 0000000..9b543b0
--- /dev/null
+++ b/src/libui_sdl/libui/unix/progressbar.c
@@ -0,0 +1,71 @@
+// 11 june 2015
+#include "uipriv_unix.h"
+
+struct uiProgressBar {
+ uiUnixControl c;
+ GtkWidget *widget;
+ GtkProgressBar *pbar;
+ gboolean indeterminate;
+ guint pulser;
+};
+
+uiUnixControlAllDefaultsExceptDestroy(uiProgressBar)
+
+static void uiProgressBarDestroy(uiControl *c)
+{
+ uiProgressBar *p = uiProgressBar(c);
+
+ // be sure to stop the timeout now
+ if (p->indeterminate)
+ g_source_remove(p->pulser);
+ g_object_unref(p->widget);
+ uiFreeControl(uiControl(p));
+}
+
+int uiProgressBarValue(uiProgressBar *p)
+{
+ if (p->indeterminate)
+ return -1;
+ return (int) (gtk_progress_bar_get_fraction(p->pbar) * 100);
+}
+
+static gboolean pulse(void* data)
+{
+ uiProgressBar *p = uiProgressBar(data);
+
+ gtk_progress_bar_pulse(p->pbar);
+ return TRUE;
+}
+
+void uiProgressBarSetValue(uiProgressBar *p, int value)
+{
+ if (value == -1) {
+ if (!p->indeterminate) {
+ p->indeterminate = TRUE;
+ // TODO verify the timeout
+ p->pulser = g_timeout_add(100, pulse, p);
+ }
+ return;
+ }
+ if (p->indeterminate) {
+ p->indeterminate = FALSE;
+ g_source_remove(p->pulser);
+ }
+
+ if (value < 0 || value > 100)
+ userbug("Value %d is out of range for a uiProgressBar.", value);
+
+ gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
+}
+
+uiProgressBar *uiNewProgressBar(void)
+{
+ uiProgressBar *p;
+
+ uiUnixNewControl(uiProgressBar, p);
+
+ p->widget = gtk_progress_bar_new();
+ p->pbar = GTK_PROGRESS_BAR(p->widget);
+
+ return p;
+}