Text with SFont, unfinished. Also merged in some Makefile tweaks by xeron

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@318 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2008-10-29 20:04:25 +00:00
parent a6ab2465fc
commit bd23cc6f76
8 changed files with 135 additions and 53 deletions

View File

@ -20,20 +20,6 @@
# write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#TrueType is optional: make NOTTF=1 to disable support and dependencies.
ifeq ($(NOTTF),1)
TTFCOPT = -DNOTTF=1
TTFLOPT =
TTFLIBS =
TTFLABEL = -nottf
else
TTFCOPT =
TTFLOPT = -L/usr/local/lib -lSDL_ttf
TTFLIBS = libfreetype-6.dll SDL_ttf.dll
TTFLABEL =
endif
# Windows specific
ifdef COMSPEC
DELCOMMAND = del
@ -58,6 +44,7 @@ else
LOPT = `sdl-config --libs` -lSDL_image -lpng -ljpeg -lz $(TTFLOPT)
CC = gcc
OBJDIR = obj/amiga
NOTTF = 1
else
# Linux specific
@ -82,9 +69,23 @@ else
endif
endif
#TrueType is optional: make NOTTF=1 to disable support and dependencies.
ifeq ($(NOTTF),1)
TTFCOPT = -DNOTTF=1
TTFLOPT =
TTFLIBS =
TTFLABEL = -nottf
else
TTFCOPT =
TTFLOPT = -L/usr/local/lib -lSDL_ttf
TTFLIBS = libfreetype-6.dll SDL_ttf.dll
TTFLABEL =
endif
.PHONY : all debug release clean depend zip version force
OBJ = $(OBJDIR)/main.o $(OBJDIR)/init.o $(OBJDIR)/graph.o $(OBJDIR)/sdlscreen.o $(OBJDIR)/divers.o $(OBJDIR)/special.o $(OBJDIR)/boutons.o $(OBJDIR)/palette.o $(OBJDIR)/aide.o $(OBJDIR)/operatio.o $(OBJDIR)/pages.o $(OBJDIR)/loadsave.o $(OBJDIR)/readline.o $(OBJDIR)/moteur.o $(OBJDIR)/files.o $(OBJDIR)/op_c.o $(OBJDIR)/linux.o $(OBJDIR)/readini.o $(OBJDIR)/saveini.o $(OBJDIR)/shade.o $(OBJDIR)/clavier.o $(OBJDIR)/io.o $(OBJDIR)/version.o $(OBJDIR)/texte.o
OBJ = $(OBJDIR)/main.o $(OBJDIR)/init.o $(OBJDIR)/graph.o $(OBJDIR)/sdlscreen.o $(OBJDIR)/divers.o $(OBJDIR)/special.o $(OBJDIR)/boutons.o $(OBJDIR)/palette.o $(OBJDIR)/aide.o $(OBJDIR)/operatio.o $(OBJDIR)/pages.o $(OBJDIR)/loadsave.o $(OBJDIR)/readline.o $(OBJDIR)/moteur.o $(OBJDIR)/files.o $(OBJDIR)/op_c.o $(OBJDIR)/linux.o $(OBJDIR)/readini.o $(OBJDIR)/saveini.o $(OBJDIR)/shade.o $(OBJDIR)/clavier.o $(OBJDIR)/io.o $(OBJDIR)/version.o $(OBJDIR)/texte.o $(OBJDIR)/SFont.o
CFGOBJ = $(OBJDIR)/gfxcfg.o $(OBJDIR)/SFont.o $(OBJDIR)/clavier.o $(OBJDIR)/io.o
all : $(BIN) $(CFGBIN)
@ -98,9 +99,9 @@ release : $(BIN) $(CFGBIN)
# A release zip archive
ziprelease: version $(BIN) $(BINCFG) release
tar cvzf src-svn`svnversion | sed 's/:/-/'`.tgz *.c *.h Makefile Makefile.dep
zip grafx2-svn`svnversion | sed 's/:/-/'`$(TTFLABEL)-win32.zip $(BIN) $(CFGBIN) gfx2.dat gfx2.ico doc/gpl-2.0.txt SDL.dll 8pxfont.png SDL_image.dll $(TTFLIBS) fonts/Tuffy.ttf src-svn`svnversion | sed 's/:/-/'`.tgz
zip grafx2-svn`svnversion | sed 's/:/-/'`$(TTFLABEL)-win32.zip $(BIN) $(CFGBIN) gfx2.dat gfx2.ico doc/gpl-2.0.txt SDL.dll fonts/8pxfont.png SDL_image.dll $(TTFLIBS) fonts/Tuffy.ttf src-svn`svnversion | sed 's/:/-/'`.tgz
$(DELCOMMAND) src-svn`svnversion | sed 's/:/-/'`.tgz
tar cvzf grafx2-svn`svnversion | sed 's/:/-/'`$(TTFLABEL)-src.tgz *.c *.h Makefile Makefile.dep gfx2.dat gfx2.ico doc/gpl-2.0.txt 8pxfont.png fonts/Tuffy.ttf
tar cvzf grafx2-svn`svnversion | sed 's/:/-/'`$(TTFLABEL)-src.tgz *.c *.h Makefile Makefile.dep gfx2.dat gfx2.ico doc/gpl-2.0.txt fonts/8pxfont.png fonts/Tuffy.ttf
$(BIN) : $(OBJ)
$(CC) $(OBJ) -o $(BIN) $(LOPT)

View File

@ -5740,6 +5740,7 @@ void Bouton_Texte()
static char Chaine[256]="";
static int Taille_police=16;
static int AntiAlias=0;
short Debut_liste=0, Position_curseur=0; // Selecteur de fonte
byte * Nouvelle_Brosse;
int Nouvelle_Largeur;
@ -5750,7 +5751,6 @@ void Bouton_Texte()
struct Fenetre_Bouton_special * Bouton_taille_texte;
struct Fenetre_Bouton_special * Bouton_texte;
byte A_redessiner=1;
short Debut_liste, Position_curseur; // Selecteur de fonte
short Temp;
Ouvrir_fenetre(288,180,"Text");
@ -5768,14 +5768,11 @@ void Bouton_Texte()
Print_dans_fenetre(13,54,AntiAlias?"AntiAlias":" No AA ", CM_Noir, CM_Clair);
// Scroller des fontes
Fenetre_Definir_bouton_scroller(94,33,NB_FONTES*8,Fonte_nombre,NB_FONTES,0); // 4
Fenetre_Definir_bouton_scroller(94,33,NB_FONTES*8,Fonte_nombre,NB_FONTES,Debut_liste); // 4
// Liste des fontes disponibles
Fenetre_Definir_bouton_special(111,32,168,NB_FONTES*8); // 5
Fenetre_Afficher_cadre_creux(110, 31, 170, NB_FONTES*8+4);
Debut_liste=0;
Position_curseur=0;
// Taille texte
Print_dans_fenetre(32,71,"Size:",CM_Fonce,CM_Clair);
@ -5853,7 +5850,7 @@ void Bouton_Texte()
case 5: // Selecteur de fonte
Temp=(((Mouse_Y-Fenetre_Pos_Y)/Menu_Facteur_Y)-32)>>3;
if (Temp!=Position_curseur)
if (Temp!=Position_curseur && Temp < Fonte_nombre)
{
Position_curseur=Temp;
// On affiche à nouveau la liste
@ -5899,7 +5896,7 @@ void Bouton_Texte()
case 11: // OK
// Rendu texte
Nouvelle_Brosse = Rendu_Texte(Chaine, Taille_police, AntiAlias, &Nouvelle_Largeur, &Nouvelle_Hauteur);
Nouvelle_Brosse = Rendu_Texte(Chaine, Position_curseur, Taille_police, AntiAlias, &Nouvelle_Largeur, &Nouvelle_Hauteur);
if (!Nouvelle_Brosse)
{
Fermer_fenetre();
@ -5909,8 +5906,11 @@ void Bouton_Texte()
return;
}
Effacer_curseur();
// On passe en brosse monochrome:
Changer_la_forme_du_pinceau(FORME_PINCEAU_BROSSE_COULEUR);
// On passe en brosse:
//if (AntiAlias)
Changer_la_forme_du_pinceau(FORME_PINCEAU_BROSSE_COULEUR);
//else
// Changer_la_forme_du_pinceau(FORME_PINCEAU_BROSSE_MONOCHROME);
if (Brosse) free(Brosse);
Brosse=Nouvelle_Brosse;

View File

Before

Width:  |  Height:  |  Size: 720 B

After

Width:  |  Height:  |  Size: 720 B

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
fonts/colorfont.pcx Normal file

Binary file not shown.

View File

@ -660,7 +660,7 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
SDL_EnableUNICODE(SDL_ENABLE);
/* On initialise SFont */
MyFont = SFont_InitFont(IMG_Load("8pxfont.png"));
MyFont = SFont_InitFont(IMG_Load("fonts/8pxfont.png"));
if(MyFont==NULL)
{

131
texte.c
View File

@ -25,6 +25,7 @@
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
// TrueType
#ifndef NOTTF
@ -58,11 +59,12 @@ T_FONTE * Liste_fontes_fin;
int Fonte_nombre;
// Ajout d'une fonte à la liste.
void Ajout_fonte(char *Nom, int EstTrueType, int EstImage)
void Ajout_fonte(char *Chemin, char *Nom, int EstTrueType, int EstImage)
{
T_FONTE * Fonte = (T_FONTE *)malloc(sizeof(T_FONTE));
Fonte->Nom = (char *)malloc(strlen(Nom)+1);
strcpy(Fonte->Nom, Nom);
Fonte->Nom = (char *)malloc(strlen(Chemin)+strlen(Nom)+1);
strcpy(Fonte->Nom, Chemin);
strcat(Fonte->Nom, Nom);
Fonte->EstTrueType = EstTrueType;
Fonte->EstImage = EstImage;
@ -120,31 +122,46 @@ char * Libelle_fonte(int Indice)
// Initialisation à faire une fois au début du programme
void Initialisation_Texte(void)
{
// Pour scan de répertoire
//DIR* Repertoire_Courant; //Répertoire courant
//struct dirent* Enreg; // Structure de lecture des éléments
//char Nom_repertoire[TAILLE_CHEMIN_FICHIER];
#ifndef NOTTF
// Initialisation de TTF
TTF_Init();
#endif
// Initialisation des fontes
Liste_fontes_debut = Liste_fontes_fin = NULL;
Fonte_nombre=0;
// Parcours du répertoire "fontes"
Ajout_fonte("fonts/Tuffy.ttf", 1, 0);
Ajout_fonte("fonts/Otherfont.ttf", 1, 0);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("8pxfont.png", 0, 1);
Ajout_fonte("fonts/Tuffy.ttf", 1, 0);
// Parcours du répertoire "fonts"
/*strcpy(Nom_repertoire, Repertoire_du_programme);
strcat(Nom_repertoire, "fonts");
Repertoire_Courant=opendir(Nom_repertoire);
strcat(Nom_repertoire, SEPARATEUR_CHEMIN);
while ((Enreg=readdir(Repertoire_Courant)))
{
struct stat Infos_enreg;
stat(Enreg->d_name,&Infos_enreg);
if (S_ISREG(Infos_enreg.st_mode))
{
Ajout_fonte(Repertoire_Courant,Enreg->d_name, 1, 0);
}
}
*/
Ajout_fonte(Repertoire_du_programme,"fonts/Tuffy.ttf", 1, 0);
Ajout_fonte(Repertoire_du_programme,"fonts/5pxtinyfont.png", 0, 1);
Ajout_fonte(Repertoire_du_programme,"fonts/colorfont.pcx", 0, 1);
Ajout_fonte(Repertoire_du_programme,"fonts/8pxfont.png", 0, 1);
// Parcours du répertoire systeme windows "fontes"
#ifdef __WIN32__
Ajout_fonte("c:/windows/fonts/","arial.ttf", 1, 0);
Ajout_fonte("c:/windows/fonts/","cour.ttf", 1, 0);
#endif
}
// Informe si texte.c a été compilé avec l'option de support TrueType ou pas.
@ -159,7 +176,7 @@ int Support_TrueType()
#ifndef NOTTF
byte *Rendu_Texte_TTF(const char *Chaine, int Taille, int AntiAlias, int *Largeur, int *Hauteur)
byte *Rendu_Texte_TTF(const char *Chaine, int Numero_fonte, int Taille, int AntiAlias, int *Largeur, int *Hauteur)
{
TTF_Font *Fonte;
SDL_Surface * TexteColore;
@ -172,7 +189,7 @@ byte *Rendu_Texte_TTF(const char *Chaine, int Taille, int AntiAlias, int *Largeu
SDL_Color Couleur_Arriere;
// Chargement de la fonte
Fonte=TTF_OpenFont(Nom_fonte(0), Taille); // FIXME fonte en dur
Fonte=TTF_OpenFont(Nom_fonte(Numero_fonte), Taille);
if (!Fonte)
{
return NULL;
@ -235,21 +252,85 @@ byte *Rendu_Texte_TTF(const char *Chaine, int Taille, int AntiAlias, int *Largeu
*Largeur=Texte8Bit->w;
*Hauteur=Texte8Bit->h;
SDL_FreeSurface(Texte8Bit);
TTF_CloseFont(Fonte);
return BrosseRetour;
}
#endif
byte *Rendu_Texte_SFont(const char *Chaine, int Numero_fonte, int *Largeur, int *Hauteur)
{
SFont_Font *Fonte;
SDL_Surface * TexteColore;
SDL_Surface * Texte8Bit;
SDL_Surface *Surface_fonte;
byte * BrosseRetour;
// Chargement de la fonte
Surface_fonte=IMG_Load(Nom_fonte(Numero_fonte));
if (!Surface_fonte)
return NULL;
Fonte=SFont_InitFont(Surface_fonte);
if (!Fonte)
{
return NULL;
}
// Calcul des dimensions
*Hauteur=SFont_TextHeight(Fonte);
*Largeur=SFont_TextWidth(Fonte, Chaine);
// Allocation d'une surface SDL
TexteColore=SDL_CreateRGBSurface(SDL_SWSURFACE, *Largeur, *Hauteur, 24, 0, 0, 0, 0);
// Rendu du texte
SFont_Write(TexteColore, Fonte, 0, 0, Chaine);
if (!TexteColore)
{
SFont_FreeFont(Fonte);
return NULL;
}
Texte8Bit=SDL_DisplayFormat(TexteColore);
SDL_FreeSurface(TexteColore);
BrosseRetour=Surface_en_bytefield(Texte8Bit, NULL);
if (!BrosseRetour)
{
SDL_FreeSurface(TexteColore);
SDL_FreeSurface(Texte8Bit);
SFont_FreeFont(Fonte);
return NULL;
}
SDL_FreeSurface(Texte8Bit);
SFont_FreeFont(Fonte);
return BrosseRetour;
}
// Crée une brosse à partir des paramètres de texte demandés.
// Si cela réussit, la fonction place les dimensions dans Largeur et Hauteur,
// et retourne l'adresse du bloc d'octets.
byte *Rendu_Texte(const char *Chaine, int Taille, int AntiAlias, int *Largeur, int *Hauteur)
byte *Rendu_Texte(const char *Chaine, int Numero_fonte, int Taille, int AntiAlias, int *Largeur, int *Hauteur)
{
T_FONTE *Fonte = Liste_fontes_debut;
int Indice=Numero_fonte;
// Verification type de la fonte
if (Numero_fonte<0 ||Numero_fonte>=Fonte_nombre)
return NULL;
while (Indice--)
Fonte = Fonte->Suivante;
if (Fonte->EstTrueType)
{
#ifndef NOTTF
return Rendu_Texte_TTF(Chaine, Taille, AntiAlias, Largeur, Hauteur);
return Rendu_Texte_TTF(Chaine, Numero_fonte, Taille, AntiAlias, Largeur, Hauteur);
#else
return NULL;
#endif
}
else
{
return Rendu_Texte_SFont(Chaine, Numero_fonte, Largeur, Hauteur);
}
}

View File

@ -27,7 +27,7 @@ int Support_TrueType(void);
// Ajout d'une fonte à la liste.
void Ajout_fonte(char *Nom, int EstTrueType, int EstImage);
// Crée une brosse à partir des paramètres de texte demandés.
byte *Rendu_Texte(const char *Chaine, int Taille, int AntiAlias, int *Largeur, int *Hauteur);
byte *Rendu_Texte(const char *Chaine, int Numero_fonte, int Taille, int AntiAlias, int *Largeur, int *Hauteur);
// Trouve le libellé d'affichage d'une fonte par son numéro
char * Libelle_fonte(int Indice);
// Trouve le nom d'une fonte par son numéro