From 6091a402784638c64cc0078f895a221f79c12772 Mon Sep 17 00:00:00 2001 From: /jedi/ Date: Sat, 1 Dec 2018 20:26:05 +0100 Subject: [PATCH] add inverted text --- .gitignore | 6 ----- inc/gfx/buffer.h | 5 ++++ inc/gfx/canvas.h | 6 ++--- inc/gfx/font.h | 6 ++--- inc/hal/hal.h | 4 ++-- src/example.cpp | 23 +++++++++++++----- src/gfx/canvas.cpp | 12 +++++----- src/gfx/font.cpp | 12 +++++----- src/gfx/screen.cpp | 13 ++++------ src/hal/avr.cpp | 15 ++++++------ src/hal/linux.cpp | 20 +++++++++++----- src/main.cpp | 59 ++++++++++++++++------------------------------ 12 files changed, 88 insertions(+), 93 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 6ac506e..0000000 --- a/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -build/* -lib/* -deps/* -.idea/* -cmake-build-debug/* -CMakeLists.txt diff --git a/inc/gfx/buffer.h b/inc/gfx/buffer.h index 364508f..19263aa 100644 --- a/inc/gfx/buffer.h +++ b/inc/gfx/buffer.h @@ -29,6 +29,11 @@ public: return ptr_[i*N/block_] & ((1<= size_) return 0; + return ptr_[i*N/block_]; + } + void set(int i, int v) { if (i < size_) { ptr_[i*N/block_] &= ~(((1<title_); + node *ptr = getChild(); + while (ptr) { + if (ptr == getCursor()) { + int len = strlen(ptr->title_); + for(int i = 0; i < 6*len; i++){ + for(int j = 0; j < 7; j++) { + c.draw(2+i, 1+7*r+j); + } + } + c.print(3, 7 * r + 2, ptr->title_, true); + } else { + c.print(3, 7 * r + 2, ptr->title_); + } ptr = ptr->getNext(); r++; } diff --git a/src/gfx/canvas.cpp b/src/gfx/canvas.cpp index 3ff9fcc..be40489 100644 --- a/src/gfx/canvas.cpp +++ b/src/gfx/canvas.cpp @@ -14,17 +14,17 @@ void canvas::clear() { buffer_.set(x * height_ + y, false); } -void canvas::draw(int x, int y) { +void canvas::draw(int x, int y, bool inv) { if (y < height_ && x < width_) - buffer_.set(x * height_ + y, true); + buffer_.set(x * height_ + y, !inv); } -void canvas::print(int x, int y, const char *str, font& f) { - f.print(x, y, str, *this); +void canvas::print(int x, int y, const char *str, bool inv, font& f) { + f.print(x, y, str, *this, inv); } -void canvas::print(int x, int y, char *str, font& f) { - f.print(x, y, str, *this); +void canvas::print(int x, int y, char *str, bool inv, font& f) { + f.print(x, y, str, *this, inv); } int canvas::getWidth(){ diff --git a/src/gfx/font.cpp b/src/gfx/font.cpp index 5049fd9..1575377 100644 --- a/src/gfx/font.cpp +++ b/src/gfx/font.cpp @@ -10,22 +10,22 @@ font::font(raw_font& raw ):raw_data_(raw){ } -void font::print(int x, int y, char l, canvas& c) { +void font::print(int x, int y, char l, canvas& c, bool inv) { int j = (l - ' ') % 32; for (int x_ = 0; x_ < 4; x_++) for (int y_ = 0; y_ < 5; y_++) if (raw_data_[j][x_ + 4 * y_]) - c.draw(x + x_, y + y_); + c.draw(x + x_, y + y_, inv); } -void font::print(int x, int y, char* str, canvas& c) { +void font::print(int x, int y, char* str, canvas& c, bool inv) { for (int i = 0; str[i]; i++) { - print(x + i * 5,y,str[i],c); + print(x + i * 5,y,str[i],c, inv); } } -void font::print(int x, int y, const char* str, canvas& c) { +void font::print(int x, int y, const char* str, canvas& c, bool inv) { for (int i = 0; str[i]; i++) { - print(x + i * 5,y,str[i],c); + print(x + i * 5,y,str[i],c, inv); } } \ No newline at end of file diff --git a/src/gfx/screen.cpp b/src/gfx/screen.cpp index 2f491be..aa07481 100644 --- a/src/gfx/screen.cpp +++ b/src/gfx/screen.cpp @@ -8,17 +8,13 @@ screen::screen(int w, int h) : width_(w), height_(h) { hal_init_screen(w,h); } -void screen::draw(int x, int y) { - hal_draw(x, y); -} - void screen::draw(int x, int y, canvas &c) { - for (int x_ = 0; x_ < width_; x_++) - for (int y_ = 0; y_ < height_; y_++) - if (c.buffer_.get(x_ * height_ + y_)) - hal_draw(x + x_, y + y_); + for (int x_ = 0; x_ < c.getWidth(); x_++) + for (int y_ = 0; y_ < c.getHeight(); y_+= 8 *sizeof(int)) + hal_draw(x + x_, y + y_,c.buffer_.getBlock(x_ * c.getHeight() + y_)); } +/* void screen::print(int x, int y, const char *str, font& f) { //f.print(x, y, str); } @@ -26,6 +22,7 @@ void screen::print(int x, int y, const char *str, font& f) { void screen::print(int x, int y, char *str, font& f) { //f.print(x, y, str); } + */ int screen::getWidth(){ return width_; diff --git a/src/hal/avr.cpp b/src/hal/avr.cpp index 461f253..9e616fe 100644 --- a/src/hal/avr.cpp +++ b/src/hal/avr.cpp @@ -3,24 +3,25 @@ // #include "ssd1306.h" -#include "nano_gfx.h" #include "buttons.h" #include #include #include -uint8_t canvasData[128 * (32 / 8)]; -NanoCanvas canvas(128, 32, canvasData); - void hal_init_screen(int w, int h) { ssd1306_128x32_i2c_init(); + ssd1306_fillScreen( 0x00 ); DDRD = 0; PORTD |= (1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5); } -void hal_draw(int x, int y){ - canvas.putPixel(x, y); +void hal_draw(int x, int y, int b){ + ssd1306_putPixels(x, y, b&0xFF); + ssd1306_putPixels(x, y+8, b>>8); +} + +void hal_clear(){ } @@ -36,9 +37,7 @@ void hal_poll_input(bool *ptr) { void hal_render() { while (true) { - ssd1306_fillScreen( 0x00 ); render(); - canvas.blt(0, 0); } } diff --git a/src/hal/linux.cpp b/src/hal/linux.cpp index 1bcd475..d94b5ae 100644 --- a/src/hal/linux.cpp +++ b/src/hal/linux.cpp @@ -35,8 +35,20 @@ void hal_init_screen(int width, int height){ } } -void hal_draw(int x, int y){ - SDL_RenderDrawPoint(renderer, x, y); +void hal_draw(int x, int y, int b) { + for (int i = 0; i < 8 *sizeof(int);i++) + if (b & (1 << i)) { + SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255); + SDL_RenderDrawPoint(renderer, x, y + i); + }else{ + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); + SDL_RenderDrawPoint(renderer, x, y + i); + } +} + +void hal_clear(){ + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); + SDL_RenderClear(renderer); } @@ -46,10 +58,6 @@ void hal_render() { while (!quit) { - - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); - SDL_RenderClear(renderer); - SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255); render(); SDL_RenderPresent(renderer); } diff --git a/src/main.cpp b/src/main.cpp index a415d41..05e106b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,47 +29,27 @@ menu* root; int main() { - root = new menu("", - new menu("foo", - new menu("baz", - new fooValue("I", 5), - new fooValue("II", 5), - new fooValue("III", 5), - new fooValue("IIII", 5) + root = new menu("", + new menu("baz", + new menu("x", + new fooValue("x x", 5), + new blubValue("xxx", 5) ), - new menu("peng", - new fooValue("o", 5), - new fooValue("oo", 5), - new fooValue("o o", 5) - ), - new menu("x", - new fooValue("x x", 5), - new fooValue("xxx", 5) - ), - new menu("y", - new fooValue("y y", 5), - new fooValue("yyy", 5) - ) - ), - new menu("a", - new blubValue("a a", 5), - new blubValue("aa", 5), - new blubValue("aaa", 5) - ), - new menu("b", - new blubValue("b b", 5), - new blubValue("bb", 5), - new blubValue("bbb", 5) - ), - new menu("c", - new blubValue("c c", 5), - new blubValue("cc", 5), - new blubValue("ccc", 5) - ) - ); + new fooValue("I", 5), + new fooValue("II", 5), + new blubValue("III", 5), + new blubValue("IIII", 5) + ), + new menu("peng", + new fooValue("o", 5), + new fooValue("oo", 5), + new fooValue("o o", 5) + ) + ); - hal_render(); - return 0; + + hal_render(); + return 0; } void render(){ @@ -92,6 +72,7 @@ void buttons::onPush(int id, bool state) { } break; case I_UP: + // TODO implement break; case I_RIGHT: c = l.cursor;