aboutsummaryrefslogtreecommitdiff
path: root/screenbuffer.h
blob: a461145f86ae49f59dd6784a4403040d7f77a8e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once

#include <cstdarg>

using namespace std;


class ScreenBuffer{
	struct Style{
		int fg=9,bg=9;
	};

	struct Cell{
		char c=' ';
		Style style;
	};

	int W,H;
	Cell *prevscreen,*screen;
	int curx=0,cury=0;
	Style curstyle;

	void printstr(const char *buf);
	int printf_varargs(const char *format,va_list ap);

	friend bool operator!=(const ScreenBuffer::Style &a,const ScreenBuffer::Style &b);
	friend bool operator!=(const ScreenBuffer::Cell &a,const ScreenBuffer::Cell &b);

public:
	ScreenBuffer(int W,int H);
	~ScreenBuffer();

	void moveto(int x,int y);
	int printf(const char *format,...) __attribute__((format (printf, 2, 3)));
	int mvprintf(int x,int y,const char *format,...) __attribute__((format (printf, 4, 5)));

	void setfg(int fg);
	void setbg(int bg);

	void draw();

	void emergencyDeinit();
};