Merge pull request #7 from mikrogl/jedi/dev

Jedi/dev
This commit is contained in:
j3d1 2018-11-06 09:07:06 +01:00 committed by GitHub
commit 1585d7e363
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 765 additions and 252 deletions

View file

@ -1,5 +1,9 @@
TARGET = main
SRC = col.cpp hal.cpp main.cpp example.cpp
SRC = hal.cpp main.cpp example.cpp
SRC += gfx/screen.cpp gfx/canvas.cpp gfx/font.cpp gfx/layout.cpp gfx/buffer.cpp
SRC += fonts/basic_5x4.cpp
SRCDIR = src
INCDIR = inc

View file

@ -49,6 +49,7 @@ LDFLAGS = -Llib -lssd1306
#==== Programming Options (avrdude) ============================================
AVRDUDE_PROGRAMMER = arduino
AVRDUDE_PORT = /dev/arduinoACM
AVRDUDE_BAUD = 115200
#AVRDUDE_NO_VERIFY = -V
@ -175,10 +176,12 @@ $(OBJDIR)/%.elf: $(OBJ) | $(OBJDIR)
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
@echo compile $<
@mkdir -p $(dir $@)
@$(CC) -c $(CPU) $(CFLAGS) $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | $(OBJDIR)
@echo compile $<
@mkdir -p $(dir $@)
@$(CXX) -c $(CPU) $(CXXFLAGS) $< -o $@

View file

@ -1,84 +0,0 @@
#ifndef _COL_H_
#define _COL_H_
class Node;
typedef void (*drawfun_t)(int offset, int size, Node*);
void draw_menu(int, int, Node*);
class Drawable{
public:
const int minsize;
const int maxsize;
drawfun_t render;
Drawable(drawfun_t fun, int min = 0, int max=0): minsize(min), maxsize(max), render(fun){
}
};
class Node{
private:
Node* parent_ = 0;
Node* child_ = 0;
Node* next_ = 0;
void addNodes(bool b){
}
template<class ...Us>
void addNodes(bool b, Node* n, Us ... ns){
next_ = n;
next_->parent_ = parent_;
next_->addNodes(!b,ns...);
}
public:
Drawable view;
const char* title_ = 0;
Node(int min = 24, int max=48): next_(nullptr), child_(nullptr), parent_(nullptr), view(nullptr, min, max){
}
Node(const char* t, drawfun_t fun=draw_menu, int min = 24, int max=48) : title_(t), view(fun, min, max), next_(nullptr), child_(nullptr), parent_(nullptr){
}
template<typename ... Args>
Node(const char* t, Node* n, Args ... ns) : title_(t), view(draw_menu, 24, 48){
child_ = n;
n->parent_=this;
child_->addNodes(true,ns...);
}
Node* getChild(){
return child_;
}
};
class Value: public Node{
public:
const char* header;
int state;
Value(const char* t, int val, drawfun_t fun): Node(t, fun, 64, 96), header(t), state(val){
}
};
class Layout{
class Slot{
private:
int pos_;
int size_;
public:
Node* node;
friend Layout;
};
private:
const int maxwidth_;
int allocated_;
int allocate_(Node*, int);
int expand_(int );
int pack_(int);
public:
static const int maxslots = 10;
Layout(int max) : maxwidth_(max){
}
int apply(Node*);
Slot slots[maxslots];
void render();
};
#endif

View file

@ -2,8 +2,33 @@
#ifndef _EXAMPLE_H_
#define _EXAMPLE_H_
void draw_foo(int offset, int size, Node* ptr);
#include "gfx/canvas.h"
#include "node.h"
void draw_blub(int offset, int size, Node* ptr);
class menu : public node {
public:
template<typename ... Args>
menu(Args ... ns) : node(ns...) {
}
void render(canvas &c);
};
class fooValue : public value {
public:
fooValue(const char* str, int val) : value(str, val, 64, 96) {
}
void render(canvas &c);
};
class blubValue : public value{
public:
template<typename ... Args>
blubValue(Args ... ns) : value(ns..., 64, 96) {
}
void render(canvas& c);
};
#endif

12
inc/fonts/basic_5x4.h Normal file
View file

@ -0,0 +1,12 @@
//
// Created by jedi on 11/2/18.
//
#ifndef MGL_DMXMENU_BASIC_5X4_H
#define MGL_DMXMENU_BASIC_5X4_H
#include "gfx/font.h"
extern font basic_5x4;
#endif //MGL_DMXMENU_BASIC_5X4_H

50
inc/gfx/buffer.h Normal file
View file

@ -0,0 +1,50 @@
//
// Created by jedi on 11/2/18.
//
#ifndef MGL_DMXMENU_BUFFER_1_H
#define MGL_DMXMENU_BUFFER_1_H
#include <stdlib.h>
#include <stdint.h>
enum bufferBlocks{
_1bit = 1, _2bit = 2, _4bit = 4, _8bit = 8, _16bit = 16, _24bit = 24, _32bit = 32
};
template <bufferBlocks N>
class buffer {
private:
int *ptr_;
int size_;
constexpr static const int block_ = 8 * sizeof(int);
public:
buffer(int size) : size_(size) {
ptr_ = (int *) malloc(size * N / 8);
}
int get(int i) {
if (i >= size_) return 0;
return ptr_[i*N/block_] & ((1<<N)-1) << (i*N%block_);
}
void set(int i, int v) {
if (i < size_) {
ptr_[i*N/block_] &= ~(((1<<N)-1) << (i*N%block_));
ptr_[i*N/block_] |= (((1<<N)-1)&v) << (i*N%block_);
}
}
~buffer() {
free(ptr_);
}
};
template <>
int buffer<_32bit>::get(int i);
template <>
void buffer<_32bit>::set(int i, int v);
#endif //MGL_DMXMENU_BUFFER_1_H

15
inc/gfx/buffer_32.h Normal file
View file

@ -0,0 +1,15 @@
//
// Created by jedi on 11/2/18.
//
#ifndef MGL_DMXMENU_BUFFER_8_H
#define MGL_DMXMENU_BUFFER_8_H
#include <stdlib.h>
#include <stdint.h>
#endif //MGL_DMXMENU_BUFFER_8_H

43
inc/gfx/canvas.h Normal file
View file

@ -0,0 +1,43 @@
//
// Created by jedi on 11/1/18.
//
#ifndef MGL_DMXMENU_CANVAS_H
#define MGL_DMXMENU_CANVAS_H
#include "hal/hal.h"
#include "gfx/font.h"
#include "fonts/basic_5x4.h"
#include "gfx/buffer.h"
#include "gfx/buffer_32.h"
class screen;
class canvas {
private:
const int width_;
const int height_;
buffer<_1bit> buffer_;
void draw_onto_(screen &);
public:
canvas(int w, int h);
void clear();
void draw(int x, int y);
void print(int x, int y, const char *str, font & = basic_5x4);
void print(int x, int y, char *str, font & = basic_5x4);
int getWidth();
int getHeight();
friend screen;
};
#endif //MGL_DMXMENU_CANVAS_H

22
inc/gfx/font.h Normal file
View file

@ -0,0 +1,22 @@
//
// Created by jedi on 11/1/18.
//
#ifndef MGL_DMXMENU_FONT_H
#define MGL_DMXMENU_FONT_H
class canvas;
class font {
public:
typedef const bool raw_font[32][20];
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&);
};
#endif //MGL_DMXMENU_FONT_H

49
inc/gfx/layout.h Normal file
View file

@ -0,0 +1,49 @@
//
// Created by jedi on 11/5/18.
//
#ifndef MGL_DMXMENU_LAYOUT_H
#define MGL_DMXMENU_LAYOUT_H
#include "gfx/canvas.h"
#include "gfx/screen.h"
class layout {
class Slot {
private:
int pos_;
int size_;
canvas *canvas_ = 0;
public:
node *content;
friend layout;
};
private:
const int maxwidth_;
int allocated_;
screen screen_;
int allocate_(node *, int);
int expand_(int);
int pack_(int);
public:
static const int maxslots = 10;
Slot slots[maxslots];
layout(int width) : maxwidth_(width), screen_(width, 32) {
}
int apply(node *);
void render();
};
#endif //MGL_DMXMENU_LAYOUT_H

43
inc/gfx/screen.h Normal file
View file

@ -0,0 +1,43 @@
//
// Created by jedi on 11/1/18.
//
#ifndef MGL_DMXMENU_SCREEN_H
#define MGL_DMXMENU_SCREEN_H
#include "hal/hal.h"
#include "gfx/canvas.h"
class screen {
private:
const int width_;
const int height_;
public:
screen(int w, int h) : width_(w), height_(h) {
}
void draw(int x, int y) {
hal_draw(x, y);
}
void draw(int x, int y, canvas &c) {
for (int x_ = 0; x_ < 128; x_++)
for (int y_ = 0; y_ < 32; y_++)
if (c.buffer_.get(x_ * 32 + y_))
hal_draw(x + x_, y + y_);
}
void print(int x, int y, const char *str, font & = basic_5x4){
}
void print(int x, int y, char *str, font & = basic_5x4){
}
};
#endif //MGL_DMXMENU_SCREEN_H

View file

@ -2,19 +2,18 @@
#ifndef _HAL_H_
#define _HAL_H_
#include "col.h"
#define I_LEFT 0
#define I_RIGHT 0
#define I_UP 0
#define I_DOWN 0
#define I_RIGHT 1
#define I_UP 2
#define I_DOWN 3
void debug(const char* str);
void setup();
void draw(int x, int y);
void print(int x, int y, const char* str);
void render(Layout&);
void hal_init();
void hal_draw(int x, int y);
void hal_print(int x, int y, const char* str);
void hal_render();
void render();
void quit();
extern bool input[4];

64
inc/node.h Normal file
View file

@ -0,0 +1,64 @@
//
// Created by jedi on 11/5/18.
//
#ifndef MGL_DMXMENU_NODE_H
#define MGL_DMXMENU_NODE_H
#include "gfx/canvas.h"
class node {
private:
node *parent_ = 0;
node *child_ = 0;
node *next_ = 0;
void addNodes(bool b) {
}
template<class ...Us>
void addNodes(bool b, node *n, Us ... ns) {
next_ = n;
next_->parent_ = parent_;
next_->addNodes(!b, ns...);
}
public:
const char *title_ = 0;
const int minsize;
const int maxsize;
virtual void render(canvas &c) = 0;
node(int min = 24, int max = 48) : next_(nullptr), child_(nullptr), parent_(nullptr), minsize(min), maxsize(max) {
}
node(const char *t, int min = 24, int max = 48) : title_(t), minsize(min), maxsize(max), next_(nullptr),
child_(nullptr),
parent_(nullptr) {
}
template<typename ... Args>
node(const char *t, node *n, Args ... ns) : title_(t), minsize(24), maxsize(48) {
child_ = n;
n->parent_ = this;
child_->addNodes(true, ns...);
}
node *getChild() {
return child_;
}
};
class value: public node {
public:
const char *header;
int state;
value(const char *t, int val, int min = 64, int max = 96) : node(t, min, max), header(t), state(val) {
}
};
#endif //MGL_DMXMENU_NODE_H

View file

@ -28,10 +28,12 @@ $(OBJDIR)/$(TARGET): $(OBJ) | $(OBJDIR)
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
@echo compile $<
@mkdir -p $(dir $@)
@$(CC) -c $(CFLAGS) $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | $(OBJDIR)
@echo compile $<
@mkdir -p $(dir $@)
@$(CXX) -c $(CXXFLAGS) $< -o $@
$(OBJDIR):

View file

@ -1,58 +0,0 @@
#include "hal.h"
#include "col.h"
void Layout::render(){
for(int j = 0; j < allocated_; j++){
Node * node;
if((node = slots[j].node) && node->view.render){
node->view.render(slots[j].pos_,slots[j].size_,node);
}
}
}
int Layout::apply(Node* node){
int rootslot = allocate_(node, maxslots);
int minsize = pack_(rootslot);
expand_(minsize);
return 0;
}
int Layout::pack_(int usedslots){
int minsum = 0;
int i;
for(i = 0; i<usedslots; i++){
if(!slots[i].node) break;
if(minsum+slots[i].node->view.minsize>maxwidth_) break;
minsum+=slots[i].node->view.minsize;
}
allocated_ = i;
return minsum;
}
int Layout::expand_(int packedsize){
int diff = maxwidth_ - packedsize;
int pos = 0;
for(int i = allocated_-1; i>=0; i--){
slots[i].pos_=pos;
int size = slots[i].node->view.minsize + (diff*slots[i].node->view.minsize)/packedsize;
if(size > slots[i].node->view.maxsize)
size = slots[i].node->view.maxsize;
slots[i].size_=size;
pos+=size;
}
return 0;
}
int Layout::allocate_(Node* node, int depth){
if(Node* next = node->getChild()){
int i = allocate_(next, depth) + 1;
slots[i].node = node;
return i;
}else{
slots[0].node = node;
return 0;
}
}

View file

@ -1,62 +1,40 @@
#include "hal.h"
#include "col.h"
#include "example.h"
#include "../inc/hal.h"
#include "node.h"
#include "gfx/canvas.h"
char peng[] = {'_','_','_','_','_',0};
char peng[] = {' ', ' ', ' ', ' ', ' ', 0};
int j = 0;
void draw_foo(int offset, int size, Node* ptr){
Value* val = (Value*) ptr;
/*debug("|");
if(ptr)
debug(ptr->title_);
//print(ptr->state);
debug("|");*/
void fooValue::render(canvas& c){
for(int i = 0; i<32; i++)
draw(offset,i);
for(int i = 0; i<size; i++)
draw(offset+i,31-i%32);
for(int i = 0; i<size; i++)
draw(offset+i,31-(i+16)%32);
c.draw(0,i);
print(offset+5 , 10, ptr->title_);
peng[0]=input[0]?' ':'#';
peng[1]=input[1]?' ':'#';
peng[2]=input[2]?' ':'#';
peng[3]=input[3]?' ':'#';
c.print(5 , 10, title_);
peng[0] = input[0] ? 'L' : ' ';
peng[1] = input[1] ? 'R' : ' ';
peng[2] = input[2] ? 'U' : ' ';
peng[3] = input[3] ? 'D' : ' ';
j++;
j%=26;
peng[4] = 'a'+j;
print(offset+5 , 20, peng);
j %= 10;
peng[4] = 'A' + j;
c.print(5 , 20, peng);
}
void draw_blub(int offset, int size, Node* ptr){
Value* val = (Value*) ptr;
/*debug("#");
if(ptr)
debug(ptr->title_);
//print(ptr->state);
debug("#");*/
void blubValue::render(canvas& c){
for(int i = 0; i<32;i++)
draw(offset,i);
c.draw(0,i);
print(offset+5 , 10, ptr->title_);
c.print(5 , 10, title_);
}
void draw_menu(int offset, int size, Node* val){
/*if(val&&val->title_){
debug("_");
debug(val->title_);
debug("_");
//print(ptr->state);
}*/
void menu::render(canvas& c){
for(int i = 0; i<32;i++)
draw(offset,i);
for(int i = 0; i<32 && i<size;i++)
draw(offset+(i%size),i);
c.draw(0,i);
c.print(5, 10, title_);
}

172
src/fonts/basic_5x4.cpp Normal file
View file

@ -0,0 +1,172 @@
//
// Created by jedi on 11/2/18.
//
#include "fonts/basic_5x4.h"
const bool basic_5x4_raw[32][20] = {
//0
{0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0},
//A
{0,1,1,0,
1,0,0,1,
1,0,0,1,
1,1,1,1,
1,0,0,1},
//B
{1,1,1,0,
1,0,0,1,
1,1,1,0,
1,0,0,1,
1,1,1,0},
//C
{0,1,1,0,
1,0,0,1,
1,0,0,0,
1,0,0,1,
0,1,1,0},
//D
{1,1,1,0,
1,0,0,1,
1,0,0,1,
1,0,0,1,
1,1,1,0},
//E
{1,1,1,1,
1,0,0,0,
1,1,1,0,
1,0,0,0,
1,1,1,1},
//F
{1,1,1,1,
1,0,0,0,
1,1,1,0,
1,0,0,0,
1,0,0,0},
//G
{0,1,1,1,
1,0,0,0,
1,0,1,1,
1,0,0,1,
0,1,1,1},
//H
{1,0,0,1,
1,0,0,1,
1,1,1,1,
1,0,0,1,
1,0,0,1},
//I
{1,1,1,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,
1,1,1,0},
//J
{1,1,1,1,
0,0,0,1,
0,0,0,1,
0,0,0,1,
1,1,1,0},
//K
{1,0,0,1,
1,0,1,0,
1,1,0,0,
1,0,1,0,
1,0,0,1},
//L
{1,0,0,0,
1,0,0,0,
1,0,0,0,
1,0,0,0,
1,1,1,1},
//M
{1,0,0,1,
1,1,1,1,
1,1,1,1,
1,0,0,1,
1,0,0,1},
//N
{1,0,0,1,
1,1,0,1,
1,0,1,1,
1,0,0,1,
1,0,0,1},
//O
{0,1,1,0,
1,0,0,1,
1,0,0,1,
1,0,0,1,
0,1,1,0},
//P
{1,1,1,0,
1,0,0,1,
1,0,0,1,
1,1,1,0,
1,0,0,0},
//Q
{0,1,1,0,
1,0,0,1,
1,0,0,1,
1,0,1,1,
0,1,1,1},
//R
{1,1,1,0,
1,0,0,1,
1,0,0,1,
1,1,1,0,
1,0,0,1},
//S
{0,1,1,1,
1,0,0,0,
0,1,1,0,
0,0,0,1,
1,1,1,0},
//T
{1,1,1,1,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0},
//U
{1,0,0,1,
1,0,0,1,
1,0,0,1,
1,0,0,1,
0,1,1,0},
//V
{1,0,0,1,
1,0,0,1,
1,0,1,0,
1,0,1,0,
0,1,0,0},
//W
{1,0,0,1,
1,0,0,1,
1,1,1,1,
1,1,1,1,
0,1,1,0},
//X
{1,0,0,1,
1,0,0,1,
0,1,1,0,
1,0,0,1,
1,0,0,1},
//Y
{1,0,0,1,
1,0,0,1,
0,1,1,1,
0,0,0,1,
1,1,1,0},
//Z
{1,1,1,1,
0,0,0,1,
0,1,1,0,
1,0,0,0,
1,1,1,1},
};
font basic_5x4(basic_5x4_raw);

17
src/gfx/buffer.cpp Normal file
View file

@ -0,0 +1,17 @@
//
// Created by jedi on 11/2/18.
//
#include "gfx/buffer.h"
template <>
int buffer<_32bit>::get(int i){
if (i >= size_) return 0;
return ptr_[i];
}
template <>
void buffer<_32bit>::set(int i, int v) {
if (i < size_)
ptr_[i] = v;
}

5
src/gfx/buffer_32.cpp Normal file
View file

@ -0,0 +1,5 @@
//
// Created by jedi on 11/2/18.
//
#include "gfx/buffer_32.h"

35
src/gfx/canvas.cpp Normal file
View file

@ -0,0 +1,35 @@
//
// Created by jedi on 11/1/18.
//
#include "gfx/canvas.h"
canvas::canvas(int w, int h) : width_(w), height_(h), buffer_(w*h) {
clear();
}
void canvas::clear() {
for (int x = 0; x < width_; x++)
for (int y = 0; y < height_; y++)
buffer_.set(x * height_ + y, false);
}
void canvas::draw(int x, int y) {
buffer_.set(x * height_ + y, true);
}
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, char *str, font& f) {
f.print(x, y, str, *this);
}
int canvas::getWidth(){
return width_;
}
int canvas::getHeight(){
return height_;
}

31
src/gfx/font.cpp Normal file
View file

@ -0,0 +1,31 @@
//
// Created by jedi on 11/1/18.
//
#include "gfx/font.h"
#include "gfx/canvas.h"
font::font(raw_font& raw ):raw_data_(raw){
}
void font::print(int x, int y, char l, canvas& c) {
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_);
}
void font::print(int x, int y, char* str, canvas& c) {
for (int i = 0; str[i]; i++) {
print(x + i * 5,y,str[i],c);
}
}
void font::print(int x, int y, const char* str, canvas& c) {
for (int i = 0; str[i]; i++) {
print(x + i * 5,y,str[i],c);
}
}

63
src/gfx/layout.cpp Normal file
View file

@ -0,0 +1,63 @@
//
// Created by jedi on 11/5/18.
//
#include "node.h"
#include "gfx/layout.h"
void layout::render() {
for (int j = 0; j < allocated_; j++) {
node *node_ptr;
if (node_ptr = slots[j].content) {
slots[j].canvas_->clear();
node_ptr->render(*slots[j].canvas_);
screen_.draw(slots[j].pos_, 0, *slots[j].canvas_);
}
}
}
int layout::apply(node* node) {
int rootslot = allocate_(node, maxslots);
int minsize = pack_(rootslot);
expand_(minsize);
return 0;
}
int layout::pack_(int usedslots) {
int minsum = 0;
int i;
for (i = 0; i < usedslots; i++) {
if (!slots[i].content) break;
if (minsum + slots[i].content->minsize > maxwidth_) break;
minsum += slots[i].content->minsize;
}
allocated_ = i;
return minsum;
}
int layout::expand_(int packedsize) {
int diff = maxwidth_ - packedsize;
int pos = 0;
for (int i = allocated_ - 1; i >= 0; i--) {
slots[i].pos_ = pos;
int size = slots[i].content->minsize + (diff * slots[i].content->minsize) / packedsize;
if (size > slots[i].content->maxsize)
size = slots[i].content->maxsize;
slots[i].size_ = size;
slots[i].canvas_ = new canvas(size, 32);
pos += size;
}
return 0;
}
int layout::allocate_(node* current, int depth) {
if (node* next = current->getChild()) {
int i = allocate_(next, depth) + 1;
slots[i].content = current;
return i;
} else {
slots[0].content = current;
return 0;
}
}

5
src/gfx/screen.cpp Normal file
View file

@ -0,0 +1,5 @@
//
// Created by jedi on 11/1/18.
//
#include "gfx/screen.h"

View file

@ -1,6 +1,6 @@
#include "hal.h"
#include "hal/hal.h"
const int SCREEN_WIDTH = 128;
const int SCREEN_WIDTH = 128;
const int SCREEN_HEIGHT = 32;
bool input[4];

View file

@ -9,22 +9,17 @@
uint8_t canvasData[SCREEN_WIDTH*(SCREEN_HEIGHT/8)];
NanoCanvas canvas(SCREEN_WIDTH, SCREEN_HEIGHT, canvasData);
void setup(){
void hal_init(){
ssd1306_128x32_i2c_init();
ssd1306_fillScreen( 0x00 );
//ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_setFixedFont(ssd1306xled_font5x7);
canvas.clear();
}
void draw(int x, int y){
void hal_draw(int x, int y){
canvas.putPixel(x, y);
}
void print(int x, int y, const char* str){
canvas.printFixed(x, y, str, STYLE_NORMAL);
}
void render(Layout& layout) {
void hal_render() {
DDRD = 0;
PORTD |= (1 << PC2)|(1 << PC3)|(1 << PC4)|(1 << PC5);
@ -38,7 +33,7 @@ void render(Layout& layout) {
input[3]=in & (1<<PC5);
canvas.clear();
layout.render();
render();
canvas.blt(0, 0);
}
}

View file

@ -6,51 +6,46 @@
//Using SDL and standard IO
#include <SDL2/SDL.h>
#include <stdio.h>
#include <cstdio>
SDL_Window* window = NULL;
SDL_Window *window = nullptr;
SDL_Event event;
SDL_Renderer *renderer;
void setup(){
if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
void hal_init() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
exit(1);
}
//Create window
window = SDL_CreateWindow( "SDL Tutorial", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN|SDL_WINDOW_BORDERLESS );
if( window == NULL ) {
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
exit(1);
}
int i;
/* //Create window
window = SDL_CreateWindow( "SDL Tutorial", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN|SDL_WINDOW_BORDERLESS );
if( window == NULL ) {
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
exit(1);
}
*/
SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, 0, &window, &renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
}
void draw(int x, int y){
void hal_draw(int x, int y){
SDL_RenderDrawPoint(renderer, x, y);
}
void print(int x, int y, const char* str){
//TODO implement
void hal_print(int x, int y, const char* str){
//TODO delete
}
void render(Layout& layout) {
void hal_render() {
bool quit = false;
while (!quit) {
if (SDL_WaitEvent(&event)) {
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
@ -91,9 +86,14 @@ void render(Layout& layout) {
quit = true;
break;
}
} else {
SDL_Delay(10);
}
layout.render();
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
render();
SDL_RenderPresent(renderer);
}

View file

@ -1,33 +1,43 @@
#include "hal.h"
#include "col.h"
#include "hal/hal.h"
#include "node.h"
#include "gfx/layout.h"
#include "example.h"
#include "gfx/screen.h"
#include "gfx/canvas.h"
#ifdef LINUX
#include <SDL2/SDL.h>
#include <stdio.h>
extern SDL_Window* window;
extern SDL_Event event;
extern SDL_Renderer *renderer;
#ifdef AVR
#include "ssd1306.h"
#endif
layout* lp;
int main() {
//build tree
Node root(nullptr,
new Node("foo1",
new Node("foo2",
new Node("foo3", new Value("FOO4",5,draw_foo))
menu root(nullptr,
new menu("foo1",
new menu("foo2",
new menu("foo3", new fooValue("FOO4",5))
),
new Node("foo", new Value("BAR",5,draw_foo)),
new Node("foo", new Value("BAZ",5,draw_foo))
new menu("foo", new fooValue("BAR",5)),
new menu("foo", new fooValue("BAZ",5))
),
new Node("blub", new Value("BLUB",5,draw_blub)),
new Node("blub", new Value("BLUB",5,draw_blub)),
new Node("blub", new Value("BLUB",5,draw_blub))
new menu("blub", new blubValue("BLUB",5)),
new menu("blub", new blubValue("BLUB",5)),
new menu("blub", new blubValue("BLUB",5))
);
///root.p(0);
@ -36,13 +46,21 @@ int main() {
//walk tree + allocate slots
//position slots
// 128 x 32
Layout l(128);
screen s(128, 32);//<128, 32> s;
layout l(128);
l.apply(&root);
lp=&l;
//render
setup();
render(l);
hal_init();
hal_render();
return 0;
}
void render(){
lp->render();
}

5
src/node.cpp Normal file
View file

@ -0,0 +1,5 @@
//
// Created by jedi on 11/5/18.
//
#include "node.h"