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