cleanup prototype code

This commit is contained in:
j3d1 2018-11-05 21:09:01 +01:00
parent d958452e48
commit bfef6fdc1e
17 changed files with 272 additions and 243 deletions

View file

@ -1,87 +0,0 @@
#ifndef _COL_H_
#define _COL_H_
class canvas;
#include "gfx/canvas.h"
class Node;
typedef void (*drawfun_t)(int offset, int size, Node*, canvas& c);
void draw_menu(int, int, Node*, canvas& c);
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

@ -3,9 +3,32 @@
#define _EXAMPLE_H_
#include "gfx/canvas.h"
#include "node.h"
void draw_foo(int offset, int size, Node* ptr, canvas& c);
class menu : public node {
public:
template<typename ... Args>
menu(Args ... ns) : node(ns...) {
}
void draw_blub(int offset, int size, Node* ptr, canvas& c);
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

View file

@ -5,7 +5,7 @@
#ifndef MGL_DMXMENU_CANVAS_H
#define MGL_DMXMENU_CANVAS_H
#include "hal.h"
#include "hal/hal.h"
#include "gfx/font.h"
#include "fonts/basic_5x4.h"
#include "gfx/buffer_1.h"
@ -32,6 +32,10 @@ public:
void print(int x, int y, char *str, font & = basic_5x4);
int getWidth();
int getHeight();
friend screen;
};

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

View file

@ -5,7 +5,8 @@
#ifndef MGL_DMXMENU_SCREEN_H
#define MGL_DMXMENU_SCREEN_H
#include "hal.h"
#include "hal/hal.h"
#include "gfx/canvas.h"
class screen {
private:
@ -13,22 +14,26 @@ private:
const int height_;
public:
screen(int w, int h): width_(w), height_(h){
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) {
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_);
if (c.buffer_.get(x_ * 32 + y_))
hal_draw(x + x_, y + y_);
}
void print(int x, int y, char* str){
void print(int x, int y, const char *str, font & = basic_5x4){
}
void print(int x, int y, char *str, font & = basic_5x4){
}

View file

@ -2,9 +2,6 @@
#ifndef _HAL_H_
#define _HAL_H_
class Layout;
#include "col.h"
#define I_LEFT 0
#define I_RIGHT 0
#define I_UP 0
@ -15,8 +12,8 @@ void debug(const char* str);
void hal_init();
void hal_draw(int x, int y);
void hal_print(int x, int y, const char* str);
void render(Layout&);
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