aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/wnd/wndclass/slider.h
blob: 55c451ea374bcf50afb6490097efceef225d42c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#ifndef _SLIDER_H
#define _SLIDER_H

#include <bfc/common.h>
#include <tataki/bitmap/autobitmap.h>
#include <api/wnd/wndclass/guiobjwnd.h>

#define SLIDERWND_PARENT GuiObjectWnd
/**
  Slider style control.
  
  @short Slider style control.
  @author Nullsoft
  @ver 1.0
*/
class SliderWnd : public SLIDERWND_PARENT 
{
public:
  /**
    Sets the defaults for the slider. Defaults to a horizontal 
    slider with the thumb in the center and is enabled.
  */
  SliderWnd();
  
  /**
    Nothing is handled by the destructor.
  */
  virtual ~SliderWnd();

  /**
    Event is triggered when the window requires a repaint.
    Override this to implement your own behavior.
    
    Paints the slider on canvas according to current 
    state of the slider.

    @ret 0, Failed; 1, Success;
    @param canvas The canvas on which to paint.
  */
  virtual int onPaint(Canvas *canvas);

  /**
    Event is triggered when the left mouse button is pressed while 
    the slider has focus. Override this to implement your
    own behavior.
    
    @ret 
    @param x X coordinate of the mouse pointer.
    @param y Y coordinate of the mouse pointer.
  */
  virtual int onLeftButtonDown(int x, int y);
  
  /**
    Event is triggered when the mouse has capture on the slider
    and is being moved. Override this to implement your own
    behavior.
    
    @ret 0, Failed; 1, Success;
    @param x The X position of the mouse.
    @param y The Y position of the mouse.
  */
  virtual int onMouseMove(int x, int y); // only called when mouse captured
  
  /**
    Event is triggered when the left mouse button is released.
    Note that the mouse button must have been previously pressed
    for this event to happen. Override this to implement your 
    own behavior.
    
    @ret 1, If you handle the event; 0, If you don't handle the event;
    @param x The X position of the mouse.
    @param y The Y position of the mouse.
  */
  virtual int onLeftButtonUp(int x, int y);
  
  /**
    Event is triggered when the right mouse button is pressed.
    Override this to implement your own behavior.
  */
  virtual int onRightButtonDown(int x, int y);
  
  /**
    Event is triggered when a key is pressed and the slider
    has focus. Override this to implement your own behavior.
    
    @ret 1, If you handle the event; 0, If you don't handle the event;
    @param c The key that was pressed.
  */
  virtual int onChar(unsigned int c);

  /**
    Event is triggered when the mouse enters the region 
    of the slider. Override this to implement your 
    own behavior.
  */
  virtual void onEnterArea();
  
  /**
    Event is triggered when the mouse leaves the region 
    of the slider. Override this to implement your 
    own behavior.
  */
  virtual void onLeaveArea();

  /**
    Event is triggered then the slider is about to be initialized.
    Override this event to implement your own behavior.
    
    By default this will render the slider according the it's current settings
    and position of the thumb.
    
    @ret 1, Success; 0, Failure;
  */
  virtual int onInit();

  /**
    Constants for positioning of the thumb.
  */
  enum {
    START = 0,
    END = 65535,
    FULL = END
  };
  
  /**
    Set the sliders position.
    
    @param newpos The sliders new position.
    @param wantcb !0, Generate a callback after the position has been set; 0, No callback;
  */
  virtual void setPosition(int newpos, int wantcb=1);
  
  /**
    Get the sliders current position. The range is from
    START (0) to END (65535).
    
    @ret The sliders position (ranges from 0 to 65535).
  */
  int getSliderPosition();

  //void cancelSeek();
  
  /**
    Use a base texture when rendering the slider.
    
    @see setBaseTexture()
    @param useit 0, Do not use; 1, Use base texture;
  */
  void setUseBaseTexture(int useit);
  
  /**
    Set the base texture of the slider.
    
    @see setUseBaseTexture()
    @see SkinBitmap
    @param bmp The bitmap to use as a texture.
    @param x  The X position of the base texture.
    @param y  The Y position of the base texture.
  */
  void setBaseTexture(SkinBitmap *bmp, int x, int y);
  
  /**
    Set the draw area to include the edge borders.
    
    @param draw 0, Do not include the edges; 1, Include the edges;
  */
  void setDrawOnBorders(int draw);
  
  /**
    Do not use the default background provided 
    by the current skin?
    
    If you set this to 1, you MUST specify your bitmaps.
    
    @param no 0, Use default background; 1, Do not use default;
  */
  void setNoDefaultBackground(int no);

  /**
    Set the bitmaps to be used to render the slider.
    These include bitmaps for the left, middle, right of
    the slider. For the thumb, we have bitmaps for the
    normal, hilited and pushed thumb. 
    
    The bitmaps are set using their xml id or "name".
    The name should resemble something like this: 
    "studio.seekbar.left".
    
    @see setLeftBmp()
    @see setMiddleBmp()
    @see setRightBmp()
    @see setThumbBmp()
    @see setThumbDownBmp()
    @see setThumbHiliteBmp()
    @param thumbbmp The normal thumb bitmap name.
    @param thumbdownbmp The thumb down bitmap name.
    @param thumbhighbmp The hilited thumb bitmap name.
    @param leftbmp The left bitmap of the slider name.
    @param middlebmp The middle bitmap of the slider name.
    @param rightbmp The right bitmap of the slider name.
  */
  void setBitmaps(const wchar_t *thumbbmp, const wchar_t *thumbdownbmp, const wchar_t *thumbhighbmp, const wchar_t *leftbmp, const wchar_t *middlebmp, const wchar_t *rightbmp);

  /**
    Set the left bitmap of the slider.
    
    @param name The left bitmap name.
  */
  void setLeftBmp(const wchar_t *name);
  
  /**
    Set the middle bitmap of the slider.
    
    @param name The middle bitmap name.
  */
  void setMiddleBmp(const wchar_t *name);
  
  /**
    Set the right bitmap of the slider.
    
    @param name The right bitmap name.
  */
  void setRightBmp(const wchar_t *name);
  
  /**
    Set the normal thumb bitmap of the slider.
    
    @param name The normal thumb bitmap name.
  */
  void setThumbBmp(const wchar_t *name);
  
  /**
    Set the thumb down bitmap of the slider.
    
    @param name The thumb down bitmap name.
  */
  void setThumbDownBmp(const wchar_t *name);
  
  /**
    Set the hilited thumb bitmap of the slider.
    
    @param name The hilited thumb bitmap name.
  */
  void setThumbHiliteBmp(const wchar_t *name);

  /**
    Get the height of the slider in pixels.
    
    @ret The height of the slider (in pixels).
  */
  virtual int getHeight();
  
  /**
    Get the width of the slider in pixels.
    
    @ret The width of the slider (in pixels).
  */
  virtual int getWidth();

  /**
    Get the left bitmap of the slider.
    
    @see SkinBitmap
    @ret The left SkinBitmap.
  */
  SkinBitmap *getLeftBitmap();
  
  /**
    Get the right bitmap of the slider.
    
    @see SkinBitmap
    @ret The right SkinBitmap.
  */
  SkinBitmap *getRightBitmap();

  /**
    Get the middle bitmap of the slider.
    
    @see SkinBitmap
    @ret The middle SkinBitmap.
  */
  SkinBitmap *getMiddleBitmap();

  /**
    Get the thumb bitmap of the slider.
    
    @see SkinBitmap
    @ret The thumb SkinBitmap.
  */
  SkinBitmap *getThumbBitmap();

  /**
    Get the thumb down bitmap of the slider.
    
    @see SkinBitmap
    @ret The thumb down SkinBitmap.
  */
  SkinBitmap *getThumbDownBitmap();

  /**
    Get the thumb hilite bitmap of the slider.
    
    @see SkinBitmap
    @ret The thumb hilite SkinBitmap.
  */
  SkinBitmap *getThumbHiliteBitmap();

  /**
    Set the sliders enable state.
    
    @param en 1, Enabled; 0, Disabled;
  */
    
  virtual void setEnable(int en);
  
  /**
    Get the sliders enable state.
    
    @ret 1, Enabled; 0, Disabled;
  */
  virtual int getEnable(void);

  /**
    Set the orientation of the slider 
    (horizontal or vertical).
    
    @param o 0, Horizontal; 1, Vertical;
  */
  virtual void setOrientation(int o); 
  
  /**
    This will set a "jump-to" position (like "center" for a balance slider).
    The parameter is in thumb coordinates (0 to 65535).
    
    @param h The jump-to position (ranges from 0 to 65535, or START to END).
  */
  virtual void setHotPosition(int h);
  virtual int getHotPosRange() { return hotposrange; }
  virtual void setHotPosRange(int range) { hotposrange = range; }

  /**
    Set the thumb center flag. If on, this flag will
    cause the thumb of the slider to be centered
    automatically.
    
    @param c 1, Centered; 0, No centering;
  */
  virtual void setThumbCentered(int c);
  virtual void setThumbStretched(int c);

  /**
    Set the thumb offset (from the left hand side).
    This offset will be added to the zero position of the thumb.
    Note, if you're using centering also, this will cause the slider
    thumb to be passed the middle of the slider.
    
    @param o The offset of the thumb (in pixels).
  */
  virtual void setThumbOffset(int o);

  /**
    Set the minimum and maximum limit for the slider.
    
    @param minlimit The minimum value.
    @param maxlimit The maximum value.
  */
  virtual void setLimits(int minlimit, int maxlimit);

  virtual int getMaxLimit() { return maxlimit; }
  virtual int getMinLimit() { return minlimit; }
  virtual int getRange() { return maxlimit-minlimit; }

  virtual int onKeyDown(int vkcode);
  
	virtual void onCancelCapture();
protected:
  /**
    Abort the current seek and end capture.
  */
  void abort();

  // override this to get position change notification
  /**
    Event is triggered when the mouse is moving the thumb
    is being moved. Override this to implment your own behavior.
    
    @ret The thumb's position (ranges from 0 to 65535 or START to END).
  */
  virtual int onSetPosition();		// called constantly as mouse moves
  
  /**
    Event is triggered when the thumb is released and the final position
    is about to be set.
    
    @ret The thumb's position (ranges from 0 to 65535 or START to END).
  */
  virtual int onSetFinalPosition();	// called once after move done

  /**
    Get the seeking status.
    
    @ret 1, User is seeking; 0, User is not seeking;
  */
  int getSeekStatus();	// returns 1 if user is sliding tab

  int vertical;	// set to 1 for up-n-down instead

  /**
    Get the width of the thumb bitmap, in pixels.
    
    @ret The thumb's width (in pixels).
  */
  int thumbWidth();
  
  /**
    Get the height of the thumb bitmap, in pixels.
    
    @ret The thumb's width (in pixels).
  */
  int thumbHeight();
  // keyboard
  void move_left(int bigstep);
  void move_right(int bigstep);
  void move_start();
  void move_end();

  int minlimit, maxlimit, length;

private:
  int seeking;
  int enabled;
  int hilite;
  int pos;
  int oldpos;
  int thumbwidth;
  int captured;
  int xShift, yShift;
  SkinBitmap *base_texture;
  int use_base_texture;
  int no_default_background;
  int drawOnBorders;
  int hotPosition;
  int origPos;
  int thumbCentered, thumbOffset, thumbStretched;
  int hotposrange;

  AutoSkinBitmap left, middle, right;
  AutoSkinBitmap thumb, thumbdown, thumbhilite;
};

#endif