SlideBar.h 6.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /******************************************************************************/
  2. enum SLIDEBAR_BACK_CLICK_MODE : Byte // action when clicking on the background of the SlideBar
  3. {
  4. SBC_OFF , // nothing happens
  5. SBC_STEP , // one time scroll will be performed by a single step
  6. SBC_SMOOTH , // smooth scrolling will be performed as long as the click is hold
  7. SBC_SET_POS, // slidebar position will be immediately set to the click position
  8. };
  9. const_mem_addr STRUCT(SlideBar , GuiObj) // Gui SlideBar !! must be stored in constant memory address !!
  10. //{
  11. Button button[3]; // 3 buttons (0=middle, 1=left/up, 2=right/down)
  12. SLIDEBAR_BACK_CLICK_MODE sbc ; // default=SBC_STEP
  13. // manage
  14. SlideBar& del ( ); // delete
  15. SlideBar& create( ); // create
  16. SlideBar& create(C Rect &rect) {return create().rect(rect);} // create and set rectangle
  17. SlideBar& create(C SlideBar &src ); // create from 'src'
  18. // set / get
  19. SlideBar& setLengths (Flt length, Flt length_total ); // set, 'length'=covered length, 'length_total'=total length
  20. SlideBar& set (Flt step , SET_MODE mode=SET_DEFAULT); // set slidebar step (0..1)
  21. Flt operator() ( )C; // get slidebar step (0..1)
  22. Flt wantedOffset( )C; // get slidebar offset desired (0..length_total-length)
  23. Flt offset( )C {return _offset ;} // get slidebar offset at the moment (0..length_total-length)
  24. SlideBar& offset(Flt offset, SET_MODE mode=SET_DEFAULT); // set slidebar offset (0..length_total-length)
  25. Flt length ( )C {return _length ;} // get slidebar length
  26. Flt lengthTotal( )C {return _length_total;} // get slidebar length total
  27. SlideBar& skin (C GuiSkinPtr &skin ); // set skin override, default=null (if set to null then current value of 'Gui.skin' is used), changing this value will automatically change the skin of the SlideBar buttons
  28. C GuiSkinPtr& skin ( )C {return _skin ;} // get skin override, default=null (if set to null then current value of 'Gui.skin' is used)
  29. GuiSkin* getSkin ( )C {return _skin ? _skin() : Gui.skin();} // get actual skin
  30. Bool wantedAtEnd(Flt eps=EPS)C {return wantedOffset()+length()+eps>=lengthTotal();} // if slidebar is wanted to be at the end
  31. SlideBar& func(void (*func)(Ptr user), Ptr user=null, Bool immediate=true); // set function called when value has changed, with 'user' as its parameter
  32. T1(TYPE) SlideBar& func(void (*func)(TYPE *user), TYPE *user , Bool immediate=true) {return T.func((void(*)(Ptr))func, user, immediate);} // set function called when value has changed, with 'user' as its parameter
  33. T1(TYPE) SlideBar& func(void (*func)(TYPE &user), TYPE &user , Bool immediate=true) {return T.func((void(*)(Ptr))func, &user, immediate);} // set function called when value has changed, with 'user' as its parameter
  34. virtual SlideBar& desc(C Str &desc); C Str& desc()C {return super::desc();} // set/get description
  35. SlideBar& focusable(Bool on); Bool focusable()C {return _focusable;} // set/get if can catch keyboard focus, default=true
  36. // operations
  37. virtual SlideBar& rect(C Rect &rect ); C Rect& rect()C {return super::rect();} // set/get rectangle
  38. virtual SlideBar& move(C Vec2 &delta); // move by delta
  39. SlideBar& scroll (Flt delta , Bool immediate=false); // scroll by delta
  40. SlideBar& scrollTo (Flt pos , Bool immediate=false); // scroll to pos
  41. SlideBar& scrollFit(Flt min, Flt max, Bool immediate=false); // scroll to fit min..max range
  42. SlideBar& scrollEnd( Bool immediate=false); // scroll to end
  43. SlideBar& scrollOptions(Flt relative=0.5f, Flt base=0, Bool immediate=false, Flt button_speed=1.5f); // set scrolling options, 'relative'=amount of scrolling using the mouse wheel relative to slidebar 'length' (0..Inf, default=1), 'base'=constant amount of scrolling using mouse wheel (0..Inf, default=0), 'immediate'=if mouse wheel scrolling is immediate or smooth, 'button_speed'=speed of scrolling upon pressing the left/up/right/down buttons
  44. SlideBar& removeSideButtons(); // remove side buttons (left/up and right/down) leaving only the middle button
  45. // main
  46. virtual GuiObj* test (C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel); // test if 'pos' screen position intersects with the object, by returning pointer to object or its children upon intersection and null in case no intersection, 'mouse_wheel' may be modified upon intersection either to the object or its children or null
  47. virtual void update(C GuiPC &gpc); // update object
  48. virtual void draw (C GuiPC &gpc); // draw object
  49. #if EE_PRIVATE
  50. void zero ();
  51. void setButtonSubType();
  52. void setParams ();
  53. void setButtonRect ();
  54. SlideBar& setOffset (Flt offset, Bool stop=true, SET_MODE mode=SET_DEFAULT);
  55. void call ();
  56. #endif
  57. ~SlideBar() {del();}
  58. SlideBar();
  59. #if !EE_PRIVATE
  60. private:
  61. #endif
  62. Bool _scroll_immediate, _scroll, _vertical, _usable, _focusable, _func_immediate;
  63. Flt _scroll_to, _offset, _length, _length_total, _scroll_mul, _scroll_add, _scroll_button, _button_size;
  64. Ptr _func_user;
  65. void (*_func)(Ptr user);
  66. GuiSkinPtr _skin;
  67. protected:
  68. virtual Bool save(File &f, CChar *path=null)C;
  69. virtual Bool load(File &f, CChar *path=null) ;
  70. NO_COPY_CONSTRUCTOR(SlideBar);
  71. #if EE_PRIVATE
  72. friend struct Region; friend struct TextBox;
  73. #endif
  74. };
  75. /******************************************************************************/