-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.h
More file actions
72 lines (50 loc) · 1.73 KB
/
Copy pathColor.h
File metadata and controls
72 lines (50 loc) · 1.73 KB
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
//
// Created by Leon Boshuizen on 10/11/2021.
//
#ifndef TOUCHCONTROLLER_COLOR_H
#define TOUCHCONTROLLER_COLOR_H
#include "stdint.h"
class Point{
private:
uint16_t _x,_y;
public:
Point(uint16_t x, uint16_t y): _x(x), _y(y){}
[[nodiscard]] Point flip() const{ return {_y,_x}; }
[[nodiscard]] inline uint16_t X() const { return _x;};
[[nodiscard]] inline uint16_t Y() const { return _y;};
[[nodiscard]] Point shiftx(uint16_t x) const { return shift(x,0); }
[[nodiscard]] Point shifty(uint16_t y) const { return shift(0,y); }
[[nodiscard]] Point shift(uint16_t x, uint16_t y) const {return Point(_x+x,_y+y); }
};
class Rect {
public:
Rect(const Point &tl, const Point& br): TL(tl), BR(br){};
Rect(const Point &tl, uint16_t w, uint16_t h): TL(tl), BR(Point(tl.X() + w, tl.Y() + h)){};
const Point &TL;
const Point BR;
[[nodiscard]] inline bool covers(const Point& p) const { return p.X() >= TL.X() && p.X() <= BR.X() && p.Y() >= TL.Y() && p.Y() <= BR.Y(); }
};
class Color {
private:
uint8_t red;
uint8_t green;
uint8_t blue;
[[nodiscard]] static inline uint8_t mult(uint8_t c, float f) { return (uint8_t) ((float) c * f); }
public:
Color(uint8_t r, uint8_t g, uint8_t b): red(r), blue(b), green(g){}
Color(const Color& c){
red = c.red;
blue = c.blue;
green = c.green;
}
[[nodiscard]] Color dim(float f) const {
return {mult(red,f), mult(green,f), mult(blue,f) };
}
explicit operator uint16_t() const {return (red & 0x1f) << 11 | (green & 0x3f) << 5 | (blue & 0x1f); }
};
extern const Color Black;
extern const Color White;
extern const Color Red;
extern const Color Green;
extern const Color Blue;
#endif //TOUCHCONTROLLER_COLOR_H