diff --git a/app/include/gui.h b/app/include/gui.h index a8d9924..9b324b9 100644 --- a/app/include/gui.h +++ b/app/include/gui.h @@ -34,33 +34,33 @@ typedef struct { extern bool g_running; namespace GUI { - void ResetCheckbox(MenuItem *item); - void GetStorageSize(MenuItem *item); + void ResetCheckbox(MenuItem &itemitem); + void GetStorageSize(MenuItem &itemitem); void DisplayStatusBar(void); void ProgressBar(const std::string &title, std::string message, u64 offset, u64 size); int RenderLoop(void); - void HandleMenubarAnim(float *delta_time); + void HandleMenubarAnim(float &delta); void DisplayMenubar(void); - void ControlMenubar(MenuItem *item, int *ctrl); + void ControlMenubar(MenuItem &itemitem, int &ctrl); - void DisplayFileBrowser(MenuItem *item); - void ControlFileBrowser(MenuItem *item, int *ctrl); + void DisplayFileBrowser(MenuItem &itemitem); + void ControlFileBrowser(MenuItem &itemitem, int &ctrl); - void DisplayFileOptions(MenuItem *item); - void ControlFileOptions(MenuItem *item, int *ctrl); + void DisplayFileOptions(MenuItem &itemitem); + void ControlFileOptions(MenuItem &itemitem, int &ctrl); - void DisplayFileProperties(MenuItem *item); - void ControlFileProperties(MenuItem *item); + void DisplayFileProperties(MenuItem &itemitem); + void ControlFileProperties(MenuItem &itemitem); void DisplayDeleteOptions(void); - void ControlDeleteOptions(MenuItem *item, int *ctrl); + void ControlDeleteOptions(MenuItem &itemitem, int &ctrl); - void DisplaySettings(MenuItem *item); - void ControlSettings(MenuItem *item, int *ctrl); + void DisplaySettings(MenuItem &itemitem); + void ControlSettings(MenuItem &itemitem, int &ctrl); - void DisplayImageViewer(MenuItem *item); - void ControlImageViewer(MenuItem *item, float *delta_time); + void DisplayImageViewer(MenuItem &itemitem); + void ControlImageViewer(MenuItem &itemitem, float &delta); } #endif diff --git a/app/source/gui.cpp b/app/source/gui.cpp index 0ce667c..cfcdd75 100644 --- a/app/source/gui.cpp +++ b/app/source/gui.cpp @@ -14,18 +14,18 @@ namespace GUI { static MenuItem item; - void ResetCheckbox(MenuItem *item) { - item->checked.clear(); - item->checked_copy.clear(); - item->checked.resize(item->entries.size()); - item->checked.assign(item->checked.size(), false); - item->checked_cwd.clear(); - item->checked_count = 0; + void ResetCheckbox(MenuItem &itemitem) { + item.checked.clear(); + item.checked_copy.clear(); + item.checked.resize(item.entries.size()); + item.checked.assign(item.checked.size(), false); + item.checked_cwd.clear(); + item.checked_count = 0; }; - void GetStorageSize(MenuItem *item) { - item->total_storage = Utils::GetTotalStorage(); - item->used_storage = Utils::GetUsedStorage(); + void GetStorageSize(MenuItem &itemitem) { + item.total_storage = Utils::GetTotalStorage(); + item.used_storage = Utils::GetUsedStorage(); } void DisplayStatusBar(void) { @@ -61,7 +61,7 @@ namespace GUI { G2D::DrawRect(0, 18, 480, 34, MENU_BAR_COLOUR); G2D::DrawImageScale(icon_nav_drawer, 5, 24, 26.f, 26.f); GUI::DisplayStatusBar(); - GUI::DisplayFileBrowser(&item); + GUI::DisplayFileBrowser(item); G2D::DrawRect(0, 18, 480, 254, G2D_RGBA(0, 0, 0, cfg.dark_theme? 50 : 80)); G2D::DrawImage(dialog[cfg.dark_theme], ((480 - (dialog[0]->w)) / 2), ((272 - (dialog[0]->h)) / 2)); @@ -84,21 +84,24 @@ namespace GUI { if (R_FAILED(ret = FS::GetDirList(cfg.cwd, item.entries))) return ret; - GUI::ResetCheckbox(&item); - GUI::GetStorageSize(&item); - - u64 last = 0; - u32 tick = sceRtcGetTickResolution(); - sceRtcGetCurrentTick(&last); + GUI::ResetCheckbox(item); + GUI::GetStorageSize(item); Colours::Get(); + + // Delta time + u64 last_tick = 0; + float resolution = sceRtcGetTickResolution() / 1000.f; + sceRtcGetCurrentTick(&last_tick); while(g_running) { - u64 current = 0; - sceRtcGetCurrentTick(¤t); - - float delta_time = (current - last) / static_cast(tick); - last = current; + u64 current_tick = 0; + sceRtcGetCurrentTick(¤t_tick); + float delta = (current_tick - last_tick) / resolution; + last_tick = current_tick; + + if (delta < 0.001f) + delta = 0.001f; int ctrl = Utils::ReadControls(); @@ -107,42 +110,42 @@ namespace GUI { G2D::DrawRect(0, 18, 480, 34, MENU_BAR_COLOUR); GUI::DisplayStatusBar(); G2D::DrawImageScale(icon_nav_drawer, 5, 24, 26.f, 26.f); - GUI::DisplayFileBrowser(&item); + GUI::DisplayFileBrowser(item); switch(item.state) { case MENU_STATE_MENUBAR: - GUI::HandleMenubarAnim(&delta_time); + GUI::HandleMenubarAnim(delta); GUI::DisplayMenubar(); - GUI::ControlMenubar(&item, &ctrl); + GUI::ControlMenubar(item, ctrl); break; case MENU_STATE_FILEBROWSER: - GUI::ControlFileBrowser(&item, &ctrl); + GUI::ControlFileBrowser(item, ctrl); break; case MENU_STATE_OPTIONS: - GUI::DisplayFileOptions(&item); - GUI::ControlFileOptions(&item, &ctrl); + GUI::DisplayFileOptions(item); + GUI::ControlFileOptions(item, ctrl); break; case MENU_STATE_PROPERTIES: - GUI::DisplayFileProperties(&item); - GUI::ControlFileProperties(&item); + GUI::DisplayFileProperties(item); + GUI::ControlFileProperties(item); break; case MENU_STATE_DELETE: GUI::DisplayDeleteOptions(); - GUI::ControlDeleteOptions(&item, &ctrl); + GUI::ControlDeleteOptions(item, ctrl); break; case MENU_STATE_SETTINGS: - GUI::DisplaySettings(&item); - GUI::ControlSettings(&item, &ctrl); + GUI::DisplaySettings(item); + GUI::ControlSettings(item, ctrl); break; case MENU_STATE_IMAGEVIEWER: - GUI::DisplayImageViewer(&item); - GUI::ControlImageViewer(&item, &delta_time); + GUI::DisplayImageViewer(item); + GUI::ControlImageViewer(item, delta); break; default: diff --git a/app/source/gui/delete.cpp b/app/source/gui/delete.cpp index 3344eda..ee5e069 100644 --- a/app/source/gui/delete.cpp +++ b/app/source/gui/delete.cpp @@ -7,14 +7,14 @@ #include "utils.h" namespace Options { - void Delete(MenuItem *item, int *selection) { + void Delete(MenuItem &item, int *selection) { int ret = 0; - if ((item->checked_count > 1) && (!item->checked_cwd.compare(cfg.cwd))) { - for (u32 i = 0; i < item->checked.size(); i++) { - if (item->checked.at(i)) { - if (R_FAILED(ret = FS::Delete(item->entries[i]))) { - FS::GetDirList(cfg.cwd, item->entries); + if ((item.checked_count > 1) && (!item.checked_cwd.compare(cfg.cwd))) { + for (u32 i = 0; i < item.checked.size(); i++) { + if (item.checked.at(i)) { + if (R_FAILED(ret = FS::Delete(item.entries[i]))) { + FS::GetDirList(cfg.cwd, item.entries); GUI::ResetCheckbox(item); break; } @@ -22,17 +22,17 @@ namespace Options { } } else - ret = FS::Delete(item->entries[item->selected]); + ret = FS::Delete(item.entries[item.selected]); if (R_SUCCEEDED(ret)) { - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); GUI::ResetCheckbox(item); } GUI::GetStorageSize(item); *selection = 0; - item->selected = 0; - item->state = MENU_STATE_FILEBROWSER; + item.selected = 0; + item.state = MENU_STATE_FILEBROWSER; } } @@ -62,21 +62,21 @@ namespace GUI { G2D::DrawText(((480 - (prompt_width)) / 2), ((272 - (dialog[0]->h)) / 2) + 60, prompt.c_str()); } - void ControlDeleteOptions(MenuItem *item, int *ctrl) { - if (*ctrl & PSP_CTRL_RIGHT) + void ControlDeleteOptions(MenuItem &item, int &ctrl) { + if (ctrl & PSP_CTRL_RIGHT) selection++; - else if (*ctrl & PSP_CTRL_LEFT) + else if (ctrl & PSP_CTRL_LEFT) selection--; if (Utils::IsButtonPressed(PSP_CTRL_ENTER)) { if (selection == 1) Options::Delete(item, &selection); else - item->state = MENU_STATE_OPTIONS; + item.state = MENU_STATE_OPTIONS; } else if (Utils::IsButtonPressed(PSP_CTRL_CANCEL)) - item->state = MENU_STATE_OPTIONS; + item.state = MENU_STATE_OPTIONS; Utils::SetBounds(selection, 0, 1); } diff --git a/app/source/gui/filebrowser.cpp b/app/source/gui/filebrowser.cpp index fc8e02a..7a75332 100644 --- a/app/source/gui/filebrowser.cpp +++ b/app/source/gui/filebrowser.cpp @@ -21,35 +21,35 @@ namespace GUI { static const std::string empty_dir = "This is an empty directory"; - void DisplayFileBrowser(MenuItem *item) { + void DisplayFileBrowser(MenuItem &item) { G2D::FontSetStyle(1.f, WHITE, INTRAFONT_ALIGN_LEFT); float height = G2D::GetTextHeight(); intraFontPrintf(font, 40, 36, cfg.cwd.length() > 42? "%.42s..." : "%s", cfg.cwd.c_str()); G2D::DrawRect(40, 43, 400, 3, SELECTOR_COLOUR); if ((device == BROWSE_STATE_INTERNAL) || (device == BROWSE_STATE_EXTERNAL)) { - float fill = (static_cast(item->used_storage)/static_cast(item->total_storage)) * 400.f; + float fill = (static_cast(item.used_storage)/static_cast(item.total_storage)) * 400.f; G2D::DrawRect(40, 43, fill, 3, TITLE_COLOUR); } - if (item->entries.empty()) { + if (item.entries.empty()) { G2D::FontSetStyle(1.f, cfg.dark_theme? WHITE : BLACK, INTRAFONT_ALIGN_CENTER); G2D::DrawText(240, 136, empty_dir.c_str()); } - for (u32 i = start; i < item->entries.size(); i++) { - std::string filename = item->entries[i].d_name; + for (u32 i = start; i < item.entries.size(); i++) { + std::string filename = item.entries[i].d_name; - if (i == static_cast(item->selected)) + if (i == static_cast(item.selected)) G2D::DrawRect(0, start_y + (sel_dist * (i - start)), 480, sel_dist, SELECTOR_COLOUR); - if ((item->checked[i]) && (!item->checked_cwd.compare(cfg.cwd))) + if ((item.checked[i]) && (!item.checked_cwd.compare(cfg.cwd))) G2D::DrawImageScale(icon_check[cfg.dark_theme], 0, start_y + (sel_dist * (i - start)), 18.f, 18.f); else G2D::DrawImageScale(icon_uncheck[cfg.dark_theme], 0, start_y + (sel_dist * (i - start)), 18.f, 18.f); FileType file_type = FS::GetFileType(filename); - if (FIO_S_ISDIR(item->entries[i].d_stat.st_mode)) + if (FIO_S_ISDIR(item.entries[i].d_stat.st_mode)) G2D::DrawImageScale(icon_dir[cfg.dark_theme], 20, start_y + (sel_dist * (i - start)), 18.f, 18.f); else G2D::DrawImageScale(file_icons[file_type], 20, start_y + (sel_dist * (i - start)), 18.f, 18.f); @@ -59,60 +59,60 @@ namespace GUI { } } - void ControlFileBrowser(MenuItem *item, int *ctrl) { - u32 size = (item->entries.size() - 1); - Utils::SetBounds(item->selected, 0, size); + void ControlFileBrowser(MenuItem &item, int &ctrl) { + u32 size = (item.entries.size() - 1); + Utils::SetBounds(item.selected, 0, size); - if (*ctrl & PSP_CTRL_UP) { - item->selected--; - if (item->selected < 0) - item->selected = size; + if (ctrl & PSP_CTRL_UP) { + item.selected--; + if (item.selected < 0) + item.selected = size; if (size < max_entries) start = 0; - else if (start > item->selected) + else if (start > item.selected) start--; - else if ((static_cast(item->selected) == size) && (size > (max_entries - 1))) + else if ((static_cast(item.selected) == size) && (size > (max_entries - 1))) start = size - (max_entries - 1); } - else if (*ctrl & PSP_CTRL_DOWN) { - item->selected++; - if(static_cast(item->selected) > size) - item->selected = 0; + else if (ctrl & PSP_CTRL_DOWN) { + item.selected++; + if(static_cast(item.selected) > size) + item.selected = 0; - if ((static_cast(item->selected) > (start + (max_entries - 1))) && ((start + (max_entries - 1)) < size)) + if ((static_cast(item.selected) > (start + (max_entries - 1))) && ((start + (max_entries - 1)) < size)) start++; - if (item->selected == 0) + if (item.selected == 0) start = 0; } if (Utils::IsButtonPressed(PSP_CTRL_LEFT)) { - item->selected = 0; + item.selected = 0; start = 0; } else if (Utils::IsButtonPressed(PSP_CTRL_RIGHT)) { - item->selected = item->entries.size() - 1; - if ((item->entries.size() - 1) > max_entries) + item.selected = item.entries.size() - 1; + if ((item.entries.size() - 1) > max_entries) start = size - (max_entries - 1); } if (Utils::IsButtonPressed(PSP_CTRL_ENTER)) { - if (FIO_S_ISDIR(item->entries[item->selected].d_stat.st_mode)) { - if (item->entries.size() != 0) { - if (R_SUCCEEDED(FS::ChangeDirNext(item->entries[item->selected].d_name, item->entries))) { + if (FIO_S_ISDIR(item.entries[item.selected].d_stat.st_mode)) { + if (item.entries.size() != 0) { + if (R_SUCCEEDED(FS::ChangeDirNext(item.entries[item.selected].d_name, item.entries))) { start = 0; // Make a copy before resizing our vector. - if ((item->checked_count > 1) && (item->checked_copy.empty())) - item->checked_copy = item->checked; + if ((item.checked_count > 1) && (item.checked_copy.empty())) + item.checked_copy = item.checked; - item->checked.resize(item->entries.size()); - item->selected = 0; + item.checked.resize(item.entries.size()); + item.selected = 0; } } } else { - std::string path = FS::BuildPath(cfg.cwd, item->entries[item->selected].d_name); - FileType file_type = FS::GetFileType(item->entries[item->selected].d_name); + std::string path = FS::BuildPath(cfg.cwd, item.entries[item.selected].d_name); + FileType file_type = FS::GetFileType(item.entries[item.selected].d_name); switch(file_type) { case FileTypeApp: @@ -125,15 +125,15 @@ namespace GUI { case FileTypeArchive: if (R_SUCCEEDED(ArchiveHelper::Extract(path))) { - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); GUI::ResetCheckbox(item); } break; case FileTypeImage: - item->texture = Textures::LoadImage(path.c_str()); - if (item->texture) - item->state = MENU_STATE_IMAGEVIEWER; + item.texture = Textures::LoadImage(path.c_str()); + if (item.texture) + item.state = MENU_STATE_IMAGEVIEWER; break; case FileTypeText: @@ -146,28 +146,28 @@ namespace GUI { } } else if (Utils::IsButtonPressed(PSP_CTRL_CANCEL)) { - if (R_SUCCEEDED(FS::ChangeDirPrev(item->entries))) { + if (R_SUCCEEDED(FS::ChangeDirPrev(item.entries))) { // Make a copy before resizing our vector. - if (item->checked_count > 1) - item->checked_copy = item->checked; + if (item.checked_count > 1) + item.checked_copy = item.checked; - item->checked.resize(item->entries.size()); - item->selected = 0; + item.checked.resize(item.entries.size()); + item.selected = 0; start = 0; } } else if (Utils::IsButtonPressed(PSP_CTRL_SQUARE)) { - if ((!item->checked_cwd.empty()) && (item->checked_cwd.compare(cfg.cwd) != 0)) + if ((!item.checked_cwd.empty()) && (item.checked_cwd.compare(cfg.cwd) != 0)) GUI::ResetCheckbox(item); - item->checked_cwd = cfg.cwd; - item->checked[item->selected] = !item->checked[item->selected]; - item->checked_count = std::count(item->checked.begin(), item->checked.end(), true); + item.checked_cwd = cfg.cwd; + item.checked[item.selected] = !item.checked[item.selected]; + item.checked_count = std::count(item.checked.begin(), item.checked.end(), true); } else if (Utils::IsButtonPressed(PSP_CTRL_TRIANGLE)) - item->state = MENU_STATE_OPTIONS; + item.state = MENU_STATE_OPTIONS; if (Utils::IsButtonPressed(PSP_CTRL_SELECT)) - item->state = MENU_STATE_MENUBAR; + item.state = MENU_STATE_MENUBAR; } } diff --git a/app/source/gui/imageviewer.cpp b/app/source/gui/imageviewer.cpp index 2a21c03..ff7c194 100644 --- a/app/source/gui/imageviewer.cpp +++ b/app/source/gui/imageviewer.cpp @@ -20,24 +20,24 @@ namespace ImageViewer { } namespace GUI { - static bool properties = false, horizantal_flip = false, vertical_flip = false; + static bool properties = false; static float scale_factor = 1.f, width = 0.f, height = 0.f, zoom_factor = 1.f; static int degrees = 0, pos_x = 0, pos_y = 0; - void DisplayImageViewer(MenuItem *item) { + void DisplayImageViewer(MenuItem &item) { g2dClear(BLACK_BG); - if (static_cast(item->texture->h) > 272.f) { - scale_factor = (272.f / static_cast(item->texture->h)); - width = static_cast(item->texture->w) * scale_factor; - height = static_cast(item->texture->h) * scale_factor; + if (static_cast(item.texture->h) > 272.f) { + scale_factor = (272.f / static_cast(item.texture->h)); + width = static_cast(item.texture->w) * scale_factor; + height = static_cast(item.texture->h) * scale_factor; } else { - width = static_cast(item->texture->w) * scale_factor; - height = static_cast(item->texture->h) * scale_factor; + width = static_cast(item.texture->w) * scale_factor; + height = static_cast(item.texture->h) * scale_factor; } - ImageViewer::Draw(item->texture, width, height, zoom_factor, degrees, pos_x, pos_y); + ImageViewer::Draw(item.texture, width, height, zoom_factor, degrees, pos_x, pos_y); if (properties) { G2D::DrawRect(0, 0, 480, 272, G2D_RGBA(0, 0, 0, cfg.dark_theme? 50 : 80)); @@ -51,17 +51,14 @@ namespace GUI { G2D::DrawText(340 - (ok_width), (232 - (font->texYSize - 15)) - 3, "OK"); G2D::FontSetStyle(1.f, TEXT_COLOUR, INTRAFONT_ALIGN_LEFT); - intraFontPrintf(font, 140, 74, std::string(item->entries[item->selected].d_name).length() > 14? "Name: %.14s..." : "%s", - item->entries[item->selected].d_name); - intraFontPrintf(font, 140, 92, "Width: %dpx", item->texture->w); - intraFontPrintf(font, 140, 110, "Height: %dpx", item->texture->h); + intraFontPrintf(font, 140, 74, std::string(item.entries[item.selected].d_name).length() > 14? "Name: %.14s..." : "%s", + item.entries[item.selected].d_name); + intraFontPrintf(font, 140, 92, "Width: %dpx", item.texture->w); + intraFontPrintf(font, 140, 110, "Height: %dpx", item.texture->h); } } - void ControlImageViewer(MenuItem *item, float *delta_time) { - if (Utils::IsButtonPressed(PSP_CTRL_TRIANGLE)) - properties = !properties; - + void ControlImageViewer(MenuItem &item, float &delta) { if (Utils::IsButtonPressed(PSP_CTRL_LTRIGGER)) { degrees -= 90; @@ -74,71 +71,62 @@ namespace GUI { if (degrees > 270) degrees = 0; } - - // Flip horizantally - if (Utils::IsButtonPressed(PSP_CTRL_SQUARE)) { - horizantal_flip = !horizantal_flip; - width = -width; - } - // Flip vertically - if (Utils::IsButtonPressed(PSP_CTRL_TRIANGLE)) { - vertical_flip = !vertical_flip; - height = -height; - } + if (Utils::IsButtonPressed(PSP_CTRL_TRIANGLE)) + properties = !properties; if (Utils::IsButtonHeld(PSP_CTRL_UP)) { - zoom_factor += 0.5f * (*delta_time); + zoom_factor += (delta / 1000.f); - if (zoom_factor > 2.0f) - zoom_factor = 2.0f; + if (zoom_factor > 2.f) + zoom_factor = 2.f; } else if (Utils::IsButtonHeld(PSP_CTRL_DOWN)) { - zoom_factor -= 0.5f * (*delta_time); + zoom_factor -= (delta / 1000.f); if (zoom_factor < 0.5f) zoom_factor = 0.5f; - if (zoom_factor <= 1.0f) { + if (zoom_factor <= 1.f) { pos_x = 0; pos_y = 0; } } if ((height * zoom_factor > 272.f) || (width * zoom_factor > 480.f)) { - double velocity = 2.f / zoom_factor; + float velocity = 2.f / zoom_factor; if (Utils::GetAnalogY() < -0.4f) - pos_y -= ((velocity * zoom_factor) * (*delta_time) * 1000.f); + pos_y -= ((velocity * zoom_factor) * delta); if (Utils::GetAnalogY() > 0.4f) - pos_y += ((velocity * zoom_factor) * (*delta_time) * 1000.f); + pos_y += ((velocity * zoom_factor) * delta); if (Utils::GetAnalogX() < -0.4f) - pos_x -= ((velocity * zoom_factor) * (*delta_time) * 1000.f); + pos_x -= ((velocity * zoom_factor) * delta); if (Utils::GetAnalogX() > 0.4f) - pos_x += ((velocity * zoom_factor) * (*delta_time) * 1000.f); + pos_x += ((velocity * zoom_factor) * delta); } if ((degrees == 0) || (degrees == 180)) { - Utils::SetMax(pos_x, horizantal_flip? -width : width, horizantal_flip? -width : width); - Utils::SetMin(pos_x, horizantal_flip? width : -width, horizantal_flip? width : -width); - Utils::SetMax(pos_y, vertical_flip? -height : height, vertical_flip? -height : height); - Utils::SetMin(pos_y, vertical_flip? height : -height, vertical_flip? height : -height); + Utils::SetMax(pos_x, width, width); + Utils::SetMin(pos_x, -width, -width); + Utils::SetMax(pos_y, height, height); + Utils::SetMin(pos_y, -height, -height); } else { - Utils::SetMax(pos_x, vertical_flip? -height : height, vertical_flip? -height : height); - Utils::SetMin(pos_x, vertical_flip? height : -height, vertical_flip? height : -height); - Utils::SetMax(pos_y, horizantal_flip? -width : width, horizantal_flip? -width : width); - Utils::SetMin(pos_y, horizantal_flip? width : -width, horizantal_flip? width : -width); + Utils::SetMax(pos_x, height, height); + Utils::SetMin(pos_x, -height, -height); + Utils::SetMax(pos_y, width, width); + Utils::SetMin(pos_y, -width, -width); } if (Utils::IsButtonPressed(PSP_CTRL_CANCEL)) { if (!properties) { - if (item->texture) - g2dTexFree(&item->texture); + if (item.texture) + g2dTexFree(&item.texture); zoom_factor = 1.f; pos_x = 0; pos_y = 0; - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; } else properties = false; diff --git a/app/source/gui/menubar.cpp b/app/source/gui/menubar.cpp index ed7fa7c..80b935e 100644 --- a/app/source/gui/menubar.cpp +++ b/app/source/gui/menubar.cpp @@ -14,8 +14,8 @@ namespace GUI { static float pos_x = -180.f; static const float pos_x_bounds = 0.f; - void HandleMenubarAnim(float *delta_time) { - pos_x += 1000 * (*delta_time); + void HandleMenubarAnim(float &delta) { + pos_x += delta; if (pos_x > 0) pos_x = pos_x_bounds; @@ -90,10 +90,10 @@ namespace GUI { } } - void ControlMenubar(MenuItem *item, int *ctrl) { - if (*ctrl & PSP_CTRL_UP) + void ControlMenubar(MenuItem &item, int &ctrl) { + if (ctrl & PSP_CTRL_UP) selection--; - else if (*ctrl & PSP_CTRL_DOWN) + else if (ctrl & PSP_CTRL_DOWN) selection++; if (is_psp_go) { @@ -227,16 +227,16 @@ namespace GUI { pos_x -= 10.0; pos_x = -180; - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); if ((device == BROWSE_STATE_FLASH0) || (device == BROWSE_STATE_FLASH1) || (device == BROWSE_STATE_FLASH2) || (device == BROWSE_STATE_FLASH3)) cfg.cwd.pop_back(); - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; } else if ((Utils::IsButtonPressed(PSP_CTRL_CANCEL)) || (Utils::IsButtonPressed(PSP_CTRL_SELECT))) { pos_x -= 10.0; pos_x = -180; - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; } } } diff --git a/app/source/gui/options.cpp b/app/source/gui/options.cpp index da58e34..38ba57c 100644 --- a/app/source/gui/options.cpp +++ b/app/source/gui/options.cpp @@ -18,51 +18,51 @@ namespace Options { column = 0; } - static void HandleMultipleCopy(MenuItem *item, int (*func)()) { + static void HandleMultipleCopy(MenuItem &item, int (*func)()) { int ret = 0; std::vector entries; - if (R_FAILED(ret = FS::GetDirList(item->checked_cwd.data(), entries))) + if (R_FAILED(ret = FS::GetDirList(item.checked_cwd.data(), entries))) return; - for (u32 i = 0; i < item->checked_copy.size(); i++) { - if (item->checked_copy.at(i)) { - FS::Copy(entries[i], item->checked_cwd); + for (u32 i = 0; i < item.checked_copy.size(); i++) { + if (item.checked_copy.at(i)) { + FS::Copy(entries[i], item.checked_cwd); if (R_FAILED((*func)())) { - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); GUI::ResetCheckbox(item); break; } } } - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); GUI::ResetCheckbox(item); entries.clear(); } - static void CreateFolder(MenuItem *item) { + static void CreateFolder(MenuItem &item) { std::string name = G2D::KeyboardGetText("Enter folder name", "New folder"); std::string path = FS::BuildPath(cfg.cwd, name); if (R_SUCCEEDED(FS::MakeDir(path.c_str()))) { - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); GUI::ResetCheckbox(item); } } - static void CreateFile(MenuItem *item) { + static void CreateFile(MenuItem &item) { std::string name = G2D::KeyboardGetText("Enter file name", "New File"); std::string path = FS::BuildPath(cfg.cwd, name); if (R_SUCCEEDED(FS::CreateFile(path.c_str()))) { - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); GUI::ResetCheckbox(item); } } - static void Rename(MenuItem *item, const std::string &filename) { - std::string src_path = FS::BuildPath(cfg.cwd, item->entries[item->selected].d_name); + static void Rename(MenuItem &item, const std::string &filename) { + std::string src_path = FS::BuildPath(cfg.cwd, item.entries[item.selected].d_name); std::string name = G2D::KeyboardGetText("Enter new name", filename); std::string dest_path = FS::BuildPath(cfg.cwd, name); @@ -71,63 +71,63 @@ namespace Options { #else if (R_SUCCEEDED(pspIoRename(src_path.c_str(), dest_path.c_str()))) { #endif - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); Options::ResetSelector(); options_more = false; - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; } } - static void Copy(MenuItem *item) { + static void Copy(MenuItem &item) { if (!copy) { - if ((item->checked_count >= 1) && (item->checked_cwd.compare(cfg.cwd) != 0)) + if ((item.checked_count >= 1) && (item.checked_cwd.compare(cfg.cwd) != 0)) GUI::ResetCheckbox(item); - if (item->checked_count <= 1) - FS::Copy(item->entries[item->selected], cfg.cwd); + if (item.checked_count <= 1) + FS::Copy(item.entries[item.selected], cfg.cwd); copy = !copy; - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; } else { - if ((item->checked_count > 1) && (item->checked_cwd.compare(cfg.cwd) != 0)) + if ((item.checked_count > 1) && (item.checked_cwd.compare(cfg.cwd) != 0)) Options::HandleMultipleCopy(item, &FS::Paste); else { if (R_SUCCEEDED(FS::Paste())) { - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); GUI::ResetCheckbox(item); } } GUI::GetStorageSize(item); copy = !copy; - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; } } - static void Move(MenuItem *item) { + static void Move(MenuItem &item) { if (!move) { - if ((item->checked_count >= 1) && (item->checked_cwd.compare(cfg.cwd) != 0)) + if ((item.checked_count >= 1) && (item.checked_cwd.compare(cfg.cwd) != 0)) GUI::ResetCheckbox(item); - if (item->checked_count <= 1) - FS::Copy(item->entries[item->selected], cfg.cwd); + if (item.checked_count <= 1) + FS::Copy(item.entries[item.selected], cfg.cwd); } else { - if ((item->checked_count > 1) && (item->checked_cwd.compare(cfg.cwd) != 0)) + if ((item.checked_count > 1) && (item.checked_cwd.compare(cfg.cwd) != 0)) Options::HandleMultipleCopy(item, &FS::Move); else if (R_SUCCEEDED(FS::Move())) { - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); GUI::ResetCheckbox(item); } } move = !move; - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; } } namespace GUI { - void DisplayFileOptions(MenuItem *item) { + void DisplayFileOptions(MenuItem &item) { G2D::DrawRect(0, 18, 480, 254, G2D_RGBA(0, 0, 0, cfg.dark_theme? 50 : 80)); G2D::DrawImage(options_dialog[cfg.dark_theme], (480 - options_dialog[0]->w) / 2, (272 - options_dialog[0]->h) / 2); G2D::FontSetStyle(1.f, TITLE_COLOUR, INTRAFONT_ALIGN_LEFT); @@ -170,15 +170,15 @@ namespace GUI { } } - void ControlFileOptions(MenuItem *item, int *ctrl) { - if (*ctrl & PSP_CTRL_RIGHT) + void ControlFileOptions(MenuItem &item, int &ctrl) { + if (ctrl & PSP_CTRL_RIGHT) row++; - else if (*ctrl & PSP_CTRL_LEFT) + else if (ctrl & PSP_CTRL_LEFT) row--; - if (*ctrl & PSP_CTRL_DOWN) + if (ctrl & PSP_CTRL_DOWN) column++; - else if (*ctrl & PSP_CTRL_UP) + else if (ctrl & PSP_CTRL_UP) column--; if (!options_more) { @@ -195,16 +195,16 @@ namespace GUI { } if (Utils::IsButtonPressed(PSP_CTRL_ENTER)) { - const std::string filename = item->entries[item->selected].d_name; + const std::string filename = item.entries[item.selected].d_name; if (row == 0) { if (!options_more) { if (column == 0) - item->state = MENU_STATE_PROPERTIES; + item.state = MENU_STATE_PROPERTIES; else if (column == 1) Options::Copy(item); else if (column == 2) - item->state = MENU_STATE_DELETE; + item.state = MENU_STATE_DELETE; } else { if (column == 0) @@ -216,11 +216,11 @@ namespace GUI { else if (row == 1) { if (!options_more) { if (column == 0) { - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); Options::ResetSelector(); options_more = false; - item->selected = 0; - item->state = MENU_STATE_FILEBROWSER; + item.selected = 0; + item.state = MENU_STATE_FILEBROWSER; } else if (column == 1) Options::Move(item); @@ -239,14 +239,14 @@ namespace GUI { move = false; Options::ResetSelector(); options_more = false; - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; } } if (Utils::IsButtonPressed(PSP_CTRL_CANCEL)) { Options::ResetSelector(); if (!options_more) - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; else options_more = false; } diff --git a/app/source/gui/properties.cpp b/app/source/gui/properties.cpp index cc2f91c..15a54fc 100644 --- a/app/source/gui/properties.cpp +++ b/app/source/gui/properties.cpp @@ -8,7 +8,7 @@ #include "utils.h" namespace GUI { - void DisplayFileProperties(MenuItem *item) { + void DisplayFileProperties(MenuItem &item) { G2D::DrawRect(0, 18, 480, 254, G2D_RGBA(0, 0, 0, cfg.dark_theme? 50 : 80)); G2D::DrawImage(properties_dialog[cfg.dark_theme], ((480 - (properties_dialog[0]->w)) / 2), ((272 - (properties_dialog[0]->h)) / 2)); G2D::FontSetStyle(1.f, TITLE_COLOUR, INTRAFONT_ALIGN_LEFT); @@ -20,28 +20,28 @@ namespace GUI { G2D::DrawText(340 - (ok_width), (232 - (font->texYSize - 15)) - 3, "OK"); G2D::FontSetStyle(1.f, TEXT_COLOUR, INTRAFONT_ALIGN_LEFT); - intraFontPrintf(font, 140, 74, std::string(item->entries[item->selected].d_name).length() > 14? "Name: %.14s..." : "%s", - item->entries[item->selected].d_name); + intraFontPrintf(font, 140, 74, std::string(item.entries[item.selected].d_name).length() > 14? "Name: %.14s..." : "%s", + item.entries[item.selected].d_name); - if (!(FIO_S_ISDIR(item->entries[item->selected].d_stat.st_mode))) { + if (!(FIO_S_ISDIR(item.entries[item.selected].d_stat.st_mode))) { char size[16] = {0}; - Utils::GetSizeString(size, item->entries[item->selected].d_stat.st_size); + Utils::GetSizeString(size, item.entries[item.selected].d_stat.st_size); intraFontPrintf(font, 140, 92, "Size: %s", size); - intraFontPrintf(font, 140, 110, "Created: %s", FS::GetFileTimestamp(item->entries[item->selected].d_stat, FileCreatedTime)); - intraFontPrintf(font, 140, 128, "Accessed: %s", FS::GetFileTimestamp(item->entries[item->selected].d_stat, FileAccessedTime)); - intraFontPrintf(font, 140, 146, "Modified: %s", FS::GetFileTimestamp(item->entries[item->selected].d_stat, FileModifiedTime)); - intraFontPrintf(font, 140, 164, "Perms: %s", FS::GetFilePermission(item->entries[item->selected].d_stat)); + intraFontPrintf(font, 140, 110, "Created: %s", FS::GetFileTimestamp(item.entries[item.selected].d_stat, FileCreatedTime)); + intraFontPrintf(font, 140, 128, "Accessed: %s", FS::GetFileTimestamp(item.entries[item.selected].d_stat, FileAccessedTime)); + intraFontPrintf(font, 140, 146, "Modified: %s", FS::GetFileTimestamp(item.entries[item.selected].d_stat, FileModifiedTime)); + intraFontPrintf(font, 140, 164, "Perms: %s", FS::GetFilePermission(item.entries[item.selected].d_stat)); } else { - intraFontPrintf(font, 140, 92, "Created: %s", FS::GetFileTimestamp(item->entries[item->selected].d_stat, FileCreatedTime)); - intraFontPrintf(font, 140, 110, "Accessed: %s", FS::GetFileTimestamp(item->entries[item->selected].d_stat, FileAccessedTime)); - intraFontPrintf(font, 140, 128, "Modified: %s", FS::GetFileTimestamp(item->entries[item->selected].d_stat, FileModifiedTime)); - intraFontPrintf(font, 140, 146, "Perms: %s", FS::GetFilePermission(item->entries[item->selected].d_stat)); + intraFontPrintf(font, 140, 92, "Created: %s", FS::GetFileTimestamp(item.entries[item.selected].d_stat, FileCreatedTime)); + intraFontPrintf(font, 140, 110, "Accessed: %s", FS::GetFileTimestamp(item.entries[item.selected].d_stat, FileAccessedTime)); + intraFontPrintf(font, 140, 128, "Modified: %s", FS::GetFileTimestamp(item.entries[item.selected].d_stat, FileModifiedTime)); + intraFontPrintf(font, 140, 146, "Perms: %s", FS::GetFilePermission(item.entries[item.selected].d_stat)); } } - void ControlFileProperties(MenuItem *item) { + void ControlFileProperties(MenuItem &item) { if ((Utils::IsButtonPressed(PSP_CTRL_ENTER)) || (Utils::IsButtonPressed(PSP_CTRL_CANCEL))) - item->state = MENU_STATE_OPTIONS; + item.state = MENU_STATE_OPTIONS; } } diff --git a/app/source/gui/settings.cpp b/app/source/gui/settings.cpp index f64f865..e6df4f3 100644 --- a/app/source/gui/settings.cpp +++ b/app/source/gui/settings.cpp @@ -80,11 +80,11 @@ namespace GUI { G2D::DrawImage(cfg.sort == 3? icon_radio_on[cfg.dark_theme] : icon_radio_off[cfg.dark_theme], 425, 192); } - static void ControlSortSettings(MenuItem *item) { + static void ControlSortSettings(MenuItem &item) { if (Utils::IsButtonPressed(PSP_CTRL_ENTER)) { cfg.sort = selection; Config::Save(cfg); - FS::GetDirList(cfg.cwd, item->entries); + FS::GetDirList(cfg.cwd, item.entries); } else if (Utils::IsButtonPressed(PSP_CTRL_CANCEL)) { selection = 0; @@ -153,7 +153,7 @@ namespace GUI { G2D::DrawImage(cfg.dev_options? icon_toggle_on[cfg.dark_theme] : icon_toggle_off, 415, 187); } - static void ControlGeneralSettings(MenuItem *item, int *ctrl) { + static void ControlGeneralSettings(MenuItem &item, int &ctrl) { if (Utils::IsButtonPressed(PSP_CTRL_ENTER)) { switch(selection) { case 0: @@ -184,13 +184,13 @@ namespace GUI { } else if (Utils::IsButtonPressed(PSP_CTRL_CANCEL)) { selection = 0; - item->state = MENU_STATE_FILEBROWSER; + item.state = MENU_STATE_FILEBROWSER; } Utils::SetBounds(selection, 0, 4); } - void DisplaySettings(MenuItem *item) { + void DisplaySettings(MenuItem &item) { G2D::DrawRect(0, 18, 480, 34, MENU_BAR_COLOUR); G2D::DrawRect(0, 52, 480, 220, BG_COLOUR); G2D::DrawImage(icon_back, 5, 20); @@ -219,10 +219,10 @@ namespace GUI { } } - void ControlSettings(MenuItem *item, int *ctrl) { - if (*ctrl & PSP_CTRL_UP) + void ControlSettings(MenuItem &item, int &ctrl) { + if (ctrl & PSP_CTRL_UP) selection--; - else if (*ctrl & PSP_CTRL_DOWN) + else if (ctrl & PSP_CTRL_DOWN) selection++; switch(settings_state) { diff --git a/app/source/utils.cpp b/app/source/utils.cpp index 0def71c..6b2e1eb 100644 --- a/app/source/utils.cpp +++ b/app/source/utils.cpp @@ -85,8 +85,8 @@ namespace Utils { int i = 0; const char *units[] = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; - while (size >= 1024.0f) { - size /= 1024.0f; + while (size >= 1024.f) { + size /= 1024.f; i++; }