2015-06-11 18:07:06 -05:00
|
|
|
// 11 june 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
struct uiSlider {
|
|
|
|
uiUnixControl c;
|
2015-06-11 18:07:06 -05:00
|
|
|
GtkWidget *widget;
|
2015-06-27 18:46:11 -05:00
|
|
|
GtkRange *range;
|
|
|
|
GtkScale *scale;
|
2015-06-11 18:07:06 -05:00
|
|
|
void (*onChanged)(uiSlider *, void *);
|
|
|
|
void *onChangedData;
|
2015-07-01 18:11:51 -05:00
|
|
|
gulong onChangedSignal;
|
2015-06-11 18:07:06 -05:00
|
|
|
};
|
|
|
|
|
2016-04-25 19:00:25 -05:00
|
|
|
uiUnixControlAllDefaults(uiSlider)
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-07-01 10:26:14 -05:00
|
|
|
static void onChanged(GtkRange *range, gpointer data)
|
|
|
|
{
|
2015-08-27 22:00:34 -05:00
|
|
|
uiSlider *s = uiSlider(data);
|
2015-07-01 10:26:14 -05:00
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
(*(s->onChanged))(s, s->onChangedData);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnChanged(uiSlider *s, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
int uiSliderValue(uiSlider *s)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2016-06-13 19:55:50 -05:00
|
|
|
return gtk_range_get_value(s->range);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
void uiSliderSetValue(uiSlider *s, int value)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-07-01 18:11:51 -05:00
|
|
|
// we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise
|
|
|
|
g_signal_handler_block(s->range, s->onChangedSignal);
|
2015-07-01 10:26:14 -05:00
|
|
|
gtk_range_set_value(s->range, value);
|
2015-07-01 18:11:51 -05:00
|
|
|
g_signal_handler_unblock(s->range, s->onChangedSignal);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *, void *), void *data)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
|
|
|
s->onChanged = f;
|
|
|
|
s->onChangedData = data;
|
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
uiSlider *uiNewSlider(int min, int max)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-08-27 22:00:34 -05:00
|
|
|
uiSlider *s;
|
2016-06-13 19:55:50 -05:00
|
|
|
int temp;
|
2016-05-22 19:11:52 -05:00
|
|
|
|
|
|
|
if (min >= max) {
|
|
|
|
temp = min;
|
|
|
|
min = max;
|
|
|
|
max = temp;
|
|
|
|
}
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2016-04-25 19:00:25 -05:00
|
|
|
uiUnixNewControl(uiSlider, s);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-06-27 18:46:11 -05:00
|
|
|
s->widget = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, min, max, 1);
|
|
|
|
s->range = GTK_RANGE(s->widget);
|
|
|
|
s->scale = GTK_SCALE(s->widget);
|
|
|
|
|
2016-05-22 23:41:56 -05:00
|
|
|
// ensure integers, just to be safe
|
2015-06-27 18:46:11 -05:00
|
|
|
gtk_scale_set_digits(s->scale, 0);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-07-01 18:11:51 -05:00
|
|
|
s->onChangedSignal = g_signal_connect(s->scale, "value-changed", G_CALLBACK(onChanged), s);
|
2015-08-27 22:00:34 -05:00
|
|
|
uiSliderOnChanged(s, defaultOnChanged, NULL);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-08-27 22:00:34 -05:00
|
|
|
return s;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|