Skip to content

Commit 5ae6366

Browse files
committed
refactor menu button generation
1 parent 4bfb8bb commit 5ae6366

File tree

6 files changed

+54
-130
lines changed

6 files changed

+54
-130
lines changed

.DS_Store

-10 KB
Binary file not shown.

hbas.elf

-1.91 KB
Binary file not shown.

hbas_dbg.elf

-1.83 KB
Binary file not shown.

src/.DS_Store

-6 KB
Binary file not shown.

src/menu/HomebrewWindow.cpp

Lines changed: 52 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,40 @@
3737
#define INSTALLED 2
3838
#define GET 3
3939

40+
void HomebrewWindow::positionHomebrewButton(homebrewButton* button, int index)
41+
{
42+
const float cfImageScale = 0.8f;
43+
44+
button->iconImg = new GuiImage(button->iconImgData);
45+
button->iconImg->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
46+
button->iconImg->setPosition(30, 0);
47+
button->iconImg->setScale(cfImageScale);
48+
49+
button->nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
50+
button->nameLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
51+
button->nameLabel->setPosition(256 + 10, 20);
52+
53+
button->descriptionLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
54+
button->descriptionLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
55+
button->descriptionLabel->setPosition(256 + 10, -20);
56+
57+
// set the right image for the status
58+
button->image->setScale(0.9);
59+
60+
button->button->setImage(button->image);
61+
button->button->setLabel(button->nameLabel, 0);
62+
button->button->setLabel(button->descriptionLabel, 1);
63+
button->button->setIcon(button->iconImg);
64+
float fXOffset = (index % 2)? 270 : -270;
65+
float fYOffset = scrollOffY + (button->image->getHeight() + 20.0f) * 1.5f - (button->image->getHeight() + 20) * ((index % 2)? (int)(index/2)-1 : (int)(index/2));
66+
button->button->setPosition(currentLeftPosition + fXOffset, fYOffset);
67+
button->button->setTrigger(&touchTrigger);
68+
button->button->setTrigger(&wpadTouchTrigger);
69+
button->button->setEffectGrow();
70+
// button->button->setSoundClick(buttonClickSound);
71+
button->button->clicked.connect(this, &HomebrewWindow::OnHomebrewButtonClick);
72+
}
73+
4074
HomebrewWindow::HomebrewWindow(int w, int h)
4175
: GuiFrame(w, h)
4276
, buttonClickSound(Resources::GetSound("button_click.mp3"))
@@ -72,16 +106,10 @@ HomebrewWindow::HomebrewWindow(int w, int h)
72106
// load up local apps
73107
for(int i = 0; i < dirList.GetFilecount(); i++)
74108
{
75-
//! skip our own application in the listing
76-
//!if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.elf") == 0)
77-
//! continue;
78-
79109
//! skip hidden linux and mac files
80110
if(dirList.GetFilename(i)[0] == '.' || dirList.GetFilename(i)[0] == '_')
81111
continue;
82112

83-
// createHomebrewButton(dirList.GetFilepath(i),
84-
85113
int idx = homebrewButtons.size();
86114
homebrewButtons.resize(homebrewButtons.size() + 1);
87115

@@ -113,13 +141,6 @@ HomebrewWindow::HomebrewWindow(int w, int h)
113141
iconData = NULL;
114142
}
115143

116-
const float cfImageScale = 0.8f;
117-
118-
homebrewButtons[idx].iconImg = new GuiImage(homebrewButtons[idx].iconImgData);
119-
homebrewButtons[idx].iconImg->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
120-
homebrewButtons[idx].iconImg->setPosition(30, 0);
121-
homebrewButtons[idx].iconImg->setScale(cfImageScale);
122-
123144
HomebrewXML metaXml;
124145

125146
bool xmlReadSuccess = metaXml.LoadHomebrewXMLData((homebrewPath + "/meta.xml").c_str());
@@ -128,56 +149,25 @@ HomebrewWindow::HomebrewWindow(int w, int h)
128149
const char *cpDescription = xmlReadSuccess ? metaXml.GetShortDescription() : "";
129150

130151
if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0)
131-
cpName += strlen("sd:/wiiu/apps/");
132-
152+
cpName += strlen("sd:/wiiu/apps/");
153+
133154
homebrewButtons[idx].nameLabel = new GuiText(cpName, 28, glm::vec4(0, 0, 0, 1));
134-
homebrewButtons[idx].nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
135-
homebrewButtons[idx].nameLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
136-
homebrewButtons[idx].nameLabel->setPosition(256 + 10, 20);
137-
138155
homebrewButtons[idx].descriptionLabel = new GuiText(metaXml.GetCoder(), 28, glm::vec4(0, 0, 0, 1));
139-
homebrewButtons[idx].descriptionLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
140-
homebrewButtons[idx].descriptionLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
141-
homebrewButtons[idx].descriptionLabel->setPosition(256 + 10, -20);
142-
143156
homebrewButtons[idx].button = new GuiButton(installedButtonImgData->getWidth(), installedButtonImgData->getHeight());
144-
145-
// set the right image for the status
146157
homebrewButtons[idx].image = new GuiImage(appButtonImages[homebrewButtons[idx].status]);
147-
homebrewButtons[idx].image->setScale(0.9);
148-
149-
homebrewButtons[idx].button->setImage(homebrewButtons[idx].image);
150-
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].nameLabel, 0);
151-
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].descriptionLabel, 1);
152-
homebrewButtons[idx].button->setIcon(homebrewButtons[idx].iconImg);
153-
float fXOffset = (idx % 2)? 270 : -270;
154-
float fYOffset = scrollOffY + (homebrewButtons[idx].image->getHeight() + 20.0f) * 1.5f - (homebrewButtons[idx].image->getHeight() + 20) * ((idx % 2)? (int)(idx/2)-1 : (int)(idx/2));
155-
homebrewButtons[idx].button->setPosition(currentLeftPosition + fXOffset, fYOffset);
156-
homebrewButtons[idx].button->setTrigger(&touchTrigger);
157-
homebrewButtons[idx].button->setTrigger(&wpadTouchTrigger);
158-
homebrewButtons[idx].button->setEffectGrow();
159-
// homebrewButtons[idx].button->setSoundClick(buttonClickSound);
160-
homebrewButtons[idx].button->clicked.connect(this, &HomebrewWindow::OnHomebrewButtonClick);
158+
159+
positionHomebrewButton(&homebrewButtons[idx], idx);
161160

162161
append(homebrewButtons[idx].button);
163-
164-
// // try to go through the string
165-
// for (int x=0; x<fileContents.size(); x++)
166-
// {
167-
//
168-
// }
169-
170162
}
171163

172-
// download app list from wiiubru
164+
// download app list from the repo
173165
std::string fileContents;
174166
std::string repoUrl = "http://192.168.1.104:8000";
175167
std::string targetUrl = std::string(repoUrl+"/directory.yaml");
176168
FileDownloader::getFile(targetUrl, fileContents);
177169
std::istringstream f(fileContents);
178170

179-
// int loops = 0;
180-
// int i2;
181171
while (true)
182172
{
183173
std::string shortname;
@@ -197,7 +187,7 @@ HomebrewWindow::HomebrewWindow(int w, int h)
197187
std::getline(f, binary);
198188
binary = binary.substr(2);
199189

200-
int idx = homebrewButtons.size();
190+
int idx = homebrewButtons.size();
201191
homebrewButtons.resize(homebrewButtons.size() + 1);
202192

203193
// file path
@@ -214,105 +204,37 @@ HomebrewWindow::HomebrewWindow(int w, int h)
214204

215205
homebrewButtons[idx].dirPath = homebrewPath;
216206

217-
// since we got this app from the sd card, mark it local for now.
218-
// if we see it later on the server, update its status appropriately to
219-
// update or installed
207+
// since we got this app from the net, mark it as a GET
220208
homebrewButtons[idx].status = GET;
221209
homebrewButtons[idx].shortname = shortname;
222210
homebrewButtons[idx].binary = binary;
223-
// download app list from wiiubru
211+
212+
// download app icon
224213
std::string targetIcon;
225214
std::string targetIconUrl = std::string(repoUrl+"/apps/" + shortname + "/icon.png");
226215
FileDownloader::getFile(targetIconUrl, targetIcon);
227-
228-
// if(targetIcon != NULL)
229-
// {
230-
homebrewButtons[idx].iconImgData = new GuiImageData((u8*)targetIcon.c_str(), targetIcon.size());
231-
// free(iconData);
232-
// }
233-
234-
const float cfImageScale = 1.0f;
235-
236-
homebrewButtons[idx].iconImg = new GuiImage(homebrewButtons[idx].iconImgData);
237-
homebrewButtons[idx].iconImg->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
238-
homebrewButtons[idx].iconImg->setPosition(60, 0);
239-
homebrewButtons[idx].iconImg->setScale(cfImageScale);
240-
241-
HomebrewXML metaXml;
242-
243-
// bool xmlReadSuccess = metaXml.LoadHomebrewXMLData((homebrewPath + "/meta.xml").c_str());
216+
217+
homebrewButtons[idx].iconImgData = new GuiImageData((u8*)targetIcon.c_str(), targetIcon.size());
244218

245219
const char *cpName = name.c_str();
246220
const char *cpDescription = desc.c_str();
247221

248222
if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0)
249223
cpName += strlen("sd:/wiiu/apps/");
250-
251-
homebrewButtons[idx].nameLabel = new GuiText(cpName, 32, glm::vec4(0, 0, 0, 1));
252-
homebrewButtons[idx].nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
253-
homebrewButtons[idx].nameLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
254-
homebrewButtons[idx].nameLabel->setPosition(256 + 80, 20);
255-
256-
homebrewButtons[idx].descriptionLabel = new GuiText(cpDescription, 32, glm::vec4(0, 0, 0, 1));
257-
homebrewButtons[idx].descriptionLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
258-
homebrewButtons[idx].descriptionLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
259-
homebrewButtons[idx].descriptionLabel->setPosition(256 + 80, -20);
260-
224+
225+
homebrewButtons[idx].nameLabel = new GuiText(cpName, 28, glm::vec4(0, 0, 0, 1));
226+
homebrewButtons[idx].descriptionLabel = new GuiText(author.c_str(), 28, glm::vec4(0, 0, 0, 1));
261227
homebrewButtons[idx].button = new GuiButton(installedButtonImgData->getWidth(), installedButtonImgData->getHeight());
262-
263-
// set the right image for the status
264228
homebrewButtons[idx].image = new GuiImage(appButtonImages[homebrewButtons[idx].status]);
265-
homebrewButtons[idx].image->setScale(0.9f);
266-
267-
homebrewButtons[idx].button->setImage(homebrewButtons[idx].image);
268-
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].nameLabel, 0);
269-
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].descriptionLabel, 1);
270-
homebrewButtons[idx].button->setIcon(homebrewButtons[idx].iconImg);
271-
float fXOffset = 0;
272-
float fYOffset = scrollOffY + (homebrewButtons[idx].image->getHeight() + 20.0f) * 1.5f - (homebrewButtons[idx].image->getHeight() + 20) * (idx);
273-
homebrewButtons[idx].button->setPosition(currentLeftPosition + fXOffset, fYOffset);
274-
homebrewButtons[idx].button->setTrigger(&touchTrigger);
275-
homebrewButtons[idx].button->setTrigger(&wpadTouchTrigger);
276-
homebrewButtons[idx].button->setEffectGrow();
277-
// homebrewButtons[idx].button->setSoundClick(buttonClickSound);
278-
homebrewButtons[idx].button->clicked.connect(this, &HomebrewWindow::OnHomebrewButtonClick);
229+
230+
positionHomebrewButton(&homebrewButtons[idx], idx);
279231

280232
append(homebrewButtons[idx].button);
281233
}
282-
283-
// while (std::getline(f, line)) {
284-
// if (!strncmp(str, substr, strlen("app: "))) {
285-
//
286-
// }
287-
// }
288-
289-
290-
// if((MAX_BUTTONS_ON_PAGE) < homebrewButtons.size())
291-
// {
292-
// arrowLeftButton.setImage(&arrowLeftImage);
293-
// arrowLeftButton.setEffectGrow();
294-
// arrowLeftButton.setPosition(40, 0);
295-
// arrowLeftButton.setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
296-
// arrowLeftButton.setTrigger(&touchTrigger);
297-
// arrowLeftButton.setTrigger(&wpadTouchTrigger);
298-
// arrowLeftButton.setTrigger(&buttonLTrigger);
299-
// arrowLeftButton.setSoundClick(buttonClickSound);
300-
// arrowLeftButton.clicked.connect(this, &HomebrewWindow::OnLeftArrowClick);
301-
//
302-
// arrowRightButton.setImage(&arrowRightImage);
303-
// arrowRightButton.setEffectGrow();
304-
// arrowRightButton.setPosition(-40, 0);
305-
// arrowRightButton.setAlignment(ALIGN_RIGHT | ALIGN_MIDDLE);
306-
// arrowRightButton.setTrigger(&touchTrigger);
307-
// arrowRightButton.setTrigger(&wpadTouchTrigger);
308-
// arrowRightButton.setTrigger(&buttonRTrigger);
309-
// arrowRightButton.setSoundClick(buttonClickSound);
310-
// arrowRightButton.clicked.connect(this, &HomebrewWindow::OnRightArrowClick);
311-
// append(&arrowRightButton);
312-
// }
234+
313235

314236
hblVersionText.setAlignment(ALIGN_BOTTOM | ALIGN_RIGHT);
315-
hblVersionText.setPosition(-30, 0);
237+
hblVersionText.setPosition(0, 0);
316238
append(&hblVersionText);
317239
}
318240

src/menu/HomebrewWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class HomebrewWindow : public GuiFrame, public sigslot::has_slots<>
4646
float scrollOffY = 0;
4747
float lastScrollOffY = 0;
4848
std::vector<homebrewButton> homebrewButtons;
49+
50+
void positionHomebrewButton(homebrewButton*, int);
4951

5052
private:
5153
void OnOpenEffectFinish(GuiElement *element);

0 commit comments

Comments
 (0)