mirror of
https://github.com/BernardoGiordano/Checkpoint
synced 2024-11-28 19:40:18 +00:00
Update scrollable drawing logic
This commit is contained in:
parent
258b4a7d70
commit
e0cc88bf2e
11 changed files with 126 additions and 65 deletions
|
@ -49,8 +49,6 @@ namespace Gui
|
|||
void exit(void);
|
||||
|
||||
bool askForConfirmation(const std::string& text);
|
||||
bool bottomScroll(void);
|
||||
void bottomScroll(bool enable);
|
||||
void showError(Result res, const std::string& message);
|
||||
void showInfo(const std::string& message);
|
||||
void draw(void);
|
||||
|
|
35
3ds/include/main.hpp
Normal file
35
3ds/include/main.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of Checkpoint
|
||||
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#ifndef MAIN_HPP
|
||||
#define MAIN_HPP
|
||||
|
||||
#include "thread.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
extern bool g_bottomScrollEnabled;
|
||||
|
||||
#endif
|
|
@ -33,6 +33,7 @@
|
|||
#include "clickable.hpp"
|
||||
#include "colors.hpp"
|
||||
#include "hid.hpp"
|
||||
#include "main.hpp"
|
||||
|
||||
class Scrollable : public IScrollable<u32>
|
||||
{
|
||||
|
@ -50,7 +51,7 @@ public:
|
|||
|
||||
void draw(void) override;
|
||||
void setIndex(size_t i);
|
||||
void push_back(u32 color, u32 colorMessage, const std::string& message) override;
|
||||
void push_back(u32 color, u32 colorMessage, const std::string& message, bool selected) override;
|
||||
void resetIndex(void) override;
|
||||
void updateSelection(void) override;
|
||||
|
||||
|
|
|
@ -58,23 +58,26 @@ bool Clickable::released(void)
|
|||
|
||||
void Clickable::draw(float size, u32 overlay)
|
||||
{
|
||||
static const float messageHeight = ceilf(size*fontGetInfo()->lineFeed);
|
||||
const float messageWidth = mCentered ? mC2dText.width * size : mw- (mSelected ? 20 : 8);
|
||||
const u8 r = overlay & 0xFF;
|
||||
const u8 g = (overlay >> 8) & 0xFF;
|
||||
const u8 b = (overlay >> 16) & 0xFF;
|
||||
const float messageHeight = ceilf(size * fontGetInfo()->lineFeed);
|
||||
const float messageWidth = mCentered ? mC2dText.width * size : mw - (mSelected ? 20 : 8);
|
||||
|
||||
C2D_DrawRectSolid(mx, my, 0.5f, mw, mh, mColorBg);
|
||||
if (mCanInvertColor && held())
|
||||
{
|
||||
C2D_DrawRectSolid(mx, my, 0.5f, mw, mh, overlay);
|
||||
C2D_DrawRectSolid(mx, my, 0.5f, mw, mh, C2D_Color32(r, g, b, 100));
|
||||
}
|
||||
if (mSelected)
|
||||
{
|
||||
C2D_DrawRectSolid(mx + 4, my + 6, 0.5f, 4, mh - 12, COLOR_WHITE);
|
||||
C2D_DrawRectSolid(mx, my, 0.5f, mw, mh, (overlay & 0x00FFFFF) | (100 << 24));
|
||||
C2D_DrawRectSolid(mx, my, 0.5f, mw, mh, C2D_Color32(r, g, b, 100));
|
||||
}
|
||||
C2D_DrawText(&mC2dText, C2D_WithColor, mx + (mSelected ? 8 : 0) + (mw - messageWidth)/2, my + (mh - messageHeight)/2, 0.5f, size, size, mColorText);
|
||||
C2D_DrawText(&mC2dText, C2D_WithColor, mx + (mSelected ? 8 : 0) + (mw - messageWidth)/2, my + ceilf((mh - messageHeight) / 2), 0.5f, size, size, mColorText);
|
||||
}
|
||||
|
||||
void Clickable::drawOutline(u32 color)
|
||||
{
|
||||
drawPulsingOutline(mx, my, mw, mh, 4, color);
|
||||
drawPulsingOutline(mx, my, mw, mh, 2, color);
|
||||
}
|
|
@ -43,17 +43,17 @@ static C2D_Text checkpoint, version;
|
|||
static Clickable* buttonBackup;
|
||||
static Clickable* buttonRestore;
|
||||
static Scrollable* directoryList;
|
||||
bool g_bottomScrollEnabled;
|
||||
|
||||
static const size_t rowlen = 4;
|
||||
static const size_t collen = 8;
|
||||
static bool bottomScrollEnabled;
|
||||
static HidHorizontal* hid;
|
||||
|
||||
static void drawBackground(gfxScreen_t screen);
|
||||
static void drawSelector(void);
|
||||
static int selectorX(size_t i);
|
||||
static int selectorY(size_t i);
|
||||
static float timer = 0;
|
||||
float g_timer = 0;
|
||||
|
||||
C2D_Image Gui::TWLIcon(void)
|
||||
{
|
||||
|
@ -99,7 +99,7 @@ void drawPulsingOutline(u32 x, u32 y, u16 w, u16 h, u8 size, u32 color)
|
|||
u8 r = color & 0xFF;
|
||||
u8 g = (color >> 8) & 0xFF;
|
||||
u8 b = (color >> 16) & 0xFF;
|
||||
float highlight_multiplier = fmax(0.0, fabs(fmod(timer, 1.0) - 0.5) / 0.5);
|
||||
float highlight_multiplier = fmax(0.0, fabs(fmod(g_timer, 1.0) - 0.5) / 0.5);
|
||||
color = C2D_Color32(r + (255 - r) * highlight_multiplier, g + (255 - g) * highlight_multiplier, b + (255 - b) * highlight_multiplier, 255);
|
||||
C2D_DrawRectSolid(x - size, y - size, 0.5f, w + 2*size, size, color); // top
|
||||
C2D_DrawRectSolid(x - size, y, 0.5f, size, h, color); // left
|
||||
|
@ -291,7 +291,7 @@ void Gui::init(void)
|
|||
top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
|
||||
bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
|
||||
|
||||
bottomScrollEnabled = false;
|
||||
g_bottomScrollEnabled = false;
|
||||
hid = new HidHorizontal(rowlen * collen, collen);
|
||||
|
||||
buttonBackup = new Clickable(204, 102, 110, 54, COLOR_GREY_DARKER, COLOR_WHITE, "Backup \uE004", true);
|
||||
|
@ -345,43 +345,42 @@ void Gui::exit(void)
|
|||
gfxExit();
|
||||
}
|
||||
|
||||
bool Gui::bottomScroll(void)
|
||||
{
|
||||
return bottomScrollEnabled;
|
||||
}
|
||||
|
||||
size_t Gui::index(void)
|
||||
{
|
||||
return hid->fullIndex();
|
||||
}
|
||||
|
||||
void Gui::bottomScroll(bool enable)
|
||||
{
|
||||
bottomScrollEnabled = enable;
|
||||
}
|
||||
|
||||
void Gui::updateButtonsColor(void)
|
||||
{
|
||||
if (MS::multipleSelectionEnabled())
|
||||
{
|
||||
buttonBackup->setColors(COLOR_WHITE, COLOR_BLACK);
|
||||
buttonRestore->setColors(COLOR_WHITE, COLOR_GREY_LIGHT);
|
||||
buttonRestore->canInvertColor(true);
|
||||
buttonRestore->canInvertColor(false);
|
||||
// buttonCheats->canInvertColor(false);
|
||||
buttonBackup->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
|
||||
buttonRestore->setColors(COLOR_GREY_DARKER, COLOR_GREY_LIGHT);
|
||||
// buttonCheats->setColors(COLOR_GREY_DARKER, COLOR_GREY_LIGHT);
|
||||
}
|
||||
else if (bottomScrollEnabled)
|
||||
else if (g_bottomScrollEnabled)
|
||||
{
|
||||
buttonBackup->setColors(COLOR_WHITE, COLOR_BLACK);
|
||||
buttonRestore->setColors(COLOR_WHITE, COLOR_BLACK);
|
||||
buttonBackup->canInvertColor(true);
|
||||
buttonRestore->canInvertColor(true);
|
||||
// buttonCheats->canInvertColor(true);
|
||||
buttonBackup->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
|
||||
buttonRestore->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
|
||||
// buttonCheats->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonBackup->setColors(COLOR_WHITE, COLOR_GREY_LIGHT);
|
||||
buttonRestore->setColors(COLOR_WHITE, COLOR_GREY_LIGHT);
|
||||
buttonBackup->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
|
||||
buttonRestore->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
|
||||
// buttonCheats->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
void Gui::updateSelector(void)
|
||||
{
|
||||
if (!bottomScrollEnabled)
|
||||
if (!g_bottomScrollEnabled)
|
||||
{
|
||||
if (getTitleCount() > 0)
|
||||
{
|
||||
|
@ -400,7 +399,7 @@ static void drawSelector(void)
|
|||
static const int w = 2;
|
||||
const int x = selectorX(hid->index());
|
||||
const int y = selectorY(hid->index());
|
||||
float highlight_multiplier = fmax(0.0, fabs(fmod(timer, 1.0) - 0.5) / 0.5);
|
||||
float highlight_multiplier = fmax(0.0, fabs(fmod(g_timer, 1.0) - 0.5) / 0.5);
|
||||
u8 r = COLOR_SELECTOR & 0xFF;
|
||||
u8 g = (COLOR_SELECTOR >> 8) & 0xFF;
|
||||
u8 b = (COLOR_SELECTOR >> 16) & 0xFF;
|
||||
|
@ -487,11 +486,7 @@ void Gui::draw(void)
|
|||
|
||||
for (size_t i = 0; i < dirs.size(); i++)
|
||||
{
|
||||
directoryList->push_back(COLOR_WHITE, bottomScrollEnabled ? COLOR_BLUE : COLOR_GREY_LIGHT, convert.to_bytes(dirs.at(i)));
|
||||
if (i == directoryList->index())
|
||||
{
|
||||
directoryList->invertCellColors(i);
|
||||
}
|
||||
directoryList->push_back(COLOR_GREY_DARKER, COLOR_WHITE, convert.to_bytes(dirs.at(i)), i == directoryList->index());
|
||||
}
|
||||
|
||||
C2D_TextBufClear(dynamicBuf);
|
||||
|
@ -530,15 +525,12 @@ void Gui::draw(void)
|
|||
C2D_DrawRectSolid(260, 27, 0.5f, 52, 52, COLOR_BLACK);
|
||||
C2D_DrawImageAt(title.icon(), 262, 29, 0.5f, NULL, 1.0f, 1.0f);
|
||||
|
||||
C2D_DrawRectSolid(4, 100, 0.5f, 312, 114, COLOR_GREY_LIGHT);
|
||||
C2D_DrawRectSolid(6, 102, 0.5f, 308, 110, COLOR_GREY_DARK);
|
||||
|
||||
C2D_DrawRectSolid(4, 100, 0.5f, 312, 114, COLOR_GREY_DARK);
|
||||
C2D_DrawRectSolid(202, 102, 0.5f, 2, 110, COLOR_GREY_DARK);
|
||||
C2D_DrawRectSolid(204, 156, 0.5f, 110, 2, COLOR_GREY_DARK);
|
||||
directoryList->draw();
|
||||
buttonBackup->draw(0.7, 0);
|
||||
buttonRestore->draw(0.7, 0);
|
||||
|
||||
C2D_DrawRectSolid(202, 102, 0.5f, 2, 110, COLOR_GREY_LIGHT);
|
||||
C2D_DrawRectSolid(204, 156, 0.5f, 110, 2, COLOR_GREY_LIGHT);
|
||||
}
|
||||
|
||||
C2D_DrawText(&ins4, C2D_WithColor, ceilf((320 - ins4.width*0.47f) / 2), 224, 0.5f, 0.47f, 0.47f, COLOR_WHITE);
|
||||
|
@ -563,5 +555,5 @@ void Gui::resetIndex(void)
|
|||
void Gui::frameEnd(void)
|
||||
{
|
||||
C3D_FrameEnd(0);
|
||||
timer += 0.025f;
|
||||
g_timer += 0.025f;
|
||||
}
|
|
@ -24,8 +24,7 @@
|
|||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "thread.hpp"
|
||||
#include "util.hpp"
|
||||
#include "main.hpp"
|
||||
|
||||
int main() {
|
||||
if (R_FAILED(servicesInit())) {
|
||||
|
@ -52,7 +51,7 @@ int main() {
|
|||
if (kDown & KEY_A)
|
||||
{
|
||||
// If backup list is active...
|
||||
if (Gui::bottomScroll())
|
||||
if (g_bottomScrollEnabled)
|
||||
{
|
||||
// If the "New..." entry is selected...
|
||||
if (0 == Gui::scrollableIndex())
|
||||
|
@ -69,7 +68,7 @@ int main() {
|
|||
// Activate backup list only if multiple selections are not enabled
|
||||
if (!MS::multipleSelectionEnabled())
|
||||
{
|
||||
Gui::bottomScroll(true);
|
||||
g_bottomScrollEnabled = true;
|
||||
Gui::updateButtonsColor();
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +76,7 @@ int main() {
|
|||
|
||||
if (kDown & KEY_B)
|
||||
{
|
||||
Gui::bottomScroll(false);
|
||||
g_bottomScrollEnabled = false;
|
||||
MS::clearSelectedEntries();
|
||||
Gui::resetScrollableIndex();
|
||||
Gui::updateButtonsColor();
|
||||
|
@ -85,7 +84,7 @@ int main() {
|
|||
|
||||
if (kDown & KEY_X)
|
||||
{
|
||||
if (Gui::bottomScroll())
|
||||
if (g_bottomScrollEnabled)
|
||||
{
|
||||
bool isSaveMode = Archive::mode() == MODE_SAVE;
|
||||
size_t index = Gui::scrollableIndex();
|
||||
|
@ -111,10 +110,10 @@ int main() {
|
|||
|
||||
if (kDown & KEY_Y)
|
||||
{
|
||||
if (Gui::bottomScroll())
|
||||
if (g_bottomScrollEnabled)
|
||||
{
|
||||
Gui::resetScrollableIndex();
|
||||
Gui::bottomScroll(false);
|
||||
g_bottomScrollEnabled = false;
|
||||
}
|
||||
MS::addSelectedEntry(Gui::index());
|
||||
Gui::updateButtonsColor(); // Do this last
|
||||
|
@ -170,7 +169,7 @@ int main() {
|
|||
MS::clearSelectedEntries();
|
||||
Gui::updateButtonsColor();
|
||||
}
|
||||
else if (Gui::bottomScroll())
|
||||
else if (g_bottomScrollEnabled)
|
||||
{
|
||||
io::backup(Gui::index());
|
||||
}
|
||||
|
@ -183,7 +182,7 @@ int main() {
|
|||
MS::clearSelectedEntries();
|
||||
Gui::updateButtonsColor();
|
||||
}
|
||||
else if (Gui::bottomScroll())
|
||||
else if (g_bottomScrollEnabled)
|
||||
{
|
||||
io::restore(Gui::index());
|
||||
}
|
||||
|
|
|
@ -38,10 +38,11 @@ void Scrollable::resetIndex(void)
|
|||
setIndex(0);
|
||||
}
|
||||
|
||||
void Scrollable::push_back(u32 color, u32 colorMessage, const std::string& message)
|
||||
void Scrollable::push_back(u32 color, u32 colorMessage, const std::string& message, bool selected)
|
||||
{
|
||||
static const float spacing = mh / mVisibleEntries;
|
||||
Clickable* cell = new Clickable(mx, my + (size() % mVisibleEntries)*spacing, mw, spacing, color, colorMessage, message, false);
|
||||
cell->selected(selected);
|
||||
mCells.push_back(cell);
|
||||
}
|
||||
|
||||
|
@ -70,4 +71,18 @@ void Scrollable::draw(void)
|
|||
{
|
||||
mCells.at(i)->draw(0.5f, 0);
|
||||
}
|
||||
|
||||
size_t blankRows = mVisibleEntries - sz;
|
||||
size_t rowHeight = mh / mVisibleEntries;
|
||||
C2D_DrawRectSolid(mx, my + sz * rowHeight, 0.5f, mw, rowHeight * blankRows, COLOR_GREY_DARKER);
|
||||
|
||||
// draw selector
|
||||
for (size_t i = baseIndex; i < baseIndex + sz; i++)
|
||||
{
|
||||
if (mCells.at(i)->selected())
|
||||
{
|
||||
mCells.at(i)->drawOutline(g_bottomScrollEnabled ? COLOR_BLUE : COLOR_GREY_LIGHT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
}
|
||||
|
||||
virtual void draw(void) = 0;
|
||||
virtual void push_back(T color, T colorMessage, const std::string& message) = 0;
|
||||
virtual void push_back(T color, T colorMessage, const std::string& message, bool selected) = 0;
|
||||
virtual void updateSelection(void) = 0;
|
||||
|
||||
std::string cellName(size_t index)
|
||||
|
|
|
@ -1,3 +1,29 @@
|
|||
/*
|
||||
* This file is part of Checkpoint
|
||||
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#ifndef MAIN_HPP
|
||||
#define MAIN_HPP
|
||||
|
||||
|
|
|
@ -51,8 +51,7 @@ public:
|
|||
|
||||
void draw(void) override;
|
||||
void setIndex(size_t i);
|
||||
void push_back(SDL_Color color, SDL_Color colorMessage, const std::string& message);
|
||||
void push_back(SDL_Color color, SDL_Color colorMessage, const std::string& message, bool selected);
|
||||
void push_back(SDL_Color color, SDL_Color colorMessage, const std::string& message, bool selected) override;
|
||||
void resetIndex(void) override;
|
||||
void updateSelection(void) override;
|
||||
|
||||
|
|
|
@ -39,13 +39,6 @@ void Scrollable::resetIndex(void)
|
|||
mHid->page(0);
|
||||
}
|
||||
|
||||
void Scrollable::push_back(SDL_Color color, SDL_Color colorMessage, const std::string& message)
|
||||
{
|
||||
static const float spacing = mh / mVisibleEntries;
|
||||
Clickable* cell = new Clickable(mx, my + (size() % mVisibleEntries)*spacing, mw, spacing, color, colorMessage, message, false);
|
||||
mCells.push_back(cell);
|
||||
}
|
||||
|
||||
void Scrollable::push_back(SDL_Color color, SDL_Color colorMessage, const std::string& message, bool selected)
|
||||
{
|
||||
static const float spacing = mh / mVisibleEntries;
|
||||
|
|
Loading…
Reference in a new issue