2015-07-11 15:56:37 -05:00
|
|
|
// 11 june 2015
|
2015-07-11 16:02:01 -05:00
|
|
|
#include "uipriv_darwin.h"
|
2015-07-11 15:56:37 -05:00
|
|
|
|
2015-07-26 12:53:35 -05:00
|
|
|
// TODO events
|
|
|
|
|
2015-07-11 15:56:37 -05:00
|
|
|
struct slider {
|
|
|
|
uiSlider s;
|
2015-07-26 12:53:35 -05:00
|
|
|
NSSlider *slider;
|
2015-07-11 15:56:37 -05:00
|
|
|
void (*onChanged)(uiSlider *, void *);
|
|
|
|
void *onChangedData;
|
|
|
|
};
|
|
|
|
|
|
|
|
uiDefineControlType(uiSlider, uiTypeSlider, struct slider)
|
|
|
|
|
|
|
|
static uintptr_t sliderHandle(uiControl *c)
|
|
|
|
{
|
|
|
|
struct slider *s = (struct slider *) c;
|
|
|
|
|
2015-07-26 12:53:35 -05:00
|
|
|
return (uintptr_t) (s->slider);
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnChanged(uiSlider *s, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
static intmax_t sliderValue(uiSlider *ss)
|
|
|
|
{
|
|
|
|
struct slider *s = (struct slider *) ss;
|
|
|
|
|
|
|
|
return PUT_CODE_HERE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sliderSetValue(uiSlider *ss, intmax_t value)
|
|
|
|
{
|
|
|
|
struct slider *s = (struct slider *) ss;
|
|
|
|
|
|
|
|
PUT_CODE_HERE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sliderOnChanged(uiSlider *ss, void (*f)(uiSlider *, void *), void *data)
|
|
|
|
{
|
|
|
|
struct slider *s = (struct slider *) ss;
|
|
|
|
|
|
|
|
s->onChanged = f;
|
|
|
|
s->onChangedData = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiSlider *uiNewSlider(intmax_t min, intmax_t max)
|
|
|
|
{
|
|
|
|
struct slider *s;
|
2015-07-26 12:53:35 -05:00
|
|
|
NSSliderCell *cell;
|
2015-07-11 15:56:37 -05:00
|
|
|
|
2015-07-26 12:53:35 -05:00
|
|
|
s = (struct slider *) uiNewControl(uiTypeSlider());
|
2015-07-11 15:56:37 -05:00
|
|
|
|
2015-07-26 12:53:35 -05:00
|
|
|
s->slider = [[NSSlider alloc] initWithFrame:NSZeroRect];
|
|
|
|
// TODO vertical is defined by wider than tall
|
|
|
|
[s->slider setMinValue:min];
|
|
|
|
[s->slider setMaxValue:max];
|
2015-07-27 22:38:44 -05:00
|
|
|
[s->slider setAllowsTickMarkValuesOnly:NO];
|
2015-07-29 12:34:25 -05:00
|
|
|
[s->slider setNumberOfTickMarks:0];
|
2015-07-27 22:38:44 -05:00
|
|
|
[s->slider setTickMarkPosition:NSTickMarkAbove];
|
2015-07-26 12:53:35 -05:00
|
|
|
|
|
|
|
cell = (NSSliderCell *) [s->slider cell];
|
|
|
|
[cell setSliderType:NSLinearSlider];
|
|
|
|
|
|
|
|
uiDarwinMakeSingleViewControl(uiControl(s), s->slider, NO);
|
2015-07-11 15:56:37 -05:00
|
|
|
|
|
|
|
s->onChanged = defaultOnChanged;
|
|
|
|
|
|
|
|
uiControl(s)->Handle = sliderHandle;
|
|
|
|
|
|
|
|
uiSlider(s)->Value = sliderValue;
|
|
|
|
uiSlider(s)->SetValue = sliderSetValue;
|
|
|
|
uiSlider(s)->OnChanged = sliderOnChanged;
|
|
|
|
|
|
|
|
return uiSlider(s);
|
|
|
|
}
|