From 8bf49928e596e77c343e74433215ca571920beb8 Mon Sep 17 00:00:00 2001 From: /jedi/ Date: Fri, 19 Oct 2018 13:49:11 +0200 Subject: [PATCH] add first code --- inc/col.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ inc/hal.h | 11 +++++++++ src/col.cpp | 29 +++++++++++++++++++++++ src/hal.cpp | 35 ++++++++++++++++++++++++++++ src/main.cpp | 41 +++++++++++++++++++++++++++++++- 5 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 inc/col.h create mode 100644 inc/hal.h create mode 100644 src/col.cpp create mode 100644 src/hal.cpp diff --git a/inc/col.h b/inc/col.h new file mode 100644 index 0000000..c6e68a5 --- /dev/null +++ b/inc/col.h @@ -0,0 +1,66 @@ + +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 + 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(): next_(nullptr), child_(nullptr), parent_(nullptr), view(nullptr){ + } + Node(const char* t, drawfun_t fun=draw_menu) : title_(t), view(fun), next_(nullptr), child_(nullptr), parent_(nullptr){ + } + + template + Node(const char* t, Node* n, Args ... ns) : title_(t), view(nullptr){ + child_ = n; + n->parent_=this; + child_->addNodes(true,ns...); + } + + void p(int i); +}; + +class Value: public Node{ + public: + const char* header; + int state; + Value(const char* t, int val, drawfun_t fun): Node(t, fun), header(t), state(val){ + + } +}; + +class Layout{ + private: + int menuthrs_; + public: + Layout(int max) : menuthrs_(max){ + + } + //slots +}; diff --git a/inc/hal.h b/inc/hal.h new file mode 100644 index 0000000..15e8d9d --- /dev/null +++ b/inc/hal.h @@ -0,0 +1,11 @@ + + +void print(const char* str); +void print(int str); + +#ifndef LINUX + +void * operator new(unsigned int size); +void operator delete(void * ptr); + +#endif diff --git a/src/col.cpp b/src/col.cpp new file mode 100644 index 0000000..7f62953 --- /dev/null +++ b/src/col.cpp @@ -0,0 +1,29 @@ + +#include "hal.h" +#include "col.h" + + +void Node::p(int i){ + for(int j = 0; j < i; j++){ print("__"); } + if(title_) + print(title_); + else + print("--"); + + if(view.render) + view.render(0,0,this); + + print("\n"); + + if(child_) + child_->p(i+1); + + if(next_) + next_->p(i); +} + + + +void draw_menu(int offset, int size, Node* val){ + +} diff --git a/src/hal.cpp b/src/hal.cpp new file mode 100644 index 0000000..1e57d1b --- /dev/null +++ b/src/hal.cpp @@ -0,0 +1,35 @@ + +#ifdef LINUX + +#include + +void print(const char* str){ + std::cout << str << std::flush; +} +void print(int str){ + std::cout << str << std::flush; +} + +#else + +#include + +void * operator new(unsigned int size) +{ + return malloc(size); +} + +void operator delete(void * ptr) +{ + free(ptr); +} + +void print(const char* str){ + +} + +void print(int str){ + +} + +#endif diff --git a/src/main.cpp b/src/main.cpp index 75d689f..cf51cdf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,45 @@ +#include "hal.h" +#include "col.h" + +void draw_foo(int offset, int size, Node* ptr){ + Value* val = (Value*) ptr; + print("\t|"); + if(ptr) + print(ptr->title_); + //print(ptr->state); + print("|"); +} + +void draw_blub(int offset, int size, Node* val){ + +} + int main() { - return 0; + Node root(nullptr, + new Node("foo", + new Node("foo", + new Node("foo", new Value("FOO",5,draw_foo)) + ), + new Node("foo", new Value("FOO",5,draw_foo)), + new Node("foo", new Value("FOO",5,draw_foo)) + ), + 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)) + ); + + + root.p(0); + + + // 128 x 32 + Layout l(64); + + //build tree + //walk tree + allocate slots + //position slots + //render }