use a system font
This commit is contained in:
parent
b7a7c607ee
commit
37266dae69
5 changed files with 382 additions and 380 deletions
3
Makefile
3
Makefile
|
@ -1,6 +1,7 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
LIBS = $(shell pkg-config --libs sdl2 SDL2_ttf)
|
||||||
CFLAGS = -Wall -Werror -O3 -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=missing-braces -Wno-error=incompatible-pointer-types
|
CFLAGS = -Wall -Werror -O3 -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=missing-braces -Wno-error=incompatible-pointer-types
|
||||||
LIBS += $(shell pkg-config --libs sdl2 SDL2_ttf)
|
CFLAGS += -DSDL_TTF=1 #-DFONT_FILENAME="/usr/share/fonts/TTF/unifont.ttf"
|
||||||
|
|
||||||
.PHONY: all clean clean-all pretty-code install
|
.PHONY: all clean clean-all pretty-code install
|
||||||
|
|
||||||
|
|
BIN
dist/FreeSans.ttf
vendored
BIN
dist/FreeSans.ttf
vendored
Binary file not shown.
14
src/gui.c
14
src/gui.c
|
@ -44,8 +44,8 @@
|
||||||
extern SDL_Renderer* renderer;
|
extern SDL_Renderer* renderer;
|
||||||
extern SDL_Texture* faceplateTexture;
|
extern SDL_Texture* faceplateTexture;
|
||||||
#ifdef SDL_TTF
|
#ifdef SDL_TTF
|
||||||
extern TTF_Font* ArialFonte;
|
extern TTF_Font* ttffont;
|
||||||
extern TTF_Font* ArialFonte2;
|
extern TTF_Font* ttffont2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SDL_Surface* surfA[ 49 ];
|
SDL_Surface* surfA[ 49 ];
|
||||||
|
@ -133,7 +133,7 @@ void drawText( int index, int x, int y, int btn_w, int btn_h ) {
|
||||||
void gui_initKeyboard( Button* calcbuttons ) {
|
void gui_initKeyboard( Button* calcbuttons ) {
|
||||||
printf( "init texts\n" );
|
printf( "init texts\n" );
|
||||||
#ifdef SDL_TTF
|
#ifdef SDL_TTF
|
||||||
if ( ArialFonte == NULL ) {
|
if ( ttffont == NULL ) {
|
||||||
printf( "init texts error Font NULL\n" );
|
printf( "init texts error Font NULL\n" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ void gui_initKeyboard( Button* calcbuttons ) {
|
||||||
SDL_Surface* s = NULL;
|
SDL_Surface* s = NULL;
|
||||||
SDL_Texture* t = NULL;
|
SDL_Texture* t = NULL;
|
||||||
if ( buttons->text && strcmp( buttons->text, "" ) != 0 ) {
|
if ( buttons->text && strcmp( buttons->text, "" ) != 0 ) {
|
||||||
s = TTF_RenderText_Blended( ArialFonte, buttons->text,
|
s = TTF_RenderUTF8_Blended( ttffont, buttons->text,
|
||||||
couleurBlanche );
|
couleurBlanche );
|
||||||
if ( s ) {
|
if ( s ) {
|
||||||
t = SDL_CreateTextureFromSurface( renderer, s );
|
t = SDL_CreateTextureFromSurface( renderer, s );
|
||||||
|
@ -170,7 +170,7 @@ void gui_initKeyboard( Button* calcbuttons ) {
|
||||||
SDL_Surface* s = NULL;
|
SDL_Surface* s = NULL;
|
||||||
SDL_Texture* t = NULL;
|
SDL_Texture* t = NULL;
|
||||||
if ( buttons->textB && strcmp( buttons->textB, "" ) != 0 ) {
|
if ( buttons->textB && strcmp( buttons->textB, "" ) != 0 ) {
|
||||||
s = TTF_RenderText_Blended( ArialFonte2, buttons->textB,
|
s = TTF_RenderUTF8_Blended( ttffont2, buttons->textB,
|
||||||
couleurPurple );
|
couleurPurple );
|
||||||
if ( s ) {
|
if ( s ) {
|
||||||
t = SDL_CreateTextureFromSurface( renderer, s );
|
t = SDL_CreateTextureFromSurface( renderer, s );
|
||||||
|
@ -188,7 +188,7 @@ void gui_initKeyboard( Button* calcbuttons ) {
|
||||||
SDL_Surface* s = NULL;
|
SDL_Surface* s = NULL;
|
||||||
SDL_Texture* t = NULL;
|
SDL_Texture* t = NULL;
|
||||||
if ( buttons->textC && strcmp( buttons->textC, "" ) != 0 ) {
|
if ( buttons->textC && strcmp( buttons->textC, "" ) != 0 ) {
|
||||||
s = TTF_RenderText_Blended( ArialFonte2, buttons->textC,
|
s = TTF_RenderUTF8_Blended( ttffont2, buttons->textC,
|
||||||
couleurGreen );
|
couleurGreen );
|
||||||
if ( s ) {
|
if ( s ) {
|
||||||
t = SDL_CreateTextureFromSurface( renderer, s );
|
t = SDL_CreateTextureFromSurface( renderer, s );
|
||||||
|
@ -206,7 +206,7 @@ void gui_initKeyboard( Button* calcbuttons ) {
|
||||||
SDL_Surface* s = NULL;
|
SDL_Surface* s = NULL;
|
||||||
SDL_Texture* t = NULL;
|
SDL_Texture* t = NULL;
|
||||||
if ( buttons->textD && strcmp( buttons->textD, "" ) != 0 ) {
|
if ( buttons->textD && strcmp( buttons->textD, "" ) != 0 ) {
|
||||||
s = TTF_RenderText_Blended( ArialFonte2, buttons->textD,
|
s = TTF_RenderUTF8_Blended( ttffont2, buttons->textD,
|
||||||
couleurYellow );
|
couleurYellow );
|
||||||
if ( s ) {
|
if ( s ) {
|
||||||
t = SDL_CreateTextureFromSurface( renderer, s );
|
t = SDL_CreateTextureFromSurface( renderer, s );
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
#ifndef __GUI_H
|
#ifndef __GUI_H
|
||||||
#define __GUI_H
|
#define __GUI_H
|
||||||
|
|
||||||
#define SDL_TTF
|
/* #define SDL_TTF */
|
||||||
|
#define FONT_FILENAME "/usr/share/fonts/TTF/unifont.ttf"
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
|
12
src/main.c
12
src/main.c
|
@ -59,8 +59,8 @@ SDL_Texture* tex2Target = NULL;
|
||||||
SDL_Texture* faceplateTexture = NULL;
|
SDL_Texture* faceplateTexture = NULL;
|
||||||
|
|
||||||
#ifdef SDL_TTF
|
#ifdef SDL_TTF
|
||||||
TTF_Font* ArialFonte = NULL;
|
TTF_Font* ttffont = NULL;
|
||||||
TTF_Font* ArialFonte2 = NULL;
|
TTF_Font* ttffont2 = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SDL_TimerID my_timer0_id;
|
SDL_TimerID my_timer0_id;
|
||||||
|
@ -224,8 +224,8 @@ static void program_init( void ) {
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
ArialFonte = TTF_OpenFont( "FreeSans.ttf", 14 );
|
ttffont = TTF_OpenFont( FONT_FILENAME, 14 );
|
||||||
ArialFonte2 = TTF_OpenFont( "FreeSans.ttf", 10 );
|
ttffont2 = TTF_OpenFont( FONT_FILENAME, 10 );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
window = SDL_CreateWindow( "jsEmu48", SDL_WINDOWPOS_UNDEFINED,
|
window = SDL_CreateWindow( "jsEmu48", SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
@ -293,8 +293,8 @@ static void program_exit( void ) {
|
||||||
SDL_RemoveTimer(my_timer4_id);
|
SDL_RemoveTimer(my_timer4_id);
|
||||||
*/
|
*/
|
||||||
#ifdef SDL_TTF
|
#ifdef SDL_TTF
|
||||||
TTF_CloseFont( ArialFonte );
|
TTF_CloseFont( ttffont );
|
||||||
TTF_CloseFont( ArialFonte2 );
|
TTF_CloseFont( ttffont2 );
|
||||||
TTF_Quit();
|
TTF_Quit();
|
||||||
#endif
|
#endif
|
||||||
SDL_DestroyRenderer( renderer );
|
SDL_DestroyRenderer( renderer );
|
||||||
|
|
Loading…
Reference in a new issue