So many changes

This commit is contained in:
XorTroll 2019-10-20 21:08:14 +02:00
parent 873c4460a7
commit f34a5f5512
16 changed files with 116 additions and 89 deletions

View file

@ -9,8 +9,7 @@ namespace am
{
Invalid,
StartupScreen,
MenuNormal,
MenuHomebrewMode,
Menu,
MenuApplicationSuspended,
MenuLaunchFailure
};

View file

@ -27,6 +27,10 @@ using JSON = nlohmann::json;
#define Q_ENTRIES_PATH Q_BASE_SD_DIR "/entries"
#define Q_THEMES_PATH Q_BASE_SD_DIR "/themes"
#ifndef Q_VERSION
#error Project's version isn't defined.
#endif
// Thanks SciresM
#define R_TRY(res_expr) \
({ \

View file

@ -32,7 +32,7 @@ ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -Wl,-wrap,apmInitialize
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CFLAGS += $(INCLUDE) -D__SWITCH__ -DQ_VERSION=\"$(Q_VERSION)\"
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17

View file

@ -12,18 +12,22 @@ namespace ui
class MenuLayout : public pu::ui::Layout
{
public:
MenuLayout(void *raw, u8 min_alpha, bool hb_mode);
MenuLayout(void *raw, u8 min_alpha);
~MenuLayout();
PU_SMART_CTOR(MenuLayout)
void menu_Click(u64 down, u32 index);
void menu_OnSelected(u32 index);
void toggle_Click();
void menuToggle_Click();
void logo_Click();
void settings_Click();
void themes_Click();
void MoveFolder(std::string name, bool fade);
void OnInput(u64 down, u64 up, u64 held, pu::ui::Touch pos);
bool HandleFolderChange(cfg::TitleRecord &rec);
void HandleCloseSuspended();
void HandleHomebrewLaunch(cfg::TitleRecord &rec);
private:
void *susptr;
bool last_hasconn;
@ -35,13 +39,15 @@ namespace ui
pu::ui::elm::TextBlock::Ref timeText;
pu::ui::elm::TextBlock::Ref batteryText;
pu::ui::elm::Image::Ref batteryIcon;
ClickableImage::Ref settings;
ClickableImage::Ref themes;
SideMenu::Ref itemsMenu;
RawData::Ref bgSuspendedRaw;
pu::ui::elm::TextBlock::Ref itemName;
pu::ui::elm::TextBlock::Ref itemAuthor;
pu::ui::elm::TextBlock::Ref itemVersion;
pu::ui::elm::Image::Ref bannerImage;
ClickableImage::Ref menuToggleClickable;
ClickableImage::Ref menuToggle;
std::string curfolder;
std::chrono::steady_clock::time_point tp;
bool warnshown;

View file

@ -32,7 +32,7 @@ ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -Wl,-wrap,apmInitialize
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CFLAGS += $(INCLUDE) -D__SWITCH__ -DQ_VERSION=\"$(Q_VERSION)\"
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

@ -22,7 +22,7 @@ cfg::ProcessedTheme theme;
namespace qmenu
{
void Initialize()
void Initialize(bool cache_homebrew)
{
accountInitialize();
nsInitialize();
@ -40,7 +40,7 @@ namespace qmenu
am::QMenu_InitializeDaemonService();
// Cache all homebrew (is this too slow...?)
homebrew = cfg::QueryAllHomebrew(true);
homebrew = cfg::QueryAllHomebrew(cache_homebrew);
// Load menu config
config = cfg::EnsureConfig();
@ -65,14 +65,14 @@ u8 *app_buf;
int main()
{
app_buf = new u8[1280 * 720 * 4]();
qmenu::Initialize();
auto [_rc, menulist] = cfg::LoadTitleList(true);
list = menulist;
auto [rc, smode] = am::QMenu_ProcessInput();
if(R_SUCCEEDED(rc))
{
app_buf = new u8[1280 * 720 * 4]();
qmenu::Initialize(smode == am::QMenuStartMode::StartupScreen); // Cache homebrew only on first launch
auto [_rc, menulist] = cfg::LoadTitleList(true);
list = menulist;
if(smode != am::QMenuStartMode::Invalid)
{
auto renderer = pu::ui::render::Renderer::New(SDL_INIT_EVERYTHING, pu::ui::render::RendererInitOptions::RendererEverything, pu::ui::render::RendererHardwareFlags);
@ -84,10 +84,10 @@ int main()
if(smode == am::QMenuStartMode::MenuApplicationSuspended) qapp->Show();
else qapp->ShowWithFadeIn();
}
}
delete[] app_buf;
qmenu::Exit();
delete[] app_buf;
qmenu::Exit();
}
return 0;
}

View file

@ -14,7 +14,7 @@ extern cfg::ProcessedTheme theme;
namespace ui
{
MenuLayout::MenuLayout(void *raw, u8 min_alpha, bool hb_mode)
MenuLayout::MenuLayout(void *raw, u8 min_alpha)
{
this->susptr = raw;
this->mode = 0;
@ -26,7 +26,7 @@ namespace ui
this->last_charge = false;
this->warnshown = false;
this->minalpha = min_alpha;
this->homebrew_mode = hb_mode;
this->homebrew_mode = false;
pu::ui::Color textclr = pu::ui::Color::FromHex(qapp->GetUIConfigValue<std::string>("text_color", "#e1e1e1ff"));
@ -36,6 +36,9 @@ namespace ui
this->topMenuImage = pu::ui::elm::Image::New(40, 35, cfg::ProcessedThemeResource(theme, "ui/TopMenu.png"));
this->Add(this->topMenuImage);
this->logo = ClickableImage::New(610, 13 + 35, "romfs:/Logo.png");
this->logo->SetWidth(60);
this->logo->SetHeight(60);
this->logo->SetOnClick(std::bind(&MenuLayout::logo_Click, this));
this->Add(this->logo);
this->connIcon = pu::ui::elm::Image::New(80, 53, cfg::ProcessedThemeResource(theme, "ui/NoConnectionIcon.png"));
this->Add(this->connIcon);
@ -51,10 +54,18 @@ namespace ui
this->batteryIcon = pu::ui::elm::Image::New(700, 80, cfg::ProcessedThemeResource(theme, "ui/BatteryNormalIcon.png"));
this->Add(this->batteryIcon);
this->menuToggleClickable = ClickableImage::New(0, 200, cfg::ProcessedThemeResource(theme, "ui/ToggleClick.png"));
this->menuToggleClickable->SetOnClick(std::bind(&MenuLayout::toggle_Click, this));
this->menuToggleClickable->SetHorizontalAlign(pu::ui::elm::HorizontalAlign::Center);
this->Add(this->menuToggleClickable);
this->settings = ClickableImage::New(880, 53, cfg::ProcessedThemeResource(theme, "ui/SettingsIcon.png"));
this->settings->SetOnClick(std::bind(&MenuLayout::settings_Click, this));
this->Add(this->settings);
this->themes = ClickableImage::New(950, 53, cfg::ProcessedThemeResource(theme, "ui/ThemesIcon.png"));
this->themes->SetOnClick(std::bind(&MenuLayout::themes_Click, this));
this->Add(this->themes);
this->menuToggle = ClickableImage::New(0, 200, cfg::ProcessedThemeResource(theme, "ui/ToggleClick.png"));
this->menuToggle->SetOnClick(std::bind(&MenuLayout::menuToggle_Click, this));
this->menuToggle->SetHorizontalAlign(pu::ui::elm::HorizontalAlign::Center);
this->Add(this->menuToggle);
this->bannerImage = pu::ui::elm::Image::New(0, 585, cfg::ProcessedThemeResource(theme, "ui/BannerInstalled.png"));
this->Add(this->bannerImage);
@ -122,17 +133,7 @@ namespace ui
if(this->homebrew_mode)
{
auto hb = homebrew[realidx];
if(down & KEY_A)
{
am::QMenuCommandWriter writer(am::QDaemonMessage::LaunchHomebrewLibApplet);
writer.Write<hb::TargetInput>(hb.nro_target);
writer.FinishWrite();
pu::audio::Play(this->sfxTitleLaunch);
qapp->StopPlayBGM();
qapp->CloseWithFadeOut();
return;
}
if(down & KEY_A) this->HandleHomebrewLaunch(hb);
else if(down & KEY_X)
{
auto sopt = qapp->CreateShowDialog("Add to menu", "Would you like to add this homebrew to the main menu?", { "Yes", "Cancel" }, true);
@ -158,42 +159,7 @@ namespace ui
{
if(!qapp->IsSuspended())
{
if((cfg::TitleType)title.title_type == cfg::TitleType::Homebrew)
{
int sopt = qapp->CreateShowDialog("Homebrew launch", "How would you like to launch this homebrew?\n\nNOTE: Launching as application might involve BAN RISK, so use it at your own risk!", { "Applet", "Application", "Cancel" }, true);
if(sopt == 0)
{
am::QMenuCommandWriter writer(am::QDaemonMessage::LaunchHomebrewLibApplet);
writer.Write<hb::TargetInput>(title.nro_target);
writer.FinishWrite();
pu::audio::Play(this->sfxTitleLaunch);
qapp->StopPlayBGM();
qapp->CloseWithFadeOut();
return;
}
else if(sopt == 1)
{
am::QMenuCommandWriter writer(am::QDaemonMessage::LaunchHomebrewApplication);
writer.Write<hb::TargetInput>(title.nro_target);
writer.FinishWrite();
am::QMenuCommandResultReader reader;
if(reader && R_SUCCEEDED(reader.GetReadResult()))
{
pu::audio::Play(this->sfxTitleLaunch);
qapp->StopPlayBGM();
qapp->CloseWithFadeOut();
return;
}
else
{
auto rc = reader.GetReadResult();
qapp->CreateShowDialog("Title launch", "An error ocurred attempting to launch the title:\n" + util::FormatResultDisplay(rc) + " (" + util::FormatResultHex(rc) + ")", { "Ok" }, true);
}
reader.FinishRead();
}
}
if((cfg::TitleType)title.title_type == cfg::TitleType::Homebrew) this->HandleHomebrewLaunch(title);
else
{
am::QMenuCommandWriter writer(am::QDaemonMessage::LaunchApplication);
@ -321,7 +287,7 @@ namespace ui
{
auto foldr = list.folders[realidx - folder.titles.size()];
this->bannerImage->SetImage(cfg::ProcessedThemeResource(theme, "ui/BannerFolder.png"));
this->itemAuthor->SetVisible(false);
this->itemAuthor->SetText(std::to_string(foldr.titles.size()) + " entries");
this->itemVersion->SetVisible(false);
this->itemName->SetText(foldr.name);
}
@ -561,13 +527,28 @@ namespace ui
}
}
void MenuLayout::toggle_Click()
void MenuLayout::menuToggle_Click()
{
pu::audio::Play(this->sfxMenuToggle);
this->homebrew_mode = !this->homebrew_mode;
this->MoveFolder("", true);
}
void MenuLayout::logo_Click()
{
qapp->CreateShowDialog("About {qlaunch-reimpl}", "{qlaunch-reimpl} v" + std::string(Q_VERSION) + "\n\n- Custom, open source, fully-featured HOME menu replacement.", { "Ok" }, true, "romfs:/Logo.png");
}
void MenuLayout::settings_Click()
{
qapp->CreateShowDialog("Settings", "Settings", {"Ok"}, true);
}
void MenuLayout::themes_Click()
{
qapp->CreateShowDialog("Themes", "Themes", {"Ok"}, true);
}
bool MenuLayout::HandleFolderChange(cfg::TitleRecord &rec)
{
bool changedone = false;
@ -609,4 +590,41 @@ namespace ui
this->bgSuspendedRaw->SetAlphaFactor(0);
}
}
void MenuLayout::HandleHomebrewLaunch(cfg::TitleRecord &rec)
{
int sopt = qapp->CreateShowDialog("Homebrew launch", "How would you like to launch this homebrew?\n\nNOTE: Launching as application might involve BAN RISK, so use it at your own risk!", { "Applet", "Application", "Cancel" }, true);
if(sopt == 0)
{
am::QMenuCommandWriter writer(am::QDaemonMessage::LaunchHomebrewLibApplet);
writer.Write<hb::TargetInput>(rec.nro_target);
writer.FinishWrite();
pu::audio::Play(this->sfxTitleLaunch);
qapp->StopPlayBGM();
qapp->CloseWithFadeOut();
return;
}
else if(sopt == 1)
{
am::QMenuCommandWriter writer(am::QDaemonMessage::LaunchHomebrewApplication);
writer.Write<hb::TargetInput>(rec.nro_target);
writer.FinishWrite();
am::QMenuCommandResultReader reader;
if(reader && R_SUCCEEDED(reader.GetReadResult()))
{
pu::audio::Play(this->sfxTitleLaunch);
qapp->StopPlayBGM();
qapp->CloseWithFadeOut();
return;
}
else
{
auto rc = reader.GetReadResult();
qapp->CreateShowDialog("Title launch", "An error ocurred attempting to launch the title:\n" + util::FormatResultDisplay(rc) + " (" + util::FormatResultHex(rc) + ")", { "Ok" }, true);
}
reader.FinishRead();
}
}
}

View file

@ -38,14 +38,11 @@ namespace ui
this->bgm = pu::audio::Open(cfg::ProcessedThemeResource(theme, "sound/BGM.mp3"));
this->startupLayout = StartupLayout::New();
bool hb = false;
if(this->stmode == am::QMenuStartMode::MenuHomebrewMode) hb = true;
this->menuLayout = MenuLayout::New(app_buf, 80, hb);
this->menuLayout = MenuLayout::New(app_buf, 80);
switch(this->stmode)
{
case am::QMenuStartMode::MenuNormal:
case am::QMenuStartMode::MenuHomebrewMode:
case am::QMenuStartMode::Menu:
case am::QMenuStartMode::MenuApplicationSuspended:
case am::QMenuStartMode::MenuLaunchFailure:
this->LoadMenu();

View file

@ -107,7 +107,7 @@ namespace ui
{
for(u32 i = 0; i < this->ricons.size(); i++)
{
if((Touch.X >= basex) && (Touch.X < (basex + ItemSize)) && (Touch.Y >= basey) && (Touch.Y < (basey + ItemSize)))
if((Touch.X >= basex) && (Touch.X < (basex + (s32)ItemSize)) && (Touch.Y >= basey) && (Touch.Y < (basey + (s32)ItemSize)))
{
if((this->baseiconidx + i) == selitm) (this->onselect)(KEY_A, this->selitm);
else

View file

@ -1,4 +1,6 @@
export Q_VERSION := dev
.PHONY: all clean
all:

View file

@ -38,16 +38,19 @@
// CaptureBox
//
this.CaptureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.CaptureBox.Location = new System.Drawing.Point(12, 12);
this.CaptureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.CaptureBox.Location = new System.Drawing.Point(0, 0);
this.CaptureBox.Margin = new System.Windows.Forms.Padding(0);
this.CaptureBox.Name = "CaptureBox";
this.CaptureBox.Size = new System.Drawing.Size(1280, 720);
this.CaptureBox.Size = new System.Drawing.Size(812, 331);
this.CaptureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.CaptureBox.TabIndex = 0;
this.CaptureBox.TabStop = false;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.ScreenshotButton);
this.groupBox1.Location = new System.Drawing.Point(1305, 12);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 282);
this.groupBox1.TabIndex = 1;
@ -68,7 +71,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1517, 741);
this.ClientSize = new System.Drawing.Size(812, 331);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.CaptureBox);
this.Name = "ViewerMainForm";

View file

@ -32,7 +32,7 @@ ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -Wl,-wrap,apmInitialize
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CFLAGS += $(INCLUDE) -D__SWITCH__ -DQ_VERSION=\"$(Q_VERSION)\"
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17

View file

@ -78,7 +78,7 @@ void HandleHomeButton()
if(am::LibraryAppletIsActive() && !am::LibraryAppletIsQMenu())
{
am::LibraryAppletTerminate();
am::QDaemon_LaunchQMenu(am::QMenuStartMode::MenuHomebrewMode);
am::QDaemon_LaunchQMenu(am::QMenuStartMode::Menu);
return;
}
if(am::ApplicationIsActive())
@ -340,7 +340,7 @@ namespace qdaemon
void ForegroundMain(void *arg)
{
u8 *demo = new u8[1280 * 720 * 4]();
u8 *demo = new (std::align_val_t(0x1000)) u8[1280 * 720 * 4]();
usbCommsInitialize();
while(true)
@ -446,10 +446,8 @@ int main()
switch(am::LibraryAppletGetId())
{
case am::QHbTargetAppletId:
am::QDaemon_LaunchQMenu(am::QMenuStartMode::MenuHomebrewMode);
break;
case AppletId_web:
am::QDaemon_LaunchQMenu(am::QMenuStartMode::MenuNormal);
am::QDaemon_LaunchQMenu(am::QMenuStartMode::Menu);
break;
default:
break;

View file

@ -32,7 +32,7 @@ ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -Wl,-wrap,apmInitialize
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CFLAGS += $(INCLUDE) -D__SWITCH__ -DQ_VERSION=\"$(Q_VERSION)\"
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17