-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathProgress.h
executable file
·217 lines (176 loc) · 7.12 KB
/
Progress.h
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#if !defined(AFX_PROGRESS_H__F26E8924_D1C1_11D3_B261_00104BB13A66__INCLUDED_)
#define AFX_PROGRESS_H__F26E8924_D1C1_11D3_B261_00104BB13A66__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
///////////////////////////////////////////////////////////////////////////////
// class CProgress
//
// Author: Yury Goltsman
// email: ygprg@go.to
// page: http://go.to/ygprg
// Copyright © 2000, Yury Goltsman
//
// This code provided "AS IS," without warranty of any kind.
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
// version : 1.4
// Gradient Animation added
//
// version : 1.3
// Separated to window independent classes CProgress and CGradient (base)
// Added palette support for 256 colors mode (to CGradient)
// Added shaped style drawing
//
//
// Old history of CProgressCtrlX:
//
// version : 1.2
// Added support for "Any angle text rotation"
// (define PBT_ANY_ANGLE and set font with appropriated angle)
// Added text alignment
// Added possibility to format text (via virtual function FormatText())
// e.g. you can show percent as decimal fraction instead of integer
//
// version : 1.1
// Added multi-color gradient
// Added filling with brush for background and bar(overrides color settings)
// Added borders attribute
// Added vertical text support
// Added snake mode
// Added reverse mode
// Added dual color for text
// Added text formatting
// Added tied mode for text and rubber bar mode
// Added support for vertical oriented control(PBS_VERTICAL)
//
// version : 1.0
//
#ifndef UIBITS_API
#ifdef UIBITS_DLL
#define UIBITS_API __declspec(dllexport)
#else
#define UIBITS_API __declspec(dllimport)
#endif
#endif
#include "Gradient.h"
// To set text alignment styles use ModifyBarStyle()
#define PBS_LEFT 0x0010L
#define PBS_RIGHT 0x0020L
#define PBS_CENTER 0x0030L
#define PBS_TOP 0x0040L
#define PBS_BOTTOM 0x0080L
#define PBS_VCENTER 0x00C0L
// To set text format use "SetTextFormat" and "HideText"
#define PBS_SHOW_PERCENT 0x0100L
#define PBS_SHOW_POSITION 0x0200L
#define PBS_SHOW_TEXTONLY 0x0300L
#define PBS_TEXTMASK 0x0300L
// To set this attributes use ModifyBarStyle() or appropriated functions
#define PBS_TIED_TEXT 0x1000L
#define PBS_RUBBER_BAR 0x2000L
#define PBS_REVERSE 0x4000L
#define PBS_SNAKE 0x8000L
/////////////////////////////////////////////////////////////////////////////
// class CProgress
class /*UIBITS_API*/ CProgress : public CGradient
{
// Construction
public:
CProgress();
// Attributes
public:
void SetBarBrush(CBrush* pbrBar) { m_pbrBar = pbrBar; }
CBrush* GetBarBrush() { return m_pbrBar; }
void SetBkColor(COLORREF clrBk) { m_clrBk = clrBk; }
COLORREF GetBkColor() { return m_clrBk; }
void SetBkBrush(CBrush* pbrBk) { m_pbrBk = pbrBk; }
CBrush* GetBkBrush() { return m_pbrBk; }
void SetTextColor(COLORREF clrTextOnBar, COLORREF clrTextOnBk = -1) { m_clrTextOnBar = m_clrTextOnBk = clrTextOnBar; if(clrTextOnBk != -1) m_clrTextOnBk = clrTextOnBk;}
COLORREF GetTextColor() { return m_clrTextOnBar; }
COLORREF GetTextColorOnBk() { return m_clrTextOnBk; }
void SetShowPercent(BOOL fShowPercent = TRUE) { SetTextFormat(fShowPercent ? "%d%%" : NULL, PBS_SHOW_PERCENT); }
BOOL GetShowPercent() { return GetBarStyle()&PBS_SHOW_PERCENT; }
void SetTextAlign(DWORD dwStyle) {ModifyBarStyle(PBS_CENTER|PBS_VCENTER, dwStyle&(PBS_CENTER|PBS_VCENTER));}
DWORD GetTextAlign() {return GetBarStyle()&(PBS_CENTER|PBS_VCENTER); }
void SetTextFormat(LPCTSTR szFormat, DWORD ffFormat = PBS_SHOW_TEXTONLY);
void HideText() {SetTextFormat(0);}
void SetText(LPCTSTR lpszText) {m_sText = lpszText;}
CString GetText() {return m_sText;}
void SetTiedText(BOOL fTiedText = TRUE) { ModifyBarStyle(fTiedText ? 0 : PBS_TIED_TEXT, fTiedText ? PBS_TIED_TEXT : 0); }
BOOL GetTiedText() { return GetBarStyle()&PBS_TIED_TEXT; }
void SetRubberBar(BOOL fRubberBar = TRUE) { ModifyBarStyle(fRubberBar ? 0 : PBS_RUBBER_BAR, fRubberBar ? PBS_RUBBER_BAR : 0); }
BOOL GetRubberBar() { return GetBarStyle()&PBS_RUBBER_BAR; }
void SetReverse(BOOL fReverse = TRUE) { ModifyBarStyle(fReverse ? 0 : PBS_REVERSE, fReverse ? PBS_REVERSE : 0); }
BOOL GetReverse() { return GetBarStyle()&PBS_REVERSE; }
void SetSnake(BOOL fSnake = TRUE) { ModifyBarStyle(fSnake ? 0 : PBS_SNAKE|PBS_RUBBER_BAR, fSnake ? PBS_SNAKE|PBS_RUBBER_BAR : 0); }
BOOL GetSnake() { return GetBarStyle()&PBS_SNAKE; }
void SetSnakeTail(int nTailSize) { m_nTailSize = nTailSize; }
int GetSnakeTail() { return m_nTailSize; }
void SetBorders(const CRect& rcBorders) { m_rcBorders = rcBorders; }
const CRect& GetBorders() { return m_rcBorders; }
BOOL SetShape(HRGN hRgn);
void SetRange(int nLower, int nUpper);
void GetRange(int& nLower, int& nUpper) {nLower = m_nLower; nUpper = m_nUpper;}
int GetPos() {return m_nPos;}
int SetPos(int nPos);
int OffsetPos(int nIncrement);
int SetStep(int nStep);
void SetFont(CFont* pFont) {m_pFont = pFont;}
CFont* GetFont() {return m_pFont;}
virtual DWORD GetBarStyle() {return m_dwStyle;}
virtual void ModifyBarStyle(DWORD dwRemove, DWORD dwAdd) {m_dwStyle &= ~dwRemove; m_dwStyle |= dwAdd;}
void Animate(int nStep) {m_nAnimPos += nStep; m_nAnimPos %= int((m_nUpper - m_nLower)*GetStretchGradient());}
void ResetAnimation() {m_nAnimPos = 0;}
// Operations
public:
int StepIt();
void Draw(CDC* pDC, CRect rcDraw, BOOL fSkipDCCache = FALSE);
// Implementation
public:
virtual ~CProgress(){}
protected:
struct CDrawInfo
{
CDC *pDC;
DWORD dwStyle;
CRect rcClient;
int nCurPos;
int nLower;
int nUpper;
};
virtual void DrawText(const CDrawInfo& info, const CRect &rcMax, const CRect &rcGrad);
virtual void DrawClippedText(const CDrawInfo& info, const CRect& rcClip, CString& sText, const CPoint& ptWndOrg);
CRect ConvertToReal(const CDrawInfo& info, const CRect& rcVirt);
virtual BOOL SetSnakePos(int nNewPos, BOOL fIncrement = FALSE);
virtual CString FormatText(const CDrawInfo& info, CString sFormat, float nValue);
virtual float CalcPos(const CDrawInfo& info);
void UpdatePos(int nNewPos, BOOL fForse = FALSE);
virtual BOOL OnPosChanging(int nOldPos, int nNewPos) {return TRUE;}
virtual void OnPosChanged(int nNewPos) {}
// color atributes
CBrush* m_pbrBar;
COLORREF m_clrBk;
CBrush* m_pbrBk;
COLORREF m_clrTextOnBar;
COLORREF m_clrTextOnBk;
// snake/progress attributes
int m_nTail;
int m_nTailSize;
int m_nStep;
int m_nLower;
int m_nUpper;
CRect m_rcBorders;
CString m_sText;
CFont* m_pFont;
DWORD m_dwStyle;
CRgn m_rgnShape;
private:
int m_nPos;
int m_nAnimPos;
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_PROGRESS_H__F26E8924_D1C1_11D3_B261_00104BB13A66__INCLUDED_)