GlistEngine
Loading...
Searching...
No Matches
gGUIScrollable.h
Go to the documentation of this file.
1/****************************************************************************
2 * Copyright (c) 2014 Nitra Games Ltd., Istanbul, Turkey *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
11 * *
12 * The above copyright notice and this permission notice should not be *
13 * deleted from the source form of the Software. *
14 * *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22 * *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
26 * authorization. *
27 ****************************************************************************/
28
29/****************************************************************************
30 * Author: Noyan Culum, Sevval Bulburu, Aynur Dogan 2022-08-19 *
31 ****************************************************************************/
32
33/*
34 * gGUIScrollable.h
35 *
36 * Created on: Feb 5, 2022
37 * Author: noyan
38 */
39
40#ifndef UI_GGUISCROLLABLE_H_
41#define UI_GGUISCROLLABLE_H_
42
43#include "gGUIControl.h"
44#include "gFbo.h"
45
46/*
47 * This class is a child class of gGUIControl. Scrollable class provide scrollable
48 * function on objects. When the box object's width and height is smaller than
49 * it's content, developers can use this class.
50 *
51 * For using this class, firstly a set function must be wrote in the class that
52 * used Scrollalble class. In this set function, set function must be called
53 * from gGUIControl class. Secondly, setDimensions() function must be called
54 * from Scrollable class. setDimensions() function updates some variables for
55 * using draw window and scroll bars. Because of that parameters should be width
56 * and height. Except for this two function, developers can call any function
57 * which should be setted when added object to panel.
58 *
59 * After written set function, enableScrollbars function must be called. This
60 * function makes scroll bars visible. For using scrollable function at least one
61 * of the parameters must be active.
62 *
63 * If a class is generated from Scrollable class with inheritance, new class must
64 * overrided drawContent() function.
65 *
66 */
67
69public:
71 virtual ~gGUIScrollable();
72
73 /*
74 * Makes scrollbars visible or invisible. For using scrollable function in
75 * other gui objects, this function must be used. First parameter is for the
76 * verticle scroll bar and the second one is horizontal scroll bar. Developer
77 * can use both of the equalities or one of them. bool 'true' makes the bars
78 * visible. When a bar is visible, that means that scrollable function is
79 * active for the given direction.
80 *
81 * @param isVerticalEnabled is a bool value that makes vertical scroll bar
82 * active or inactive. 'true ' for activation, 'false ' for inactivation.
83 *
84 * @param isHorizontalEnabled is a bool value that makes horizontal scroll bar
85 * active or inactive. 'true ' for activation, 'false ' for inactivation.
86 */
87 void enableScrollbars(bool isVerticalEnabled, bool isHorizontalEnabled);
88
90
91 void draw();
92
93 /*
94 * Draws contents of class. But it is empty for now, must be overrided in
95 * child classes from this parent class.
96 */
97 virtual void drawContent();
98
99 /*
100 * Draws scroll bars according to if vertical or horizontal movement is
101 * enabled.
102 */
103 virtual void drawScrollbars();
104
105 /*
106 * Updates the width and height of the window with given parameters. This
107 * function is overrided from gGUIControl class.
108 *
109 * @param w is the new width value.
110 *
111 * @param h is the new height value.
112 */
113 virtual void windowResized(int w, int h);
114
115 virtual void mouseMoved(int x, int y);
116 virtual void mousePressed(int x, int y, int button);
117 virtual void mouseDragged(int x, int y, int button);
118 virtual void mouseReleased(int x, int y, int button);
119
120 /*
121 * Makes the scroll movement according to coordinate of the mouse. When mouse
122 * used for scroll, it changed some values of box that we draw.
123 *
124 */
125 virtual void mouseScrolled(int x, int y);
126
128
129
131
133
134 void setToolbarSpace(int toolbarW, int toolbarH);
135
136protected:
137 bool isPointInsideVerticalScrollbar(int x, int y, bool checkFullSize = false);
138 bool isPointInsideHorizontalScrollbar(int x, int y, bool checkFullSize = false);
139
140 /*
141 * Updates the values of variables that we use to draw window and scrollbars
142 * with the given parameters.
143 *
144 * @param w is the new width value.
145 *
146 * @param h is the new height value.
147 */
148 void setDimensions(int width, int height);
149
150protected:
151 const int barsize = 12;
152
154
155 int boxw = 0, boxh = 0; // viewport size
156 int totalw = 0, totalh = 0; // content size
157 int verticalscroll = 0, horizontalscroll = 0; // content scroll amounts
158
159 int verticalscrollbarpos = 0, horizontalscrollbarpos = 0; // scaled scrollbar position for rendering
160 int scrollbarverticalsize = 0, scrollbarhorizontalsize = 0; // scrollbar size for rendering
161
162 // for dragging the bars
169private:
170 gFbo* boxfbo;
171
172 bool enableverticalscroll, enablehorizontalscroll;
173 gColor barbackgroundcolor, barforegroundcolor;
174 int toolbarw, toolbarh;
175};
176
177#endif /* UI_GGUISCROLLABLE_H_ */
int width
Definition gBaseGUIObject.h:120
int height
Definition gBaseGUIObject.h:120
Definition gColor.h:17
Definition gFbo.h:15
Definition gGUIControl.h:29
Definition gGUIScrollable.h:68
virtual ~gGUIScrollable()
int verticalscroll
Definition gGUIScrollable.h:157
virtual void drawScrollbars()
const int barsize
Definition gGUIScrollable.h:151
int boxh
Definition gGUIScrollable.h:155
int totalh
Definition gGUIScrollable.h:156
bool isPointInsideVerticalScrollbar(int x, int y, bool checkFullSize=false)
virtual void drawContent()
virtual void mousePressed(int x, int y, int button)
virtual void mouseMoved(int x, int y)
bool isdraggingverticalscroll
Definition gGUIScrollable.h:163
virtual void mouseReleased(int x, int y, int button)
void enableScrollbars(bool isVerticalEnabled, bool isHorizontalEnabled)
int totalw
Definition gGUIScrollable.h:156
int horizontalscroll
Definition gGUIScrollable.h:157
void setDimensions(int width, int height)
virtual void mouseDragged(int x, int y, int button)
void updateScrollbar()
virtual void windowResized(int w, int h)
int scrollbarverticalsize
Definition gGUIScrollable.h:160
bool isPointInsideHorizontalScrollbar(int x, int y, bool checkFullSize=false)
int horizontalscrollbarpos
Definition gGUIScrollable.h:159
int getVerticalScroll()
int verticalscrollbarpos
Definition gGUIScrollable.h:159
float verticalscrollclickedtime
Definition gGUIScrollable.h:165
int boxw
Definition gGUIScrollable.h:155
float horizontalscrollclickedtime
Definition gGUIScrollable.h:168
gFbo * getFbo()
virtual void mouseScrolled(int x, int y)
void setToolbarSpace(int toolbarW, int toolbarH)
int scrollbarhorizontalsize
Definition gGUIScrollable.h:160
int verticalscrolldragstart
Definition gGUIScrollable.h:164
int horizontalscrolldragstart
Definition gGUIScrollable.h:167
bool isdragginghorizontalscroll
Definition gGUIScrollable.h:166
int scrollamount
Definition gGUIScrollable.h:153