Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splash fix and draw bmp fuc logic wrong #2376

Merged
merged 10 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion firmware/application/apps/ui_sigfrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ SIGFRXView::~SIGFRXView() {
void SIGFRXView::paint(Painter& painter) {
uint8_t i, xp;

// portapack::display.drawBMP({0, 302-160}, fox_bmp);
// portapack::display.draw_bmp_from_bmp_hex_arr({0, 302-160}, fox_bmp);
portapack::display.fill_rectangle({0, 16, 240, 160 - 16}, Theme::getInstance()->bg_darkest->foreground);
for (i = 0; i < 6; i++) {
xp = sigfrx_marks[i * 3];
Expand Down
2 changes: 1 addition & 1 deletion firmware/application/apps/ui_ss_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool SplashViewer::on_key(const KeyEvent key) {
void SplashViewer::paint(Painter& painter) {
painter.fill_rectangle({0, 0, screen_width, screen_height}, Color::black());

if (!portapack::display.drawBMP2({0, 0}, path_)) {
if (!portapack::display.draw_bmp_from_sdcard_file({0, 0}, path_)) {
painter.draw_string({10, 160}, *Theme::getInstance()->bg_darkest, "Not a valid splash image.");
return;
}
Expand Down
20 changes: 11 additions & 9 deletions firmware/application/ui_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ SystemView::SystemView(
navigation_view.push<SystemMenuView>();

if (pmem::config_splash()) {
navigation_view.push<BMPView>();
navigation_view.push<SplashScreenView>();
}
status_view.set_back_enabled(false);
status_view.set_title_image_enabled(true);
Expand Down Expand Up @@ -970,11 +970,11 @@ void SystemView::set_app_fullscreen(bool fullscreen) {

/* ***********************************************************************/

void BMPView::focus() {
void SplashScreenView::focus() {
button_done.focus();
}

BMPView::BMPView(NavigationView& nav)
SplashScreenView::SplashScreenView(NavigationView& nav)
: nav_(nav) {
add_children({&button_done});

Expand All @@ -983,12 +983,14 @@ BMPView::BMPView(NavigationView& nav)
};
}

void BMPView::paint(Painter&) {
if (!portapack::display.drawBMP2({0, 0}, splash_dot_bmp))
portapack::display.drawBMP({0, 16}, splash_bmp, (const uint8_t[]){0x29, 0x18, 0x16});
void SplashScreenView::paint(Painter&) {
if (!portapack::display.draw_bmp_from_sdcard_file({0, 0}, splash_dot_bmp))
// ^ try draw bmp file from sdcard at (0,0), and the (0,0) already bypassed the status bar, so actual pos is (0, STATUS_BAR_HEIGHT)
portapack::display.draw_bmp_from_bmp_hex_arr({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, (const uint8_t[]){0x29, 0x18, 0x16});
// ^ draw BMP HEX arr in firmware, note that the BMP HEX arr only cover the image part (instead of fill the screen with background, this position is located it in the center)
}

bool BMPView::on_touch(const TouchEvent event) {
bool SplashScreenView::on_touch(const TouchEvent event) {
/* the event thing were resolved by HTotoo, talked here https://discord.com/channels/719669764804444213/956561375155589192/1287756910950486027
* the touch screen policy can be better, talked here https://discord.com/channels/719669764804444213/956561375155589192/1198926225897443328
* this workaround discussed here: https://discord.com/channels/719669764804444213/1170738202924044338/1295630640158478418
Expand All @@ -1010,7 +1012,7 @@ bool BMPView::on_touch(const TouchEvent event) {
return false;
}

void BMPView::handle_pop() {
void SplashScreenView::handle_pop() {
if (nav_.is_valid()) {
nav_.pop();
}
Expand Down Expand Up @@ -1079,7 +1081,7 @@ ModalMessageView::ModalMessageView(
}

void ModalMessageView::paint(Painter& painter) {
if (!compact) portapack::display.drawBMP({100, 48}, modal_warning_bmp, (const uint8_t[]){0, 0, 0});
if (!compact) portapack::display.draw_bmp_from_bmp_hex_arr({100, 48}, modal_warning_bmp, (const uint8_t[]){0, 0, 0});

// Break lines.
auto lines = split_string(message_, '\n');
Expand Down
4 changes: 2 additions & 2 deletions firmware/application/ui_navigation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ class InformationView : public View {
{86, 0, 19 * 8, 16}};
};

class BMPView : public View {
class SplashScreenView : public View {
public:
BMPView(NavigationView& nav);
SplashScreenView(NavigationView& nav);
void paint(Painter&) override;
void focus() override;

Expand Down
16 changes: 9 additions & 7 deletions firmware/common/lcd_ili9341.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,19 @@ void ILI9341::render_box(const ui::Point p, const ui::Size s, const ui::Color* l

// RLE_4 BMP loader (delta not implemented)
/* draw transparent, pass transparent color as arg, usage inline anonymous obj
* portapack::display.drawBMP({100, 100}, foo_bmp, (const uint8_t[]){41, 24, 22}); // dec, out of {255, 255, 255}
* portapack::display.drawBMP({100, 100}, foo_bmp, (const uint8_t[]){0x29, 0x18, 0x16}); //hex out of {0xFF, 0xFF, 0xFF}
* portapack::display.draw_bmp_from_bmp_hex_arr({100, 100}, foo_bmp, (const uint8_t[]){41, 24, 22}); // dec, out of {255, 255, 255}
* portapack::display.draw_bmp_from_bmp_hex_arr({100, 100}, foo_bmp, (const uint8_t[]){0x29, 0x18, 0x16}); //hex out of {0xFF, 0xFF, 0xFF}
*
* draw transparent, pass transparent color as arg, usage pass uint8_t[] obj
* const uint8_t c[] = {41, 24, 22}; or const uint8_t c[3] = {0x29, 0x18, 0x16};
* portapack::display.drawBMP({100, 100}, foo_bmp, c);
* portapack::display.draw_bmp_from_bmp_hex_arr({100, 100}, foo_bmp, c);
*
* don't draw transparent, pass nullptr as arg, usage
* portapack::display.drawBMP({100, 100}, foo_bmp, nullptr);
* portapack::display.draw_bmp_from_bmp_hex_arr({100, 100}, foo_bmp, nullptr);
*
* if your image use RLE compress as transparency methods, pass any valid color as arg, it doesn't matter (like the modal bmp. TODO: write RLE transparency generator)
* */
void ILI9341::drawBMP(const ui::Point p, const uint8_t* bitmap, const uint8_t* transparency_color) {
void ILI9341::draw_bmp_from_bmp_hex_arr(const ui::Point p, const uint8_t* bitmap, const uint8_t* transparency_color) {
const bmp_header_t* bmp_header = (const bmp_header_t*)bitmap;
uint32_t data_idx;
uint8_t by, c, count, transp_idx = 0;
Expand Down Expand Up @@ -463,7 +463,7 @@ void ILI9341::drawBMP(const ui::Point p, const uint8_t* bitmap, const uint8_t* t
* 24bpp RGB
* 32bpp ARGB
*/
bool ILI9341::drawBMP2(const ui::Point p, const std::filesystem::path& file) {
bool ILI9341::draw_bmp_from_sdcard_file(const ui::Point p, const std::filesystem::path& file) {
File bmpimage;
size_t file_pos = 0;
uint16_t pointer = 0;
Expand Down Expand Up @@ -512,7 +512,9 @@ bool ILI9341::drawBMP2(const ui::Point p, const std::filesystem::path& file) {

file_pos = bmp_header.image_data;

py = height + 16;
py = height + 16 - 1;
/* ^ this is for to "start" AKA "image end" draw at the 17th line,
* because the render_line logic below is start with p.y() + py until "end" AKA "image start"*/

while (1) {
while (px < width) {
Expand Down
4 changes: 2 additions & 2 deletions firmware/common/lcd_ili9341.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class ILI9341 {
const ui::Color background);

void draw_pixel(const ui::Point p, const ui::Color color);
void drawBMP(const ui::Point p, const uint8_t* bitmap, const uint8_t* transparency_color);
bool drawBMP2(const ui::Point p, const std::filesystem::path& file);
void draw_bmp_from_bmp_hex_arr(const ui::Point p, const uint8_t* bitmap, const uint8_t* transparency_color);
bool draw_bmp_from_sdcard_file(const ui::Point p, const std::filesystem::path& file);
void render_line(const ui::Point p, const uint8_t count, const ui::Color* line_buffer);
void render_box(const ui::Point p, const ui::Size s, const ui::Color* line_buffer);

Expand Down
Loading