add dynamic buffers

This commit is contained in:
j3d1 2018-11-05 10:53:59 +01:00
parent 3f3c40a9b1
commit d958452e48
14 changed files with 176 additions and 67 deletions

View file

@ -2,10 +2,13 @@
#ifndef _COL_H_
#define _COL_H_
class Node;
typedef void (*drawfun_t)(int offset, int size, Node*);
class canvas;
#include "gfx/canvas.h"
void draw_menu(int, int, Node*);
class Node;
typedef void (*drawfun_t)(int offset, int size, Node*, canvas& c);
void draw_menu(int, int, Node*, canvas& c);
class Drawable{
public:

View file

@ -2,8 +2,10 @@
#ifndef _EXAMPLE_H_
#define _EXAMPLE_H_
void draw_foo(int offset, int size, Node* ptr);
#include "gfx/canvas.h"
void draw_blub(int offset, int size, Node* ptr);
void draw_foo(int offset, int size, Node* ptr, canvas& c);
void draw_blub(int offset, int size, Node* ptr, canvas& c);
#endif

40
inc/gfx/buffer_1.h Normal file
View file

@ -0,0 +1,40 @@
//
// 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>
class buffer_1 {
private:
int *ptr_;
int size_;
constexpr static const int block_ = 8 * sizeof(int);
public:
buffer_1(int size) : size_(size) {
ptr_ = (int *) malloc(size * sizeof(int));
}
bool get(int i) {
if (i >= size_) return 0;
return ptr_[i/block_] & 1 << (i%block_);
}
void set(int i, bool v) {
if (i < size_) {
ptr_[i/block_] &= ~(1 << (i%block_));
ptr_[i/block_] |= v << (i%block_);
}
}
~buffer_1() {
free(ptr_);
}
};
#endif //MGL_DMXMENU_BUFFER_1_H

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

@ -0,0 +1,37 @@
//
// 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>
class buffer_32 {
private:
int size_;
void *ptr;
public:
buffer_32(int size) : size_(size) {
ptr = (uint8_t *) malloc(size * 4);
}
bool get(int i) {
if (i >= size_) return 0;
return ((int *) ptr)[i];
}
void set(int i, bool v) {
if (i < size_)
((int *) ptr)[i] = v;
}
~buffer_32() {
free(ptr);
}
};
#endif //MGL_DMXMENU_BUFFER_8_H

View file

@ -8,19 +8,31 @@
#include "hal.h"
#include "gfx/font.h"
#include "fonts/basic_5x4.h"
#include "gfx/buffer_1.h"
#include "gfx/buffer_32.h"
class screen;
class canvas {
private:
const int width_;
const int height_;
buffer_1 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, const char *str, font & = basic_5x4);
void print(int x, int y, char *str, font& = basic_5x4);
void print(int x, int y, char *str, font & = basic_5x4);
friend screen;
};

View file

@ -7,7 +7,6 @@
#include "hal.h"
//template <int WIDTH, int HEIGHT>
class screen {
private:
const int width_;
@ -22,6 +21,13 @@ public:
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, char* str){
}

View file

@ -2,6 +2,7 @@
#ifndef _HAL_H_
#define _HAL_H_
class Layout;
#include "col.h"
#define I_LEFT 0