21 void UI_SLIDER2::create(
UI_WINDOW *wnd,
int _x,
int _y,
int _w,
int _h,
int _numberItems,
char *_bitmapSliderControl,
void (* _upCallback)(),
void (*_downCallback)(),
22 void (* _captureCallback)()) {
24 int buttonHeight, buttonWidth;
28 Assert(_upCallback != NULL);
29 Assert(_downCallback != NULL);
31 upCallback = _upCallback;
32 downCallback = _downCallback;
34 captureCallback = _captureCallback;
36 Assert(_bitmapSliderControl != NULL);
45 slider_w = buttonWidth;
46 slider_h = buttonHeight;
48 slider_half_h = (
int)(buttonHeight / 2);
49 numberPositions = _h - buttonHeight;
51 Assert(numberPositions >= 0);
55 numberItems = _numberItems;
56 if (numberItems <= 0) {
60 slider_mode = S2M_DEFAULT;
63 void UI_SLIDER2::draw() {
64 Assert((currentPosition >= 0) && (currentPosition <= numberPositions));
67 switch (slider_mode) {
83 void UI_SLIDER2::process(
int focus)
85 int OnMe, mouse_lock_move;
95 slider_mode = S2M_ON_ME;
101 slider_mode = S2M_DEFAULT;
104 if (mouse_locked == 1)
105 if (captureCallback != NULL) {
107 mprintf((
"Called captureCallback()!\n"));
112 if (!OnMe && !mouse_locked)
116 if ((OnMe &&
B1_PRESSED &&
ui_mouse.
y < (currentPosition+
y+slider_half_h-1)) || (mouse_locked && (
ui_mouse.
y < (currentPosition+
y+slider_half_h-1))) ) {
121 if (currentItem > 0) {
123 if (upCallback != NULL) {
125 if (captureCallback != NULL)
129 currentPosition =
fl2i((((
float)currentItem/(
float)numberItems) * (
float)numberPositions)-.49);
131 mouse_lock_move =
fl2i( ((((
float)
ui_mouse.
y - (
float)
y - (
float)slider_half_h)/(
float)numberPositions) * (
float)numberItems) -.49);
132 mouse_lock_move = currentItem - mouse_lock_move;
133 if (mouse_lock_move > 0) {
134 while (mouse_lock_move > 0) {
135 if (currentItem > 0) {
137 if (upCallback != NULL)
144 currentPosition =
fl2i((((
float)currentItem/(
float)numberItems) * (
float)numberPositions)-.49);
146 if (currentPosition < 0)
148 if (currentPosition > numberPositions)
149 currentPosition = numberPositions;
150 slider_mode = S2M_MOVING;
154 if ( ( OnMe &&
B1_PRESSED &&
ui_mouse.
y > (currentPosition+
y+slider_half_h+1)) || (mouse_locked && (
ui_mouse.
y > (currentPosition+
y+slider_half_h+1))) ) {
159 if (currentItem < numberItems) {
161 if (downCallback != NULL) {
163 if (captureCallback != NULL)
167 currentPosition =
fl2i((((
float)currentItem/(
float)numberItems) * (
float)numberPositions)-.49);
169 mouse_lock_move =
fl2i( ((((
float)
ui_mouse.
y - (
float)
y - (
float)slider_half_h)/(
float)numberPositions) * (
float)numberItems) -.49);
170 mouse_lock_move -= currentItem;
171 if (mouse_lock_move > 0) {
172 while (mouse_lock_move > 0) {
173 if (currentItem < numberItems) {
175 if (downCallback != NULL)
182 currentPosition =
fl2i((((
float)currentItem/(
float)numberItems) * (
float)numberPositions)-.49);
184 if (currentPosition < 0){
187 if (currentPosition > numberPositions){
188 currentPosition = numberPositions;
190 slider_mode = S2M_MOVING;
197 slider_mode = S2M_MOVING;
208 return currentPosition;
218 numberItems = _numberItems;
225 currentPosition =
fl2i((((
float)currentItem/(
float)numberItems) * (
float)numberPositions)-.49);
226 if (currentPosition < 0){
229 if (currentPosition > numberPositions){
230 currentPosition = numberPositions;
233 if (numberItems <= 0){
242 if (_currentItem > numberItems)
245 if (_currentItem == currentItem)
248 if (_currentItem < 0)
251 if (_currentItem > currentItem) {
252 while (currentItem != _currentItem) {
254 if (downCallback != NULL)
257 }
else if (_currentItem < currentItem) {
258 while (currentItem != _currentItem) {
260 if (upCallback != NULL)
265 if (numberItems > 0) {
266 currentPosition =
fl2i(((
float)currentItem/(
float)numberItems) * (
float)numberPositions);
272 if (currentPosition > numberItems)
273 currentPosition = numberItems;
275 if (currentPosition < 0)
280 if (_currentItem > numberItems)
283 if (_currentItem == currentItem)
286 currentItem = _currentItem;
292 currentPosition =
fl2i(((
float)currentItem/(
float)numberItems) * (
float)numberPositions);
295 if (currentPosition > numberItems)
296 currentPosition = numberItems;
298 if (currentPosition < 0)
303 if (currentItem < numberItems) {
305 currentPosition =
fl2i(((
float)currentItem/(
float)numberItems) * (
float)numberPositions);
310 if (currentItem > 0) {
312 currentPosition =
fl2i(((
float)currentItem/(
float)numberItems) * (
float)numberPositions);
314 if (currentPosition < 0)
int bmap_ids[MAX_BMAPS_PER_GADGET]
int bm_get_info(int handle, int *w, int *h, ubyte *flags, int *nframes, int *fps)
Gets info on the bitmap indexed by handle.
void base_create(UI_WINDOW *wnd, int _kind, int _x, int _y, int _w, int _h)
void gr_set_bitmap(int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha)
int get_currentPosition()
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
int set_bmaps(char *ani_filename, int nframes=3, int start_frame=1)
void set_numberItems(int _numberItems, int _reset=1)
void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, int _numberItems, char *_bitmapSliderControl, void(*_upCallback)(), void(*_downCallback)(), void(*_captureCallback)())
GLint GLint GLint GLint GLint x
void force_currentItem(int _currentItem)
void set_currentItem(int _currentItem)
void gr_bitmap(int _x, int _y, int resize_mode)
int timer_get_milliseconds()