diff --git a/Makefile b/Makefile index 21ca3f45..579b97f4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ # Grafx2 - The Ultimate 256-color bitmap paint program # +# Copyright 2008 Peter Gordon # Copyright 2008 Yves Rizoud # Copyright 2007 Adrien Destugues # Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) @@ -19,14 +20,24 @@ # 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 = +else + TTFCOPT = + TTFLOPT = -L/usr/local/lib -lSDL_ttf +endif + + # Windows specific ifdef COMSPEC DELCOMMAND = del MKDIR = mkdir /s BIN = grafx2.exe CFGBIN = gfxcfg.exe - COPT = -W -Wall -O -g -ggdb `sdl-config --cflags` - LOPT = `sdl-config --libs` + COPT = -W -Wall -O -g -ggdb `sdl-config --cflags` $(TTFCOPT) + LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT) CC = gcc OBJDIR = obj/win32 else @@ -39,8 +50,8 @@ else MKDIR = mkdir -p BIN = grafx2 CFGBIN = gfxcfg - COPT = -Wall -c -gstabs -mcrt=newlib `sdl-config --cflags` - LOPT = `sdl-config --libs` -lpng -ljpeg -lz + COPT = -Wall -c -gstabs -mcrt=newlib `sdl-config --cflags` $(TTFCOPT) + LOPT = `sdl-config --libs` -lpng -ljpeg -lz $(TTFLOPT) CC = gcc OBJDIR = obj/amiga else @@ -53,14 +64,14 @@ else CC = i586-mingw32msvc-gcc BIN = grafx2.exe CFGBIN = gfxcfg.exe - COPT = -W -Wall -O -g -ggdb -Dmain=SDL_main `/usr/local/cross-tools/i386-mingw32/bin/sdl-config --cflags` - LOPT = -mwindows -lmingw32 -lSDLmain -lSDL -lshlwapi `/usr/local/cross-tools/i386-mingw32/bin/sdl-config --libs` + COPT = -W -Wall -O -g -ggdb -Dmain=SDL_main `/usr/local/cross-tools/i386-mingw32/bin/sdl-config --cflags` $(TTFCOPT) + LOPT = -mwindows -lmingw32 -lSDLmain -lSDL -lshlwapi `/usr/local/cross-tools/i386-mingw32/bin/sdl-config --libs` $(TTFLOPT) OBJDIR = obj/win32 else BIN = grafx2 CFGBIN = gfxcfg - COPT = -W -Wall -c -g `sdl-config --cflags` - LOPT = `sdl-config --libs` + COPT = -W -Wall -c -g `sdl-config --cflags` $(TTFCOPT) + LOPT = `sdl-config --libs` $(TTFLOPT) CC = gcc OBJDIR = obj/unix endif @@ -75,7 +86,7 @@ OBJ = $(OBJDIR)/main.o $(OBJDIR)/init.o $(OBJDIR)/graph.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)/version.o $(OBJDIR)/texte.o CFGOBJ = $(OBJDIR)/gfxcfg.o $(OBJDIR)/SFont.o $(OBJDIR)/clavier.o $(OBJDIR)/io.o all : $(BIN) $(CFGBIN) @@ -97,7 +108,7 @@ $(BIN) : $(OBJ) $(CC) $(OBJ) -o $(BIN) $(LOPT) $(CFGBIN) : $(CFGOBJ) - $(CC) $(CFGOBJ) -o $(CFGBIN) $(LOPT) -lSDL_image + $(CC) $(CFGOBJ) -o $(CFGBIN) $(LOPT) # SVN revision number version.c : @@ -118,7 +129,7 @@ $(OBJDIR) : $(MKDIR) $(OBJDIR) depend : - $(CC) -MM *.c | sed 's:^[^ ]:$(OBJDIR)/&:' > Makefile.dep + $(CC) -MM *.c | sed 's:^[^ ]:$$(OBJDIR)/&:' > Makefile.dep clean : diff --git a/Makefile.dep b/Makefile.dep index d8cdab71..8e87331b 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -3,7 +3,7 @@ $(OBJDIR)/aide.o: aide.c const.h struct.h global.h loadsave.h divers.h graph.h \ moteur.h tables_aide.h aide.h sdlscreen.h $(OBJDIR)/boutons.o: boutons.c const.h struct.h global.h loadsave.h divers.h \ graph.h moteur.h readline.h files.h init.h boutons.h operatio.h pages.h \ - erreurs.h readini.h saveini.h shade.h io.h aide.h sdlscreen.h + erreurs.h readini.h saveini.h shade.h io.h aide.h texte.h $(OBJDIR)/clavier.o: clavier.c global.h struct.h const.h loadsave.h $(OBJDIR)/divers.o: divers.c struct.h const.h sdlscreen.h global.h loadsave.h \ graph.h erreurs.h boutons.h moteur.h divers.h clavier.h @@ -23,13 +23,14 @@ $(OBJDIR)/main.o: main.c const.h struct.h global.h loadsave.h graph.h divers.h \ readini.h saveini.h linux.h io.h $(OBJDIR)/moteur.o: moteur.c const.h struct.h global.h loadsave.h graph.h divers.h \ special.h boutons.h operatio.h shade.h erreurs.h linux.h sdlscreen.h -$(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h erreurs.h +$(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h erreurs.h graph.h $(OBJDIR)/operatio.o: operatio.c const.h struct.h global.h loadsave.h divers.h \ moteur.h graph.h operatio.h boutons.h pages.h erreurs.h $(OBJDIR)/pages.o: pages.c global.h struct.h const.h loadsave.h pages.h graph.h \ erreurs.h linux.h $(OBJDIR)/palette.o: palette.c const.h struct.h global.h loadsave.h divers.h \ - graph.h moteur.h readline.h boutons.h pages.h aide.h sdlscreen.h + graph.h moteur.h readline.h boutons.h pages.h aide.h sdlscreen.h \ + erreurs.h op_c.h $(OBJDIR)/readini.o: readini.c const.h global.h struct.h loadsave.h graph.h $(OBJDIR)/readline.o: readline.c const.h struct.h global.h loadsave.h graph.h \ divers.h erreurs.h linux.h sdlscreen.h @@ -41,4 +42,5 @@ $(OBJDIR)/shade.o: shade.c global.h struct.h const.h loadsave.h graph.h moteur.h divers.h readline.h aide.h sdlscreen.h $(OBJDIR)/special.o: special.c const.h struct.h global.h loadsave.h graph.h \ moteur.h +$(OBJDIR)/texte.o: texte.c SFont.h sdlscreen.h struct.h const.h global.h loadsave.h $(OBJDIR)/version.o: version.c diff --git a/boutons.c b/boutons.c index 1b4c48db..3a4a6f01 100644 --- a/boutons.c +++ b/boutons.c @@ -46,7 +46,7 @@ #include "shade.h" #include "io.h" #include "aide.h" -#include "sdlscreen.h" +#include "texte.h" #ifdef __WATCOMC__ #include @@ -5707,7 +5707,167 @@ void Bouton_Effets(void) Afficher_curseur(); } +void Bouton_Texte() +{ + static char Chaine[256]=""; + static int Taille_police=16; + static int AntiAlias=0; + byte * Nouvelle_Brosse; + int Nouvelle_Largeur; + int Nouvelle_Hauteur; + int Bouton_clicke; + const int NB_FONTES=8; + char Buffer_taille[3]; + struct Fenetre_Bouton_special * Bouton_taille_texte; + struct Fenetre_Bouton_special * Bouton_texte; + byte A_redessiner=1; + + Ouvrir_fenetre(288,180,"Text"); + + // Texte saisi + Print_dans_fenetre(6,19,"Txt:",CM_Fonce,CM_Clair); + Fenetre_Definir_bouton_saisie(41,18,30); // 1 + Bouton_texte=Fenetre_Liste_boutons_special; + + // Bouton 'Clear Text' + Fenetre_Definir_bouton_normal(9,33,80,14,"Clear Txt",0,1,SDLK_LAST); // 2 + + // AA + 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); + + // Scroller des fontes + Fenetre_Definir_bouton_scroller(94,33,NB_FONTES*8,12,1,0); // 4 + + // Liste des fontes disponibles + Fenetre_Definir_bouton_special(110,32,172,NB_FONTES*8); // 5 + Fenetre_Afficher_cadre_creux(109, 31, 174, NB_FONTES*8+4); + + // Taille texte + Print_dans_fenetre(32,71,"Size:",CM_Fonce,CM_Clair); + Fenetre_Definir_bouton_saisie(35,84,3); // 6 + Bouton_taille_texte=Fenetre_Liste_boutons_special; + Fenetre_Definir_bouton_normal(18,84,14,11,"-",0,1,SDLK_LAST); // 7 + Fenetre_Definir_bouton_normal(64,84,14,11,"+",0,1,SDLK_LAST); // 8 + + // Preview + Fenetre_Definir_bouton_special(7,105,276,50); // 9 + Fenetre_Afficher_cadre_creux(6, 104, 278, 52); + + Fenetre_Definir_bouton_special(110,32,172,NB_FONTES*8); // 10 + + 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 + Display_Window(288,180); + + // Redessin + + // Chaine texte + Fenetre_Contenu_bouton_saisie(Bouton_texte,Chaine); + // Taille police + A_redessiner=1; + // -- + + while (1) + { + if (A_redessiner) + { + Num2str(Taille_police,Buffer_taille,3); + Fenetre_Contenu_bouton_saisie(Bouton_taille_texte,Buffer_taille); + A_redessiner=0; + Afficher_curseur(); + } + + Bouton_clicke=Fenetre_Bouton_clicke(); + switch(Bouton_clicke) + { + case 1: // Texte saisi + Effacer_curseur(); + Readline(43,20,Chaine,30,0); + Afficher_curseur(); + break; + + case 2: // Clear + Chaine[0]='\0'; + Effacer_curseur(); + Fenetre_Contenu_bouton_saisie(Bouton_texte,Chaine); + Afficher_curseur(); + break; + + case 3: // AA + AntiAlias = (AntiAlias==0); + Effacer_curseur(); + Print_dans_fenetre(13,53,AntiAlias?"AntiAlias":" No AA ", CM_Noir, CM_Clair); + Afficher_curseur(); + break; + + case 6: // Taille du texte (nombre) + Effacer_curseur(); + Readline(37,86,Buffer_taille,3,1); + Taille_police=atoi(Buffer_taille); + // On corrige les dimensions + if (Taille_police < 1) + { + Taille_police = 1; + } + else if (Taille_police>500) + { + Taille_police = 500; + } + A_redessiner=1; + break; + + case 7: // Taille - + if (Taille_police > 0) + { + Taille_police--; + Effacer_curseur(); + A_redessiner=1; + } + break; + + case 8: // Taille + + if (Taille_police < 255) + { + Taille_police++; + Effacer_curseur(); + A_redessiner=1; + } + break; + + + case 11: // OK + // Rendu texte + Nouvelle_Brosse = Rendu_Texte(Chaine, Taille_police, AntiAlias, &Nouvelle_Largeur, &Nouvelle_Hauteur); + if (!Nouvelle_Brosse) + { + Fermer_fenetre(); + Desenclencher_bouton(BOUTON_TEXTE); + Afficher_curseur(); + Erreur(0); + return; + } + Effacer_curseur(); + // On passe en brosse monochrome: + Changer_la_forme_du_pinceau(FORME_PINCEAU_BROSSE_COULEUR); + if (Brosse) free(Brosse); + + Brosse=Nouvelle_Brosse; + Brosse_Largeur=Nouvelle_Largeur; + Brosse_Hauteur=Nouvelle_Hauteur; + Brosse_Decalage_X=Brosse_Largeur>>1; + Brosse_Decalage_Y=Brosse_Hauteur>>1; + + // Attention pas de break + case 12: // Cancel + Fermer_fenetre(); + Desenclencher_bouton(BOUTON_TEXTE); + Afficher_curseur(); + return; + } + } +} diff --git a/boutons.h b/boutons.h index 46d921ac..f073dc51 100644 --- a/boutons.h +++ b/boutons.h @@ -61,6 +61,9 @@ void Bouton_Courbes_Switch_mode(void); void Bouton_Rectangle_vide(void); void Bouton_Rectangle_plein(void); +// Boutons relatifs au texte +void Bouton_Texte(void); + // Boutons relatifs aux dégradés void Bouton_Degrades(void); void Degrade_Charger_infos_du_tableau(int Indice); diff --git a/fonts/Tuffy.ttf b/fonts/Tuffy.ttf new file mode 100644 index 00000000..8ea64709 Binary files /dev/null and b/fonts/Tuffy.ttf differ diff --git a/gfx2.cfg b/gfx2.cfg index f0ea2855..59c4331d 100644 Binary files a/gfx2.cfg and b/gfx2.cfg differ diff --git a/init.c b/init.c index 3881a2a9..c8477567 100644 --- a/init.c +++ b/init.c @@ -735,7 +735,7 @@ void Initialisation_des_boutons(void) 123,18, 16,16, FORME_BOUTON_RECTANGLE, - Message_Non_disponible,Message_Non_disponible, + Bouton_Texte,Message_Non_disponible, Rien_du_tout, FAMILLE_INSTANTANE); /* diff --git a/main.c b/main.c index 0c5207ad..276cb8cb 100644 --- a/main.c +++ b/main.c @@ -345,6 +345,9 @@ void Initialisation_du_programme(int argc,char * argv[]) SDL_EnableUNICODE(SDL_ENABLE); SDL_WM_SetCaption("GrafX2 beta "POURCENTAGE_VERSION" - USE AT YOUR OWN RISK","grafx2.gif"); + // Texte + Initialisation_Texte(); + // On initialise tous les modes vidéo Definition_des_modes_video(); diff --git a/sdlscreen.c b/sdlscreen.c index bf229eb1..53ffbcb0 100644 --- a/sdlscreen.c +++ b/sdlscreen.c @@ -559,4 +559,50 @@ void UpdateRect(short X, short Y, unsigned short Largeur, unsigned short Hauteur #if (METHODE_UPDATE == METHODE_UPDATE_PLEINE_PAGE) Update_necessaire=1; #endif + +} + +// Convertit une SDL_Surface (couleurs indexées ou RGB) en tableau de bytes (couleurs indexées) +// Si on passe NULL comme destination, elle est allouée par malloc(). Sinon, +// attention aux dimensions! +byte * Surface_en_bytefield(SDL_Surface *Source, byte * Destination) +{ + byte *Src; + byte *Dst; + int Y; + int Reste; + + // Support seulement des images 256 couleurs + if (Source->format->BytesPerPixel != 1) + return NULL; + + if (Source->w & 3) + Reste=4-(Source->w&3); + else + Reste=0; + + if (Destination==NULL) + Destination=(byte *)malloc(Source->w*Source->h); + + Dst=Destination; + Src=(byte *)(Source->pixels); + for(Y=0; Y < Source->h; Y++) + { + memcpy(Dst, Src,Source->w); + Dst += Source->w; + Src += Source->w + Reste; + } + return Destination; + +} + +// Convertit un index de palette en couleur RGB 24 bits +SDL_Color Conversion_couleur_SDL(byte Index) +{ + SDL_Color Couleur; + Couleur.r = (Principal_Palette[Index].R<<2) + (Principal_Palette[Index].R>>4); + Couleur.g = (Principal_Palette[Index].V<<2) + (Principal_Palette[Index].V>>4); + Couleur.b = (Principal_Palette[Index].B<<2) + (Principal_Palette[Index].B>>4); + Couleur.unused = 255; + return Couleur; } diff --git a/sdlscreen.h b/sdlscreen.h index b4fffe7b..5988c61b 100644 --- a/sdlscreen.h +++ b/sdlscreen.h @@ -52,6 +52,7 @@ void UpdateRect(short X, short Y, unsigned short Largeur, unsigned short Hauteur); void Flush_update(void); - + byte * Surface_en_bytefield(SDL_Surface *Source, byte * Destination); + SDL_Color Conversion_couleur_SDL(byte); #endif // SDLSCREEN_H_INCLUDED diff --git a/texte.c b/texte.c new file mode 100644 index 00000000..e7e38505 --- /dev/null +++ b/texte.c @@ -0,0 +1,139 @@ +/* Grafx2 - The Ultimate 256-color bitmap paint program + + Copyright 2008 Yves Rizoud + Copyright 2008 Adrien Destugues + Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) + + Grafx2 is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; version 2 + of the License. + + Grafx2 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grafx2; if not, see or + write to the Free Software Foundation, Inc., + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +// Pour désactiver le support TrueType, définir NOTTF +// To disable TrueType support, define NOTTF + + +// TrueType +#ifndef NOTTF +#include +#endif +// SFont +#include +#include "SFont.h" + +#include "sdlscreen.h" +#include "struct.h" +#include "global.h" + + +void Initialisation_Texte(void) +{ + #ifndef NOTTF + TTF_Init(); + #endif +} + + +#ifndef NOTTF +byte *Rendu_Texte_TTF(const char *Chaine, int Taille, int AntiAlias, int *Largeur, int *Hauteur) +{ + TTF_Font *Police; + SDL_Surface * TexteColore; + SDL_Surface * Texte8Bit; + byte * BrosseRetour; + int Indice; + SDL_Color PaletteSDL[256]; + + SDL_Color Couleur_Avant; // FIXME couleur avant + SDL_Color Couleur_Arriere; // FIXME couleur arriere + + // Chargement de la police + Police=TTF_OpenFont("fonts/Tuffy.ttf", Taille); // FIXME police en dur + if (!Police) + { + return NULL; + } + // Couleurs + Couleur_Avant = Conversion_couleur_SDL(Fore_color); + Couleur_Arriere = Conversion_couleur_SDL(Back_color); + + // Rendu du texte: crée une surface SDL RGB 24bits + if (AntiAlias) + TexteColore=TTF_RenderText_Shaded(Police, Chaine, Couleur_Avant, Couleur_Arriere ); + else + TexteColore=TTF_RenderText_Solid(Police, Chaine, Couleur_Avant); + if (!TexteColore) + { + TTF_CloseFont(Police); + return NULL; + } + + Texte8Bit=SDL_DisplayFormat(TexteColore); + /* + + Texte8Bit=SDL_CreateRGBSurface(SDL_SWSURFACE, TexteColore->w, TexteColore->h, 8, 0, 0, 0, 0); + if (!Texte8Bit) + { + SDL_FreeSurface(TexteColore); + TTF_CloseFont(Police); + return NULL; + } + + for(Indice=0;Indice<256;Indice++) + { + PaletteSDL[Indice].r=(Principal_Palette[Indice].R<<2) + (Principal_Palette[Indice].R>>4); //Les couleurs VGA ne vont que de 0 à 63 + PaletteSDL[Indice].g=(Principal_Palette[Indice].V<<2) + (Principal_Palette[Indice].V>>4); + PaletteSDL[Indice].b=(Principal_Palette[Indice].B<<2) + (Principal_Palette[Indice].B>>4); + } + SDL_SetPalette(Texte8Bit,SDL_PHYSPAL|SDL_LOGPAL,PaletteSDL,0,256); + SDL_BlitSurface(TexteColore, NULL, Texte8Bit, NULL); + */ + SDL_FreeSurface(TexteColore); + + BrosseRetour=Surface_en_bytefield(Texte8Bit, NULL); + if (!BrosseRetour) + { + SDL_FreeSurface(TexteColore); + SDL_FreeSurface(Texte8Bit); + TTF_CloseFont(Police); + return NULL; + } + if (!AntiAlias) + { + // Mappage des couleurs + /*for (Indice=0; Indice < Texte8Bit->w * Texte8Bit->h; Indice++) + { + if () + *(BrosseRetour+Indice)=*(BrosseRetour+Indice) ? (*(BrosseRetour+Indice)+96-15) : 0; + }*/ + } + + *Largeur=Texte8Bit->w; + *Hauteur=Texte8Bit->h; + SDL_FreeSurface(Texte8Bit); + + return BrosseRetour; +} +#endif + +byte *Rendu_Texte(const char *Chaine, int Taille, int AntiAlias, int *Largeur, int *Hauteur) +{ + #ifndef NOTTF + return Rendu_Texte_TTF(Chaine, Taille, AntiAlias, Largeur, Hauteur); + #else + return NULL; + #endif +} + + diff --git a/texte.h b/texte.h new file mode 100644 index 00000000..7a31e7cc --- /dev/null +++ b/texte.h @@ -0,0 +1,26 @@ +/* Grafx2 - The Ultimate 256-color bitmap paint program + + Copyright 2008 Yves Rizoud + Copyright 2008 Adrien Destugues + Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) + + Grafx2 is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; version 2 + of the License. + + Grafx2 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grafx2; if not, see or + write to the Free Software Foundation, Inc., + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +void Initialisation_Texte(void); +byte *Rendu_Texte(const char *Chaine, int Taille, int AntiAlias, int *Largeur, int *Hauteur); + +