-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbklayer.cpp
576 lines (512 loc) · 18.2 KB
/
bklayer.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
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
/*
* Bookr: document reader for the Sony PSP
* Copyright (C) 2005 Carlos Carrasco Martinez (carloscm at gmail dot com),
* 2007 Christian Payeur (christian dot payeur at gmail dot com)
*
* 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
* (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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "fzinstreammem.h"
#include "fzscreen.h"
#include "bklayer.h"
#include <cmath>
FZFont* BKLayer::fontBig = 0;
FZFont* BKLayer::fontSmall = 0;
FZTexture* BKLayer::texUI = 0;
FZTexture* BKLayer::texUI2 = 0;
FZTexture* BKLayer::texLogo = 0;
extern "C" {
extern unsigned int size_res_logo;
extern unsigned char res_logo[];
extern unsigned int size_res_uitex;
extern unsigned char res_uitex[];
extern unsigned int size_res_uitex2;
extern unsigned char res_uitex2[];
extern unsigned int size_res_uifont;
extern unsigned char res_uifont[];
};
void BKLayer::load() {
fontBig = FZFont::createFromMemory(res_uifont, size_res_uifont, 14, false);
fontBig->texEnv(FZ_TEX_MODULATE);
fontBig->filter(FZ_NEAREST, FZ_NEAREST);
fontSmall = FZFont::createFromMemory(res_uifont, size_res_uifont, 11, false);
fontSmall->texEnv(FZ_TEX_MODULATE);
fontSmall->filter(FZ_NEAREST, FZ_NEAREST);
FZInputStreamMem* ins = FZInputStreamMem::create((char*)res_uitex, size_res_uitex);
FZImage* image = FZImage::createFromPNG(ins);
ins->release();
ins = 0;
texUI = FZTexture::createFromImage(image, false);
texUI->texEnv(FZ_TEX_MODULATE);
texUI->filter(FZ_NEAREST, FZ_NEAREST);
image->release();
ins = FZInputStreamMem::create((char*)res_uitex2, size_res_uitex2);
image = FZImage::createFromPNG(ins);
ins->release();
ins = 0;
texUI2 = FZTexture::createFromImage(image, false);
texUI2->texEnv(FZ_TEX_MODULATE);
texUI2->filter(FZ_NEAREST, FZ_NEAREST);
image->release();
ins = FZInputStreamMem::create((char*)res_logo, size_res_logo);
image = FZImage::createFromPNG(ins);
ins->release();
ins = 0;
texLogo = FZTexture::createFromImage(image, false);
texLogo->texEnv(FZ_TEX_REPLACE);
texLogo->filter(FZ_NEAREST, FZ_NEAREST);
image->release();
}
struct T32FV32F2D {
float u,v;
float x,y,z;
};
void BKLayer::drawImage(int x, int y, int w, int h, int tx, int ty) {
struct T32FV32F2D vertices[2] = {
{ tx, ty, x, y, 0 },
{ tx + w, ty + h, x + w, y + h, 0 }
};
T32FV32F2D* verts = (T32FV32F2D*)FZScreen::getListMemory(2*sizeof(struct T32FV32F2D));
memcpy(verts, vertices, 2 * sizeof(struct T32FV32F2D));
FZScreen::drawArray(FZ_SPRITES,FZ_TEXTURE_32BITF|FZ_VERTEX_32BITF|FZ_TRANSFORM_2D,2,0,verts);
}
void BKLayer::drawImageScale(int x, int y, int w, int h, int tx, int ty, int tw, int th) {
struct T32FV32F2D vertices[2] = {
{ tx, ty, x, y, 0 },
{ tx + tw, ty + th, x + w, y + h, 0 }
};
T32FV32F2D* verts = (T32FV32F2D*)FZScreen::getListMemory(2*sizeof(struct T32FV32F2D));
memcpy(verts, vertices, 2 * sizeof(struct T32FV32F2D));
FZScreen::drawArray(FZ_SPRITES,FZ_TEXTURE_32BITF|FZ_VERTEX_32BITF|FZ_TRANSFORM_2D,2,0,verts);
}
void BKLayer::drawPill(int x, int y, int w, int h, int r, int tx, int ty) {
struct T32FV32F2D vertices[7*2] = {
{ tx, ty, x, y, 0 },
{ tx + r, ty + r, x + r, y + r, 0 },
{ tx + r, ty, x + w, y, 0 },
{ tx, ty + r, x + w + r, y + r, 0 },
{ tx, ty + r, x, y + h, 0 },
{ tx + r, ty, x + r, y + h + r, 0 },
{ tx + r, ty + r, x + w, y + h, 0 },
{ tx, ty, x + w + r, y + h + r, 0 },
{ tx + r, ty + r, x + r, y, 0 },
{ tx + r, ty + r, x + w, y + h + r, 0 },
{ tx + r, ty + r, x, y + r, 0 },
{ tx + r, ty + r, x + r, y + h, 0 },
{ tx + r, ty + r, x + w, y + r, 0 },
{ tx + r, ty + r, x + r + w, y + h, 0 }
};
T32FV32F2D* verts = (T32FV32F2D*)FZScreen::getListMemory(2 * 7 * sizeof(struct T32FV32F2D));
memcpy(verts, vertices, 2 * 7 * sizeof(struct T32FV32F2D));
FZScreen::drawArray(FZ_SPRITES,FZ_TEXTURE_32BITF|FZ_VERTEX_32BITF|FZ_TRANSFORM_2D,14,0,verts);
}
void BKLayer::drawTPill(int x, int y, int w, int h, int r, int tx, int ty) {
struct T32FV32F2D vertices[5*2] = {
{ tx, ty, x, y, 0 },
{ tx + r, ty + r, x + r, y + r, 0 },
{ tx + r, ty, x + w, y, 0 },
{ tx, ty + r, x + w + r, y + r, 0 },
/*{ tx, ty + r, x, y + h, 0 },
{ tx + r, ty, x + r, y + h + r, 0 },
{ tx + r, ty + r, x + w, y + h, 0 },
{ tx, ty, x + w + r, y + h + r, 0 },*/
{ tx + r, ty + r, x + r, y, 0 },
{ tx + r, ty + r, x + w, y + h + r, 0 },
{ tx + r, ty + r, x, y + r, 0 },
{ tx + r, ty + r, x + r, y + h, 0 },
{ tx + r, ty + r, x + w, y + r, 0 },
{ tx + r, ty + r, x + r + w, y + h, 0 }
};
T32FV32F2D* verts = (T32FV32F2D*)FZScreen::getListMemory(2 * 5 * sizeof(struct T32FV32F2D));
memcpy(verts, vertices, 2 * 5 * sizeof(struct T32FV32F2D));
FZScreen::drawArray(FZ_SPRITES,FZ_TEXTURE_32BITF|FZ_VERTEX_32BITF|FZ_TRANSFORM_2D,10,0,verts);
}
void BKLayer::drawRect(int x, int y, int w, int h, int r, int tx, int ty) {
struct T32FV32F2D vertices[1*2] = {
{ tx + r, ty + r, x, y, 0 },
{ tx + r, ty + r, x + w, y + h, 0 }
};
T32FV32F2D* verts = (T32FV32F2D*)FZScreen::getListMemory(2 * 1 * sizeof(struct T32FV32F2D));
memcpy(verts, vertices, 2 * 1 * sizeof(struct T32FV32F2D));
FZScreen::drawArray(FZ_SPRITES,FZ_TEXTURE_32BITF|FZ_VERTEX_32BITF|FZ_TRANSFORM_2D,2,0,verts);
}
int BKLayer::textWidthRange(char* t, int n, FZFont* font) {
int baseX = 0;
for (unsigned char *p = (unsigned char*)t; *p != 0; p++) {
int idx = *p;
// printable & white space
if (idx >= 32)
baseX += font->getMetrics(idx)->xadvance;
}
return baseX;
}
int BKLayer::textW(char* t, FZFont* font) {
// precalc vertex count
int vc = 0;
for (unsigned char *p = (unsigned char*)t; *p != 0; p++) {
if (*p <= 32)
continue;
vc += 2;
}
// lame
if (vc == 0)
return 0;
int baseX = 0;
for (unsigned char *p = (unsigned char*)t; *p != 0; p++) {
int idx = *p;
// new line
if (idx == 10) {
return baseX;
}
// white space
if (idx == 32) {
baseX += font->getMetrics(idx)->xadvance;
continue;
}
// printable
if (idx > 32) {
baseX += font->getMetrics(idx)->xadvance;
continue;
}
}
return baseX;
}
void BKLayer::drawTextHC(char* t, FZFont* font, int y) {
int w = textW(t, font);
drawText(t, font, (480 - w) / 2, y);
}
int BKLayer::drawText(char* t, FZFont* font, int x, int y, int n, bool useLF, bool usePS, float ps, bool use3D) {
if (n < 0) {
n = strlen(t);
}
// precalc vertex count
int vc = 0;
int i = 0;
for (unsigned char *p = (unsigned char*)t; i < n; i++, p++) {
if (*p <= 32)
continue;
vc += 2;
}
// lame
if (vc == 0)
return 0;
// build varray
T32FV32F2D* vertices = (T32FV32F2D*)FZScreen::getListMemory(vc * sizeof(struct T32FV32F2D));
// fill varray
int iv = 0;
int baseX = x;
int baseY = y;
i = 0;
float fx = 0.0f;
for (unsigned char *p = (unsigned char*)t; i < n; i++, p++) {
int idx = *p;
// new line
if (idx == 10 && useLF) {
baseY += font->getLineHeight()*(BKUser::options.txtHeightPct/100.0);
baseX = x;
fx = 0.0f;
}
// white space
if (idx == 32) {
if (usePS)
fx += ps;
else
baseX += font->getMetrics(idx)->xadvance;
continue;
}
// printable
if (idx > 32) {
int topleft = iv;
int botright = topleft + 1;
int cx = usePS ? x + int(floor(fx)) : baseX;
FZCharMetrics *fontChar = font->getMetrics(idx);
vertices[topleft].u = fontChar->x;
vertices[topleft].v = fontChar->y;
vertices[topleft].x = cx + fontChar->xoffset;
vertices[topleft].y = baseY + fontChar->yoffset;
vertices[topleft].z = 0;
vertices[botright].u = fontChar->x + fontChar->width;
vertices[botright].v = fontChar->y + fontChar->height;
vertices[botright].x = cx + fontChar->xoffset + fontChar->width;
vertices[botright].y = baseY + fontChar->yoffset + fontChar->height;
vertices[botright].z = 0;
baseX += fontChar->xadvance;
if (usePS)
fx += float(fontChar->xadvance);
iv+=2;
continue;
}
}
if (use3D) {
// no quads on psp so we need triangles
T32FV32F2D* vertices3d = (T32FV32F2D*)FZScreen::getListMemory(vc * sizeof(struct T32FV32F2D) * 3);
int i3d = 0;
for (iv = 0; iv < vc; iv+=2, i3d+=6) {
int topleft = iv;
int botright = topleft + 1;
// tri 1
vertices3d[i3d] = vertices[topleft];
vertices3d[i3d+1].u = vertices[botright].u;
vertices3d[i3d+1].v = vertices[topleft].v;
vertices3d[i3d+1].x = vertices[botright].x;
vertices3d[i3d+1].y = vertices[topleft].y;
vertices3d[i3d+1].z = 0;
vertices3d[i3d+2].u = vertices[topleft].u;
vertices3d[i3d+2].v = vertices[botright].v;
vertices3d[i3d+2].x = vertices[topleft].x;
vertices3d[i3d+2].y = vertices[botright].y;
vertices3d[i3d+2].z = 0;
// tri 2
vertices3d[i3d+3] = vertices3d[i3d+1];
vertices3d[i3d+4] = vertices[botright];
vertices3d[i3d+5] = vertices3d[i3d+2];
}
FZScreen::drawArray(FZ_TRIANGLES,FZ_TEXTURE_32BITF|FZ_VERTEX_32BITF|FZ_TRANSFORM_3D,vc * 3,0,vertices3d);
} else {
FZScreen::drawArray(FZ_SPRITES,FZ_TEXTURE_32BITF|FZ_VERTEX_32BITF|FZ_TRANSFORM_2D,vc,0,vertices);
}
return baseX;
}
void BKLayer::drawDialogFrame(string& title, string& triangleLabel, string& circleLabel, int flags) {
int scrY = 0;
char *t =(char*)circleLabel.c_str();
int tw = textW(t, fontBig);
texUI->bindForDisplay();
FZScreen::ambientColor(0xf0222222);
// back
drawTPill(20, 20 + scrY, 480 - 46, 272, 6, 31, 1);
// title
FZScreen::ambientColor(0xffaaaaaa);
drawPill(25, 25 + scrY, 480 - 46 - 10, 20, 6, 31, 1);
// context label
FZScreen::ambientColor(0xff555555);
drawTPill(25, 272 - 30 + scrY, 480 - 46 - 11, 30, 6, 31, 1);
// icons
FZScreen::ambientColor(0xff000000);
//drawImage(430, 30 + scrY, BK_IMG_TRIANGLE_XSIZE, BK_IMG_TRIANGLE_YSIZE, BK_IMG_TRIANGLE_X, BK_IMG_TRIANGLE_Y); tri!
// drawImage(430, 29 + scrY, BK_IMG_CIRCLE_XSIZE, BK_IMG_CIRCLE_YSIZE, BK_IMG_CIRCLE_X, BK_IMG_CIRCLE_Y); // close handle
switch (BKUser::controls.select) {
case FZ_REPS_CROSS:
drawImage(430, 29 + scrY, BK_IMG_CIRCLE_XSIZE, BK_IMG_CIRCLE_YSIZE, BK_IMG_CIRCLE_X, BK_IMG_CIRCLE_Y);
break;
case FZ_REPS_CIRCLE:
default:
drawImage(430, 29 + scrY, BK_IMG_CROSS_XSIZE, BK_IMG_CROSS_YSIZE, BK_IMG_CROSS_X, BK_IMG_CROSS_Y);
break;
}
FZScreen::ambientColor(0xffcccccc);
// circle or other context icon
if (flags & BK_MENU_ITEM_USE_LR_ICON) {
drawImage(480 - tw - 65, 248 + scrY, BK_IMG_LRARROWS_XSIZE, BK_IMG_LRARROWS_YSIZE, BK_IMG_LRARROWS_X, BK_IMG_LRARROWS_Y);
} else {
switch(BKUser::controls.select) {
case FZ_REPS_CROSS:
drawImage(480 - tw - 65, 248 + scrY, BK_IMG_CROSS_XSIZE, BK_IMG_CROSS_YSIZE, BK_IMG_CROSS_X, BK_IMG_CROSS_Y);
break;
case FZ_REPS_CIRCLE:
default:
drawImage(480 - tw - 65, 248 + scrY, BK_IMG_CIRCLE_XSIZE, BK_IMG_CIRCLE_YSIZE, BK_IMG_CIRCLE_X, BK_IMG_CIRCLE_Y);
break;
}
// drawImage(480 - tw - 65, 248 + scrY, BK_IMG_CROSS_XSIZE, BK_IMG_CROSS_YSIZE, BK_IMG_CROSS_X, BK_IMG_CROSS_Y);
}
if (triangleLabel.size() > 0 || flags & BK_MENU_ITEM_OPTIONAL_TRIANGLE_LABEL) {
//drawImage(37, 248 + scrY, 20, 20, 107, 5);
// drawImage(37, 248 + scrY, BK_IMG_TRIANGLE_XSIZE, BK_IMG_TRIANGLE_YSIZE, BK_IMG_TRIANGLE_X, BK_IMG_TRIANGLE_Y);
drawImage(37, 248 + scrY, BK_IMG_TRIANGLE_XSIZE, BK_IMG_TRIANGLE_YSIZE, BK_IMG_TRIANGLE_X, BK_IMG_TRIANGLE_Y);
}
fontBig->bindForDisplay();
// title
FZScreen::ambientColor(0xffffffff);
drawText((char*)title.c_str(), fontBig, 31, 28 + scrY);
// labels
FZScreen::ambientColor(0xffcccccc);
if (triangleLabel.size() > 0) {
drawText((char*)triangleLabel.c_str(), fontBig, 37 + 25, 248 + scrY);
}
drawText(t, fontBig, 480 - tw - 40, 248 + scrY);
}
void BKLayer::drawMenu(string& title, string& triangleLabel, vector<BKMenuItem>& items) {
int selPos = selItem - topItem;
int scrY = 0;
if (selPos < 0) {
topItem += selPos;
selPos = 0;
}
if (selPos > 7) {
topItem += selPos - 7;
selPos = 7;
}
bool scrollbar = items.size() > 8;
string tl(triangleLabel);
if (items[selItem].flags & BK_MENU_ITEM_OPTIONAL_TRIANGLE_LABEL) {
tl = items[selItem].triangleLabel;
}
drawDialogFrame(title, tl, items[selItem].circleLabel, items[selItem].flags);
texUI->bindForDisplay();
// folder icons
FZScreen::ambientColor(0xffffffff);
for (int i = 0; i < 8; ++i) {
if (i + topItem == selItem)
continue;
if ((60 + (i+1)*fontBig->getLineHeight()) > 250)
break;
if ((i + topItem) >= (int)(items.size()))
break;
if (items[i + topItem].flags & BK_MENU_ITEM_FOLDER) {
//drawImage(40, 60 + i*fontBig->getLineHeight() + scrY, 20, 20, 84, 52);
drawImage(40, 60 + i*fontBig->getLineHeight() + scrY, 20, 20, 58, 81);
}
}
// selected item
int wSelBox = scrollbar ? 480 - 46 - 10 - 24: 480 - 46 - 10;
drawPill(25, 57 + scrY + selPos*fontBig->getLineHeight(), wSelBox, 19, 6, 31, 1);
if (items[selItem].flags & BK_MENU_ITEM_FOLDER) {
FZScreen::ambientColor(0xff000000);
//drawImage(40, 60 + scrY + selPos*fontBig->getLineHeight(), 20, 20, 84, 52);
drawImage(40, 60 + scrY + selPos*fontBig->getLineHeight(), BK_IMG_FOLDER_XSIZE, BK_IMG_FOLDER_YSIZE, BK_IMG_FOLDER_X, BK_IMG_FOLDER_Y);
}
// scrollbar
if (scrollbar) {
float barh = 8.0f / float(items.size());
barh *= 173.0f;
if (barh < 15.0f)
barh = 15.0f;
float trel = float(topItem) / float(items.size());
trel *= 173.0f;
FZScreen::ambientColor(0xff555555);
drawPill(436, 57, 12, 173, 6, 31, 1);
FZScreen::ambientColor(0xffaaaaaa);
drawPill(436, 57 + int(trel), 12, int(barh), 6, 31, 1);
}
// color rects items
for (int i = 0; i < 8; ++i) {
if ((60 + (i+1)*fontBig->getLineHeight()) > 250)
break;
if ((i + topItem) >= (int)(items.size()))
break;
if (items[i + topItem].flags & BK_MENU_ITEM_COLOR_RECT) {
int tw = textW((char*)items[i + topItem].label.c_str(), fontBig);
FZScreen::ambientColor(items[i + topItem].bgcolor | 0xff000000);
drawRect(40 + 25 + tw + 10, 60 + i*fontBig->getLineHeight() + scrY, 30, 15, 6, 31, 1);
FZScreen::ambientColor(items[i + topItem].fgcolor | 0xff000000);
drawRect(40 + 25 + tw + 15, 60 + i*fontBig->getLineHeight() + scrY + 4, 30, 15, 6, 31, 1);
}
}
fontBig->bindForDisplay();
FZScreen::ambientColor(0xffffffff);
// contents
for (int i = 0; i < 8; ++i) {
if (i + topItem == selItem)
continue;
if ((60 + (i+1)*fontBig->getLineHeight()) > 250)
break;
if ((i + topItem) >= (int)(items.size()))
break;
drawText((char*)items[i + topItem].label.c_str(), fontBig, 40 + 25, 60 + i*fontBig->getLineHeight() + scrY);
}
FZScreen::ambientColor(0xff000000);
drawText((char*)items[selItem].label.c_str(), fontBig, 40 + 25, 60 + scrY + selPos*fontBig->getLineHeight());
}
static int countLines(string& t) {
int lines = 1;
char* c = (char*)t.c_str();
while (*c != 0) {
if (*c == 0xa) ++lines;
++c;
}
return lines;
}
void BKLayer::drawPopup(string& text, string& title, int bg1, int bg2, int fg) {
texUI->bindForDisplay();
int l = countLines(text);
int h = 25 + 25*l;
int y = (272 - h) /2;
// back
FZScreen::ambientColor(bg1);
drawPill(40, y, 480 - 86, h, 6, 31, 1);
// title
FZScreen::ambientColor(bg2);
drawPill(45, 5 + y, 480 - 86 - 10, 20, 6, 31, 1);
// icons
FZScreen::ambientColor(bg1|0xff000000);
// drawImage(410, 9 + y, BK_IMG_CIRCLE_XSIZE, BK_IMG_CIRCLE_YSIZE, BK_IMG_CIRCLE_X, BK_IMG_CIRCLE_Y);
switch (BKUser::controls.select) {
case FZ_REPS_CIRCLE:
drawImage(410, 9 + y, BK_IMG_CROSS_XSIZE, BK_IMG_CROSS_YSIZE, BK_IMG_CROSS_X, BK_IMG_CROSS_Y);
break;
case FZ_REPS_CROSS:
default:
drawImage(410, 9 + y, BK_IMG_CIRCLE_XSIZE, BK_IMG_CIRCLE_YSIZE, BK_IMG_CIRCLE_X, BK_IMG_CIRCLE_Y);
break;
}
fontBig->bindForDisplay();
FZScreen::ambientColor(fg);
drawText((char*)title.c_str(), fontBig, 51, y + 9);
drawText((char*)text.c_str(), fontBig, 51, y + 35);
}
void BKLayer::drawClockAndBattery(string& extra, bool reduced) {
texUI->bindForDisplay();
FZScreen::ambientColor(0xffbbbbbb);
drawImage(300, 226, BK_IMG_BATTERY_XSIZE, BK_IMG_BATTERY_YSIZE, BK_IMG_BATTERY_X, BK_IMG_BATTERY_Y);
drawImage(405, 222, BK_IMG_CLOCK_XSIZE, BK_IMG_CLOCK_YSIZE, BK_IMG_CLOCK_X, BK_IMG_CLOCK_Y);
// drawImage(292, 224, BK_IMG_MEMORY_XSIZE, BK_IMG_MEMORY_YSIZE, BK_IMG_MEMORY_X, BK_IMG_MEMORY_Y);
if (!reduced)
drawImage(237, 224, BK_IMG_MEMORY_XSIZE, BK_IMG_MEMORY_YSIZE,
BK_IMG_MEMORY_X, BK_IMG_MEMORY_Y);
fontSmall->bindForDisplay();
FZScreen::ambientColor(0xffbbbbbb);
int ew = textW((char*)extra.c_str(), fontSmall);
drawText((char*)extra.c_str(), fontSmall, 480 - 30 - ew, 205);
int h = 0, m = 0;
FZScreen::getTime(h, m);
int b = FZScreen::getBattery();
int bm = FZScreen::getBatteryMinutes();
int mem = FZScreen::getUsedMemory();
int speed = FZScreen::getSpeed();
char t1[20];
snprintf(t1, 20, "%02d:%02d", h, m);
char t2[50];
snprintf(t2, 50, "%d%% (%dh %dm)", b, bm / 60, bm % 60);
char t3[20];
// snprintf(t3, 20, "%.1fM", ((float)(mem)) / (1024.0f*1024.0f));
snprintf(t3, 20, "%dK", mem / 1024);
char t4[20];
snprintf(t4, 20, "%dMHz", speed);
drawText(t1, fontSmall, 425, 224);
drawText(t2, fontSmall, 320, 224);
if (!reduced)
drawText(t3, fontSmall, 260, 224);
// drawText(t4, fontSmall, 240, 224);
if (!reduced)
drawText(t4, fontSmall, 185, 224);
}
void BKLayer::menuCursorUpdate(unsigned int buttons, int max) {
int* b = FZScreen::ctrlReps();
if (b[BKUser::controls.menuUp] == 1 || b[BKUser::controls.menuUp] > 20) {
selItem--;
if (selItem < 0) {
selItem = max - 1;
}
}
if (b[BKUser::controls.menuDown] == 1 || b[BKUser::controls.menuDown] > 20) {
selItem++;
if (selItem >= max) {
selItem = 0;
}
}
}
BKLayer::BKLayer() : topItem(0), selItem(0) {
}
BKLayer::~BKLayer() {
}