use SDF in decorations
This commit is contained in:
parent
2b3c21be22
commit
a8ddac6ff2
@ -11,6 +11,7 @@
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <syscall.h>
|
||||
#include <wait.h>
|
||||
|
||||
#include <toaru/yutani.h>
|
||||
#include <toaru/graphics.h>
|
||||
@ -171,6 +172,8 @@ int main (int argc, char ** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
wait(NULL);
|
||||
|
||||
yutani_close(yctx, wina);
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <toaru/yutani.h>
|
||||
#include <toaru/graphics.h>
|
||||
#include <toaru/decorations.h>
|
||||
#include <toaru/drawstring.h>
|
||||
#include <toaru/sdf.h>
|
||||
|
||||
#define INACTIVE 9
|
||||
|
||||
@ -79,19 +79,19 @@ static void render_decorations_fancy(yutani_window_t * window, gfx_context_t * c
|
||||
|
||||
#define EXTRA_SPACE 40
|
||||
|
||||
if (draw_string_width(tmp_title) + EXTRA_SPACE > width) {
|
||||
while (t_l >= 0 && (draw_string_width(tmp_title) + EXTRA_SPACE > width)) {
|
||||
if (draw_sdf_string_width(tmp_title, 18) + EXTRA_SPACE > width) {
|
||||
while (t_l >= 0 && (draw_sdf_string_width(tmp_title, 18) + EXTRA_SPACE > width)) {
|
||||
tmp_title[t_l] = '\0';
|
||||
t_l--;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(tmp_title)) {
|
||||
int title_offset = (width / 2) - (draw_string_width(tmp_title) / 2);
|
||||
int title_offset = (width / 2) - (draw_sdf_string_width(tmp_title, 18) / 2);
|
||||
if (decors_active == 0) {
|
||||
draw_string(ctx, title_offset, TEXT_OFFSET, rgb(226,226,226), tmp_title);
|
||||
draw_sdf_string(ctx, title_offset, TEXT_OFFSET, tmp_title, 18, rgb(226,226,226));
|
||||
} else {
|
||||
draw_string(ctx, title_offset, TEXT_OFFSET, rgb(147,147,147), tmp_title);
|
||||
draw_sdf_string(ctx, title_offset, TEXT_OFFSET, tmp_title, 18, rgb(147,147,147));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,10 +116,13 @@ struct {
|
||||
{0,0},
|
||||
};
|
||||
|
||||
static int loaded = 0;
|
||||
|
||||
__attribute__((constructor))
|
||||
static void _init_sdf(void) {
|
||||
/* Load the font. */
|
||||
load_sprite(&_font_data, "/usr/share/sdf.bmp");
|
||||
loaded = 1;
|
||||
}
|
||||
|
||||
static int draw_sdf_character(gfx_context_t * ctx, int32_t x, int32_t y, int ch, int size, uint32_t color, sprite_t * tmp) {
|
||||
@ -136,12 +139,13 @@ static int draw_sdf_character(gfx_context_t * ctx, int32_t x, int32_t y, int ch,
|
||||
}
|
||||
|
||||
double scale = (double)size / 50.0;
|
||||
size_t width = _char_data[ch].width * scale;
|
||||
int width = _char_data[ch].width * scale;
|
||||
int fx = ((BASE_WIDTH * ch) % _font_data.width) * scale;
|
||||
int fy = (((BASE_WIDTH * ch) / _font_data.width) * BASE_HEIGHT) * scale;
|
||||
|
||||
int height = BASE_HEIGHT * ((double)size / 50.0);
|
||||
|
||||
|
||||
/* ignore size */
|
||||
for (int j = 0; j < height; ++j) {
|
||||
for (int i = 0; i < width; ++i) {
|
||||
@ -166,6 +170,8 @@ static int draw_sdf_character(gfx_context_t * ctx, int32_t x, int32_t y, int ch,
|
||||
|
||||
int draw_sdf_string(gfx_context_t * ctx, int32_t x, int32_t y, char * str, int size, uint32_t color) {
|
||||
|
||||
if (!loaded) return 0;
|
||||
|
||||
double scale = (double)size / 50.0;
|
||||
sprite_t * tmp = create_sprite(scale * _font_data.width, scale * _font_data.height, ALPHA_OPAQUE);
|
||||
gfx_context_t * t = init_graphics_sprite(tmp);
|
||||
|
Loading…
Reference in New Issue
Block a user