mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-06-21 05:14:26 -04:00
Move LCD display object to portapack namespace.
Globals are bad... Except in embedded development!
This commit is contained in:
parent
fecbb7205e
commit
65d5f68bfb
9 changed files with 26 additions and 29 deletions
|
@ -486,7 +486,7 @@ int main(void) {
|
||||||
|
|
||||||
portapack::io.init();
|
portapack::io.init();
|
||||||
ui::Context context;
|
ui::Context context;
|
||||||
context.display.init();
|
portapack::display.init();
|
||||||
|
|
||||||
sdcStart(&SDCD1, nullptr);
|
sdcStart(&SDCD1, nullptr);
|
||||||
|
|
||||||
|
@ -503,7 +503,7 @@ int main(void) {
|
||||||
context,
|
context,
|
||||||
{ 0, 0, 240, 320 }
|
{ 0, 0, 240, 320 }
|
||||||
};
|
};
|
||||||
ui::Painter painter { context.display };
|
ui::Painter painter;
|
||||||
EventDispatcher event_dispatcher { &system_view, painter, context };
|
EventDispatcher event_dispatcher { &system_view, painter, context };
|
||||||
|
|
||||||
context.message_map[Message::ID::FSKPacket] = [](const Message* const p) {
|
context.message_map[Message::ID::FSKPacket] = [](const Message* const p) {
|
||||||
|
|
|
@ -48,6 +48,8 @@ portapack::IO io {
|
||||||
portapack::gpio_unused,
|
portapack::gpio_unused,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lcd::ILI9341 display;
|
||||||
|
|
||||||
I2C i2c0(&I2CD0);
|
I2C i2c0(&I2CD0);
|
||||||
SPI ssp0(&SPID1);
|
SPI ssp0(&SPID1);
|
||||||
SPI ssp1(&SPID2);
|
SPI ssp1(&SPID2);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "spi_pp.hpp"
|
#include "spi_pp.hpp"
|
||||||
#include "wm8731.hpp"
|
#include "wm8731.hpp"
|
||||||
|
#include "lcd_ili9341.hpp"
|
||||||
|
|
||||||
#include "radio.hpp"
|
#include "radio.hpp"
|
||||||
|
|
||||||
|
@ -32,6 +33,8 @@ namespace portapack {
|
||||||
|
|
||||||
extern portapack::IO io;
|
extern portapack::IO io;
|
||||||
|
|
||||||
|
extern lcd::ILI9341 display;
|
||||||
|
|
||||||
extern SPI ssp0;
|
extern SPI ssp0;
|
||||||
extern SPI ssp1;
|
extern SPI ssp1;
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@
|
||||||
|
|
||||||
#include "ui_console.hpp"
|
#include "ui_console.hpp"
|
||||||
|
|
||||||
|
#include "portapack.hpp"
|
||||||
|
using namespace portapack;
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
void Console::write(const std::string message) {
|
void Console::write(const std::string message) {
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
#include "ui_painter.hpp"
|
#include "ui_painter.hpp"
|
||||||
#include "ui_widget.hpp"
|
#include "ui_widget.hpp"
|
||||||
|
|
||||||
#include "lcd_ili9341.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
@ -35,10 +33,8 @@ namespace ui {
|
||||||
class Console : public Widget {
|
class Console : public Widget {
|
||||||
public:
|
public:
|
||||||
constexpr Console(
|
constexpr Console(
|
||||||
const Rect parent_rect,
|
const Rect parent_rect
|
||||||
lcd::ILI9341& display
|
) : Widget { parent_rect }
|
||||||
) : Widget { parent_rect },
|
|
||||||
display(display)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +48,6 @@ private:
|
||||||
static constexpr Color foreground { Color::white() };
|
static constexpr Color foreground { Color::white() };
|
||||||
|
|
||||||
Point pos { 0, 0 };
|
Point pos { 0, 0 };
|
||||||
lcd::ILI9341& display;
|
|
||||||
|
|
||||||
void crlf();
|
void crlf();
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
#include "ui_widget.hpp"
|
#include "ui_widget.hpp"
|
||||||
#include "spectrum_color_lut.hpp"
|
#include "spectrum_color_lut.hpp"
|
||||||
|
|
||||||
#include "lcd_ili9341.hpp"
|
#include "portapack.hpp"
|
||||||
|
using namespace portapack;
|
||||||
|
|
||||||
#include "message.hpp"
|
#include "message.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
@ -180,14 +182,14 @@ class WaterfallView : public Widget {
|
||||||
public:
|
public:
|
||||||
void on_show() override {
|
void on_show() override {
|
||||||
const auto screen_r = screen_rect();
|
const auto screen_r = screen_rect();
|
||||||
context().display.scroll_set_area(screen_r.top(), screen_r.bottom());
|
display.scroll_set_area(screen_r.top(), screen_r.bottom());
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_hide() override {
|
void on_hide() override {
|
||||||
/* TODO: Clear region to eliminate brief flash of content at un-shifted
|
/* TODO: Clear region to eliminate brief flash of content at un-shifted
|
||||||
* position?
|
* position?
|
||||||
*/
|
*/
|
||||||
context().display.scroll_disable();
|
display.scroll_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void paint(Painter& painter) override {
|
void paint(Painter& painter) override {
|
||||||
|
@ -212,7 +214,6 @@ public:
|
||||||
pixel_row[i] = pixel_color;
|
pixel_row[i] = pixel_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& display = context().display;
|
|
||||||
const auto draw_y = display.scroll(1);
|
const auto draw_y = display.scroll(1);
|
||||||
|
|
||||||
display.draw_pixels(
|
display.draw_pixels(
|
||||||
|
|
|
@ -21,6 +21,9 @@
|
||||||
|
|
||||||
#include "ui_painter.hpp"
|
#include "ui_painter.hpp"
|
||||||
|
|
||||||
|
#include "portapack.hpp"
|
||||||
|
using namespace portapack;
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
Style Style::invert() const {
|
Style Style::invert() const {
|
||||||
|
@ -33,7 +36,7 @@ Style Style::invert() const {
|
||||||
|
|
||||||
size_t Painter::draw_char(const Point p, const Style& style, const char c) {
|
size_t Painter::draw_char(const Point p, const Style& style, const char c) {
|
||||||
const auto glyph = style.font.glyph(c);
|
const auto glyph = style.font.glyph(c);
|
||||||
display_.draw_glyph(p, glyph, style.foreground, style.background);
|
display.draw_glyph(p, glyph, style.foreground, style.background);
|
||||||
return glyph.advance().x;
|
return glyph.advance().x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +44,7 @@ size_t Painter::draw_string(Point p, const Style& style, const std::string text)
|
||||||
size_t width = 0;
|
size_t width = 0;
|
||||||
for(const auto c : text) {
|
for(const auto c : text) {
|
||||||
const auto glyph = style.font.glyph(c);
|
const auto glyph = style.font.glyph(c);
|
||||||
display_.draw_glyph(p, glyph, style.foreground, style.background);
|
display.draw_glyph(p, glyph, style.foreground, style.background);
|
||||||
const auto advance = glyph.advance();
|
const auto advance = glyph.advance();
|
||||||
p += advance;
|
p += advance;
|
||||||
width += advance.x;
|
width += advance.x;
|
||||||
|
@ -50,11 +53,11 @@ size_t Painter::draw_string(Point p, const Style& style, const std::string text)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::draw_hline(Point p, size_t width, const Color c) {
|
void Painter::draw_hline(Point p, size_t width, const Color c) {
|
||||||
display_.fill_rectangle({ p, { static_cast<Dim>(width), 1 } }, c);
|
display.fill_rectangle({ p, { static_cast<Dim>(width), 1 } }, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::draw_vline(Point p, size_t height, const Color c) {
|
void Painter::draw_vline(Point p, size_t height, const Color c) {
|
||||||
display_.fill_rectangle({ p, { 1, static_cast<Dim>(height) } }, c);
|
display.fill_rectangle({ p, { 1, static_cast<Dim>(height) } }, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::draw_rectangle(const Rect r, const Color c) {
|
void Painter::draw_rectangle(const Rect r, const Color c) {
|
||||||
|
@ -65,7 +68,7 @@ void Painter::draw_rectangle(const Rect r, const Color c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::fill_rectangle(const Rect r, const Color c) {
|
void Painter::fill_rectangle(const Rect r, const Color c) {
|
||||||
display_.fill_rectangle(r, c);
|
display.fill_rectangle(r, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace ui */
|
} /* namespace ui */
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
#include "ui.hpp"
|
#include "ui.hpp"
|
||||||
#include "ui_text.hpp"
|
#include "ui_text.hpp"
|
||||||
|
|
||||||
#include "lcd_ili9341.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
@ -41,11 +39,7 @@ struct Style {
|
||||||
|
|
||||||
class Painter {
|
class Painter {
|
||||||
public:
|
public:
|
||||||
Painter(
|
Painter() { };
|
||||||
lcd::ILI9341& display
|
|
||||||
) : display_(display)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Painter(const Painter&) = delete;
|
Painter(const Painter&) = delete;
|
||||||
Painter(Painter&&) = delete;
|
Painter(Painter&&) = delete;
|
||||||
|
@ -58,8 +52,6 @@ public:
|
||||||
void fill_rectangle(const Rect r, const Color c);
|
void fill_rectangle(const Rect r, const Color c);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
lcd::ILI9341& display_;
|
|
||||||
|
|
||||||
void draw_hline(Point p, size_t width, const Color c);
|
void draw_hline(Point p, size_t width, const Color c);
|
||||||
void draw_vline(Point p, size_t height, const Color c);
|
void draw_vline(Point p, size_t height, const Color c);
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
|
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
#include "lcd_ili9341.hpp"
|
|
||||||
#include "message.hpp"
|
#include "message.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -48,7 +47,6 @@ std::string to_string_hex(const uint32_t n, const int32_t l = 0);
|
||||||
|
|
||||||
struct Context {
|
struct Context {
|
||||||
FocusManager focus_manager;
|
FocusManager focus_manager;
|
||||||
lcd::ILI9341 display;
|
|
||||||
MessageHandlerMap message_map;
|
MessageHandlerMap message_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue