guiScrollBar.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright (C) 2002-2013 Nikolaus Gebhardt
  3. This file is part of the "Irrlicht Engine".
  4. For conditions of distribution and use, see copyright notice in irrlicht.h
  5. Modified 2019.05.01 by stujones11, Stuart Jones <stujones111@gmail.com>
  6. This is a heavily modified copy of the Irrlicht CGUIScrollBar class
  7. which includes automatic scaling of the thumb slider and hiding of
  8. the arrow buttons where there is insufficient space.
  9. */
  10. #pragma once
  11. #include "irrlichttypes_extrabloated.h"
  12. class ISimpleTextureSource;
  13. using namespace irr;
  14. using namespace gui;
  15. class GUIScrollBar : public IGUIElement
  16. {
  17. public:
  18. GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id,
  19. core::rect<s32> rectangle, bool horizontal, bool auto_scale,
  20. ISimpleTextureSource *tsrc);
  21. enum ArrowVisibility
  22. {
  23. HIDE,
  24. SHOW,
  25. DEFAULT
  26. };
  27. virtual void draw();
  28. virtual void updateAbsolutePosition();
  29. virtual bool OnEvent(const SEvent &event);
  30. s32 getMax() const { return max_pos; }
  31. s32 getMin() const { return min_pos; }
  32. s32 getLargeStep() const { return large_step; }
  33. s32 getSmallStep() const { return small_step; }
  34. s32 getPos() const;
  35. void setMax(const s32 &max);
  36. void setMin(const s32 &min);
  37. void setSmallStep(const s32 &step);
  38. void setLargeStep(const s32 &step);
  39. void setPos(const s32 &pos);
  40. void setPageSize(const s32 &size);
  41. void setArrowsVisible(ArrowVisibility visible);
  42. private:
  43. void refreshControls();
  44. s32 getPosFromMousePos(const core::position2di &p) const;
  45. f32 range() const { return f32(max_pos - min_pos); }
  46. IGUIButton *up_button;
  47. IGUIButton *down_button;
  48. ArrowVisibility arrow_visibility = DEFAULT;
  49. bool is_dragging;
  50. bool is_horizontal;
  51. bool is_auto_scaling;
  52. bool dragged_by_slider;
  53. bool tray_clicked;
  54. s32 scroll_pos;
  55. s32 draw_center;
  56. s32 thumb_size;
  57. s32 min_pos;
  58. s32 max_pos;
  59. s32 small_step;
  60. s32 large_step;
  61. s32 drag_offset;
  62. s32 page_size;
  63. s32 border_size;
  64. core::rect<s32> slider_rect;
  65. video::SColor current_icon_color;
  66. ISimpleTextureSource *m_tsrc;
  67. };