Added Drawstring function
This commit is contained in:
parent
e34798f749
commit
f1ff0606e7
@ -1,5 +1,6 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include "config.h"
|
||||
#include "font.h"
|
||||
|
||||
static SDL_Window *window;
|
||||
static SDL_Renderer *renderer;
|
||||
@ -44,3 +45,30 @@ void initWindow(){
|
||||
void clearScreen(uint32_t pixels[], uint32_t color){
|
||||
for (uint32_t i = 0; i < SDL_X_SIZE * SDL_Y_SIZE; i++) pixels[i] = color;
|
||||
}
|
||||
|
||||
#define CHARMARGIN 0
|
||||
void drawString(const char* string, uint32_t pixels[], uint16_t screenXsize, uint32_t foreground, uint32_t background, uint16_t x, uint16_t y, uint8_t scale){
|
||||
uint16_t xCount = x;
|
||||
uint16_t yCount = y;
|
||||
|
||||
for (int i = 0; string[i]; i++){
|
||||
if (string[i] > 31 && string[i] < 127){
|
||||
for (int _x = 0; _x < FONT_WIDTH * scale; _x++){
|
||||
if (xCount + _x >= screenXsize){
|
||||
xCount = x;
|
||||
yCount += (FONT_HEIGHT + CHARMARGIN) * scale;
|
||||
}
|
||||
|
||||
for (int _y = 0; _y < FONT_HEIGHT * scale; _y++){
|
||||
uint8_t value = typeface[((string[i] - 32) * FONT_HEIGHT) + (_y / scale)] & (128 >> (_x / scale));
|
||||
if (value && foreground != 0) pixels[(( yCount + _y) * screenXsize) + (xCount + _x)] = foreground;
|
||||
else if (!value && background != 0) pixels[(( yCount + _y) * screenXsize) + (xCount + _x)] = background;
|
||||
}
|
||||
}
|
||||
xCount += (FONT_WIDTH + CHARMARGIN) * scale;
|
||||
} else if (string[i] == '\n'){
|
||||
xCount = x;
|
||||
yCount += (FONT_HEIGHT + CHARMARGIN) * scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user