Various bits of cleanup
This commit is contained in:
parent
fd53947564
commit
327523aabf
@ -108,7 +108,6 @@ void display() {
|
||||
draw_sprite(ctx, sprites[124 + direction], decor_left_width + map_x + CELL_SIZE * 4, decor_top_height + map_y + CELL_SIZE * 4);
|
||||
render_decorations(window, ctx->backbuffer, "RPG Demo");
|
||||
flip(ctx);
|
||||
//window_redraw_wait(window);
|
||||
}
|
||||
|
||||
void transition(int nx, int ny) {
|
||||
|
@ -2,26 +2,14 @@
|
||||
#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"
|
||||
#include "lib/shmemfonts.h"
|
||||
#include "lib/pthread.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;
|
||||
|
||||
gfx_context_t * ctx;
|
||||
|
||||
|
||||
@ -36,7 +24,6 @@ int center_y(int y) {
|
||||
return (win_height - y) / 2;
|
||||
}
|
||||
|
||||
|
||||
void init_sprite(int i, char * filename, char * alpha) {
|
||||
sprites[i] = malloc(sizeof(sprite_t));
|
||||
load_sprite(sprites[i], filename);
|
||||
@ -50,66 +37,6 @@ void init_sprite(int i, char * filename, char * alpha) {
|
||||
sprites[i]->blank = 0x0;
|
||||
}
|
||||
|
||||
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(ctx, i,j) = alpha_blend(GFX(ctx, 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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static 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
|
||||
|
||||
void _loadDejavu() {
|
||||
char * font;
|
||||
size_t s = 0;
|
||||
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;
|
||||
@ -162,17 +89,13 @@ int main (int argc, char ** argv) {
|
||||
|
||||
setup_windowing();
|
||||
|
||||
FT_Init_FreeType(&library);
|
||||
_loadDejavu();
|
||||
init_shmemfonts();
|
||||
|
||||
/* Do something with a window */
|
||||
window_t * wina = window_create(0,0, width, height);
|
||||
assert(wina);
|
||||
ctx = init_graphics_window_double_buffer(wina);
|
||||
draw_fill(ctx, rgb(0,0,0));
|
||||
#if 0
|
||||
window_redraw_full(wina);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
printf("Loading background...\n");
|
||||
@ -203,11 +126,10 @@ int main (int argc, char ** argv) {
|
||||
/* Redraw the background by memcpy (super speedy) */
|
||||
memcpy(ctx->backbuffer, buf, buf_size);
|
||||
|
||||
draw_string(50 + scale * 30,50 + scale * 30, rgb(255,0,0), input_buffer);
|
||||
draw_string(ctx, 50 + scale * 30,50 + scale * 30, rgb(255,0,0), input_buffer);
|
||||
|
||||
|
||||
flip(ctx);
|
||||
window_redraw_full(wina);
|
||||
#endif
|
||||
|
||||
++i;
|
||||
|
@ -206,8 +206,6 @@ int main(int argc, char * argv[]) {
|
||||
++j;
|
||||
} while ( j < height );
|
||||
|
||||
window_redraw_wait(window);
|
||||
|
||||
int playing = 1;
|
||||
while (playing) {
|
||||
char ch = 0;
|
||||
|
@ -29,7 +29,7 @@ static void _loadSansSerif() {
|
||||
char * font;
|
||||
size_t s = 0;
|
||||
int error;
|
||||
font = (char *)syscall_shm_obtain(WINS_SERVER_IDENTIFIER ".fonts.sans-serif.bold", &s);
|
||||
font = (char *)syscall_shm_obtain(WINS_SERVER_IDENTIFIER ".fonts.sans-serif", &s);
|
||||
error = FT_New_Memory_Face(library, font, s, 0, &face);
|
||||
error = FT_Set_Pixel_Sizes(face, FONT_SIZE, FONT_SIZE);
|
||||
}
|
||||
|
@ -60,7 +60,6 @@ void draw_char(FT_Bitmap * bitmap, int x, int y, uint32_t fg) {
|
||||
for (j = y, q = 0; j < y_max; j++, q++) {
|
||||
for ( i = x, p = 0; i < x_max; i++, p++) {
|
||||
GFX(ctx, i,j) = alpha_blend(GFX(ctx, 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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,7 +181,6 @@ int main (int argc, char ** argv) {
|
||||
memcpy(buf, ctx->backbuffer, buf_size);
|
||||
|
||||
flip(ctx);
|
||||
//window_redraw_wait(panel);
|
||||
|
||||
struct timeval now;
|
||||
int last = 0;
|
||||
@ -217,7 +215,6 @@ int main (int argc, char ** argv) {
|
||||
draw_string_wide(10, 17, rgb(255,255,255), os_name);
|
||||
|
||||
flip(ctx);
|
||||
//window_redraw_wait(panel);
|
||||
syscall_yield();
|
||||
}
|
||||
}
|
||||
|
@ -2937,15 +2937,6 @@ int buffer_put(char c) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void * screen_redrawer(void * garbage) {
|
||||
while (1) {
|
||||
if (needs_redraw) {
|
||||
needs_redraw = 0;
|
||||
window_redraw_wait(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void * wait_for_exit(void * garbage) {
|
||||
syscall_wait(child_pid);
|
||||
/* Clean up */
|
||||
|
@ -1,11 +1,12 @@
|
||||
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
||||
*
|
||||
* Wallpaper renderer.
|
||||
*
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#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"
|
||||
|
||||
@ -68,7 +69,6 @@ int main (int argc, char ** argv) {
|
||||
#endif
|
||||
|
||||
flip(ctx);
|
||||
window_redraw_full(wina);
|
||||
|
||||
while (1) {
|
||||
syscall_yield();
|
||||
|
Loading…
Reference in New Issue
Block a user