Repository navigation
Expand file tree
/
Copy pathUIProgress.cpp
More file actions
139 lines (117 loc) · 3.37 KB
/
Copy pathUIProgress.cpp
File metadata and controls
139 lines (117 loc) · 3.37 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "stdafx.h"
#include "UIProgress.h"
namespace DuiLib
{
CProgressUI::CProgressUI() : m_bHorizontal(true), m_nMin(0), m_nMax(100), m_nValue(0), m_bStretchForeImage(true)
{
m_uTextStyle = DT_SINGLELINE | DT_CENTER;
SetFixedHeight(12);
}
LPCTSTR CProgressUI::GetClass() const
{
return _T("ProgressUI");
}
LPVOID CProgressUI::GetInterface(LPCTSTR pstrName)
{
if( _tcscmp(pstrName, DUI_CTR_PROGRESS) == 0 ) return static_cast<CProgressUI*>(this);
return CLabelUI::GetInterface(pstrName);
}
bool CProgressUI::IsHorizontal()
{
return m_bHorizontal;
}
void CProgressUI::SetHorizontal(bool bHorizontal)
{
if( m_bHorizontal == bHorizontal ) return;
m_bHorizontal = bHorizontal;
Invalidate();
}
int CProgressUI::GetMinValue() const
{
return m_nMin;
}
void CProgressUI::SetMinValue(int nMin)
{
m_nMin = nMin;
Invalidate();
}
int CProgressUI::GetMaxValue() const
{
return m_nMax;
}
void CProgressUI::SetMaxValue(int nMax)
{
m_nMax = nMax;
Invalidate();
}
int CProgressUI::GetValue() const
{
return m_nValue;
}
void CProgressUI::SetValue(int nValue)
{
if(nValue == m_nValue || nValue<m_nMin || nValue > m_nMax)
{
return;
}
m_nValue = nValue;
Invalidate();
}
LPCTSTR CProgressUI::GetForeImage() const
{
return m_sForeImage;
}
void CProgressUI::SetForeImage(LPCTSTR pStrImage)
{
if( m_sForeImage == pStrImage ) return;
m_sForeImage = pStrImage;
Invalidate();
}
void CProgressUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
if( _tcscmp(pstrName, _T("foreimage")) == 0 ) SetForeImage(pstrValue);
else if( _tcscmp(pstrName, _T("hor")) == 0 ) SetHorizontal(_tcscmp(pstrValue, _T("true")) == 0);
else if( _tcscmp(pstrName, _T("min")) == 0 ) SetMinValue(_ttoi(pstrValue));
else if( _tcscmp(pstrName, _T("max")) == 0 ) SetMaxValue(_ttoi(pstrValue));
else if( _tcscmp(pstrName, _T("value")) == 0 ) SetValue(_ttoi(pstrValue));
else if( _tcscmp(pstrName, _T("isstretchfore"))==0) SetStretchForeImage(_tcscmp(pstrValue, _T("true")) == 0? true : false);
else CLabelUI::SetAttribute(pstrName, pstrValue);
}
void CProgressUI::PaintStatusImage(HDC hDC)
{
if( m_nMax <= m_nMin ) m_nMax = m_nMin + 1;
if( m_nValue > m_nMax ) m_nValue = m_nMax;
if( m_nValue < m_nMin ) m_nValue = m_nMin;
RECT rc = {0};
if( m_bHorizontal ) {
rc.right = (m_nValue - m_nMin) * (m_rcItem.right - m_rcItem.left) / (m_nMax - m_nMin);
rc.bottom = m_rcItem.bottom - m_rcItem.top;
}
else {
rc.top = (m_rcItem.bottom - m_rcItem.top) * (m_nMax - m_nValue) / (m_nMax - m_nMin);
rc.right = m_rcItem.right - m_rcItem.left;
rc.bottom = m_rcItem.bottom - m_rcItem.top;
}
if( !m_sForeImage.IsEmpty() ) {
m_sForeImageModify.Empty();
if (m_bStretchForeImage)
m_sForeImageModify.SmallFormat(_T("dest='%d,%d,%d,%d'"), rc.left, rc.top, rc.right, rc.bottom);
else
m_sForeImageModify.SmallFormat(_T("dest='%d,%d,%d,%d' source='%d,%d,%d,%d'")
, rc.left, rc.top, rc.right, rc.bottom
, rc.left, rc.top, rc.right, rc.bottom);
if( !DrawImage(hDC, (LPCTSTR)m_sForeImage, (LPCTSTR)m_sForeImageModify) ) m_sForeImage.Empty();
else return;
}
}
bool CProgressUI::IsStretchForeImage()
{
return m_bStretchForeImage;
}
void CProgressUI::SetStretchForeImage( bool bStretchForeImage /*= true*/ )
{
if (m_bStretchForeImage==bStretchForeImage) return;
m_bStretchForeImage=bStretchForeImage;
Invalidate();
}
}