-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm.cpp
executable file
·155 lines (125 loc) · 3.52 KB
/
Form.cpp
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
// Form.cpp: implementation of the CForm class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SuperTX.h"
#include "Display.h"
#include "Form.h"
#include "FormManager.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CForm::CForm(CFormManager* pManager)
: m_pManager(pManager)
, m_rClient(0,0,pManager->Display().Width(), pManager->Display().Height())
{
assert(pManager);
// Allow for title bar in client area:
// Get size of a space in ix & iy for scaling
int iy = 0;
int ix = 0;
Manager()->Display().TextExtent(" ",ix,iy,Font());
m_rClient.top += 2*iy;
}
CForm::~CForm()
{
}
CFormManager* CForm::Manager()
{
assert(this);
return m_pManager;
}
const CRect& CForm::Client() const
{
assert(this);
return m_rClient;
}
void CForm::SetButton(int idx, const std::string& strName)
{
assert(this);
const int iBorder = 4; // allow 4 pixels to allow for border
// around text
// Get size of a space in ix & iy for scaling
int iy = 0;
int ix = 0;
Manager()->Display().TextExtent(" ",ix,iy,Font());
iy = Manager()->Display().Height() / BUTTONS;
// & size of the text string
int cx,cy;
Manager()->Display().TextExtent(strName,cx,cy,Font());
if(idx < BUTTONS/2) // left side
{
ix = iBorder;
iy *= (1 + 2*idx);
int iRight = cx + 2 * iBorder;
if(iRight > m_rClient.left)
m_rClient.left = iRight;
}
else // right side
{
iy *= (1 + 2*(idx-BUTTONS/2));
int iLeft = Manager()->Display().Width() - cx - 2*iBorder;
ix = iLeft + iBorder;
if(iLeft < m_rClient.right)
m_rClient.right = iLeft;
}
iy -= cy/2;
// Draw a button border
Manager()->Display().Rectangle(ix-1, iy-1, ix+cx, iy+cy);
Manager()->Display().Line(ix-2, iy+cy+1, ix+cx+1, iy+cy+1);
Manager()->Display().Line(ix+cx+1, iy+cy+1, ix+cx+1, iy-2);
Manager()->Display().Rectangle(ix-3, iy-3, ix+cx+2, iy+cy+2);
// and internal text
Manager()->Display().TextBack(strName,ix,iy,Font(),false);
}
void CForm::SetButton(int idx, const BitmapT* pbmp)
{
assert(this);
int iy = 0;
int ix = 0;
Manager()->Display().TextExtent(" ",ix,iy,Font());
iy = Manager()->Display().Height() / BUTTONS;
int cx = pbmp->m_iWidth;
int cy = pbmp->m_iHeight;
if(idx < BUTTONS/2) // left side
{
iy *= (1 + 2*idx);
if(ix + cx > m_rClient.left)
m_rClient.left = ix + cx;
}
else // right side
{
iy *= (1 + 2*(idx-BUTTONS/2));
ix = Manager()->Display().Width() - ix - cx;
if(ix < m_rClient.right)
m_rClient.right = ix;
}
iy -= cy/2;
Manager()->Display().Draw(*pbmp, ix, iy);
}
const FontT& CForm::Font() const
{
assert(this);
return font8;
}
void CForm::SetCaption(const std::string& strCaption)
{
assert(this);
// Get size of a space in ix & iy for scaling
int iy = 0;
int ix = 0;
Manager()->Display().TextExtent(" ",ix,iy,Font());
// left justify text, 1/2 char in
Manager()->Display().Text(strCaption, ix/2, iy/2, Font());
Manager()->Display().Line(0,iy*2,Manager()->Display().Width(),0);
}
CRect CForm::GetDisplayArea(int ixPix, int iyPix)
{
assert(this);
return CRect(0,0,0,0);
}