work in progress on Text menu
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@314 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
3fb9a91c8f
commit
cc81845f7b
54
boutons.c
54
boutons.c
@ -5725,6 +5725,16 @@ void Bouton_Effets(void)
|
|||||||
Afficher_curseur();
|
Afficher_curseur();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Affiche tout le selecteur de fontes
|
||||||
|
void Dessiner_selecteur_fontes(short X, short Y, short Debut_liste, short Position_curseur, short Nombre_visibles)
|
||||||
|
{
|
||||||
|
int Indice;
|
||||||
|
for (Indice=0; Indice < Nombre_visibles; Indice++)
|
||||||
|
{
|
||||||
|
Print_dans_fenetre(X,Y+Indice*8,Libelle_fonte(Indice+Debut_liste), CM_Noir, (Position_curseur==Indice)?CM_Fonce:CM_Clair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Bouton_Texte()
|
void Bouton_Texte()
|
||||||
{
|
{
|
||||||
static char Chaine[256]="";
|
static char Chaine[256]="";
|
||||||
@ -5740,6 +5750,8 @@ void Bouton_Texte()
|
|||||||
struct Fenetre_Bouton_special * Bouton_taille_texte;
|
struct Fenetre_Bouton_special * Bouton_taille_texte;
|
||||||
struct Fenetre_Bouton_special * Bouton_texte;
|
struct Fenetre_Bouton_special * Bouton_texte;
|
||||||
byte A_redessiner=1;
|
byte A_redessiner=1;
|
||||||
|
short Debut_liste, Position_curseur; // Selecteur de fonte
|
||||||
|
short Temp;
|
||||||
|
|
||||||
Ouvrir_fenetre(288,180,"Text");
|
Ouvrir_fenetre(288,180,"Text");
|
||||||
|
|
||||||
@ -5753,14 +5765,17 @@ void Bouton_Texte()
|
|||||||
|
|
||||||
// AA
|
// AA
|
||||||
Fenetre_Definir_bouton_normal(9,51,80,14,"",0,1,SDLK_LAST); // 3
|
Fenetre_Definir_bouton_normal(9,51,80,14,"",0,1,SDLK_LAST); // 3
|
||||||
Print_dans_fenetre(13,53,AntiAlias?"AntiAlias":" No AA ", CM_Noir, CM_Clair);
|
Print_dans_fenetre(13,54,AntiAlias?"AntiAlias":" No AA ", CM_Noir, CM_Clair);
|
||||||
|
|
||||||
// Scroller des fontes
|
// Scroller des fontes
|
||||||
Fenetre_Definir_bouton_scroller(94,33,NB_FONTES*8,12,1,0); // 4
|
Fenetre_Definir_bouton_scroller(94,33,NB_FONTES*8,Fonte_nombre,NB_FONTES,0); // 4
|
||||||
|
|
||||||
// Liste des fontes disponibles
|
// Liste des fontes disponibles
|
||||||
Fenetre_Definir_bouton_special(110,32,172,NB_FONTES*8); // 5
|
Fenetre_Definir_bouton_special(111,32,168,NB_FONTES*8); // 5
|
||||||
Fenetre_Afficher_cadre_creux(109, 31, 174, NB_FONTES*8+4);
|
Fenetre_Afficher_cadre_creux(110, 31, 170, NB_FONTES*8+4);
|
||||||
|
Debut_liste=0;
|
||||||
|
Position_curseur=0;
|
||||||
|
|
||||||
|
|
||||||
// Taille texte
|
// Taille texte
|
||||||
Print_dans_fenetre(32,71,"Size:",CM_Fonce,CM_Clair);
|
Print_dans_fenetre(32,71,"Size:",CM_Fonce,CM_Clair);
|
||||||
@ -5773,7 +5788,7 @@ void Bouton_Texte()
|
|||||||
Fenetre_Definir_bouton_special(7,105,276,50); // 9
|
Fenetre_Definir_bouton_special(7,105,276,50); // 9
|
||||||
Fenetre_Afficher_cadre_creux(6, 104, 278, 52);
|
Fenetre_Afficher_cadre_creux(6, 104, 278, 52);
|
||||||
|
|
||||||
Fenetre_Definir_bouton_special(110,32,172,NB_FONTES*8); // 10
|
Fenetre_Definir_bouton_special(0,0,1,1); // 10 ???
|
||||||
|
|
||||||
Fenetre_Definir_bouton_normal(7,161,40,14,"OK",0,1,SDLK_RETURN); // 11
|
Fenetre_Definir_bouton_normal(7,161,40,14,"OK",0,1,SDLK_RETURN); // 11
|
||||||
Fenetre_Definir_bouton_normal(53,161,60,14,"Cancel",0,1,SDLK_ESCAPE); // 12
|
Fenetre_Definir_bouton_normal(53,161,60,14,"Cancel",0,1,SDLK_ESCAPE); // 12
|
||||||
@ -5791,8 +5806,12 @@ void Bouton_Texte()
|
|||||||
{
|
{
|
||||||
if (A_redessiner)
|
if (A_redessiner)
|
||||||
{
|
{
|
||||||
|
// Taille
|
||||||
Num2str(Taille_police,Buffer_taille,3);
|
Num2str(Taille_police,Buffer_taille,3);
|
||||||
Fenetre_Contenu_bouton_saisie(Bouton_taille_texte,Buffer_taille);
|
Fenetre_Contenu_bouton_saisie(Bouton_taille_texte,Buffer_taille);
|
||||||
|
// Selecteur de fonte
|
||||||
|
Dessiner_selecteur_fontes(111, 33, Debut_liste, Position_curseur, NB_FONTES);
|
||||||
|
|
||||||
A_redessiner=0;
|
A_redessiner=0;
|
||||||
Afficher_curseur();
|
Afficher_curseur();
|
||||||
}
|
}
|
||||||
@ -5816,10 +5835,33 @@ void Bouton_Texte()
|
|||||||
case 3: // AA
|
case 3: // AA
|
||||||
AntiAlias = (AntiAlias==0);
|
AntiAlias = (AntiAlias==0);
|
||||||
Effacer_curseur();
|
Effacer_curseur();
|
||||||
Print_dans_fenetre(13,53,AntiAlias?"AntiAlias":" No AA ", CM_Noir, CM_Clair);
|
Print_dans_fenetre(13,54,AntiAlias?"AntiAlias":" No AA ", CM_Noir, CM_Clair);
|
||||||
Afficher_curseur();
|
Afficher_curseur();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 4: // Scroller des fontes
|
||||||
|
if (Debut_liste!=Fenetre_Attribut2)
|
||||||
|
{
|
||||||
|
Position_curseur+=Debut_liste;
|
||||||
|
Debut_liste=Fenetre_Attribut2;
|
||||||
|
Position_curseur-=Debut_liste;
|
||||||
|
// On affiche à nouveau la liste
|
||||||
|
Effacer_curseur();
|
||||||
|
A_redessiner=1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5: // Selecteur de fonte
|
||||||
|
Temp=(((Mouse_Y-Fenetre_Pos_Y)/Menu_Facteur_Y)-32)>>3;
|
||||||
|
if (Temp!=Position_curseur)
|
||||||
|
{
|
||||||
|
Position_curseur=Temp;
|
||||||
|
// On affiche à nouveau la liste
|
||||||
|
Effacer_curseur();
|
||||||
|
A_redessiner=1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 6: // Taille du texte (nombre)
|
case 6: // Taille du texte (nombre)
|
||||||
Effacer_curseur();
|
Effacer_curseur();
|
||||||
Readline(37,86,Buffer_taille,3,1);
|
Readline(37,86,Buffer_taille,3,1);
|
||||||
|
|||||||
123
texte.c
123
texte.c
@ -23,6 +23,8 @@
|
|||||||
// Pour désactiver le support TrueType, définir NOTTF
|
// Pour désactiver le support TrueType, définir NOTTF
|
||||||
// To disable TrueType support, define NOTTF
|
// To disable TrueType support, define NOTTF
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
// TrueType
|
// TrueType
|
||||||
#ifndef NOTTF
|
#ifndef NOTTF
|
||||||
@ -32,15 +34,112 @@
|
|||||||
#include <SDL/SDL_image.h>
|
#include <SDL/SDL_image.h>
|
||||||
#include "SFont.h"
|
#include "SFont.h"
|
||||||
|
|
||||||
#include "sdlscreen.h"
|
|
||||||
#include "struct.h"
|
#include "struct.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include "sdlscreen.h"
|
||||||
|
#include "io.h"
|
||||||
|
|
||||||
|
typedef struct T_FONTE
|
||||||
|
{
|
||||||
|
char * Nom;
|
||||||
|
int EstTrueType;
|
||||||
|
int EstImage;
|
||||||
|
|
||||||
|
// Liste chainée simple
|
||||||
|
struct T_FONTE * Suivante;
|
||||||
|
} T_FONTE;
|
||||||
|
// Liste chainée des polices de texte
|
||||||
|
T_FONTE * Liste_fontes_debut;
|
||||||
|
T_FONTE * Liste_fontes_fin;
|
||||||
|
int Fonte_nombre;
|
||||||
|
|
||||||
|
// Ajout d'une fonte à la liste.
|
||||||
|
void Ajout_fonte(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->EstTrueType = EstTrueType;
|
||||||
|
Fonte->EstImage = EstImage;
|
||||||
|
|
||||||
|
// Gestion Liste
|
||||||
|
Fonte->Suivante = NULL;
|
||||||
|
if (Liste_fontes_debut==NULL)
|
||||||
|
Liste_fontes_debut = Fonte;
|
||||||
|
else
|
||||||
|
Liste_fontes_fin->Suivante = Fonte;
|
||||||
|
Liste_fontes_fin = Fonte;
|
||||||
|
Fonte_nombre++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trouve le nom d'une fonte par son numéro
|
||||||
|
char * Nom_fonte(int Indice)
|
||||||
|
{
|
||||||
|
T_FONTE *Fonte = Liste_fontes_debut;
|
||||||
|
if (Indice<0 ||Indice>=Fonte_nombre)
|
||||||
|
return "";
|
||||||
|
while (Indice--)
|
||||||
|
Fonte = Fonte->Suivante;
|
||||||
|
return Fonte->Nom;
|
||||||
|
}
|
||||||
|
// Trouve le libellé d'affichage d'une fonte par son numéro
|
||||||
|
char * Libelle_fonte(int Indice)
|
||||||
|
{
|
||||||
|
T_FONTE *Fonte;
|
||||||
|
static char Libelle[22];
|
||||||
|
char * Nom_fonte;
|
||||||
|
|
||||||
|
strcpy(Libelle, " ");
|
||||||
|
|
||||||
|
// Recherche de la fonte
|
||||||
|
Fonte = Liste_fontes_debut;
|
||||||
|
if (Indice<0 ||Indice>=Fonte_nombre)
|
||||||
|
return Libelle;
|
||||||
|
while (Indice--)
|
||||||
|
Fonte = Fonte->Suivante;
|
||||||
|
|
||||||
|
// Libellé
|
||||||
|
if (Fonte->EstTrueType)
|
||||||
|
Libelle[19]=Libelle[20]='T'; // Logo TT
|
||||||
|
Nom_fonte=Position_dernier_slash(Fonte->Nom);
|
||||||
|
if (Nom_fonte==NULL)
|
||||||
|
Nom_fonte=Fonte->Nom;
|
||||||
|
else
|
||||||
|
Nom_fonte++;
|
||||||
|
for (Indice=0; Indice < 19 && Nom_fonte[Indice]!='\0' && Nom_fonte[Indice]!='.'; Indice++)
|
||||||
|
Libelle[Indice]=Nom_fonte[Indice];
|
||||||
|
return Libelle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialisation à faire une fois au début du programme
|
// Initialisation à faire une fois au début du programme
|
||||||
void Initialisation_Texte(void)
|
void Initialisation_Texte(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifndef NOTTF
|
#ifndef NOTTF
|
||||||
|
// Initialisation de TTF
|
||||||
TTF_Init();
|
TTF_Init();
|
||||||
|
|
||||||
|
// 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);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,19 +157,19 @@ int Support_TrueType()
|
|||||||
#ifndef NOTTF
|
#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 Taille, int AntiAlias, int *Largeur, int *Hauteur)
|
||||||
{
|
{
|
||||||
TTF_Font *Police;
|
TTF_Font *Fonte;
|
||||||
SDL_Surface * TexteColore;
|
SDL_Surface * TexteColore;
|
||||||
SDL_Surface * Texte8Bit;
|
SDL_Surface * Texte8Bit;
|
||||||
byte * BrosseRetour;
|
byte * BrosseRetour;
|
||||||
int Indice;
|
int Indice;
|
||||||
SDL_Color PaletteSDL[256];
|
SDL_Color PaletteSDL[256];
|
||||||
|
|
||||||
SDL_Color Couleur_Avant; // FIXME couleur avant
|
SDL_Color Couleur_Avant;
|
||||||
SDL_Color Couleur_Arriere; // FIXME couleur arriere
|
SDL_Color Couleur_Arriere;
|
||||||
|
|
||||||
// Chargement de la police
|
// Chargement de la fonte
|
||||||
Police=TTF_OpenFont("fonts/Tuffy.ttf", Taille); // FIXME police en dur
|
Fonte=TTF_OpenFont(Nom_fonte(0), Taille); // FIXME fonte en dur
|
||||||
if (!Police)
|
if (!Fonte)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -80,12 +179,12 @@ byte *Rendu_Texte_TTF(const char *Chaine, int Taille, int AntiAlias, int *Largeu
|
|||||||
|
|
||||||
// Rendu du texte: crée une surface SDL RGB 24bits
|
// Rendu du texte: crée une surface SDL RGB 24bits
|
||||||
if (AntiAlias)
|
if (AntiAlias)
|
||||||
TexteColore=TTF_RenderText_Shaded(Police, Chaine, Couleur_Avant, Couleur_Arriere );
|
TexteColore=TTF_RenderText_Shaded(Fonte, Chaine, Couleur_Avant, Couleur_Arriere );
|
||||||
else
|
else
|
||||||
TexteColore=TTF_RenderText_Solid(Police, Chaine, Couleur_Avant);
|
TexteColore=TTF_RenderText_Solid(Fonte, Chaine, Couleur_Avant);
|
||||||
if (!TexteColore)
|
if (!TexteColore)
|
||||||
{
|
{
|
||||||
TTF_CloseFont(Police);
|
TTF_CloseFont(Fonte);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +195,7 @@ byte *Rendu_Texte_TTF(const char *Chaine, int Taille, int AntiAlias, int *Largeu
|
|||||||
if (!Texte8Bit)
|
if (!Texte8Bit)
|
||||||
{
|
{
|
||||||
SDL_FreeSurface(TexteColore);
|
SDL_FreeSurface(TexteColore);
|
||||||
TTF_CloseFont(Police);
|
TTF_CloseFont(Fonte);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +215,7 @@ byte *Rendu_Texte_TTF(const char *Chaine, int Taille, int AntiAlias, int *Largeu
|
|||||||
{
|
{
|
||||||
SDL_FreeSurface(TexteColore);
|
SDL_FreeSurface(TexteColore);
|
||||||
SDL_FreeSurface(Texte8Bit);
|
SDL_FreeSurface(Texte8Bit);
|
||||||
TTF_CloseFont(Police);
|
TTF_CloseFont(Fonte);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!AntiAlias)
|
if (!AntiAlias)
|
||||||
|
|||||||
13
texte.h
13
texte.h
@ -20,6 +20,17 @@
|
|||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int Support_TrueType();
|
// Initialisation à faire une fois au début du programme
|
||||||
void Initialisation_Texte(void);
|
void Initialisation_Texte(void);
|
||||||
|
// Informe si texte.c a été compilé avec l'option de support TrueType ou pas.
|
||||||
|
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 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
|
||||||
|
char * Nom_fonte(int Indice);
|
||||||
|
// Nombre de fontes déclarées
|
||||||
|
extern int Fonte_nombre;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user