shm_obtain takes a (size_t *), altering it according to the size of the
block it returned. Conflicts: userspace/compositor.c
This commit is contained in:
commit
71fd14d6f7
@ -474,11 +474,15 @@ char * loadMemFont(char * ident, char * name, size_t * size) {
|
||||
s = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
printf("loading %s, size %d\n", name, s);
|
||||
size_t shm_size = s;
|
||||
char * font = (char *)syscall_shm_obtain(ident, &shm_size); //malloc(s);
|
||||
assert((shm_size >= s) && "shm_obtain returned too little memory to load a font into!");
|
||||
|
||||
fread(font, s, 1, f);
|
||||
|
||||
printf("First few bytes are %x%x%x%x\n", font[0], font[1], font[2], font[3]);
|
||||
|
||||
fclose(f);
|
||||
*size = s;
|
||||
return font;
|
||||
|
@ -2,12 +2,26 @@
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_CACHE_H
|
||||
|
||||
#include "lib/window.h"
|
||||
#include "lib/graphics.h"
|
||||
|
||||
sprite_t * sprites[128];
|
||||
sprite_t alpha_tmp;
|
||||
|
||||
FT_Library library;
|
||||
FT_Face face;
|
||||
FT_Face face_bold;
|
||||
FT_Face face_italic;
|
||||
FT_Face face_bold_italic;
|
||||
FT_Face face_extra;
|
||||
FT_GlyphSlot slot;
|
||||
FT_UInt glyph_index;
|
||||
|
||||
|
||||
uint16_t win_width;
|
||||
uint16_t win_height;
|
||||
|
||||
@ -89,6 +103,95 @@ void draw_sprite_scaled(sprite_t * sprite, uint16_t x, uint16_t y, uint16_t widt
|
||||
}
|
||||
}
|
||||
|
||||
void draw_char(FT_Bitmap * bitmap, int x, int y, uint32_t fg) {
|
||||
int i, j, p, q;
|
||||
int x_max = x + bitmap->width;
|
||||
int y_max = y + bitmap->rows;
|
||||
for (j = y, q = 0; j < y_max; j++, q++) {
|
||||
for ( i = x, p = 0; i < x_max; i++, p++) {
|
||||
GFX(i,j) = alpha_blend(GFX(i,j),fg,rgb(bitmap->buffer[q * bitmap->width + p],0,0));
|
||||
//term_set_point(i,j, alpha_blend(bg, fg, rgb(bitmap->buffer[q * bitmap->width + p],0,0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_string(int x, int y, uint32_t fg, char * string) {
|
||||
slot = face->glyph;
|
||||
int pen_x = x, pen_y = y, i = 0;
|
||||
int len = strlen(string);
|
||||
int error;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
FT_UInt glyph_index;
|
||||
|
||||
glyph_index = FT_Get_Char_Index( face, string[i]);
|
||||
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
|
||||
if (error) {
|
||||
printf("Error loading glyph for '%c'\n", string[i]);
|
||||
continue;
|
||||
}
|
||||
slot = (face)->glyph;
|
||||
if (slot->format == FT_GLYPH_FORMAT_OUTLINE) {
|
||||
error = FT_Render_Glyph((face)->glyph, FT_RENDER_MODE_NORMAL);
|
||||
if (error) {
|
||||
printf("Error rendering glyph for '%c'\n", string[i]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
draw_char(&slot->bitmap, pen_x + slot->bitmap_left, pen_y - slot->bitmap_top, fg);
|
||||
pen_x += slot->advance.x >> 6;
|
||||
pen_y += slot->advance.y >> 6;
|
||||
}
|
||||
}
|
||||
|
||||
#define FONT_SIZE 14
|
||||
#define FONT_BYTE_SIZE 720012
|
||||
|
||||
void _loadDejavu() {
|
||||
char * font;
|
||||
size_t s = FONT_BYTE_SIZE;
|
||||
int error;
|
||||
font = (char *)syscall_shm_obtain(WINS_SERVER_IDENTIFIER ".fonts.sans-serif", s);
|
||||
error = FT_New_Memory_Face(library, font, s, 0, &face);
|
||||
if (error) {
|
||||
printf("Oh dear, this is bad.\n");
|
||||
}
|
||||
error = FT_Set_Pixel_Sizes(face, FONT_SIZE, FONT_SIZE);
|
||||
if (error) {
|
||||
printf("Oh my.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define INPUT_SIZE 1024
|
||||
char input_buffer[1024];
|
||||
uint32_t input_collected = 0;
|
||||
|
||||
int buffer_put(char c) {
|
||||
if (c == 8) {
|
||||
/* Backspace */
|
||||
if (input_collected > 0) {
|
||||
input_collected--;
|
||||
input_buffer[input_collected] = '\0';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (c < 10 || (c > 10 && c < 32) || c > 126) {
|
||||
return 0;
|
||||
}
|
||||
input_buffer[input_collected] = c;
|
||||
if (input_buffer[input_collected] == '\n') {
|
||||
input_collected++;
|
||||
return 1;
|
||||
}
|
||||
input_collected++;
|
||||
if (input_collected == INPUT_SIZE) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char ** argv) {
|
||||
if (argc < 3) {
|
||||
printf("usage: %s width height\n", argv[0]);
|
||||
@ -103,6 +206,9 @@ int main (int argc, char ** argv) {
|
||||
|
||||
setup_windowing();
|
||||
|
||||
FT_Init_FreeType(&library);
|
||||
_loadDejavu();
|
||||
|
||||
/* Do something with a window */
|
||||
window_t * wina = window_create(0,0, width, height);
|
||||
assert(wina);
|
||||
@ -112,12 +218,16 @@ int main (int argc, char ** argv) {
|
||||
window_redraw_full(wina);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
printf("Loading background...\n");
|
||||
init_sprite(0, "/usr/share/login-background.bmp", NULL);
|
||||
printf("Background loaded.\n");
|
||||
init_sprite(1, "/usr/share/bs.bmp", "/usr/share/bs-alpha.bmp");
|
||||
|
||||
draw_sprite_scaled(sprites[0], 0, 0, width, height);
|
||||
#endif
|
||||
|
||||
init_sprite(1, "/usr/share/bs.bmp", "/usr/share/bs-alpha.bmp");
|
||||
draw_sprite_scaled(sprites[1], center_x(sprites[1]->width), center_y(sprites[1]->height), sprites[1]->width, sprites[1]->height);
|
||||
|
||||
flip();
|
||||
|
||||
size_t buf_size = wina->width * wina->height * sizeof(uint32_t);
|
||||
@ -129,7 +239,7 @@ int main (int argc, char ** argv) {
|
||||
while (1) {
|
||||
w_keyboard_t * kbd = poll_keyboard();
|
||||
if (kbd != NULL) {
|
||||
printf("[glogin] got key '%c'\n", (char)kbd->key);
|
||||
buffer_put(kbd->key);
|
||||
free(kbd);
|
||||
}
|
||||
|
||||
@ -137,7 +247,10 @@ int main (int argc, char ** argv) {
|
||||
|
||||
/* Redraw the background by memcpy (super speedy) */
|
||||
memcpy(frame_mem, buf, buf_size);
|
||||
draw_sprite_scaled(sprites[1], center_x(sprites[1]->width * scale), center_y(sprites[1]->height * scale), sprites[1]->width * scale, sprites[1]->height * scale);
|
||||
|
||||
draw_string(50 + scale * 30,50 + scale * 30, rgb(255,0,0), input_buffer);
|
||||
|
||||
|
||||
flip();
|
||||
window_redraw_full(wina);
|
||||
++i;
|
||||
|
Loading…
Reference in New Issue
Block a user