refactor naming
This commit is contained in:
parent
e0181cc3e8
commit
24d6e756ee
30 changed files with 569 additions and 534 deletions
|
@ -2,27 +2,30 @@
|
|||
// Created by jedi on 11/6/18.
|
||||
//
|
||||
|
||||
#ifndef MGL_DMXMENU_INPUT_H
|
||||
#define MGL_DMXMENU_INPUT_H
|
||||
#pragma once
|
||||
|
||||
namespace micromenu {
|
||||
|
||||
enum direction {
|
||||
I_LEFT = 0,
|
||||
I_RIGHT,
|
||||
I_UP,
|
||||
I_DOWN
|
||||
};
|
||||
|
||||
class buttons {
|
||||
private:
|
||||
static void onPush(direction id, bool state);
|
||||
|
||||
public:
|
||||
bool raw[4] = {false, false, false, false};
|
||||
bool last[4] = {false, false, false, false};
|
||||
|
||||
void poll();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define I_LEFT 0
|
||||
#define I_RIGHT 1
|
||||
#define I_UP 2
|
||||
#define I_DOWN 3
|
||||
extern buttons input;
|
||||
|
||||
|
||||
class buttons {
|
||||
private:
|
||||
void onPush(int id, bool state);
|
||||
public:
|
||||
bool raw[4]={false,false, false, false};
|
||||
bool last[4]={false,false, false, false};
|
||||
void poll();
|
||||
};
|
||||
|
||||
|
||||
extern buttons input;
|
||||
|
||||
#endif //MGL_DMXMENU_INPUT_H
|
||||
}
|
||||
|
|
|
@ -2,33 +2,38 @@
|
|||
#ifndef _EXAMPLE_H_
|
||||
#define _EXAMPLE_H_
|
||||
|
||||
#include "gfx/canvas.h"
|
||||
#include "gfx/Canvas.h"
|
||||
#include "node.h"
|
||||
|
||||
class menu : public node {
|
||||
public:
|
||||
template<typename ... Args>
|
||||
menu(Args ... ns) : node(ns...) {
|
||||
}
|
||||
using canvas = micromenu::Canvas;
|
||||
using node = micromenu::node;
|
||||
using value = micromenu::value;
|
||||
|
||||
void render(canvas &c);
|
||||
class menu : public node {
|
||||
public:
|
||||
template<typename ... Args>
|
||||
explicit menu(Args ... ns) : node(ns...) {
|
||||
}
|
||||
|
||||
void render(canvas &c) override;
|
||||
|
||||
};
|
||||
|
||||
class fooValue : public value {
|
||||
public:
|
||||
fooValue(const char* str, int val) : value(str, val, 32, 48) {
|
||||
}
|
||||
public:
|
||||
fooValue(const char *str, int val) : value(str, val, 32, 48) {
|
||||
}
|
||||
|
||||
void render(canvas &c);
|
||||
void render(canvas &c) override;
|
||||
};
|
||||
|
||||
class blubValue : public value{
|
||||
public:
|
||||
template<typename ... Args>
|
||||
blubValue(Args ... ns) : value(ns..., 64, 96) {
|
||||
}
|
||||
void render(canvas& c);
|
||||
class blubValue : public value {
|
||||
public:
|
||||
template<typename ... Args>
|
||||
explicit blubValue(Args ... ns) : value(ns..., 64, 96) {
|
||||
}
|
||||
|
||||
void render(canvas &c) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
// Created by jedi on 11/2/18.
|
||||
//
|
||||
|
||||
#ifndef MGL_DMXMENU_BASIC_5X4_H
|
||||
#define MGL_DMXMENU_BASIC_5X4_H
|
||||
#pragma once
|
||||
|
||||
#include "gfx/font.h"
|
||||
#include "gfx/Font.h"
|
||||
|
||||
extern font basic_5x4;
|
||||
namespace micromenu {
|
||||
extern Font basic_5x4;
|
||||
}
|
||||
|
||||
#endif //MGL_DMXMENU_BASIC_5X4_H
|
||||
|
|
54
inc/gfx/Buffer.h
Normal file
54
inc/gfx/Buffer.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// Created by jedi on 11/2/18.
|
||||
//
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
|
||||
namespace micromenu {
|
||||
|
||||
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_);
|
||||
}
|
||||
|
||||
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_));
|
||||
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);
|
||||
|
||||
}
|
42
inc/gfx/Canvas.h
Normal file
42
inc/gfx/Canvas.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// Created by jedi on 11/1/18.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/hal.h"
|
||||
#include "gfx/Font.h"
|
||||
#include "fonts/basic_5x4.h"
|
||||
#include "gfx/Buffer.h"
|
||||
|
||||
namespace micromenu {
|
||||
|
||||
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, bool inv = false);
|
||||
|
||||
void print(int x, int y, const char *str, bool inv = false, Font & = basic_5x4);
|
||||
|
||||
void print(int x, int y, char *str, bool inv = false, Font & = basic_5x4);
|
||||
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
|
||||
friend Screen;
|
||||
};
|
||||
|
||||
}
|
27
inc/gfx/Font.h
Normal file
27
inc/gfx/Font.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// Created by jedi on 11/1/18.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace micromenu {
|
||||
|
||||
class Canvas;
|
||||
|
||||
class Font {
|
||||
public:
|
||||
typedef const bool raw_font[32][20];
|
||||
private:
|
||||
raw_font &raw_data_;
|
||||
public:
|
||||
explicit Font(raw_font &) noexcept;
|
||||
|
||||
void print(int x, int y, char c, Canvas &, bool inv = false);
|
||||
|
||||
void print(int x, int y, char *str, Canvas &, bool inv = false);
|
||||
|
||||
void print(int x, int y, const char *str, Canvas &, bool inv = false);
|
||||
};
|
||||
|
||||
}
|
||||
|
49
inc/gfx/Layout.h
Normal file
49
inc/gfx/Layout.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// Created by jedi on 11/5/18.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gfx/Canvas.h"
|
||||
#include "gfx/Screen.h"
|
||||
|
||||
namespace micromenu {
|
||||
|
||||
class Layout {
|
||||
class Slot {
|
||||
private:
|
||||
int pos_ = 0;
|
||||
int size_ = 0;
|
||||
Canvas *canvas_ = nullptr;
|
||||
public:
|
||||
node *content = nullptr;
|
||||
friend Layout;
|
||||
};
|
||||
|
||||
private:
|
||||
const int maxwidth_;
|
||||
const int maxheight_;
|
||||
int allocated_ = 0;
|
||||
Screen &screen_;
|
||||
|
||||
int allocate_(node *, int);
|
||||
|
||||
int expand_(int);
|
||||
|
||||
int pack_(int);
|
||||
|
||||
public:
|
||||
static const int maxslots = 10;
|
||||
Slot slots[maxslots];
|
||||
node *cursor = nullptr;
|
||||
|
||||
explicit Layout(Screen &s) noexcept: maxwidth_(s.getWidth()), maxheight_(s.getHeight()), screen_(s) {
|
||||
|
||||
}
|
||||
|
||||
int apply(node *);
|
||||
|
||||
void render();
|
||||
};
|
||||
|
||||
}
|
38
inc/gfx/Screen.h
Normal file
38
inc/gfx/Screen.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// Created by jedi on 11/1/18.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/hal.h"
|
||||
#include "gfx/Canvas.h"
|
||||
|
||||
namespace micromenu {
|
||||
|
||||
class Screen {
|
||||
private:
|
||||
const int width_;
|
||||
const int height_;
|
||||
|
||||
public:
|
||||
explicit Screen(int w, int h) noexcept;
|
||||
|
||||
void draw(int x, int y);
|
||||
|
||||
void draw(int x, int y, Canvas &c);
|
||||
|
||||
void print(int x, int y, const char *str, Font & = basic_5x4);
|
||||
|
||||
void print(int x, int y, char *str, Font & = basic_5x4);
|
||||
|
||||
[[nodiscard]] int getWidth() const{
|
||||
return width_;
|
||||
}
|
||||
|
||||
[[nodiscard]] int getHeight() const{
|
||||
return height_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
//
|
||||
// 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_);
|
||||
}
|
||||
|
||||
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_));
|
||||
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
|
|
@ -1,42 +0,0 @@
|
|||
//
|
||||
// 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"
|
||||
|
||||
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, bool inv = false);
|
||||
|
||||
void print(int x, int y, const char *str, bool inv = 0, font & = basic_5x4);
|
||||
|
||||
void print(int x, int y, char *str, bool inv = 0, font & = basic_5x4);
|
||||
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
|
||||
friend screen;
|
||||
};
|
||||
|
||||
|
||||
#endif //MGL_DMXMENU_CANVAS_H
|
|
@ -1,22 +0,0 @@
|
|||
//
|
||||
// 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&, 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
|
|
@ -1,51 +0,0 @@
|
|||
//
|
||||
// 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_ = 0;
|
||||
int size_ = 0;
|
||||
canvas *canvas_ = nullptr;
|
||||
public:
|
||||
node *content = nullptr;
|
||||
friend layout;
|
||||
};
|
||||
|
||||
private:
|
||||
const int maxwidth_;
|
||||
const int maxheight_;
|
||||
int allocated_;
|
||||
screen& screen_;
|
||||
|
||||
int allocate_(node *, int);
|
||||
|
||||
int expand_(int);
|
||||
|
||||
int pack_(int);
|
||||
|
||||
|
||||
public:
|
||||
static const int maxslots = 10;
|
||||
Slot slots[maxslots];
|
||||
node *cursor;
|
||||
|
||||
layout(screen& s) : maxwidth_(s.getWidth()), maxheight_(s.getHeight()), screen_(s) {
|
||||
|
||||
}
|
||||
|
||||
int apply(node *);
|
||||
|
||||
void render();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //MGL_DMXMENU_LAYOUT_H
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// 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);
|
||||
|
||||
void draw(int x, int y);
|
||||
|
||||
void draw(int x, int y, canvas &c);
|
||||
|
||||
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();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //MGL_DMXMENU_SCREEN_H
|
122
inc/node.h
122
inc/node.h
|
@ -2,82 +2,84 @@
|
|||
// Created by jedi on 11/5/18.
|
||||
//
|
||||
|
||||
#ifndef MGL_DMXMENU_NODE_H
|
||||
#define MGL_DMXMENU_NODE_H
|
||||
#pragma once
|
||||
|
||||
#include "gfx/canvas.h"
|
||||
#include "gfx/Canvas.h"
|
||||
|
||||
class node {
|
||||
private:
|
||||
node *parent_ = nullptr;
|
||||
node *child_ = nullptr;
|
||||
node *cursor_ = nullptr;
|
||||
node *next_ = nullptr;
|
||||
namespace micromenu {
|
||||
|
||||
void addNodes(bool b) {
|
||||
}
|
||||
class node {
|
||||
private:
|
||||
node *parent_ = nullptr;
|
||||
node *child_ = nullptr;
|
||||
node *cursor_ = nullptr;
|
||||
node *next_ = nullptr;
|
||||
|
||||
template<class ...Us>
|
||||
void addNodes(bool b, node *n, Us ... ns) {
|
||||
next_ = n;
|
||||
next_->parent_ = parent_;
|
||||
next_->addNodes(!b, ns...);
|
||||
}
|
||||
void addNodes(bool b) {
|
||||
}
|
||||
|
||||
public:
|
||||
const char *title_ = 0;
|
||||
const int minsize;
|
||||
const int maxsize;
|
||||
template<class ...Us>
|
||||
void addNodes(bool b, node *n, Us ... ns) {
|
||||
next_ = n;
|
||||
next_->parent_ = parent_;
|
||||
next_->addNodes(!b, ns...);
|
||||
}
|
||||
|
||||
virtual void render(canvas &c) = 0;
|
||||
public:
|
||||
const char *title_ = 0;
|
||||
const int minsize;
|
||||
const int maxsize;
|
||||
|
||||
explicit node(int min = 24, int max = 48) : next_(nullptr), child_(nullptr), parent_(nullptr), minsize(min),
|
||||
maxsize(max) {
|
||||
}
|
||||
virtual void render(Canvas &c) = 0;
|
||||
|
||||
explicit node(const char *t, int min = 24, int max = 48) : title_(t), minsize(min), maxsize(max), next_(nullptr),
|
||||
child_(nullptr),
|
||||
parent_(nullptr) {
|
||||
}
|
||||
explicit node(int min = 24, int max = 48) : next_(nullptr), child_(nullptr), parent_(nullptr), minsize(min),
|
||||
maxsize(max) {
|
||||
}
|
||||
|
||||
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...);
|
||||
}
|
||||
explicit node(const char *t, int min = 24, int max = 48) : title_(t), minsize(min), maxsize(max),
|
||||
next_(nullptr),
|
||||
child_(nullptr),
|
||||
parent_(nullptr) {
|
||||
}
|
||||
|
||||
node *getChild() {
|
||||
return child_;
|
||||
}
|
||||
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...);
|
||||
}
|
||||
|
||||
node *getNext() {
|
||||
return next_;
|
||||
}
|
||||
node *getChild() {
|
||||
return child_;
|
||||
}
|
||||
|
||||
node *getCursor() {
|
||||
return cursor_;
|
||||
}
|
||||
node *getNext() {
|
||||
return next_;
|
||||
}
|
||||
|
||||
node *getParent() {
|
||||
return parent_;
|
||||
}
|
||||
node *getCursor() {
|
||||
return cursor_;
|
||||
}
|
||||
|
||||
void setCursor(node *c) {
|
||||
cursor_ = c;
|
||||
}
|
||||
};
|
||||
node *getParent() {
|
||||
return parent_;
|
||||
}
|
||||
|
||||
void setCursor(node *c) {
|
||||
cursor_ = c;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class value: public node {
|
||||
public:
|
||||
const char *header;
|
||||
int state;
|
||||
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) {
|
||||
}
|
||||
};
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue