diff options
author | Vojtech Bocek <vbocek@gmail.com> | 2013-07-25 22:53:02 +0200 |
---|---|---|
committer | Gerrit Code Review <gerrit@198.50.184.117> | 2013-08-24 14:56:48 +0200 |
commit | fafb0c541bb4b24515c57251a44d87825eec90fb (patch) | |
tree | 9cddb55ceef8912c8fafe618c98147ff6df19ef6 /gui | |
parent | Clean-up in partitions.hpp (diff) | |
download | android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.gz android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.bz2 android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.lz android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.xz android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.tar.zst android_bootable_recovery-fafb0c541bb4b24515c57251a44d87825eec90fb.zip |
Diffstat (limited to 'gui')
-rw-r--r-- | gui/action.cpp | 498 | ||||
-rw-r--r-- | gui/animation.cpp | 190 | ||||
-rw-r--r-- | gui/blanktimer.hpp | 54 | ||||
-rw-r--r-- | gui/button.cpp | 255 | ||||
-rw-r--r-- | gui/checkbox.cpp | 224 | ||||
-rw-r--r-- | gui/conditional.cpp | 260 | ||||
-rw-r--r-- | gui/console.cpp | 615 | ||||
-rw-r--r-- | gui/fileselector.cpp | 18 | ||||
-rw-r--r-- | gui/fill.cpp | 30 | ||||
-rw-r--r-- | gui/gui.cpp | 840 | ||||
-rw-r--r-- | gui/hardwarekeyboard.cpp | 19 | ||||
-rw-r--r-- | gui/image.cpp | 105 | ||||
-rw-r--r-- | gui/input.cpp | 106 | ||||
-rw-r--r-- | gui/listbox.cpp | 46 | ||||
-rw-r--r-- | gui/objects.hpp | 815 | ||||
-rw-r--r-- | gui/pages.cpp | 1191 | ||||
-rw-r--r-- | gui/pages.hpp | 128 | ||||
-rw-r--r-- | gui/partitionlist.cpp | 30 | ||||
-rw-r--r-- | gui/progressbar.cpp | 346 | ||||
-rw-r--r-- | gui/resources.cpp | 318 | ||||
-rw-r--r-- | gui/resources.hpp | 55 | ||||
-rw-r--r-- | gui/slider.cpp | 218 | ||||
-rw-r--r-- | gui/text.cpp | 260 |
23 files changed, 3327 insertions, 3294 deletions
diff --git a/gui/action.cpp b/gui/action.cpp index 3e1f793df..ee3373154 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -64,72 +64,72 @@ extern blanktimer blankTimer; void curtainClose(void); GUIAction::GUIAction(xml_node<>* node) - : Conditional(node) + : Conditional(node) { - xml_node<>* child; - xml_node<>* actions; - xml_attribute<>* attr; - - mKey = 0; - - if (!node) return; - - // First, get the action - actions = node->first_node("actions"); - if (actions) child = actions->first_node("action"); - else child = node->first_node("action"); - - if (!child) return; - - while (child) - { - Action action; - - attr = child->first_attribute("function"); - if (!attr) return; - - action.mFunction = attr->value(); - action.mArg = child->value(); - mActions.push_back(action); - - child = child->next_sibling("action"); - } - - // Now, let's get either the key or region - child = node->first_node("touch"); - if (child) - { - attr = child->first_attribute("key"); - if (attr) - { - std::string key = attr->value(); - - mKey = getKeyByName(key); - } - else - { - attr = child->first_attribute("x"); - if (!attr) return; - mActionX = atol(attr->value()); - attr = child->first_attribute("y"); - if (!attr) return; - mActionY = atol(attr->value()); - attr = child->first_attribute("w"); - if (!attr) return; - mActionW = atol(attr->value()); - attr = child->first_attribute("h"); - if (!attr) return; - mActionH = atol(attr->value()); - } - } + xml_node<>* child; + xml_node<>* actions; + xml_attribute<>* attr; + + mKey = 0; + + if (!node) return; + + // First, get the action + actions = node->first_node("actions"); + if (actions) child = actions->first_node("action"); + else child = node->first_node("action"); + + if (!child) return; + + while (child) + { + Action action; + + attr = child->first_attribute("function"); + if (!attr) return; + + action.mFunction = attr->value(); + action.mArg = child->value(); + mActions.push_back(action); + + child = child->next_sibling("action"); + } + + // Now, let's get either the key or region + child = node->first_node("touch"); + if (child) + { + attr = child->first_attribute("key"); + if (attr) + { + std::string key = attr->value(); + + mKey = getKeyByName(key); + } + else + { + attr = child->first_attribute("x"); + if (!attr) return; + mActionX = atol(attr->value()); + attr = child->first_attribute("y"); + if (!attr) return; + mActionY = atol(attr->value()); + attr = child->first_attribute("w"); + if (!attr) return; + mActionW = atol(attr->value()); + attr = child->first_attribute("h"); + if (!attr) return; + mActionH = atol(attr->value()); + } + } } int GUIAction::NotifyTouch(TOUCH_STATE state, int x, int y) { - if (state == TOUCH_RELEASE) - doActions(); + if (state == TOUCH_RELEASE) + doActions(); - return 0; + return 0; } int GUIAction::NotifyKey(int key) @@ -143,17 +143,17 @@ int GUIAction::NotifyKey(int key) int GUIAction::NotifyVarChange(std::string varName, std::string value) { - if (varName.empty() && !isConditionValid() && !mKey && !mActionW) - doActions(); + if (varName.empty() && !isConditionValid() && !mKey && !mActionW) + doActions(); - // This handles notifying the condition system of page start - if (varName.empty() && isConditionValid()) - NotifyPageSet(); + // This handles notifying the condition system of page start + if (varName.empty() && isConditionValid()) + NotifyPageSet(); - if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) - doActions(); + if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) + doActions(); - return 0; + return 0; } void GUIAction::simulate_progress_bar(void) @@ -168,54 +168,54 @@ void GUIAction::simulate_progress_bar(void) int GUIAction::flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache) { - int ret_val = 0; + int ret_val = 0; DataManager::SetValue("ui_progress", 0); - if (filename.empty()) - { - LOGERR("No file specified.\n"); - return -1; - } + if (filename.empty()) + { + LOGERR("No file specified.\n"); + return -1; + } - // We're going to jump to this page first, like a loading page - gui_changePage(pageName); + // We're going to jump to this page first, like a loading page + gui_changePage(pageName); - int fd = -1; - ZipArchive zip; + int fd = -1; + ZipArchive zip; - if (!PartitionManager.Mount_By_Path(filename, true)) + if (!PartitionManager.Mount_By_Path(filename, true)) return -1; if (mzOpenZipArchive(filename.c_str(), &zip)) - { - LOGERR("Unable to open zip file.\n"); - return -1; - } + { + LOGERR("Unable to open zip file.\n"); + return -1; + } - // Check the zip to see if it has a custom installer theme + // Check the zip to see if it has a custom installer theme const ZipEntry* twrp = mzFindZipEntry(&zip, "META-INF/teamwin/twrp.zip"); - if (twrp != NULL) - { - unlink("/tmp/twrp.zip"); - fd = creat("/tmp/twrp.zip", 0666); - } - if (fd >= 0 && twrp != NULL && - mzExtractZipEntryToFile(&zip, twrp, fd) && - !PageManager::LoadPackage("install", "/tmp/twrp.zip", "main")) - { - mzCloseZipArchive(&zip); + if (twrp != NULL) + { + unlink("/tmp/twrp.zip"); + fd = creat("/tmp/twrp.zip", 0666); + } + if (fd >= 0 && twrp != NULL && + mzExtractZipEntryToFile(&zip, twrp, fd) && + !PageManager::LoadPackage("install", "/tmp/twrp.zip", "main")) + { + mzCloseZipArchive(&zip); PageManager::SelectPackage("install"); - gui_changePage("main"); - } - else - { - // In this case, we just use the default page - mzCloseZipArchive(&zip); + gui_changePage("main"); + } + else + { + // In this case, we just use the default page + mzCloseZipArchive(&zip); gui_changePage(pageName); - } - if (fd >= 0) - close(fd); + } + if (fd >= 0) + close(fd); if (simulate) { simulate_progress_bar(); @@ -237,20 +237,20 @@ int GUIAction::flash_zip(std::string filename, std::string pageName, const int s } } - // Done - DataManager::SetValue("ui_progress", 100); - DataManager::SetValue("ui_progress", 0); - return ret_val; + // Done + DataManager::SetValue("ui_progress", 100); + DataManager::SetValue("ui_progress", 0); + return ret_val; } int GUIAction::doActions() { - if (mActions.size() < 1) return -1; - if (mActions.size() == 1) + if (mActions.size() < 1) return -1; + if (mActions.size() == 1) return doAction(mActions.at(0), 0); - // For multi-action, we always use a thread - pthread_t t; + // For multi-action, we always use a thread + pthread_t t; pthread_attr_t tattr; if (pthread_attr_init(&tattr)) { @@ -271,7 +271,7 @@ int GUIAction::doActions() } */ int ret = pthread_create(&t, &tattr, thread_start, this); - if (ret) { + if (ret) { LOGERR("Unable to create more threads for actions... continuing in same thread! %i\n", ret); thread_start(this); } else { @@ -284,30 +284,30 @@ int GUIAction::doActions() return -1; } - return 0; + return 0; } void* GUIAction::thread_start(void *cookie) { - GUIAction* ourThis = (GUIAction*) cookie; + GUIAction* ourThis = (GUIAction*) cookie; DataManager::SetValue(TW_ACTION_BUSY, 1); - if (ourThis->mActions.size() > 1) - { - std::vector<Action>::iterator iter; - for (iter = ourThis->mActions.begin(); iter != ourThis->mActions.end(); iter++) - ourThis->doAction(*iter, 1); - } - else - { - ourThis->doAction(ourThis->mActions.at(0), 1); - } + if (ourThis->mActions.size() > 1) + { + std::vector<Action>::iterator iter; + for (iter = ourThis->mActions.begin(); iter != ourThis->mActions.end(); iter++) + ourThis->doAction(*iter, 1); + } + else + { + ourThis->doAction(ourThis->mActions.at(0), 1); + } int check = 0; DataManager::GetValue("tw_background_thread_running", check); if (check == 0) DataManager::SetValue(TW_ACTION_BUSY, 0); - return NULL; + return NULL; } void GUIAction::operation_start(const string operation_name) @@ -357,7 +357,7 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) if (function == "reboot") { - //curtainClose(); this sometimes causes a crash + //curtainClose(); this sometimes causes a crash sync(); DataManager::SetValue("tw_gui_done", 1); @@ -365,25 +365,25 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) return 0; } - if (function == "home") - { - PageManager::SelectPackage("TWRP"); - gui_changePage("main"); - return 0; - } - - if (function == "key") - { - PageManager::NotifyKey(getKeyByName(arg)); - return 0; - } - - if (function == "page") { + if (function == "home") + { + PageManager::SelectPackage("TWRP"); + gui_changePage("main"); + return 0; + } + + if (function == "key") + { + PageManager::NotifyKey(getKeyByName(arg)); + return 0; + } + + if (function == "page") { std::string page_name = gui_parse_text(arg); - return gui_changePage(page_name); + return gui_changePage(page_name); } - if (function == "reload") { + if (function == "reload") { int check = 0, ret_val = 0; std::string theme_path; @@ -405,85 +405,85 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) ret_val = 1; } } - operation_end(ret_val, simulate); + operation_end(ret_val, simulate); return 0; } - if (function == "readBackup") - { + if (function == "readBackup") + { string Restore_Name; DataManager::GetValue("tw_restore", Restore_Name); PartitionManager.Set_Restore_Files(Restore_Name); - return 0; - } - - if (function == "set") - { - if (arg.find('=') != string::npos) - { - string varName = arg.substr(0, arg.find('=')); - string value = arg.substr(arg.find('=') + 1, string::npos); - - DataManager::GetValue(value, value); - DataManager::SetValue(varName, value); - } - else - DataManager::SetValue(arg, "1"); - return 0; - } - if (function == "clear") - { - DataManager::SetValue(arg, "0"); - return 0; - } - - if (function == "mount") - { - if (arg == "usb") - { - DataManager::SetValue(TW_ACTION_BUSY, 1); + return 0; + } + + if (function == "set") + { + if (arg.find('=') != string::npos) + { + string varName = arg.substr(0, arg.find('=')); + string value = arg.substr(arg.find('=') + 1, string::npos); + + DataManager::GetValue(value, value); + DataManager::SetValue(varName, value); + } + else + DataManager::SetValue(arg, "1"); + return 0; + } + if (function == "clear") + { + DataManager::SetValue(arg, "0"); + return 0; + } + + if (function == "mount") + { + if (arg == "usb") + { + DataManager::SetValue(TW_ACTION_BUSY, 1); if (!simulate) PartitionManager.usb_storage_enable(); else gui_print("Simulating actions...\n"); - } - else if (!simulate) - { - string cmd; + } + else if (!simulate) + { + string cmd; if (arg == "EXTERNAL") PartitionManager.Mount_By_Path(DataManager::GetStrValue(TW_EXTERNAL_MOUNT), true); else if (arg == "INTERNAL") PartitionManager.Mount_By_Path(DataManager::GetStrValue(TW_INTERNAL_MOUNT), true); else PartitionManager.Mount_By_Path(arg, true); - } else + } else gui_print("Simulating actions...\n"); - return 0; - } - - if (function == "umount" || function == "unmount") - { - if (arg == "usb") - { - if (!simulate) + return 0; + } + + if (function == "umount" || function == "unmount") + { + if (arg == "usb") + { + if (!simulate) PartitionManager.usb_storage_disable(); else gui_print("Simulating actions...\n"); DataManager::SetValue(TW_ACTION_BUSY, 0); - } - else if (!simulate) - { - string cmd; + } + else if (!simulate) + { + string cmd; if (arg == "EXTERNAL") PartitionManager.UnMount_By_Path(DataManager::GetStrValue(TW_EXTERNAL_MOUNT), true); else if (arg == "INTERNAL") PartitionManager.UnMount_By_Path(DataManager::GetStrValue(TW_INTERNAL_MOUNT), true); else PartitionManager.UnMount_By_Path(arg, true); - } else + } else gui_print("Simulating actions...\n"); - return 0; - } + return 0; + } if (function == "restoredefaultsettings") { @@ -519,20 +519,20 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) if (function == "compute" || function == "addsubtract") { if (arg.find("+") != string::npos) - { - string varName = arg.substr(0, arg.find('+')); - string string_to_add = arg.substr(arg.find('+') + 1, string::npos); + { + string varName = arg.substr(0, arg.find('+')); + string string_to_add = arg.substr(arg.find('+') + 1, string::npos); int amount_to_add = atoi(string_to_add.c_str()); int value; DataManager::GetValue(varName, value); - DataManager::SetValue(varName, value + amount_to_add); + DataManager::SetValue(varName, value + amount_to_add); return 0; - } + } if (arg.find("-") != string::npos) - { - string varName = arg.substr(0, arg.find('-')); - string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos); + { + string varName = arg.substr(0, arg.find('-')); + string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos); int amount_to_subtract = atoi(string_to_subtract.c_str()); int value; @@ -540,9 +540,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) value -= amount_to_subtract; if (value <= 0) value = 0; - DataManager::SetValue(varName, value); + DataManager::SetValue(varName, value); return 0; - } + } if (arg.find("*") != string::npos) { string varName = arg.substr(0, arg.find('*')); @@ -653,11 +653,11 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) } if (function == "overlay") - return gui_changeOverlay(arg); + return gui_changeOverlay(arg); if (function == "queuezip") - { - if (zip_queue_index >= 10) { + { + if (zip_queue_index >= 10) { gui_print("Maximum zip queue reached!\n"); return 0; } @@ -670,8 +670,8 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) } if (function == "cancelzip") - { - if (zip_queue_index <= 0) { + { + if (zip_queue_index <= 0) { gui_print("Minimum zip queue reached!\n"); return 0; } else { @@ -696,9 +696,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) return 0; } - if (isThreaded) - { - if (function == "fileexists") + if (isThreaded) + { + if (function == "fileexists") { struct stat st; string newpath = arg + "/."; @@ -712,13 +712,13 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) } if (function == "flash") - { + { int i, ret_val = 0, wipe_cache = 0; for (i=0; i<zip_queue_index; i++) { operation_start("Flashing"); - DataManager::SetValue("tw_filename", zip_queue[i]); - DataManager::SetValue(TW_ZIP_INDEX, (i + 1)); + DataManager::SetValue("tw_filename", zip_queue[i]); + DataManager::SetValue(TW_ZIP_INDEX, (i + 1)); ret_val = flash_zip(zip_queue[i], arg, simulate, &wipe_cache); if (ret_val != 0) { @@ -751,12 +751,12 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) } PartitionManager.Update_System_Details(); operation_end(ret_val, simulate); - return 0; - } - if (function == "wipe") - { - operation_start("Format"); - DataManager::SetValue("tw_partition", arg); + return 0; + } + if (function == "wipe") + { + operation_start("Format"); + DataManager::SetValue("tw_partition", arg); int ret_val = false; @@ -863,9 +863,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) ret_val = 0; // 0 is success else ret_val = 1; // 1 is failure - operation_end(ret_val, simulate); - return 0; - } + operation_end(ret_val, simulate); + return 0; + } if (function == "refreshsizes") { operation_start("Refreshing Sizes"); @@ -876,9 +876,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) operation_end(0, simulate); return 0; } - if (function == "nandroid") - { - operation_start("Nandroid"); + if (function == "nandroid") + { + operation_start("Nandroid"); int ret = 0; if (simulate) { @@ -910,13 +910,13 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) ret = 1; // 1 for failure else ret = 0; // 0 for success - operation_end(ret, simulate); + operation_end(ret, simulate); return 0; - } + } if (function == "fixpermissions") { operation_start("Fix Permissions"); - LOGINFO("fix permissions started!\n"); + LOGINFO("fix permissions started!\n"); if (simulate) { simulate_progress_bar(); } else { @@ -927,9 +927,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) } return 0; } - if (function == "dd") - { - operation_start("imaging"); + if (function == "dd") + { + operation_start("imaging"); if (simulate) { simulate_progress_bar(); @@ -938,9 +938,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) string cmd = "dd " + arg; TWFunc::Exec_Cmd(cmd, result); } - operation_end(0, simulate); - return 0; - } + operation_end(0, simulate); + return 0; + } if (function == "partitionsd") { operation_start("Partition SD Card"); @@ -1292,26 +1292,26 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) operation_end(op_status, simulate); return 0; } - } - else - { + } + else + { pthread_t t; pthread_create(&t, NULL, thread_start, this); - return 0; - } + return 0; + } LOGERR("Unknown action '%s'\n", function.c_str()); - return -1; + return -1; } int GUIAction::getKeyByName(std::string key) { - if (key == "home") return KEY_HOME; - else if (key == "menu") return KEY_MENU; - else if (key == "back") return KEY_BACK; - else if (key == "search") return KEY_SEARCH; - else if (key == "voldown") return KEY_VOLUMEDOWN; - else if (key == "volup") return KEY_VOLUMEUP; - else if (key == "power") { + if (key == "home") return KEY_HOME; + else if (key == "menu") return KEY_MENU; + else if (key == "back") return KEY_BACK; + else if (key == "search") return KEY_SEARCH; + else if (key == "voldown") return KEY_VOLUMEDOWN; + else if (key == "volup") return KEY_VOLUMEUP; + else if (key == "power") { int ret_val; DataManager::GetValue(TW_POWER_BUTTON, ret_val); if (!ret_val) @@ -1320,7 +1320,7 @@ int GUIAction::getKeyByName(std::string key) return ret_val; } - return atol(key.c_str()); + return atol(key.c_str()); } void* GUIAction::command_thread(void *cookie) diff --git a/gui/animation.cpp b/gui/animation.cpp index 77d7b54ad..8c922786d 100644 --- a/gui/animation.cpp +++ b/gui/animation.cpp @@ -28,109 +28,109 @@ extern "C" { GUIAnimation::GUIAnimation(xml_node<>* node) { - xml_node<>* child; - xml_attribute<>* attr; - - mAnimation = NULL; - mFrame = 1; - mFPS = 1; - mLoop = -1; - mRender = 1; - mUpdateCount = 0; - - if (!node) return; - - child = node->first_node("resource"); - if (child) - { - attr = child->first_attribute("name"); - if (attr) - mAnimation = (AnimationResource*) PageManager::FindResource(attr->value()); - } - - // Load the placement - LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement); - - child = node->first_node("speed"); - if (child) - { - attr = child->first_attribute("fps"); - if (attr) - mFPS = atoi(attr->value()); - attr = child->first_attribute("render"); - if (attr) - mRender = atoi(attr->value()); - } - if (mFPS > 30) mFPS = 30; - - child = node->first_node("loop"); - if (child) - { - attr = child->first_attribute("frame"); - if (attr) - mLoop = atoi(attr->value()) - 1; - attr = child->first_attribute("start"); - if (attr) - mFrame = atoi(attr->value()); - } - - // Fetch the render sizes - if (mAnimation && mAnimation->GetResource()) - { - mRenderW = gr_get_width(mAnimation->GetResource()); - mRenderH = gr_get_height(mAnimation->GetResource()); - - // Adjust for placement - if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT) - { - if (mPlacement == CENTER) - mRenderX -= (mRenderW / 2); - else - mRenderX -= mRenderW; - } - if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT) - { - if (mPlacement == CENTER) - mRenderY -= (mRenderH / 2); - else - mRenderY -= mRenderH; - } - SetPlacement(TOP_LEFT); - } + xml_node<>* child; + xml_attribute<>* attr; + + mAnimation = NULL; + mFrame = 1; + mFPS = 1; + mLoop = -1; + mRender = 1; + mUpdateCount = 0; + + if (!node) return; + + child = node->first_node("resource"); + if (child) + { + attr = child->first_attribute("name"); + if (attr) + mAnimation = (AnimationResource*) PageManager::FindResource(attr->value()); + } + + // Load the placement + LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement); + + child = node->first_node("speed"); + if (child) + { + attr = child->first_attribute("fps"); + if (attr) + mFPS = atoi(attr->value()); + attr = child->first_attribute("render"); + if (attr) + mRender = atoi(attr->value()); + } + if (mFPS > 30) mFPS = 30; + + child = node->first_node("loop"); + if (child) + { + attr = child->first_attribute("frame"); + if (attr) + mLoop = atoi(attr->value()) - 1; + attr = child->first_attribute("start"); + if (attr) + mFrame = atoi(attr->value()); + } + + // Fetch the render sizes + if (mAnimation && mAnimation->GetResource()) + { + mRenderW = gr_get_width(mAnimation->GetResource()); + mRenderH = gr_get_height(mAnimation->GetResource()); + + // Adjust for placement + if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT) + { + if (mPlacement == CENTER) + mRenderX -= (mRenderW / 2); + else + mRenderX -= mRenderW; + } + if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT) + { + if (mPlacement == CENTER) + mRenderY -= (mRenderH / 2); + else + mRenderY -= mRenderH; + } + SetPlacement(TOP_LEFT); + } } int GUIAnimation::Render(void) { - if (!mAnimation || !mAnimation->GetResource(mFrame)) return -1; + if (!mAnimation || !mAnimation->GetResource(mFrame)) return -1; - gr_blit(mAnimation->GetResource(mFrame), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); - return 0; + gr_blit(mAnimation->GetResource(mFrame), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); + return 0; } int GUIAnimation::Update(void) { - if (!mAnimation) return -1; - - // Handle the "end-of-animation" state - if (mLoop == -2) return 0; - - // Determine if we need the next frame yet... - if (++mUpdateCount > 30 / mFPS) - { - mUpdateCount = 0; - if (++mFrame >= mAnimation->GetResourceCount()) - { - if (mLoop < 0) - { - mFrame = mAnimation->GetResourceCount() - 1; - mLoop = -2; - } - else - mFrame = mLoop; - } - if (mRender == 2) return 2; - return (Render() == 0 ? 1 : -1); - } - return 0; + if (!mAnimation) return -1; + + // Handle the "end-of-animation" state + if (mLoop == -2) return 0; + + // Determine if we need the next frame yet... + if (++mUpdateCount > 30 / mFPS) + { + mUpdateCount = 0; + if (++mFrame >= mAnimation->GetResourceCount()) + { + if (mLoop < 0) + { + mFrame = mAnimation->GetResourceCount() - 1; + mLoop = -2; + } + else + mFrame = mLoop; + } + if (mRender == 2) return 2; + return (Render() == 0 ? 1 : -1); + } + return 0; } diff --git a/gui/blanktimer.hpp b/gui/blanktimer.hpp index 60d5b1b42..01c1dfb0c 100644 --- a/gui/blanktimer.hpp +++ b/gui/blanktimer.hpp @@ -24,31 +24,35 @@ using namespace std; -class blanktimer { - public: - blanktimer(void); - int setTimerThread(void); - void resetTimerAndUnblank(void); - void setTime(int newtime); - bool IsScreenOff(); - - private: - void setConBlank(int blank); - void setTimer(void); - timespec getTimer(void); - int getBrightness(void); - int setBrightness(int brightness); - int setBlankTimer(void); - int setClockTimer(void); - typedef int (blanktimer::*ThreadPtr)(void); - typedef void* (*PThreadPtr)(void*); - pthread_mutex_t conblankmutex; - pthread_mutex_t timermutex; - int conblank; - timespec btimer; - unsigned long long sleepTimer; - int orig_brightness; - bool screenoff; +class blanktimer +{ +public: + blanktimer(void); + + int setTimerThread(void); + void resetTimerAndUnblank(void); + void setTime(int newtime); + bool IsScreenOff(); + +private: + typedef int (blanktimer::*ThreadPtr)(void); + typedef void* (*PThreadPtr)(void*); + + void setConBlank(int blank); + void setTimer(void); + timespec getTimer(void); + int getBrightness(void); + int setBrightness(int brightness); + int setBlankTimer(void); + int setClockTimer(void); + + pthread_mutex_t conblankmutex; + pthread_mutex_t timermutex; + int conblank; + timespec btimer; + unsigned long long sleepTimer; + int orig_brightness; + bool screenoff; }; extern blanktimer blankTimer; diff --git a/gui/button.cpp b/gui/button.cpp index af7d07b8f..9fc85a052 100644 --- a/gui/button.cpp +++ b/gui/button.cpp @@ -42,42 +42,42 @@ extern "C" { #include "objects.hpp" GUIButton::GUIButton(xml_node<>* node) - : Conditional(node) + : Conditional(node) { - xml_attribute<>* attr; - xml_node<>* child; + xml_attribute<>* attr; + xml_node<>* child; - mButtonImg = NULL; - mButtonIcon = NULL; - mButtonLabel = NULL; - mAction = NULL; - mRendered = false; + mButtonImg = NULL; + mButtonIcon = NULL; + mButtonLabel = NULL; + mAction = NULL; + mRendered = false; hasHighlightColor = false; renderHighlight = false; hasFill = false; - if (!node) return; + if (!node) return; - // Three of the four can be loaded directly from the node - mButtonImg = new GUIImage(node); - mButtonLabel = new GUIText(node); - mAction = new GUIAction(node); + // Three of the four can be loaded directly from the node + mButtonImg = new GUIImage(node); + mButtonLabel = new GUIText(node); + mAction = new GUIAction(node); - if (mButtonImg->Render() < 0) - { - delete mButtonImg; - mButtonImg = NULL; - } - if (mButtonLabel->Render() < 0) - { - delete mButtonLabel; - mButtonLabel = NULL; - } + if (mButtonImg->Render() < 0) + { + delete mButtonImg; + mButtonImg = NULL; + } + if (mButtonLabel->Render() < 0) + { + delete mButtonLabel; + mButtonLabel = NULL; + } // Load fill if it exists memset(&mFillColor, 0, sizeof(COLOR)); child = node->first_node("fill"); - if (child) - { + if (child) + { attr = child->first_attribute("color"); if (attr) { hasFill = true; @@ -89,14 +89,14 @@ GUIButton::GUIButton(xml_node<>* node) LOGERR("No image resource or fill specified for button.\n"); } - // The icon is a special case - child = node->first_node("icon"); - if (child) - { - attr = child->first_attribute("resource"); - if (attr) - mButtonIcon = PageManager::FindResource(attr->value()); - } + // The icon is a special case + child = node->first_node("icon"); + if (child) + { + attr = child->first_attribute("resource"); + if (attr) + mButtonIcon = PageManager::FindResource(attr->value()); + } memset(&mHighlightColor, 0, sizeof(COLOR)); child = node->first_node("highlight"); @@ -109,43 +109,43 @@ GUIButton::GUIButton(xml_node<>* node) } } - int x, y, w, h; - if (mButtonImg) { + int x, y, w, h; + if (mButtonImg) { mButtonImg->GetRenderPos(x, y, w, h); } else if (hasFill) { LoadPlacement(node->first_node("placement"), &x, &y, &w, &h); } SetRenderPos(x, y, w, h); - return; + return; } GUIButton::~GUIButton() { - if (mButtonImg) delete mButtonImg; - if (mButtonLabel) delete mButtonLabel; - if (mAction) delete mAction; - if (mButtonIcon) delete mButtonIcon; + if (mButtonImg) delete mButtonImg; + if (mButtonLabel) delete mButtonLabel; + if (mAction) delete mAction; + if (mButtonIcon) delete mButtonIcon; } int GUIButton::Render(void) { - if (!isConditionTrue()) - { - mRendered = false; - return 0; - } + if (!isConditionTrue()) + { + mRendered = false; + return 0; + } - int ret = 0; + int ret = 0; - if (mButtonImg) ret = mButtonImg->Render(); - if (ret < 0) return ret; + if (mButtonImg) ret = mButtonImg->Render(); + if (ret < 0) return ret; if (hasFill) { gr_color(mFillColor.red, mFillColor.green, mFillColor.blue, mFillColor.alpha); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); } - if (mButtonIcon && mButtonIcon->GetResource()) - gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); - if (mButtonLabel) { + if (mButtonIcon && mButtonIcon->GetResource()) + gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); + if (mButtonLabel) { int w, h; mButtonLabel->GetCurrentBounds(w, h); if (w != mTextW) { @@ -163,109 +163,109 @@ int GUIButton::Render(void) mButtonLabel->SetRenderPos(mTextX, mTextY); } ret = mButtonLabel->Render(); - if (ret < 0) return ret; + if (ret < 0) return ret; } if (renderHighlight && hasHighlightColor) { gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); } - mRendered = true; - return ret; + mRendered = true; + return ret; } int GUIButton::Update(void) { - if (!isConditionTrue()) return (mRendered ? 2 : 0); - if (!mRendered) return 2; + if (!isConditionTrue()) return (mRendered ? 2 : 0); + if (!mRendered) return 2; - int ret = 0, ret2 = 0; + int ret = 0, ret2 = 0; - if (mButtonImg) ret = mButtonImg->Update(); - if (ret < 0) return ret; + if (mButtonImg) ret = mButtonImg->Update(); + if (ret < 0) return ret; - if (ret == 0) - { - if (mButtonLabel) { + if (ret == 0) + { + if (mButtonLabel) { ret2 = mButtonLabel->Update(); - if (ret2 < 0) return ret2; - if (ret2 > ret) ret = ret2; + if (ret2 < 0) return ret2; + if (ret2 > ret) ret = ret2; } - } - else if (ret == 1) - { - // The button re-rendered, so everyone else is a render - if (mButtonIcon && mButtonIcon->GetResource()) - gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); - if (mButtonLabel) ret = mButtonLabel->Render(); - if (ret < 0) return ret; - ret = 1; - } - else - { - // Aparently, the button needs a background update - ret = 2; - } - return ret; + } + else if (ret == 1) + { + // The button re-rendered, so everyone else is a render + if (mButtonIcon && mButtonIcon->GetResource()) + gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY); + if (mButtonLabel) ret = mButtonLabel->Render(); + if (ret < 0) return ret; + ret = 1; + } + else + { + // Aparently, the button needs a background update + ret = 2; + } + return ret; } int GUIButton::SetRenderPos(int x, int y, int w, int h) { - mRenderX = x; - mRenderY = y; - if (w || h) - { - mRenderW = w; - mRenderH = h; - } + mRenderX = x; + mRenderY = y; + if (w || h) + { + mRenderW = w; + mRenderH = h; + } - mIconW = 0; mIconH = 0; - if (mButtonIcon && mButtonIcon->GetResource()) - { - mIconW = gr_get_width(mButtonIcon->GetResource()); - mIconH = gr_get_height(mButtonIcon->GetResource()); - } + mIconW = 0; mIconH = 0; + if (mButtonIcon && mButtonIcon->GetResource()) + { + mIconW = gr_get_width(mButtonIcon->GetResource()); + mIconH = gr_get_height(mButtonIcon->GetResource()); + } - mTextH = 0; - mTextW = 0; - mIconX = mRenderX + ((mRenderW - mIconW) / 2); - if (mButtonLabel) mButtonLabel->GetCurrentBounds(mTextW, mTextH); - if (mTextW) - { - // As a special case, we'll allow large text which automatically moves it to the right. - if (mTextW > mRenderW) - { - mTextX = mRenderW + mRenderX + 5; - mRenderW += mTextW + 5; - } - else - { - mTextX = mRenderX + ((mRenderW - mTextW) / 2); - } - } + mTextH = 0; + mTextW = 0; + mIconX = mRenderX + ((mRenderW - mIconW) / 2); + if (mButtonLabel) mButtonLabel->GetCurrentBounds(mTextW, mTextH); + if (mTextW) + { + // As a special case, we'll allow large text which automatically moves it to the right. + if (mTextW > mRenderW) + { + mTextX = mRenderW + mRenderX + 5; + mRenderW += mTextW + 5; + } + else + { + mTextX = mRenderX + ((mRenderW - mTextW) / 2); + } + } - if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH) - { - mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2); - mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2); - } - else - { - int divisor = mRenderH - (mIconH + mTextH); - mIconY = mRenderY + (divisor / 3); - mTextY = mRenderY + (divisor * 2 / 3) + mIconH; - } + if (mIconH == 0 || mTextH == 0 || mIconH + mTextH > mRenderH) + { + mIconY = mRenderY + (mRenderH / 2) - (mIconH / 2); + mTextY = mRenderY + (mRenderH / 2) - (mTextH / 2); + } + else + { + int divisor = mRenderH - (mIconH + mTextH); + mIconY = mRenderY + (divisor / 3); + mTextY = mRenderY + (divisor * 2 / 3) + mIconH; + } - if (mButtonLabel) mButtonLabel->SetRenderPos(mTextX, mTextY); - if (mAction) mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); - SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); - return 0; + if (mButtonLabel) mButtonLabel->SetRenderPos(mTextX, mTextY); + if (mAction) mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); + SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); + return 0; } int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y) { static int last_state = 0; - if (!isConditionTrue()) return -1; + if (!isConditionTrue()) return -1; if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH || state == TOUCH_RELEASE) { if (last_state == 1) { last_state = 0; @@ -289,6 +289,5 @@ int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y) } if (x < mRenderX || x - mRenderX > mRenderW || y < mRenderY || y - mRenderY > mRenderH) return 0; - return (mAction ? mAction->NotifyTouch(state, x, y) : 1); + return (mAction ? mAction->NotifyTouch(state, x, y) : 1); } - diff --git a/gui/checkbox.cpp b/gui/checkbox.cpp index 077d5e2dc..b6d5e6348 100644 --- a/gui/checkbox.cpp +++ b/gui/checkbox.cpp @@ -26,63 +26,64 @@ extern "C" { #include "objects.hpp" GUICheckbox::GUICheckbox(xml_node<>* node) - : Conditional(node) + : Conditional(node) { - xml_attribute<>* attr; - xml_node<>* child; - - mChecked = NULL; - mUnchecked = NULL; - mLabel = NULL; - mRendered = false; - - mLastState = 0; - - if (!node) return; - - // The label can be loaded directly - mLabel = new GUIText(node); - - // Read the check states - child = node->first_node("image"); - if (child) - { - attr = child->first_attribute("checked"); - if (attr) - mChecked = PageManager::FindResource(attr->value()); - attr = child->first_attribute("unchecked"); - if (attr) - mUnchecked = PageManager::FindResource(attr->value()); - } - - // Get the variable data - child = node->first_node("data"); - if (child) - { - attr = child->first_attribute("variable"); - if (attr) - mVarName = attr->value(); - attr = child->first_attribute("default"); - if (attr) - DataManager::SetValue(mVarName, attr->value()); - } - - mCheckW = 0; mCheckH = 0; - if (mChecked && mChecked->GetResource()) - { - mCheckW = gr_get_width(mChecked->GetResource()); - mCheckH = gr_get_height(mChecked->GetResource()); - } - else if (mUnchecked && mUnchecked->GetResource()) - { - mCheckW = gr_get_width(mUnchecked->GetResource()); - mCheckH = gr_get_height(mUnchecked->GetResource()); - } - - int x, y, w, h; - mLabel->GetRenderPos(x, y, w, h); - SetRenderPos(x, y, 0, 0); - return; + xml_attribute<>* attr; + xml_node<>* child; + + mChecked = NULL; + mUnchecked = NULL; + mLabel = NULL; + mRendered = false; + + mLastState = 0; + + if (!node) + return; + + // The label can be loaded directly + mLabel = new GUIText(node); + + // Read the check states + child = node->first_node("image"); + if (child) + { + attr = child->first_attribute("checked"); + if (attr) + mChecked = PageManager::FindResource(attr->value()); + attr = child->first_attribute("unchecked"); + if (attr) + mUnchecked = PageManager::FindResource(attr->value()); + } + + // Get the variable data + child = node->first_node("data"); + if (child) + { + attr = child->first_attribute("variable"); + if (attr) + mVarName = attr->value(); + attr = child->first_attribute("default"); + if (attr) + DataManager::SetValue(mVarName, attr->value()); + } + + mCheckW = 0; mCheckH = 0; + if (mChecked && mChecked->GetResource()) + { + mCheckW = gr_get_width(mChecked->GetResource()); + mCheckH = gr_get_height(mChecked->GetResource()); + } + else if (mUnchecked && mUnchecked->GetResource()) + { + mCheckW = gr_get_width(mUnchecked->GetResource()); + mCheckH = gr_get_height(mUnchecked->GetResource()); + } + + int x, y, w, h; + mLabel->GetRenderPos(x, y, w, h); + SetRenderPos(x, y, 0, 0); + return; } GUICheckbox::~GUICheckbox() @@ -91,78 +92,81 @@ GUICheckbox::~GUICheckbox() int GUICheckbox::Render(void) { - if (!isConditionTrue()) - { - mRendered = false; - return 0; - } - - int ret = 0; - int lastState = 0; - DataManager::GetValue(mVarName, lastState); - - if (lastState) - { - if (mChecked && mChecked->GetResource()) - gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY); - } - else - { - if (mUnchecked && mUnchecked->GetResource()) - gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY); - } - if (mLabel) ret = mLabel->Render(); - mLastState = lastState; - mRendered = true; - return ret; + if (!isConditionTrue()) + { + mRendered = false; + return 0; + } + + int ret = 0; + int lastState = 0; + DataManager::GetValue(mVarName, lastState); + + if (lastState) + { + if (mChecked && mChecked->GetResource()) + gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY); + } + else + { + if (mUnchecked && mUnchecked->GetResource()) + gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY); + } + if (mLabel) + ret = mLabel->Render(); + mLastState = lastState; + mRendered = true; + return ret; } int GUICheckbox::Update(void) { - if (!isConditionTrue()) return (mRendered ? 2 : 0); - if (!mRendered) return 2; + if (!isConditionTrue()) return (mRendered ? 2 : 0); + if (!mRendered) return 2; - int lastState = 0; - DataManager::GetValue(mVarName, lastState); + int lastState = 0; + DataManager::GetValue(mVarName, lastState); - if (lastState != mLastState) - return 2; - return 0; + if (lastState != mLastState) + return 2; + return 0; } int GUICheckbox::SetRenderPos(int x, int y, int w, int h) { - mRenderX = x; - mRenderY = y; + mRenderX = x; + mRenderY = y; - if (w || h) return -1; + if (w || h) + return -1; - int textW, textH; - mLabel->GetCurrentBounds(textW, textH); + int textW, textH; + mLabel->GetCurrentBounds(textW, textH); - w = textW + mCheckW + 5; - mRenderW = w; - mRenderH = mCheckH; + w = textW + mCheckW + 5; + mRenderW = w; + mRenderH = mCheckH; - mTextX = mRenderX + mCheckW + 5; - mTextY = mRenderY + ((mCheckH / 2) - (textH / 2)); + mTextX = mRenderX + mCheckW + 5; + mTextY = mRenderY + ((mCheckH / 2) - (textH / 2)); - mLabel->SetRenderPos(mTextX, mTextY, 0, 0); - SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); - return 0; + mLabel->SetRenderPos(mTextX, mTextY, 0, 0); + SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); + return 0; } int GUICheckbox::NotifyTouch(TOUCH_STATE state, int x, int y) { - if (!isConditionTrue()) return -1; - - if (state == TOUCH_RELEASE) - { - int lastState; - DataManager::GetValue(mVarName, lastState); - lastState = (lastState == 0) ? 1 : 0; - DataManager::SetValue(mVarName, lastState); - } - return 0; + if (!isConditionTrue()) + return -1; + + if (state == TOUCH_RELEASE) + { + int lastState; + DataManager::GetValue(mVarName, lastState); + lastState = (lastState == 0) ? 1 : 0; + DataManager::SetValue(mVarName, lastState); + } + return 0; } diff --git a/gui/conditional.cpp b/gui/conditional.cpp index b3aba2d0c..5ea8d176c 100644 --- a/gui/conditional.cpp +++ b/gui/conditional.cpp @@ -29,153 +29,156 @@ extern "C" { Conditional::Conditional(xml_node<>* node) { - // Break out early, it's too hard to check if valid every step - if (!node) return; + // Break out early, it's too hard to check if valid every step + if (!node) return; - // First, get the action - xml_node<>* condition = node->first_node("conditions"); - if (condition) condition = condition->first_node("condition"); - else condition = node->first_node("condition"); + // First, get the action + xml_node<>* condition = node->first_node("conditions"); + if (condition) condition = condition->first_node("condition"); + else condition = node->first_node("condition"); - if (!condition) return; + if (!condition) return; - while (condition) - { - Condition cond; + while (condition) + { + Condition cond; - cond.mCompareOp = "="; + cond.mCompareOp = "="; - xml_attribute<>* attr; - attr = condition->first_attribute("var1"); - if (attr) cond.mVar1 = attr->value(); + xml_attribute<>* attr; + attr = condition->first_attribute("var1"); + if (attr) cond.mVar1 = attr->value(); - attr = condition->first_attribute("op"); - if (attr) cond.mCompareOp = attr->value(); + attr = condition->first_attribute("op"); + if (attr) cond.mCompareOp = attr->value(); - attr = condition->first_attribute("var2"); - if (attr) cond.mVar2 = attr->value(); - - mConditions.push_back(cond); + attr = condition->first_attribute("var2"); + if (attr) cond.mVar2 = attr->value(); + + mConditions.push_back(cond); - condition = condition->next_sibling("condition"); - } + condition = condition->next_sibling("condition"); + } } bool Conditional::IsConditionVariable(std::string var) { - std::vector<Condition>::iterator iter; - for (iter = mConditions.begin(); iter != mConditions.end(); iter++) - { - if (iter->mVar1 == var) return true; - } - return false; + std::vector<Condition>::iterator iter; + for (iter = mConditions.begin(); iter != mConditions.end(); iter++) + { + if (iter->mVar1 == var) + return true; + } + return false; } bool Conditional::isConditionTrue() { - std::vector<Condition>::iterator iter; - for (iter = mConditions.begin(); iter != mConditions.end(); iter++) - { - if (!isConditionTrue(&(*iter))) return false; - } - return true; + std::vector<Condition>::iterator iter; + for (iter = mConditions.begin(); iter != mConditions.end(); iter++) + { + if (!isConditionTrue(&(*iter))) + return false; + } + return true; } bool Conditional::isConditionTrue(Condition* condition) { - // This is used to hold the proper value of "true" based on the '!' NOT flag - bool bTrue = true; - - if (condition->mVar1.empty()) return bTrue; - - if (!condition->mCompareOp.empty() && condition->mCompareOp[0] == '!') - bTrue = false; - - if (condition->mVar2.empty() && condition->mCompareOp != "modified") - { - if (!DataManager::GetStrValue(condition->mVar1).empty()) - return bTrue; - - return !bTrue; - } - - string var1, var2; - if (DataManager::GetValue(condition->mVar1, var1)) - var1 = condition->mVar1; - if (DataManager::GetValue(condition->mVar2, var2)) - var2 = condition->mVar2; - - // This is a special case, we stat the file and that determines our result - if (var1 == "fileexists") - { - struct stat st; - if (stat(var2.c_str(), &st) == 0) - var2 = var1; - else - var2 = "FAILED"; - } - if (var1 == "mounted") - { - if (isMounted(condition->mVar2)) - var2 = var1; - else - var2 = "FAILED"; - } - - if (condition->mCompareOp.find('=') != string::npos && var1 == var2) - return bTrue; - - if (condition->mCompareOp.find('>') != string::npos && (atof(var1.c_str()) > atof(var2.c_str()))) - return bTrue; - - if (condition->mCompareOp.find('<') != string::npos && (atof(var1.c_str()) < atof(var2.c_str()))) - return bTrue; - - if (condition->mCompareOp == "modified") - { - // This is a hack to allow areas to reset the default value - if (var1.empty()) - { - condition->mLastVal = var1; - return !bTrue; - } - - if (var1 != condition->mLastVal) - return bTrue; - } - - return !bTrue; + // This is used to hold the proper value of "true" based on the '!' NOT flag + bool bTrue = true; + + if (condition->mVar1.empty()) + return bTrue; + + if (!condition->mCompareOp.empty() && condition->mCompareOp[0] == '!') + bTrue = false; + + if (condition->mVar2.empty() && condition->mCompareOp != "modified") + { + if (!DataManager::GetStrValue(condition->mVar1).empty()) + return bTrue; + + return !bTrue; + } + + string var1, var2; + if (DataManager::GetValue(condition->mVar1, var1)) + var1 = condition->mVar1; + if (DataManager::GetValue(condition->mVar2, var2)) + var2 = condition->mVar2; + + // This is a special case, we stat the file and that determines our result + if (var1 == "fileexists") + { + struct stat st; + if (stat(var2.c_str(), &st) == 0) + var2 = var1; + else + var2 = "FAILED"; + } + if (var1 == "mounted") + { + if (isMounted(condition->mVar2)) + var2 = var1; + else + var2 = "FAILED"; + } + + if (condition->mCompareOp.find('=') != string::npos && var1 == var2) + return bTrue; + + if (condition->mCompareOp.find('>') != string::npos && (atof(var1.c_str()) > atof(var2.c_str()))) + return bTrue; + + if (condition->mCompareOp.find('<') != string::npos && (atof(var1.c_str()) < atof(var2.c_str()))) + return bTrue; + + if (condition->mCompareOp == "modified") + { + // This is a hack to allow areas to reset the default value + if (var1.empty()) + { + condition->mLastVal = var1; + return !bTrue; + } + + if (var1 != condition->mLastVal) + return bTrue; + } + + return !bTrue; } bool Conditional::isConditionValid() { - return !mConditions.empty(); + return !mConditions.empty(); } void Conditional::NotifyPageSet() { - std::vector<Condition>::iterator iter; - for (iter = mConditions.begin(); iter != mConditions.end(); iter++) - { - if (iter->mCompareOp == "modified") - { - string val; - - // If this fails, val will not be set, which is perfect - if (DataManager::GetValue(iter->mVar1, val)) - { - DataManager::SetValue(iter->mVar1, ""); - DataManager::GetValue(iter->mVar1, val); - } - iter->mLastVal = val; - } - } + std::vector<Condition>::iterator iter; + for (iter = mConditions.begin(); iter != mConditions.end(); iter++) + { + if (iter->mCompareOp == "modified") + { + string val; + + // If this fails, val will not be set, which is perfect + if (DataManager::GetValue(iter->mVar1, val)) + { + DataManager::SetValue(iter->mVar1, ""); + DataManager::GetValue(iter->mVar1, val); + } + iter->mLastVal = val; + } + } } bool Conditional::isMounted(string vol) { FILE *fp; - char tmpOutput[255]; + char tmpOutput[255]; if (strcmp(vol.c_str(), "EXTERNAL") == 0) DataManager::GetValue(TW_EXTERNAL_MOUNT, vol); @@ -184,19 +187,18 @@ bool Conditional::isMounted(string vol) fp = fopen("/proc/mounts", "rt"); while (fgets(tmpOutput,255,fp) != NULL) { - char* mnt = tmpOutput; - while (*mnt > 32) mnt++; - while (*mnt > 0 && *mnt <= 32) mnt++; - char* pos = mnt; - while (*pos > 32) pos++; - *pos = 0; - if (vol == mnt) - { - fclose(fp); - return true; - } - } - fclose(fp); - return false; + char* mnt = tmpOutput; + while (*mnt > 32) mnt++; + while (*mnt > 0 && *mnt <= 32) mnt++; + char* pos = mnt; + while (*pos > 32) pos++; + *pos = 0; + if (vol == mnt) + { + fclose(fp); + return true; + } + } + fclose(fp); + return false; } - diff --git a/gui/console.cpp b/gui/console.cpp index ee3b5e580..517a7c293 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -30,373 +30,374 @@ static std::vector<std::string> gConsole; extern "C" void gui_print(const char *fmt, ...) { - char buf[512]; // We're going to limit a single request to 512 bytes + char buf[512]; // We're going to limit a single request to 512 bytes - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, 512, fmt, ap); - va_end(ap); + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, 512, fmt, ap); + va_end(ap); fputs(buf, stdout); - char *start, *next; + char *start, *next; if (buf[0] == '\n' && strlen(buf) < 2) { // This prevents the double lines bug seen in the console during zip installs return; } - for (start = next = buf; *next != '\0'; next++) - { - if (*next == '\n') - { - *next = '\0'; - next++; + for (start = next = buf; *next != '\0'; next++) + { + if (*next == '\n') + { + *next = '\0'; + next++; - std::string line = start; - gConsole.push_back(line); - start = next; + std::string line = start; + gConsole.push_back(line); + start = next; // Handle the normal \n\0 case - if (*next == '\0') + if (*next == '\0') return; - } - } - std::string line = start; - gConsole.push_back(line); - return; + } + } + std::string line = start; + gConsole.push_back(line); + return; } extern "C" void gui_print_overwrite(const char *fmt, ...) { - char buf[512]; // We're going to limit a single request to 512 bytes + char buf[512]; // We're going to limit a single request to 512 bytes - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, 512, fmt, ap); - va_end(ap); + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, 512, fmt, ap); + va_end(ap); fputs(buf, stdout); - // Pop the last line, and we can continue - if (!gConsole.empty()) gConsole.pop_back(); - - char *start, *next; - for (start = next = buf; *next != '\0'; next++) - { - if (*next == '\n') - { - *next = '\0'; - next++; - - std::string line = start; - gConsole.push_back(line); - start = next; - - // Handle the normal \n\0 case - if (*next == '\0') + // Pop the last line, and we can continue + if (!gConsole.empty()) gConsole.pop_back(); + + char *start, *next; + for (start = next = buf; *next != '\0'; next++) + { + if (*next == '\n') + { + *next = '\0'; + next++; + + std::string line = start; + gConsole.push_back(line); + start = next; + + // Handle the normal \n\0 case + if (*next == '\0') return; - } - } - std::string line = start; - gConsole.push_back(line); - return; + } + } + std::string line = start; + gConsole.push_back(line); + return; } GUIConsole::GUIConsole(xml_node<>* node) { - xml_attribute<>* attr; - xml_node<>* child; - - mFont = NULL; - mCurrentLine = -1; - memset(&mForegroundColor, 255, sizeof(COLOR)); - memset(&mBackgroundColor, 0, sizeof(COLOR)); - mBackgroundColor.alpha = 255; - memset(&mScrollColor, 0x08, sizeof(COLOR)); - mScrollColor.alpha = 255; - mLastCount = 0; - mSlideout = 0; - mSlideoutState = hidden; - - mRenderX = 0; mRenderY = 0; mRenderW = gr_fb_width(); mRenderH = gr_fb_height(); - - if (!node) - { - mSlideoutX = 0; mSlideoutY = 0; mSlideoutW = 0; mSlideoutH = 0; - mConsoleX = 0; mConsoleY = 0; mConsoleW = gr_fb_width(); mConsoleH = gr_fb_height(); - } - else - { - child = node->first_node("font"); - if (child) - { - attr = child->first_attribute("resource"); - if (attr) - mFont = PageManager::FindResource(attr->value()); - } - - child = node->first_node("color"); - if (child) - { - attr = child->first_attribute("foreground"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mForegroundColor); - } - attr = child->first_attribute("background"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mBackgroundColor); - } - attr = child->first_attribute("scroll"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mScrollColor); - } - } - - // Load the placement - LoadPlacement(node->first_node("placement"), &mConsoleX, &mConsoleY, &mConsoleW, &mConsoleH); - - child = node->first_node("slideout"); - if (child) - { - mSlideout = 1; - LoadPlacement(child, &mSlideoutX, &mSlideoutY); - - attr = child->first_attribute("resource"); - if (attr) mSlideoutImage = PageManager::FindResource(attr->value()); - - if (mSlideoutImage && mSlideoutImage->GetResource()) - { - mSlideoutW = gr_get_width(mSlideoutImage->GetResource()); - mSlideoutH = gr_get_height(mSlideoutImage->GetResource()); - } - } - } - - gr_getFontDetails(mFont, &mFontHeight, NULL); - SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); - SetRenderPos(mConsoleX, mConsoleY); - return; + xml_attribute<>* attr; + xml_node<>* child; + + mFont = NULL; + mCurrentLine = -1; + memset(&mForegroundColor, 255, sizeof(COLOR)); + memset(&mBackgroundColor, 0, sizeof(COLOR)); + mBackgroundColor.alpha = 255; + memset(&mScrollColor, 0x08, sizeof(COLOR)); + mScrollColor.alpha = 255; + mLastCount = 0; + mSlideout = 0; + mSlideoutState = hidden; + + mRenderX = 0; mRenderY = 0; mRenderW = gr_fb_width(); mRenderH = gr_fb_height(); + + if (!node) + { + mSlideoutX = 0; mSlideoutY = 0; mSlideoutW = 0; mSlideoutH = 0; + mConsoleX = 0; mConsoleY = 0; mConsoleW = gr_fb_width(); mConsoleH = gr_fb_height(); + } + else + { + child = node->first_node("font"); + if (child) + { + attr = child->first_attribute("resource"); + if (attr) + mFont = PageManager::FindResource(attr->value()); + } + + child = node->first_node("color"); + if (child) + { + attr = child->first_attribute("foreground"); + if (attr) + { + std::string color = attr->value(); + ConvertStrToColor(color, &mForegroundColor); + } + attr = child->first_attribute("background"); + if (attr) + { + std::string color = attr->value(); + ConvertStrToColor(color, &mBackgroundColor); + } + attr = child->first_attribute("scroll"); + if (attr) + { + std::string color = attr->value(); + ConvertStrToColor(color, &mScrollColor); + } + } + + // Load the placement + LoadPlacement(node->first_node("placement"), &mConsoleX, &mConsoleY, &mConsoleW, &mConsoleH); + + child = node->first_node("slideout"); + if (child) + { + mSlideout = 1; + LoadPlacement(child, &mSlideoutX, &mSlideoutY); + + attr = child->first_attribute("resource"); + if (attr) mSlideoutImage = PageManager::FindResource(attr->value()); + + if (mSlideoutImage && mSlideoutImage->GetResource()) + { + mSlideoutW = gr_get_width(mSlideoutImage->GetResource()); + mSlideoutH = gr_get_height(mSlideoutImage->GetResource()); + } + } + } + + gr_getFontDetails(mFont, &mFontHeight, NULL); + SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); + SetRenderPos(mConsoleX, mConsoleY); + return; } int GUIConsole::RenderSlideout(void) { - if (!mSlideoutImage || !mSlideoutImage->GetResource()) return -1; + if (!mSlideoutImage || !mSlideoutImage->GetResource()) + return -1; - gr_blit(mSlideoutImage->GetResource(), 0, 0, mSlideoutW, mSlideoutH, mSlideoutX, mSlideoutY); - return 0; + gr_blit(mSlideoutImage->GetResource(), 0, 0, mSlideoutW, mSlideoutH, mSlideoutX, mSlideoutY); + return 0; } int GUIConsole::RenderConsole(void) { - void* fontResource = NULL; - if (mFont) fontResource = mFont->GetResource(); - - // We fill the background - gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); - gr_fill(mConsoleX, mConsoleY, mConsoleW, mConsoleH); - - gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha); - gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH); - - // Render the lines - gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha); - - // Don't try to continue to render without data - mLastCount = gConsole.size(); - if (mLastCount == 0) return (mSlideout ? RenderSlideout() : 0); - - // Find the start point - int start; - int curLine = mCurrentLine; // Thread-safing (Another thread updates this value) - if (curLine == -1) - { - start = mLastCount - mMaxRows; - } - else - { - if (curLine > (int) mLastCount) curLine = (int) mLastCount; - if ((int) mMaxRows > curLine) curLine = (int) mMaxRows; - start = curLine - mMaxRows; - } - - unsigned int line; - for (line = 0; line < mMaxRows; line++) - { - if ((start + (int) line) >= 0 && (start + (int) line) < (int) mLastCount) - { - gr_textExW(mConsoleX, mStartY + (line * mFontHeight), gConsole[start + line].c_str(), fontResource, mConsoleW + mConsoleX); - } - } - return (mSlideout ? RenderSlideout() : 0); + void* fontResource = NULL; + if (mFont) + fontResource = mFont->GetResource(); + + // We fill the background + gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); + gr_fill(mConsoleX, mConsoleY, mConsoleW, mConsoleH); + + gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha); + gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH); + + // Render the lines + gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha); + + // Don't try to continue to render without data + mLastCount = gConsole.size(); + if (mLastCount == 0) + return (mSlideout ? RenderSlideout() : 0); + + // Find the start point + int start; + int curLine = mCurrentLine; // Thread-safing (Another thread updates this value) + if (curLine == -1) + { + start = mLastCount - mMaxRows; + } + else + { + if (curLine > (int) mLastCount) + curLine = (int) mLastCount; + if ((int) mMaxRows > curLine) + curLine = (int) mMaxRows; + start = curLine - mMaxRows; + } + + unsigned int line; + for (line = 0; line < mMaxRows; line++) + { + if ((start + (int) line) >= 0 && (start + (int) line) < (int) mLastCount) + gr_textExW(mConsoleX, mStartY + (line * mFontHeight), gConsole[start + line].c_str(), fontResource, mConsoleW + mConsoleX); + } + return (mSlideout ? RenderSlideout() : 0); } int GUIConsole::Render(void) { - if (mSlideout && mSlideoutState == hidden) - { - return RenderSlideout(); - } - return RenderConsole(); + if (mSlideout && mSlideoutState == hidden) + return RenderSlideout(); + + return RenderConsole(); } int GUIConsole::Update(void) { - if (mSlideout && mSlideoutState != visible) - { - if (mSlideoutState == hidden) - return 0; - - if (mSlideoutState == request_hide) - mSlideoutState = hidden; - - if (mSlideoutState == request_show) - mSlideoutState = visible; - - // Any time we activate the slider, we reset the position - mCurrentLine = -1; - return 2; - } - - if (mCurrentLine == -1 && mLastCount != gConsole.size()) - { - // We can use Render, and return for just a flip - Render(); - return 2; - } - else if (mLastTouchY >= 0) - { - // They're still touching, so re-render - Render(); - mLastTouchY = -1; - return 2; - } - return 0; + if (mSlideout && mSlideoutState != visible) + { + if (mSlideoutState == hidden) + return 0; + + if (mSlideoutState == request_hide) + mSlideoutState = hidden; + + if (mSlideoutState == request_show) + mSlideoutState = visible; + + // Any time we activate the slider, we reset the position + mCurrentLine = -1; + return 2; + } + + if (mCurrentLine == -1 && mLastCount != gConsole.size()) + { + // We can use Render, and return for just a flip + Render(); + return 2; + } + else if (mLastTouchY >= 0) + { + // They're still touching, so re-render + Render(); + mLastTouchY = -1; + return 2; + } + return 0; } int GUIConsole::SetRenderPos(int x, int y, int w, int h) { - // Adjust the stub position accordingly - mSlideoutX += (x - mConsoleX); - mSlideoutY += (y - mConsoleY); - - mConsoleX = x; - mConsoleY = y; - if (w || h) - { - mConsoleW = w; - mConsoleH = h; - } - - // Calculate the max rows - mMaxRows = mConsoleH / mFontHeight; - - // Adjust so we always fit to bottom - mStartY = mConsoleY + (mConsoleH % mFontHeight); - return 0; + // Adjust the stub position accordingly + mSlideoutX += (x - mConsoleX); + mSlideoutY += (y - mConsoleY); + + mConsoleX = x; + mConsoleY = y; + if (w || h) + { + mConsoleW = w; + mConsoleH = h; + } + + // Calculate the max rows + mMaxRows = mConsoleH / mFontHeight; + + // Adjust so we always fit to bottom + mStartY = mConsoleY + (mConsoleH % mFontHeight); + return 0; } // IsInRegion - Checks if the request is handled by this object // Return 0 if this object handles the request, 1 if not int GUIConsole::IsInRegion(int x, int y) { - if (mSlideout) - { - // Check if they tapped the slideout button - if (x >= mSlideoutX && x <= mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH) - return 1; - - // If we're only rendering the slideout, bail now - if (mSlideoutState == hidden) - return 0; - } - - return (x < mConsoleX || x > mConsoleX + mConsoleW || y < mConsoleY || y > mConsoleY + mConsoleH) ? 0 : 1; + if (mSlideout) + { + // Check if they tapped the slideout button + if (x >= mSlideoutX && x <= mSlideoutX + mSlideoutW && y >= mSlideoutY && y < mSlideoutY + mSlideoutH) + return 1; + + // If we're only rendering the slideout, bail now + if (mSlideoutState == hidden) + return 0; + } + + return (x < mConsoleX || x > mConsoleX + mConsoleW || y < mConsoleY || y > mConsoleY + mConsoleH) ? 0 : 1; } // NotifyTouch - Notify of a touch event // Return 0 on success, >0 to ignore remainder of touch, and <0 on error int GUIConsole::NotifyTouch(TOUCH_STATE state, int x, int y) { - if (mSlideout && mSlideoutState == hidden) - { - if (state == TOUCH_START) - { - mSlideoutState = request_show; - return 1; - } - } - else if (mSlideout && mSlideoutState == visible) - { - // Are we sliding it back in? - if (state == TOUCH_START && x > mSlideoutX && x < (mSlideoutX + mSlideoutW) && y > mSlideoutY && y < (mSlideoutY + mSlideoutH)) - { - mSlideoutState = request_hide; - return 1; - } - } - - // If we don't have enough lines to scroll, throw this away. - if (mLastCount < mMaxRows) return 1; - - // We are scrolling!!! - switch (state) - { - case TOUCH_START: - mLastTouchX = x; - mLastTouchY = y; - if ((x - mConsoleX) > ((9 * mConsoleW) / 10)) - mSlideMultiplier = 10; - else - mSlideMultiplier = 1; - break; - - case TOUCH_DRAG: - // This handles tapping - if (x == mLastTouchX && y == mLastTouchY) break; - mLastTouchX = -1; - - if (y > mLastTouchY + 5) - { - mLastTouchY = y; - if (mCurrentLine == -1) - mCurrentLine = mLastCount - 1; - else if (mCurrentLine > mSlideMultiplier) - mCurrentLine -= mSlideMultiplier; - else - mCurrentLine = mMaxRows; - - if (mCurrentLine < (int) mMaxRows) - mCurrentLine = mMaxRows; - } - else if (y < mLastTouchY - 5) - { - mLastTouchY = y; - if (mCurrentLine >= 0) - { - mCurrentLine += mSlideMultiplier; - if (mCurrentLine >= (int) mLastCount) - mCurrentLine = -1; - } - } - break; - - case TOUCH_RELEASE: - // On a tap, we jump to the tail - if (mLastTouchX >= 0) - mCurrentLine = -1; - - mLastTouchY = -1; + if (mSlideout && mSlideoutState == hidden) + { + if (state == TOUCH_START) + { + mSlideoutState = request_show; + return 1; + } + } + else if (mSlideout && mSlideoutState == visible) + { + // Are we sliding it back in? + if (state == TOUCH_START && x > mSlideoutX && x < (mSlideoutX + mSlideoutW) && y > mSlideoutY && y < (mSlideoutY + mSlideoutH)) + { + mSlideoutState = request_hide; + return 1; + } + } + + // If we don't have enough lines to scroll, throw this away. + if (mLastCount < mMaxRows) return 1; + + // We are scrolling!!! + switch (state) + { + case TOUCH_START: + mLastTouchX = x; + mLastTouchY = y; + if ((x - mConsoleX) > ((9 * mConsoleW) / 10)) + mSlideMultiplier = 10; + else + mSlideMultiplier = 1; + break; + + case TOUCH_DRAG: + // This handles tapping + if (x == mLastTouchX && y == mLastTouchY) break; + mLastTouchX = -1; + + if (y > mLastTouchY + 5) + { + mLastTouchY = y; + if (mCurrentLine == -1) + mCurrentLine = mLastCount - 1; + else if (mCurrentLine > mSlideMultiplier) + mCurrentLine -= mSlideMultiplier; + else + mCurrentLine = mMaxRows; + + if (mCurrentLine < (int) mMaxRows) + mCurrentLine = mMaxRows; + } + else if (y < mLastTouchY - 5) + { + mLastTouchY = y; + if (mCurrentLine >= 0) + { + mCurrentLine += mSlideMultiplier; + if (mCurrentLine >= (int) mLastCount) + mCurrentLine = -1; + } + } + break; + + case TOUCH_RELEASE: + // On a tap, we jump to the tail + if (mLastTouchX >= 0) + mCurrentLine = -1; + + mLastTouchY = -1; case TOUCH_REPEAT: case TOUCH_HOLD: - break; - } - return 0; + break; + } + return 0; } - diff --git a/gui/fileselector.cpp b/gui/fileselector.cpp index 539bba096..0f8d903a3 100644 --- a/gui/fileselector.cpp +++ b/gui/fileselector.cpp @@ -198,12 +198,12 @@ GUIFileSelector::GUIFileSelector(xml_node<>* node) attr = child->first_attribute("highlightcolor"); memset(&mFontHighlightColor, 0, sizeof(COLOR)); - if (attr) - { - std::string color = attr->value(); + if (attr) + { + std::string color = attr->value(); ConvertStrToColor(color, &mFontHighlightColor); hasFontHighlightColor = true; - } + } } // Load the separator if it exists @@ -408,11 +408,10 @@ int GUIFileSelector::Render(void) if (updateFileList) { string value; DataManager::GetValue(mPathVar, value); - if (GetFileList(value) == 0) { + if (GetFileList(value) == 0) updateFileList = false; - } else { + else return 0; - } } // This tells us how many lines we can actually render @@ -652,7 +651,9 @@ int GUIFileSelector::Update(void) int GUIFileSelector::GetSelection(int x, int y) { // We only care about y position - if (y < mRenderY || y - mRenderY <= mHeaderH || y - mRenderY > mRenderH) return -1; + if (y < mRenderY || y - mRenderY <= mHeaderH || y - mRenderY > mRenderH) + return -1; + return (y - mRenderY - mHeaderH); } @@ -674,7 +675,6 @@ int GUIFileSelector::NotifyTouch(TOUCH_STATE state, int x, int y) startY = lastY = last2Y = y; scrollingSpeed = 0; break; - case TOUCH_DRAG: // Check if we dragged out of the selection window if (GetSelection(x, y) == -1) { diff --git a/gui/fill.cpp b/gui/fill.cpp index 901eee140..ad1f4e075 100644 --- a/gui/fill.cpp +++ b/gui/fill.cpp @@ -27,31 +27,31 @@ extern "C" { GUIFill::GUIFill(xml_node<>* node) { - xml_attribute<>* attr; - xml_node<>* child; + xml_attribute<>* attr; + xml_node<>* child; - if (!node) - return; + if (!node) + return; - attr = node->first_attribute("color"); - if (!attr) { + attr = node->first_attribute("color"); + if (!attr) { LOGERR("No color specified for fill\n"); - return; + return; } - std::string color = attr->value(); - ConvertStrToColor(color, &mColor); + std::string color = attr->value(); + ConvertStrToColor(color, &mColor); - // Load the placement - LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH); + // Load the placement + LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH); - return; + return; } int GUIFill::Render(void) { - gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha); - gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); - return 0; + gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha); + gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); + return 0; } diff --git a/gui/gui.cpp b/gui/gui.cpp index 87556891d..821c7f5b2 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -69,685 +69,659 @@ int gGuiRunning = 0; static int gRecorder = -1; -extern "C" void gr_write_frame_to_file (int fd); +extern "C" void gr_write_frame_to_file(int fd); -void -flip (void) +void flip(void) { - if (gRecorder != -1) + if (gRecorder != -1) { - timespec time; - clock_gettime (CLOCK_MONOTONIC, &time); - write (gRecorder, &time, sizeof (timespec)); - gr_write_frame_to_file (gRecorder); + timespec time; + clock_gettime(CLOCK_MONOTONIC, &time); + write(gRecorder, &time, sizeof(timespec)); + gr_write_frame_to_file(gRecorder); } - gr_flip (); - return; + gr_flip(); } -void -rapidxml::parse_error_handler (const char *what, void *where) +void rapidxml::parse_error_handler(const char *what, void *where) { - fprintf (stderr, "Parser error: %s\n", what); - fprintf (stderr, " Start of string: %s\n", (char *) where); - LOGERR("Error parsing XML file.\n"); - //abort (); + fprintf(stderr, "Parser error: %s\n", what); + fprintf(stderr, " Start of string: %s\n",(char *) where); + LOGERR("Error parsing XML file.\n"); + //abort(); } -static void -curtainSet () +static void curtainSet() { - gr_color (0, 0, 0, 255); - gr_fill (0, 0, gr_fb_width (), gr_fb_height ()); - gr_blit (gCurtain, 0, 0, gr_get_width (gCurtain), gr_get_height (gCurtain), - 0, 0); - gr_flip (); - return; + gr_color(0, 0, 0, 255); + gr_fill(0, 0, gr_fb_width(), gr_fb_height()); + gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), 0, 0); + gr_flip(); } -static void -curtainRaise (gr_surface surface) +static void curtainRaise(gr_surface surface) { - int sy = 0; - int h = gr_get_height (gCurtain) - 1; - int w = gr_get_width (gCurtain); - int fy = 1; + int sy = 0; + int h = gr_get_height(gCurtain) - 1; + int w = gr_get_width(gCurtain); + int fy = 1; - int msw = gr_get_width (surface); - int msh = gr_get_height (surface); - int CURTAIN_RATE = msh / 30; + int msw = gr_get_width(surface); + int msh = gr_get_height(surface); + int CURTAIN_RATE = msh / 30; - if (gNoAnimation == 0) + if (gNoAnimation == 0) { - for (; h > 0; h -= CURTAIN_RATE, sy += CURTAIN_RATE, fy += CURTAIN_RATE) + for (; h > 0; h -= CURTAIN_RATE, sy += CURTAIN_RATE, fy += CURTAIN_RATE) { - gr_blit (surface, 0, 0, msw, msh, 0, 0); - gr_blit (gCurtain, 0, sy, w, h, 0, 0); - gr_flip (); + gr_blit(surface, 0, 0, msw, msh, 0, 0); + gr_blit(gCurtain, 0, sy, w, h, 0, 0); + gr_flip(); } } - gr_blit (surface, 0, 0, msw, msh, 0, 0); - flip (); - return; + gr_blit(surface, 0, 0, msw, msh, 0, 0); + flip(); } -void -curtainClose () +void curtainClose() { #if 0 - int w = gr_get_width (gCurtain); - int h = 1; - int sy = gr_get_height (gCurtain) - 1; - int fbh = gr_fb_height (); - int CURTAIN_RATE = fbh / 30; + int w = gr_get_width(gCurtain); + int h = 1; + int sy = gr_get_height(gCurtain) - 1; + int fbh = gr_fb_height(); + int CURTAIN_RATE = fbh / 30; - if (gNoAnimation == 0) + if (gNoAnimation == 0) { - for (; h < fbh; h += CURTAIN_RATE, sy -= CURTAIN_RATE) + for (; h < fbh; h += CURTAIN_RATE, sy -= CURTAIN_RATE) { - gr_blit (gCurtain, 0, sy, w, h, 0, 0); - gr_flip (); + gr_blit(gCurtain, 0, sy, w, h, 0, 0); + gr_flip(); } - gr_blit (gCurtain, 0, 0, gr_get_width (gCurtain), - gr_get_height (gCurtain), 0, 0); - gr_flip (); + gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), + gr_get_height(gCurtain), 0, 0); + gr_flip(); - if (gRecorder != -1) - close (gRecorder); + if (gRecorder != -1) + close(gRecorder); - int fade; - for (fade = 16; fade < 255; fade += CURTAIN_FADE) + int fade; + for (fade = 16; fade < 255; fade += CURTAIN_FADE) { - gr_blit (gCurtain, 0, 0, gr_get_width (gCurtain), - gr_get_height (gCurtain), 0, 0); - gr_color (0, 0, 0, fade); - gr_fill (0, 0, gr_fb_width (), gr_fb_height ()); - gr_flip (); + gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), + gr_get_height(gCurtain), 0, 0); + gr_color(0, 0, 0, fade); + gr_fill(0, 0, gr_fb_width(), gr_fb_height()); + gr_flip(); } - gr_color (0, 0, 0, 255); - gr_fill (0, 0, gr_fb_width (), gr_fb_height ()); - gr_flip (); + gr_color(0, 0, 0, 255); + gr_fill(0, 0, gr_fb_width(), gr_fb_height()); + gr_flip(); } #else - gr_blit (gCurtain, 0, 0, gr_get_width (gCurtain), gr_get_height (gCurtain), - 0, 0); - gr_flip (); + gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), 0, 0); + gr_flip(); #endif - return; } -static void * -input_thread (void *cookie) +static void * input_thread(void *cookie) { - int drag = 0; - static int touch_and_hold = 0, dontwait = 0, touch_repeat = 0, x = 0, y = - 0, lshift = 0, rshift = 0, key_repeat = 0; - static struct timeval touchStart; - HardwareKeyboard kb; - string seconds; - - //start screen timeout threads - blankTimer.setTimerThread(); - DataManager::GetValue("tw_screen_timeout_secs", seconds); - blankTimer.setTime(atoi(seconds.c_str())); - - for (;;) + int drag = 0; + static int touch_and_hold = 0, dontwait = 0; + static int touch_repeat = 0, key_repeat = 0; + static int x = 0, y = 0; + static int lshift = 0, rshift = 0; + static struct timeval touchStart; + HardwareKeyboard kb; + string seconds; + + //start screen timeout threads + blankTimer.setTimerThread(); + DataManager::GetValue("tw_screen_timeout_secs", seconds); + blankTimer.setTime(atoi(seconds.c_str())); + + for (;;) { + // wait for the next event + struct input_event ev; + int state = 0, ret = 0; - // wait for the next event - struct input_event ev; - int state = 0, ret = 0; + ret = ev_get(&ev, dontwait); - ret = ev_get (&ev, dontwait); - - if (ret < 0) + if (ret < 0) { - struct timeval curTime; - gettimeofday (&curTime, NULL); - long mtime, seconds, useconds; + struct timeval curTime; + gettimeofday(&curTime, NULL); + long mtime, seconds, useconds; - seconds = curTime.tv_sec - touchStart.tv_sec; - useconds = curTime.tv_usec - touchStart.tv_usec; + seconds = curTime.tv_sec - touchStart.tv_sec; + useconds = curTime.tv_usec - touchStart.tv_usec; - mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5; - if (touch_and_hold && mtime > 500) + mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5; + if (touch_and_hold && mtime > 500) { - touch_and_hold = 0; - touch_repeat = 1; - gettimeofday (&touchStart, NULL); + touch_and_hold = 0; + touch_repeat = 1; + gettimeofday(&touchStart, NULL); #ifdef _EVENT_LOGGING - LOGERR("TOUCH_HOLD: %d,%d\n", x, y); + LOGERR("TOUCH_HOLD: %d,%d\n", x, y); #endif - PageManager::NotifyTouch (TOUCH_HOLD, x, y); - blankTimer.resetTimerAndUnblank(); + PageManager::NotifyTouch(TOUCH_HOLD, x, y); + blankTimer.resetTimerAndUnblank(); } - else if (touch_repeat && mtime > 100) + else if (touch_repeat && mtime > 100) { #ifdef _EVENT_LOGGING - LOGERR("TOUCH_REPEAT: %d,%d\n", x, y); + LOGERR("TOUCH_REPEAT: %d,%d\n", x, y); #endif - gettimeofday (&touchStart, NULL); - PageManager::NotifyTouch (TOUCH_REPEAT, x, y); - blankTimer.resetTimerAndUnblank(); + gettimeofday(&touchStart, NULL); + PageManager::NotifyTouch(TOUCH_REPEAT, x, y); + blankTimer.resetTimerAndUnblank(); } - else if (key_repeat == 1 && mtime > 500) + else if (key_repeat == 1 && mtime > 500) { #ifdef _EVENT_LOGGING - LOGERR("KEY_HOLD: %d,%d\n", x, y); + LOGERR("KEY_HOLD: %d,%d\n", x, y); #endif - gettimeofday (&touchStart, NULL); - key_repeat = 2; - kb.KeyRepeat (); - blankTimer.resetTimerAndUnblank(); + gettimeofday(&touchStart, NULL); + key_repeat = 2; + kb.KeyRepeat(); + blankTimer.resetTimerAndUnblank(); } - else if (key_repeat == 2 && mtime > 100) + else if (key_repeat == 2 && mtime > 100) { #ifdef _EVENT_LOGGING - LOGERR("KEY_REPEAT: %d,%d\n", x, y); + LOGERR("KEY_REPEAT: %d,%d\n", x, y); #endif - gettimeofday (&touchStart, NULL); - kb.KeyRepeat (); - blankTimer.resetTimerAndUnblank(); + gettimeofday(&touchStart, NULL); + kb.KeyRepeat(); + blankTimer.resetTimerAndUnblank(); } } - else if (ev.type == EV_ABS) + else if (ev.type == EV_ABS) { - x = ev.value >> 16; - y = ev.value & 0xFFFF; + x = ev.value >> 16; + y = ev.value & 0xFFFF; - if (ev.code == 0) + if (ev.code == 0) { - if (state == 0) + if (state == 0) { #ifdef _EVENT_LOGGING - LOGERR("TOUCH_RELEASE: %d,%d\n", x, y); + LOGERR("TOUCH_RELEASE: %d,%d\n", x, y); #endif - PageManager::NotifyTouch (TOUCH_RELEASE, x, y); - blankTimer.resetTimerAndUnblank(); - touch_and_hold = 0; - touch_repeat = 0; - if (!key_repeat) - dontwait = 0; + PageManager::NotifyTouch(TOUCH_RELEASE, x, y); + blankTimer.resetTimerAndUnblank(); + touch_and_hold = 0; + touch_repeat = 0; + if (!key_repeat) + dontwait = 0; } - state = 0; - drag = 0; + state = 0; + drag = 0; } - else + else { - if (!drag) + if (!drag) { #ifdef _EVENT_LOGGING - LOGERR("TOUCH_START: %d,%d\n", x, y); + LOGERR("TOUCH_START: %d,%d\n", x, y); #endif - if (PageManager::NotifyTouch (TOUCH_START, x, y) > 0) - state = 1; - drag = 1; - touch_and_hold = 1; - dontwait = 1; - key_repeat = 0; - gettimeofday (&touchStart, NULL); - blankTimer.resetTimerAndUnblank(); + if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0) + state = 1; + drag = 1; + touch_and_hold = 1; + dontwait = 1; + key_repeat = 0; + gettimeofday(&touchStart, NULL); + blankTimer.resetTimerAndUnblank(); } - else + else { - if (state == 0) + if (state == 0) { #ifdef _EVENT_LOGGING - LOGERR("TOUCH_DRAG: %d,%d\n", x, y); + LOGERR("TOUCH_DRAG: %d,%d\n", x, y); #endif - if (PageManager::NotifyTouch (TOUCH_DRAG, x, y) > 0) - state = 1; - key_repeat = 0; - blankTimer.resetTimerAndUnblank(); + if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0) + state = 1; + key_repeat = 0; + blankTimer.resetTimerAndUnblank(); } } } } - else if (ev.type == EV_KEY) + else if (ev.type == EV_KEY) { - // Handle key-press here + // Handle key-press here #ifdef _EVENT_LOGGING - LOGERR("TOUCH_KEY: %d\n", ev.code); + LOGERR("TOUCH_KEY: %d\n", ev.code); #endif - if (ev.value != 0) + if (ev.value != 0) { - // This is a key press - if (kb.KeyDown (ev.code)) + // This is a key press + if (kb.KeyDown(ev.code)) { - key_repeat = 1; - touch_and_hold = 0; - touch_repeat = 0; - dontwait = 1; - gettimeofday (&touchStart, NULL); - blankTimer.resetTimerAndUnblank(); + key_repeat = 1; + touch_and_hold = 0; + touch_repeat = 0; + dontwait = 1; + gettimeofday(&touchStart, NULL); + blankTimer.resetTimerAndUnblank(); } - else + else { - key_repeat = 0; - touch_and_hold = 0; - touch_repeat = 0; - dontwait = 0; - blankTimer.resetTimerAndUnblank(); + key_repeat = 0; + touch_and_hold = 0; + touch_repeat = 0; + dontwait = 0; + blankTimer.resetTimerAndUnblank(); } } - else + else { - // This is a key release - kb.KeyUp (ev.code); - key_repeat = 0; - touch_and_hold = 0; - touch_repeat = 0; - dontwait = 0; - blankTimer.resetTimerAndUnblank(); + // This is a key release + kb.KeyUp(ev.code); + key_repeat = 0; + touch_and_hold = 0; + touch_repeat = 0; + dontwait = 0; + blankTimer.resetTimerAndUnblank(); } } } - return NULL; + return NULL; } // This special function will return immediately the first time, but then // always returns 1/30th of a second (or immediately if called later) from // the last time it was called -static void -loopTimer (void) +static void loopTimer(void) { - static timespec lastCall; - static int initialized = 0; + static timespec lastCall; + static int initialized = 0; - if (!initialized) + if (!initialized) { - clock_gettime (CLOCK_MONOTONIC, &lastCall); - initialized = 1; - return; + clock_gettime(CLOCK_MONOTONIC, &lastCall); + initialized = 1; + return; } - do + do { - timespec curTime; - clock_gettime (CLOCK_MONOTONIC, &curTime); + timespec curTime; + clock_gettime(CLOCK_MONOTONIC, &curTime); - timespec diff = TWFunc::timespec_diff (lastCall, curTime); + timespec diff = TWFunc::timespec_diff(lastCall, curTime); - // This is really 30 times per second - if (diff.tv_sec || diff.tv_nsec > 33333333) + // This is really 30 times per second + if (diff.tv_sec || diff.tv_nsec > 33333333) { - lastCall = curTime; - return; + lastCall = curTime; + return; } - // We need to sleep some period time microseconds - unsigned int sleepTime = 33333 - (diff.tv_nsec / 1000); - usleep (sleepTime); - } - while (1); - return; + // We need to sleep some period time microseconds + unsigned int sleepTime = 33333 -(diff.tv_nsec / 1000); + usleep(sleepTime); + } while (1); } -static int -runPages (void) +static int runPages(void) { - // Raise the curtain - if (gCurtain != NULL) + // Raise the curtain + if (gCurtain != NULL) { - gr_surface surface; + gr_surface surface; - PageManager::Render (); - gr_get_surface (&surface); - curtainRaise (surface); - gr_free_surface (surface); + PageManager::Render(); + gr_get_surface(&surface); + curtainRaise(surface); + gr_free_surface(surface); } - gGuiRunning = 1; + gGuiRunning = 1; - DataManager::SetValue ("tw_loaded", 1); + DataManager::SetValue("tw_loaded", 1); - for (;;) + for (;;) { - loopTimer (); + loopTimer(); - if (!gForceRender) + if (!gForceRender) { - int ret; + int ret; - ret = PageManager::Update (); - if (ret > 1) - PageManager::Render (); + ret = PageManager::Update(); + if (ret > 1) + PageManager::Render(); - if (ret > 0) - flip (); + if (ret > 0) + flip(); } - else + else { - pthread_mutex_lock(&gForceRendermutex); - gForceRender = 0; - pthread_mutex_unlock(&gForceRendermutex); - PageManager::Render (); - flip (); + pthread_mutex_lock(&gForceRendermutex); + gForceRender = 0; + pthread_mutex_unlock(&gForceRendermutex); + PageManager::Render(); + flip(); } + if (DataManager::GetIntValue("tw_gui_done") != 0) - { break; - } } - gGuiRunning = 0; - return 0; + gGuiRunning = 0; + return 0; } -static int -runPage (const char *page_name) +static int runPage(const char *page_name) { - gui_changePage (page_name); + gui_changePage(page_name); - // Raise the curtain - if (gCurtain != NULL) + // Raise the curtain + if (gCurtain != NULL) { - gr_surface surface; + gr_surface surface; - PageManager::Render (); - gr_get_surface (&surface); - curtainRaise (surface); - gr_free_surface (surface); + PageManager::Render(); + gr_get_surface(&surface); + curtainRaise(surface); + gr_free_surface(surface); } - gGuiRunning = 1; + gGuiRunning = 1; - DataManager::SetValue ("tw_loaded", 1); + DataManager::SetValue("tw_loaded", 1); - for (;;) + for (;;) { - loopTimer (); + loopTimer(); - if (!gForceRender) + if (!gForceRender) { - int ret; + int ret; - ret = PageManager::Update (); - if (ret > 1) - PageManager::Render (); + ret = PageManager::Update(); + if (ret > 1) + PageManager::Render(); - if (ret > 0) - flip (); + if (ret > 0) + flip(); } - else + else { - pthread_mutex_lock(&gForceRendermutex); - gForceRender = 0; - pthread_mutex_unlock(&gForceRendermutex); - PageManager::Render (); - flip (); + pthread_mutex_lock(&gForceRendermutex); + gForceRender = 0; + pthread_mutex_unlock(&gForceRendermutex); + PageManager::Render(); + flip(); } - if (DataManager::GetIntValue ("tw_page_done") != 0) + if (DataManager::GetIntValue("tw_page_done") != 0) { - gui_changePage ("main"); - break; + gui_changePage("main"); + break; } } - gGuiRunning = 0; - return 0; + gGuiRunning = 0; + return 0; } -int -gui_forceRender (void) +int gui_forceRender(void) { - pthread_mutex_lock(&gForceRendermutex); - gForceRender = 1; - pthread_mutex_unlock(&gForceRendermutex); - return 0; + pthread_mutex_lock(&gForceRendermutex); + gForceRender = 1; + pthread_mutex_unlock(&gForceRendermutex); + return 0; } -int -gui_changePage (std::string newPage) +int gui_changePage(std::string newPage) { - LOGINFO("Set page: '%s'\n", newPage.c_str ()); - PageManager::ChangePage (newPage); - pthread_mutex_lock(&gForceRendermutex); - gForceRender = 1; - pthread_mutex_unlock(&gForceRendermutex); - return 0; + LOGINFO("Set page: '%s'\n", newPage.c_str()); + PageManager::ChangePage(newPage); + pthread_mutex_lock(&gForceRendermutex); + gForceRender = 1; + pthread_mutex_unlock(&gForceRendermutex); + return 0; } -int -gui_changeOverlay (std::string overlay) +int gui_changeOverlay(std::string overlay) { - PageManager::ChangeOverlay (overlay); - pthread_mutex_lock(&gForceRendermutex); - gForceRender = 1; - pthread_mutex_unlock(&gForceRendermutex); - return 0; + PageManager::ChangeOverlay(overlay); + pthread_mutex_lock(&gForceRendermutex); + gForceRender = 1; + pthread_mutex_unlock(&gForceRendermutex); + return 0; } -int -gui_changePackage (std::string newPackage) +int gui_changePackage(std::string newPackage) { - PageManager::SelectPackage (newPackage); - pthread_mutex_lock(&gForceRendermutex); - gForceRender = 1; - pthread_mutex_unlock(&gForceRendermutex); - return 0; + PageManager::SelectPackage(newPackage); + pthread_mutex_lock(&gForceRendermutex); + gForceRender = 1; + pthread_mutex_unlock(&gForceRendermutex); + return 0; } -std::string gui_parse_text (string inText) +std::string gui_parse_text(string inText) { - // Copied from std::string GUIText::parseText(void) - // This function parses text for DataManager values encompassed by %value% in the XML - static int counter = 0; - std::string str = inText; - size_t pos = 0; - size_t next = 0, end = 0; - - while (1) + // Copied from std::string GUIText::parseText(void) + // This function parses text for DataManager values encompassed by %value% in the XML + static int counter = 0; + std::string str = inText; + size_t pos = 0; + size_t next = 0, end = 0; + + while (1) { - next = str.find ('%', pos); - if (next == std::string::npos) - return str; - end = str.find ('%', next + 1); - if (end == std::string::npos) - return str; - - // We have a block of data - std::string var = str.substr (next + 1, (end - next) - 1); - str.erase (next, (end - next) + 1); - - if (next + 1 == end) - { - str.insert (next, 1, '%'); - } - else + next = str.find('%', pos); + if (next == std::string::npos) + return str; + + end = str.find('%', next + 1); + if (end == std::string::npos) + return str; + + // We have a block of data + std::string var = str.substr(next + 1,(end - next) - 1); + str.erase(next,(end - next) + 1); + + if (next + 1 == end) + str.insert(next, 1, '%'); + else { - std::string value; - if (DataManager::GetValue (var, value) == 0) - str.insert (next, value); + std::string value; + if (DataManager::GetValue(var, value) == 0) + str.insert(next, value); } - pos = next + 1; + pos = next + 1; } } -extern "C" int -gui_init () +extern "C" int gui_init(void) { - int fd; + int fd; - gr_init (); + gr_init(); - if (res_create_surface ("/res/images/curtain.jpg", &gCurtain)) + if (res_create_surface("/res/images/curtain.jpg", &gCurtain)) { - printf + printf ("Unable to locate '/res/images/curtain.jpg'\nDid you set a DEVICE_RESOLUTION in your config files?\n"); - return -1; + return -1; } - curtainSet (); + curtainSet(); - ev_init (); - return 0; + ev_init(); + return 0; } -extern "C" int -gui_loadResources () +extern "C" int gui_loadResources(void) { -// unlink("/sdcard/video.last"); -// rename("/sdcard/video.bin", "/sdcard/video.last"); -// gRecorder = open("/sdcard/video.bin", O_CREAT | O_WRONLY); + // unlink("/sdcard/video.last"); + // rename("/sdcard/video.bin", "/sdcard/video.last"); + // gRecorder = open("/sdcard/video.bin", O_CREAT | O_WRONLY); - int check = 0; - DataManager::GetValue (TW_IS_ENCRYPTED, check); - if (check) + int check = 0; + DataManager::GetValue(TW_IS_ENCRYPTED, check); + if (check) { - if (PageManager::LoadPackage ("TWRP", "/res/ui.xml", "decrypt")) + if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "decrypt")) { - LOGERR("Failed to load base packages.\n"); - goto error; + LOGERR("Failed to load base packages.\n"); + goto error; } - else - check = 1; + else + check = 1; } - if (check == 0 - && PageManager::LoadPackage("TWRP", "/script/ui.xml", "main")) + + if (check == 0 && PageManager::LoadPackage("TWRP", "/script/ui.xml", "main")) { - std::string theme_path; + std::string theme_path; - theme_path = DataManager::GetSettingsStoragePath (); - if (!PartitionManager.Mount_Settings_Storage(false)) + theme_path = DataManager::GetSettingsStoragePath(); + if (!PartitionManager.Mount_Settings_Storage(false)) { - int retry_count = 5; - while (retry_count > 0 - && !PartitionManager.Mount_Settings_Storage(false)) + int retry_count = 5; + while (retry_count > 0 && !PartitionManager.Mount_Settings_Storage(false)) { - usleep (500000); - retry_count--; + usleep(500000); + retry_count--; } - if (!PartitionManager.Mount_Settings_Storage(false)) + + if (!PartitionManager.Mount_Settings_Storage(false)) { - LOGERR("Unable to mount %s during GUI startup.\n", - theme_path.c_str ()); - check = 1; + LOGERR("Unable to mount %s during GUI startup.\n", + theme_path.c_str()); + check = 1; } } - theme_path += "/TWRP/theme/ui.zip"; - if (check || PageManager::LoadPackage("TWRP", theme_path, "main")) + theme_path += "/TWRP/theme/ui.zip"; + if (check || PageManager::LoadPackage("TWRP", theme_path, "main")) { - if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "main")) + if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "main")) { - LOGERR("Failed to load base packages.\n"); - goto error; + LOGERR("Failed to load base packages.\n"); + goto error; } } } - // Set the default package - PageManager::SelectPackage ("TWRP"); + // Set the default package + PageManager::SelectPackage("TWRP"); - gGuiInitialized = 1; - return 0; + gGuiInitialized = 1; + return 0; error: - LOGERR("An internal error has occurred.\n"); - gGuiInitialized = 0; - return -1; + LOGERR("An internal error has occurred.\n"); + gGuiInitialized = 0; + return -1; } -extern "C" int -gui_start () +extern "C" int gui_start(void) { - if (!gGuiInitialized) - return -1; + if (!gGuiInitialized) + return -1; + + gGuiConsoleTerminate = 1; - gGuiConsoleTerminate = 1; - while (gGuiConsoleRunning) - loopTimer (); + while (gGuiConsoleRunning) + loopTimer(); - // Set the default package - PageManager::SelectPackage ("TWRP"); + // Set the default package + PageManager::SelectPackage("TWRP"); - if (!gGuiInputRunning) + if (!gGuiInputRunning) { - // Start by spinning off an input handler. - pthread_t t; - pthread_create (&t, NULL, input_thread, NULL); - gGuiInputRunning = 1; + // Start by spinning off an input handler. + pthread_t t; + pthread_create(&t, NULL, input_thread, NULL); + gGuiInputRunning = 1; } - return runPages (); + return runPages(); } -extern "C" int -gui_startPage (const char *page_name) +extern "C" int gui_startPage(const char *page_name) { - if (!gGuiInitialized) - return -1; + if (!gGuiInitialized) + return -1; - gGuiConsoleTerminate = 1; - while (gGuiConsoleRunning) - loopTimer (); + gGuiConsoleTerminate = 1; - // Set the default package - PageManager::SelectPackage("TWRP"); + while (gGuiConsoleRunning) + loopTimer(); - if (!gGuiInputRunning) + // Set the default package + PageManager::SelectPackage("TWRP"); + + if (!gGuiInputRunning) { - // Start by spinning off an input handler. - pthread_t t; - pthread_create (&t, NULL, input_thread, NULL); - gGuiInputRunning = 1; + // Start by spinning off an input handler. + pthread_t t; + pthread_create(&t, NULL, input_thread, NULL); + gGuiInputRunning = 1; } - DataManager::SetValue("tw_page_done", 0); - return runPage (page_name); + DataManager::SetValue("tw_page_done", 0); + return runPage(page_name); } -static void * -console_thread (void *cookie) +static void * console_thread(void *cookie) { - PageManager::SwitchToConsole (); + PageManager::SwitchToConsole(); - while (!gGuiConsoleTerminate) + while (!gGuiConsoleTerminate) { - loopTimer (); + loopTimer(); - if (!gForceRender) + if (!gForceRender) { - int ret; + int ret; - ret = PageManager::Update (); - if (ret > 1) - PageManager::Render (); + ret = PageManager::Update(); + if (ret > 1) + PageManager::Render(); - if (ret > 0) - flip (); + if (ret > 0) + flip(); - if (ret < 0) - LOGERR("An update request has failed.\n"); + if (ret < 0) + LOGERR("An update request has failed.\n"); } - else + else { - pthread_mutex_lock(&gForceRendermutex); - gForceRender = 0; - pthread_mutex_unlock(&gForceRendermutex); - PageManager::Render (); - flip (); + pthread_mutex_lock(&gForceRendermutex); + gForceRender = 0; + pthread_mutex_unlock(&gForceRendermutex); + PageManager::Render(); + flip(); } } - gGuiConsoleRunning = 0; - return NULL; + gGuiConsoleRunning = 0; + return NULL; } -extern "C" int -gui_console_only () +extern "C" int gui_console_only(void) { - if (!gGuiInitialized) - return -1; + if (!gGuiInitialized) + return -1; - gGuiConsoleTerminate = 0; - gGuiConsoleRunning = 1; + gGuiConsoleTerminate = 0; + gGuiConsoleRunning = 1; - // Start by spinning off an input handler. - pthread_t t; - pthread_create (&t, NULL, console_thread, NULL); + // Start by spinning off an input handler. + pthread_t t; + pthread_create(&t, NULL, console_thread, NULL); - return 0; + return 0; } diff --git a/gui/hardwarekeyboard.cpp b/gui/hardwarekeyboard.cpp index 96958d50a..a5a9987ae 100644 --- a/gui/hardwarekeyboard.cpp +++ b/gui/hardwarekeyboard.cpp @@ -26,15 +26,18 @@ extern "C" { #include "rapidxml.hpp" #include "objects.hpp" -HardwareKeyboard::HardwareKeyboard(void) { - // Do Nothing +HardwareKeyboard::HardwareKeyboard(void) +{ + } -HardwareKeyboard::~HardwareKeyboard() { - // Do Nothing +HardwareKeyboard::~HardwareKeyboard() +{ + } -int HardwareKeyboard::KeyDown(int key_code) { +int HardwareKeyboard::KeyDown(int key_code) +{ #ifdef _EVENT_LOGGING LOGERR("HardwareKeyboard::KeyDown %i\n", key_code); #endif @@ -42,14 +45,16 @@ int HardwareKeyboard::KeyDown(int key_code) { return 0; // 0 = no key repeat anything else turns on key repeat } -int HardwareKeyboard::KeyUp(int key_code) { +int HardwareKeyboard::KeyUp(int key_code) +{ #ifdef _EVENT_LOGGING LOGERR("HardwareKeyboard::KeyUp %i\n", key_code); #endif return 0; } -int HardwareKeyboard::KeyRepeat(void) { +int HardwareKeyboard::KeyRepeat(void) +{ #ifdef _EVENT_LOGGING LOGERR("HardwareKeyboard::KeyRepeat\n"); #endif diff --git a/gui/image.cpp b/gui/image.cpp index c684d1b53..45d863673 100644 --- a/gui/image.cpp +++ b/gui/image.cpp @@ -27,71 +27,76 @@ extern "C" { GUIImage::GUIImage(xml_node<>* node) { - xml_attribute<>* attr; - xml_node<>* child; + xml_attribute<>* attr; + xml_node<>* child; - mImage = NULL; + mImage = NULL; mHighlightImage = NULL; isHighlighted = false; - if (!node) - return; + if (!node) + return; - child = node->first_node("image"); - if (child) - { - attr = child->first_attribute("resource"); - if (attr) - mImage = PageManager::FindResource(attr->value()); + child = node->first_node("image"); + if (child) + { + attr = child->first_attribute("resource"); + if (attr) + mImage = PageManager::FindResource(attr->value()); attr = child->first_attribute("highlightresource"); - if (attr) - mHighlightImage = PageManager::FindResource(attr->value()); - } - - // Load the placement - LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement); - - if (mImage && mImage->GetResource()) - { - mRenderW = gr_get_width(mImage->GetResource()); - mRenderH = gr_get_height(mImage->GetResource()); - - // Adjust for placement - if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT) - { - if (mPlacement == CENTER) - mRenderX -= (mRenderW / 2); - else - mRenderX -= mRenderW; - } - if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT) - { - if (mPlacement == CENTER) - mRenderY -= (mRenderH / 2); - else - mRenderY -= mRenderH; - } - SetPlacement(TOP_LEFT); - } - - return; + if (attr) + mHighlightImage = PageManager::FindResource(attr->value()); + } + + // Load the placement + LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement); + + if (mImage && mImage->GetResource()) + { + mRenderW = gr_get_width(mImage->GetResource()); + mRenderH = gr_get_height(mImage->GetResource()); + + // Adjust for placement + if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT) + { + if (mPlacement == CENTER) + mRenderX -= (mRenderW / 2); + else + mRenderX -= mRenderW; + } + if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT) + { + if (mPlacement == CENTER) + mRenderY -= (mRenderH / 2); + else + mRenderY -= mRenderH; + } + SetPlacement(TOP_LEFT); + } + + return; } int GUIImage::Render(void) { - if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) { + if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) { gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); return 0; - } else if (!mImage || !mImage->GetResource()) return -1; - gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); - return 0; + } + else if (!mImage || !mImage->GetResource()) + return -1; + + gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); + return 0; } int GUIImage::SetRenderPos(int x, int y, int w, int h) { - if (w || h) return -1; - mRenderX = x; - mRenderY = y; - return 0; + if (w || h) + return -1; + + mRenderX = x; + mRenderY = y; + return 0; } diff --git a/gui/input.cpp b/gui/input.cpp index e0167244d..19e4e6a5b 100644 --- a/gui/input.cpp +++ b/gui/input.cpp @@ -29,17 +29,17 @@ extern "C" { #include "../data.hpp" GUIInput::GUIInput(xml_node<>* node) - : Conditional(node) + : Conditional(node) { - xml_attribute<>* attr; - xml_node<>* child; + xml_attribute<>* attr; + xml_node<>* child; - mInputText = NULL; + mInputText = NULL; mAction = NULL; mBackground = NULL; mCursor = NULL; mFont = NULL; - mRendered = false; + mRendered = false; HasMask = false; DrawCursor = false; isLocalChange = true; @@ -52,18 +52,19 @@ GUIInput::GUIInput(xml_node<>* node) ConvertStrToColor("black", &mBackgroundColor); ConvertStrToColor("white", &mCursorColor); - if (!node) return; + if (!node) + return; - // Load text directly from the node - mInputText = new GUIText(node); + // Load text directly from the node + mInputText = new GUIText(node); // Load action directly from the node mAction = new GUIAction(node); if (mInputText->Render() < 0) - { - delete mInputText; - mInputText = NULL; - } + { + delete mInputText; + mInputText = NULL; + } // Load the background child = node->first_node("background"); @@ -114,18 +115,18 @@ GUIInput::GUIInput(xml_node<>* node) DrawCursor = HasInputFocus; // Load the font, and possibly override the color - child = node->first_node("font"); - if (child) - { - attr = child->first_attribute("resource"); - if (attr) { - mFont = PageManager::FindResource(attr->value()); + child = node->first_node("font"); + if (child) + { + attr = child->first_attribute("resource"); + if (attr) { + mFont = PageManager::FindResource(attr->value()); gr_getFontDetails(mFont ? mFont->GetResource() : NULL, &mFontHeight, NULL); } - } + } child = node->first_node("text"); - if (child) mText = child->value(); + if (child) mText = child->value(); mLastValue = gui_parse_text(mText); child = node->first_node("data"); @@ -175,7 +176,7 @@ GUIInput::GUIInput(xml_node<>* node) } } - // Load the placement + // Load the placement LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH); SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); @@ -190,17 +191,15 @@ GUIInput::GUIInput(xml_node<>* node) isLocalChange = false; HandleTextLocation(-3); - - return; } GUIInput::~GUIInput() { - if (mInputText) delete mInputText; - if (mBackground) delete mBackground; - if (mCursor) delete mCursor; - if (mFont) delete mFont; - if (mAction) delete mAction; + if (mInputText) delete mInputText; + if (mBackground) delete mBackground; + if (mCursor) delete mCursor; + if (mFont) delete mFont; + if (mAction) delete mAction; } int GUIInput::HandleTextLocation(int x) @@ -209,7 +208,8 @@ int GUIInput::HandleTextLocation(int x) string displayValue, originalValue, insertChar; void* fontResource = NULL; - if (mFont) fontResource = mFont->GetResource(); + if (mFont) + fontResource = mFont->GetResource(); DataManager::GetValue(mVariable, originalValue); displayValue = originalValue; @@ -229,9 +229,10 @@ int GUIInput::HandleTextLocation(int x) mRendered = false; return 0; } - if (skipChars && skipChars < displayValue.size()) { + + if (skipChars && skipChars < displayValue.size()) displayValue.erase(0, skipChars); - } + textWidth = gr_measureEx(displayValue.c_str(), fontResource); mRendered = false; @@ -239,9 +240,9 @@ int GUIInput::HandleTextLocation(int x) if (x < -1000) { // No change in scrolling - if (x == -1003) { + if (x == -1003) mCursorLocation = -1; - } + if (mCursorLocation == -1) { displayValue = originalValue; skipChars = 0; @@ -372,15 +373,15 @@ int GUIInput::HandleTextLocation(int x) int GUIInput::Render(void) { if (!isConditionTrue()) - { - mRendered = false; - return 0; - } + { + mRendered = false; + return 0; + } void* fontResource = NULL; if (mFont) fontResource = mFont->GetResource(); - // First step, fill background + // First step, fill background gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); gr_fill(mRenderX, mRenderY, mRenderW, mRenderH); @@ -394,11 +395,11 @@ int GUIInput::Render(void) int ret = 0; - // Render the text + // Render the text mInputText->SetRenderPos(mRenderX + scrollingX, mFontY); mInputText->SetMaxWidth(mRenderW - scrollingX); - if (mInputText) ret = mInputText->Render(); - if (ret < 0) return ret; + if (mInputText) ret = mInputText->Render(); + if (ret < 0) return ret; if (HasInputFocus && DrawCursor) { // Render the cursor @@ -451,21 +452,21 @@ int GUIInput::Render(void) gr_fill(cursorX, mFontY, CursorWidth, mFontHeight); } - mRendered = true; - return ret; + mRendered = true; + return ret; } int GUIInput::Update(void) { - if (!isConditionTrue()) return (mRendered ? 2 : 0); - if (!mRendered) return 2; + if (!isConditionTrue()) return (mRendered ? 2 : 0); + if (!mRendered) return 2; - int ret = 0; + int ret = 0; - if (mInputText) ret = mInputText->Update(); - if (ret < 0) return ret; + if (mInputText) ret = mInputText->Update(); + if (ret < 0) return ret; - return ret; + return ret; } int GUIInput::GetSelection(int x, int y) @@ -476,14 +477,15 @@ int GUIInput::GetSelection(int x, int y) int GUIInput::NotifyTouch(TOUCH_STATE state, int x, int y) { - static int startSelection = -1; + static int startSelection = -1; int textWidth; string displayValue, originalValue; void* fontResource = NULL; if (mFont) fontResource = mFont->GetResource(); - if (!isConditionTrue()) return -1; + if (!isConditionTrue()) + return -1; if (!HasInputFocus) { if (state != TOUCH_RELEASE) @@ -569,7 +571,7 @@ int GUIInput::NotifyTouch(TOUCH_STATE state, int x, int y) break; } } - return 0; + return 0; } int GUIInput::NotifyVarChange(std::string varName, std::string value) diff --git a/gui/listbox.cpp b/gui/listbox.cpp index 3af40ed5b..a4976f4e1 100644 --- a/gui/listbox.cpp +++ b/gui/listbox.cpp @@ -191,12 +191,12 @@ GUIListBox::GUIListBox(xml_node<>* node) attr = child->first_attribute("highlightcolor"); memset(&mFontHighlightColor, 0, sizeof(COLOR)); - if (attr) - { - std::string color = attr->value(); + if (attr) + { + std::string color = attr->value(); ConvertStrToColor(color, &mFontHighlightColor); hasFontHighlightColor = true; - } + } } // Load the separator if it exists @@ -323,15 +323,15 @@ GUIListBox::GUIListBox(xml_node<>* node) // Get the data for the list child = node->first_node("listitem"); - if (!child) return; + if (!child) return; while (child) - { - ListData data; + { + ListData data; attr = child->first_attribute("name"); - if (!attr) return; - data.displayName = attr->value(); + if (!attr) return; + data.displayName = attr->value(); data.variableValue = child->value(); if (child->value() == currentValue) { @@ -340,10 +340,10 @@ GUIListBox::GUIListBox(xml_node<>* node) data.selected = 0; } - mList.push_back(data); + mList.push_back(data); - child = child->next_sibling("listitem"); - } + child = child->next_sibling("listitem"); + } } GUIListBox::~GUIListBox() @@ -430,21 +430,21 @@ int GUIListBox::Render(void) } if (mList.at(line + mStart).selected != 0) - { - icon = mIconSelected; + { + icon = mIconSelected; currentIconHeight = mSelectedIconHeight; currentIconWidth = mSelectedIconWidth; currentIconOffsetY = SelectedIconOffsetY; currentIconOffsetX = SelectedIconOffsetX; - } - else - { - icon = mIconUnselected; + } + else + { + icon = mIconUnselected; currentIconHeight = mSelectedIconHeight; currentIconWidth = mSelectedIconWidth; currentIconOffsetY = SelectedIconOffsetY; currentIconOffsetX = SelectedIconOffsetX; - } + } if (icon && icon->GetResource()) { @@ -758,8 +758,8 @@ int GUIListBox::NotifyVarChange(std::string varName, std::string value) } } if (varName == mVariable) - { - int i, listSize = mList.size(), selected_index = 0; + { + int i, listSize = mList.size(), selected_index = 0; currentValue = value; @@ -783,8 +783,8 @@ int GUIListBox::NotifyVarChange(std::string varName, std::string value) } mUpdate = 1; - return 0; - } + return 0; + } return 0; } diff --git a/gui/objects.hpp b/gui/objects.hpp index ff5429a9c..8f6f9bbf6 100644 --- a/gui/objects.hpp +++ b/gui/objects.hpp @@ -39,124 +39,123 @@ using namespace rapidxml; class RenderObject { public: - enum Placement { - TOP_LEFT = 0, - TOP_RIGHT = 1, - BOTTOM_LEFT = 2, - BOTTOM_RIGHT = 3, - CENTER = 4, + enum Placement { + TOP_LEFT = 0, + TOP_RIGHT = 1, + BOTTOM_LEFT = 2, + BOTTOM_RIGHT = 3, + CENTER = 4, CENTER_X_ONLY = 5, - }; + }; public: - RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; } - virtual ~RenderObject() {} + RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; } + virtual ~RenderObject() {} public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void) = 0; + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void) = 0; - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void) { return 0; } + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void) { return 0; } - // GetRenderPos - Returns the current position of the object - virtual int GetRenderPos(int& x, int& y, int& w, int& h) { x = mRenderX; y = mRenderY; w = mRenderW; h = mRenderH; return 0; } + // GetRenderPos - Returns the current position of the object + virtual int GetRenderPos(int& x, int& y, int& w, int& h) { x = mRenderX; y = mRenderY; w = mRenderW; h = mRenderH; return 0; } - // SetRenderPos - Update the position of the object - // Return 0 on success, <0 on error - virtual int SetRenderPos(int x, int y, int w = 0, int h = 0) { mRenderX = x; mRenderY = y; if (w || h) { mRenderW = w; mRenderH = h; } return 0; } + // SetRenderPos - Update the position of the object + // Return 0 on success, <0 on error + virtual int SetRenderPos(int x, int y, int w = 0, int h = 0) { mRenderX = x; mRenderY = y; if (w || h) { mRenderW = w; mRenderH = h; } return 0; } - // GetPlacement - Returns the current placement - virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; } + // GetPlacement - Returns the current placement + virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; } - // SetPlacement - Update the current placement - virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; } + // SetPlacement - Update the current placement + virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; } - // SetPageFocus - Notify when a page gains or loses focus - virtual void SetPageFocus(int inFocus) { return; } + // SetPageFocus - Notify when a page gains or loses focus + virtual void SetPageFocus(int inFocus) { return; } protected: - int mRenderX, mRenderY, mRenderW, mRenderH; - Placement mPlacement; + int mRenderX, mRenderY, mRenderW, mRenderH; + Placement mPlacement; }; class ActionObject { public: - ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; } - virtual ~ActionObject() {} + ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; } + virtual ~ActionObject() {} public: - // NotifyTouch - Notify of a touch event - // Return 0 on success, >0 to ignore remainder of touch, and <0 on error - virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; } + // NotifyTouch - Notify of a touch event + // Return 0 on success, >0 to ignore remainder of touch, and <0 on error + virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; } - // NotifyKey - Notify of a key press - // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error - virtual int NotifyKey(int key) { return 1; } + // NotifyKey - Notify of a key press + // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error + virtual int NotifyKey(int key) { return 1; } - // GetRenderPos - Returns the current position of the object - virtual int GetActionPos(int& x, int& y, int& w, int& h) { x = mActionX; y = mActionY; w = mActionW; h = mActionH; return 0; } + // GetRenderPos - Returns the current position of the object + virtual int GetActionPos(int& x, int& y, int& w, int& h) { x = mActionX; y = mActionY; w = mActionW; h = mActionH; return 0; } - // SetRenderPos - Update the position of the object - // Return 0 on success, <0 on error - virtual int SetActionPos(int x, int y, int w = 0, int h = 0); + // SetRenderPos - Update the position of the object + // Return 0 on success, <0 on error + virtual int SetActionPos(int x, int y, int w = 0, int h = 0); - // IsInRegion - Checks if the request is handled by this object - // Return 0 if this object handles the request, 1 if not - virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); } + // IsInRegion - Checks if the request is handled by this object + // Return 0 if this object handles the request, 1 if not + virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); } - // NotifyVarChange - Notify of a variable change - // Returns 0 on success, <0 on error - virtual int NotifyVarChange(std::string varName, std::string value) { return 0; } + // NotifyVarChange - Notify of a variable change + // Returns 0 on success, <0 on error + virtual int NotifyVarChange(std::string varName, std::string value) { return 0; } protected: - int mActionX, mActionY, mActionW, mActionH; + int mActionX, mActionY, mActionW, mActionH; }; class Conditional { public: - Conditional(xml_node<>* node); + Conditional(xml_node<>* node); public: - bool IsConditionVariable(std::string var); - bool isConditionTrue(); - bool isConditionValid(); - void NotifyPageSet(); + bool IsConditionVariable(std::string var); + bool isConditionTrue(); + bool isConditionValid(); + void NotifyPageSet(); protected: - class Condition - { - public: - std::string mVar1; - std::string mVar2; - std::string mCompareOp; - std::string mLastVal; - }; + class Condition + { + public: + std::string mVar1; + std::string mVar2; + std::string mCompareOp; + std::string mLastVal; + }; - std::vector<Condition> mConditions; + std::vector<Condition> mConditions; protected: - bool isMounted(std::string vol); - bool isConditionTrue(Condition* condition); - + bool isMounted(std::string vol); + bool isConditionTrue(Condition* condition); }; class InputObject { public: - InputObject() { HasInputFocus = 0; } - virtual ~InputObject() {} + InputObject() { HasInputFocus = 0; } + virtual ~InputObject() {} public: - // NotifyKeyboard - Notify of keyboard input - // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error - virtual int NotifyKeyboard(int key) { return 1; } + // NotifyKeyboard - Notify of keyboard input + // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error + virtual int NotifyKeyboard(int key) { return 1; } - virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; } + virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; } protected: int HasInputFocus; @@ -165,26 +164,25 @@ protected: // Derived Objects // GUIText - Used for static text class GUIText : public RenderObject, public ActionObject, public Conditional - { public: - // w and h may be ignored, in which case, no bounding box is applied - GUIText(xml_node<>* node); + // w and h may be ignored, in which case, no bounding box is applied + GUIText(xml_node<>* node); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); - // Retrieve the size of the current string (dynamic strings may change per call) - virtual int GetCurrentBounds(int& w, int& h); + // Retrieve the size of the current string (dynamic strings may change per call) + virtual int GetCurrentBounds(int& w, int& h); - // Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + // Notify of a variable change + virtual int NotifyVarChange(std::string varName, std::string value); // Set maximum width in pixels virtual int SetMaxWidth(unsigned width); @@ -196,42 +194,42 @@ public: bool isHighlighted; protected: - std::string mText; - std::string mLastValue; - COLOR mColor; + std::string mText; + std::string mLastValue; + COLOR mColor; COLOR mHighlightColor; - Resource* mFont; - int mIsStatic; - int mVarChanged; - int mFontHeight; + Resource* mFont; + int mIsStatic; + int mVarChanged; + int mFontHeight; unsigned maxWidth; unsigned charSkip; bool hasHighlightColor; protected: - std::string parseText(void); + std::string parseText(void); }; // GUIImage - Used for static image class GUIImage : public RenderObject { public: - GUIImage(xml_node<>* node); + GUIImage(xml_node<>* node); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // SetRenderPos - Update the position of the object - // Return 0 on success, <0 on error - virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); + // SetRenderPos - Update the position of the object + // Return 0 on success, <0 on error + virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); public: bool isHighlighted; protected: - Resource* mImage; + Resource* mImage; Resource* mHighlightImage; }; @@ -239,46 +237,46 @@ protected: class GUIFill : public RenderObject { public: - GUIFill(xml_node<>* node); + GUIFill(xml_node<>* node); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); protected: - COLOR mColor; + COLOR mColor; }; // GUIAction - Used for standard actions class GUIAction : public ActionObject, public Conditional { public: - GUIAction(xml_node<>* node); + GUIAction(xml_node<>* node); public: - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); - virtual int NotifyKey(int key); - virtual int NotifyVarChange(std::string varName, std::string value); + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + virtual int NotifyKey(int key); + virtual int NotifyVarChange(std::string varName, std::string value); virtual int doActions(); protected: - class Action - { - public: - std::string mFunction; - std::string mArg; - }; + class Action + { + public: + std::string mFunction; + std::string mArg; + }; - std::vector<Action> mActions; - int mKey; + std::vector<Action> mActions; + int mKey; protected: - int getKeyByName(std::string key); - virtual int doAction(Action action, int isThreaded = 0); - static void* thread_start(void *cookie); + int getKeyByName(std::string key); + virtual int doAction(Action action, int isThreaded = 0); + static void* thread_start(void *cookie); void simulate_progress_bar(void); - int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache); + int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache); void operation_start(const string operation_name); void operation_end(const int operation_status, const int simulate); static void* command_thread(void *cookie); @@ -287,92 +285,92 @@ protected: class GUIConsole : public RenderObject, public ActionObject { public: - GUIConsole(xml_node<>* node); - -public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); - - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); - - // SetRenderPos - Update the position of the object - // Return 0 on success, <0 on error - virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); - - // IsInRegion - Checks if the request is handled by this object - // Return 0 if this object handles the request, 1 if not - virtual int IsInRegion(int x, int y); - - // NotifyTouch - Notify of a touch event - // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers) - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); - -protected: - enum SlideoutState - { - hidden = 0, - visible, - request_hide, - request_show - }; - Resource* mFont; - Resource* mSlideoutImage; - COLOR mForegroundColor; - COLOR mBackgroundColor; - COLOR mScrollColor; - unsigned int mFontHeight; - int mCurrentLine; - unsigned int mLastCount; - unsigned int mMaxRows; - int mStartY; - int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH; - int mSlideinX, mSlideinY, mSlideinW, mSlideinH; - int mConsoleX, mConsoleY, mConsoleW, mConsoleH; - int mLastTouchX, mLastTouchY; - int mSlideMultiplier; - int mSlideout; - SlideoutState mSlideoutState; - -protected: - virtual int RenderSlideout(void); - virtual int RenderConsole(void); + GUIConsole(xml_node<>* node); + +public: + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); + + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); + + // SetRenderPos - Update the position of the object + // Return 0 on success, <0 on error + virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); + + // IsInRegion - Checks if the request is handled by this object + // Return 0 if this object handles the request, 1 if not + virtual int IsInRegion(int x, int y); + // NotifyTouch - Notify of a touch event + // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers) + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + +protected: + enum SlideoutState + { + hidden = 0, + visible, + request_hide, + request_show + }; + + Resource* mFont; + Resource* mSlideoutImage; + COLOR mForegroundColor; + COLOR mBackgroundColor; + COLOR mScrollColor; + unsigned int mFontHeight; + int mCurrentLine; + unsigned int mLastCount; + unsigned int mMaxRows; + int mStartY; + int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH; + int mSlideinX, mSlideinY, mSlideinW, mSlideinH; + int mConsoleX, mConsoleY, mConsoleW, mConsoleH; + int mLastTouchX, mLastTouchY; + int mSlideMultiplier; + int mSlideout; + SlideoutState mSlideoutState; + +protected: + virtual int RenderSlideout(void); + virtual int RenderConsole(void); }; class GUIButton : public RenderObject, public ActionObject, public Conditional { public: - GUIButton(xml_node<>* node); - virtual ~GUIButton(); + GUIButton(xml_node<>* node); + virtual ~GUIButton(); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); - // SetPos - Update the position of the render object - // Return 0 on success, <0 on error - virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); + // SetPos - Update the position of the render object + // Return 0 on success, <0 on error + virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); - // NotifyTouch - Notify of a touch event - // Return 0 on success, >0 to ignore remainder of touch, and <0 on error - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + // NotifyTouch - Notify of a touch event + // Return 0 on success, >0 to ignore remainder of touch, and <0 on error + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); protected: - GUIImage* mButtonImg; - Resource* mButtonIcon; - GUIText* mButtonLabel; - GUIAction* mAction; - int mTextX, mTextY, mTextW, mTextH; - int mIconX, mIconY, mIconW, mIconH; - bool mRendered; + GUIImage* mButtonImg; + Resource* mButtonIcon; + GUIText* mButtonLabel; + GUIAction* mAction; + int mTextX, mTextY, mTextW, mTextH; + int mIconX, mIconY, mIconW, mIconH; + bool mRendered; bool hasHighlightColor; bool renderHighlight; bool hasFill; @@ -383,103 +381,103 @@ protected: class GUICheckbox: public RenderObject, public ActionObject, public Conditional { public: - GUICheckbox(xml_node<>* node); - virtual ~GUICheckbox(); + GUICheckbox(xml_node<>* node); + virtual ~GUICheckbox(); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); - // SetPos - Update the position of the render object - // Return 0 on success, <0 on error - virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); + // SetPos - Update the position of the render object + // Return 0 on success, <0 on error + virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); - // NotifyTouch - Notify of a touch event - // Return 0 on success, >0 to ignore remainder of touch, and <0 on error - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + // NotifyTouch - Notify of a touch event + // Return 0 on success, >0 to ignore remainder of touch, and <0 on error + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); protected: - Resource* mChecked; - Resource* mUnchecked; - GUIText* mLabel; - int mTextX, mTextY; - int mCheckX, mCheckY, mCheckW, mCheckH; - int mLastState; - bool mRendered; - std::string mVarName; + Resource* mChecked; + Resource* mUnchecked; + GUIText* mLabel; + int mTextX, mTextY; + int mCheckX, mCheckY, mCheckW, mCheckH; + int mLastState; + bool mRendered; + std::string mVarName; }; class GUIFileSelector : public RenderObject, public ActionObject { public: - GUIFileSelector(xml_node<>* node); - virtual ~GUIFileSelector(); + GUIFileSelector(xml_node<>* node); + virtual ~GUIFileSelector(); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); - // NotifyTouch - Notify of a touch event - // Return 0 on success, >0 to ignore remainder of touch, and <0 on error - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + // NotifyTouch - Notify of a touch event + // Return 0 on success, >0 to ignore remainder of touch, and <0 on error + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); - // NotifyVarChange - Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + // NotifyVarChange - Notify of a variable change + virtual int NotifyVarChange(std::string varName, std::string value); - // SetPos - Update the position of the render object - // Return 0 on success, <0 on error - virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); + // SetPos - Update the position of the render object + // Return 0 on success, <0 on error + virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); - // SetPageFocus - Notify when a page gains or loses focus - virtual void SetPageFocus(int inFocus); + // SetPageFocus - Notify when a page gains or loses focus + virtual void SetPageFocus(int inFocus); protected: - struct FileData { - std::string fileName; - unsigned char fileType; // Uses d_type format from struct dirent - mode_t protection; // Uses mode_t format from stat - uid_t userId; - gid_t groupId; - off_t fileSize; - time_t lastAccess; // Uses time_t format from stat - time_t lastModified; // Uses time_t format from stat - time_t lastStatChange; // Uses time_t format from stat - }; + struct FileData { + std::string fileName; + unsigned char fileType; // Uses d_type format from struct dirent + mode_t protection; // Uses mode_t format from stat + uid_t userId; + gid_t groupId; + off_t fileSize; + time_t lastAccess; // Uses time_t format from stat + time_t lastModified; // Uses time_t format from stat + time_t lastStatChange; // Uses time_t format from stat + }; protected: - virtual int GetSelection(int x, int y); + virtual int GetSelection(int x, int y); - virtual int GetFileList(const std::string folder); - static bool fileSort(FileData d1, FileData d2); + virtual int GetFileList(const std::string folder); + static bool fileSort(FileData d1, FileData d2); protected: - std::vector<FileData> mFolderList; - std::vector<FileData> mFileList; - std::string mPathVar; - std::string mExtn; - std::string mVariable; + std::vector<FileData> mFolderList; + std::vector<FileData> mFileList; + std::string mPathVar; + std::string mExtn; + std::string mVariable; std::string mSortVariable; std::string mSelection; std::string mHeaderText; std::string mLastValue; - int actualLineHeight; + int actualLineHeight; int mStart; - int mLineSpacing; + int mLineSpacing; int mSeparatorH; int mHeaderSeparatorH; - int mShowFolders, mShowFiles, mShowNavFolders; - int mUpdate; - int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH; + int mShowFolders, mShowFiles, mShowNavFolders; + int mUpdate; + int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH; int mHeaderH; int mFastScrollW; int mFastScrollLineW; @@ -493,16 +491,16 @@ protected: int scrollingY; int mHeaderIsStatic; int touchDebounce; - unsigned mFontHeight; - unsigned mLineHeight; - int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth; - Resource* mHeaderIcon; + unsigned mFontHeight; + unsigned mLineHeight; + int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth; + Resource* mHeaderIcon; Resource* mFolderIcon; - Resource* mFileIcon; - Resource* mBackground; - Resource* mFont; - COLOR mBackgroundColor; - COLOR mFontColor; + Resource* mFileIcon; + Resource* mBackground; + Resource* mFont; + COLOR mBackgroundColor; + COLOR mFontColor; COLOR mHeaderBackgroundColor; COLOR mHeaderFontColor; COLOR mSeparatorColor; @@ -521,56 +519,56 @@ protected: class GUIListBox : public RenderObject, public ActionObject { public: - GUIListBox(xml_node<>* node); - virtual ~GUIListBox(); + GUIListBox(xml_node<>* node); + virtual ~GUIListBox(); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); - // NotifyTouch - Notify of a touch event - // Return 0 on success, >0 to ignore remainder of touch, and <0 on error - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + // NotifyTouch - Notify of a touch event + // Return 0 on success, >0 to ignore remainder of touch, and <0 on error + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); - // NotifyVarChange - Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + // NotifyVarChange - Notify of a variable change + virtual int NotifyVarChange(std::string varName, std::string value); - // SetPos - Update the position of the render object - // Return 0 on success, <0 on error - virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); + // SetPos - Update the position of the render object + // Return 0 on success, <0 on error + virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); - // SetPageFocus - Notify when a page gains or loses focus - virtual void SetPageFocus(int inFocus); + // SetPageFocus - Notify when a page gains or loses focus + virtual void SetPageFocus(int inFocus); protected: - struct ListData { - std::string displayName; + struct ListData { + std::string displayName; std::string variableValue; unsigned int selected; - }; + }; protected: - virtual int GetSelection(int x, int y); + virtual int GetSelection(int x, int y); protected: - std::vector<ListData> mList; - std::string mVariable; + std::vector<ListData> mList; + std::string mVariable; std::string mSelection; std::string currentValue; std::string mHeaderText; std::string mLastValue; int actualLineHeight; - int mStart; + int mStart; int startY; int mSeparatorH, mHeaderSeparatorH; - int mLineSpacing; - int mUpdate; - int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH; + int mLineSpacing; + int mUpdate; + int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH; int mFastScrollW; int mFastScrollLineW; int mFastScrollRectW; @@ -581,15 +579,15 @@ protected: int scrollingSpeed; int scrollingY; static int mSortOrder; - unsigned mFontHeight; - unsigned mLineHeight; + unsigned mFontHeight; + unsigned mLineHeight; Resource* mHeaderIcon; - Resource* mIconSelected; - Resource* mIconUnselected; - Resource* mBackground; - Resource* mFont; - COLOR mBackgroundColor; - COLOR mFontColor; + Resource* mIconSelected; + Resource* mIconUnselected; + Resource* mBackground; + Resource* mFont; + COLOR mBackgroundColor; + COLOR mFontColor; COLOR mHeaderBackgroundColor; COLOR mHeaderFontColor; COLOR mSeparatorColor; @@ -609,53 +607,51 @@ protected: class GUIPartitionList : public RenderObject, public ActionObject { public: - GUIPartitionList(xml_node<>* node); - virtual ~GUIPartitionList(); + GUIPartitionList(xml_node<>* node); + virtual ~GUIPartitionList(); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); - - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // NotifyTouch - Notify of a touch event - // Return 0 on success, >0 to ignore remainder of touch, and <0 on error - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); - // NotifyVarChange - Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + // NotifyTouch - Notify of a touch event + // Return 0 on success, >0 to ignore remainder of touch, and <0 on error + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); - // SetPos - Update the position of the render object - // Return 0 on success, <0 on error - virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); + // NotifyVarChange - Notify of a variable change + virtual int NotifyVarChange(std::string varName, std::string value); - // SetPageFocus - Notify when a page gains or loses focus - virtual void SetPageFocus(int inFocus); + // SetPos - Update the position of the render object + // Return 0 on success, <0 on error + virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); -protected: + // SetPageFocus - Notify when a page gains or loses focus + virtual void SetPageFocus(int inFocus); protected: - virtual int GetSelection(int x, int y); + virtual int GetSelection(int x, int y); virtual void MatchList(void); protected: - std::vector<PartitionList> mList; + std::vector<PartitionList> mList; std::string ListType; - std::string mVariable; + std::string mVariable; std::string selectedList; std::string currentValue; std::string mHeaderText; std::string mLastValue; int actualLineHeight; - int mStart; + int mStart; int startY; int mSeparatorH, mHeaderSeparatorH; - int mLineSpacing; - int mUpdate; - int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH; + int mLineSpacing; + int mUpdate; + int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH; int mFastScrollW; int mFastScrollLineW; int mFastScrollRectW; @@ -666,15 +662,15 @@ protected: int scrollingSpeed; int scrollingY; static int mSortOrder; - unsigned mFontHeight; - unsigned mLineHeight; + unsigned mFontHeight; + unsigned mLineHeight; Resource* mHeaderIcon; - Resource* mIconSelected; - Resource* mIconUnselected; - Resource* mBackground; - Resource* mFont; - COLOR mBackgroundColor; - COLOR mFontColor; + Resource* mIconSelected; + Resource* mIconUnselected; + Resource* mBackground; + Resource* mFont; + COLOR mBackgroundColor; + COLOR mFontColor; COLOR mHeaderBackgroundColor; COLOR mHeaderFontColor; COLOR mSeparatorColor; @@ -696,87 +692,86 @@ protected: class GUIAnimation : public RenderObject { public: - GUIAnimation(xml_node<>* node); + GUIAnimation(xml_node<>* node); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); protected: - AnimationResource* mAnimation; - int mFrame; - int mFPS; - int mLoop; - int mRender; - int mUpdateCount; + AnimationResource* mAnimation; + int mFrame; + int mFPS; + int mLoop; + int mRender; + int mUpdateCount; }; class GUIProgressBar : public RenderObject, public ActionObject { public: - GUIProgressBar(xml_node<>* node); + GUIProgressBar(xml_node<>* node); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); - // NotifyVarChange - Notify of a variable change - // Returns 0 on success, <0 on error - virtual int NotifyVarChange(std::string varName, std::string value); + // NotifyVarChange - Notify of a variable change + // Returns 0 on success, <0 on error + virtual int NotifyVarChange(std::string varName, std::string value); protected: - Resource* mEmptyBar; - Resource* mFullBar; - std::string mMinValVar; - std::string mMaxValVar; - std::string mCurValVar; - float mSlide; - float mSlideInc; - int mSlideFrames; - int mLastPos; + Resource* mEmptyBar; + Resource* mFullBar; + std::string mMinValVar; + std::string mMaxValVar; + std::string mCurValVar; + float mSlide; + float mSlideInc; + int mSlideFrames; + int mLastPos; protected: - virtual int RenderInternal(void); // Does the actual render - + virtual int RenderInternal(void); // Does the actual render }; class GUISlider : public RenderObject, public ActionObject { public: - GUISlider(xml_node<>* node); - virtual ~GUISlider(); + GUISlider(xml_node<>* node); + virtual ~GUISlider(); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); - // NotifyTouch - Notify of a touch event - // Return 0 on success, >0 to ignore remainder of touch, and <0 on error - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + // NotifyTouch - Notify of a touch event + // Return 0 on success, >0 to ignore remainder of touch, and <0 on error + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); protected: - GUIAction* sAction; - Resource* sSlider; - Resource* sSliderUsed; - Resource* sTouch; - int sTouchW, sTouchH; - int sCurTouchX; - int sUpdate; + GUIAction* sAction; + Resource* sSlider; + Resource* sSliderUsed; + Resource* sTouch; + int sTouchW, sTouchH; + int sCurTouchX; + int sUpdate; }; #define MAX_KEYBOARD_LAYOUTS 5 @@ -799,7 +794,7 @@ class GUIKeyboard : public RenderObject, public ActionObject, public Conditional { public: GUIKeyboard(xml_node<>* node); - virtual ~GUIKeyboard(); + virtual ~GUIKeyboard(); public: virtual int Render(void); @@ -812,12 +807,12 @@ protected: protected: struct keyboard_key_class - { - unsigned char key; + { + unsigned char key; unsigned char longpresskey; - unsigned int end_x; + unsigned int end_x; unsigned int layout; - }; + }; Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS]; struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS]; @@ -836,25 +831,25 @@ protected: class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject { public: - // w and h may be ignored, in which case, no bounding box is applied - GUIInput(xml_node<>* node); + // w and h may be ignored, in which case, no bounding box is applied + GUIInput(xml_node<>* node); virtual ~GUIInput(); public: - // Render - Render the full object to the GL surface - // Return 0 on success, <0 on error - virtual int Render(void); + // Render - Render the full object to the GL surface + // Return 0 on success, <0 on error + virtual int Render(void); - // Update - Update any UI component animations (called <= 30 FPS) - // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error - virtual int Update(void); + // Update - Update any UI component animations (called <= 30 FPS) + // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error + virtual int Update(void); - // Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + // Notify of a variable change + virtual int NotifyVarChange(std::string varName, std::string value); // NotifyTouch - Notify of a touch event - // Return 0 on success, >0 to ignore remainder of touch, and <0 on error - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + // Return 0 on success, >0 to ignore remainder of touch, and <0 on error + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); virtual int NotifyKeyboard(int key); @@ -865,17 +860,17 @@ protected: virtual int HandleTextLocation(int x); protected: - GUIText* mInputText; + GUIText* mInputText; GUIAction* mAction; Resource* mBackground; Resource* mCursor; Resource* mFont; std::string mText; - std::string mLastValue; + std::string mLastValue; std::string mVariable; std::string mMask; std::string mMaskVariable; - COLOR mBackgroundColor; + COLOR mBackgroundColor; COLOR mCursorColor; int scrollingX; int lastX; diff --git a/gui/pages.cpp b/gui/pages.cpp index 86d4dff9f..9aea1b85a 100644 --- a/gui/pages.cpp +++ b/gui/pages.cpp @@ -50,27 +50,28 @@ std::map<std::string, PageSet*> PageManager::mPageSets; PageSet* PageManager::mCurrentSet; PageSet* PageManager::mBaseSet = NULL; - // Helper routine to convert a string to a color declaration int ConvertStrToColor(std::string str, COLOR* color) { - // Set the default, solid black - memset(color, 0, sizeof(COLOR)); - color->alpha = 255; + // Set the default, solid black + memset(color, 0, sizeof(COLOR)); + color->alpha = 255; + + // Translate variables + DataManager::GetValue(str, str); + + // Look for some defaults + if (str == "black") return 0; + else if (str == "white") { color->red = color->green = color->blue = 255; return 0; } + else if (str == "red") { color->red = 255; return 0; } + else if (str == "green") { color->green = 255; return 0; } + else if (str == "blue") { color->blue = 255; return 0; } - // Translate variables - DataManager::GetValue(str, str); - - // Look for some defaults - if (str == "black") return 0; - else if (str == "white") { color->red = color->green = color->blue = 255; return 0; } - else if (str == "red") { color->red = 255; return 0; } - else if (str == "green") { color->green = 255; return 0; } - else if (str == "blue") { color->blue = 255; return 0; } + // At this point, we require an RGB(A) color + if (str[0] != '#') + return -1; - // At this point, we require an RGB(A) color - if (str[0] != '#') return -1; - str.erase(0, 1); + str.erase(0, 1); int result; if (str.size() >= 8) { @@ -95,186 +96,188 @@ int ConvertStrToColor(std::string str, COLOR* color) // Helper APIs bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */) { - if (!node) return false; - - std::string value; - if (node->first_attribute("x")) - { - value = node->first_attribute("x")->value(); - DataManager::GetValue(value, value); - *x = atol(value.c_str()); - } - - if (node->first_attribute("y")) - { - value = node->first_attribute("y")->value(); - DataManager::GetValue(value, value); - *y = atol(value.c_str()); - } - - if (w && node->first_attribute("w")) - { - value = node->first_attribute("w")->value(); - DataManager::GetValue(value, value); - *w = atol(value.c_str()); - } - - if (h && node->first_attribute("h")) - { - value = node->first_attribute("h")->value(); - DataManager::GetValue(value, value); - *h = atol(value.c_str()); - } - - if (placement && node->first_attribute("placement")) - { - value = node->first_attribute("placement")->value(); - DataManager::GetValue(value, value); - *placement = (RenderObject::Placement) atol(value.c_str()); - } - - return true; + if (!node) + return false; + + std::string value; + if (node->first_attribute("x")) + { + value = node->first_attribute("x")->value(); + DataManager::GetValue(value, value); + *x = atol(value.c_str()); + } + + if (node->first_attribute("y")) + { + value = node->first_attribute("y")->value(); + DataManager::GetValue(value, value); + *y = atol(value.c_str()); + } + + if (w && node->first_attribute("w")) + { + value = node->first_attribute("w")->value(); + DataManager::GetValue(value, value); + *w = atol(value.c_str()); + } + + if (h && node->first_attribute("h")) + { + value = node->first_attribute("h")->value(); + DataManager::GetValue(value, value); + *h = atol(value.c_str()); + } + + if (placement && node->first_attribute("placement")) + { + value = node->first_attribute("placement")->value(); + DataManager::GetValue(value, value); + *placement = (RenderObject::Placement) atol(value.c_str()); + } + + return true; } int ActionObject::SetActionPos(int x, int y, int w, int h) { - if (x < 0 || y < 0) return -1; + if (x < 0 || y < 0) + return -1; - mActionX = x; - mActionY = y; - if (w || h) - { - mActionW = w; - mActionH = h; - } - return 0; + mActionX = x; + mActionY = y; + if (w || h) + { + mActionW = w; + mActionH = h; + } + return 0; } Page::Page(xml_node<>* page, xml_node<>* templates /* = NULL */) { - mTouchStart = NULL; + mTouchStart = NULL; - // We can memset the whole structure, because the alpha channel is ignored - memset(&mBackground, 0, sizeof(COLOR)); + // We can memset the whole structure, because the alpha channel is ignored + memset(&mBackground, 0, sizeof(COLOR)); - // With NULL, we make a console-only display - if (!page) - { - mName = "console"; + // With NULL, we make a console-only display + if (!page) + { + mName = "console"; - GUIConsole* element = new GUIConsole(NULL); - mRenders.push_back(element); - mActions.push_back(element); - return; - } + GUIConsole* element = new GUIConsole(NULL); + mRenders.push_back(element); + mActions.push_back(element); + return; + } - if (page->first_attribute("name")) - mName = page->first_attribute("name")->value(); - else - { - LOGERR("No page name attribute found!\n"); - return; - } + if (page->first_attribute("name")) + mName = page->first_attribute("name")->value(); + else + { + LOGERR("No page name attribute found!\n"); + return; + } - LOGINFO("Loading page %s\n", mName.c_str()); + LOGINFO("Loading page %s\n", mName.c_str()); - // This is a recursive routine for template handling - ProcessNode(page, templates); + // This is a recursive routine for template handling + ProcessNode(page, templates); - return; + return; } bool Page::ProcessNode(xml_node<>* page, xml_node<>* templates /* = NULL */, int depth /* = 0 */) { - if (depth == 10) - { - LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n"); - return false; - } - - // Let's retrieve the background value, if any - xml_node<>* bg = page->first_node("background"); - if (bg) - { - xml_attribute<>* attr = bg->first_attribute("color"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mBackground); - } - } - - xml_node<>* child; - child = page->first_node("object"); - while (child) - { - if (!child->first_attribute("type")) - break; - - std::string type = child->first_attribute("type")->value(); - - if (type == "text") - { - GUIText* element = new GUIText(child); - mRenders.push_back(element); - mActions.push_back(element); - } - else if (type == "image") - { - GUIImage* element = new GUIImage(child); - mRenders.push_back(element); - } - else if (type == "fill") - { - GUIFill* element = new GUIFill(child); - mRenders.push_back(element); - } - else if (type == "action") - { - GUIAction* element = new GUIAction(child); - mActions.push_back(element); - } - else if (type == "console") - { - GUIConsole* element = new GUIConsole(child); - mRenders.push_back(element); - mActions.push_back(element); - } - else if (type == "button") - { - GUIButton* element = new GUIButton(child); - mRenders.push_back(element); - mActions.push_back(element); - } - else if (type == "checkbox") - { - GUICheckbox* element = new GUICheckbox(child); - mRenders.push_back(element); - mActions.push_back(element); - } - else if (type == "fileselector") - { - GUIFileSelector* element = new GUIFileSelector(child); - mRenders.push_back(element); - mActions.push_back(element); - } - else if (type == "animation") - { - GUIAnimation* element = new GUIAnimation(child); - mRenders.push_back(element); - } - else if (type == "progressbar") - { - GUIProgressBar* element = new GUIProgressBar(child); - mRenders.push_back(element); - mActions.push_back(element); - } + if (depth == 10) + { + LOGERR("Page processing depth has exceeded 10. Failing out. This is likely a recursive template.\n"); + return false; + } + + // Let's retrieve the background value, if any + xml_node<>* bg = page->first_node("background"); + if (bg) + { + xml_attribute<>* attr = bg->first_attribute("color"); + if (attr) + { + std::string color = attr->value(); + ConvertStrToColor(color, &mBackground); + } + } + + xml_node<>* child; + child = page->first_node("object"); + while (child) + { + if (!child->first_attribute("type")) + break; + + std::string type = child->first_attribute("type")->value(); + + if (type == "text") + { + GUIText* element = new GUIText(child); + mRenders.push_back(element); + mActions.push_back(element); + } + else if (type == "image") + { + GUIImage* element = new GUIImage(child); + mRenders.push_back(element); + } + else if (type == "fill") + { + GUIFill* element = new GUIFill(child); + mRenders.push_back(element); + } + else if (type == "action") + { + GUIAction* element = new GUIAction(child); + mActions.push_back(element); + } + else if (type == "console") + { + GUIConsole* element = new GUIConsole(child); + mRenders.push_back(element); + mActions.push_back(element); + } + else if (type == "button") + { + GUIButton* element = new GUIButton(child); + mRenders.push_back(element); + mActions.push_back(element); + } + else if (type == "checkbox") + { + GUICheckbox* element = new GUICheckbox(child); + mRenders.push_back(element); + mActions.push_back(element); + } + else if (type == "fileselector") + { + GUIFileSelector* element = new GUIFileSelector(child); + mRenders.push_back(element); + mActions.push_back(element); + } + else if (type == "animation") + { + GUIAnimation* element = new GUIAnimation(child); + mRenders.push_back(element); + } + else if (type == "progressbar") + { + GUIProgressBar* element = new GUIProgressBar(child); + mRenders.push_back(element); + mActions.push_back(element); + } else if (type == "slider") - { - GUISlider* element = new GUISlider(child); - mRenders.push_back(element); - mActions.push_back(element); - } + { + GUISlider* element = new GUISlider(child); + mRenders.push_back(element); + mActions.push_back(element); + } else if (type == "slidervalue") { GUISliderValue *element = new GUISliderValue(child); @@ -306,627 +309,651 @@ bool Page::ProcessNode(xml_node<>* page, xml_node<>* templates /* = NULL */, int mRenders.push_back(element); mActions.push_back(element); } - else if (type == "template") - { - if (!templates || !child->first_attribute("name")) - { - LOGERR("Invalid template request.\n"); - } - else - { - std::string name = child->first_attribute("name")->value(); - - // We need to find the correct template - xml_node<>* node; - node = templates->first_node("template"); - - while (node) - { - if (!node->first_attribute("name")) - continue; - - if (name == node->first_attribute("name")->value()) - { - if (!ProcessNode(node, templates, depth + 1)) - return false; - else - break; - } - node = node->next_sibling("template"); - } - } - } - else - { - LOGERR("Unknown object type.\n"); - } - child = child->next_sibling("object"); - } - return true; + else if (type == "template") + { + if (!templates || !child->first_attribute("name")) + { + LOGERR("Invalid template request.\n"); + } + else + { + std::string name = child->first_attribute("name")->value(); + + // We need to find the correct template + xml_node<>* node; + node = templates->first_node("template"); + + while (node) + { + if (!node->first_attribute("name")) + continue; + + if (name == node->first_attribute("name")->value()) + { + if (!ProcessNode(node, templates, depth + 1)) + return false; + else + break; + } + node = node->next_sibling("template"); + } + } + } + else + { + LOGERR("Unknown object type.\n"); + } + child = child->next_sibling("object"); + } + return true; } int Page::Render(void) { - // Render background - gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha); - gr_fill(0, 0, gr_fb_width(), gr_fb_height()); + // Render background + gr_color(mBackground.red, mBackground.green, mBackground.blue, mBackground.alpha); + gr_fill(0, 0, gr_fb_width(), gr_fb_height()); - // Render remaining objects - std::vector<RenderObject*>::iterator iter; - for (iter = mRenders.begin(); iter != mRenders.end(); iter++) - { - if ((*iter)->Render()) - LOGERR("A render request has failed.\n"); - } - return 0; + // Render remaining objects + std::vector<RenderObject*>::iterator iter; + for (iter = mRenders.begin(); iter != mRenders.end(); iter++) + { + if ((*iter)->Render()) + LOGERR("A render request has failed.\n"); + } + return 0; } int Page::Update(void) { - int retCode = 0; + int retCode = 0; - std::vector<RenderObject*>::iterator iter; - for (iter = mRenders.begin(); iter != mRenders.end(); iter++) - { - int ret = (*iter)->Update(); - if (ret < 0) - LOGERR("An update request has failed.\n"); - else if (ret > retCode) - retCode = ret; - } + std::vector<RenderObject*>::iterator iter; + for (iter = mRenders.begin(); iter != mRenders.end(); iter++) + { + int ret = (*iter)->Update(); + if (ret < 0) + LOGERR("An update request has failed.\n"); + else if (ret > retCode) + retCode = ret; + } - return retCode; + return retCode; } int Page::NotifyTouch(TOUCH_STATE state, int x, int y) { - // By default, return 1 to ignore further touches if nobody is listening - int ret = 1; - - // Don't try to handle a lack of handlers - if (mActions.size() == 0) return ret; - - // We record mTouchStart so we can pass all the touch stream to the same handler - if (state == TOUCH_START) - { - std::vector<ActionObject*>::reverse_iterator iter; - // We work backwards, from top-most element to bottom-most element - for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) - { - if ((*iter)->IsInRegion(x, y)) - { - mTouchStart = (*iter); - ret = mTouchStart->NotifyTouch(state, x, y); - if (ret >= 0) break; - mTouchStart = NULL; - } - } - } - else if (state == TOUCH_RELEASE && mTouchStart != NULL) - { - ret = mTouchStart->NotifyTouch(state, x, y); - mTouchStart = NULL; - } - else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL) - { - ret = mTouchStart->NotifyTouch(state, x, y); - } - return ret; + // By default, return 1 to ignore further touches if nobody is listening + int ret = 1; + + // Don't try to handle a lack of handlers + if (mActions.size() == 0) + return ret; + + // We record mTouchStart so we can pass all the touch stream to the same handler + if (state == TOUCH_START) + { + std::vector<ActionObject*>::reverse_iterator iter; + // We work backwards, from top-most element to bottom-most element + for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) + { + if ((*iter)->IsInRegion(x, y)) + { + mTouchStart = (*iter); + ret = mTouchStart->NotifyTouch(state, x, y); + if (ret >= 0) + break; + mTouchStart = NULL; + } + } + } + else if (state == TOUCH_RELEASE && mTouchStart != NULL) + { + ret = mTouchStart->NotifyTouch(state, x, y); + mTouchStart = NULL; + } + else if ((state == TOUCH_DRAG || state == TOUCH_HOLD || state == TOUCH_REPEAT) && mTouchStart != NULL) + { + ret = mTouchStart->NotifyTouch(state, x, y); + } + return ret; } int Page::NotifyKey(int key) { - std::vector<ActionObject*>::reverse_iterator iter; + std::vector<ActionObject*>::reverse_iterator iter; - // Don't try to handle a lack of handlers - if (mActions.size() == 0) return 1; + // Don't try to handle a lack of handlers + if (mActions.size() == 0) + return 1; - // We work backwards, from top-most element to bottom-most element - for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) - { - int ret = (*iter)->NotifyKey(key); - if (ret == 0) - return 0; - else if (ret < 0) - LOGERR("An action handler has returned an error"); - } - return 1; + // We work backwards, from top-most element to bottom-most element + for (iter = mActions.rbegin(); iter != mActions.rend(); iter++) + { + int ret = (*iter)->NotifyKey(key); + if (ret == 0) + return 0; + else if (ret < 0) + LOGERR("An action handler has returned an error"); + } + return 1; } int Page::NotifyKeyboard(int key) { - std::vector<InputObject*>::reverse_iterator iter; + std::vector<InputObject*>::reverse_iterator iter; - // Don't try to handle a lack of handlers - if (mInputs.size() == 0) return 1; + // Don't try to handle a lack of handlers + if (mInputs.size() == 0) + return 1; - // We work backwards, from top-most element to bottom-most element - for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) - { - int ret = (*iter)->NotifyKeyboard(key); - if (ret == 0) - return 0; - else if (ret < 0) - LOGERR("A keyboard handler has returned an error"); - } - return 1; + // We work backwards, from top-most element to bottom-most element + for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) + { + int ret = (*iter)->NotifyKeyboard(key); + if (ret == 0) + return 0; + else if (ret < 0) + LOGERR("A keyboard handler has returned an error"); + } + return 1; } int Page::SetKeyBoardFocus(int inFocus) { - std::vector<InputObject*>::reverse_iterator iter; + std::vector<InputObject*>::reverse_iterator iter; - // Don't try to handle a lack of handlers - if (mInputs.size() == 0) return 1; + // Don't try to handle a lack of handlers + if (mInputs.size() == 0) + return 1; - // We work backwards, from top-most element to bottom-most element - for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) - { - int ret = (*iter)->SetInputFocus(inFocus); - if (ret == 0) - return 0; - else if (ret < 0) - LOGERR("An input focus handler has returned an error"); - } - return 1; + // We work backwards, from top-most element to bottom-most element + for (iter = mInputs.rbegin(); iter != mInputs.rend(); iter++) + { + int ret = (*iter)->SetInputFocus(inFocus); + if (ret == 0) + return 0; + else if (ret < 0) + LOGERR("An input focus handler has returned an error"); + } + return 1; } void Page::SetPageFocus(int inFocus) { - // Render remaining objects - std::vector<RenderObject*>::iterator iter; - for (iter = mRenders.begin(); iter != mRenders.end(); iter++) - { - (*iter)->SetPageFocus(inFocus); - } - return; + // Render remaining objects + std::vector<RenderObject*>::iterator iter; + for (iter = mRenders.begin(); iter != mRenders.end(); iter++) + (*iter)->SetPageFocus(inFocus); + + return; } int Page::NotifyVarChange(std::string varName, std::string value) { - std::vector<ActionObject*>::iterator iter; + std::vector<ActionObject*>::iterator iter; - // Don't try to handle a lack of handlers - if (mActions.size() == 0) return 1; + // Don't try to handle a lack of handlers + if (mActions.size() == 0) + return 1; - for (iter = mActions.begin(); iter != mActions.end(); ++iter) - { - if ((*iter)->NotifyVarChange(varName, value)) - LOGERR("An action handler errored on NotifyVarChange.\n"); - } - return 0; + for (iter = mActions.begin(); iter != mActions.end(); ++iter) + { + if ((*iter)->NotifyVarChange(varName, value)) + LOGERR("An action handler errored on NotifyVarChange.\n"); + } + return 0; } PageSet::PageSet(char* xmlFile) { - mResources = NULL; - mCurrentPage = NULL; - mOverlayPage = NULL; + mResources = NULL; + mCurrentPage = NULL; + mOverlayPage = NULL; - mXmlFile = xmlFile; - if (xmlFile) - mDoc.parse<0>(mXmlFile); - else - mCurrentPage = new Page(NULL); + mXmlFile = xmlFile; + if (xmlFile) + mDoc.parse<0>(mXmlFile); + else + mCurrentPage = new Page(NULL); } PageSet::~PageSet() { - delete mResources; - free(mXmlFile); + delete mResources; + free(mXmlFile); } int PageSet::Load(ZipArchive* package) { - xml_node<>* parent; - xml_node<>* child; - xml_node<>* templates; + xml_node<>* parent; + xml_node<>* child; + xml_node<>* templates; - parent = mDoc.first_node("recovery"); - if (!parent) - parent = mDoc.first_node("install"); + parent = mDoc.first_node("recovery"); + if (!parent) + parent = mDoc.first_node("install"); - // Now, let's parse the XML - LOGINFO("Loading resources...\n"); - child = parent->first_node("resources"); - if (child) - mResources = new ResourceManager(child, package); + // Now, let's parse the XML + LOGINFO("Loading resources...\n"); + child = parent->first_node("resources"); + if (child) + mResources = new ResourceManager(child, package); - LOGINFO("Loading variables...\n"); - child = parent->first_node("variables"); - if (child) - LoadVariables(child); + LOGINFO("Loading variables...\n"); + child = parent->first_node("variables"); + if (child) + LoadVariables(child); - LOGINFO("Loading pages...\n"); - // This may be NULL if no templates are present - templates = parent->first_node("templates"); + LOGINFO("Loading pages...\n"); + // This may be NULL if no templates are present + templates = parent->first_node("templates"); - child = parent->first_node("pages"); - if (!child) - return -1; + child = parent->first_node("pages"); + if (!child) + return -1; - return LoadPages(child, templates); + return LoadPages(child, templates); } int PageSet::SetPage(std::string page) { - Page* tmp = FindPage(page); - if (tmp) - { - if (mCurrentPage) mCurrentPage->SetPageFocus(0); - mCurrentPage = tmp; - mCurrentPage->SetPageFocus(1); - mCurrentPage->NotifyVarChange("", ""); - return 0; - } - else - { - LOGERR("Unable to locate page (%s)\n", page.c_str()); - } - return -1; + Page* tmp = FindPage(page); + if (tmp) + { + if (mCurrentPage) mCurrentPage->SetPageFocus(0); + mCurrentPage = tmp; + mCurrentPage->SetPageFocus(1); + mCurrentPage->NotifyVarChange("", ""); + return 0; + } + else + { + LOGERR("Unable to locate page (%s)\n", page.c_str()); + } + return -1; } int PageSet::SetOverlay(Page* page) { - if (mOverlayPage) mOverlayPage->SetPageFocus(0); - mOverlayPage = page; - if (mOverlayPage) - { - mOverlayPage->SetPageFocus(1); - mOverlayPage->NotifyVarChange("", ""); - } - return 0; + if (mOverlayPage) mOverlayPage->SetPageFocus(0); + mOverlayPage = page; + if (mOverlayPage) + { + mOverlayPage->SetPageFocus(1); + mOverlayPage->NotifyVarChange("", ""); + } + return 0; } Resource* PageSet::FindResource(std::string name) { - return mResources ? mResources->FindResource(name) : NULL; + return mResources ? mResources->FindResource(name) : NULL; } Page* PageSet::FindPage(std::string name) { - std::vector<Page*>::iterator iter; + std::vector<Page*>::iterator iter; - for (iter = mPages.begin(); iter != mPages.end(); iter++) - { - if (name == (*iter)->GetName()) - return (*iter); - } - return NULL; + for (iter = mPages.begin(); iter != mPages.end(); iter++) + { + if (name == (*iter)->GetName()) + return (*iter); + } + return NULL; } int PageSet::LoadVariables(xml_node<>* vars) { - xml_node<>* child; + xml_node<>* child; - child = vars->first_node("variable"); - while (child) - { - if (!child->first_attribute("name")) - break; - if (!child->first_attribute("value")) - break; + child = vars->first_node("variable"); + while (child) + { + if (!child->first_attribute("name")) + break; + if (!child->first_attribute("value")) + break; - DataManager::SetValue(child->first_attribute("name")->value(), child->first_attribute("value")->value()); - child = child->next_sibling("variable"); - } - return 0; + DataManager::SetValue(child->first_attribute("name")->value(), child->first_attribute("value")->value()); + child = child->next_sibling("variable"); + } + return 0; } int PageSet::LoadPages(xml_node<>* pages, xml_node<>* templates /* = NULL */) { - xml_node<>* child; - - if (!pages) return -1; - - child = pages->first_node("page"); - while (child != NULL) - { - Page* page = new Page(child, templates); - if (page->GetName().empty()) - { - LOGERR("Unable to process load page\n"); - delete page; - } - else - { - mPages.push_back(page); - } - child = child->next_sibling("page"); - } - if (mPages.size() > 0) - return 0; - return -1; + xml_node<>* child; + + if (!pages) + return -1; + + child = pages->first_node("page"); + while (child != NULL) + { + Page* page = new Page(child, templates); + if (page->GetName().empty()) + { + LOGERR("Unable to process load page\n"); + delete page; + } + else + { + mPages.push_back(page); + } + child = child->next_sibling("page"); + } + if (mPages.size() > 0) + return 0; + return -1; } int PageSet::IsCurrentPage(Page* page) { - return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); + return ((mCurrentPage && mCurrentPage == page) ? 1 : 0); } int PageSet::Render(void) { - int ret; + int ret; - ret = (mCurrentPage ? mCurrentPage->Render() : -1); - if (ret < 0) return ret; - ret = (mOverlayPage ? mOverlayPage->Render() : -1); - return ret; + ret = (mCurrentPage ? mCurrentPage->Render() : -1); + if (ret < 0) + return ret; + ret = (mOverlayPage ? mOverlayPage->Render() : -1); + return ret; } int PageSet::Update(void) { - int ret; + int ret; - ret = (mCurrentPage ? mCurrentPage->Update() : -1); - if (ret < 0 || ret > 1) return ret; - ret = (mOverlayPage ? mOverlayPage->Update() : -1); - return ret; + ret = (mCurrentPage ? mCurrentPage->Update() : -1); + if (ret < 0 || ret > 1) + return ret; + ret = (mOverlayPage ? mOverlayPage->Update() : -1); + return ret; } int PageSet::NotifyTouch(TOUCH_STATE state, int x, int y) { - if (mOverlayPage) return (mOverlayPage->NotifyTouch(state, x, y)); - return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); + if (mOverlayPage) + return (mOverlayPage->NotifyTouch(state, x, y)); + + return (mCurrentPage ? mCurrentPage->NotifyTouch(state, x, y) : -1); } int PageSet::NotifyKey(int key) { - if (mOverlayPage) return (mOverlayPage->NotifyKey(key)); - return (mCurrentPage ? mCurrentPage->NotifyKey(key) : -1); + if (mOverlayPage) + return (mOverlayPage->NotifyKey(key)); + + return (mCurrentPage ? mCurrentPage->NotifyKey(key) : -1); } int PageSet::NotifyKeyboard(int key) { - if (mOverlayPage) return (mOverlayPage->NotifyKeyboard(key)); - return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1); + if (mOverlayPage) + return (mOverlayPage->NotifyKeyboard(key)); + + return (mCurrentPage ? mCurrentPage->NotifyKeyboard(key) : -1); } int PageSet::SetKeyBoardFocus(int inFocus) { - if (mOverlayPage) return (mOverlayPage->SetKeyBoardFocus(inFocus)); - return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); + if (mOverlayPage) + return (mOverlayPage->SetKeyBoardFocus(inFocus)); + + return (mCurrentPage ? mCurrentPage->SetKeyBoardFocus(inFocus) : -1); } int PageSet::NotifyVarChange(std::string varName, std::string value) { - if (mOverlayPage) mOverlayPage->NotifyVarChange(varName, value); - return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); + if (mOverlayPage) + mOverlayPage->NotifyVarChange(varName, value); + + return (mCurrentPage ? mCurrentPage->NotifyVarChange(varName, value) : -1); } int PageManager::LoadPackage(std::string name, std::string package, std::string startpage) { - int fd; - ZipArchive zip, *pZip = NULL; - long len; - char* xmlFile = NULL; - PageSet* pageSet = NULL; - int ret; - - // Open the XML file - LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); - if (mzOpenZipArchive(package.c_str(), &zip)) - { - // We can try to load the XML directly... - struct stat st; - if(stat(package.c_str(),&st) != 0) - return -1; - - len = st.st_size; - xmlFile = (char*) malloc(len + 1); - if (!xmlFile) return -1; - - fd = open(package.c_str(), O_RDONLY); - if (fd == -1) goto error; - - read(fd, xmlFile, len); - close(fd); - } - else - { - pZip = &zip; - const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml"); - if (ui_xml == NULL) - { - LOGERR("Unable to locate ui.xml in zip file\n"); - goto error; - } - - // Allocate the buffer for the file - len = mzGetZipEntryUncompLen(ui_xml); - xmlFile = (char*) malloc(len + 1); - if (!xmlFile) goto error; - - if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile)) - { - LOGERR("Unable to extract ui.xml\n"); - goto error; - } - } - - // NULL-terminate the string - xmlFile[len] = 0x00; - - // Before loading, mCurrentSet must be the loading package so we can find resources - pageSet = mCurrentSet; - mCurrentSet = new PageSet(xmlFile); - - ret = mCurrentSet->Load(pZip); - if (ret == 0) - { - mCurrentSet->SetPage(startpage); - mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet)); - } - else - { - LOGERR("Package %s failed to load.\n", name.c_str()); - } + int fd; + ZipArchive zip, *pZip = NULL; + long len; + char* xmlFile = NULL; + PageSet* pageSet = NULL; + int ret; + + // Open the XML file + LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); + if (mzOpenZipArchive(package.c_str(), &zip)) + { + // We can try to load the XML directly... + struct stat st; + if(stat(package.c_str(),&st) != 0) + return -1; + + len = st.st_size; + xmlFile = (char*) malloc(len + 1); + if (!xmlFile) + return -1; + + fd = open(package.c_str(), O_RDONLY); + if (fd == -1) + goto error; + + read(fd, xmlFile, len); + close(fd); + } + else + { + pZip = &zip; + const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml"); + if (ui_xml == NULL) + { + LOGERR("Unable to locate ui.xml in zip file\n"); + goto error; + } + + // Allocate the buffer for the file + len = mzGetZipEntryUncompLen(ui_xml); + xmlFile = (char*) malloc(len + 1); + if (!xmlFile) + goto error; - // The first successful package we loaded is the base - if (mBaseSet == NULL) - mBaseSet = mCurrentSet; + if (!mzExtractZipEntryToBuffer(&zip, ui_xml, (unsigned char*) xmlFile)) + { + LOGERR("Unable to extract ui.xml\n"); + goto error; + } + } + + // NULL-terminate the string + xmlFile[len] = 0x00; - mCurrentSet = pageSet; + // Before loading, mCurrentSet must be the loading package so we can find resources + pageSet = mCurrentSet; + mCurrentSet = new PageSet(xmlFile); + + ret = mCurrentSet->Load(pZip); + if (ret == 0) + { + mCurrentSet->SetPage(startpage); + mPageSets.insert(std::pair<std::string, PageSet*>(name, mCurrentSet)); + } + else + { + LOGERR("Package %s failed to load.\n", name.c_str()); + } + + // The first successful package we loaded is the base + if (mBaseSet == NULL) + mBaseSet = mCurrentSet; - if (pZip) mzCloseZipArchive(pZip); - return ret; + mCurrentSet = pageSet; + + if (pZip) + mzCloseZipArchive(pZip); + return ret; error: - LOGERR("An internal error has occurred.\n"); - if (pZip) mzCloseZipArchive(pZip); - if (xmlFile) free(xmlFile); - return -1; + LOGERR("An internal error has occurred.\n"); + if (pZip) + mzCloseZipArchive(pZip); + if (xmlFile) + free(xmlFile); + return -1; } PageSet* PageManager::FindPackage(std::string name) { - std::map<std::string, PageSet*>::iterator iter; + std::map<std::string, PageSet*>::iterator iter; + + iter = mPageSets.find(name); + if (iter != mPageSets.end()) + return (*iter).second; - iter = mPageSets.find(name); - if (iter != mPageSets.end()) - { - return (*iter).second; - } - LOGERR("Unable to locate package %s\n", name.c_str()); - return NULL; + LOGERR("Unable to locate package %s\n", name.c_str()); + return NULL; } PageSet* PageManager::SelectPackage(std::string name) { - LOGINFO("Switching packages (%s)\n", name.c_str()); - PageSet* tmp; + LOGINFO("Switching packages (%s)\n", name.c_str()); + PageSet* tmp; - tmp = FindPackage(name); - if (tmp) - mCurrentSet = tmp; - else - LOGERR("Unable to find package.\n"); + tmp = FindPackage(name); + if (tmp) + mCurrentSet = tmp; + else + LOGERR("Unable to find package.\n"); - return mCurrentSet; + return mCurrentSet; } int PageManager::ReloadPackage(std::string name, std::string package) { - std::map<std::string, PageSet*>::iterator iter; + std::map<std::string, PageSet*>::iterator iter; - iter = mPageSets.find(name); - if (iter == mPageSets.end()) - return -1; + iter = mPageSets.find(name); + if (iter == mPageSets.end()) + return -1; - PageSet* set = (*iter).second; - mPageSets.erase(iter); + PageSet* set = (*iter).second; + mPageSets.erase(iter); - if (LoadPackage(name, package, "main") != 0) - { - LOGERR("Failed to load package.\n"); - mPageSets.insert(std::pair<std::string, PageSet*>(name, set)); - return -1; - } - if (mCurrentSet == set) SelectPackage(name); - delete set; - return 0; + if (LoadPackage(name, package, "main") != 0) + { + LOGERR("Failed to load package.\n"); + mPageSets.insert(std::pair<std::string, PageSet*>(name, set)); + return -1; + } + if (mCurrentSet == set) + SelectPackage(name); + delete set; + return 0; } void PageManager::ReleasePackage(std::string name) { - std::map<std::string, PageSet*>::iterator iter; + std::map<std::string, PageSet*>::iterator iter; - iter = mPageSets.find(name); - if (iter == mPageSets.end()) - return; + iter = mPageSets.find(name); + if (iter == mPageSets.end()) + return; - PageSet* set = (*iter).second; - mPageSets.erase(iter); - delete set; - return; + PageSet* set = (*iter).second; + mPageSets.erase(iter); + delete set; + return; } int PageManager::ChangePage(std::string name) { - DataManager::SetValue("tw_operation_state", 0); - int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1); - return ret; + DataManager::SetValue("tw_operation_state", 0); + int ret = (mCurrentSet ? mCurrentSet->SetPage(name) : -1); + return ret; } int PageManager::ChangeOverlay(std::string name) { - if (name.empty()) - return mCurrentSet->SetOverlay(NULL); - else - { - Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL; - return mCurrentSet->SetOverlay(page); - } + if (name.empty()) + return mCurrentSet->SetOverlay(NULL); + else + { + Page* page = mBaseSet ? mBaseSet->FindPage(name) : NULL; + return mCurrentSet->SetOverlay(page); + } } Resource* PageManager::FindResource(std::string name) { - return (mCurrentSet ? mCurrentSet->FindResource(name) : NULL); + return (mCurrentSet ? mCurrentSet->FindResource(name) : NULL); } Resource* PageManager::FindResource(std::string package, std::string name) { - PageSet* tmp; + PageSet* tmp; - tmp = FindPackage(name); - return (tmp ? tmp->FindResource(name) : NULL); + tmp = FindPackage(name); + return (tmp ? tmp->FindResource(name) : NULL); } int PageManager::SwitchToConsole(void) { - PageSet* console = new PageSet(NULL); + PageSet* console = new PageSet(NULL); - mCurrentSet = console; - return 0; + mCurrentSet = console; + return 0; } int PageManager::IsCurrentPage(Page* page) { - return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0); + return (mCurrentSet ? mCurrentSet->IsCurrentPage(page) : 0); } int PageManager::Render(void) { - return (mCurrentSet ? mCurrentSet->Render() : -1); + return (mCurrentSet ? mCurrentSet->Render() : -1); } int PageManager::Update(void) { - if(blankTimer.IsScreenOff()) - return 0; + if(blankTimer.IsScreenOff()) + return 0; - return (mCurrentSet ? mCurrentSet->Update() : -1); + return (mCurrentSet ? mCurrentSet->Update() : -1); } int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y) { - return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1); + return (mCurrentSet ? mCurrentSet->NotifyTouch(state, x, y) : -1); } int PageManager::NotifyKey(int key) { - return (mCurrentSet ? mCurrentSet->NotifyKey(key) : -1); + return (mCurrentSet ? mCurrentSet->NotifyKey(key) : -1); } int PageManager::NotifyKeyboard(int key) { - return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1); + return (mCurrentSet ? mCurrentSet->NotifyKeyboard(key) : -1); } int PageManager::SetKeyBoardFocus(int inFocus) { - return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1); + return (mCurrentSet ? mCurrentSet->SetKeyBoardFocus(inFocus) : -1); } int PageManager::NotifyVarChange(std::string varName, std::string value) { - return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1); + return (mCurrentSet ? mCurrentSet->NotifyVarChange(varName, value) : -1); } extern "C" void gui_notifyVarChange(const char *name, const char* value) { - if (!gGuiRunning) return; + if (!gGuiRunning) + return; - PageManager::NotifyVarChange(name, value); + PageManager::NotifyVarChange(name, value); } - diff --git a/gui/pages.hpp b/gui/pages.hpp index 2c7173552..c308c1a5c 100644 --- a/gui/pages.hpp +++ b/gui/pages.hpp @@ -4,10 +4,10 @@ #define _PAGES_HEADER_HPP typedef struct { - unsigned char red; - unsigned char green; - unsigned char blue; - unsigned char alpha; + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char alpha; } COLOR; // Utility Functions @@ -26,110 +26,110 @@ class InputObject; class Page { public: - virtual ~Page() {} + virtual ~Page() {} public: - Page(xml_node<>* page, xml_node<>* templates = NULL); - std::string GetName(void) { return mName; } + Page(xml_node<>* page, xml_node<>* templates = NULL); + std::string GetName(void) { return mName; } public: - virtual int Render(void); - virtual int Update(void); - virtual int NotifyTouch(TOUCH_STATE state, int x, int y); - virtual int NotifyKey(int key); + virtual int Render(void); + virtual int Update(void); + virtual int NotifyTouch(TOUCH_STATE state, int x, int y); + virtual int NotifyKey(int key); virtual int NotifyKeyboard(int key); virtual int SetKeyBoardFocus(int inFocus); - virtual int NotifyVarChange(std::string varName, std::string value); - virtual void SetPageFocus(int inFocus); + virtual int NotifyVarChange(std::string varName, std::string value); + virtual void SetPageFocus(int inFocus); protected: - std::string mName; - std::vector<RenderObject*> mRenders; - std::vector<ActionObject*> mActions; + std::string mName; + std::vector<RenderObject*> mRenders; + std::vector<ActionObject*> mActions; std::vector<InputObject*> mInputs; - ActionObject* mTouchStart; - COLOR mBackground; + ActionObject* mTouchStart; + COLOR mBackground; protected: - bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0); + bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0); }; class PageSet { public: - PageSet(char* xmlFile); - virtual ~PageSet(); + PageSet(char* xmlFile); + virtual ~PageSet(); public: - int Load(ZipArchive* package); + int Load(ZipArchive* package); - Page* FindPage(std::string name); - int SetPage(std::string page); + Page* FindPage(std::string name); + int SetPage(std::string page); int SetOverlay(Page* page); - Resource* FindResource(std::string name); + Resource* FindResource(std::string name); - // Helper routine for identifing if we're the current page - int IsCurrentPage(Page* page); + // Helper routine for identifing if we're the current page + int IsCurrentPage(Page* page); - // These are routing routines - int Render(void); - int Update(void); - int NotifyTouch(TOUCH_STATE state, int x, int y); - int NotifyKey(int key); + // These are routing routines + int Render(void); + int Update(void); + int NotifyTouch(TOUCH_STATE state, int x, int y); + int NotifyKey(int key); int NotifyKeyboard(int key); int SetKeyBoardFocus(int inFocus); - int NotifyVarChange(std::string varName, std::string value); + int NotifyVarChange(std::string varName, std::string value); protected: - int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL); - int LoadVariables(xml_node<>* vars); + int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL); + int LoadVariables(xml_node<>* vars); protected: - char* mXmlFile; - xml_document<> mDoc; - ResourceManager* mResources; - std::vector<Page*> mPages; - Page* mCurrentPage; - Page* mOverlayPage; // This is a special case, used for "locking" the screen + char* mXmlFile; + xml_document<> mDoc; + ResourceManager* mResources; + std::vector<Page*> mPages; + Page* mCurrentPage; + Page* mOverlayPage; // This is a special case, used for "locking" the screen }; class PageManager { public: - // Used by GUI - static int LoadPackage(std::string name, std::string package, std::string startpage); - static PageSet* SelectPackage(std::string name); - static int ReloadPackage(std::string name, std::string package); - static void ReleasePackage(std::string name); - - // Used for actions and pages - static int ChangePage(std::string name); + // Used by GUI + static int LoadPackage(std::string name, std::string package, std::string startpage); + static PageSet* SelectPackage(std::string name); + static int ReloadPackage(std::string name, std::string package); + static void ReleasePackage(std::string name); + + // Used for actions and pages + static int ChangePage(std::string name); static int ChangeOverlay(std::string name); - static Resource* FindResource(std::string name); - static Resource* FindResource(std::string package, std::string name); + static Resource* FindResource(std::string name); + static Resource* FindResource(std::string package, std::string name); - // Used for console-only mode - Can be reverted via ChangePage - static int SwitchToConsole(void); + // Used for console-only mode - Can be reverted via ChangePage + static int SwitchToConsole(void); - // Helper to identify if a particular page is the active page - static int IsCurrentPage(Page* page); + // Helper to identify if a particular page is the active page + static int IsCurrentPage(Page* page); - // These are routing routines - static int Render(void); - static int Update(void); - static int NotifyTouch(TOUCH_STATE state, int x, int y); - static int NotifyKey(int key); + // These are routing routines + static int Render(void); + static int Update(void); + static int NotifyTouch(TOUCH_STATE state, int x, int y); + static int NotifyKey(int key); static int NotifyKeyboard(int key); static int SetKeyBoardFocus(int inFocus); - static int NotifyVarChange(std::string varName, std::string value); + static int NotifyVarChange(std::string varName, std::string value); protected: - static PageSet* FindPackage(std::string name); + static PageSet* FindPackage(std::string name); protected: - static std::map<std::string, PageSet*> mPageSets; - static PageSet* mCurrentSet; + static std::map<std::string, PageSet*> mPageSets; + static PageSet* mCurrentSet; static PageSet* mBaseSet; }; diff --git a/gui/partitionlist.cpp b/gui/partitionlist.cpp index 36d5c1609..abe0a38ad 100644 --- a/gui/partitionlist.cpp +++ b/gui/partitionlist.cpp @@ -193,12 +193,12 @@ GUIPartitionList::GUIPartitionList(xml_node<>* node) attr = child->first_attribute("highlightcolor"); memset(&mFontHighlightColor, 0, sizeof(COLOR)); - if (attr) - { - std::string color = attr->value(); + if (attr) + { + std::string color = attr->value(); ConvertStrToColor(color, &mFontHighlightColor); hasFontHighlightColor = true; - } + } } // Load the separator if it exists @@ -433,21 +433,21 @@ int GUIPartitionList::Render(void) } if (mList.at(line + mStart).selected != 0) - { - icon = mIconSelected; + { + icon = mIconSelected; currentIconHeight = mSelectedIconHeight; currentIconWidth = mSelectedIconWidth; currentIconOffsetY = SelectedIconOffsetY; currentIconOffsetX = SelectedIconOffsetX; - } - else - { - icon = mIconUnselected; + } + else + { + icon = mIconUnselected; currentIconHeight = mSelectedIconHeight; currentIconWidth = mSelectedIconWidth; currentIconOffsetY = SelectedIconOffsetY; currentIconOffsetX = SelectedIconOffsetX; - } + } if (icon && icon->GetResource()) { @@ -827,8 +827,8 @@ int GUIPartitionList::NotifyVarChange(std::string varName, std::string value) } } if (varName == mVariable && !mUpdate) - { - if (ListType == "storage") { + { + if (ListType == "storage") { int i, listSize = mList.size(), selected_index = 0; currentValue = value; @@ -856,8 +856,8 @@ int GUIPartitionList::NotifyVarChange(std::string varName, std::string value) } mUpdate = 1; - return 0; - } + return 0; + } return 0; } diff --git a/gui/progressbar.cpp b/gui/progressbar.cpp index dce431508..d53fdc19f 100644 --- a/gui/progressbar.cpp +++ b/gui/progressbar.cpp @@ -27,188 +27,200 @@ extern "C" { GUIProgressBar::GUIProgressBar(xml_node<>* node) { - xml_attribute<>* attr; - xml_node<>* child; - - mEmptyBar = NULL; - mFullBar = NULL; - mLastPos = 0; - mSlide = 0.0; - mSlideInc = 0.0; - - if (!node) - { - LOGERR("GUIProgressBar created without XML node\n"); - return; - } - - child = node->first_node("resource"); - if (child) - { - attr = child->first_attribute("empty"); - if (attr) - mEmptyBar = PageManager::FindResource(attr->value()); - - attr = child->first_attribute("full"); - if (attr) - mFullBar = PageManager::FindResource(attr->value()); - } - - // Load the placement - LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY); - - // Load the data - child = node->first_node("data"); - if (child) - { - attr = child->first_attribute("min"); - if (attr) mMinValVar = attr->value(); - - attr = child->first_attribute("max"); - if (attr) mMaxValVar = attr->value(); - - attr = child->first_attribute("name"); - if (attr) mCurValVar = attr->value(); - } - - if (mEmptyBar && mEmptyBar->GetResource()) - { - mRenderW = gr_get_width(mEmptyBar->GetResource()); - mRenderH = gr_get_height(mEmptyBar->GetResource()); - } - - return; + xml_attribute<>* attr; + xml_node<>* child; + + mEmptyBar = NULL; + mFullBar = NULL; + mLastPos = 0; + mSlide = 0.0; + mSlideInc = 0.0; + + if (!node) + { + LOGERR("GUIProgressBar created without XML node\n"); + return; + } + + child = node->first_node("resource"); + if (child) + { + attr = child->first_attribute("empty"); + if (attr) + mEmptyBar = PageManager::FindResource(attr->value()); + + attr = child->first_attribute("full"); + if (attr) + mFullBar = PageManager::FindResource(attr->value()); + } + + // Load the placement + LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY); + + // Load the data + child = node->first_node("data"); + if (child) + { + attr = child->first_attribute("min"); + if (attr) mMinValVar = attr->value(); + + attr = child->first_attribute("max"); + if (attr) mMaxValVar = attr->value(); + + attr = child->first_attribute("name"); + if (attr) mCurValVar = attr->value(); + } + + if (mEmptyBar && mEmptyBar->GetResource()) + { + mRenderW = gr_get_width(mEmptyBar->GetResource()); + mRenderH = gr_get_height(mEmptyBar->GetResource()); + } + + return; } int GUIProgressBar::Render(void) { - // This handles making sure timing updates occur - Update(); - return RenderInternal(); + // This handles making sure timing updates occur + Update(); + return RenderInternal(); } int GUIProgressBar::RenderInternal(void) { - if (!mEmptyBar || !mEmptyBar->GetResource()) return -1; - if (!mFullBar || !mFullBar->GetResource()) return -1; + if (!mEmptyBar || !mEmptyBar->GetResource()) + return -1; - gr_blit(mEmptyBar->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); - gr_blit(mFullBar->GetResource(), 0, 0, mLastPos, mRenderH, mRenderX, mRenderY); - return 0; + if (!mFullBar || !mFullBar->GetResource()) + return -1; + + gr_blit(mEmptyBar->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); + gr_blit(mFullBar->GetResource(), 0, 0, mLastPos, mRenderH, mRenderX, mRenderY); + return 0; } int GUIProgressBar::Update(void) { - std::string str; - int min, max, cur, pos; - - if (mMinValVar.empty()) min = 0; - else - { - str.clear(); - if (atoi(mMinValVar.c_str()) != 0) str = mMinValVar; - else DataManager::GetValue(mMinValVar, str); - min = atoi(str.c_str()); - } - - if (mMaxValVar.empty()) max = 100; - else - { - str.clear(); - if (atoi(mMaxValVar.c_str()) != 0) str = mMaxValVar; - else DataManager::GetValue(mMaxValVar, str); - max = atoi(str.c_str()); - } - - str.clear(); - DataManager::GetValue(mCurValVar, str); - cur = atoi(str.c_str()); - - // Do slide, if needed - if (mSlideFrames) - { - mSlide += mSlideInc; - mSlideFrames--; - if (cur != (int) mSlide) - { - cur = (int) mSlide; - DataManager::SetValue(mCurValVar, cur); - } - } - - // Normalize to 0 - max -= min; - cur -= min; - min = 0; - - if (cur < min) cur = min; - if (cur > max) cur = max; - - if (max == 0) pos = 0; - else pos = (cur * mRenderW) / max; - - if (pos == mLastPos) return 0; - mLastPos = pos; - if (RenderInternal() != 0) return -1; - return 2; + std::string str; + int min, max, cur, pos; + + if (mMinValVar.empty()) + min = 0; + else + { + str.clear(); + if (atoi(mMinValVar.c_str()) != 0) + str = mMinValVar; + else + DataManager::GetValue(mMinValVar, str); + min = atoi(str.c_str()); + } + + if (mMaxValVar.empty()) + max = 100; + else + { + str.clear(); + if (atoi(mMaxValVar.c_str()) != 0) + str = mMaxValVar; + else + DataManager::GetValue(mMaxValVar, str); + max = atoi(str.c_str()); + } + + str.clear(); + DataManager::GetValue(mCurValVar, str); + cur = atoi(str.c_str()); + + // Do slide, if needed + if (mSlideFrames) + { + mSlide += mSlideInc; + mSlideFrames--; + if (cur != (int) mSlide) + { + cur = (int) mSlide; + DataManager::SetValue(mCurValVar, cur); + } + } + + // Normalize to 0 + max -= min; + cur -= min; + min = 0; + + if (cur < min) cur = min; + if (cur > max) cur = max; + + if (max == 0) pos = 0; + else pos = (cur * mRenderW) / max; + + if (pos == mLastPos) + return 0; + + mLastPos = pos; + + if (RenderInternal() != 0) + return -1; + return 2; } int GUIProgressBar::NotifyVarChange(std::string varName, std::string value) { - static int nextPush = 0; - - if (varName.empty()) - { - nextPush = 0; - mLastPos = 0; - mSlide = 0.0; - mSlideInc = 0.0; - return 0; - } - - if (varName == "ui_progress_portion" || varName == "ui_progress_frames") - { - std::string str; - int cur; - - if (mSlideFrames) - { - mSlide += (mSlideInc * mSlideFrames); - cur = (int) mSlide; - DataManager::SetValue(mCurValVar, cur); - mSlideFrames = 0; - } - - if (nextPush) - { - mSlide += nextPush; - cur = (int) mSlide; - DataManager::SetValue(mCurValVar, cur); - nextPush = 0; - } - - if (varName == "ui_progress_portion") mSlide = atof(value.c_str()); - else - { - mSlideFrames = atol(value.c_str()); - if (mSlideFrames == 0) - { - // We're just holding this progress until the next push - nextPush = mSlide; - } - } - - if (mSlide > 0 && mSlideFrames > 0) - { - // Get the current position - str.clear(); - DataManager::GetValue(mCurValVar, str); - cur = atoi(str.c_str()); - - mSlideInc = (float) mSlide / (float) mSlideFrames; - mSlide = cur; - } - } - return 0; + static int nextPush = 0; + + if (varName.empty()) + { + nextPush = 0; + mLastPos = 0; + mSlide = 0.0; + mSlideInc = 0.0; + return 0; + } + + if (varName == "ui_progress_portion" || varName == "ui_progress_frames") + { + std::string str; + int cur; + + if (mSlideFrames) + { + mSlide += (mSlideInc * mSlideFrames); + cur = (int) mSlide; + DataManager::SetValue(mCurValVar, cur); + mSlideFrames = 0; + } + + if (nextPush) + { + mSlide += nextPush; + cur = (int) mSlide; + DataManager::SetValue(mCurValVar, cur); + nextPush = 0; + } + + if (varName == "ui_progress_portion") mSlide = atof(value.c_str()); + else + { + mSlideFrames = atol(value.c_str()); + if (mSlideFrames == 0) + { + // We're just holding this progress until the next push + nextPush = mSlide; + } + } + + if (mSlide > 0 && mSlideFrames > 0) + { + // Get the current position + str.clear(); + DataManager::GetValue(mCurValVar, str); + cur = atoi(str.c_str()); + + mSlideInc = (float) mSlide / (float) mSlideFrames; + mSlide = cur; + } + } + return 0; } - diff --git a/gui/resources.cpp b/gui/resources.cpp index aaa153303..6babc575c 100644 --- a/gui/resources.cpp +++ b/gui/resources.cpp @@ -32,59 +32,56 @@ extern "C" { Resource::Resource(xml_node<>* node, ZipArchive* pZip) { - if (node && node->first_attribute("name")) - mName = node->first_attribute("name")->value(); + if (node && node->first_attribute("name")) + mName = node->first_attribute("name")->value(); } - -int Resource::ExtractResource(ZipArchive* pZip, - std::string folderName, - std::string fileName, - std::string fileExtn, - std::string destFile) +int Resource::ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile) { - if (!pZip) return -1; + if (!pZip) + return -1; - std::string src = folderName + "/" + fileName + fileExtn; + std::string src = folderName + "/" + fileName + fileExtn; const ZipEntry* binary = mzFindZipEntry(pZip, src.c_str()); - if (binary == NULL) { - return -1; + if (binary == NULL) { + return -1; } - unlink(destFile.c_str()); - int fd = creat(destFile.c_str(), 0666); - if (fd < 0) - return -1; + unlink(destFile.c_str()); + int fd = creat(destFile.c_str(), 0666); + if (fd < 0) + return -1; - int ret = 0; - if (!mzExtractZipEntryToFile(pZip, binary, fd)) - ret = -1; + int ret = 0; + if (!mzExtractZipEntryToFile(pZip, binary, fd)) + ret = -1; - close(fd); - return ret; + close(fd); + return ret; } FontResource::FontResource(xml_node<>* node, ZipArchive* pZip) : Resource(node, pZip) { - std::string file; - - mFont = NULL; - if (!node) return; - - if (node->first_attribute("filename")) - file = node->first_attribute("filename")->value(); - - if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0) - { - mFont = gr_loadFont(TMP_RESOURCE_NAME); - unlink(TMP_RESOURCE_NAME); - } - else - { - mFont = gr_loadFont(file.c_str()); - } + std::string file; + + mFont = NULL; + if (!node) + return; + + if (node->first_attribute("filename")) + file = node->first_attribute("filename")->value(); + + if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0) + { + mFont = gr_loadFont(TMP_RESOURCE_NAME); + unlink(TMP_RESOURCE_NAME); + } + else + { + mFont = gr_loadFont(file.c_str()); + } } FontResource::~FontResource() @@ -94,115 +91,118 @@ FontResource::~FontResource() ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip) : Resource(node, pZip) { - std::string file; + std::string file; - mSurface = NULL; - if (!node) return; + mSurface = NULL; + if (!node) + return; - if (node->first_attribute("filename")) - file = node->first_attribute("filename")->value(); + if (node->first_attribute("filename")) + file = node->first_attribute("filename")->value(); - if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0) - { - res_create_surface(TMP_RESOURCE_NAME, &mSurface); - unlink(TMP_RESOURCE_NAME); - } else if (ExtractResource(pZip, "images", file, "", TMP_RESOURCE_NAME) == 0) - { - // JPG includes the .jpg extension in the filename so extension should be blank + if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0) + { + res_create_surface(TMP_RESOURCE_NAME, &mSurface); + unlink(TMP_RESOURCE_NAME); + } + else if (ExtractResource(pZip, "images", file, "", TMP_RESOURCE_NAME) == 0) + { + // JPG includes the .jpg extension in the filename so extension should be blank res_create_surface(TMP_RESOURCE_NAME, &mSurface); - unlink(TMP_RESOURCE_NAME); - } - else + unlink(TMP_RESOURCE_NAME); + } + else res_create_surface(file.c_str(), &mSurface); } ImageResource::~ImageResource() { - if (mSurface) - res_free_surface(mSurface); + if (mSurface) + res_free_surface(mSurface); } AnimationResource::AnimationResource(xml_node<>* node, ZipArchive* pZip) : Resource(node, pZip) { - std::string file; - int fileNum = 1; - - if (!node) return; - - if (node->first_attribute("filename")) - file = node->first_attribute("filename")->value(); - - for ( ; ; ) - { - std::ostringstream fileName; - fileName << file << std::setfill ('0') << std::setw (3) << fileNum; - - gr_surface surface; - if (pZip) - { - if (ExtractResource(pZip, "images", fileName.str(), ".png", TMP_RESOURCE_NAME) != 0) - break; - - if (res_create_surface(TMP_RESOURCE_NAME, &surface)) - break; - - unlink(TMP_RESOURCE_NAME); - } - else - { - if (res_create_surface(fileName.str().c_str(), &surface)) - break; - } - mSurfaces.push_back(surface); - fileNum++; - } + std::string file; + int fileNum = 1; + + if (!node) + return; + + if (node->first_attribute("filename")) + file = node->first_attribute("filename")->value(); + + for (;;) + { + std::ostringstream fileName; + fileName << file << std::setfill ('0') << std::setw (3) << fileNum; + + gr_surface surface; + if (pZip) + { + if (ExtractResource(pZip, "images", fileName.str(), ".png", TMP_RESOURCE_NAME) != 0) + break; + + if (res_create_surface(TMP_RESOURCE_NAME, &surface)) + break; + + unlink(TMP_RESOURCE_NAME); + } + else + { + if (res_create_surface(fileName.str().c_str(), &surface)) + break; + } + mSurfaces.push_back(surface); + fileNum++; + } } AnimationResource::~AnimationResource() { - std::vector<gr_surface>::iterator it; + std::vector<gr_surface>::iterator it; + + for (it = mSurfaces.begin(); it != mSurfaces.end(); ++it) + res_free_surface(*it); - for (it = mSurfaces.begin(); it != mSurfaces.end(); ++it) - { - res_free_surface(*it); - } - mSurfaces.clear(); + mSurfaces.clear(); } Resource* ResourceManager::FindResource(std::string name) { - std::vector<Resource*>::iterator iter; - - for (iter = mResources.begin(); iter != mResources.end(); iter++) - { - if (name == (*iter)->GetName()) - return (*iter); - } - return NULL; + std::vector<Resource*>::iterator iter; + + for (iter = mResources.begin(); iter != mResources.end(); iter++) + { + if (name == (*iter)->GetName()) + return (*iter); + } + return NULL; } ResourceManager::ResourceManager(xml_node<>* resList, ZipArchive* pZip) { - xml_node<>* child; + xml_node<>* child; - if (!resList) return; + if (!resList) + return; - child = resList->first_node("resource"); - while (child != NULL) - { - xml_attribute<>* attr = child->first_attribute("type"); - if (!attr) - break; + child = resList->first_node("resource"); + while (child != NULL) + { + xml_attribute<>* attr = child->first_attribute("type"); + if (!attr) + break; std::string type = attr->value(); - if (type == "font") - { - FontResource* res = new FontResource(child, pZip); - if (res == NULL || res->GetResource() == NULL) - { - xml_attribute<>* attr_name = child->first_attribute("name"); + if (type == "font") + { + FontResource* res = new FontResource(child, pZip); + if (res == NULL || res->GetResource() == NULL) + { + xml_attribute<>* attr_name = child->first_attribute("name"); if (!attr_name) { std::string res_name = attr_name->value(); @@ -210,19 +210,19 @@ ResourceManager::ResourceManager(xml_node<>* resList, ZipArchive* pZip) } else LOGERR("Resource type (%s) failed to load\n", type.c_str()); - delete res; - } - else - { - mResources.push_back((Resource*) res); - } - } - else if (type == "image") - { + delete res; + } + else + { + mResources.push_back((Resource*) res); + } + } + else if (type == "image") + { ImageResource* res = new ImageResource(child, pZip); - if (res == NULL || res->GetResource() == NULL) - { - xml_attribute<>* attr_name = child->first_attribute("name"); + if (res == NULL || res->GetResource() == NULL) + { + xml_attribute<>* attr_name = child->first_attribute("name"); if (!attr_name) { std::string res_name = attr_name->value(); @@ -230,19 +230,19 @@ ResourceManager::ResourceManager(xml_node<>* resList, ZipArchive* pZip) } else LOGERR("Resource type (%s) failed to load\n", type.c_str()); - delete res; - } - else - { + delete res; + } + else + { mResources.push_back((Resource*) res); - } - } - else if (type == "animation") - { - AnimationResource* res = new AnimationResource(child, pZip); - if (res == NULL || res->GetResource() == NULL) - { - xml_attribute<>* attr_name = child->first_attribute("name"); + } + } + else if (type == "animation") + { + AnimationResource* res = new AnimationResource(child, pZip); + if (res == NULL || res->GetResource() == NULL) + { + xml_attribute<>* attr_name = child->first_attribute("name"); if (!attr_name) { std::string res_name = attr_name->value(); @@ -250,30 +250,28 @@ ResourceManager::ResourceManager(xml_node<>* resList, ZipArchive* pZip) } else LOGERR("Resource type (%s) failed to load\n", type.c_str()); - delete res; - } - else - { - mResources.push_back((Resource*) res); - } - } - else - { - LOGERR("Resource type (%s) not supported.\n", type.c_str()); - } - - child = child->next_sibling("resource"); - } + delete res; + } + else + { + mResources.push_back((Resource*) res); + } + } + else + { + LOGERR("Resource type (%s) not supported.\n", type.c_str()); + } + + child = child->next_sibling("resource"); + } } ResourceManager::~ResourceManager() { - std::vector<Resource*>::iterator iter; + std::vector<Resource*>::iterator iter; - for (iter = mResources.begin(); iter != mResources.end(); iter++) - { - delete *iter; - } - mResources.clear(); -} + for (iter = mResources.begin(); iter != mResources.end(); iter++) + delete *iter; + mResources.clear(); +} diff --git a/gui/resources.hpp b/gui/resources.hpp index 6cb5da263..4e05e4186 100644 --- a/gui/resources.hpp +++ b/gui/resources.hpp @@ -7,24 +7,24 @@ class Resource { public: - Resource(xml_node<>* node, ZipArchive* pZip); - virtual ~Resource() {} + Resource(xml_node<>* node, ZipArchive* pZip); + virtual ~Resource() {} public: - virtual void* GetResource(void) = 0; - std::string GetName(void) { return mName; } + virtual void* GetResource(void) = 0; + std::string GetName(void) { return mName; } private: - std::string mName; + std::string mName; protected: - static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile); + static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile); }; typedef enum { - TOUCH_START = 0, - TOUCH_DRAG = 1, - TOUCH_RELEASE = 2, + TOUCH_START = 0, + TOUCH_DRAG = 1, + TOUCH_RELEASE = 2, TOUCH_HOLD = 3, TOUCH_REPEAT = 4 } TOUCH_STATE; @@ -32,56 +32,55 @@ typedef enum { class FontResource : public Resource { public: - FontResource(xml_node<>* node, ZipArchive* pZip); - virtual ~FontResource(); + FontResource(xml_node<>* node, ZipArchive* pZip); + virtual ~FontResource(); public: - virtual void* GetResource(void) { return mFont; } + virtual void* GetResource(void) { return mFont; } protected: - void* mFont; + void* mFont; }; class ImageResource : public Resource { public: - ImageResource(xml_node<>* node, ZipArchive* pZip); - virtual ~ImageResource(); + ImageResource(xml_node<>* node, ZipArchive* pZip); + virtual ~ImageResource(); public: - virtual void* GetResource(void) { return mSurface; } + virtual void* GetResource(void) { return mSurface; } protected: - gr_surface mSurface; + gr_surface mSurface; }; class AnimationResource : public Resource { public: - AnimationResource(xml_node<>* node, ZipArchive* pZip); - virtual ~AnimationResource(); + AnimationResource(xml_node<>* node, ZipArchive* pZip); + virtual ~AnimationResource(); public: - virtual void* GetResource(void) { return mSurfaces.at(0); } - virtual void* GetResource(int entry) { return mSurfaces.at(entry); } - virtual int GetResourceCount(void) { return mSurfaces.size(); } + virtual void* GetResource(void) { return mSurfaces.at(0); } + virtual void* GetResource(int entry) { return mSurfaces.at(entry); } + virtual int GetResourceCount(void) { return mSurfaces.size(); } protected: - std::vector<gr_surface> mSurfaces; + std::vector<gr_surface> mSurfaces; }; class ResourceManager { public: - ResourceManager(xml_node<>* resList, ZipArchive* pZip); - virtual ~ResourceManager(); + ResourceManager(xml_node<>* resList, ZipArchive* pZip); + virtual ~ResourceManager(); public: - Resource* FindResource(std::string name); + Resource* FindResource(std::string name); private: - std::vector<Resource*> mResources; + std::vector<Resource*> mResources; }; #endif // _RESOURCE_HEADER - diff --git a/gui/slider.cpp b/gui/slider.cpp index 4542d60e1..b46d156f6 100644 --- a/gui/slider.cpp +++ b/gui/slider.cpp @@ -28,143 +28,143 @@ extern "C" { GUISlider::GUISlider(xml_node<>* node) { - xml_attribute<>* attr; - xml_node<>* child; - - sAction = NULL; - sSlider = NULL; - sSliderUsed = NULL; - sTouch = NULL; - sTouchW = 20; - - if (!node) - { - LOGERR("GUISlider created without XML node\n"); - return; - } - - child = node->first_node("resource"); - if (child) - { - attr = child->first_attribute("base"); - if (attr) - sSlider = PageManager::FindResource(attr->value()); - - attr = child->first_attribute("used"); - if (attr) - sSliderUsed = PageManager::FindResource(attr->value()); - - attr = child->first_attribute("touch"); - if (attr) - sTouch = PageManager::FindResource(attr->value()); - } - - // Load the placement + xml_attribute<>* attr; + xml_node<>* child; + + sAction = NULL; + sSlider = NULL; + sSliderUsed = NULL; + sTouch = NULL; + sTouchW = 20; + + if (!node) + { + LOGERR("GUISlider created without XML node\n"); + return; + } + + child = node->first_node("resource"); + if (child) + { + attr = child->first_attribute("base"); + if (attr) + sSlider = PageManager::FindResource(attr->value()); + + attr = child->first_attribute("used"); + if (attr) + sSliderUsed = PageManager::FindResource(attr->value()); + + attr = child->first_attribute("touch"); + if (attr) + sTouch = PageManager::FindResource(attr->value()); + } + + // Load the placement LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY); - if (sSlider && sSlider->GetResource()) - { + if (sSlider && sSlider->GetResource()) + { mRenderW = gr_get_width(sSlider->GetResource()); - mRenderH = gr_get_height(sSlider->GetResource()); - } - if (sTouch && sTouch->GetResource()) - { - sTouchW = gr_get_width(sTouch->GetResource()); // Width of the "touch image" that follows the touch (arrow) - sTouchH = gr_get_height(sTouch->GetResource()); // Height of the "touch image" that follows the touch (arrow) - } - - //LOGINFO("mRenderW: %i mTouchW: %i\n", mRenderW, mTouchW); + mRenderH = gr_get_height(sSlider->GetResource()); + } + if (sTouch && sTouch->GetResource()) + { + sTouchW = gr_get_width(sTouch->GetResource()); // Width of the "touch image" that follows the touch (arrow) + sTouchH = gr_get_height(sTouch->GetResource()); // Height of the "touch image" that follows the touch (arrow) + } + + //LOGINFO("mRenderW: %i mTouchW: %i\n", mRenderW, mTouchW); mActionX = mRenderX; - mActionY = mRenderY; - mActionW = mRenderW; - mActionH = mRenderH; + mActionY = mRenderY; + mActionW = mRenderW; + mActionH = mRenderH; - sAction = new GUIAction(node); + sAction = new GUIAction(node); - sCurTouchX = mRenderX; - sUpdate = 1; - - return; + sCurTouchX = mRenderX; + sUpdate = 1; } GUISlider::~GUISlider() { - delete sAction; + delete sAction; } int GUISlider::Render(void) { - if (!sSlider || !sSlider->GetResource()) return -1; + if (!sSlider || !sSlider->GetResource()) + return -1; - // Draw the slider - gr_blit(sSlider->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); + // Draw the slider + gr_blit(sSlider->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); - // Draw the used - if (sSliderUsed && sSliderUsed->GetResource() && sCurTouchX > mRenderX) - { - gr_blit(sSliderUsed->GetResource(), 0, 0, sCurTouchX - mRenderX, mRenderH, mRenderX, mRenderY); - } + // Draw the used + if (sSliderUsed && sSliderUsed->GetResource() && sCurTouchX > mRenderX) + gr_blit(sSliderUsed->GetResource(), 0, 0, sCurTouchX - mRenderX, mRenderH, mRenderX, mRenderY); - // Draw the touch icon - if (sTouch && sTouch->GetResource()) - { - gr_blit(sTouch->GetResource(), 0, 0, sTouchW, sTouchH, sCurTouchX, (mRenderY + ((mRenderH - sTouchH) / 2))); - } + // Draw the touch icon + if (sTouch && sTouch->GetResource()) + gr_blit(sTouch->GetResource(), 0, 0, sTouchW, sTouchH, sCurTouchX, (mRenderY + ((mRenderH - sTouchH) / 2))); - sUpdate = 0; - return 0; + sUpdate = 0; + return 0; } int GUISlider::Update(void) { - if (sUpdate) return 2; - return 0; + if (sUpdate) + return 2; + return 0; } int GUISlider::NotifyTouch(TOUCH_STATE state, int x, int y) { - static bool dragging = false; + static bool dragging = false; switch (state) - { - case TOUCH_START: - if (x >= mRenderX && x <= mRenderX + sTouchW && - y >= mRenderY && y <= mRenderY + mRenderH) - { - sCurTouchX = x - (sTouchW / 2); - if (sCurTouchX < mRenderX) sCurTouchX = mRenderX; - dragging = true; - } - break; - - case TOUCH_DRAG: - if (!dragging) return 0; - if (y < mRenderY - sTouchH || y > mRenderY + (sTouchH * 2)) - { - sCurTouchX = mRenderX; - dragging = false; - sUpdate = 1; - break; - } - sCurTouchX = x - (sTouchW / 2); - if (sCurTouchX < mRenderX) sCurTouchX = mRenderX; - if (sCurTouchX > mRenderX + mRenderW - sTouchW) sCurTouchX = mRenderX + mRenderW - sTouchW; - sUpdate = 1; - break; - - case TOUCH_RELEASE: - if (!dragging) return 0; - if (sCurTouchX >= mRenderX + mRenderW - sTouchW) - { - sAction->doActions(); - } - sCurTouchX = mRenderX; - dragging = false; - sUpdate = 1; + { + case TOUCH_START: + if (x >= mRenderX && x <= mRenderX + sTouchW && + y >= mRenderY && y <= mRenderY + mRenderH) + { + sCurTouchX = x - (sTouchW / 2); + if (sCurTouchX < mRenderX) + sCurTouchX = mRenderX; + dragging = true; + } + break; + + case TOUCH_DRAG: + if (!dragging) + return 0; + if (y < mRenderY - sTouchH || y > mRenderY + (sTouchH * 2)) + { + sCurTouchX = mRenderX; + dragging = false; + sUpdate = 1; + break; + } + sCurTouchX = x - (sTouchW / 2); + if (sCurTouchX < mRenderX) + sCurTouchX = mRenderX; + if (sCurTouchX > mRenderX + mRenderW - sTouchW) + sCurTouchX = mRenderX + mRenderW - sTouchW; + sUpdate = 1; + break; + + case TOUCH_RELEASE: + if (!dragging) + return 0; + + if (sCurTouchX >= mRenderX + mRenderW - sTouchW) + sAction->doActions(); + + sCurTouchX = mRenderX; + dragging = false; + sUpdate = 1; case TOUCH_REPEAT: case TOUCH_HOLD: - break; - } - return 0; + break; + } + return 0; } - diff --git a/gui/text.cpp b/gui/text.cpp index 46a6622e2..7eb6c18b4 100644 --- a/gui/text.cpp +++ b/gui/text.cpp @@ -26,116 +26,119 @@ extern "C" { #include "objects.hpp" GUIText::GUIText(xml_node<>* node) - : Conditional(node) + : Conditional(node) { - xml_attribute<>* attr; - xml_node<>* child; + xml_attribute<>* attr; + xml_node<>* child; - mFont = NULL; - mIsStatic = 1; - mVarChanged = 0; - mFontHeight = 0; + mFont = NULL; + mIsStatic = 1; + mVarChanged = 0; + mFontHeight = 0; maxWidth = 0; charSkip = 0; isHighlighted = false; hasHighlightColor = false; - if (!node) return; + if (!node) + return; - // Initialize color to solid black - memset(&mColor, 0, sizeof(COLOR)); - mColor.alpha = 255; + // Initialize color to solid black + memset(&mColor, 0, sizeof(COLOR)); + mColor.alpha = 255; memset(&mHighlightColor, 0, sizeof(COLOR)); - mHighlightColor.alpha = 255; - - attr = node->first_attribute("color"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mColor); - } + mHighlightColor.alpha = 255; + + attr = node->first_attribute("color"); + if (attr) + { + std::string color = attr->value(); + ConvertStrToColor(color, &mColor); + } attr = node->first_attribute("highlightcolor"); - if (attr) - { - std::string color = attr->value(); + if (attr) + { + std::string color = attr->value(); ConvertStrToColor(color, &mHighlightColor); hasHighlightColor = true; - } - - // Load the font, and possibly override the color - child = node->first_node("font"); - if (child) - { - attr = child->first_attribute("resource"); - if (attr) - mFont = PageManager::FindResource(attr->value()); - - attr = child->first_attribute("color"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mColor); - } + } + + // Load the font, and possibly override the color + child = node->first_node("font"); + if (child) + { + attr = child->first_attribute("resource"); + if (attr) + mFont = PageManager::FindResource(attr->value()); + + attr = child->first_attribute("color"); + if (attr) + { + std::string color = attr->value(); + ConvertStrToColor(color, &mColor); + } attr = child->first_attribute("highlightcolor"); - if (attr) - { - std::string color = attr->value(); + if (attr) + { + std::string color = attr->value(); ConvertStrToColor(color, &mHighlightColor); hasHighlightColor = true; - } - } + } + } - // Load the placement - LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH, &mPlacement); + // Load the placement + LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, &mRenderW, &mRenderH, &mPlacement); - child = node->first_node("text"); - if (child) mText = child->value(); + child = node->first_node("text"); + if (child) mText = child->value(); - // Simple way to check for static state - mLastValue = parseText(); - if (mLastValue != mText) mIsStatic = 0; + // Simple way to check for static state + mLastValue = parseText(); + if (mLastValue != mText) mIsStatic = 0; - gr_getFontDetails(mFont ? mFont->GetResource() : NULL, (unsigned*) &mFontHeight, NULL); - return; + gr_getFontDetails(mFont ? mFont->GetResource() : NULL, (unsigned*) &mFontHeight, NULL); + return; } int GUIText::Render(void) { - if (!isConditionTrue()) return 0; + if (!isConditionTrue()) + return 0; - void* fontResource = NULL; + void* fontResource = NULL; string displayValue; - if (mFont) fontResource = mFont->GetResource(); + if (mFont) + fontResource = mFont->GetResource(); - mLastValue = parseText(); + mLastValue = parseText(); displayValue = mLastValue; if (charSkip) displayValue.erase(0, charSkip); - mVarChanged = 0; - - int x = mRenderX, y = mRenderY; - int width = gr_measureEx(displayValue.c_str(), fontResource); - - if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT) - { - if (mPlacement == CENTER || mPlacement == CENTER_X_ONLY) - x -= (width / 2); - else - x -= width; - } - if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT) - { - if (mPlacement == CENTER) - y -= (mFontHeight / 2); - else if (mPlacement == BOTTOM_LEFT || mPlacement == BOTTOM_RIGHT) - y -= mFontHeight; - } - - if (hasHighlightColor && isHighlighted) + mVarChanged = 0; + + int x = mRenderX, y = mRenderY; + int width = gr_measureEx(displayValue.c_str(), fontResource); + + if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT) + { + if (mPlacement == CENTER || mPlacement == CENTER_X_ONLY) + x -= (width / 2); + else + x -= width; + } + if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT) + { + if (mPlacement == CENTER) + y -= (mFontHeight / 2); + else if (mPlacement == BOTTOM_LEFT || mPlacement == BOTTOM_RIGHT) + y -= mFontHeight; + } + + if (hasHighlightColor && isHighlighted) gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha); else gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha); @@ -144,82 +147,85 @@ int GUIText::Render(void) gr_textExW(x, y, displayValue.c_str(), fontResource, maxWidth + x); else gr_textEx(x, y, displayValue.c_str(), fontResource); - return 0; + return 0; } int GUIText::Update(void) { - if (!isConditionTrue()) return 0; + if (!isConditionTrue()) + return 0; - static int updateCounter = 3; + static int updateCounter = 3; - // This hack just makes sure we update at least once a minute for things like clock and battery - if (updateCounter) updateCounter--; - else - { - mVarChanged = 1; - updateCounter = 3; - } + // This hack just makes sure we update at least once a minute for things like clock and battery + if (updateCounter) updateCounter--; + else + { + mVarChanged = 1; + updateCounter = 3; + } - if (mIsStatic || !mVarChanged) return 0; + if (mIsStatic || !mVarChanged) + return 0; - std::string newValue = parseText(); - if (mLastValue == newValue) + std::string newValue = parseText(); + if (mLastValue == newValue) return 0; else mLastValue = newValue; - return 2; + return 2; } int GUIText::GetCurrentBounds(int& w, int& h) { - void* fontResource = NULL; + void* fontResource = NULL; - if (mFont) fontResource = mFont->GetResource(); + if (mFont) + fontResource = mFont->GetResource(); - h = mFontHeight; + h = mFontHeight; mLastValue = parseText(); - w = gr_measureEx(mLastValue.c_str(), fontResource); - return 0; + w = gr_measureEx(mLastValue.c_str(), fontResource); + return 0; } std::string GUIText::parseText(void) { - static int counter = 0; - std::string str = mText; - size_t pos = 0; - size_t next = 0, end = 0; - - while (1) - { - next = str.find('%', pos); - if (next == std::string::npos) return str; - end = str.find('%', next + 1); - if (end == std::string::npos) return str; - - // We have a block of data - std::string var = str.substr(next + 1, (end - next) - 1); - str.erase(next, (end - next) + 1); - - if (next + 1 == end) - { - str.insert(next, 1, '%'); - } - else - { - std::string value; - if (DataManager::GetValue(var, value) == 0) - str.insert(next, value); - } - - pos = next + 1; - } + static int counter = 0; + std::string str = mText; + size_t pos = 0; + size_t next = 0, end = 0; + + while (1) + { + next = str.find('%', pos); + if (next == std::string::npos) return str; + end = str.find('%', next + 1); + if (end == std::string::npos) return str; + + // We have a block of data + std::string var = str.substr(next + 1, (end - next) - 1); + str.erase(next, (end - next) + 1); + + if (next + 1 == end) + { + str.insert(next, 1, '%'); + } + else + { + std::string value; + if (DataManager::GetValue(var, value) == 0) + str.insert(next, value); + } + + pos = next + 1; + } } int GUIText::NotifyVarChange(std::string varName, std::string value) { - mVarChanged = 1; - return 0; + mVarChanged = 1; + return 0; } int GUIText::SetMaxWidth(unsigned width) |