Skip to content

Commit d13df72

Browse files
author
Martin Klang
committed
added ColourScreenPatch
1 parent 3e6851c commit d13df72

6 files changed

Lines changed: 300 additions & 275 deletions

File tree

LibSource/ColourScreenPatch.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <cstddef>
2+
#include <string.h>
3+
#include "device.h"
4+
#include "ColourScreenPatch.h"
5+
#include "ProgramVector.h"
6+
#include "PatchProcessor.h"
7+
#include "ServiceCall.h"
8+
9+
#include "font.c" // todo load as resource
10+
11+
PatchProcessor* getInitialisingPatchProcessor();
12+
13+
void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
14+
ColourScreenPatch* patch = (ColourScreenPatch*)getInitialisingPatchProcessor()->patch;
15+
if(patch != NULL){
16+
ColourScreenBuffer screen(width, height);
17+
screen.setBuffer(pixels);
18+
patch->processScreen(screen);
19+
}
20+
}
21+
22+
ColourScreenPatch::ColourScreenPatch(){
23+
void* drawArgs[] = {(void*)SYSTEM_FUNCTION_DRAW, (void*)&onDrawCallback};
24+
getProgramVector()->serviceCall(OWL_SERVICE_REGISTER_CALLBACK, drawArgs, 2);
25+
}
26+
27+
ColourScreenPatch::~ColourScreenPatch(){}
28+
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){
55+
if(x >= width || y >= height)
56+
return 0;
57+
return pixels[y*width+x];
58+
}
59+
60+
void ScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
61+
if(x < width && y < height)
62+
pixels[y*width+x] = c;
63+
}
64+
65+
void ScreenBuffer::invertPixel(unsigned int x, unsigned int y){
66+
if(x < width && y < height)
67+
pixels[y*width+x] ^= WHITE;
68+
}
69+
70+
void ScreenBuffer::fade(uint16_t steps){
71+
for(int i=0; i<height*width; ++i)
72+
pixels[i] =
73+
(((pixels[i] & RED) >> steps) & RED) |
74+
(((pixels[i] & GREEN) >> steps) & GREEN) |
75+
(((pixels[i] & BLUE) >> steps) & BLUE);
76+
}
77+
78+
void ScreenBuffer::fill(Colour c) {
79+
for(int i=0; i<height*width; ++i)
80+
pixels[i] = c;
81+
}
82+

LibSource/ColourScreenPatch.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "Patch.h"
2+
#include "ScreenBuffer.h"
3+
4+
typedef uint16_t Colour;
5+
typedef ScreenBuffer<uint16_t> ColourScreenBuffer;
6+
7+
class ColourScreenPatch : public Patch {
8+
public:
9+
ColourScreenPatch();
10+
virtual ~ColourScreenPatch();
11+
uint16_t getScreenWidth();
12+
uint16_t getScreenHeight();
13+
virtual void processScreen(ColourScreenBuffer& screen);
14+
};

LibSource/MonochromeScreenBuffer.h

Lines changed: 0 additions & 76 deletions
This file was deleted.

LibSource/MonochromeScreenPatch.cpp

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -119,76 +119,3 @@ void MonochromeScreenBuffer::fill(Colour c) {
119119
// for(unsigned int i=0; i<height*width; ++i)
120120
// pixels[i] = c;
121121
}
122-
123-
// Draw a character
124-
template<typename Colour>
125-
void ScreenBuffer<Colour>::drawChar(uint16_t x, uint16_t y, unsigned char ch,
126-
Colour c, Colour bg, uint8_t size) {
127-
// if((x >= width) || // Clip right
128-
// (y >= height) || // Clip bottom
129-
// ((x + 6 * size - 1) < 0) || // Clip left
130-
// ((y + 8 * size - 1) < 0)) // Clip top
131-
// return;
132-
y -= 8 * size; // set origin to bottom left
133-
for(int8_t i=0; i<6; i++ ) {
134-
uint8_t line;
135-
if (i == 5)
136-
line = 0x0;
137-
else
138-
line = font[(ch*5)+i];
139-
for (int8_t j = 0; j<8; j++) {
140-
if (line & 0x1) {
141-
if (size == 1) // default size
142-
setPixel(x+i, y+j, c);
143-
else { // big size
144-
fillRectangle(x+(i*size), y+(j*size), size, size, c);
145-
}
146-
} else if (bg != c) {
147-
if (size == 1) // default size
148-
setPixel(x+i, y+j, bg);
149-
else { // big size
150-
fillRectangle(x+i*size, y+j*size, size, size, bg);
151-
}
152-
}
153-
line >>= 1;
154-
}
155-
}
156-
}
157-
158-
// Draw a character rotated 90 degrees
159-
template<typename Colour>
160-
void ScreenBuffer<Colour>::drawRotatedChar(uint16_t x, uint16_t y, unsigned char ch,
161-
Colour c, Colour bg, uint8_t size) {
162-
// if((x >= width) || // Clip right
163-
// (y >= height) || // Clip bottom
164-
// ((x + 8 * size - 1) < 0) || // Clip left
165-
// ((y + 6 * size - 1) < 0)) // Clip top
166-
// return;
167-
// for (int8_t i=5; i>=0; i-- ) {
168-
for (int8_t i=0; i<6; i++ ) {
169-
uint8_t line;
170-
if (i == 5)
171-
line = 0x0;
172-
else
173-
line = font[(ch*5)+i];
174-
// for (int8_t j = 0; j<8; j++) {
175-
for (int8_t j = 7; j>=0; j--) {
176-
if (line & 0x1) {
177-
if (size == 1) // default size
178-
setPixel(y+i, x+j, c);
179-
else { // big size
180-
// fillRectangle(x+(i*size), y+(j*size), size, size, c);
181-
fillRectangle(y+(j*size), x+(i*size), size, size, c);
182-
}
183-
} else if (bg != c) {
184-
if (size == 1) // default size
185-
setPixel(y+i, x+j, bg);
186-
else { // big size
187-
// fillRectangle(x+i*size, y+j*size, size, size, bg);
188-
fillRectangle(y+j*size, x+i*size, size, size, bg);
189-
}
190-
}
191-
line >>= 1;
192-
}
193-
}
194-
}

LibSource/MonochromeScreenPatch.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "Patch.h"
2-
#include "MonochromeScreenBuffer.h"
2+
#include "ScreenBuffer.h"
3+
4+
typedef uint8_t Colour;
5+
typedef ScreenBuffer<uint8_t> MonochromeScreenBuffer;
36

47
class MonochromeScreenPatch : public Patch {
58
public:

0 commit comments

Comments
 (0)