Add a flag for inversing the intensity in char drawings.

Change-Id: Ibc22dd8aeaf95ef0aa49d2f9aa8867c47324ce80
This commit is contained in:
Felix Raimundo
2016-03-25 14:34:29 +01:00
parent c56c506b19
commit e0184ba975
7 changed files with 21 additions and 22 deletions

View File

@@ -73,7 +73,7 @@ static void interactive_expression_parsing() {
}
delete e;
} else {
KDDrawString("PARSING ERROR", KDPointMake(10,10));
KDDrawString("PARSING ERROR", KDPointMake(10,10), 0);
}
// We dealocate the memory allocated by get_text;
free(text_input);

View File

@@ -30,8 +30,8 @@ static void print_prompt(char* text, int index) {
KDSize font_size = KDStringSize(tmp);
KDDrawLine(KDPointMake(0, SCREEN_HEIGHT - PROMPT_HEIGHT),
KDPointMake(SCREEN_WIDTH, SCREEN_HEIGHT - PROMPT_HEIGHT), 0xff);
KDDrawString(text, KDPointMake(0, SCREEN_HEIGHT - (PROMPT_HEIGHT / 2)));
KDDrawInverseChar(text[index], KDPointMake(index * font_size.width, SCREEN_HEIGHT - (PROMPT_HEIGHT / 2)));
KDDrawString(text, KDPointMake(0, SCREEN_HEIGHT - (PROMPT_HEIGHT / 2)), 0);
KDDrawChar(text[index], KDPointMake(index * font_size.width, SCREEN_HEIGHT - (PROMPT_HEIGHT / 2)), true);
}
char* get_text() {

View File

@@ -3,9 +3,8 @@
#include <kandinsky/types.h>
void KDDrawChar(char character, KDPoint p);
void KDDrawInverseChar(char character, KDPoint p);
void KDDrawString(const char * text, KDPoint p);
void KDDrawChar(char character, KDPoint p, uint8_t inverse);
void KDDrawString(const char * text, KDPoint p, uint8_t inverse);
KDSize KDStringSize(char * text);
#endif

View File

@@ -3,26 +3,21 @@
#include <string.h>
#include "font.h"
void KDDrawChar(char character, KDPoint p) {
void KDDrawChar(char character, KDPoint p, uint8_t inverse) {
for (int j=0; j<BITMAP_FONT_CHARACTER_HEIGHT;j++) {
for (int i=0; i<BITMAP_FONT_CHARACTER_WIDTH;i++) {
KDSetPixel(KDPointMake(p.x+i, p.y+j), 0xFF-bitmapFont[character-BITMAP_FONT_FIRST_CHARACTER][j][i]);
uint8_t intensity = inverse ?
bitmapFont[character-BITMAP_FONT_FIRST_CHARACTER][j][i] :
(0xFF-bitmapFont[character-BITMAP_FONT_FIRST_CHARACTER][j][i]);
KDSetPixel(KDPointMake(p.x+i, p.y+j), intensity);
}
}
}
void KDDrawInverseChar(char character, KDPoint p) {
for (int j=0; j<BITMAP_FONT_CHARACTER_HEIGHT;j++) {
for (int i=0; i<BITMAP_FONT_CHARACTER_WIDTH;i++) {
KDSetPixel(KDPointMake(p.x+i, p.y+j), bitmapFont[character-BITMAP_FONT_FIRST_CHARACTER][j][i]);
}
}
}
void KDDrawString(const char * text, KDPoint p) {
void KDDrawString(const char * text, KDPoint p, uint8_t inverse) {
KDPoint position = p;
while(*text != 0) {
KDDrawChar(*text, position);
KDDrawChar(*text, position, inverse);
text++;
position.x += BITMAP_FONT_CHARACTER_WIDTH;
}

View File

@@ -2,11 +2,12 @@
#include <stdlib.h>
#include "string_layout.h"
StringLayout::StringLayout(const char * string, size_t length) :
StringLayout::StringLayout(const char * string, size_t length, uint8_t inverse) :
ExpressionLayout() {
assert(string[length] == 0); // Assert NULL-termination
m_string = (char *)malloc(sizeof(char)*(length+1));
memcpy(m_string, string, (length+1));
m_inverse = inverse;
}
StringLayout::~StringLayout() {
@@ -18,7 +19,7 @@ ExpressionLayout * StringLayout::child(uint16_t index) {
}
void StringLayout::render(KDPoint point) {
KDDrawString(m_string, point);
KDDrawString(m_string, point, m_inverse);
}
KDPoint StringLayout::positionOfChild(ExpressionLayout * child) {

View File

@@ -6,7 +6,10 @@
class StringLayout : public ExpressionLayout {
public:
StringLayout(const char * string, size_t length);
// Here the inverse is a uint8_t instead of a bool, because the size of a bool is
// not standardized, thus since we call a foreign C function with this value we want to be
// sure about compatibility.
StringLayout(const char * string, size_t length, uint8_t inverse=0);
~StringLayout();
protected:
void render(KDPoint point) override;
@@ -15,6 +18,7 @@ class StringLayout : public ExpressionLayout {
KDPoint positionOfChild(ExpressionLayout * child) override;
private:
char * m_string;
bool m_inverse;
};
#endif

View File

@@ -6,7 +6,7 @@
void print(char * message) {
static int line_y = 0;
int line_height = KDStringSize("M").height;
KDDrawString(message, (KDPoint){.x = 0, .y = line_y});
KDDrawString(message, (KDPoint){.x = 0, .y = line_y}, 0);
line_y += line_height;
if (line_y > SCREEN_HEIGHT) {
line_y = 0;