slider.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. #ifndef _SLIDER_H
  2. #define _SLIDER_H
  3. #include <bfc/common.h>
  4. #include <tataki/bitmap/autobitmap.h>
  5. #include <api/wnd/wndclass/guiobjwnd.h>
  6. #define SLIDERWND_PARENT GuiObjectWnd
  7. /**
  8. Slider style control.
  9. @short Slider style control.
  10. @author Nullsoft
  11. @ver 1.0
  12. */
  13. class SliderWnd : public SLIDERWND_PARENT
  14. {
  15. public:
  16. /**
  17. Sets the defaults for the slider. Defaults to a horizontal
  18. slider with the thumb in the center and is enabled.
  19. */
  20. SliderWnd();
  21. /**
  22. Nothing is handled by the destructor.
  23. */
  24. virtual ~SliderWnd();
  25. /**
  26. Event is triggered when the window requires a repaint.
  27. Override this to implement your own behavior.
  28. Paints the slider on canvas according to current
  29. state of the slider.
  30. @ret 0, Failed; 1, Success;
  31. @param canvas The canvas on which to paint.
  32. */
  33. virtual int onPaint(Canvas *canvas);
  34. /**
  35. Event is triggered when the left mouse button is pressed while
  36. the slider has focus. Override this to implement your
  37. own behavior.
  38. @ret
  39. @param x X coordinate of the mouse pointer.
  40. @param y Y coordinate of the mouse pointer.
  41. */
  42. virtual int onLeftButtonDown(int x, int y);
  43. /**
  44. Event is triggered when the mouse has capture on the slider
  45. and is being moved. Override this to implement your own
  46. behavior.
  47. @ret 0, Failed; 1, Success;
  48. @param x The X position of the mouse.
  49. @param y The Y position of the mouse.
  50. */
  51. virtual int onMouseMove(int x, int y); // only called when mouse captured
  52. /**
  53. Event is triggered when the left mouse button is released.
  54. Note that the mouse button must have been previously pressed
  55. for this event to happen. Override this to implement your
  56. own behavior.
  57. @ret 1, If you handle the event; 0, If you don't handle the event;
  58. @param x The X position of the mouse.
  59. @param y The Y position of the mouse.
  60. */
  61. virtual int onLeftButtonUp(int x, int y);
  62. /**
  63. Event is triggered when the right mouse button is pressed.
  64. Override this to implement your own behavior.
  65. */
  66. virtual int onRightButtonDown(int x, int y);
  67. /**
  68. Event is triggered when a key is pressed and the slider
  69. has focus. Override this to implement your own behavior.
  70. @ret 1, If you handle the event; 0, If you don't handle the event;
  71. @param c The key that was pressed.
  72. */
  73. virtual int onChar(unsigned int c);
  74. /**
  75. Event is triggered when the mouse enters the region
  76. of the slider. Override this to implement your
  77. own behavior.
  78. */
  79. virtual void onEnterArea();
  80. /**
  81. Event is triggered when the mouse leaves the region
  82. of the slider. Override this to implement your
  83. own behavior.
  84. */
  85. virtual void onLeaveArea();
  86. /**
  87. Event is triggered then the slider is about to be initialized.
  88. Override this event to implement your own behavior.
  89. By default this will render the slider according the it's current settings
  90. and position of the thumb.
  91. @ret 1, Success; 0, Failure;
  92. */
  93. virtual int onInit();
  94. /**
  95. Constants for positioning of the thumb.
  96. */
  97. enum {
  98. START = 0,
  99. END = 65535,
  100. FULL = END
  101. };
  102. /**
  103. Set the sliders position.
  104. @param newpos The sliders new position.
  105. @param wantcb !0, Generate a callback after the position has been set; 0, No callback;
  106. */
  107. virtual void setPosition(int newpos, int wantcb=1);
  108. /**
  109. Get the sliders current position. The range is from
  110. START (0) to END (65535).
  111. @ret The sliders position (ranges from 0 to 65535).
  112. */
  113. int getSliderPosition();
  114. //void cancelSeek();
  115. /**
  116. Use a base texture when rendering the slider.
  117. @see setBaseTexture()
  118. @param useit 0, Do not use; 1, Use base texture;
  119. */
  120. void setUseBaseTexture(int useit);
  121. /**
  122. Set the base texture of the slider.
  123. @see setUseBaseTexture()
  124. @see SkinBitmap
  125. @param bmp The bitmap to use as a texture.
  126. @param x The X position of the base texture.
  127. @param y The Y position of the base texture.
  128. */
  129. void setBaseTexture(SkinBitmap *bmp, int x, int y);
  130. /**
  131. Set the draw area to include the edge borders.
  132. @param draw 0, Do not include the edges; 1, Include the edges;
  133. */
  134. void setDrawOnBorders(int draw);
  135. /**
  136. Do not use the default background provided
  137. by the current skin?
  138. If you set this to 1, you MUST specify your bitmaps.
  139. @param no 0, Use default background; 1, Do not use default;
  140. */
  141. void setNoDefaultBackground(int no);
  142. /**
  143. Set the bitmaps to be used to render the slider.
  144. These include bitmaps for the left, middle, right of
  145. the slider. For the thumb, we have bitmaps for the
  146. normal, hilited and pushed thumb.
  147. The bitmaps are set using their xml id or "name".
  148. The name should resemble something like this:
  149. "studio.seekbar.left".
  150. @see setLeftBmp()
  151. @see setMiddleBmp()
  152. @see setRightBmp()
  153. @see setThumbBmp()
  154. @see setThumbDownBmp()
  155. @see setThumbHiliteBmp()
  156. @param thumbbmp The normal thumb bitmap name.
  157. @param thumbdownbmp The thumb down bitmap name.
  158. @param thumbhighbmp The hilited thumb bitmap name.
  159. @param leftbmp The left bitmap of the slider name.
  160. @param middlebmp The middle bitmap of the slider name.
  161. @param rightbmp The right bitmap of the slider name.
  162. */
  163. 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);
  164. /**
  165. Set the left bitmap of the slider.
  166. @param name The left bitmap name.
  167. */
  168. void setLeftBmp(const wchar_t *name);
  169. /**
  170. Set the middle bitmap of the slider.
  171. @param name The middle bitmap name.
  172. */
  173. void setMiddleBmp(const wchar_t *name);
  174. /**
  175. Set the right bitmap of the slider.
  176. @param name The right bitmap name.
  177. */
  178. void setRightBmp(const wchar_t *name);
  179. /**
  180. Set the normal thumb bitmap of the slider.
  181. @param name The normal thumb bitmap name.
  182. */
  183. void setThumbBmp(const wchar_t *name);
  184. /**
  185. Set the thumb down bitmap of the slider.
  186. @param name The thumb down bitmap name.
  187. */
  188. void setThumbDownBmp(const wchar_t *name);
  189. /**
  190. Set the hilited thumb bitmap of the slider.
  191. @param name The hilited thumb bitmap name.
  192. */
  193. void setThumbHiliteBmp(const wchar_t *name);
  194. /**
  195. Get the height of the slider in pixels.
  196. @ret The height of the slider (in pixels).
  197. */
  198. virtual int getHeight();
  199. /**
  200. Get the width of the slider in pixels.
  201. @ret The width of the slider (in pixels).
  202. */
  203. virtual int getWidth();
  204. /**
  205. Get the left bitmap of the slider.
  206. @see SkinBitmap
  207. @ret The left SkinBitmap.
  208. */
  209. SkinBitmap *getLeftBitmap();
  210. /**
  211. Get the right bitmap of the slider.
  212. @see SkinBitmap
  213. @ret The right SkinBitmap.
  214. */
  215. SkinBitmap *getRightBitmap();
  216. /**
  217. Get the middle bitmap of the slider.
  218. @see SkinBitmap
  219. @ret The middle SkinBitmap.
  220. */
  221. SkinBitmap *getMiddleBitmap();
  222. /**
  223. Get the thumb bitmap of the slider.
  224. @see SkinBitmap
  225. @ret The thumb SkinBitmap.
  226. */
  227. SkinBitmap *getThumbBitmap();
  228. /**
  229. Get the thumb down bitmap of the slider.
  230. @see SkinBitmap
  231. @ret The thumb down SkinBitmap.
  232. */
  233. SkinBitmap *getThumbDownBitmap();
  234. /**
  235. Get the thumb hilite bitmap of the slider.
  236. @see SkinBitmap
  237. @ret The thumb hilite SkinBitmap.
  238. */
  239. SkinBitmap *getThumbHiliteBitmap();
  240. /**
  241. Set the sliders enable state.
  242. @param en 1, Enabled; 0, Disabled;
  243. */
  244. virtual void setEnable(int en);
  245. /**
  246. Get the sliders enable state.
  247. @ret 1, Enabled; 0, Disabled;
  248. */
  249. virtual int getEnable(void);
  250. /**
  251. Set the orientation of the slider
  252. (horizontal or vertical).
  253. @param o 0, Horizontal; 1, Vertical;
  254. */
  255. virtual void setOrientation(int o);
  256. /**
  257. This will set a "jump-to" position (like "center" for a balance slider).
  258. The parameter is in thumb coordinates (0 to 65535).
  259. @param h The jump-to position (ranges from 0 to 65535, or START to END).
  260. */
  261. virtual void setHotPosition(int h);
  262. virtual int getHotPosRange() { return hotposrange; }
  263. virtual void setHotPosRange(int range) { hotposrange = range; }
  264. /**
  265. Set the thumb center flag. If on, this flag will
  266. cause the thumb of the slider to be centered
  267. automatically.
  268. @param c 1, Centered; 0, No centering;
  269. */
  270. virtual void setThumbCentered(int c);
  271. virtual void setThumbStretched(int c);
  272. /**
  273. Set the thumb offset (from the left hand side).
  274. This offset will be added to the zero position of the thumb.
  275. Note, if you're using centering also, this will cause the slider
  276. thumb to be passed the middle of the slider.
  277. @param o The offset of the thumb (in pixels).
  278. */
  279. virtual void setThumbOffset(int o);
  280. /**
  281. Set the minimum and maximum limit for the slider.
  282. @param minlimit The minimum value.
  283. @param maxlimit The maximum value.
  284. */
  285. virtual void setLimits(int minlimit, int maxlimit);
  286. virtual int getMaxLimit() { return maxlimit; }
  287. virtual int getMinLimit() { return minlimit; }
  288. virtual int getRange() { return maxlimit-minlimit; }
  289. virtual int onKeyDown(int vkcode);
  290. virtual void onCancelCapture();
  291. protected:
  292. /**
  293. Abort the current seek and end capture.
  294. */
  295. void abort();
  296. // override this to get position change notification
  297. /**
  298. Event is triggered when the mouse is moving the thumb
  299. is being moved. Override this to implment your own behavior.
  300. @ret The thumb's position (ranges from 0 to 65535 or START to END).
  301. */
  302. virtual int onSetPosition(); // called constantly as mouse moves
  303. /**
  304. Event is triggered when the thumb is released and the final position
  305. is about to be set.
  306. @ret The thumb's position (ranges from 0 to 65535 or START to END).
  307. */
  308. virtual int onSetFinalPosition(); // called once after move done
  309. /**
  310. Get the seeking status.
  311. @ret 1, User is seeking; 0, User is not seeking;
  312. */
  313. int getSeekStatus(); // returns 1 if user is sliding tab
  314. int vertical; // set to 1 for up-n-down instead
  315. /**
  316. Get the width of the thumb bitmap, in pixels.
  317. @ret The thumb's width (in pixels).
  318. */
  319. int thumbWidth();
  320. /**
  321. Get the height of the thumb bitmap, in pixels.
  322. @ret The thumb's width (in pixels).
  323. */
  324. int thumbHeight();
  325. // keyboard
  326. void move_left(int bigstep);
  327. void move_right(int bigstep);
  328. void move_start();
  329. void move_end();
  330. int minlimit, maxlimit, length;
  331. private:
  332. int seeking;
  333. int enabled;
  334. int hilite;
  335. int pos;
  336. int oldpos;
  337. int thumbwidth;
  338. int captured;
  339. int xShift, yShift;
  340. SkinBitmap *base_texture;
  341. int use_base_texture;
  342. int no_default_background;
  343. int drawOnBorders;
  344. int hotPosition;
  345. int origPos;
  346. int thumbCentered, thumbOffset, thumbStretched;
  347. int hotposrange;
  348. AutoSkinBitmap left, middle, right;
  349. AutoSkinBitmap thumb, thumbdown, thumbhilite;
  350. };
  351. #endif