mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-14 01:15:38 -04:00
Added carrier wake up in Xylos TX and cute icons
This commit is contained in:
parent
7a90eab407
commit
6a0816ba56
31 changed files with 636 additions and 285 deletions
|
@ -289,17 +289,18 @@ void ILI9341::render_box(const ui::Point p, const ui::Size s, const ui::Color* l
|
|||
io.lcd_write_pixels(line_buffer, s.w * s.h);
|
||||
}
|
||||
|
||||
void ILI9341::drawBMP(const ui::Point p, const uint8_t * bitmap) {
|
||||
void ILI9341::drawBMP(const ui::Point p, const uint8_t * bitmap, const bool transparency) {
|
||||
uint32_t pixel_data, pal_data;
|
||||
uint8_t pal, by, c, count;
|
||||
uint8_t pal, by, c, count, transp_idx = 0, color_r, color_g, color_b;
|
||||
ui::Color linebuffer[240];
|
||||
ui::Coord px = 0, py;
|
||||
ui::Color palette[16];
|
||||
uint32_t bmpwidth, bmpheight;
|
||||
|
||||
// RLE_4 BMP loader with hardcoded size and no delta :(
|
||||
// RLE_4 BMP loader with no delta :(
|
||||
|
||||
if (bitmap[0x1E] != 2) return; // Bad compression type
|
||||
|
||||
bmpwidth = static_cast<int32_t>(
|
||||
(bitmap[0x12]) |
|
||||
(bitmap[0x13] << 8) |
|
||||
|
@ -316,41 +317,88 @@ void ILI9341::drawBMP(const ui::Point p, const uint8_t * bitmap) {
|
|||
pixel_data = bitmap[0x0A];
|
||||
pal = 0;
|
||||
for (c = 0; c < (16*4); c+=4) {
|
||||
palette[pal++] = ui::Color(bitmap[c+2+pal_data], bitmap[c+1+pal_data], bitmap[c+pal_data]);
|
||||
color_r = bitmap[c+2+pal_data];
|
||||
color_g = bitmap[c+1+pal_data];
|
||||
color_b = bitmap[c+pal_data];
|
||||
palette[pal] = ui::Color(color_r, color_g, color_b);
|
||||
if ((color_r == 0xFF) && (color_g == 0x00) && (color_b == 0xFF)) transp_idx = pal;
|
||||
pal++;
|
||||
}
|
||||
|
||||
py = bmpheight + 16;
|
||||
do {
|
||||
by = bitmap[pixel_data++];
|
||||
if (by) {
|
||||
count = by;
|
||||
if (!transparency) {
|
||||
py = bmpheight + 16; // +1 ?
|
||||
do {
|
||||
by = bitmap[pixel_data++];
|
||||
for (c = 0; c < count; c+=2) {
|
||||
linebuffer[px++] = palette[by >> 4];
|
||||
if (px < bmpwidth) linebuffer[px++] = palette[by & 15];
|
||||
}
|
||||
if (pixel_data & 1) pixel_data++;
|
||||
} else {
|
||||
by = bitmap[pixel_data++];
|
||||
if (by == 0) {
|
||||
render_line({p.x, p.y + py}, bmpwidth, linebuffer);
|
||||
py--;
|
||||
px = 0;
|
||||
} else if (by == 1) {
|
||||
break;
|
||||
} else if (by == 2) {
|
||||
// Delta
|
||||
} else {
|
||||
if (by) {
|
||||
count = by;
|
||||
by = bitmap[pixel_data++];
|
||||
for (c = 0; c < count; c+=2) {
|
||||
by = bitmap[pixel_data++];
|
||||
linebuffer[px++] = palette[by >> 4];
|
||||
if (px < bmpwidth) linebuffer[px++] = palette[by & 15];
|
||||
}
|
||||
if (pixel_data & 1) pixel_data++;
|
||||
} else {
|
||||
by = bitmap[pixel_data++];
|
||||
if (by == 0) {
|
||||
render_line({p.x, p.y + py}, bmpwidth, linebuffer);
|
||||
py--;
|
||||
px = 0;
|
||||
} else if (by == 1) {
|
||||
break;
|
||||
} else if (by == 2) {
|
||||
// Delta
|
||||
} else {
|
||||
count = by;
|
||||
for (c = 0; c < count; c+=2) {
|
||||
by = bitmap[pixel_data++];
|
||||
linebuffer[px++] = palette[by >> 4];
|
||||
if (px < bmpwidth) linebuffer[px++] = palette[by & 15];
|
||||
}
|
||||
if (pixel_data & 1) pixel_data++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (1);
|
||||
} while (1);
|
||||
} else {
|
||||
py = bmpheight; // +1 ?
|
||||
do {
|
||||
by = bitmap[pixel_data++];
|
||||
if (by) {
|
||||
count = by;
|
||||
by = bitmap[pixel_data++];
|
||||
for (c = 0; c < count; c+=2) {
|
||||
if ((by >> 4) != transp_idx) draw_pixel({static_cast<ui::Coord>(p.x + px), static_cast<ui::Coord>(p.y + py)}, palette[by >> 4]);
|
||||
px++;
|
||||
if (px < bmpwidth) {
|
||||
if ((by & 15) != transp_idx) draw_pixel({static_cast<ui::Coord>(p.x + px), static_cast<ui::Coord>(p.y + py)}, palette[by & 15]);
|
||||
}
|
||||
px++;
|
||||
}
|
||||
if (pixel_data & 1) pixel_data++;
|
||||
} else {
|
||||
by = bitmap[pixel_data++];
|
||||
if (by == 0) {
|
||||
py--;
|
||||
px = 0;
|
||||
} else if (by == 1) {
|
||||
break;
|
||||
} else if (by == 2) {
|
||||
// Delta
|
||||
} else {
|
||||
count = by;
|
||||
for (c = 0; c < count; c+=2) {
|
||||
by = bitmap[pixel_data++];
|
||||
if ((by >> 4) != transp_idx) draw_pixel({static_cast<ui::Coord>(p.x + px), static_cast<ui::Coord>(p.y + py)}, palette[by >> 4]);
|
||||
px++;
|
||||
if (px < bmpwidth) {
|
||||
if ((by & 15) != transp_idx) draw_pixel({static_cast<ui::Coord>(p.x + px), static_cast<ui::Coord>(p.y + py)}, palette[by & 15]);
|
||||
}
|
||||
px++;
|
||||
}
|
||||
if (pixel_data & 1) pixel_data++;
|
||||
}
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
}
|
||||
|
||||
void ILI9341::draw_line(const ui::Point start, const ui::Point end, const ui::Color color) {
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
);
|
||||
|
||||
void draw_pixel(const ui::Point p, const ui::Color color);
|
||||
void drawBMP(const ui::Point p, const uint8_t * bitmap);
|
||||
void drawBMP(const ui::Point p, const uint8_t * bitmap, const bool transparency);
|
||||
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);
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
const char md5_baseband[16] = {0x95,0x5d,0xe3,0x7e,0xf1,0x75,0x8b,0x1a,0x27,0xea,0x09,0xb7,0xb9,0xdc,0x7e,0xe2,};
|
||||
const char md5_baseband_tx[16] = {0x72,0xf5,0x35,0x17,0x37,0x57,0xd7,0x28,0x5f,0xc5,0x8a,0xc0,0x0b,0x71,0xd4,0xd1,};
|
||||
const char md5_baseband[16] = {0xb8,0x9e,0x9b,0x08,0x44,0x34,0x04,0x20,0x0b,0xbc,0x60,0x7e,0x67,0x88,0x53,0xf7,};
|
||||
const char md5_baseband_tx[16] = {0xf2,0x82,0xb2,0x1e,0xc7,0xaa,0x15,0x73,0x02,0x74,0xbf,0x51,0xbe,0x6c,0xca,0xd0,};
|
||||
|
|
|
@ -715,6 +715,83 @@ bool ImageButton::on_touch(const TouchEvent event) {
|
|||
}
|
||||
}
|
||||
|
||||
/* ImageOptionsField *****************************************************/
|
||||
|
||||
ImageOptionsField::ImageOptionsField(
|
||||
Rect parent_rect,
|
||||
options_t options
|
||||
) : Widget { parent_rect },
|
||||
options { options }
|
||||
{
|
||||
set_focusable(true);
|
||||
}
|
||||
|
||||
size_t ImageOptionsField::selected_index() const {
|
||||
return selected_index_;
|
||||
}
|
||||
|
||||
size_t ImageOptionsField::selected_index_value() const {
|
||||
return options[selected_index_].second;
|
||||
}
|
||||
|
||||
void ImageOptionsField::set_selected_index(const size_t new_index) {
|
||||
if( new_index < options.size() ) {
|
||||
if( new_index != selected_index() ) {
|
||||
selected_index_ = new_index;
|
||||
if( on_change ) {
|
||||
on_change(selected_index(), options[selected_index()].second);
|
||||
}
|
||||
set_dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImageOptionsField::set_by_value(value_t v) {
|
||||
size_t new_index { 0 };
|
||||
for(const auto& option : options) {
|
||||
if( option.second == v ) {
|
||||
set_selected_index(new_index);
|
||||
break;
|
||||
}
|
||||
new_index++;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageOptionsField::set_options(options_t new_options) {
|
||||
options = new_options;
|
||||
set_by_value(0);
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void ImageOptionsField::paint(Painter& painter) {
|
||||
const auto paint_style = has_focus() ? style().invert() : style();
|
||||
|
||||
if( selected_index() < options.size() ) {
|
||||
const auto bmp_ptr = options[selected_index()].first;
|
||||
portapack::display.fill_rectangle({screen_rect().pos, {screen_rect().size.w + 4, screen_rect().size.h + 4}}, ui::Color::black());
|
||||
painter.draw_rectangle({screen_rect().pos, {screen_rect().size.w + 4, screen_rect().size.h + 4}}, paint_style.background);
|
||||
portapack::display.drawBMP({screen_pos().x + 2, screen_pos().y + 1}, bmp_ptr, true);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageOptionsField::on_focus() {
|
||||
if( on_show_options ) {
|
||||
on_show_options();
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageOptionsField::on_encoder(const EncoderEvent delta) {
|
||||
set_selected_index(selected_index() + delta);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImageOptionsField::on_touch(const TouchEvent event) {
|
||||
if( event.type == TouchEvent::Type::Start ) {
|
||||
focus();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* OptionsField **********************************************************/
|
||||
|
||||
OptionsField::OptionsField(
|
||||
|
|
|
@ -305,6 +305,37 @@ public:
|
|||
bool on_touch(const TouchEvent event) override;
|
||||
};
|
||||
|
||||
class ImageOptionsField : public Widget {
|
||||
public:
|
||||
using image_t = const unsigned char *;
|
||||
using value_t = int32_t;
|
||||
using option_t = std::pair<image_t, value_t>;
|
||||
using options_t = std::vector<option_t>;
|
||||
|
||||
std::function<void(size_t, value_t)> on_change;
|
||||
std::function<void(void)> on_show_options;
|
||||
|
||||
ImageOptionsField(Rect parent_rect, options_t options);
|
||||
|
||||
void set_options(options_t new_options);
|
||||
|
||||
size_t selected_index() const;
|
||||
size_t selected_index_value() const;
|
||||
void set_selected_index(const size_t new_index);
|
||||
|
||||
void set_by_value(value_t v);
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
void on_focus() override;
|
||||
bool on_encoder(const EncoderEvent delta) override;
|
||||
bool on_touch(const TouchEvent event) override;
|
||||
|
||||
private:
|
||||
options_t options;
|
||||
size_t selected_index_ { 0 };
|
||||
};
|
||||
|
||||
class OptionsField : public Widget {
|
||||
public:
|
||||
using name_t = std::string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue