-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.h
90 lines (64 loc) · 2.28 KB
/
graphics.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef __GRAPHICS_H
#define __GRAPHICS_H
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>
#define charHeight(header) (header >> 4)
#define bytesPerChar(header) (header & 0b1111)
#define charIndex(chr, bytesPerChar) (1 + ((chr - 32) * bytesPerChar))
#define charWidth(charData) (charData >> 4)
#define charPixelIndex(x, y, charWidth) ((y * charWidth + x) + 4)
#define charPixelByteIndex(charIndex, charPixelIndex) (charIndex + charPixelIndex / 8)
#define charPixel(charByte, charPixelIndex) (charByte >> (7 - charPixelIndex % 8) & 0b1)
#define spriteX(i) (i >> 4)
#define spriteY(i) (i & 0b1111)
typedef void (*canvas) (int8_t x, int8_t y, uint8_t r, uint8_t g, uint8_t b);
typedef uint8_t (*fontDataReader) (uint8_t* addr);
typedef uint8_t (*spriteDataReader) (uint8_t* addr);
void transitionColor(
uint8_t r1, uint8_t g1, uint8_t b1,
uint8_t r2, uint8_t g2, uint8_t b2,
float percents, uint8_t* storage);
void pulsateColor(
uint8_t r1, uint8_t g1, uint8_t b1,
uint8_t r2, uint8_t g2, uint8_t b2,
float percents, uint8_t* storage);
void drawChar(canvas canvas, unsigned char c, int8_t x, int8_t y,
fontDataReader fontDataReader, const uint8_t* font, uint8_t* color);
void drawSprite(canvas canvas, const uint8_t palette[][3], spriteDataReader spriteDataReader, uint8_t* sprite, int8_t x, int8_t y);
void hsv2rgb(double H, double S, double V, uint8_t* output);
void clearCanvas(canvas canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
class ScrollText {
public:
ScrollText(uint8_t x, uint8_t y, uint8_t width, fontDataReader fontDataReader, uint8_t* font);
void setClearBackground(bool clearBackground);
void setText(const char* text);
void draw(canvas canvas, uint8_t * color);
bool scroll();
private:
uint8_t _x;
uint8_t _y;
uint8_t _width;
fontDataReader _fontDataReader;
uint8_t* _font;
uint8_t _charHeight;
uint8_t _bytesPerChar;
bool _clearBackground;
const char* _text;
uint16_t _textLength;
uint16_t _position;
int8_t _offset;
};
class Animation {
public:
const uint8_t frameCount;
Animation(uint8_t frameCount);
void setFrame(uint8_t idx, unsigned long duration, uint8_t* sprite);
unsigned long getDuration(uint8_t idx);
uint8_t* getSprite(uint8_t idx);
private:
unsigned long* _durations;
uint8_t** _sprites;
};
#endif