some bugfixes
This commit is contained in:
parent
6570f7fafc
commit
c822a75df0
15 changed files with 93 additions and 94 deletions
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
class fooValue : public value {
|
||||
public:
|
||||
fooValue(const char* str, int val) : value(str, val, 64, 96) {
|
||||
fooValue(const char* str, int val) : value(str, val, 32, 48) {
|
||||
}
|
||||
|
||||
void render(canvas &c);
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -9,7 +9,6 @@
|
|||
#include "gfx/font.h"
|
||||
#include "fonts/basic_5x4.h"
|
||||
#include "gfx/buffer.h"
|
||||
#include "gfx/buffer_32.h"
|
||||
|
||||
class screen;
|
||||
|
||||
|
|
|
@ -21,8 +21,9 @@ class layout {
|
|||
|
||||
private:
|
||||
const int maxwidth_;
|
||||
const int maxheight_;
|
||||
int allocated_;
|
||||
screen screen_;
|
||||
screen& screen_;
|
||||
|
||||
int allocate_(node *, int);
|
||||
|
||||
|
@ -35,7 +36,7 @@ public:
|
|||
static const int maxslots = 10;
|
||||
Slot slots[maxslots];
|
||||
|
||||
layout(int width) : maxwidth_(width), screen_(width, 32) {
|
||||
layout(screen& s) : maxwidth_(s.getWidth()), maxheight_(s.getHeight()), screen_(s) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -14,28 +14,19 @@ private:
|
|||
const int height_;
|
||||
|
||||
public:
|
||||
screen(int w, int h) : width_(w), height_(h) {
|
||||
screen(int w, int h);
|
||||
|
||||
}
|
||||
void draw(int x, int y);
|
||||
|
||||
void draw(int x, int y) {
|
||||
hal_draw(x, y);
|
||||
}
|
||||
void draw(int x, int y, canvas &c);
|
||||
|
||||
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, const char *str, font & = basic_5x4){
|
||||
void print(int x, int y, char *str, font & = basic_5x4);
|
||||
|
||||
}
|
||||
int getWidth();
|
||||
|
||||
void print(int x, int y, char *str, font & = basic_5x4){
|
||||
|
||||
}
|
||||
int getHeight();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -10,11 +10,10 @@
|
|||
|
||||
void debug(const char* str);
|
||||
void hal_init();
|
||||
void hal_init_screen(int w, int h);
|
||||
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];
|
||||
|
||||
|
@ -25,7 +24,4 @@ void operator delete(void * ptr);
|
|||
|
||||
#endif
|
||||
|
||||
extern const int SCREEN_WIDTH;
|
||||
extern const int SCREEN_HEIGHT;
|
||||
|
||||
#endif
|
||||
|
|
16
inc/node.h
16
inc/node.h
|
@ -9,9 +9,10 @@
|
|||
|
||||
class node {
|
||||
private:
|
||||
node *parent_ = 0;
|
||||
node *child_ = 0;
|
||||
node *next_ = 0;
|
||||
node *parent_ = nullptr;
|
||||
node *child_ = nullptr;
|
||||
node *cursor_ = nullptr;
|
||||
node *next_ = nullptr;
|
||||
|
||||
void addNodes(bool b) {
|
||||
}
|
||||
|
@ -41,6 +42,7 @@ public:
|
|||
template<typename ... Args>
|
||||
node(const char *t, node *n, Args ... ns) : title_(t), minsize(24), maxsize(48) {
|
||||
child_ = n;
|
||||
cursor_ = n;
|
||||
n->parent_ = this;
|
||||
child_->addNodes(true, ns...);
|
||||
}
|
||||
|
@ -48,6 +50,14 @@ public:
|
|||
node *getChild() {
|
||||
return child_;
|
||||
}
|
||||
|
||||
node *getNext() {
|
||||
return next_;
|
||||
}
|
||||
|
||||
node *getCursor() {
|
||||
return cursor_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ int j = 0;
|
|||
|
||||
void fooValue::render(canvas& c){
|
||||
|
||||
for(int i = 0; i<32; i++)
|
||||
for(int i = 0; i<c.getHeight(); i++)
|
||||
c.draw(0,i);
|
||||
|
||||
|
||||
c.print(5 , 10, title_);
|
||||
c.print(10 , 10, title_);
|
||||
peng[0] = input[0] ? 'L' : ' ';
|
||||
peng[1] = input[1] ? 'R' : ' ';
|
||||
peng[2] = input[2] ? 'U' : ' ';
|
||||
|
@ -25,16 +25,22 @@ void fooValue::render(canvas& c){
|
|||
}
|
||||
|
||||
void blubValue::render(canvas& c){
|
||||
for(int i = 0; i<32;i++)
|
||||
for(int i = 0; i<c.getHeight();i++)
|
||||
c.draw(0,i);
|
||||
|
||||
c.print(5 , 10, title_);
|
||||
c.print(3 , 15, title_);
|
||||
}
|
||||
|
||||
void menu::render(canvas& c){
|
||||
|
||||
for(int i = 0; i<32;i++)
|
||||
for(int i = 0; i<c.getHeight();i++)
|
||||
c.draw(0,i);
|
||||
|
||||
c.print(5, 10, title_);
|
||||
int r = 0;
|
||||
node* ptr = getChild();
|
||||
while(ptr){
|
||||
c.print(3,6*r+2, ptr->title_);
|
||||
ptr = ptr->getNext();
|
||||
r++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
//
|
||||
// Created by jedi on 11/2/18.
|
||||
//
|
||||
|
||||
#include "gfx/buffer_32.h"
|
|
@ -15,6 +15,7 @@ void canvas::clear() {
|
|||
}
|
||||
|
||||
void canvas::draw(int x, int y) {
|
||||
if (y < height_ && x < width_)
|
||||
buffer_.set(x * height_ + y, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "node.h"
|
||||
#include "gfx/layout.h"
|
||||
|
||||
|
||||
void layout::render() {
|
||||
for (int j = 0; j < allocated_; j++) {
|
||||
node *node_ptr;
|
||||
|
@ -18,7 +17,7 @@ void layout::render() {
|
|||
}
|
||||
|
||||
int layout::apply(node* node) {
|
||||
int rootslot = allocate_(node, maxslots);
|
||||
int rootslot = allocate_(node, maxslots)+1;
|
||||
int minsize = pack_(rootslot);
|
||||
expand_(minsize);
|
||||
return 0;
|
||||
|
@ -45,14 +44,14 @@ int layout::expand_(int packedsize) {
|
|||
if (size > slots[i].content->maxsize)
|
||||
size = slots[i].content->maxsize;
|
||||
slots[i].size_ = size;
|
||||
slots[i].canvas_ = new canvas(size, 32);
|
||||
slots[i].canvas_ = new canvas(size, maxheight_);
|
||||
pos += size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int layout::allocate_(node* current, int depth) {
|
||||
if (node* next = current->getChild()) {
|
||||
if (node* next = current->getCursor()) {
|
||||
int i = allocate_(next, depth) + 1;
|
||||
slots[i].content = current;
|
||||
return i;
|
||||
|
|
|
@ -3,3 +3,34 @@
|
|||
//
|
||||
|
||||
#include "gfx/screen.h"
|
||||
|
||||
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_);
|
||||
}
|
||||
|
||||
void screen::print(int x, int y, const char *str, font& f) {
|
||||
//f.print(x, y, str);
|
||||
}
|
||||
|
||||
void screen::print(int x, int y, char *str, font& f) {
|
||||
//f.print(x, y, str);
|
||||
}
|
||||
|
||||
int screen::getWidth(){
|
||||
return width_;
|
||||
}
|
||||
|
||||
int screen::getHeight(){
|
||||
return height_;
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
#include "hal/hal.h"
|
||||
|
||||
const int SCREEN_WIDTH = 128;
|
||||
const int SCREEN_HEIGHT = 32;
|
||||
|
||||
bool input[4];
|
||||
|
||||
#ifdef LINUX
|
||||
|
|
|
@ -13,13 +13,19 @@ SDL_Event event;
|
|||
SDL_Renderer *renderer;
|
||||
|
||||
void hal_init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void hal_init_screen(int width, int height){
|
||||
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,
|
||||
window = SDL_CreateWindow("SDL Tutorial", 0, 0, width, height,
|
||||
SDL_WINDOW_SHOWN); //|SDL_WINDOW_BORDERLESS
|
||||
if (window == nullptr) {
|
||||
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
|
||||
|
@ -31,17 +37,12 @@ void hal_init() {
|
|||
printf("Renderer could not be created! SDL_Error: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void hal_draw(int x, int y){
|
||||
SDL_RenderDrawPoint(renderer, x, y);
|
||||
}
|
||||
|
||||
void hal_print(int x, int y, const char* str){
|
||||
//TODO delete
|
||||
}
|
||||
|
||||
void hal_render() {
|
||||
|
||||
bool quit = false;
|
||||
|
|
33
src/main.cpp
33
src/main.cpp
|
@ -20,17 +20,17 @@ extern SDL_Renderer *renderer;
|
|||
|
||||
#endif
|
||||
|
||||
layout* lp;
|
||||
|
||||
screen s(128,32);
|
||||
layout l(s);
|
||||
menu* root;
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
|
||||
//build tree
|
||||
menu root(nullptr,
|
||||
new menu("foo1",
|
||||
new menu("foo2",
|
||||
new menu("foo3", new fooValue("FOO4",5))
|
||||
root = new menu("",
|
||||
new menu("fooa",
|
||||
new menu("foob",
|
||||
new menu("fooc", new fooValue("FOOd",5))
|
||||
),
|
||||
new menu("foo", new fooValue("BAR",5)),
|
||||
new menu("foo", new fooValue("BAZ",5))
|
||||
|
@ -40,20 +40,6 @@ int main() {
|
|||
new menu("blub", new blubValue("BLUB",5))
|
||||
);
|
||||
|
||||
///root.p(0);
|
||||
|
||||
|
||||
//walk tree + allocate slots
|
||||
//position slots
|
||||
// 128 x 32
|
||||
screen s(128, 32);//<128, 32> s;
|
||||
|
||||
layout l(128);
|
||||
l.apply(&root);
|
||||
lp=&l;
|
||||
|
||||
|
||||
//render
|
||||
hal_init();
|
||||
hal_render();
|
||||
|
||||
|
@ -62,5 +48,6 @@ int main() {
|
|||
}
|
||||
|
||||
void render(){
|
||||
lp->render();
|
||||
l.apply(root);
|
||||
l.render();
|
||||
}
|
Loading…
Reference in a new issue