add inverted text

This commit is contained in:
j3d1 2018-12-01 20:26:05 +01:00
parent 806fc7c3e5
commit 6091a40278
12 changed files with 88 additions and 93 deletions

6
.gitignore vendored
View file

@ -1,6 +0,0 @@
build/*
lib/*
deps/*
.idea/*
cmake-build-debug/*
CMakeLists.txt

View file

@ -29,6 +29,11 @@ public:
return ptr_[i*N/block_] & ((1<<N)-1) << (i*N%block_); return ptr_[i*N/block_] & ((1<<N)-1) << (i*N%block_);
} }
int getBlock(int i) {
if (i >= size_) return 0;
return ptr_[i*N/block_];
}
void set(int i, int v) { void set(int i, int v) {
if (i < size_) { if (i < size_) {
ptr_[i*N/block_] &= ~(((1<<N)-1) << (i*N%block_)); ptr_[i*N/block_] &= ~(((1<<N)-1) << (i*N%block_));

View file

@ -25,11 +25,11 @@ public:
void clear(); void clear();
void draw(int x, int y); void draw(int x, int y, bool inv = false);
void print(int x, int y, const char *str, font & = basic_5x4); void print(int x, int y, const char *str, bool inv = 0, font & = basic_5x4);
void print(int x, int y, char *str, font & = basic_5x4); void print(int x, int y, char *str, bool inv = 0, font & = basic_5x4);
int getWidth(); int getWidth();

View file

@ -14,9 +14,9 @@ private:
raw_font& raw_data_; raw_font& raw_data_;
public: public:
font(raw_font&); font(raw_font&);
void print(int x, int y, char c, canvas&); void print(int x, int y, char c, canvas&, bool inv = 0);
void print(int x, int y, char* str, canvas&); void print(int x, int y, char* str, canvas&, bool inv = 0);
void print(int x, int y, const char* str, canvas&); void print(int x, int y, const char* str, canvas&, bool inv = 0);
}; };
#endif //MGL_DMXMENU_FONT_H #endif //MGL_DMXMENU_FONT_H

View file

@ -5,9 +5,9 @@
void debug(const char* str); void debug(const char* str);
void hal_init_screen(int w, int h); void hal_init_screen(int w, int h);
void hal_poll_input(bool *ptr); void hal_poll_input(bool *ptr);
void hal_draw(int x, int y); void hal_clear();
void hal_draw(int x, int y, int b);
void hal_render(); void hal_render();
void render(); void render();

View file

@ -1,4 +1,5 @@
#include "string.h"
#include "buttons.h" #include "buttons.h"
#include "example.h" #include "example.h"
#include "node.h" #include "node.h"
@ -32,15 +33,25 @@ void blubValue::render(canvas& c){
c.print(3 , 15, title_); c.print(3 , 15, title_);
} }
void menu::render(canvas& c){ void menu::render(canvas& c) {
for(int i = 0; i<c.getHeight();i++) for (int i = 0; i < c.getHeight(); i++)
c.draw(0,i); c.draw(0, i);
int r = 0; int r = 0;
node* ptr = getChild(); node *ptr = getChild();
while(ptr){ while (ptr) {
c.print(3,6*r+2, ptr->title_); 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(); ptr = ptr->getNext();
r++; r++;
} }

View file

@ -14,17 +14,17 @@ void canvas::clear() {
buffer_.set(x * height_ + y, false); 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_) 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) { void canvas::print(int x, int y, const char *str, bool inv, font& f) {
f.print(x, y, str, *this); f.print(x, y, str, *this, inv);
} }
void canvas::print(int x, int y, char *str, font& f) { void canvas::print(int x, int y, char *str, bool inv, font& f) {
f.print(x, y, str, *this); f.print(x, y, str, *this, inv);
} }
int canvas::getWidth(){ int canvas::getWidth(){

View file

@ -10,22 +10,22 @@
font::font(raw_font& raw ):raw_data_(raw){ 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; int j = (l - ' ') % 32;
for (int x_ = 0; x_ < 4; x_++) for (int x_ = 0; x_ < 4; x_++)
for (int y_ = 0; y_ < 5; y_++) for (int y_ = 0; y_ < 5; y_++)
if (raw_data_[j][x_ + 4 * 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++) { 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++) { for (int i = 0; str[i]; i++) {
print(x + i * 5,y,str[i],c); print(x + i * 5,y,str[i],c, inv);
} }
} }

View file

@ -8,17 +8,13 @@ screen::screen(int w, int h) : width_(w), height_(h) {
hal_init_screen(w,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) { void screen::draw(int x, int y, canvas &c) {
for (int x_ = 0; x_ < width_; x_++) for (int x_ = 0; x_ < c.getWidth(); x_++)
for (int y_ = 0; y_ < height_; y_++) for (int y_ = 0; y_ < c.getHeight(); y_+= 8 *sizeof(int))
if (c.buffer_.get(x_ * height_ + y_)) hal_draw(x + x_, y + y_,c.buffer_.getBlock(x_ * c.getHeight() + y_));
hal_draw(x + x_, y + y_);
} }
/*
void screen::print(int x, int y, const char *str, font& f) { void screen::print(int x, int y, const char *str, font& f) {
//f.print(x, y, str); //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) { void screen::print(int x, int y, char *str, font& f) {
//f.print(x, y, str); //f.print(x, y, str);
} }
*/
int screen::getWidth(){ int screen::getWidth(){
return width_; return width_;

View file

@ -3,24 +3,25 @@
// //
#include "ssd1306.h" #include "ssd1306.h"
#include "nano_gfx.h"
#include "buttons.h" #include "buttons.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <hal/hal.h> #include <hal/hal.h>
uint8_t canvasData[128 * (32 / 8)];
NanoCanvas canvas(128, 32, canvasData);
void hal_init_screen(int w, int h) { void hal_init_screen(int w, int h) {
ssd1306_128x32_i2c_init(); ssd1306_128x32_i2c_init();
ssd1306_fillScreen( 0x00 );
DDRD = 0; DDRD = 0;
PORTD |= (1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5); PORTD |= (1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5);
} }
void hal_draw(int x, int y){ void hal_draw(int x, int y, int b){
canvas.putPixel(x, y); 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() { void hal_render() {
while (true) { while (true) {
ssd1306_fillScreen( 0x00 );
render(); render();
canvas.blt(0, 0);
} }
} }

View file

@ -35,8 +35,20 @@ void hal_init_screen(int width, int height){
} }
} }
void hal_draw(int x, int y){ void hal_draw(int x, int y, int b) {
SDL_RenderDrawPoint(renderer, x, y); 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) { while (!quit) {
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
render(); render();
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }

View file

@ -29,47 +29,27 @@ menu* root;
int main() { int main() {
root = new menu("", root = new menu("",
new menu("foo", new menu("baz",
new menu("baz", new menu("x",
new fooValue("I", 5), new fooValue("x x", 5),
new fooValue("II", 5), new blubValue("xxx", 5)
new fooValue("III", 5),
new fooValue("IIII", 5)
), ),
new menu("peng", new fooValue("I", 5),
new fooValue("o", 5), new fooValue("II", 5),
new fooValue("oo", 5), new blubValue("III", 5),
new fooValue("o o", 5) new blubValue("IIII", 5)
), ),
new menu("x", new menu("peng",
new fooValue("x x", 5), new fooValue("o", 5),
new fooValue("xxx", 5) new fooValue("oo", 5),
), new fooValue("o o", 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)
)
);
hal_render();
return 0; hal_render();
return 0;
} }
void render(){ void render(){
@ -92,6 +72,7 @@ void buttons::onPush(int id, bool state) {
} }
break; break;
case I_UP: case I_UP:
// TODO implement
break; break;
case I_RIGHT: case I_RIGHT:
c = l.cursor; c = l.cursor;