1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-07-17 03:29:10 +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 "log.h"
#include "vm_bits.h"
#include "vm_screen.h"
typedef struct {
@ -16,7 +17,7 @@ typedef struct {
} vm_bitfont;
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_offset(vm_bitfont *, char, vm_area *);

View File

@ -18,14 +18,26 @@
*/
vm_bitfont *
vm_bitfont_create(vm_screen *screen,
const char *from_name,
int width,
int height,
char cmask)
const vm_8bit *fontdata, int fontsize,
int width, int height, char cmask)
{
SDL_Surface *surf;
SDL_RWops *rw;
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));
if (font == NULL) {
@ -33,14 +45,6 @@ vm_bitfont_create(vm_screen *screen,
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->width = width;
font->height = height;

View File

@ -4,6 +4,7 @@
#include <criterion/criterion.h>
#include "objstore.h"
#include "vm_bitfont.h"
static vm_bitfont *font;
@ -13,8 +14,13 @@ setup()
{
vm_screen *screen;
objstore_init();
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