1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-12-21 23:29:16 +00:00

Change create to use objstore vm_8bit data

This commit is contained in:
Peter Evans 2018-01-03 21:50:30 -06:00
parent 565dd1b34b
commit 171ff62551
3 changed files with 26 additions and 15 deletions

View File

@ -4,6 +4,7 @@
#include <SDL.h> #include <SDL.h>
#include "log.h" #include "log.h"
#include "vm_bits.h"
#include "vm_screen.h" #include "vm_screen.h"
typedef struct { typedef struct {
@ -16,7 +17,7 @@ typedef struct {
} vm_bitfont; } vm_bitfont;
extern int vm_bitfont_render(vm_bitfont *, vm_screen *, vm_area *, char); extern int vm_bitfont_render(vm_bitfont *, vm_screen *, vm_area *, char);
extern vm_bitfont *vm_bitfont_create(vm_screen *, const char *, int, int, char); extern vm_bitfont *vm_bitfont_create(vm_screen *, const vm_8bit *, int, int, int, char);
extern void vm_bitfont_free(vm_bitfont *); extern void vm_bitfont_free(vm_bitfont *);
extern void vm_bitfont_offset(vm_bitfont *, char, vm_area *); extern void vm_bitfont_offset(vm_bitfont *, char, vm_area *);

View File

@ -18,14 +18,26 @@
*/ */
vm_bitfont * vm_bitfont *
vm_bitfont_create(vm_screen *screen, vm_bitfont_create(vm_screen *screen,
const char *from_name, const vm_8bit *fontdata, int fontsize,
int width, int width, int height, char cmask)
int height,
char cmask)
{ {
SDL_Surface *surf; SDL_Surface *surf;
SDL_RWops *rw;
vm_bitfont *font; vm_bitfont *font;
char namebuf[1024];
rw = SDL_RWFromConstMem(fontdata, fontsize);
if (rw == NULL) {
log_critical("Failed to create RWops from font data: %s",
SDL_GetError());
return NULL;
}
surf = SDL_LoadBMP_RW(rw, 0);
if (surf == NULL) {
log_critical("Failed to create bitmap from RWops: %s",
SDL_GetError());
return NULL;
}
font = malloc(sizeof(vm_bitfont)); font = malloc(sizeof(vm_bitfont));
if (font == NULL) { if (font == NULL) {
@ -33,14 +45,6 @@ vm_bitfont_create(vm_screen *screen,
return NULL; return NULL;
} }
snprintf(namebuf,
sizeof(namebuf) - 1,
"%s/fonts/%s.bmp",
INSTALL_PATH, from_name);
// FIXME: test if this even works... fail if not
surf = SDL_LoadBMP(namebuf);
font->texture = SDL_CreateTextureFromSurface(screen->render, surf); font->texture = SDL_CreateTextureFromSurface(screen->render, surf);
font->width = width; font->width = width;
font->height = height; font->height = height;

View File

@ -4,6 +4,7 @@
#include <criterion/criterion.h> #include <criterion/criterion.h>
#include "objstore.h"
#include "vm_bitfont.h" #include "vm_bitfont.h"
static vm_bitfont *font; static vm_bitfont *font;
@ -13,8 +14,13 @@ setup()
{ {
vm_screen *screen; vm_screen *screen;
objstore_init();
screen = vm_screen_create(); screen = vm_screen_create();
font = vm_bitfont_create(screen, "apple2-system", 7, 8, 0x7F); font = vm_bitfont_create(screen,
objstore_apple2_sysfont(),
APPLE2_SYSFONT_SIZE,
7, 8, 0x7F);
} }
static void static void