Neo  0.5.0
Developer Documentation
ScrollPane.h
Go to the documentation of this file.
1 #ifndef __SCROLLBAR_H
2 #define __SCROLLBAR_H
3 
4 #include <Neo2DEngine.h>
5 #include <Container.h>
6 #include <ScrollBar.h>
7 #include <vector>
8 
9 #define m_scrollWidth 1
10 #define SCROLL_BAR_WIDTH 10
11 
12 namespace Neo2D
13 {
14 namespace Gui
15 {
16 using namespace Neo;
17 
23 class NEO2D_EXPORT ScrollPane : public Container
24 {
25  ScrollBar* m_horizontal;
26  ScrollBar* m_vertical;
27 
28  void positionScrollBars()
29  {
30  // Update scale and position
31  m_horizontal->setSize(m_width - SCROLL_BAR_WIDTH, 1);
32  m_vertical->setSize(1, m_height - SCROLL_BAR_WIDTH);
33 
34  m_horizontal->setPosition(Vector2(m_x, m_y+m_height-SCROLL_BAR_WIDTH));
35  m_vertical->setPosition(Vector2(m_x + m_width - SCROLL_BAR_WIDTH, m_y));
36 
37  Vector2 sz = calculateContentSize();
38  m_horizontal->setRange(Vector2(0, MAX(m_width - SCROLL_BAR_WIDTH, sz.x)));
39  m_vertical->setRange(Vector2(0, MAX(m_height - SCROLL_BAR_WIDTH, sz.y)));
40  }
41 
42 public:
43  ScrollPane(unsigned int x, unsigned int y, unsigned int width,
44  unsigned int height)
45  : Container(x, y, width, height, "")
46  {
47  m_horizontal = new ScrollBar(x, y+height-m_scrollWidth, width, m_scrollWidth, 0, 100, SLIDER_HORIZONTAL);
48 
49  m_vertical = new ScrollBar(x + width, y, m_scrollWidth, height, 0, 100, SLIDER_VERTICAL);
50  positionScrollBars();
51  }
52 
53  ~ScrollPane();
54 
55  void draw() { draw(Vector2(0,0)); }
56  void draw(Vector2 offset);
57  void update();
58 
59  private:
60  Vector2 calculateValue() { return getPosition() - Vector2(floor(m_horizontal->getValue()), floor(m_vertical->getValue())); }
61 
62  Vector2 calculateContentSize();
63  Vector2 getSize() { return Vector2(m_width - SCROLL_BAR_WIDTH, m_height - SCROLL_BAR_WIDTH); }
64 };
65 
66 }
67 }
68 
69 #endif
void setRange(Vector2 range)
Definition: ScrollBar.h:81
float getValue()
Definition: ScrollBar.h:89
void setPosition(Vector2 pos)
Changes the widget position.
Definition: Widget.h:234
Definition: Slider.h:53
This class implements a scroll panel that can be used to display widgets.
Definition: ScrollPane.h:23
float y
Definition: Vector2.h:36
float x
Definition: Vector2.h:35
A Container organizes multiple Widgets into one to provide layout functionality.
Definition: Container.h:20
void draw()
Draws the widget to the canvas it belongs to.
Definition: ScrollPane.h:55
Definition: Vector2.h:31
Definition: Button.h:42
ScrollPane(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
Definition: ScrollPane.h:43
Definition: Slider.h:52
Definition: Color.h:29
void setSize(unsigned int w, unsigned int h)
Definition: Widget.h:141
The ScrollBar class implements a slider that interpolates values in a given range.
Definition: ScrollBar.h:57