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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
/* Project nGenEx
Destroyer Studios LLC
Copyright © 1997-2004. All Rights Reserved.
SUBSYSTEM: nGenEx.lib
FILE: ImageBox.cpp
AUTHOR: John DiCamillo
OVERVIEW
========
ImageBox class
*/
#include "MemDebug.h"
#include "ImageBox.h"
#include "Video.h"
#include "Bitmap.h"
#include "Font.h"
#include "DataLoader.h"
// +--------------------------------------------------------------------+
ImageBox::ImageBox(ActiveWindow* p, int ax, int ay, int aw, int ah, DWORD aid)
: ActiveWindow(p->GetScreen(), ax, ay, aw, ah, aid, 0, p), blend_mode(Video::BLEND_ALPHA)
{
picture_loc = 1;
text_align = DT_CENTER;
char buf[32];
sprintf(buf, "ImageBox %d", id);
desc = buf;
}
ImageBox::ImageBox(Screen* s, int ax, int ay, int aw, int ah, DWORD aid)
: ActiveWindow(s, ax, ay, aw, ah, aid, 0, 0), blend_mode(Video::BLEND_ALPHA)
{
picture_loc = 1;
text_align = DT_CENTER;
char buf[32];
sprintf(buf, "ImageBox %d", id);
desc = buf;
}
// +--------------------------------------------------------------------+
ImageBox::~ImageBox()
{ }
// +--------------------------------------------------------------------+
void
ImageBox::Draw()
{
if (!shown)
return;
int x = 0;
int y = 0;
int w = rect.w;
int h = rect.h;
int img_w = picture.Width();
int img_h = picture.Height();
Rect box_rect(x,y,w,h);
// draw the picture (if any)
if (picture.Width()) {
Rect irect = CalcPictureRect();
DrawBitmap(irect.x,
irect.y,
irect.x + irect.w,
irect.y + irect.h,
&picture,
blend_mode);
}
// draw the border:
DrawStyleRect(0, 0, w, h, style);
// draw text here:
if (font && text.length()) {
int border_size = 4;
if (style & WIN_RAISED_FRAME && style & WIN_SUNK_FRAME)
border_size = 8;
Rect label_rect = CalcLabelRect(img_w,img_h);
int vert_space = label_rect.h;
int horz_space = label_rect.w;
DrawText(text.data(), 0, label_rect, DT_CALCRECT | DT_WORDBREAK | DT_CENTER);
vert_space = (vert_space - label_rect.h)/2;
label_rect.w = horz_space;
if (vert_space > 0)
label_rect.y += vert_space;
Color fore = ShadeColor(fore_color, 1);
font->SetColor(fore);
DrawText(text.data(), 0, label_rect, DT_WORDBREAK | DT_CENTER);
}
}
void
ImageBox::DrawTabbedText()
{
if (!shown)
return;
int x = 0;
int y = 0;
int w = rect.w;
int h = rect.h;
int img_w = picture.Width();
int img_h = picture.Height();
Rect box_rect(x,y,w,h);
// draw the picture (if any)
if (picture.Width()) {
Rect irect = CalcPictureRect();
DrawBitmap(irect.x,
irect.y,
irect.x + irect.w,
irect.y + irect.h,
&picture,
Video::BLEND_ALPHA);
}
ActiveWindow::DrawTabbedText();
}
Rect ImageBox::CalcLabelRect(int img_w, int img_h)
{
// fit the text in the bevel:
Rect label_rect;
label_rect.x = 0;
label_rect.y = 0;
label_rect.w = rect.w;
label_rect.h = rect.h;
label_rect.Deflate(2,2);
// and around the picture, if any:
if (img_h != 0) {
switch (picture_loc) {
default:
case 0: // the four corner positions
case 2: // and the center position
case 4: // don't affect the text position
case 6:
case 8:
break;
case 1: // north
label_rect.y += img_h;
label_rect.h -= img_h;
break;
case 3: // west
label_rect.x += img_w;
label_rect.w -= img_w;
break;
case 5: // east
label_rect.w -= img_w;
break;
case 7: // south
label_rect.h -= img_h;
break;
}
}
return label_rect;
}
// +--------------------------------------------------------------------+
Rect
ImageBox::CalcPictureRect()
{
if (target_rect.w > 0 && target_rect.h > 0)
return target_rect;
int w = rect.w;
int h = rect.h;
int img_w = picture.Width();
int img_h = picture.Height();
if (img_h > h) img_h = h-2;
if (img_w > w) img_w = w-2;
int img_x_offset = 0;
int img_y_offset = 0;
switch (picture_loc) {
default:
// TOP ROW:
case 0: break;
case 1: img_x_offset = (w/2-img_w/2);
break;
case 2: img_x_offset = w - img_w;
break;
// MIDDLE ROW:
case 3: img_y_offset = (h/2-img_h/2);
break;
case 4: img_x_offset = (w/2-img_w/2);
img_y_offset = (h/2-img_h/2);
break;
case 5: img_x_offset = w - img_w;
img_y_offset = (h/2-img_h/2);
break;
// BOTTOM ROW:
case 6:
img_y_offset = h - img_h;
break;
case 7: img_x_offset = (w/2-img_w/2);
img_y_offset = h - img_h;
break;
case 8: img_x_offset = w - img_w;
img_y_offset = h - img_h;
break;
}
Rect img_rect;
img_rect.x = img_x_offset;
img_rect.y = img_y_offset;
img_rect.w = img_w;
img_rect.h = img_h;
return img_rect;
}
// +--------------------------------------------------------------------+
int ImageBox::OnMouseMove(int x, int y)
{
return ActiveWindow::OnMouseMove(x,y);
}
int ImageBox::OnLButtonDown(int x, int y)
{
return ActiveWindow::OnLButtonDown(x,y);
}
int ImageBox::OnLButtonUp(int x, int y)
{
return ActiveWindow::OnLButtonUp(x,y);
}
int ImageBox::OnClick()
{
return ActiveWindow::OnClick();
}
int ImageBox::OnMouseEnter(int mx, int my)
{
return ActiveWindow::OnMouseEnter(mx, my);
}
int ImageBox::OnMouseExit(int mx, int my)
{
return ActiveWindow::OnMouseExit(mx, my);
}
// +--------------------------------------------------------------------+
void ImageBox::GetPicture(Bitmap& img) const
{
img.CopyBitmap(picture);
}
void ImageBox::SetPicture(const Bitmap& img)
{
picture.CopyBitmap(img);
picture.AutoMask();
picture.MakeTexture();
}
int ImageBox::GetPictureLocation() const
{
return picture_loc;
}
void ImageBox::SetPictureLocation(int n)
{
if (picture_loc != n && n >= 0 && n <= 8) {
picture_loc = n;
}
}
|