-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathlayout_zone.cc
439 lines (365 loc) · 12.5 KB
/
layout_zone.cc
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/*
* Copyright ViewTouch, Inc., 1995, 1996, 1997, 1998
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* layout_zone.cc - revision 67 (8/31/98)
* Implementation of LayoutZone base class
*/
#include "layout_zone.hh"
#include "terminal.hh"
#include "image_data.hh"
#include <string.h>
#ifdef DMALLOC
#include <dmalloc.h>
#endif
/**** LayoutZone Class ****/
// Constructor
LayoutZone::LayoutZone()
{
selected_x = -1;
selected_y = -1;
size_x = 0.0;
min_size_x = 1.0;
max_size_x = 0.0;
size_y = 0.0;
min_size_y = 1.0;
max_size_y = 0.0;
font_width = 0;
font_height = 0;
left_margin = 0;
right_margin = 0;
}
// Member Functions
RenderResult LayoutZone::Render(Terminal *term, int update_flag)
{
FnTrace("LayoutZone::Render()");
RenderZone(term, NULL, update_flag);
term->FontSize(font, font_width, font_height);
int lw = w - (border * 2) - left_margin - right_margin;
int lh = h - (border * 2) - header - footer;
size_x = (Flt) lw / (Flt) font_width;
size_y = (Flt) lh / (Flt) font_height;
max_size_x = (Flt) (w - (border * 2)) / (Flt) font_width;
max_size_y = (Flt) (h - (border * 2)) / (Flt) font_height;
return RENDER_OKAY;
}
SignalResult LayoutZone::Touch(Terminal *t, int tx, int ty)
{
FnTrace("LayoutZone::Touch()");
selected_x = (Flt) (tx - (x + border + left_margin)) / (Flt) font_width;
selected_y = (Flt) (ty - (y + border + header)) / (Flt) font_height;
return SIGNAL_OKAY;
}
int LayoutZone::SetSize(Terminal *t, int width, int height)
{
FnTrace("LayoutZone::SetSize()");
int mw = (int) (min_size_x * (Flt) font_width) +
(border * 2) + left_margin + right_margin;
mw -= mw % t->grid_x;
if (width < mw)
width = mw;
int mh = (int) (min_size_y * (Flt) font_height) +
(border * 2) + header + footer;
mh -= mh % t->grid_y;
if (height < mh)
height = mh;
w = width;
h = height;
return 0;
}
Flt LayoutZone::TextWidth(Terminal *t, const genericChar* str, int len)
{
if (str == NULL)
return 0.0;
if (len <= 0)
len = strlen(str);
return (Flt) t->TextWidth(str, len, font) / (Flt) font_width;
}
int LayoutZone::SetMargins(int left, int right)
{
FnTrace("LayoutZone::SetMargins()");
left_margin = left;
right_margin = right;
int lw = w - (border * 2) - left_margin - right_margin;
int lh = h - (border * 2) - header - footer;
size_x = (Flt) lw / (Flt) font_width;
size_y = (Flt) lh / (Flt) font_height;
return 0;
}
int LayoutZone::TextL(Terminal *t, Flt line, const genericChar* text, int my_color, int mode)
{
FnTrace("LayoutZone::TextL()");
if (line < 0.0 || line >= size_y || text == NULL)
return 1; // Can't draw text
if (my_color == COLOR_DEFAULT)
my_color = t->TextureTextColor(texture[0]);
int pw = w - (border * 2) - left_margin - right_margin;
int px = x + border + left_margin;
int py = y + border + header + (int) (line * (Flt) font_height);
t->RenderText(text, px, py, my_color, font, ALIGN_LEFT, pw, mode);
return 0;
}
int LayoutZone::TextC(Terminal *t, Flt line, const genericChar* text, int my_color, int mode)
{
FnTrace("LayoutZone::TextC()");
if (line < 0.0 || line >= size_y || text == NULL)
return 1; // Can't draw text
if (my_color == COLOR_DEFAULT)
my_color = t->TextureTextColor(texture[0]);
int pw = w - (border * 2) - left_margin - right_margin;
int px = x + border + left_margin + (pw / 2);
int py = y + border + header + (int) (line * (Flt) font_height);
t->RenderText(text, px, py, my_color, font, ALIGN_CENTER, pw, mode);
return 0;
}
int LayoutZone::TextR(Terminal *t, Flt line, const genericChar* text, int my_color, int mode)
{
FnTrace("LayoutZone::TextR()");
if (line < 0.0 || line >= size_y || text == NULL)
return 1; // Can't draw text
if (my_color == COLOR_DEFAULT)
my_color = t->TextureTextColor(texture[0]);
int len = strlen(text), pos = 0;
if (size_x < len)
{
pos = len - (int) size_x;
len = (int) size_x;
}
int px = x + w - border - right_margin;
int py = y + border + header + (int) (line * (Flt) font_height);
t->RenderTextLen(&text[pos], len, px, py, my_color, font, ALIGN_RIGHT, 0, mode);
return 0;
}
int LayoutZone::TextPosL(Terminal *t, Flt row, Flt line, const genericChar* text,
int my_color, int mode)
{
FnTrace("LayoutZone::TextPosL()");
if (line < 0.0 || line >= size_y || text == NULL)
return 1; // Can't draw text
if (my_color == COLOR_DEFAULT)
my_color = t->TextureTextColor(texture[0]);
int offset = (int) (row * (Flt) font_width) + border;
int px = x + left_margin + offset;
int py = y + border + header + (int) (line * (Flt) font_height);
int pw = w - border - offset - left_margin - right_margin;
if (pw <= 0)
return 1;
t->RenderText(text, px, py, my_color, font, ALIGN_LEFT, pw, mode);
return 0;
}
int LayoutZone::TextPosC(Terminal *t, Flt row, Flt line, const genericChar* text,
int my_color, int mode)
{
FnTrace("LayoutZone::TextPosC()");
if (line < 0.0 || line >= size_y || text == NULL)
return 1;
if (my_color == COLOR_DEFAULT)
my_color = t->TextureTextColor(texture[0]);
int px = x + border + left_margin + (int) (row * (Flt) font_width);
int py = y + border + header + (int) (line * (Flt) font_height);
t->RenderText(text, px, py, my_color, font, ALIGN_CENTER, 0, mode);
return 0;
}
int LayoutZone::TextPosR(Terminal *t, Flt row, Flt line, const genericChar* text,
int my_color, int mode)
{
FnTrace("LayoutZone::TextPosR()");
if (line < 0.0 || line >= size_y || text == NULL)
return 1;
if (my_color == COLOR_DEFAULT)
my_color = t->TextureTextColor(texture[0]);
int px = x + border + left_margin + (int) (row * (Flt) font_width);
int py = y + border + header + (int) (line * (Flt) font_height);
t->RenderText(text, px, py, my_color, font, ALIGN_RIGHT, 0, mode);
return 0;
}
int LayoutZone::TextLR(Terminal *t, Flt line,
const genericChar* l_text, int l_color, const genericChar* r_text, int r_color)
{
FnTrace("LayoutZone::TextLR()");
if (line < 0.0 || line >= size_y)
return 1; // Can't draw text
int l_len = 0, l_width = 0, r_len = 0, r_width = 0;
if (l_text)
{
l_len = strlen(l_text);
l_width = t->TextWidth(l_text, l_len, font);
}
if (r_text)
{
r_len = strlen(r_text);
r_width = t->TextWidth(r_text, r_len, font);
}
int lw = w - (border * 2) - left_margin - right_margin;
if (l_text)
{
if (l_color == COLOR_DEFAULT)
l_color = t->TextureTextColor(texture[0]);
int px = x + border + left_margin;
int py = y + border + (int) (line * (Flt) font_height);
t->RenderTextLen(l_text, l_len, px, py, l_color, font, ALIGN_LEFT,
lw - r_width - font_width);
}
if (r_text)
{
if (r_color == COLOR_DEFAULT)
r_color = t->TextureTextColor(texture[0]);
int px = x + w - border - right_margin;
int py = y + border + (int) (line * (Flt) font_height);
t->RenderTextLen(r_text, r_len, px, py, r_color, font, ALIGN_RIGHT, lw);
}
return 0;
}
int LayoutZone::Line(Terminal *t, Flt line, int my_color)
{
FnTrace("LayoutZone::Line()");
if (line < 0.0 || line >= size_y)
return 1; // Can't draw line
int lw = w - (border * 2) + 3 - left_margin - right_margin;
if (lw <= 0)
return 1; // zone not wide enough
if (my_color == COLOR_DEFAULT)
my_color = t->TextureTextColor(texture[0]);
int x1 = x + border - 2 + left_margin;
int y1 = y + border + header + (int) (line * (Flt) font_height) +
(font_height / 2) - 1;
t->RenderHLine(x1, y1, lw, my_color);
return 0;
}
int LayoutZone::LinePos(Terminal *t, Flt row, Flt line, Flt len, int my_color)
{
FnTrace("LayoutZone::LinePos()");
return 1;
}
int LayoutZone::Entry(Terminal *t, Flt px, Flt py, Flt len, RegionInfo *place)
{
FnTrace("LayoutZone::Entry()");
if (px >= size_x || py >= size_y)
return 1;
int xx = (int) (px * (Flt) font_width);
int sx = x + border - 2 + left_margin + xx;
int sy = y + border - 2 + header + (int) (py * (Flt) font_height);
int w1 = (int) (len * (Flt) font_width) + 6;
int w2 = w - xx - (border * 2) - left_margin - right_margin;
int sw = Min(w1, w2);
int sh = font_height + 5;
if (sw <= 0)
return 1;
int tex = texture[0], ft;
if (tex == IMAGE_DEFAULT)
tex = t->page->default_texture[0];
if (tex == IMAGE_CLEAR)
tex = t->page->image;
switch(tex)
{
case IMAGE_LITE_WOOD:
case IMAGE_WOOD:
case IMAGE_GRAY_PARCHMENT:
ft = IMAGE_DARK_WOOD; break;
case IMAGE_DARK_SAND:
ft = IMAGE_SAND; break;
case IMAGE_DARK_WOOD:
ft = IMAGE_WOOD; break;
default:
ft = IMAGE_DARK_SAND; break;
}
t->RenderFilledFrame(sx, sy, sw, sh, 2, ft, FRAME_INSET | FRAME_2COLOR);
if (place != NULL)
{
place->x = sx;
place->y = sy;
place->w = sw;
place->h = sh;
}
return 0;
}
int LayoutZone::Button(Terminal *t, Flt px, Flt py, Flt len, int lit)
{
FnTrace("LayoutZone::Button()");
if (px >= size_x || py >= size_y)
return 1;
int xx = (int) (px * (Flt) font_width);
int sx = x + border - 3 + left_margin + xx;
int sy = y + border - 4 + header + (int) (py * (Flt) font_height);
int w1 = (int) (len * (Flt) font_width) + 8;
int w2 = w - xx - (border * 2) - left_margin - right_margin;
int sw = Min(w1, w2);
int sh = font_height + 8;
if (sw <= 0)
return 1;
if (lit)
t->RenderFilledFrame(sx, sy, sw, sh, 2, IMAGE_LIT_SAND, FRAME_LIT);
else
t->RenderFilledFrame(sx, sy, sw, sh, 2, IMAGE_SAND);
return 0;
}
int LayoutZone::Background(Terminal *t, Flt line, Flt height, int my_texture)
{
FnTrace("LayoutZone::Background()");
if (line >= size_y)
return 1;
int sx = x + border - 3 + left_margin;
int sy = y + border - 1 + header + (int) ((line * (Flt) font_height) + .5);
int sw = w - (border * 2) + 6 - left_margin - right_margin;
int sh = (int) ((height * (Flt) font_height) + .5);
if (sx < x)
sx = x;
if (sw > w)
sw = w;
t->RenderRectangle(sx, sy, sw, sh, my_texture);
return 0;
}
int LayoutZone::Raised(Terminal *t, Flt line, Flt height)
{
FnTrace("LayoutZone::Raised()");
if (line >= size_y)
return 1;
int sx = x + border - 3 + left_margin;
int sy = y + border - 1 + header + (int) ((line * (Flt) font_height) + .5);
int sw = w - (border * 2) + 6 - left_margin - right_margin;
int sh = (int) ((height * (Flt) font_height) + .5);
if (sx < x)
sx = x;
if (sw > w)
sw = w;
t->RenderButton(sx, sy, sw, sh, ZF_RAISED, IMAGE_SAND);
return 0;
}
int LayoutZone::Underline(Terminal *t, Flt px, Flt py, Flt len, int my_color)
{
FnTrace("LayoutZone::Underline()");
int xx = x + border + left_margin + (int) (px * (Flt) font_width);
int yy = y + border + header + (int) ((py + .95) * (Flt) font_height);
int ll = (int) (len * (Flt) font_width);
if (my_color == COLOR_DEFAULT)
my_color = t->TextureTextColor(texture[0]);
t->RenderHLine(xx, yy, ll, my_color);
return 0;
}
int LayoutZone::ColumnSpacing(Terminal *term, int num_columns)
{
FnTrace("LayoutZone::ColumnSpacing()");
if (num_columns > 0)
{
term->FontSize(font, font_width, font_height);
num_spaces = w / font_width / num_columns;
}
return num_spaces;
}
int LayoutZone::Width(Terminal *term)
{
FnTrace("LayoutZone::Width()");
term->FontSize(font, font_width, font_height);
return w/font_width;
}