Skip to content

Commit 0658dd2

Browse files
author
Martin Klang
committed
templated colours
1 parent d13df72 commit 0658dd2

6 files changed

Lines changed: 30 additions & 68 deletions

File tree

LibSource/ColourScreenPatch.cpp

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
#include "PatchProcessor.h"
77
#include "ServiceCall.h"
88

9-
#include "font.c" // todo load as resource
10-
119
PatchProcessor* getInitialisingPatchProcessor();
1210

13-
void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
11+
static void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
1412
ColourScreenPatch* patch = (ColourScreenPatch*)getInitialisingPatchProcessor()->patch;
1513
if(patch != NULL){
1614
ColourScreenBuffer screen(width, height);
@@ -26,56 +24,36 @@ ColourScreenPatch::ColourScreenPatch(){
2624

2725
ColourScreenPatch::~ColourScreenPatch(){}
2826

29-
void drawMessage(ColourScreenBuffer& screen){
30-
ProgramVector* pv = getProgramVector();
31-
if(pv->message != NULL){
32-
screen.setTextSize(1);
33-
screen.setTextWrap(true);
34-
screen.print(0, 26, pv->message);
35-
}
36-
}
37-
void drawTitle(const char* title, ColourScreenBuffer& screen){
38-
// draw title
39-
screen.setTextSize(2);
40-
screen.print(0, 16, title);
41-
}
42-
43-
void ColourScreenPatch::processScreen(ColourScreenBuffer& screen){
44-
// screen.clear();
45-
const char* title = getInitialisingPatchProcessor()->getPatchName();
46-
drawTitle(title, screen);
47-
drawMessage(screen);
48-
// const char title[] = "KickBox";
49-
// screen.setTextSize(2);
50-
// screen.print(0, 16, title);
51-
}
52-
53-
54-
Colour ScreenBuffer::getPixel(unsigned int x, unsigned int y){
27+
template<>
28+
Colour ColourScreenBuffer::getPixel(unsigned int x, unsigned int y){
5529
if(x >= width || y >= height)
5630
return 0;
5731
return pixels[y*width+x];
5832
}
5933

60-
void ScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
34+
template<>
35+
void ColourScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
6136
if(x < width && y < height)
6237
pixels[y*width+x] = c;
6338
}
6439

65-
void ScreenBuffer::invertPixel(unsigned int x, unsigned int y){
40+
template<>
41+
void ColourScreenBuffer::invertPixel(unsigned int x, unsigned int y){
6642
if(x < width && y < height)
6743
pixels[y*width+x] ^= WHITE;
6844
}
6945

70-
void ScreenBuffer::fade(uint16_t steps){
46+
template<>
47+
void ColourScreenBuffer::fade(uint16_t steps){
7148
for(int i=0; i<height*width; ++i)
7249
pixels[i] =
7350
(((pixels[i] & RED) >> steps) & RED) |
7451
(((pixels[i] & GREEN) >> steps) & GREEN) |
7552
(((pixels[i] & BLUE) >> steps) & BLUE);
7653
}
7754

78-
void ScreenBuffer::fill(Colour c) {
55+
template<>
56+
void ColourScreenBuffer::fill(Colour c) {
7957
for(int i=0; i<height*width; ++i)
8058
pixels[i] = c;
8159
}

LibSource/ColourScreenPatch.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
#include "Patch.h"
22
#include "ScreenBuffer.h"
33

4+
#define BLACK 0x0000
5+
#define BLUE 0x001F
6+
#define RED 0xF800
7+
#define GREEN 0x07E0
8+
#define CYAN 0x07FF
9+
#define MAGENTA 0xF81F
10+
#define YELLOW 0xFFE0
11+
#define WHITE 0xFFFF
12+
413
typedef uint16_t Colour;
5-
typedef ScreenBuffer<uint16_t> ColourScreenBuffer;
14+
typedef ScreenBuffer<uint16_t, BLACK, WHITE> ColourScreenBuffer;
615

716
class ColourScreenPatch : public Patch {
817
public:
918
ColourScreenPatch();
1019
virtual ~ColourScreenPatch();
1120
uint16_t getScreenWidth();
1221
uint16_t getScreenHeight();
13-
virtual void processScreen(ColourScreenBuffer& screen);
22+
virtual void processScreen(ColourScreenBuffer& screen) = 0;
1423
};

LibSource/MonochromeScreenPatch.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
PatchProcessor* getInitialisingPatchProcessor();
1212

13-
void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
13+
static void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
1414
MonochromeScreenPatch* patch = (MonochromeScreenPatch*)getInitialisingPatchProcessor()->patch;
1515
if(patch != NULL){
1616
MonochromeScreenBuffer screen(width, height);
@@ -26,31 +26,6 @@ MonochromeScreenPatch::MonochromeScreenPatch(){
2626

2727
MonochromeScreenPatch::~MonochromeScreenPatch(){}
2828

29-
void drawMessage(MonochromeScreenBuffer& screen){
30-
ProgramVector* pv = getProgramVector();
31-
if(pv->message != NULL){
32-
screen.setTextSize(1);
33-
screen.setTextWrap(true);
34-
screen.print(0, 26, pv->message);
35-
}
36-
}
37-
void drawTitle(const char* title, MonochromeScreenBuffer& screen){
38-
// draw title
39-
screen.setTextSize(2);
40-
screen.print(0, 16, title);
41-
}
42-
43-
void MonochromeScreenPatch::processScreen(MonochromeScreenBuffer& screen){
44-
// screen.clear();
45-
const char* title = getInitialisingPatchProcessor()->getPatchName();
46-
drawTitle(title, screen);
47-
drawMessage(screen);
48-
// const char title[] = "KickBox";
49-
// screen.setTextSize(2);
50-
// screen.print(0, 16, title);
51-
}
52-
53-
5429
template<>
5530
Colour MonochromeScreenBuffer::getPixel(unsigned int x, unsigned int y){
5631
if(x >= width || y >= height)

LibSource/MonochromeScreenPatch.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#include "Patch.h"
22
#include "ScreenBuffer.h"
33

4+
#define BLACK 0
5+
#define WHITE 1
6+
47
typedef uint8_t Colour;
5-
typedef ScreenBuffer<uint8_t> MonochromeScreenBuffer;
8+
typedef ScreenBuffer<uint8_t, BLACK, WHITE> MonochromeScreenBuffer;
69

710
class MonochromeScreenPatch : public Patch {
811
public:
912
MonochromeScreenPatch();
1013
virtual ~MonochromeScreenPatch();
1114
uint16_t getScreenWidth();
1215
uint16_t getScreenHeight();
13-
virtual void processScreen(MonochromeScreenBuffer& screen);
16+
virtual void processScreen(MonochromeScreenBuffer& screen) = 0;
1417
};

LibSource/ScreenBuffer.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#include "device.h"
66
#include "message.h"
77

8-
#define BLACK 0
9-
#define WHITE 1
10-
118
#define swap(a, b) { int16_t t = a; a = b; b = t; }
129
#ifndef min
1310
#define min(a,b) ((a)<(b)?(a):(b))
@@ -19,7 +16,7 @@
1916
#define abs(x) ((x)>0?(x):-(x))
2017
#endif
2118

22-
template<typename Colour>
19+
template<typename Colour, Colour BLACK, Colour WHITE>
2320
class ScreenBuffer {
2421
private:
2522
const uint16_t width;

compile.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CPP_SRC += SmoothValue.cpp PatchParameter.cpp
1111
CPP_SRC += PatchProgram.cpp
1212
# CPP_SRC += ShortPatchProgram.cpp
1313
# CPP_SRC += ScreenBuffer.cpp ScreenBufferDevice.cpp
14-
CPP_SRC += MonochromeScreenPatch.cpp
14+
CPP_SRC += MonochromeScreenPatch.cpp ColourScreenPatch.cpp
1515

1616
SOURCE = $(BUILDROOT)/Source
1717
LIBSOURCE = $(BUILDROOT)/LibSource

0 commit comments

Comments
 (0)