Root/
Source at commit 04d9d93 created 10 years 8 months ago. By Paul Cercueil, Remove trailing slash from CARD_ROOT | |
---|---|
1 | /*************************************************************************** |
2 | * Copyright (C) 2006 by Massimiliano Torromeo * |
3 | * massimiliano.torromeo@gmail.com * |
4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License, or * |
8 | * (at your option) any later version. * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ***************************************************************************/ |
20 | |
21 | #include "gp2x.h" |
22 | |
23 | #include "asfont.h" |
24 | #include "cpu.h" |
25 | #include "debug.h" |
26 | #include "filedialog.h" |
27 | #include "filelister.h" |
28 | #include "gmenu2x.h" |
29 | #include "iconbutton.h" |
30 | #include "inputdialog.h" |
31 | #include "linkapp.h" |
32 | #include "menu.h" |
33 | #include "menusettingbool.h" |
34 | #include "menusettingdir.h" |
35 | #include "menusettingfile.h" |
36 | #include "menusettingimage.h" |
37 | #include "menusettingint.h" |
38 | #include "menusettingmultistring.h" |
39 | #include "menusettingrgba.h" |
40 | #include "menusettingstring.h" |
41 | #include "messagebox.h" |
42 | #include "powersaver.h" |
43 | #include "settingsdialog.h" |
44 | #include "textdialog.h" |
45 | #include "wallpaperdialog.h" |
46 | #include "utilities.h" |
47 | |
48 | #include <iostream> |
49 | #include <sstream> |
50 | #include <fstream> |
51 | #include <algorithm> |
52 | #include <stdlib.h> |
53 | #include <unistd.h> |
54 | #include <math.h> |
55 | #include <SDL.h> |
56 | #include <SDL_gfxPrimitives.h> |
57 | #include <signal.h> |
58 | |
59 | #include <sys/statvfs.h> |
60 | #include <errno.h> |
61 | |
62 | #include <sys/fcntl.h> //for battery |
63 | |
64 | #ifdef PLATFORM_PANDORA |
65 | //#include <pnd_container.h> |
66 | //#include <pnd_conf.h> |
67 | //#include <pnd_discovery.h> |
68 | #endif |
69 | |
70 | //for browsing the filesystem |
71 | #include <sys/stat.h> |
72 | #include <sys/types.h> |
73 | #include <dirent.h> |
74 | |
75 | //for soundcard |
76 | #include <sys/ioctl.h> |
77 | #include <linux/soundcard.h> |
78 | |
79 | #include <sys/mman.h> |
80 | |
81 | typedef fastdelegate::FastDelegate0<> MenuAction; |
82 | struct MenuOption { |
83 | std::string text; |
84 | MenuAction action; |
85 | }; |
86 | |
87 | using namespace std; |
88 | using namespace fastdelegate; |
89 | |
90 | #ifndef DEFAULT_WALLPAPER_PATH |
91 | #define DEFAULT_WALLPAPER_PATH \ |
92 | GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers/default.png" |
93 | #endif |
94 | |
95 | #ifdef _CARD_ROOT |
96 | const char *CARD_ROOT = _CARD_ROOT; |
97 | #elif defined(PLATFORM_A320) || defined(PLATFORM_GCW0) |
98 | const char *CARD_ROOT = "/media"; |
99 | #else |
100 | const char *CARD_ROOT = "/card"; |
101 | #endif |
102 | |
103 | static GMenu2X *app; |
104 | static string gmenu2x_home; |
105 | |
106 | // Note: Keep this in sync with the enum! |
107 | static const char *colorNames[NUM_COLORS] = { |
108 | "topBarBg", |
109 | "bottomBarBg", |
110 | "selectionBg", |
111 | "messageBoxBg", |
112 | "messageBoxBorder", |
113 | "messageBoxSelection", |
114 | }; |
115 | |
116 | static enum color stringToColor(const string &name) |
117 | { |
118 | for (unsigned int i = 0; i < NUM_COLORS; i++) { |
119 | if (strcmp(colorNames[i], name.c_str()) == 0) { |
120 | return (enum color)i; |
121 | } |
122 | } |
123 | return (enum color)-1; |
124 | } |
125 | |
126 | static const char *colorToString(enum color c) |
127 | { |
128 | return colorNames[c]; |
129 | } |
130 | |
131 | static void quit_all(int err) { |
132 | delete app; |
133 | exit(err); |
134 | } |
135 | |
136 | const string GMenu2X::getHome(void) |
137 | { |
138 | return gmenu2x_home; |
139 | } |
140 | |
141 | int main(int /*argc*/, char * /*argv*/[]) { |
142 | INFO("---- GMenu2X starting ----\n"); |
143 | |
144 | signal(SIGINT, &quit_all); |
145 | signal(SIGSEGV,&quit_all); |
146 | signal(SIGTERM,&quit_all); |
147 | |
148 | char *home = getenv("HOME"); |
149 | if (home == NULL) { |
150 | ERROR("Unable to find gmenu2x home directory. The $HOME variable is not defined.\n"); |
151 | return 1; |
152 | } |
153 | |
154 | gmenu2x_home = (string)home + (string)"/.gmenu2x"; |
155 | if (!fileExists(gmenu2x_home) && mkdir(gmenu2x_home.c_str(), 0770) < 0) { |
156 | ERROR("Unable to create gmenu2x home directory.\n"); |
157 | return 1; |
158 | } |
159 | |
160 | DEBUG("Home path: %s.\n", gmenu2x_home.c_str()); |
161 | |
162 | app = new GMenu2X(); |
163 | DEBUG("Starting main()\n"); |
164 | app->main(); |
165 | |
166 | return 0; |
167 | } |
168 | |
169 | #ifdef ENABLE_CPUFREQ |
170 | void GMenu2X::initCPULimits() { |
171 | // Note: These values are for the Dingoo. |
172 | // The NanoNote does not have cpufreq enabled in its kernel and |
173 | // other devices are not actively maintained. |
174 | // TODO: Read min and max from sysfs. |
175 | cpuFreqMin = 30; |
176 | cpuFreqMax = 500; |
177 | cpuFreqSafeMax = 420; |
178 | cpuFreqMenuDefault = 200; |
179 | cpuFreqAppDefault = 384; |
180 | cpuFreqMultiple = 24; |
181 | |
182 | // Round min and max values to the specified multiple. |
183 | cpuFreqMin = ((cpuFreqMin + cpuFreqMultiple - 1) / cpuFreqMultiple) |
184 | * cpuFreqMultiple; |
185 | cpuFreqMax = (cpuFreqMax / cpuFreqMultiple) * cpuFreqMultiple; |
186 | cpuFreqSafeMax = (cpuFreqSafeMax / cpuFreqMultiple) * cpuFreqMultiple; |
187 | cpuFreqMenuDefault = (cpuFreqMenuDefault / cpuFreqMultiple) * cpuFreqMultiple; |
188 | cpuFreqAppDefault = (cpuFreqAppDefault / cpuFreqMultiple) * cpuFreqMultiple; |
189 | } |
190 | #endif |
191 | |
192 | GMenu2X::GMenu2X() |
193 | { |
194 | usbnet = samba = inet = web = false; |
195 | useSelectionPng = false; |
196 | |
197 | #ifdef ENABLE_CPUFREQ |
198 | initCPULimits(); |
199 | #endif |
200 | //load config data |
201 | readConfig(); |
202 | |
203 | halfX = resX/2; |
204 | halfY = resY/2; |
205 | bottomBarIconY = resY-18; |
206 | bottomBarTextY = resY-10; |
207 | |
208 | /* Do not clear the screen on exit. |
209 | * This may require an SDL patch available at |
210 | * https://github.com/mthuurne/opendingux-buildroot/blob |
211 | * /opendingux-2010.11/package/sdl/sdl-fbcon-clear-onexit.patch |
212 | */ |
213 | setenv("SDL_FBCON_DONT_CLEAR", "1", 0); |
214 | |
215 | //Screen |
216 | if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK)<0 ) { |
217 | ERROR("Could not initialize SDL: %s\n", SDL_GetError()); |
218 | quit(); |
219 | } |
220 | |
221 | s = Surface::openOutputSurface(resX, resY, confInt["videoBpp"]); |
222 | |
223 | bg = NULL; |
224 | font = NULL; |
225 | menu = NULL; |
226 | setSkin(confStr["skin"], !fileExists(confStr["wallpaper"])); |
227 | initMenu(); |
228 | |
229 | if (!fileExists(confStr["wallpaper"])) { |
230 | DEBUG("No wallpaper defined; we will take the default one.\n"); |
231 | confStr["wallpaper"] = DEFAULT_WALLPAPER_PATH; |
232 | } |
233 | |
234 | initBG(); |
235 | |
236 | /* If a user-specified input.conf file exists, we load it; |
237 | * otherwise, we load the default one. */ |
238 | string input_file = getHome() + "/input.conf"; |
239 | if (fileExists(input_file.c_str())) { |
240 | DEBUG("Loading user-specific input.conf file: %s.\n", input_file.c_str()); |
241 | } else { |
242 | input_file = GMENU2X_SYSTEM_DIR "/input.conf"; |
243 | DEBUG("Loading system input.conf file: %s.\n", input_file.c_str()); |
244 | } |
245 | |
246 | input.init(input_file, menu); |
247 | |
248 | if (confInt["backlightTimeout"] > 0) |
249 | PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] ); |
250 | |
251 | setInputSpeed(); |
252 | #ifdef ENABLE_CPUFREQ |
253 | setClock(confInt["menuClock"]); |
254 | #endif |
255 | //recover last session |
256 | readTmp(); |
257 | if (lastSelectorElement>-1 && menu->selLinkApp()!=NULL && (!menu->selLinkApp()->getSelectorDir().empty() || !lastSelectorDir.empty())) |
258 | menu->selLinkApp()->selector(lastSelectorElement,lastSelectorDir); |
259 | |
260 | } |
261 | |
262 | GMenu2X::~GMenu2X() { |
263 | if (PowerSaver::isRunning()) |
264 | delete PowerSaver::getInstance(); |
265 | quit(); |
266 | |
267 | delete menu; |
268 | delete font; |
269 | } |
270 | |
271 | void GMenu2X::quit() { |
272 | fflush(NULL); |
273 | sc.clear(); |
274 | delete s; |
275 | |
276 | SDL_Quit(); |
277 | unsetenv("SDL_FBCON_DONT_CLEAR"); |
278 | } |
279 | |
280 | void GMenu2X::initBG() { |
281 | sc.del("bgmain"); |
282 | |
283 | // Load wallpaper. |
284 | delete bg; |
285 | bg = Surface::loadImage(confStr["wallpaper"]); |
286 | if (!bg) { |
287 | bg = Surface::emptySurface(resX, resY); |
288 | } |
289 | |
290 | drawTopBar(bg); |
291 | drawBottomBar(bg); |
292 | |
293 | Surface *bgmain = new Surface(bg); |
294 | sc.add(bgmain,"bgmain"); |
295 | |
296 | Surface *sd = Surface::loadImage("imgs/sd.png", confStr["skin"]); |
297 | if (sd) sd->blit(bgmain, 3, bottomBarIconY); |
298 | |
299 | #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) |
300 | string df = getDiskFree("/boot"); |
301 | #else |
302 | string df = getDiskFree(CARD_ROOT); |
303 | #endif |
304 | bgmain->write(font, df, 22, bottomBarTextY, ASFont::HAlignLeft, ASFont::VAlignMiddle); |
305 | delete sd; |
306 | |
307 | cpuX = font->getTextWidth(df)+32; |
308 | #ifdef ENABLE_CPUFREQ |
309 | Surface *cpu = Surface::loadImage("imgs/cpu.png", confStr["skin"]); |
310 | if (cpu) cpu->blit(bgmain, cpuX, bottomBarIconY); |
311 | cpuX += 19; |
312 | manualX = cpuX+font->getTextWidth("300MHz")+5; |
313 | delete cpu; |
314 | #else |
315 | manualX = cpuX; |
316 | #endif |
317 | |
318 | int serviceX = resX-38; |
319 | if (usbnet) { |
320 | if (web) { |
321 | Surface *webserver = Surface::loadImage( |
322 | "imgs/webserver.png", confStr["skin"]); |
323 | if (webserver) webserver->blit(bgmain, serviceX, bottomBarIconY); |
324 | serviceX -= 19; |
325 | delete webserver; |
326 | } |
327 | if (samba) { |
328 | Surface *sambaS = Surface::loadImage( |
329 | "imgs/samba.png", confStr["skin"]); |
330 | if (sambaS) sambaS->blit(bgmain, serviceX, bottomBarIconY); |
331 | serviceX -= 19; |
332 | delete sambaS; |
333 | } |
334 | if (inet) { |
335 | Surface *inetS = Surface::loadImage("imgs/inet.png", confStr["skin"]); |
336 | if (inetS) inetS->blit(bgmain, serviceX, bottomBarIconY); |
337 | serviceX -= 19; |
338 | delete inetS; |
339 | } |
340 | } |
341 | |
342 | bgmain->convertToDisplayFormat(); |
343 | } |
344 | |
345 | void GMenu2X::initFont() { |
346 | if (font != NULL) { |
347 | delete font; |
348 | font = NULL; |
349 | } |
350 | |
351 | string fontFile = sc.getSkinFilePath("imgs/font.png"); |
352 | if (fontFile.empty()) { |
353 | ERROR("Font png not found!\n"); |
354 | quit(); |
355 | exit(-1); |
356 | } |
357 | font = new ASFont(fontFile); |
358 | } |
359 | |
360 | void GMenu2X::initMenu() { |
361 | //Menu structure handler |
362 | menu = new Menu(this, ts); |
363 | for (uint i=0; i<menu->getSections().size(); i++) { |
364 | //Add virtual links in the applications section |
365 | if (menu->getSections()[i]=="applications") { |
366 | menu->addActionLink(i,"Explorer",MakeDelegate(this,&GMenu2X::explorer),tr["Launch an application"],"skin:icons/explorer.png"); |
367 | } |
368 | |
369 | //Add virtual links in the setting section |
370 | else if (menu->getSections()[i]=="settings") { |
371 | menu->addActionLink(i,"GMenu2X",MakeDelegate(this,&GMenu2X::options),tr["Configure GMenu2X's options"],"skin:icons/configure.png"); |
372 | menu->addActionLink(i,tr["Skin"],MakeDelegate(this,&GMenu2X::skinMenu),tr["Configure skin"],"skin:icons/skin.png"); |
373 | menu->addActionLink(i,tr["Wallpaper"],MakeDelegate(this,&GMenu2X::changeWallpaper),tr["Change GMenu2X wallpaper"],"skin:icons/wallpaper.png"); |
374 | if (fileExists(getHome()+"/log.txt")) |
375 | menu->addActionLink(i,tr["Log Viewer"],MakeDelegate(this,&GMenu2X::viewLog),tr["Displays last launched program's output"],"skin:icons/ebook.png"); |
376 | menu->addActionLink(i,tr["About"],MakeDelegate(this,&GMenu2X::about),tr["Info about GMenu2X"],"skin:icons/about.png"); |
377 | } |
378 | } |
379 | |
380 | menu->setSectionIndex(confInt["section"]); |
381 | menu->setLinkIndex(confInt["link"]); |
382 | |
383 | menu->loadIcons(); |
384 | |
385 | //DEBUG |
386 | //menu->addLink( CARD_ROOT, "sample.pxml", "applications" ); |
387 | } |
388 | |
389 | void GMenu2X::about() { |
390 | vector<string> text; |
391 | string line; |
392 | string fn(GMENU2X_SYSTEM_DIR); |
393 | string build_date("Build date: "); |
394 | fn.append("/about.txt"); |
395 | build_date.append(__DATE__); |
396 | |
397 | ifstream inf(fn.c_str(), ios_base::in); |
398 | |
399 | while(getline(inf, line, '\n')) |
400 | text.push_back(line); |
401 | inf.close(); |
402 | |
403 | TextDialog td(this, "GMenu2X", build_date, "icons/about.png", &text); |
404 | td.exec(); |
405 | } |
406 | |
407 | void GMenu2X::viewLog() { |
408 | string logfile = getHome()+"/log.txt"; |
409 | if (fileExists(logfile)) { |
410 | ifstream inf(logfile.c_str(), ios_base::in); |
411 | if (inf.is_open()) { |
412 | vector<string> log; |
413 | |
414 | string line; |
415 | while (getline(inf, line, '\n')) |
416 | log.push_back(line); |
417 | inf.close(); |
418 | |
419 | TextDialog td(this, tr["Log Viewer"], tr["Displays last launched program's output"], "icons/ebook.png", &log); |
420 | td.exec(); |
421 | |
422 | MessageBox mb(this, tr["Do you want to delete the log file?"], "icons/ebook.png"); |
423 | mb.setButton(InputManager::ACCEPT, tr["Yes"]); |
424 | mb.setButton(InputManager::CANCEL, tr["No"]); |
425 | if (mb.exec() == InputManager::ACCEPT) { |
426 | unlink(logfile.c_str()); |
427 | sync(); |
428 | menu->deleteSelectedLink(); |
429 | } |
430 | } |
431 | } |
432 | } |
433 | |
434 | void GMenu2X::readConfig() { |
435 | string conffile = GMENU2X_SYSTEM_DIR "/gmenu2x.conf"; |
436 | readConfig(conffile); |
437 | |
438 | conffile = getHome() + "/gmenu2x.conf"; |
439 | readConfig(conffile); |
440 | } |
441 | |
442 | void GMenu2X::readConfig(string conffile) { |
443 | if (fileExists(conffile)) { |
444 | ifstream inf(conffile.c_str(), ios_base::in); |
445 | if (inf.is_open()) { |
446 | string line; |
447 | while (getline(inf, line, '\n')) { |
448 | string::size_type pos = line.find("="); |
449 | string name = trim(line.substr(0,pos)); |
450 | string value = trim(line.substr(pos+1,line.length())); |
451 | |
452 | if (value.length()>1 && value.at(0)=='"' && value.at(value.length()-1)=='"') |
453 | confStr[name] = value.substr(1,value.length()-2); |
454 | else |
455 | confInt[name] = atoi(value.c_str()); |
456 | } |
457 | inf.close(); |
458 | } |
459 | } |
460 | if (!confStr["lang"].empty()) |
461 | tr.setLang(confStr["lang"]); |
462 | |
463 | if (!confStr["wallpaper"].empty() && !fileExists(confStr["wallpaper"])) |
464 | confStr["wallpaper"] = ""; |
465 | |
466 | if (confStr["skin"].empty() || SurfaceCollection::getSkinPath(confStr["skin"]).empty()) |
467 | confStr["skin"] = "Default"; |
468 | |
469 | evalIntConf( &confInt["outputLogs"], 0, 0,1 ); |
470 | #ifdef ENABLE_CPUFREQ |
471 | evalIntConf( &confInt["maxClock"], |
472 | cpuFreqSafeMax, cpuFreqMin, cpuFreqMax ); |
473 | evalIntConf( &confInt["menuClock"], |
474 | cpuFreqMenuDefault, cpuFreqMin, cpuFreqSafeMax ); |
475 | #endif |
476 | evalIntConf( &confInt["backlightTimeout"], 15, 0,120 ); |
477 | evalIntConf( &confInt["videoBpp"], 32, 16, 32 ); |
478 | |
479 | if (confStr["tvoutEncoding"] != "PAL") confStr["tvoutEncoding"] = "NTSC"; |
480 | resX = constrain( confInt["resolutionX"], 320,1920 ); |
481 | resY = constrain( confInt["resolutionY"], 240,1200 ); |
482 | } |
483 | |
484 | void GMenu2X::saveSelection() { |
485 | if (confInt["saveSelection"] && ( |
486 | confInt["section"] != menu->selSectionIndex() |
487 | || confInt["link"] != menu->selLinkIndex() |
488 | )) { |
489 | writeConfig(); |
490 | } |
491 | } |
492 | |
493 | void GMenu2X::writeConfig() { |
494 | string conffile = getHome() + "/gmenu2x.conf"; |
495 | ofstream inf(conffile.c_str()); |
496 | if (inf.is_open()) { |
497 | ConfStrHash::iterator endS = confStr.end(); |
498 | for(ConfStrHash::iterator curr = confStr.begin(); curr != endS; curr++) |
499 | inf << curr->first << "=\"" << curr->second << "\"" << endl; |
500 | |
501 | ConfIntHash::iterator endI = confInt.end(); |
502 | for(ConfIntHash::iterator curr = confInt.begin(); curr != endI; curr++) |
503 | inf << curr->first << "=" << curr->second << endl; |
504 | |
505 | inf.close(); |
506 | sync(); |
507 | } |
508 | } |
509 | |
510 | void GMenu2X::writeSkinConfig() { |
511 | string conffile = getHome() + "/skins/"; |
512 | if (!fileExists(conffile)) |
513 | mkdir(conffile.c_str(), 0770); |
514 | conffile = conffile + confStr["skin"]; |
515 | if (!fileExists(conffile)) |
516 | mkdir(conffile.c_str(), 0770); |
517 | conffile = conffile + "/skin.conf"; |
518 | |
519 | ofstream inf(conffile.c_str()); |
520 | if (inf.is_open()) { |
521 | ConfStrHash::iterator endS = skinConfStr.end(); |
522 | for(ConfStrHash::iterator curr = skinConfStr.begin(); curr != endS; curr++) |
523 | inf << curr->first << "=\"" << curr->second << "\"" << endl; |
524 | |
525 | ConfIntHash::iterator endI = skinConfInt.end(); |
526 | for(ConfIntHash::iterator curr = skinConfInt.begin(); curr != endI; curr++) |
527 | inf << curr->first << "=" << curr->second << endl; |
528 | |
529 | int i; |
530 | for (i = 0; i < NUM_COLORS; ++i) { |
531 | inf << colorToString((enum color)i) << "=#"; |
532 | inf.width(2); inf.fill('0'); |
533 | inf << right << hex << skinConfColors[i].r; |
534 | inf.width(2); inf.fill('0'); |
535 | inf << right << hex << skinConfColors[i].g; |
536 | inf.width(2); inf.fill('0'); |
537 | inf << right << hex << skinConfColors[i].b; |
538 | inf.width(2); inf.fill('0'); |
539 | inf << right << hex << skinConfColors[i].a << endl; |
540 | } |
541 | |
542 | inf.close(); |
543 | sync(); |
544 | } |
545 | } |
546 | |
547 | void GMenu2X::readTmp() { |
548 | lastSelectorElement = -1; |
549 | if (fileExists("/tmp/gmenu2x.tmp")) { |
550 | ifstream inf("/tmp/gmenu2x.tmp", ios_base::in); |
551 | if (inf.is_open()) { |
552 | string line; |
553 | string section = ""; |
554 | while (getline(inf, line, '\n')) { |
555 | string::size_type pos = line.find("="); |
556 | string name = trim(line.substr(0,pos)); |
557 | string value = trim(line.substr(pos+1,line.length())); |
558 | |
559 | if (name=="section") |
560 | menu->setSectionIndex(atoi(value.c_str())); |
561 | else if (name=="link") |
562 | menu->setLinkIndex(atoi(value.c_str())); |
563 | else if (name=="selectorelem") |
564 | lastSelectorElement = atoi(value.c_str()); |
565 | else if (name=="selectordir") |
566 | lastSelectorDir = value; |
567 | } |
568 | inf.close(); |
569 | } |
570 | } |
571 | } |
572 | |
573 | void GMenu2X::writeTmp(int selelem, const string &selectordir) { |
574 | string conffile = "/tmp/gmenu2x.tmp"; |
575 | ofstream inf(conffile.c_str()); |
576 | if (inf.is_open()) { |
577 | inf << "section=" << menu->selSectionIndex() << endl; |
578 | inf << "link=" << menu->selLinkIndex() << endl; |
579 | if (selelem>-1) |
580 | inf << "selectorelem=" << selelem << endl; |
581 | if (selectordir!="") |
582 | inf << "selectordir=" << selectordir << endl; |
583 | inf.close(); |
584 | sync(); |
585 | } |
586 | } |
587 | |
588 | void GMenu2X::main() { |
589 | uint linksPerPage = linkColumns*linkRows; |
590 | int linkSpacingX = (resX-10 - linkColumns*skinConfInt["linkWidth"])/linkColumns; |
591 | int linkSpacingY = (resY-35 - skinConfInt["topBarHeight"] - linkRows*skinConfInt["linkHeight"])/linkRows; |
592 | uint sectionLinkPadding = (skinConfInt["topBarHeight"] - 32 - font->getHeight()) / 3; |
593 | |
594 | bool quit = false; |
595 | int x,y; |
596 | int helpBoxHeight = 154; |
597 | uint i; |
598 | long tickBattery = -60000, tickNow; |
599 | string batteryIcon = "imgs/battery/0.png"; |
600 | stringstream ss; |
601 | uint sectionsCoordX = 24; |
602 | SDL_Rect re = {0,0,0,0}; |
603 | bool helpDisplayed = false; |
604 | #ifdef WITH_DEBUG |
605 | //framerate |
606 | long tickFPS = SDL_GetTicks(); |
607 | int drawn_frames = 0; |
608 | string fps = ""; |
609 | #endif |
610 | |
611 | IconButton btnContextMenu(this, ts, "skin:imgs/menu.png"); |
612 | btnContextMenu.setPosition(resX-38, bottomBarIconY); |
613 | btnContextMenu.setAction(MakeDelegate(this, &GMenu2X::contextMenu)); |
614 | |
615 | if (!fileExists(CARD_ROOT)) |
616 | CARD_ROOT = ""; |
617 | |
618 | while (!quit) { |
619 | tickNow = SDL_GetTicks(); |
620 | |
621 | //Background |
622 | sc["bgmain"]->blit(s,0,0); |
623 | |
624 | //Sections |
625 | sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2; |
626 | if (menu->firstDispSection()>0) |
627 | sc.skinRes("imgs/l_enabled.png")->blit(s,0,0); |
628 | else |
629 | sc.skinRes("imgs/l_disabled.png")->blit(s,0,0); |
630 | if (menu->firstDispSection()+linkColumns<menu->getSections().size()) |
631 | sc.skinRes("imgs/r_enabled.png")->blit(s,resX-10,0); |
632 | else |
633 | sc.skinRes("imgs/r_disabled.png")->blit(s,resX-10,0); |
634 | for (i=menu->firstDispSection(); i<menu->getSections().size() && i<menu->firstDispSection()+linkColumns; i++) { |
635 | string sectionIcon = "skin:sections/"+menu->getSections()[i]+".png"; |
636 | x = (i-menu->firstDispSection())*skinConfInt["linkWidth"]+sectionsCoordX; |
637 | if (menu->selSectionIndex()==(int)i) |
638 | s->box(x, 0, skinConfInt["linkWidth"], |
639 | skinConfInt["topBarHeight"], skinConfColors[COLOR_SELECTION_BG]); |
640 | x += skinConfInt["linkWidth"]/2; |
641 | if (sc.exists(sectionIcon)) |
642 | sc[sectionIcon]->blit(s,x-16,sectionLinkPadding,32,32); |
643 | else |
644 | sc.skinRes("icons/section.png")->blit(s,x-16,sectionLinkPadding); |
645 | s->write( font, menu->getSections()[i], x, skinConfInt["topBarHeight"]-sectionLinkPadding, ASFont::HAlignCenter, ASFont::VAlignBottom ); |
646 | } |
647 | |
648 | //Links |
649 | for (i=menu->firstDispRow()*linkColumns; i<(menu->firstDispRow()*linkColumns)+linksPerPage && i<menu->sectionLinks()->size(); i++) { |
650 | int ir = i-menu->firstDispRow()*linkColumns; |
651 | x = (ir%linkColumns)*(skinConfInt["linkWidth"]+linkSpacingX)+6; |
652 | y = ir/linkColumns*(skinConfInt["linkHeight"]+linkSpacingY)+skinConfInt["topBarHeight"]+2; |
653 | menu->sectionLinks()->at(i)->setPosition(x,y); |
654 | |
655 | if (i==(uint)menu->selLinkIndex()) |
656 | menu->sectionLinks()->at(i)->paintHover(); |
657 | |
658 | menu->sectionLinks()->at(i)->paint(); |
659 | } |
660 | s->clearClipRect(); |
661 | |
662 | drawScrollBar(linkRows,menu->sectionLinks()->size()/linkColumns + ((menu->sectionLinks()->size()%linkColumns==0) ? 0 : 1),menu->firstDispRow(),43,resY-81); |
663 | |
664 | if (menu->selLink()!=NULL) { |
665 | s->write ( font, menu->selLink()->getDescription(), halfX, resY-19, ASFont::HAlignCenter, ASFont::VAlignBottom ); |
666 | if (menu->selLinkApp()!=NULL) { |
667 | #ifdef ENABLE_CPUFREQ |
668 | s->write ( font, menu->selLinkApp()->clockStr(confInt["maxClock"]), cpuX, bottomBarTextY, ASFont::HAlignLeft, ASFont::VAlignMiddle ); |
669 | #endif |
670 | //Manual indicator |
671 | if (!menu->selLinkApp()->getManual().empty()) |
672 | sc.skinRes("imgs/manual.png")->blit(s,manualX,bottomBarIconY); |
673 | } |
674 | } |
675 | |
676 | if (ts.available()) { |
677 | btnContextMenu.paint(); |
678 | } |
679 | //check battery status every 60 seconds |
680 | if (tickNow-tickBattery >= 60000) { |
681 | tickBattery = tickNow; |
682 | unsigned short battlevel = getBatteryLevel(); |
683 | if (battlevel>5) { |
684 | batteryIcon = "imgs/battery/ac.png"; |
685 | } else { |
686 | ss.clear(); |
687 | ss << battlevel; |
688 | ss >> batteryIcon; |
689 | batteryIcon = "imgs/battery/"+batteryIcon+".png"; |
690 | } |
691 | } |
692 | sc.skinRes(batteryIcon)->blit( s, resX-19, bottomBarIconY ); |
693 | //s->write( font, tr[batstr.c_str()], 20, 170 ); |
694 | //On Screen Help |
695 | |
696 | |
697 | if (helpDisplayed) { |
698 | s->box(10,50,300,helpBoxHeight+4, skinConfColors[COLOR_MESSAGE_BOX_BG]); |
699 | s->rectangle( 12,52,296,helpBoxHeight, |
700 | skinConfColors[COLOR_MESSAGE_BOX_BORDER] ); |
701 | s->write( font, tr["CONTROLS"], 20, 60 ); |
702 | #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) |
703 | s->write( font, tr["A: Launch link / Confirm action"], 20, 80 ); |
704 | s->write( font, tr["B: Show this help menu"], 20, 95 ); |
705 | s->write( font, tr["L, R: Change section"], 20, 110 ); |
706 | s->write( font, tr["SELECT: Show contextual menu"], 20, 155 ); |
707 | s->write( font, tr["START: Show options menu"], 20, 170 ); |
708 | #endif |
709 | s->flip(); |
710 | while (input.waitForPressedButton() != InputManager::CANCEL) {} |
711 | helpDisplayed=false; |
712 | continue; |
713 | } |
714 | |
715 | #ifdef WITH_DEBUG |
716 | //framerate |
717 | drawn_frames++; |
718 | if (tickNow-tickFPS>=1000) { |
719 | ss.clear(); |
720 | ss << drawn_frames*(tickNow-tickFPS+1)/1000; |
721 | ss >> fps; |
722 | tickFPS = tickNow; |
723 | drawn_frames = 0; |
724 | } |
725 | s->write( font, fps+" FPS", resX-1,1 ,ASFont::HAlignRight ); |
726 | #endif |
727 | |
728 | s->flip(); |
729 | |
730 | //touchscreen |
731 | if (ts.available()) { |
732 | ts.poll(); |
733 | btnContextMenu.handleTS(); |
734 | re.x = 0; re.y = 0; re.h = skinConfInt["topBarHeight"]; re.w = resX; |
735 | if (ts.pressed() && ts.inRect(re)) { |
736 | re.w = skinConfInt["linkWidth"]; |
737 | sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2; |
738 | for (i=menu->firstDispSection(); !ts.handled() && i<menu->getSections().size() && i<menu->firstDispSection()+linkColumns; i++) { |
739 | re.x = (i-menu->firstDispSection())*re.w+sectionsCoordX; |
740 | |
741 | if (ts.inRect(re)) { |
742 | menu->setSectionIndex(i); |
743 | ts.setHandled(); |
744 | } |
745 | } |
746 | } |
747 | |
748 | i=menu->firstDispRow()*linkColumns; |
749 | while ( i<(menu->firstDispRow()*linkColumns)+linksPerPage && i<menu->sectionLinks()->size()) { |
750 | if (menu->sectionLinks()->at(i)->isPressed()) |
751 | menu->setLinkIndex(i); |
752 | if (menu->sectionLinks()->at(i)->handleTS()) |
753 | i = menu->sectionLinks()->size(); |
754 | i++; |
755 | } |
756 | } |
757 | |
758 | switch (input.waitForPressedButton()) { |
759 | case InputManager::ACCEPT: |
760 | if (menu->selLink() != NULL) menu->selLink()->run(); |
761 | break; |
762 | case InputManager::CANCEL: |
763 | helpDisplayed=true; |
764 | break; |
765 | case InputManager::SETTINGS: |
766 | options(); |
767 | break; |
768 | case InputManager::MENU: |
769 | contextMenu(); |
770 | break; |
771 | case InputManager::UP: |
772 | menu->linkUp(); |
773 | break; |
774 | case InputManager::DOWN: |
775 | menu->linkDown(); |
776 | break; |
777 | case InputManager::LEFT: |
778 | menu->linkLeft(); |
779 | break; |
780 | case InputManager::RIGHT: |
781 | menu->linkRight(); |
782 | break; |
783 | case InputManager::ALTLEFT: |
784 | menu->decSectionIndex(); |
785 | break; |
786 | case InputManager::ALTRIGHT: |
787 | menu->incSectionIndex(); |
788 | break; |
789 | default: |
790 | break; |
791 | } |
792 | } |
793 | } |
794 | |
795 | void GMenu2X::explorer() { |
796 | FileDialog fd(this, ts, tr["Select an application"], "dge,sh,bin,py,elf,"); |
797 | if (fd.exec()) { |
798 | if (confInt["saveSelection"] && (confInt["section"]!=menu->selSectionIndex() || confInt["link"]!=menu->selLinkIndex())) |
799 | writeConfig(); |
800 | |
801 | string command = cmdclean(fd.getPath()+"/"+fd.getFile()); |
802 | chdir(fd.getPath().c_str()); |
803 | quit(); |
804 | #ifdef ENABLE_CPUFREQ |
805 | setClock(cpuFreqAppDefault); |
806 | #endif |
807 | execlp("/bin/sh","/bin/sh","-c",command.c_str(),NULL); |
808 | |
809 | //if execution continues then something went wrong and as we already called SDL_Quit we cannot continue |
810 | //try relaunching gmenu2x |
811 | ERROR("Error executing selected application, re-launching gmenu2x\n"); |
812 | main(); |
813 | } |
814 | } |
815 | |
816 | void GMenu2X::options() { |
817 | #ifdef ENABLE_CPUFREQ |
818 | int curMenuClock = confInt["menuClock"]; |
819 | #endif |
820 | bool showRootFolder = fileExists(CARD_ROOT); |
821 | |
822 | FileLister fl_tr(GMENU2X_SYSTEM_DIR "/translations"); |
823 | fl_tr.browse(); |
824 | |
825 | string tr_path = getHome() + "/translations"; |
826 | if (fileExists(tr_path)) { |
827 | fl_tr.setPath(tr_path, false); |
828 | fl_tr.browse(false); |
829 | } |
830 | |
831 | fl_tr.insertFile("English"); |
832 | string lang = tr.lang(); |
833 | |
834 | vector<string> encodings; |
835 | encodings.push_back("NTSC"); |
836 | encodings.push_back("PAL"); |
837 | |
838 | SettingsDialog sd(this, input, ts, tr["Settings"]); |
839 | sd.addSetting(new MenuSettingMultiString(this, ts, tr["Language"], tr["Set the language used by GMenu2X"], &lang, &fl_tr.getFiles())); |
840 | sd.addSetting(new MenuSettingBool(this, ts, tr["Save last selection"], tr["Save the last selected link and section on exit"], &confInt["saveSelection"])); |
841 | #ifdef ENABLE_CPUFREQ |
842 | sd.addSetting(new MenuSettingInt(this, ts, tr["Clock for GMenu2X"], tr["Set the cpu working frequency when running GMenu2X"], &confInt["menuClock"], cpuFreqMin, cpuFreqSafeMax, cpuFreqMultiple)); |
843 | sd.addSetting(new MenuSettingInt(this, ts, tr["Maximum overclock"], tr["Set the maximum overclock for launching links"], &confInt["maxClock"], cpuFreqMin, cpuFreqMax, cpuFreqMultiple)); |
844 | #endif |
845 | sd.addSetting(new MenuSettingBool(this, ts, tr["Output logs"], tr["Logs the output of the links. Use the Log Viewer to read them."], &confInt["outputLogs"])); |
846 | sd.addSetting(new MenuSettingInt(this, ts, tr["Screen Timeout"], tr["Set screen's backlight timeout in seconds"], &confInt["backlightTimeout"], 0, 120)); |
847 | // sd.addSetting(new MenuSettingMultiString(this, ts, tr["Tv-Out encoding"], tr["Encoding of the tv-out signal"], &confStr["tvoutEncoding"], &encodings)); |
848 | sd.addSetting(new MenuSettingBool(this, ts, tr["Show root"], tr["Show root folder in the file selection dialogs"], &showRootFolder)); |
849 | |
850 | if (sd.exec() && sd.edited()) { |
851 | #ifdef ENABLE_CPUFREQ |
852 | if (curMenuClock != confInt["menuClock"]) setClock(confInt["menuClock"]); |
853 | #endif |
854 | |
855 | if (confInt["backlightTimeout"] == 0) { |
856 | if (PowerSaver::isRunning()) |
857 | delete PowerSaver::getInstance(); |
858 | } else { |
859 | PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] ); |
860 | } |
861 | |
862 | if (lang == "English") lang = ""; |
863 | if (lang != tr.lang()) { |
864 | tr.setLang(lang); |
865 | confStr["lang"] = lang; |
866 | } |
867 | /*if (fileExists(CARD_ROOT) && !showRootFolder) |
868 | unlink(CARD_ROOT); |
869 | else if (!fileExists(CARD_ROOT) && showRootFolder) |
870 | symlink("/", CARD_ROOT);*/ |
871 | //WARNING: the above might be dangerous with CARD_ROOT set to / |
872 | writeConfig(); |
873 | } |
874 | } |
875 | |
876 | void GMenu2X::skinMenu() { |
877 | FileLister fl_sk(getHome() + "/skins", true, false); |
878 | fl_sk.addExclude(".."); |
879 | fl_sk.browse(); |
880 | fl_sk.setPath(GMENU2X_SYSTEM_DIR "/skins", false); |
881 | fl_sk.browse(false); |
882 | |
883 | string curSkin = confStr["skin"]; |
884 | |
885 | SettingsDialog sd(this, input, ts, tr["Skin"]); |
886 | sd.addSetting(new MenuSettingMultiString(this, ts, tr["Skin"], tr["Set the skin used by GMenu2X"], &confStr["skin"], &fl_sk.getDirectories())); |
887 | sd.addSetting(new MenuSettingRGBA(this, ts, tr["Top Bar Color"], tr["Color of the top bar"], &skinConfColors[COLOR_TOP_BAR_BG])); |
888 | sd.addSetting(new MenuSettingRGBA(this, ts, tr["Bottom Bar Color"], tr["Color of the bottom bar"], &skinConfColors[COLOR_BOTTOM_BAR_BG])); |
889 | sd.addSetting(new MenuSettingRGBA(this, ts, tr["Selection Color"], tr["Color of the selection and other interface details"], &skinConfColors[COLOR_SELECTION_BG])); |
890 | sd.addSetting(new MenuSettingRGBA(this, ts, tr["Message Box Color"], tr["Background color of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_BG])); |
891 | sd.addSetting(new MenuSettingRGBA(this, ts, tr["Message Box Border Color"], tr["Border color of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_BORDER])); |
892 | sd.addSetting(new MenuSettingRGBA(this, ts, tr["Message Box Selection Color"], tr["Color of the selection of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_SELECTION])); |
893 | |
894 | if (sd.exec() && sd.edited()) { |
895 | if (curSkin != confStr["skin"]) { |
896 | setSkin(confStr["skin"]); |
897 | writeConfig(); |
898 | } |
899 | writeSkinConfig(); |
900 | initBG(); |
901 | } |
902 | } |
903 | |
904 | void GMenu2X::setSkin(const string &skin, bool setWallpaper) { |
905 | confStr["skin"] = skin; |
906 | |
907 | //Clear previous skin settings |
908 | skinConfStr.clear(); |
909 | skinConfInt.clear(); |
910 | |
911 | DEBUG("GMenu2X: setting new skin %s.\n", skin.c_str()); |
912 | |
913 | //clear collection and change the skin path |
914 | sc.clear(); |
915 | sc.setSkin(skin); |
916 | |
917 | //reset colors to the default values |
918 | skinConfColors[COLOR_TOP_BAR_BG] = (RGBAColor){255,255,255,130}; |
919 | skinConfColors[COLOR_BOTTOM_BAR_BG] = (RGBAColor){255,255,255,130}; |
920 | skinConfColors[COLOR_SELECTION_BG] = (RGBAColor){255,255,255,130}; |
921 | skinConfColors[COLOR_MESSAGE_BOX_BG] = (RGBAColor){255,255,255,255}; |
922 | skinConfColors[COLOR_MESSAGE_BOX_BORDER] = (RGBAColor){80,80,80,255}; |
923 | skinConfColors[COLOR_MESSAGE_BOX_SELECTION] = (RGBAColor){160,160,160,255}; |
924 | |
925 | /* Load skin settings from user directory if present, |
926 | * or from the system directory. */ |
927 | string skinconfname = getHome() + "/skins/" + skin + "/skin.conf"; |
928 | if (!fileExists(skinconfname)) |
929 | skinconfname = GMENU2X_SYSTEM_DIR "/skins/" + skin + "/skin.conf"; |
930 | |
931 | if (fileExists(skinconfname)) { |
932 | ifstream skinconf(skinconfname.c_str(), ios_base::in); |
933 | if (skinconf.is_open()) { |
934 | string line; |
935 | while (getline(skinconf, line, '\n')) { |
936 | line = trim(line); |
937 | DEBUG("skinconf: '%s'\n", line.c_str()); |
938 | string::size_type pos = line.find("="); |
939 | string name = trim(line.substr(0,pos)); |
940 | string value = trim(line.substr(pos+1,line.length())); |
941 | |
942 | if (value.length()>0) { |
943 | if (value.length()>1 && value.at(0)=='"' && value.at(value.length()-1)=='"') |
944 | skinConfStr[name] = value.substr(1,value.length()-2); |
945 | else if (value.at(0) == '#') |
946 | skinConfColors[stringToColor(name)] = strtorgba( value.substr(1,value.length()) ); |
947 | else |
948 | skinConfInt[name] = atoi(value.c_str()); |
949 | } |
950 | } |
951 | skinconf.close(); |
952 | |
953 | if (setWallpaper && !skinConfStr["wallpaper"].empty()) { |
954 | string fp = sc.getSkinFilePath("wallpapers/" + skinConfStr["wallpaper"]); |
955 | if (!fp.empty()) |
956 | confStr["wallpaper"] = fp; |
957 | else |
958 | WARNING("Unable to find wallpaper defined on skin %s\n", skin.c_str()); |
959 | } |
960 | } |
961 | } |
962 | |
963 | evalIntConf( &skinConfInt["topBarHeight"], 40, 32,120 ); |
964 | evalIntConf( &skinConfInt["linkHeight"], 40, 32,120 ); |
965 | evalIntConf( &skinConfInt["linkWidth"], 60, 32,120 ); |
966 | |
967 | //recalculate some coordinates based on the new element sizes |
968 | linkColumns = (resX-10)/skinConfInt["linkWidth"]; |
969 | linkRows = (resY-35-skinConfInt["topBarHeight"])/skinConfInt["linkHeight"]; |
970 | |
971 | if (menu != NULL) menu->loadIcons(); |
972 | |
973 | //Selection png |
974 | useSelectionPng = sc.addSkinRes("imgs/selection.png", false) != NULL; |
975 | |
976 | //font |
977 | initFont(); |
978 | } |
979 | |
980 | void GMenu2X::showManual() { |
981 | menu->selLinkApp()->showManual(); |
982 | } |
983 | |
984 | void GMenu2X::contextMenu() { |
985 | vector<MenuOption> voices; |
986 | { |
987 | MenuOption opt = {tr.translate("Add link in $1",menu->selSection().c_str(),NULL), MakeDelegate(this, &GMenu2X::addLink)}; |
988 | voices.push_back(opt); |
989 | } |
990 | |
991 | { |
992 | LinkApp* app = menu->selLinkApp(); |
993 | if (app && !app->getManual().empty()) { |
994 | MenuOption opt = {tr.translate("Show manual of $1",menu->selLink()->getTitle().c_str(),NULL), |
995 | MakeDelegate(this, &GMenu2X::showManual), |
996 | }; |
997 | voices.push_back(opt); |
998 | } |
999 | } |
1000 | |
1001 | if (menu->selLinkApp()!=NULL && menu->selLinkApp()->isEditable()) { |
1002 | |
1003 | /* FIXME(percuei): this permits to mask the "Edit link" entry |
1004 | * on the contextual menu in case CPUFREQ support is |
1005 | * not compiled in and the link corresponds to an OPK. |
1006 | * This is not a good idea as it'll break things if |
1007 | * a new config option is added to the contextual menu. */ |
1008 | #if defined(HAVE_LIBOPK) && !defined(ENABLE_CPUFREQ) |
1009 | if (!menu->selLinkApp()->isOpk() || |
1010 | !menu->selLinkApp()->getSelectorDir().empty()) |
1011 | #endif |
1012 | { |
1013 | MenuOption opt = {tr.translate("Edit $1",menu->selLink()->getTitle().c_str(),NULL), MakeDelegate(this, &GMenu2X::editLink)}; |
1014 | voices.push_back(opt); |
1015 | } |
1016 | #ifdef HAVE_LIBOPK |
1017 | if (!menu->selLinkApp()->isOpk()) |
1018 | #endif |
1019 | { |
1020 | MenuOption opt = {tr.translate("Delete $1 link",menu->selLink()->getTitle().c_str(),NULL), MakeDelegate(this, &GMenu2X::deleteLink)}; |
1021 | voices.push_back(opt); |
1022 | } |
1023 | } |
1024 | |
1025 | { |
1026 | MenuOption opt = {tr["Add section"], MakeDelegate(this, &GMenu2X::addSection)}; |
1027 | voices.push_back(opt); |
1028 | }{ |
1029 | MenuOption opt = {tr["Rename section"], MakeDelegate(this, &GMenu2X::renameSection)}; |
1030 | voices.push_back(opt); |
1031 | }{ |
1032 | MenuOption opt = {tr["Delete section"], MakeDelegate(this, &GMenu2X::deleteSection)}; |
1033 | voices.push_back(opt); |
1034 | }{ |
1035 | MenuOption opt = {tr["Scan for applications and games"], MakeDelegate(this, &GMenu2X::scanner)}; |
1036 | voices.push_back(opt); |
1037 | } |
1038 | |
1039 | bool close = false; |
1040 | uint i, fadeAlpha=0; |
1041 | int sel = 0; |
1042 | |
1043 | int h = font->getHeight(); |
1044 | SDL_Rect box; |
1045 | box.h = (h+2)*voices.size()+8; |
1046 | box.w = 0; |
1047 | for (i=0; i<voices.size(); i++) { |
1048 | int w = font->getTextWidth(voices[i].text); |
1049 | if (w>box.w) box.w = w; |
1050 | } |
1051 | box.w += 23; |
1052 | box.x = halfX - box.w/2; |
1053 | box.y = halfY - box.h/2; |
1054 | |
1055 | SDL_Rect selbox = { |
1056 | static_cast<Sint16>(box.x + 4), |
1057 | 0, |
1058 | static_cast<Uint16>(box.w - 8), |
1059 | static_cast<Uint16>(h + 2) |
1060 | }; |
1061 | long tickNow, tickStart = SDL_GetTicks(); |
1062 | |
1063 | Surface bg(s); |
1064 | /*//Darken background |
1065 | bg.box(0, 0, resX, resY, 0,0,0,150); |
1066 | bg.box(box.x, box.y, box.w, box.h, skinConfColors["messageBoxBg"]); |
1067 | bg.rectangle( box.x+2, box.y+2, box.w-4, box.h-4, skinConfColors["messageBoxBorder"] );*/ |
1068 | |
1069 | InputManager::ButtonEvent event; |
1070 | while (!close) { |
1071 | tickNow = SDL_GetTicks(); |
1072 | |
1073 | selbox.y = box.y+4+(h+2)*sel; |
1074 | bg.blit(s,0,0); |
1075 | |
1076 | if (fadeAlpha<200) fadeAlpha = intTransition(0,200,tickStart,500,tickNow); |
1077 | s->box(0, 0, resX, resY, 0,0,0,fadeAlpha); |
1078 | s->box(box.x, box.y, box.w, box.h, skinConfColors[COLOR_MESSAGE_BOX_BG]); |
1079 | s->rectangle( box.x+2, box.y+2, box.w-4, box.h-4, skinConfColors[COLOR_MESSAGE_BOX_BORDER] ); |
1080 | |
1081 | |
1082 | //draw selection rect |
1083 | s->box( selbox.x, selbox.y, selbox.w, selbox.h, skinConfColors[COLOR_MESSAGE_BOX_SELECTION] ); |
1084 | for (i=0; i<voices.size(); i++) |
1085 | s->write( font, voices[i].text, box.x+12, box.y+5+(h+2)*i, ASFont::HAlignLeft, ASFont::VAlignTop ); |
1086 | s->flip(); |
1087 | |
1088 | //touchscreen |
1089 | if (ts.available()) { |
1090 | ts.poll(); |
1091 | if (ts.released()) { |
1092 | if (!ts.inRect(box)) |
1093 | close = true; |
1094 | else if (ts.getX() >= selbox.x |
1095 | && ts.getX() <= selbox.x + selbox.w) |
1096 | for (i=0; i<voices.size(); i++) { |
1097 | selbox.y = box.y+4+(h+2)*i; |
1098 | if (ts.getY() >= selbox.y |
1099 | && ts.getY() <= selbox.y + selbox.h) { |
1100 | voices[i].action(); |
1101 | close = true; |
1102 | i = voices.size(); |
1103 | } |
1104 | } |
1105 | } else if (ts.pressed() && ts.inRect(box)) { |
1106 | for (i=0; i<voices.size(); i++) { |
1107 | selbox.y = box.y+4+(h+2)*i; |
1108 | if (ts.getY() >= selbox.y |
1109 | && ts.getY() <= selbox.y + selbox.h) { |
1110 | sel = i; |
1111 | i = voices.size(); |
1112 | } |
1113 | } |
1114 | } |
1115 | } |
1116 | |
1117 | |
1118 | if (fadeAlpha < 200) { |
1119 | if (!input.pollEvent(&event) || event.state != InputManager::PRESSED) continue; |
1120 | } else { |
1121 | event.button = input.waitForPressedButton(); |
1122 | } |
1123 | |
1124 | switch(event.button) { |
1125 | case InputManager::MENU: |
1126 | close = true; |
1127 | break; |
1128 | case InputManager::UP: |
1129 | sel = std::max(0, sel-1); |
1130 | break; |
1131 | case InputManager::DOWN: |
1132 | sel = std::min((int)voices.size()-1, sel+1); |
1133 | break; |
1134 | case InputManager::ACCEPT: |
1135 | voices[sel].action(); |
1136 | close = true; |
1137 | break; |
1138 | default: |
1139 | break; |
1140 | } |
1141 | } |
1142 | } |
1143 | |
1144 | void GMenu2X::changeWallpaper() { |
1145 | WallpaperDialog wp(this, ts); |
1146 | if (wp.exec() && confStr["wallpaper"] != wp.wallpaper) { |
1147 | confStr["wallpaper"] = wp.wallpaper; |
1148 | initBG(); |
1149 | writeConfig(); |
1150 | } |
1151 | } |
1152 | |
1153 | void GMenu2X::addLink() { |
1154 | FileDialog fd(this, ts, tr["Select an application"], "dge,sh,bin,py,elf,"); |
1155 | if (fd.exec()) { |
1156 | menu->addLink(fd.getPath(), fd.getFile()); |
1157 | sync(); |
1158 | } |
1159 | } |
1160 | |
1161 | void GMenu2X::editLink() { |
1162 | if (menu->selLinkApp()==NULL) return; |
1163 | |
1164 | vector<string> pathV; |
1165 | split(pathV,menu->selLinkApp()->getFile(),"/"); |
1166 | string oldSection = ""; |
1167 | if (pathV.size()>1) |
1168 | oldSection = pathV[pathV.size()-2]; |
1169 | string newSection = oldSection; |
1170 | |
1171 | string linkTitle = menu->selLinkApp()->getTitle(); |
1172 | string linkDescription = menu->selLinkApp()->getDescription(); |
1173 | string linkIcon = menu->selLinkApp()->getIcon(); |
1174 | string linkManual = menu->selLinkApp()->getManual(); |
1175 | string linkSelFilter = menu->selLinkApp()->getSelectorFilter(); |
1176 | string linkSelDir = menu->selLinkApp()->getSelectorDir(); |
1177 | bool linkSelBrowser = menu->selLinkApp()->getSelectorBrowser(); |
1178 | string linkSelScreens = menu->selLinkApp()->getSelectorScreens(); |
1179 | string linkSelAliases = menu->selLinkApp()->getAliasFile(); |
1180 | int linkClock = menu->selLinkApp()->clock(); |
1181 | |
1182 | string diagTitle = tr.translate("Edit link: $1",linkTitle.c_str(),NULL); |
1183 | string diagIcon = menu->selLinkApp()->getIconPath(); |
1184 | |
1185 | SettingsDialog sd(this, input, ts, diagTitle, diagIcon); |
1186 | #ifdef HAVE_LIBOPK |
1187 | if (!menu->selLinkApp()->isOpk()) { |
1188 | #endif |
1189 | sd.addSetting(new MenuSettingString(this, ts, tr["Title"], tr["Link title"], &linkTitle, diagTitle, diagIcon)); |
1190 | sd.addSetting(new MenuSettingString(this, ts, tr["Description"], tr["Link description"], &linkDescription, diagTitle, diagIcon)); |
1191 | sd.addSetting(new MenuSettingMultiString(this, ts, tr["Section"], tr["The section this link belongs to"], &newSection, &menu->getSections())); |
1192 | sd.addSetting(new MenuSettingImage(this, ts, tr["Icon"], |
1193 | tr.translate("Select an icon for the link: $1", |
1194 | linkTitle.c_str(), NULL), &linkIcon, "png")); |
1195 | sd.addSetting(new MenuSettingFile(this, ts, tr["Manual"], |
1196 | tr["Select a graphic/textual manual or a readme"], |
1197 | &linkManual, "man.png,txt")); |
1198 | #ifdef HAVE_LIBOPK |
1199 | } |
1200 | if (!menu->selLinkApp()->isOpk() || |
1201 | !menu->selLinkApp()->getSelectorDir().empty()) { |
1202 | #endif |
1203 | sd.addSetting(new MenuSettingDir(this, ts, tr["Selector Directory"], tr["Directory to scan for the selector"], &linkSelDir)); |
1204 | sd.addSetting(new MenuSettingBool(this, ts, tr["Selector Browser"], tr["Allow the selector to change directory"], &linkSelBrowser)); |
1205 | #ifdef HAVE_LIBOPK |
1206 | } |
1207 | #endif |
1208 | #ifdef ENABLE_CPUFREQ |
1209 | sd.addSetting(new MenuSettingInt(this, ts, tr["Clock frequency"], tr["Cpu clock frequency to set when launching this link"], &linkClock, cpuFreqMin, confInt["maxClock"], cpuFreqMultiple)); |
1210 | #endif |
1211 | #ifdef HAVE_LIBOPK |
1212 | if (!menu->selLinkApp()->isOpk()) { |
1213 | #endif |
1214 | sd.addSetting(new MenuSettingString(this, ts, tr["Selector Filter"], tr["Selector filter (Separate values with a comma)"], &linkSelFilter, diagTitle, diagIcon)); |
1215 | sd.addSetting(new MenuSettingDir(this, ts, tr["Selector Screenshots"], tr["Directory of the screenshots for the selector"], &linkSelScreens)); |
1216 | sd.addSetting(new MenuSettingFile(this, ts, tr["Selector Aliases"], tr["File containing a list of aliases for the selector"], &linkSelAliases)); |
1217 | sd.addSetting(new MenuSettingBool(this, ts, tr["Don't Leave"], tr["Don't quit GMenu2X when launching this link"], &menu->selLinkApp()->runsInBackgroundRef())); |
1218 | #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) |
1219 | sd.addSetting(new MenuSettingBool(this, ts, tr["Display Console"], tr["Must be enabled for console-based applications"], &menu->selLinkApp()->consoleApp)); |
1220 | #endif |
1221 | #ifdef HAVE_LIBOPK |
1222 | } |
1223 | #endif |
1224 | |
1225 | if (sd.exec() && sd.edited()) { |
1226 | menu->selLinkApp()->setTitle(linkTitle); |
1227 | menu->selLinkApp()->setDescription(linkDescription); |
1228 | menu->selLinkApp()->setIcon(linkIcon); |
1229 | menu->selLinkApp()->setManual(linkManual); |
1230 | menu->selLinkApp()->setSelectorFilter(linkSelFilter); |
1231 | menu->selLinkApp()->setSelectorDir(linkSelDir); |
1232 | menu->selLinkApp()->setSelectorBrowser(linkSelBrowser); |
1233 | menu->selLinkApp()->setSelectorScreens(linkSelScreens); |
1234 | menu->selLinkApp()->setAliasFile(linkSelAliases); |
1235 | menu->selLinkApp()->setClock(linkClock); |
1236 | |
1237 | INFO("New Section: '%s'\n", newSection.c_str()); |
1238 | |
1239 | //if section changed move file and update link->file |
1240 | if (oldSection!=newSection) { |
1241 | vector<string>::const_iterator newSectionIndex = find(menu->getSections().begin(),menu->getSections().end(),newSection); |
1242 | if (newSectionIndex==menu->getSections().end()) return; |
1243 | string newFileName = "sections/"+newSection+"/"+linkTitle; |
1244 | uint x=2; |
1245 | while (fileExists(newFileName)) { |
1246 | string id = ""; |
1247 | stringstream ss; ss << x; ss >> id; |
1248 | newFileName = "sections/"+newSection+"/"+linkTitle+id; |
1249 | x++; |
1250 | } |
1251 | rename(menu->selLinkApp()->getFile().c_str(),newFileName.c_str()); |
1252 | menu->selLinkApp()->renameFile(newFileName); |
1253 | |
1254 | INFO("New section index: %i.\n", newSectionIndex - menu->getSections().begin()); |
1255 | |
1256 | menu->linkChangeSection(menu->selLinkIndex(), menu->selSectionIndex(), newSectionIndex - menu->getSections().begin()); |
1257 | } |
1258 | menu->selLinkApp()->save(); |
1259 | sync(); |
1260 | } |
1261 | } |
1262 | |
1263 | void GMenu2X::deleteLink() { |
1264 | if (menu->selLinkApp()!=NULL) { |
1265 | MessageBox mb(this, tr.translate("Deleting $1",menu->selLink()->getTitle().c_str(),NULL)+"\n"+tr["Are you sure?"], menu->selLink()->getIconPath()); |
1266 | mb.setButton(InputManager::ACCEPT, tr["Yes"]); |
1267 | mb.setButton(InputManager::CANCEL, tr["No"]); |
1268 | if (mb.exec() == InputManager::ACCEPT) { |
1269 | menu->deleteSelectedLink(); |
1270 | sync(); |
1271 | } |
1272 | } |
1273 | } |
1274 | |
1275 | void GMenu2X::addSection() { |
1276 | InputDialog id(this, input, ts, tr["Insert a name for the new section"]); |
1277 | if (id.exec()) { |
1278 | //only if a section with the same name does not exist |
1279 | if (find(menu->getSections().begin(), menu->getSections().end(), id.getInput()) |
1280 | == menu->getSections().end()) { |
1281 | //section directory doesn't exists |
1282 | if (menu->addSection(id.getInput())) { |
1283 | menu->setSectionIndex( menu->getSections().size()-1 ); //switch to the new section |
1284 | sync(); |
1285 | } |
1286 | } |
1287 | } |
1288 | } |
1289 | |
1290 | void GMenu2X::renameSection() { |
1291 | InputDialog id(this, input, ts, tr["Insert a new name for this section"],menu->selSection()); |
1292 | if (id.exec()) { |
1293 | //only if a section with the same name does not exist & !samename |
1294 | if (menu->selSection() != id.getInput() |
1295 | && find(menu->getSections().begin(),menu->getSections().end(), id.getInput()) |
1296 | == menu->getSections().end()) { |
1297 | //section directory doesn't exists |
1298 | string newsectiondir = getHome() + "/sections/" + id.getInput(); |
1299 | string sectiondir = getHome() + "/sections/" + menu->selSection(); |
1300 | |
1301 | if (!rename(sectiondir.c_str(), newsectiondir.c_str())) { |
1302 | string oldpng = menu->selSection() + ".png"; |
1303 | string newpng = id.getInput() + ".png"; |
1304 | string oldicon = sc.getSkinFilePath(oldpng); |
1305 | string newicon = sc.getSkinFilePath(newpng); |
1306 | |
1307 | if (!oldicon.empty() && newicon.empty()) { |
1308 | newicon = oldicon; |
1309 | newicon.replace(newicon.find(oldpng), oldpng.length(), newpng); |
1310 | |
1311 | if (!fileExists(newicon)) { |
1312 | rename(oldicon.c_str(), newicon.c_str()); |
1313 | sc.move("skin:"+oldpng, "skin:"+newpng); |
1314 | } |
1315 | } |
1316 | menu->renameSection(menu->selSectionIndex(), id.getInput()); |
1317 | sync(); |
1318 | } |
1319 | } |
1320 | } |
1321 | } |
1322 | |
1323 | void GMenu2X::deleteSection() { |
1324 | MessageBox mb(this,tr["You will lose all the links in this section."]+"\n"+tr["Are you sure?"]); |
1325 | mb.setButton(InputManager::ACCEPT, tr["Yes"]); |
1326 | mb.setButton(InputManager::CANCEL, tr["No"]); |
1327 | if (mb.exec() == InputManager::ACCEPT) { |
1328 | |
1329 | if (rmtree(getHome() + "/sections/" + menu->selSection())) { |
1330 | menu->deleteSelectedSection(); |
1331 | sync(); |
1332 | } |
1333 | } |
1334 | } |
1335 | |
1336 | void GMenu2X::scanner() { |
1337 | Surface scanbg(bg); |
1338 | drawButton(&scanbg, "cancel", tr["Exit"], |
1339 | drawButton(&scanbg, "accept", "", 5)-10); |
1340 | scanbg.write(font,tr["Link Scanner"],halfX,7,ASFont::HAlignCenter,ASFont::VAlignMiddle); |
1341 | scanbg.convertToDisplayFormat(); |
1342 | |
1343 | uint lineY = 42; |
1344 | |
1345 | #ifdef PLATFORM_PANDORA |
1346 | //char *configpath = pnd_conf_query_searchpath(); |
1347 | #else |
1348 | #ifdef ENABLE_CPUFREQ |
1349 | setSafeMaxClock(); |
1350 | #endif |
1351 | |
1352 | scanbg.write(font,tr["Scanning filesystem..."],5,lineY); |
1353 | scanbg.blit(s,0,0); |
1354 | s->flip(); |
1355 | lineY += 26; |
1356 | |
1357 | vector<string> files; |
1358 | scanPath(CARD_ROOT, &files); |
1359 | |
1360 | stringstream ss; |
1361 | ss << files.size(); |
1362 | string str = ""; |
1363 | ss >> str; |
1364 | scanbg.write(font,tr.translate("$1 files found.",str.c_str(),NULL),5,lineY); |
1365 | lineY += 26; |
1366 | scanbg.write(font,tr["Creating links..."],5,lineY); |
1367 | scanbg.blit(s,0,0); |
1368 | s->flip(); |
1369 | lineY += 26; |
1370 | |
1371 | string path, file; |
1372 | string::size_type pos; |
1373 | uint linkCount = 0; |
1374 | |
1375 | for (uint i = 0; i<files.size(); i++) { |
1376 | pos = files[i].rfind("/"); |
1377 | if (pos!=string::npos && pos>0) { |
1378 | path = files[i].substr(0, pos+1); |
1379 | file = files[i].substr(pos+1, files[i].length()); |
1380 | if (menu->addLink(path,file,"found "+file.substr(file.length()-3,3))) |
1381 | linkCount++; |
1382 | } |
1383 | } |
1384 | |
1385 | ss.clear(); |
1386 | ss << linkCount; |
1387 | ss >> str; |
1388 | scanbg.write(font,tr.translate("$1 links created.",str.c_str(),NULL),5,lineY); |
1389 | scanbg.blit(s,0,0); |
1390 | s->flip(); |
1391 | lineY += 26; |
1392 | |
1393 | #ifdef ENABLE_CPUFREQ |
1394 | setMenuClock(); |
1395 | #endif |
1396 | sync(); |
1397 | #endif |
1398 | |
1399 | InputManager::Button button; |
1400 | do { |
1401 | button = input.waitForPressedButton(); |
1402 | } while ((button != InputManager::SETTINGS) |
1403 | && (button != InputManager::ACCEPT) |
1404 | && (button != InputManager::CANCEL)); |
1405 | } |
1406 | |
1407 | void GMenu2X::scanPath(string path, vector<string> *files) { |
1408 | DIR *dirp; |
1409 | struct stat st; |
1410 | struct dirent *dptr; |
1411 | string filepath, ext; |
1412 | |
1413 | if (path[path.length()-1]!='/') path += "/"; |
1414 | if ((dirp = opendir(path.c_str())) == NULL) return; |
1415 | |
1416 | while ((dptr = readdir(dirp))) { |
1417 | if (dptr->d_name[0]=='.') |
1418 | continue; |
1419 | filepath = path+dptr->d_name; |
1420 | int statRet = stat(filepath.c_str(), &st); |
1421 | if (S_ISDIR(st.st_mode)) |
1422 | scanPath(filepath, files); |
1423 | if (statRet != -1) { |
1424 | ext = filepath.substr(filepath.length()-4,4); |
1425 | #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) || defined(PLATFORM_NANONOTE) |
1426 | if (ext==".dge") |
1427 | #else |
1428 | if (ext==".pxml") |
1429 | #endif |
1430 | files->push_back(filepath); |
1431 | } |
1432 | } |
1433 | |
1434 | closedir(dirp); |
1435 | } |
1436 | |
1437 | typedef struct { |
1438 | unsigned short batt; |
1439 | unsigned short remocon; |
1440 | } MMSP2ADC; |
1441 | |
1442 | unsigned short GMenu2X::getBatteryLevel() { |
1443 | FILE *batteryHandle = NULL, |
1444 | *usbHandle = NULL; |
1445 | |
1446 | #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) || defined(PLATFORM_NANONOTE) |
1447 | usbHandle = fopen("/sys/class/power_supply/usb/online", "r"); |
1448 | #endif |
1449 | if (usbHandle) { |
1450 | int usbval = 0; |
1451 | fscanf(usbHandle, "%d", &usbval); |
1452 | fclose(usbHandle); |
1453 | if (usbval == 1) |
1454 | return 6; |
1455 | } |
1456 | |
1457 | #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) || defined(PLATFORM_NANONOTE) |
1458 | batteryHandle = fopen("/sys/class/power_supply/battery/capacity", "r"); |
1459 | #endif |
1460 | if (batteryHandle) { |
1461 | int battval = 0; |
1462 | fscanf(batteryHandle, "%d", &battval); |
1463 | fclose(batteryHandle); |
1464 | |
1465 | if (battval>90) return 5; |
1466 | if (battval>70) return 4; |
1467 | if (battval>50) return 3; |
1468 | if (battval>30) return 2; |
1469 | if (battval>10) return 1; |
1470 | } |
1471 | |
1472 | return 0; |
1473 | } |
1474 | |
1475 | void GMenu2X::setInputSpeed() { |
1476 | SDL_EnableKeyRepeat(1,150); |
1477 | } |
1478 | |
1479 | #ifdef ENABLE_CPUFREQ |
1480 | void GMenu2X::setClock(unsigned mhz) { |
1481 | mhz = constrain(mhz, cpuFreqMin, confInt["maxClock"]); |
1482 | #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) || defined(PLATFORM_NANONOTE) |
1483 | jz_cpuspeed(mhz); |
1484 | #endif |
1485 | } |
1486 | #endif |
1487 | |
1488 | string GMenu2X::getDiskFree(const char *path) { |
1489 | stringstream ss; |
1490 | string df = ""; |
1491 | struct statvfs b; |
1492 | |
1493 | int ret = statvfs(path, &b); |
1494 | if (ret==0) { |
1495 | // Make sure that the multiplication happens in 64 bits. |
1496 | unsigned long long free = |
1497 | ((unsigned long long)b.f_bfree * b.f_bsize) / 1048576; |
1498 | unsigned long long total = |
1499 | ((unsigned long long)b.f_blocks * b.f_frsize) / 1048576; |
1500 | ss << free << "/" << total << "MB"; |
1501 | ss >> df; |
1502 | } else WARNING("statvfs failed with error '%s'.\n", strerror(errno)); |
1503 | return df; |
1504 | } |
1505 | |
1506 | int GMenu2X::drawButton(Button *btn, int x, int y) { |
1507 | if (y<0) y = resY+y; |
1508 | btn->setPosition(x, y-7); |
1509 | btn->paint(); |
1510 | return x+btn->getRect().w+6; |
1511 | } |
1512 | |
1513 | int GMenu2X::drawButton(Surface *s, const string &btn, const string &text, int x, int y) { |
1514 | if (y<0) y = resY+y; |
1515 | SDL_Rect re = { static_cast<Sint16>(x), static_cast<Sint16>(y - 7), 0, 16 }; |
1516 | if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { |
1517 | sc["imgs/buttons/"+btn+".png"]->blit(s, x, y-7); |
1518 | re.w = sc["imgs/buttons/"+btn+".png"]->width() + 3; |
1519 | s->write(font, text, x+re.w, y, ASFont::HAlignLeft, ASFont::VAlignMiddle); |
1520 | re.w += font->getTextWidth(text); |
1521 | } |
1522 | return x+re.w+6; |
1523 | } |
1524 | |
1525 | int GMenu2X::drawButtonRight(Surface *s, const string &btn, const string &text, int x, int y) { |
1526 | if (y<0) y = resY+y; |
1527 | if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { |
1528 | x -= 16; |
1529 | sc["imgs/buttons/"+btn+".png"]->blit(s, x, y-7); |
1530 | x -= 3; |
1531 | s->write(font, text, x, y, ASFont::HAlignRight, ASFont::VAlignMiddle); |
1532 | return x-6-font->getTextWidth(text); |
1533 | } |
1534 | return x-6; |
1535 | } |
1536 | |
1537 | void GMenu2X::drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height) { |
1538 | if (totalsize<=pagesize) return; |
1539 | |
1540 | s->rectangle(resX-8, top, 7, height, skinConfColors[COLOR_SELECTION_BG]); |
1541 | |
1542 | //internal bar total height = height-2 |
1543 | //bar size |
1544 | uint bs = (height-2) * pagesize / totalsize; |
1545 | //bar y position |
1546 | uint by = (height-2) * pagepos / totalsize; |
1547 | by = top+2+by; |
1548 | if (by+bs>top+height-2) by = top+height-2-bs; |
1549 | |
1550 | |
1551 | s->box(resX-6, by, 3, bs, skinConfColors[COLOR_SELECTION_BG]); |
1552 | } |
1553 | |
1554 | void GMenu2X::drawTopBar(Surface *s) { |
1555 | if (s==NULL) s = this->s; |
1556 | |
1557 | Surface *bar = sc.skinRes("imgs/topbar.png", false); |
1558 | if (bar != NULL) |
1559 | bar->blit(s, 0, 0); |
1560 | else |
1561 | s->box(0, 0, resX, skinConfInt["topBarHeight"], |
1562 | skinConfColors[COLOR_TOP_BAR_BG]); |
1563 | } |
1564 | |
1565 | void GMenu2X::drawBottomBar(Surface *s) { |
1566 | if (s==NULL) s = this->s; |
1567 | |
1568 | Surface *bar = sc.skinRes("imgs/bottombar.png", false); |
1569 | if (bar != NULL) |
1570 | bar->blit(s, 0, resY-bar->height()); |
1571 | else |
1572 | s->box(0, resY-20, resX, 20, skinConfColors[COLOR_BOTTOM_BAR_BG]); |
1573 | } |
1574 |
Branches:
install_locations
master
opkrun
packages