Commit 9519933e authored by deuce's avatar deuce
Browse files

Font switching operations... added setfont() function to SDL implementation.

x_setfont() still needs to be written.
parent d6b04fdf
......@@ -16,6 +16,11 @@ endif
ifdef WITH_SDL
OBJS += $(MTOBJODIR)$(DIRSEP)sdl_con$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)sdlfuncs$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)allfonts$(OFILE)
else
ifndef NO_X
OBJS += $(MTOBJODIR)$(DIRSEP)allfonts$(OFILE)
endif
endif
ifeq ($(os),netbsd)
......
......@@ -23,6 +23,7 @@ SRC_ROOT = ..
!ifdef USE_SDL
OBJS = $(OBJS) $(MTOBJODIR)$(DIRSEP)sdl_con$(OFILE) $(MTOBJODIR)$(DIRSEP)SDL_win32_main$(OFILE)
OBJS = $(OBJS) $(MTOBJODIR)$(DIRSEP)sdlfuncs$(OFILE)
OBJS = $(OBJS) $(MTOBJODIR)$(DIRSEP)allfonts$(OFILE)
!endif
#The following is necessary only when DLL-exporting wrapper functions
......
......@@ -137,6 +137,7 @@ int try_sdl_init(int mode)
cio_api.copytext=sdl_copytext;
cio_api.getcliptext=sdl_getcliptext;
#endif
cio_api.setfont=sdl_setfont;
return(1);
}
return(0);
......@@ -955,3 +956,13 @@ CIOLIBEXPORT char * CIOLIBCALL ciolib_getcliptext(void)
else
return(NULL);
}
CIOLIBEXPORT int CIOLIBCALL ciolib_setfont(int font, int force)
{
CIOLIB_INIT();
if(cio_api.setfont!=NULL)
return(cio_api.setfont(font,force));
else
return(-1);
}
......@@ -241,6 +241,7 @@ typedef struct {
char *(*getcliptext) (void);
void (*suspend) (void);
void (*resume) (void);
int (*setfont) (int font, int force);
} cioapi_t;
CIOLIBEXPORTVAR cioapi_t cio_api;
......@@ -294,6 +295,7 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_showmouse(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_hidemouse(void);
CIOLIBEXPORT void CIOLIBCALL ciolib_copytext(const char *text, size_t buflen);
CIOLIBEXPORT char * CIOLIBCALL ciolib_getcliptext(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_setfont(int font, int force);
#ifdef __cplusplus
}
#endif
......@@ -339,7 +341,8 @@ CIOLIBEXPORT char * CIOLIBCALL ciolib_getcliptext(void);
#define setname(a) ciolib_setname(a)
#define settitle(a) ciolib_settitle(a)
#define copytext(a,b) ciolib_copytext(a,b)
#define getcliptext() ciolib_getcliptext()
#define getcliptext() ciolib_getcliptext()
#define setfont(a,b) ciolib_setfont(a,b)
#endif
/* Special hackery for SDL */
......
......@@ -114,6 +114,7 @@
#include "console.h"
#include "vidmodes.h"
#include "allfonts.h"
#include "keys.h"
#include "mouse.h"
......@@ -149,6 +150,7 @@ WORD *vmem=NULL;
static int show = 1;
BYTE CursRow=0;
BYTE CursCol=0;
static int x_current_font=-1;
typedef struct TextLine {
WORD *data;
u_char max_length; /* Not used, but here for future use */
......@@ -1303,17 +1305,30 @@ load_font(char *filename, int width, int height, int scale)
return(1);
}
if(x_current_font<0 || x_current_font>(sizeof(conio_fontdata)/sizeof(struct conio_font_data_struct)-2)) {
for(i=0; conio_fontdata[i].desc != NULL; i++) {
if(!strcmp(conio_fontdata[i].desc, "Codepage 437 English")) {
x_current_font=i;
break;
}
}
}
if(conio_fontdata[i].desc==NULL)
x_current_font=0;
if(conio_fontdata[x_current_font].desc==NULL)
return(-1);
switch(width) {
case 8:
switch(height) {
case 8:
font=vga_font_bitmap8;
font=conio_fontdata[x_current_font].eight_by_eight;
break;
case 14:
font=vga_font_bitmap14;
font=conio_fontdata[x_current_font].eight_by_fourteen;
break;
case 16:
font=vga_font_bitmap;
font=conio_fontdata[x_current_font].eight_by_sixteen;
break;
default:
return(1);
......@@ -1322,6 +1337,8 @@ load_font(char *filename, int width, int height, int scale)
default:
return(1);
}
if(font==NULL)
return(1);
FW = width;
FH = height;
memcpy(fontdata, font, height*256);
......
......@@ -24,6 +24,7 @@
#include "ciolib.h"
#include "keys.h"
#include "vidmodes.h"
#include "allfonts.h"
#ifdef main
#undef main
......@@ -59,6 +60,7 @@ SDL_Surface *sdl_cursor=NULL;
static int lastcursor_x=0;
static int lastcursor_y=0;
static int sdl_current_font=-1;
unsigned short *last_vmem=NULL;
......@@ -823,6 +825,43 @@ int sdl_hidemouse(void)
return(0);
}
int sdl_setfont(int font, int force)
{
int changemode=0;
switch(vstat.charheight) {
case 8:
if(conio_fontdata[font].eight_by_eight==NULL) {
if(force)
return(-1);
else
changemode=1;
}
break;
case 14:
if(conio_fontdata[font].eight_by_fourteen==NULL) {
if(force)
return(-1);
else
changemode=1;
}
break;
case 16:
if(conio_fontdata[font].eight_by_sixteen==NULL) {
if(force)
return(-1);
else
changemode=1;
}
break;
}
sdl_current_font=font;
if(changemode)
sdl_init_mode(3);
FREE_AND_NULL(last_vmem);
sdl_user_func(SDL_USEREVENT_UPDATERECT,0,0,0,0);
}
/* Called from event thread only */
void sdl_add_key(unsigned int keyval)
{
......@@ -874,6 +913,19 @@ int sdl_load_font(char *filename)
if(filename != NULL)
return(-1);
if(sdl_current_font<0 || sdl_current_font>(sizeof(conio_fontdata)/sizeof(struct conio_font_data_struct)-2)) {
for(x=0; conio_fontdata[x].desc != NULL; x++) {
if(!strcmp(conio_fontdata[x].desc, "Codepage 437 English")) {
sdl_current_font=x;
break;
}
}
}
if(conio_fontdata[x].desc==NULL)
sdl_current_font=0;
if(conio_fontdata[sdl_current_font].desc==NULL)
return(-1);
sdl.mutexP(sdl_vstatlock);
fh=vstat.charheight;
fw=vstat.charwidth/8+(vstat.charwidth%8?1:0);
......@@ -889,21 +941,38 @@ int sdl_load_font(char *filename)
case 8:
switch(vstat.charheight) {
case 8:
memcpy(font, vga_font_bitmap8, fontsize);
if(conio_fontdata[sdl_current_font].eight_by_eight==NULL) {
sdl.mutexV(sdl_vstatlock);
free(font);
return(-1);
}
memcpy(font, conio_fontdata[sdl_current_font].eight_by_eight, fontsize);
break;
case 14:
memcpy(font, vga_font_bitmap14, fontsize);
if(conio_fontdata[sdl_current_font].eight_by_fourteen==NULL) {
sdl.mutexV(sdl_vstatlock);
free(font);
return(-1);
}
memcpy(font, conio_fontdata[sdl_current_font].eight_by_fourteen, fontsize);
break;
case 16:
memcpy(font, vga_font_bitmap, fontsize);
if(conio_fontdata[sdl_current_font].eight_by_sixteen==NULL) {
sdl.mutexV(sdl_vstatlock);
free(font);
return(-1);
}
memcpy(font, conio_fontdata[sdl_current_font].eight_by_sixteen, fontsize);
break;
default:
sdl.mutexV(sdl_vstatlock);
free(font);
return(-1);
}
break;
default:
sdl.mutexV(sdl_vstatlock);
free(font);
return(-1);
}
......@@ -912,6 +981,7 @@ int sdl_load_font(char *filename)
sdl_font=sdl.CreateRGBSurface(SDL_SWSURFACE|SDL_SRCCOLORKEY, vstat.charwidth, vstat.charheight*256, 8, 0, 0, 0, 0);
if(sdl_font == NULL) {
sdl.mutexV(sdl_vstatlock);
free(font);
return(-1);
}
else {
......@@ -930,7 +1000,7 @@ int sdl_load_font(char *filename)
}
}
sdl.mutexV(sdl_vstatlock);
free(font);
return(0);
}
......
......@@ -35,6 +35,7 @@ int sdl_hidemouse(void);
int sdl_showmouse(void);
void sdl_copytext(const char *text, size_t buflen);
char *sdl_getcliptext(void);
int sdl_setfont(int font, int force);
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment