Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow drawing scaled chars (hagl_put_scaled_char) and text (hagl_put_scaled_text) #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (ESP_PLATFORM)
idf_component_register(
SRCS "src/bitmap.c" "src/clip.c" "src/fontx.c" "src/hagl.c" "src/hsl.c" "src/rgb565.c" "src/rgb888.c" "src/tjpgd.c"
INCLUDE_DIRS "./include"
REQUIRES hagl_hal
REQUIRES hagl_esp_mipi
)
endif()

Expand Down
4 changes: 4 additions & 0 deletions include/hagl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ color_t hagl_get_pixel(int16_t x0, int16_t y0);
*/
uint8_t hagl_put_char(wchar_t code, int16_t x0, int16_t y0, color_t color, const unsigned char *font);

uint8_t hagl_put_scaled_char(wchar_t code, int16_t x0, int16_t y0, float scalefactor, color_t color, const uint8_t *font);

/**
* Draw a string
*
Expand All @@ -109,6 +111,8 @@ uint8_t hagl_put_char(wchar_t code, int16_t x0, int16_t y0, color_t color, const
*/
uint16_t hagl_put_text(const wchar_t *str, int16_t x0, int16_t y0, color_t color, const unsigned char *font);

uint16_t hagl_put_scaled_text(const wchar_t *str, int16_t x0, int16_t y0, float scalefactor, color_t color, const unsigned char *font);

/**
* Extract a glyph into a bitmap
*
Expand Down
26 changes: 22 additions & 4 deletions src/hagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ uint8_t hagl_get_glyph(wchar_t code, color_t color, bitmap_t *bitmap, const uint
}

uint8_t hagl_put_char(wchar_t code, int16_t x0, int16_t y0, color_t color, const uint8_t *font)
{
return hagl_put_scaled_char(code, x0, y0, 1, color, font);
}

uint8_t hagl_put_scaled_char(wchar_t code, int16_t x0, int16_t y0, float scalefactor, color_t color, const uint8_t *font)
{
uint8_t set, status;
color_t buffer[HAGL_CHAR_BUFFER_SIZE];
Expand Down Expand Up @@ -367,9 +372,13 @@ uint8_t hagl_put_char(wchar_t code, int16_t x0, int16_t y0, color_t color, const
glyph.buffer += glyph.pitch;
}

hagl_blit(x0, y0, &bitmap);
if (scalefactor == 1.0) {
hagl_blit(x0, y0, &bitmap);
} else {
hagl_scale_blit(x0, y0, (int)glyph.width*scalefactor, (int)glyph.height*scalefactor, &bitmap);
}

return bitmap.width;
return (int)bitmap.width*scalefactor;
}

/*
Expand All @@ -378,6 +387,11 @@ uint8_t hagl_put_char(wchar_t code, int16_t x0, int16_t y0, color_t color, const
*/

uint16_t hagl_put_text(const wchar_t *str, int16_t x0, int16_t y0, color_t color, const unsigned char *font)
{
return hagl_put_scaled_text(str, x0, y0, 1, color, font);
}

uint16_t hagl_put_scaled_text(const wchar_t *str, int16_t x0, int16_t y0, float scalefactor, color_t color, const unsigned char *font)
{
wchar_t temp;
uint8_t status;
Expand All @@ -393,9 +407,13 @@ uint16_t hagl_put_text(const wchar_t *str, int16_t x0, int16_t y0, color_t color
temp = *str++;
if (13 == temp || 10 == temp) {
x0 = 0;
y0 += meta.height;
y0 += (int)meta.height*scalefactor;
} else {
x0 += hagl_put_char(temp, x0, y0, color, font);
if (scalefactor == 1.0) {
x0 += hagl_put_char(temp, x0, y0, color, font);
} else {
x0 += hagl_put_scaled_char(temp, x0, y0, scalefactor, color, font);
}
}
} while (*str != 0);

Expand Down