-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathTabView.cpp
More file actions
110 lines (90 loc) · 2.69 KB
/
Copy pathTabView.cpp
File metadata and controls
110 lines (90 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
TabView.cpp -- tabbed view
Copyright (C) 2017 a1batross
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "TabView.h"
#include "Scissor.h"
CMenuTabView::CMenuTabView() : BaseClass()
{
m_bWrapCursor = true;
SetCharSize( QM_BOLDFONT );
eTextAlignment = QM_CENTER;
}
Point CMenuTabView::GetPositionOffset() const
{
Point ret = m_scPos;
ret.y += m_scChSize * 1.5f;
return ret;
}
void CMenuTabView::VidInit()
{
CalcPosition();
CalcSizes();
_VidInit();
VidInitItems();
m_szTab.w = m_scSize.w / m_pItems.Count();
m_szTab.h = m_scChSize * 1.5f;
}
void CMenuTabView::DrawTab(Point pt, const char *name, bool isEnd, bool isSelected, bool isHighlighted)
{
uint textColor = uiInputTextColor;
uint fillColor = uiColorBlack;
uint textflags = ( iFlags & QMF_DROPSHADOW ) ? ETF_SHADOW : 0;
if( isSelected && !isHighlighted )
{
fillColor = uiInputBgColor;
textColor = uiInputFgColor;
}
else if( isHighlighted )
{
textColor = uiPromptFocusColor;
}
UI_FillRect( pt, m_szTab, fillColor );
UI_DrawString( font, pt, m_szTab, name, textColor, m_scChSize, eTextAlignment, textflags );
if( !isEnd )
{
int x = pt.x + m_szTab.w;
int y = pt.y - UI_OUTLINE_WIDTH;
int w = UI_OUTLINE_WIDTH;
int h = m_szTab.h + UI_OUTLINE_WIDTH + UI_OUTLINE_WIDTH;
// draw right
UI_FillRect( x, y, w, h, uiColorHelp );
}
}
void CMenuTabView::Draw()
{
// draw frame first
UI_DrawRectangle( m_scPos, m_scSize, uiColorHelp );
// draw tabs
Point tabOffset = m_scPos;
FOR_EACH_VEC( m_pItems, i )
{
bool isEnd = i == ( m_pItems.Count() - 1 );
bool isHighlighted = UI_CursorInRect( tabOffset, m_szTab );
bool isSelected = i == m_iCursor;
DrawTab( tabOffset, m_pItems[i]->szName, isEnd, isSelected, isHighlighted );
tabOffset.x += m_szTab.w;
}
Point contentOffset = Point( m_scPos.x, m_scPos.y + m_scChSize * 1.5f );
Size contentSize = Size( m_scSize.w, m_scSize.h - m_scChSize * 1.5f );
// draw line after tab
UI_FillRect( contentOffset.x, contentOffset.y,
m_scSize.w, UI_OUTLINE_WIDTH, uiColorHelp );
// fill background
UI_FillRect( contentOffset, contentSize, uiColorBlack );
// draw contents
if( m_iCursor >= 0 && m_iCursor < m_pItems.Count() )
{
UI::Scissor::PushScissor( contentOffset, contentSize );
m_pItems[m_iCursor]->Draw();
UI::Scissor::PopScissor();
}
}