mirror of
https://github.com/BernardoGiordano/Checkpoint
synced 2025-02-18 00:08:24 +00:00
merge Info and Error in a single class
This commit is contained in:
parent
7fed66dc9c
commit
1b4674d65b
9 changed files with 57 additions and 127 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
build/
|
build/
|
||||||
output/
|
out/
|
2
Makefile
2
Makefile
|
@ -15,7 +15,7 @@ APP_DESCRIPTION := Fast and simple save manager
|
||||||
APP_AUTHOR := Bernardo Giordano
|
APP_AUTHOR := Bernardo Giordano
|
||||||
|
|
||||||
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
|
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
|
||||||
OUTDIR := output
|
OUTDIR := out
|
||||||
BUILD := build
|
BUILD := build
|
||||||
SOURCES := source/pp2d source
|
SOURCES := source/pp2d source
|
||||||
INCLUDES := include
|
INCLUDES := include
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "clickable.h"
|
#include "clickable.h"
|
||||||
#include "datetime.h"
|
#include "datetime.h"
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
#include "error.h"
|
|
||||||
#include "fsstream.h"
|
#include "fsstream.h"
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "hid.h"
|
#include "hid.h"
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
/* This file is part of Checkpoint
|
|
||||||
> Copyright (C) 2017 Bernardo Giordano
|
|
||||||
>
|
|
||||||
> 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/>.
|
|
||||||
> See LICENSE for information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ERROR_H
|
|
||||||
#define ERROR_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
class Error
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void init(Result res, std::string message);
|
|
||||||
void resetTtl(void);
|
|
||||||
void draw(void);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Result res;
|
|
||||||
std::string message;
|
|
||||||
size_t width;
|
|
||||||
size_t height;
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int ttl;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -21,11 +21,17 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TYPE_INFO,
|
||||||
|
TYPE_ERROR
|
||||||
|
} Info_t;
|
||||||
|
|
||||||
class Info
|
class Info
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void init(std::string title, std::string message, int ttl);
|
void init(std::string title, std::string message, int ttl, Info_t type);
|
||||||
void resetTtl(void);
|
void init(Result res, std::string message, int ttl, Info_t type);
|
||||||
|
void resetTTL(void);
|
||||||
void draw(void);
|
void draw(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -36,6 +42,8 @@ private:
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int ttl;
|
int ttl;
|
||||||
|
Result res;
|
||||||
|
Info_t type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
/* This file is part of Checkpoint
|
|
||||||
> Copyright (C) 2017 Bernardo Giordano
|
|
||||||
>
|
|
||||||
> 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/>.
|
|
||||||
> See LICENSE for information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
void Error::init(Result res_, std::string message_)
|
|
||||||
{
|
|
||||||
res = res_;
|
|
||||||
message = message_;
|
|
||||||
width = 240;
|
|
||||||
height = 70;
|
|
||||||
x = (TOP_WIDTH - width) / 2;
|
|
||||||
y = SCREEN_HEIGHT - height - 9;
|
|
||||||
ttl = 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Error::resetTtl(void)
|
|
||||||
{
|
|
||||||
ttl = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Error::draw(void)
|
|
||||||
{
|
|
||||||
static const float size = 0.6f;
|
|
||||||
|
|
||||||
if (ttl > 0 && res != 0)
|
|
||||||
{
|
|
||||||
char buf[30];
|
|
||||||
float w, hres;
|
|
||||||
float hmessage = pp2d_get_text_height_wrap(message.c_str(), 0.46, 0.46, width - 20);
|
|
||||||
int normalizedTransparency = ttl > 255 ? 255 : ttl;
|
|
||||||
u32 color = RGBA8(255, 255, 255, normalizedTransparency);
|
|
||||||
sprintf(buf, "Error: %08lX", res);
|
|
||||||
pp2d_get_text_size(&w, &hres, size, size, buf);
|
|
||||||
static const int wrapWidth = width - 20;
|
|
||||||
float spacing = (height - hres - hmessage) / 3;
|
|
||||||
|
|
||||||
pp2d_draw_rectangle(x - 2, y - 2, width + 4, height + 4, RGBA8(255, 0, 0, normalizedTransparency));
|
|
||||||
pp2d_draw_rectangle(x, y, width, height, RGBA8(0, 0, 0, normalizedTransparency));
|
|
||||||
pp2d_draw_text(x + (width - w) / 2, y + spacing, size, size, color, buf);
|
|
||||||
pp2d_draw_text_wrap(x + 10, y + 2*spacing + hres, 0.46, 0.46, color, wrapWidth, message.c_str());
|
|
||||||
|
|
||||||
ttl--;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,10 +17,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static Info info;
|
static Info info;
|
||||||
static Error error;
|
|
||||||
static Clickable* buttonBackup;
|
static Clickable* buttonBackup;
|
||||||
static Clickable* buttonRestore;
|
static Clickable* buttonRestore;
|
||||||
static MessageBox* messageBox;
|
static MessageBox* messageBox;
|
||||||
|
@ -95,8 +93,7 @@ Gui::Gui(void)
|
||||||
index = 0;
|
index = 0;
|
||||||
page = 0;
|
page = 0;
|
||||||
bottomScrollEnabled = false;
|
bottomScrollEnabled = false;
|
||||||
info.init("", "", 0);
|
info.init("", "", 0, TYPE_INFO);
|
||||||
error.init(0, "");
|
|
||||||
buttonBackup = new Clickable(204, 102, 110, 54, WHITE, bottomScrollEnabled ? BLACK : GREYISH, "Backup \uE008", true);
|
buttonBackup = new Clickable(204, 102, 110, 54, WHITE, bottomScrollEnabled ? BLACK : GREYISH, "Backup \uE008", true);
|
||||||
buttonRestore = new Clickable(204, 158, 110, 54, WHITE, bottomScrollEnabled ? BLACK : GREYISH, "Restore \uE007", true);
|
buttonRestore = new Clickable(204, 158, 110, 54, WHITE, bottomScrollEnabled ? BLACK : GREYISH, "Restore \uE007", true);
|
||||||
messageBox = new MessageBox(COLOR_BARS, WHITE, GFX_TOP);
|
messageBox = new MessageBox(COLOR_BARS, WHITE, GFX_TOP);
|
||||||
|
@ -114,14 +111,12 @@ Gui::Gui(void)
|
||||||
|
|
||||||
void Gui::createInfo(std::string title, std::string message)
|
void Gui::createInfo(std::string title, std::string message)
|
||||||
{
|
{
|
||||||
error.resetTtl();
|
info.init(title, message, 500, TYPE_INFO);
|
||||||
info.init(title, message, 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gui::createError(Result res, std::string message)
|
void Gui::createError(Result res, std::string message)
|
||||||
{
|
{
|
||||||
info.resetTtl();
|
info.init(res, message, 500, TYPE_ERROR);
|
||||||
error.init(res, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Gui::getBottomScroll(void)
|
bool Gui::getBottomScroll(void)
|
||||||
|
@ -180,7 +175,6 @@ void Gui::drawSelector(void)
|
||||||
pp2d_draw_rectangle( x, y + w, w, 50 - 2*w, RED); //left
|
pp2d_draw_rectangle( x, y + w, w, 50 - 2*w, RED); //left
|
||||||
pp2d_draw_rectangle(x + 50 - w, y + w, w, 50 - 2*w, RED); //right
|
pp2d_draw_rectangle(x + 50 - w, y + w, w, 50 - 2*w, RED); //right
|
||||||
pp2d_draw_rectangle( x, y + 50 - w, 50, w, RED); //bottom
|
pp2d_draw_rectangle( x, y + 50 - w, 50, w, RED); //bottom
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Gui::getSelectorX(size_t index)
|
int Gui::getSelectorX(size_t index)
|
||||||
|
@ -238,7 +232,6 @@ void Gui::draw(void)
|
||||||
pp2d_draw_text(border + p1width + p2width, 224, 0.47f, 0.47f, WHITE, ".");
|
pp2d_draw_text(border + p1width + p2width, 224, 0.47f, 0.47f, WHITE, ".");
|
||||||
|
|
||||||
info.draw();
|
info.draw();
|
||||||
error.draw();
|
|
||||||
|
|
||||||
if (hidKeysHeld() & KEY_SELECT)
|
if (hidKeysHeld() & KEY_SELECT)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
|
|
||||||
void Info::init(std::string _title, std::string _message, int _ttl)
|
void Info::init(std::string _title, std::string _message, int _ttl, Info_t _type)
|
||||||
{
|
{
|
||||||
title = _title;
|
title = _title;
|
||||||
message = _message;
|
message = _message;
|
||||||
|
@ -27,9 +27,24 @@ void Info::init(std::string _title, std::string _message, int _ttl)
|
||||||
x = (TOP_WIDTH - width) / 2;
|
x = (TOP_WIDTH - width) / 2;
|
||||||
y = SCREEN_HEIGHT - height - 9;
|
y = SCREEN_HEIGHT - height - 9;
|
||||||
ttl = _ttl;
|
ttl = _ttl;
|
||||||
|
type = _type;
|
||||||
|
res = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Info::resetTtl(void)
|
void Info::init(Result _res, std::string _message, int _ttl, Info_t _type)
|
||||||
|
{
|
||||||
|
title = "";
|
||||||
|
message = _message;
|
||||||
|
width = 240;
|
||||||
|
height = 70;
|
||||||
|
x = (TOP_WIDTH - width) / 2;
|
||||||
|
y = SCREEN_HEIGHT - height - 9;
|
||||||
|
ttl = _ttl;
|
||||||
|
type = _type;
|
||||||
|
res = _res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Info::resetTTL(void)
|
||||||
{
|
{
|
||||||
ttl = 0;
|
ttl = 0;
|
||||||
}
|
}
|
||||||
|
@ -38,20 +53,36 @@ void Info::draw(void)
|
||||||
{
|
{
|
||||||
static const float size = 0.6f;
|
static const float size = 0.6f;
|
||||||
|
|
||||||
if (ttl > 0)
|
if ((type == TYPE_INFO && ttl > 0) || (type == TYPE_ERROR && ttl > 0 && res != 0))
|
||||||
{
|
{
|
||||||
|
char buf[30];
|
||||||
float w, hres;
|
float w, hres;
|
||||||
float hmessage = pp2d_get_text_height_wrap(message.c_str(), 0.46, 0.46, width - 20);
|
float hmessage = pp2d_get_text_height_wrap(message.c_str(), 0.46, 0.46, width - 20);
|
||||||
int normalizedTransparency = ttl > 255 ? 255 : ttl;
|
int normalizedTransparency = ttl > 255 ? 255 : ttl;
|
||||||
u32 color = RGBA8(0, 0, 255, normalizedTransparency);
|
u32 color = 0, bordercolor = 0, bgcolor = 0;
|
||||||
|
|
||||||
pp2d_get_text_size(&w, &hres, size, size, title.c_str());
|
if (type == TYPE_ERROR)
|
||||||
static const int wrapWidth = width - 20;
|
{
|
||||||
float spacing = (height - hres - hmessage) / 3;
|
color = RGBA8(255, 255, 255, normalizedTransparency);
|
||||||
|
bordercolor = RGBA8(255, 0, 0, normalizedTransparency);
|
||||||
|
bgcolor = RGBA8(0, 0, 0, normalizedTransparency);
|
||||||
|
sprintf(buf, "Error: %08lX", res);
|
||||||
|
pp2d_get_text_size(&w, &hres, size, size, buf);
|
||||||
|
}
|
||||||
|
else if (type == TYPE_INFO)
|
||||||
|
{
|
||||||
|
color = RGBA8(0, 0, 255, normalizedTransparency);
|
||||||
|
bordercolor = RGBA8(0, 255, 0, normalizedTransparency);
|
||||||
|
bgcolor = RGBA8(255, 255, 255, normalizedTransparency);
|
||||||
|
pp2d_get_text_size(&w, &hres, size, size, title.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
pp2d_draw_rectangle(x - 2, y - 2, width + 4, height + 4, RGBA8(0, 255, 0, normalizedTransparency));
|
const int wrapWidth = width - 20;
|
||||||
pp2d_draw_rectangle(x, y, width, height, RGBA8(255, 255, 255, normalizedTransparency));
|
const float spacing = (height - hres - hmessage) / 3;
|
||||||
pp2d_draw_text(x + (width - w) / 2, y + spacing, size, size, color, title.c_str());
|
|
||||||
|
pp2d_draw_rectangle(x - 2, y - 2, width + 4, height + 4, bordercolor);
|
||||||
|
pp2d_draw_rectangle(x, y, width, height, bgcolor);
|
||||||
|
pp2d_draw_text(x + (width - w) / 2, y + spacing, size, size, color, type == TYPE_INFO ? title.c_str() : buf);
|
||||||
pp2d_draw_text_wrap(x + 10, y + 2*spacing + hres, 0.46, 0.46, color, wrapWidth, message.c_str());
|
pp2d_draw_text_wrap(x + 10, y + 2*spacing + hres, 0.46, 0.46, color, wrapWidth, message.c_str());
|
||||||
|
|
||||||
ttl--;
|
ttl--;
|
||||||
|
|
|
@ -46,7 +46,7 @@ Result SPIWaitWriteEnd(CardType type)
|
||||||
cnt++;
|
cnt++;
|
||||||
res = SPIWriteRead(type, &cmd, 1, &statusReg, 1, 0, 0);
|
res = SPIWriteRead(type, &cmd, 1, &statusReg, 1, 0, 0);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
} while(statusReg & SPI_FLG_WIP && cnt < 1000);
|
} while (statusReg & SPI_FLG_WIP && cnt < 1000);
|
||||||
|
|
||||||
return cnt >= 1000 ? 1 : 0;
|
return cnt >= 1000 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue