Example #1
0
string choiceRev(string revs)
{
	bool stop = false;
	string rev = "NULL";

	TextLine versions;
	versions.list(revs);

	GuiText titleTxt(tr("Update"), 26, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
	titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
	titleTxt.SetPosition(0, 40);

	GuiWindow promptWindow(520,360);
	promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
	promptWindow.SetPosition(0, -10);
	GuiTrigger trigA;
	trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);

	GuiImageData dialogBox(Theme.dialog_background);
	GuiImage dialogBoxImg(&dialogBox);

	int place = 23;
	int y = 150;
	int i = 0;
	int number = 5;
	int selection = 0;
	int selctionPos = y;

	GuiText selectionTxt(">>                              <<", 20, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
	selectionTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
	selectionTxt.SetPosition(0, y);

	GuiText upTxt("c", 22, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
	upTxt.SetFont(symbol_ttf, symbol_ttf_size);
	upTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
	upTxt.SetPosition(0, y -20);

	GuiText downTxt("d", 22, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
	downTxt.SetFont(symbol_ttf, symbol_ttf_size);
	downTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
	downTxt.SetPosition(0, y + (place * (number-1)) + 15);

	GuiText * Entrie[number];

	for(i=0; i < number && i < (signed)versions.line.size(); i++)
	{
		Entrie[i] = new GuiText(versions.line[i].c_str(), 20, (GXColor) {Theme.text_1, Theme.text_2, Theme.text_3, 255});
		Entrie[i]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
		Entrie[i]->SetPosition(0, y);
		y += place;
	}

	promptWindow.Append(&dialogBoxImg);
	promptWindow.Append(&titleTxt);
	promptWindow.Append(&selectionTxt);

	for(int x=0; x < i; x++)
		promptWindow.Append(Entrie[x]);

	if((signed)versions.line.size() >= number)
	{
		promptWindow.Append(&upTxt);
		promptWindow.Append(&downTxt);
	}

	promptWindow.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 50);
	HaltGui();
	mainWindow->SetState(STATE_DISABLED);
	mainWindow->Append(&promptWindow);
	mainWindow->ChangeFocus(&promptWindow);
	ResumeGui();

	while(!stop)
	{
		usleep(100);

		if(WPAD_ButtonsHeld(0) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP) || PAD_ButtonsDown(0) & PAD_BUTTON_UP)
		{

			selection--;
			if(selection < 0)
			{
				selection = 0;

				int z = versions.text_up();
				for(int x=0; x < i; x++)
					Entrie[x]->SetText(versions.line[x + z].c_str());
			}
			selectionTxt.SetPosition(0, selection * place + selctionPos);

			HaltResumeGui();
			usleep(100000);
		}

		if(WPAD_ButtonsHeld(0) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN) || PAD_ButtonsDown(0) & PAD_BUTTON_DOWN)
		{

			selection++;
			if(selection > number -1)
			{
				selection = number -1;

				int z = versions.text_down(number);
				for(int x=0; x < i; x++)
					Entrie[x]->SetText(versions.line[x + z].c_str());
			}
			selectionTxt.SetPosition(0, selection * place + selctionPos);

			HaltResumeGui();
			usleep(100000);
		}

		if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A) || PAD_ButtonsDown(0) & PAD_BUTTON_A)
		{
			rev = versions.line[selection + versions.textScrollPos];
			stop = true;
		}

		if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B) || PAD_ButtonsDown(0) & PAD_BUTTON_B)
			stop = true;
	}

	promptWindow.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50);
	while(promptWindow.GetEffect() > 0) usleep(100);
	HaltGui();
	mainWindow->Remove(&promptWindow);
	mainWindow->SetState(STATE_DEFAULT);
	ResumeGui();
	return rev;
}
string FontList()
{
	string downloadfont = "error";
	bool stop = false;

	char buffer[100];
	sprintf(buffer, "http://www.nanolx.org/hbf/Fonts/");

	struct block file = downloadfile(buffer);
	if (file.data != NULL)
	{
		string source_fonts = (char*)file.data;
		vector<string> fonts;

		while(1)
		{
			if((signed)source_fonts.find("../Fonts/") == -1)
				break;

			source_fonts.erase(0, source_fonts.find("../Fonts/"));
			source_fonts.erase(0, source_fonts.find("s/") +2);

			fonts.push_back(source_fonts.substr(0, source_fonts.find("\"")));

			source_fonts.erase(0, source_fonts.find("<"));
		}

		free(file.data);

		GuiText titleTxt(tr("Download"), 26, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
		titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
		titleTxt.SetPosition(0, 40);

		GuiWindow promptWindow(520,360);
		promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
		promptWindow.SetPosition(0, -10);
		GuiTrigger trigA;
		trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);

		GuiImageData dialogBox(Theme.dialog_background);
		GuiImage dialogBoxImg(&dialogBox);

		int place = 23;
		int y = 150;
		int i = 0;
		int number = 5;
		int selection = 0;
		int textScrollPos = 0;
		int selctionPos = y;

		GuiText selectionTxt(">>                                                                    <<", 20, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
		selectionTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
		selectionTxt.SetPosition(0, y);

		GuiText upTxt("c", 22, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
		upTxt.SetFont(symbol_ttf, symbol_ttf_size);
		upTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
		upTxt.SetPosition(0, y -20);

		GuiText downTxt("d", 22, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
		downTxt.SetFont(symbol_ttf, symbol_ttf_size);
		downTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
		downTxt.SetPosition(0, y + (place * (number-1)) + 15);

		GuiText * Entrie[number];

		for(i=0; i < number && i < (signed)fonts.size(); i++)
		{
			Entrie[i] = new GuiText(fonts[i].c_str(), 20, (GXColor) {Theme.text_1, Theme.text_2, Theme.text_3, 255});
			Entrie[i]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
			Entrie[i]->SetPosition(0, y);
			Entrie[i]->SetMaxWidth(300, SCROLL_HORIZONTAL);
			y += place;
		}

		promptWindow.Append(&dialogBoxImg);
		promptWindow.Append(&titleTxt);
		promptWindow.Append(&selectionTxt);

		for(int x=0; x < i; x++)
			promptWindow.Append(Entrie[x]);

		if((signed)fonts.size() >= number)
		{
			promptWindow.Append(&upTxt);
			promptWindow.Append(&downTxt);
		}

		promptWindow.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 50);
		HaltGui();
		mainWindow->SetState(STATE_DISABLED);
		mainWindow->Append(&promptWindow);
		mainWindow->ChangeFocus(&promptWindow);
		ResumeGui();

		while(!stop)
		{
			usleep(100);

			if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP) || PAD_ButtonsDown(0) & PAD_BUTTON_UP
			   || WUPC_ButtonsDown(0) & WPAD_CLASSIC_BUTTON_UP)
			{
				selection--;
				if(selection < 0)
				{
					selection = 0;
					textScrollPos--;
					if(textScrollPos < 0)
						textScrollPos = 0;

					for(int x=0; x < number && x < (signed)fonts.size(); x++)
						Entrie[x]->SetText(fonts[x + textScrollPos].c_str());
				}
				selectionTxt.SetPosition(0, selection * place + selctionPos);

				HaltResumeGui();
			}

			if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN) || PAD_ButtonsDown(0) & PAD_BUTTON_DOWN
			   || WUPC_ButtonsDown(0) & WPAD_CLASSIC_BUTTON_DOWN)
			{
				selection++;
				if(selection == (signed)fonts.size())
					selection = fonts.size() -1;
				if(selection > number -1)
				{
					selection = number -1;
					textScrollPos++;
					if(textScrollPos > (signed)fonts.size() - number)
						textScrollPos = fonts.size() - number;

					for(int x=0; x < number && x < (signed)fonts.size(); x++)
						Entrie[x]->SetText(fonts[x + textScrollPos].c_str());
				}
				selectionTxt.SetPosition(0, selection * place + selctionPos);

				HaltResumeGui();
			}

			if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A) || PAD_ButtonsDown(0) & PAD_BUTTON_A
			   || WUPC_ButtonsDown(0) & WPAD_CLASSIC_BUTTON_A)
			{
				downloadfont = fonts[selection + textScrollPos];
				stop = true;
			}

			if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B) || PAD_ButtonsDown(0) & PAD_BUTTON_B
			   || WUPC_ButtonsDown(0) & WPAD_CLASSIC_BUTTON_B)
			{
				downloadfont = "NULL";
				stop = true;
			}
		}

		promptWindow.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50);
		while(promptWindow.GetEffect() > 0) usleep(100);
		HaltGui();
		mainWindow->Remove(&promptWindow);
		mainWindow->SetState(STATE_DEFAULT);
		ResumeGui();
	}

	return downloadfont;
}