mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-25 09:01:12 -05:00
XOR cursor support in Notepad (#1311)
* XOR cursor support in Notepad * XOR cursor support * XOR cursor support * Revert change * Use static buffer * Use static buffer * Clang
This commit is contained in:
parent
8c565bbf15
commit
b27c738b69
@ -72,6 +72,7 @@ void TextViewer::paint(Painter& painter) {
|
|||||||
paint_state_.first_line = first_line;
|
paint_state_.first_line = first_line;
|
||||||
paint_state_.first_col = first_col;
|
paint_state_.first_col = first_col;
|
||||||
paint_state_.redraw_text = true;
|
paint_state_.redraw_text = true;
|
||||||
|
paint_state_.line = UINT32_MAX; // forget old cursor position when overwritten
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paint_state_.redraw_text) {
|
if (paint_state_.redraw_text) {
|
||||||
@ -221,6 +222,10 @@ void TextViewer::paint_text(Painter& painter, uint32_t line, uint16_t col) {
|
|||||||
r.top() + (int)i * char_height,
|
r.top() + (int)i * char_height,
|
||||||
clear_width * char_width, char_height},
|
clear_width * char_width, char_height},
|
||||||
style().background);
|
style().background);
|
||||||
|
|
||||||
|
// if cursor line got overwritten, disable XOR of old cursor when displaying new cursor
|
||||||
|
if (i == paint_state_.line)
|
||||||
|
paint_state_.line = UINT32_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,21 +233,32 @@ void TextViewer::paint_cursor(Painter& painter) {
|
|||||||
if (!has_focus())
|
if (!has_focus())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto draw_cursor = [this, &painter](uint32_t line, uint16_t col, Color c) {
|
auto xor_cursor = [this, &painter](int32_t line, uint16_t col) {
|
||||||
auto r = screen_rect();
|
int cursor_width = char_width + 1;
|
||||||
line = line - paint_state_.first_line;
|
int x = (col - paint_state_.first_col) * char_width - 1;
|
||||||
col = col - paint_state_.first_col;
|
if (x < 0) { // cursor is one pixel narrower when in left column
|
||||||
|
cursor_width--;
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
int y = screen_rect().top() + (line - paint_state_.first_line) * char_height;
|
||||||
|
|
||||||
painter.draw_rectangle(
|
// Converting one row at a time to reduce buffer size
|
||||||
{(int)col * char_width - 1,
|
auto pbuf8 = cursor_.pixel_buffer8;
|
||||||
r.top() + (int)line * char_height,
|
auto pbuf = cursor_.pixel_buffer;
|
||||||
char_width + 1, char_height},
|
for (auto col = 0; col < char_height; col++) {
|
||||||
c);
|
// Annoyingly, read_pixels uses a 24-bit pixel format vs draw_pixels which uses 16-bit
|
||||||
|
portapack::display.read_pixels({x, y + col, cursor_width, 1}, pbuf8, cursor_width);
|
||||||
|
for (auto i = 0; i < cursor_width; i++)
|
||||||
|
pbuf[i] = Color(pbuf8[i].r, pbuf8[i].g, pbuf8[i].b).v ^ 0xFFFF;
|
||||||
|
portapack::display.draw_pixels({x, y + col, cursor_width, 1}, pbuf, cursor_width);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clear old cursor. CONSIDER: XOR cursor?
|
if (paint_state_.line != UINT32_MAX) // only XOR old cursor if it still appears on the screen
|
||||||
draw_cursor(paint_state_.line, paint_state_.col, style().background);
|
xor_cursor(paint_state_.line, paint_state_.col);
|
||||||
draw_cursor(cursor_.line, cursor_.col, style().foreground);
|
|
||||||
|
xor_cursor(cursor_.line, cursor_.col);
|
||||||
|
|
||||||
paint_state_.line = cursor_.line;
|
paint_state_.line = cursor_.line;
|
||||||
paint_state_.col = cursor_.col;
|
paint_state_.col = cursor_.col;
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,10 @@ class TextViewer : public Widget {
|
|||||||
uint32_t line{};
|
uint32_t line{};
|
||||||
uint16_t col{};
|
uint16_t col{};
|
||||||
ScrollDirection dir{ScrollDirection::Vertical};
|
ScrollDirection dir{ScrollDirection::Vertical};
|
||||||
|
|
||||||
|
// Pixel buffer used for cursor XOR'ing - Max cursor width = Max char width + 1
|
||||||
|
ColorRGB888 pixel_buffer8[ui::char_width + 1]{};
|
||||||
|
Color pixel_buffer[ui::char_width + 1]{};
|
||||||
} cursor_{};
|
} cursor_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -100,6 +100,9 @@ class ILI9341 {
|
|||||||
constexpr ui::Dim height() const { return 320; }
|
constexpr ui::Dim height() const { return 320; }
|
||||||
constexpr ui::Rect screen_rect() const { return {0, 0, width(), height()}; }
|
constexpr ui::Rect screen_rect() const { return {0, 0, width(), height()}; }
|
||||||
|
|
||||||
|
void draw_pixels(const ui::Rect r, const ui::Color* const colors, const size_t count);
|
||||||
|
void read_pixels(const ui::Rect r, ui::ColorRGB888* const colors, const size_t count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct scroll_t {
|
struct scroll_t {
|
||||||
ui::Coord top_area;
|
ui::Coord top_area;
|
||||||
@ -109,9 +112,6 @@ class ILI9341 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
scroll_t scroll_state;
|
scroll_t scroll_state;
|
||||||
|
|
||||||
void draw_pixels(const ui::Rect r, const ui::Color* const colors, const size_t count);
|
|
||||||
void read_pixels(const ui::Rect r, ui::ColorRGB888* const colors, const size_t count);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace lcd */
|
} /* namespace lcd */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user