Skip to content

Commit f43d407

Browse files
committed
Add scale parameter to display_draw_string
Allows scaling text 2x for example. Very useful for when you need bigger text like when using a board as a nametag.
1 parent e95a563 commit f43d407

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/Primitives/primitives.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ inline uint32_t param_I32_arr_len3[3] = {I32, I32, I32};
133133
inline uint32_t param_I32_arr_len4[4] = {I32, I32, I32, I32};
134134
inline uint32_t param_I32_arr_len5[5] = {I32, I32, I32, I32, I32};
135135
inline uint32_t param_I32_arr_len6[6] = {I32, I32, I32, I32, I32, I32};
136+
inline uint32_t param_I32_arr_len7[7] = {I32, I32, I32, I32, I32, I32, I32};
136137
inline uint32_t param_I32_arr_len10[10] = {I32, I32, I32, I32, I32,
137138
I32, I32, I32, I32, I32};
138139
inline uint32_t param_I64_arr_len1[1] = {I64};
@@ -194,6 +195,16 @@ inline Type sixToNoneU32 = {
194195
I32; 1 = I32; 1 = I32*/
195196
};
196197

198+
inline Type sevenToNoneU32 = {
199+
.form = FUNC,
200+
.param_count = 7,
201+
.params = param_I32_arr_len7,
202+
.result_count = 0,
203+
.results = nullptr,
204+
.mask = 0x8001111111 /* 0x800 = no return ; 1 = I32 ; 1 = I32 ; 1 = I32; 1 =
205+
I32; 1 = I32; 1 = I32; 1 = I32*/
206+
};
207+
197208
inline Type oneToOneU32 = {
198209
.form = FUNC,
199210
.param_count = 1,

src/Primitives/zephyr.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ void draw_rect(const device *display_dev, int xpos, int ypos, int w, int h,
412412
#include "vgafont.h"
413413

414414
void draw_char(const device *display_dev, int xpos, int ypos, char c,
415-
uint16_t foreground, uint16_t background) {
415+
uint16_t foreground, uint16_t background, int scale) {
416416
struct display_buffer_descriptor new_buf_desc;
417-
new_buf_desc.width = 8;
418-
new_buf_desc.height = 16;
417+
new_buf_desc.width = 8 * scale;
418+
new_buf_desc.height = 16 * scale;
419419
new_buf_desc.buf_size = new_buf_desc.width * new_buf_desc.height;
420420
new_buf_desc.pitch = new_buf_desc.width;
421421
new_buf_desc.frame_incomplete = false;
@@ -424,8 +424,9 @@ void draw_char(const device *display_dev, int xpos, int ypos, char c,
424424
for (int y = 0; y < new_buf_desc.height; y++) {
425425
for (int x = 0; x < new_buf_desc.width; x++) {
426426
new_buf[y * new_buf_desc.width + x] =
427-
(font16[16 * c + y] >> (8 - x)) & 0b1 == 1 ? foreground
428-
: background;
427+
(font16[16 * c + y / scale] >> (8 - x / scale)) & 0b1 == 1
428+
? foreground
429+
: background;
429430
}
430431
}
431432
display_write(display_dev, xpos, ypos, &new_buf_desc, new_buf);
@@ -459,7 +460,8 @@ def_prim(display_setup, NoneToNoneU32) {
459460
}
460461

461462
def_prim(display_set_orientation, oneToNoneI32) {
462-
display_set_orientation(display_dev, static_cast<display_orientation>(arg0.uint32));
463+
display_set_orientation(display_dev,
464+
static_cast<display_orientation>(arg0.uint32));
463465
pop_args(1);
464466
return true;
465467
}
@@ -485,15 +487,16 @@ def_prim(display_fill_rect, fiveToNoneU32) {
485487
return true;
486488
}
487489

488-
def_prim(display_draw_string, sixToNoneU32) {
489-
uint32_t addr = arg3.uint32;
490-
uint32_t size = arg2.uint32;
490+
def_prim(display_draw_string, sevenToNoneU32) {
491+
uint32_t addr = arg4.uint32;
492+
uint32_t size = arg3.uint32;
491493
std::string text = parse_utf8_string(m->memory.bytes, size, addr);
494+
int scale = arg2.uint32;
492495
for (int i = 0; i < text.length(); i++) {
493-
draw_char(display_dev, arg5.int32 + i * 8, arg4.int32, text[i],
494-
arg1.uint32, arg0.uint32);
496+
draw_char(display_dev, arg6.int32 + i * 8 * scale, arg5.int32, text[i],
497+
arg1.uint32, arg0.uint32, scale);
495498
}
496-
pop_args(6);
499+
pop_args(7);
497500
return true;
498501
}
499502
#endif

0 commit comments

Comments
 (0)