mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-06 21:54:27 -04:00
Support for viewing BMP files in File Manager and setting as Splash screen (#1242)
* Use filesystem::path type vs string for BMP file name * Use filesystem::path type vs string for BMP files * Use a global const file path string for "/splash.bmp" * Support for viewing BMP files and setting as Splash screen * Support for viewing BMP files and setting as Splash screen * Support for viewing BMP files and setting as Splash screen * Update ui_ss_viewer.cpp * Update ui_ss_viewer.hpp
This commit is contained in:
parent
8530fa8194
commit
fcb681f4ae
6 changed files with 67 additions and 11 deletions
|
@ -26,6 +26,8 @@ namespace fs = std::filesystem;
|
|||
|
||||
namespace ui {
|
||||
|
||||
const std::filesystem::path splash_dot_bmp{u"/splash.bmp"};
|
||||
|
||||
ScreenshotViewer::ScreenshotViewer(
|
||||
NavigationView& nav,
|
||||
const std::filesystem::path& path)
|
||||
|
@ -40,11 +42,9 @@ bool ScreenshotViewer::on_key(KeyEvent) {
|
|||
}
|
||||
|
||||
void ScreenshotViewer::paint(Painter& painter) {
|
||||
constexpr size_t pixel_width = 240;
|
||||
constexpr size_t pixel_height = 320;
|
||||
File file{};
|
||||
|
||||
painter.fill_rectangle({0, 0, pixel_width, pixel_height}, Color::black());
|
||||
painter.fill_rectangle({0, 0, screen_width, screen_height}, Color::black());
|
||||
|
||||
auto show_invalid = [&]() {
|
||||
painter.draw_string({10, 160}, Styles::white, "Not a valid screenshot.");
|
||||
|
@ -65,19 +65,19 @@ void ScreenshotViewer::paint(Painter& painter) {
|
|||
constexpr size_t read_chunk = 80; // NB: must be a factor of pixel_width.
|
||||
constexpr size_t buffer_size = sizeof(ColorRGB888) * read_chunk;
|
||||
uint8_t buffer[buffer_size];
|
||||
std::array<Color, pixel_width> pixel_data;
|
||||
std::array<Color, screen_width> pixel_data;
|
||||
|
||||
// Seek past all the headers.
|
||||
file.seek(43);
|
||||
|
||||
for (auto line = 0u; line < pixel_height; ++line) {
|
||||
for (auto line = 0u; line < screen_height; ++line) {
|
||||
// Seek past the per-line header.
|
||||
file.seek(file.tell() + 6);
|
||||
|
||||
// Per comment in PNGWriter, read in chunks of 80.
|
||||
// NB: Reading in one large chunk caused corruption so there's
|
||||
// likely a bug lurking in the SD Card/FatFs layer.
|
||||
for (auto offset = 0u; offset < pixel_width; offset += read_chunk) {
|
||||
for (auto offset = 0u; offset < screen_width; offset += read_chunk) {
|
||||
auto read = file.read(buffer, buffer_size);
|
||||
|
||||
if (!read || *read != buffer_size) {
|
||||
|
@ -92,8 +92,42 @@ void ScreenshotViewer::paint(Painter& painter) {
|
|||
}
|
||||
}
|
||||
|
||||
display.draw_pixels({0, (int)line, pixel_width, 1}, pixel_data);
|
||||
display.draw_pixels({0, (int)line, screen_width, 1}, pixel_data);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
SplashViewer::SplashViewer(
|
||||
NavigationView& nav,
|
||||
const std::filesystem::path& path)
|
||||
: nav_{nav},
|
||||
path_{path} {
|
||||
valid_image = false;
|
||||
set_focusable(true);
|
||||
}
|
||||
|
||||
bool SplashViewer::on_key(const KeyEvent key) {
|
||||
if (valid_image && key == KeyEvent::Right) {
|
||||
delete_file(splash_dot_bmp);
|
||||
copy_file(path_, splash_dot_bmp);
|
||||
}
|
||||
|
||||
nav_.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
void SplashViewer::paint(Painter& painter) {
|
||||
painter.fill_rectangle({0, 0, screen_width, screen_height}, Color::black());
|
||||
|
||||
if (!portapack::display.drawBMP2({0, 0}, path_)) {
|
||||
painter.draw_string({10, 160}, Styles::white, "Not a valid splash image.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Show option to set splash screen if it's not already the splash screen
|
||||
if (!path_iequal(path_, splash_dot_bmp)) {
|
||||
painter.draw_string({0, 0}, Styles::white, "*RIGHT BUTTON UPDATES SPLASH*");
|
||||
valid_image = true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue