add inverted text
This commit is contained in:
parent
806fc7c3e5
commit
6091a40278
12 changed files with 88 additions and 93 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1,6 +0,0 @@
|
|||
build/*
|
||||
lib/*
|
||||
deps/*
|
||||
.idea/*
|
||||
cmake-build-debug/*
|
||||
CMakeLists.txt
|
|
@ -29,6 +29,11 @@ public:
|
|||
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) {
|
||||
if (i < size_) {
|
||||
ptr_[i*N/block_] &= ~(((1<<N)-1) << (i*N%block_));
|
||||
|
|
|
@ -25,11 +25,11 @@ public:
|
|||
|
||||
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();
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@ private:
|
|||
raw_font& raw_data_;
|
||||
public:
|
||||
font(raw_font&);
|
||||
void print(int x, int y, char c, canvas&);
|
||||
void print(int x, int y, char* str, canvas&);
|
||||
void print(int x, int y, const char* str, canvas&);
|
||||
void print(int x, int y, char c, canvas&, bool inv = 0);
|
||||
void print(int x, int y, char* str, canvas&, bool inv = 0);
|
||||
void print(int x, int y, const char* str, canvas&, bool inv = 0);
|
||||
};
|
||||
|
||||
#endif //MGL_DMXMENU_FONT_H
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
void debug(const char* str);
|
||||
void hal_init_screen(int w, int h);
|
||||
|
||||
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 render();
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
#include "string.h"
|
||||
#include "buttons.h"
|
||||
#include "example.h"
|
||||
#include "node.h"
|
||||
|
@ -32,15 +33,25 @@ void blubValue::render(canvas& c){
|
|||
c.print(3 , 15, title_);
|
||||
}
|
||||
|
||||
void menu::render(canvas& c){
|
||||
void menu::render(canvas& c) {
|
||||
|
||||
for(int i = 0; i<c.getHeight();i++)
|
||||
c.draw(0,i);
|
||||
for (int i = 0; i < c.getHeight(); i++)
|
||||
c.draw(0, i);
|
||||
|
||||
int r = 0;
|
||||
node* ptr = getChild();
|
||||
while(ptr){
|
||||
c.print(3,6*r+2, ptr->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++;
|
||||
}
|
||||
|
|
|
@ -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(){
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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_;
|
||||
|
|
|
@ -3,24 +3,25 @@
|
|||
//
|
||||
|
||||
#include "ssd1306.h"
|
||||
#include "nano_gfx.h"
|
||||
#include "buttons.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <hal/hal.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
59
src/main.cpp
59
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;
|
||||
|
|
Loading…
Reference in a new issue