1 #pragma once
2 
3 #include "DiabloUI/art.h"
4 #include "DiabloUI/ui_item.h"
5 
6 namespace dvl {
7 
8 extern Art ArtScrollBarBackground;
9 extern Art ArtScrollBarThumb;
10 extern Art ArtScrollBarArrow;
11 const Uint16 SCROLLBAR_BG_WIDTH = 25;
12 
13 extern Art ArtScrollBarArrow;
14 enum ScrollBarArrowFrame {
15 	ScrollBarArrowFrame_UP_ACTIVE = 0,
16 	ScrollBarArrowFrame_UP,
17 	ScrollBarArrowFrame_DOWN_ACTIVE,
18 	ScrollBarArrowFrame_DOWN,
19 };
20 
21 extern Art ArtScrollBarThumb;
22 const Uint16 SCROLLBAR_ARROW_WIDTH = 25;
23 
UpArrowRect(const UiScrollBar * sb)24 inline SDL_Rect UpArrowRect(const UiScrollBar *sb)
25 {
26 	SDL_Rect Tmp;
27 	Tmp.x = sb->m_rect.x;
28 	Tmp.y = sb->m_rect.y;
29 	Tmp.w = SCROLLBAR_ARROW_WIDTH;
30 	Tmp.h = static_cast<Uint16>(sb->m_arrow->h());
31 
32 	return Tmp;
33 }
34 
DownArrowRect(const UiScrollBar * sb)35 inline SDL_Rect DownArrowRect(const UiScrollBar *sb)
36 {
37 	SDL_Rect Tmp;
38 	Tmp.x = sb->m_rect.x;
39 	Tmp.y = static_cast<Sint16>(sb->m_rect.y + sb->m_rect.h - sb->m_arrow->h());
40 	Tmp.w = SCROLLBAR_ARROW_WIDTH,
41 	Tmp.h = static_cast<Uint16>(sb->m_arrow->h());
42 
43 	return Tmp;
44 }
45 
BarHeight(const UiScrollBar * sb)46 inline Uint16 BarHeight(const UiScrollBar *sb)
47 {
48 	return sb->m_rect.h - 2 * sb->m_arrow->h();
49 }
50 
BarRect(const UiScrollBar * sb)51 inline SDL_Rect BarRect(const UiScrollBar *sb)
52 {
53 	SDL_Rect Tmp;
54 	Tmp.x = sb->m_rect.x;
55 	Tmp.y = static_cast<Sint16>(sb->m_rect.y + sb->m_arrow->h());
56 	Tmp.w = SCROLLBAR_ARROW_WIDTH,
57 	Tmp.h = BarHeight(sb);
58 
59 	return Tmp;
60 }
61 
ThumbRect(const UiScrollBar * sb,std::size_t selected_index,std::size_t num_items)62 inline SDL_Rect ThumbRect(const UiScrollBar *sb, std::size_t selected_index, std::size_t num_items)
63 {
64 	const int THUMB_OFFSET_X = 3;
65 	const int thumb_max_y = BarHeight(sb) - sb->m_thumb->h();
66 	const int thumb_y = (selected_index * thumb_max_y / (num_items - 1));
67 
68 	SDL_Rect Tmp;
69 	Tmp.x = static_cast<Sint16>(sb->m_rect.x + THUMB_OFFSET_X);
70 	Tmp.y = static_cast<Sint16>(sb->m_rect.y + sb->m_arrow->h() + thumb_y);
71 	Tmp.w = static_cast<Uint16>(sb->m_rect.w - THUMB_OFFSET_X);
72 	Tmp.h = static_cast<Uint16>(sb->m_thumb->h());
73 
74 	return Tmp;
75 }
76 
77 void LoadScrollBar();
78 void UnloadScrollBar();
79 
80 } // namespace dvl
81