DDraceNetwork Docs
ui_scrollregion.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_CLIENT_UI_SCROLLREGION_H
4#define GAME_CLIENT_UI_SCROLLREGION_H
5
6#include "ui.h"
7
9{
21 unsigned m_Flags;
22
23 enum
24 {
26 };
27
29 {
30 m_ScrollbarWidth = 20.0f;
31 m_ScrollbarMargin = 5.0f;
33 m_SliderMinHeight = 25.0f;
34 m_ScrollUnit = 10.0f;
35 m_ClipBgColor = ColorRGBA(0.0f, 0.0f, 0.0f, 0.0f);
36 m_ScrollbarBgColor = ColorRGBA(0.0f, 0.0f, 0.0f, 0.0f);
37 m_RailBgColor = ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f);
38 m_SliderColor = ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f);
39 m_SliderColorHover = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
40 m_SliderColorGrabbed = ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f);
41 m_Flags = 0;
42 }
43
44 ColorRGBA SliderColor(bool Active, bool Hovered) const
45 {
46 if(Active)
48 else if(Hovered)
49 return m_SliderColorHover;
50 return m_SliderColor;
51 }
52};
53
54/*
55Usage:
56 -- Initialization --
57 static CScrollRegion s_ScrollRegion;
58 vec2 ScrollOffset(0, 0);
59 s_ScrollRegion.Begin(&ScrollRegionRect, &ScrollOffset);
60 Content = ScrollRegionRect;
61 Content.y += ScrollOffset.y;
62
63 -- "Register" your content rects --
64 CUIRect Rect;
65 Content.HSplitTop(SomeValue, &Rect, &Content);
66 s_ScrollRegion.AddRect(Rect);
67
68 -- [Optional] Knowing if a rect is clipped --
69 s_ScrollRegion.RectClipped(Rect);
70
71 -- [Optional] Scroll to a rect (to the last added rect)--
72 ...
73 s_ScrollRegion.AddRect(Rect);
74 s_ScrollRegion.ScrollHere(Option);
75
76 -- [Convenience] Add rect and check for visibility at the same time
77 if(s_ScrollRegion.AddRect(Rect))
78 // The rect is visible (not clipped)
79
80 -- [Convenience] Add rect and scroll to it if it's selected
81 if(s_ScrollRegion.AddRect(Rect, ScrollToSelection && IsSelected))
82 // The rect is visible (not clipped)
83
84 -- End --
85 s_ScrollRegion.End();
86*/
87
88// Instances of CScrollRegion must be static, as member addresses are used as UI item IDs
90{
91public:
92 // TODO: Properly fix whatever is causing the 1-pixel discrepancy in scrolling rect height and remove this magic value.
93 // Currently this must be added when calculating the required height of a UI rect for a scroll region to get a perfect fit.
94 static constexpr float HEIGHT_MAGIC_FIX = 1.0f;
95
97 {
101 };
102
103private:
106 float m_RequestScrollY; // [0, ContentHeight]
109
114
117 CUIRect m_LastAddedRect; // saved for ScrollHere()
118 float m_SliderGrabPos; // where did user grab the slider
121
122public:
124 {
128 };
129
131 void Begin(CUIRect *pClipRect, vec2 *pOutOffset, const CScrollRegionParams *pParams = nullptr);
132 void End();
133 bool AddRect(const CUIRect &Rect, bool ShouldScrollHere = false); // returns true if the added rect is visible (not clipped)
135 void ScrollRelative(EScrollRelative Direction, float SpeedMultiplier = 1.0f);
136 void ScrollRelativeDirect(float ScrollAmount);
137 const CUIRect *ClipRect() const { return &m_ClipRect; }
138 void DoEdgeScrolling();
139 bool RectClipped(const CUIRect &Rect) const;
140 bool ScrollbarShown() const;
141 bool Animating() const;
142 bool Active() const;
143 const CScrollRegionParams &Params() const { return m_Params; }
144};
145
146#endif
Definition: ui_scrollregion.h:90
void DoEdgeScrolling()
Definition: ui_scrollregion.cpp:242
float m_ScrollSpeedMultiplier
Definition: ui_scrollregion.h:108
CUIRect m_RailRect
Definition: ui_scrollregion.h:116
bool ScrollbarShown() const
Definition: ui_scrollregion.cpp:263
CUIRect m_ClipRect
Definition: ui_scrollregion.h:115
bool Animating() const
Definition: ui_scrollregion.cpp:268
float m_AnimInitScrollY
Definition: ui_scrollregion.h:112
const CUIRect * ClipRect() const
Definition: ui_scrollregion.h:137
CScrollRegion()
Definition: ui_scrollregion.cpp:12
float m_AnimTime
Definition: ui_scrollregion.h:111
void ScrollRelativeDirect(float ScrollAmount)
Definition: ui_scrollregion.cpp:237
vec2 m_ContentScrollOff
Definition: ui_scrollregion.h:119
bool AddRect(const CUIRect &Rect, bool ShouldScrollHere=false)
Definition: ui_scrollregion.cpp:195
float m_AnimTimeMax
Definition: ui_scrollregion.h:110
bool Active() const
Definition: ui_scrollregion.cpp:273
EScrollOption
Definition: ui_scrollregion.h:124
@ SCROLLHERE_TOP
Definition: ui_scrollregion.h:126
@ SCROLLHERE_BOTTOM
Definition: ui_scrollregion.h:127
@ SCROLLHERE_KEEP_IN_VIEW
Definition: ui_scrollregion.h:125
void End()
Definition: ui_scrollregion.cpp:70
float m_AnimTargetScrollY
Definition: ui_scrollregion.h:113
CUIRect m_LastAddedRect
Definition: ui_scrollregion.h:117
float m_ContentH
Definition: ui_scrollregion.h:105
static constexpr float HEIGHT_MAGIC_FIX
Definition: ui_scrollregion.h:94
void Begin(CUIRect *pClipRect, vec2 *pOutOffset, const CScrollRegionParams *pParams=nullptr)
Definition: ui_scrollregion.cpp:30
EScrollRelative m_ScrollDirection
Definition: ui_scrollregion.h:107
float m_ScrollY
Definition: ui_scrollregion.h:104
EScrollRelative
Definition: ui_scrollregion.h:97
@ SCROLLRELATIVE_NONE
Definition: ui_scrollregion.h:99
@ SCROLLRELATIVE_DOWN
Definition: ui_scrollregion.h:100
@ SCROLLRELATIVE_UP
Definition: ui_scrollregion.h:98
bool RectClipped(const CUIRect &Rect) const
Definition: ui_scrollregion.cpp:258
void ScrollHere(EScrollOption Option=SCROLLHERE_KEEP_IN_VIEW)
Definition: ui_scrollregion.cpp:205
void ScrollRelative(EScrollRelative Direction, float SpeedMultiplier=1.0f)
Definition: ui_scrollregion.cpp:231
float m_RequestScrollY
Definition: ui_scrollregion.h:106
float m_SliderGrabPos
Definition: ui_scrollregion.h:118
CScrollRegionParams m_Params
Definition: ui_scrollregion.h:120
const CScrollRegionParams & Params() const
Definition: ui_scrollregion.h:143
Definition: ui.h:233
Definition: ui_rect.h:11
Definition: color.h:210
Definition: ui_scrollregion.h:9
CScrollRegionParams()
Definition: ui_scrollregion.h:28
@ FLAG_CONTENT_STATIC_WIDTH
Definition: ui_scrollregion.h:25
unsigned m_Flags
Definition: ui_scrollregion.h:21
ColorRGBA m_SliderColor
Definition: ui_scrollregion.h:18
ColorRGBA m_ScrollbarBgColor
Definition: ui_scrollregion.h:16
ColorRGBA m_ClipBgColor
Definition: ui_scrollregion.h:15
ColorRGBA m_SliderColorHover
Definition: ui_scrollregion.h:19
ColorRGBA m_RailBgColor
Definition: ui_scrollregion.h:17
float m_ScrollbarMargin
Definition: ui_scrollregion.h:11
ColorRGBA SliderColor(bool Active, bool Hovered) const
Definition: ui_scrollregion.h:44
float m_SliderMinHeight
Definition: ui_scrollregion.h:13
float m_ScrollUnit
Definition: ui_scrollregion.h:14
ColorRGBA m_SliderColorGrabbed
Definition: ui_scrollregion.h:20
float m_ScrollbarWidth
Definition: ui_scrollregion.h:10
bool m_ScrollbarNoMarginRight
Definition: ui_scrollregion.h:12