Mostly some cleanups.

Also added two experimetal functions, Ouvrir_popup and Fermer_popup, and started to implement a (commented) example popup menu for selecting freehand draw mode.
But it seems there are problem if doing a while(Mouse_K), Mouse_K seems to be reset when the mouse moves, or in some other place. Time to sleep so i'll continue that tomorrow.


git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@474 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2009-01-11 21:59:10 +00:00
parent 7c4d2675ad
commit ab5f789fdf
11 changed files with 182 additions and 23 deletions

1
aide.c
View File

@ -417,6 +417,7 @@ void Bouton_Stats(void)
} }
#else #else
// Free disk space is only for shows. Other platforms can display 0. // Free disk space is only for shows. Other platforms can display 0.
#warning "Missing code for your platform !!! Check and correct please :)"
Taille=0; Taille=0;
#endif #endif

View File

@ -1670,6 +1670,7 @@ void Bouton_Dessin(void)
void Bouton_Dessin_Switch_mode(void) void Bouton_Dessin_Switch_mode(void)
{ {
/* ANCIEN CODE SANS POPUPS */
Mode_de_dessin_en_cours++; Mode_de_dessin_en_cours++;
if (Mode_de_dessin_en_cours>OPERATION_DESSIN_POINT) if (Mode_de_dessin_en_cours>OPERATION_DESSIN_POINT)
Mode_de_dessin_en_cours=OPERATION_DESSIN_CONTINU; Mode_de_dessin_en_cours=OPERATION_DESSIN_CONTINU;
@ -1678,6 +1679,35 @@ void Bouton_Dessin_Switch_mode(void)
Afficher_sprite_dans_menu(BOUTON_DESSIN,Mode_de_dessin_en_cours); Afficher_sprite_dans_menu(BOUTON_DESSIN,Mode_de_dessin_en_cours);
Demarrer_pile_operation(Mode_de_dessin_en_cours); Demarrer_pile_operation(Mode_de_dessin_en_cours);
Afficher_curseur(); Afficher_curseur();
/* NOUVEAU CODE AVEC POPUP (EN COURS DE TEST) ***
short Bouton_clicke;
Ouvrir_popup(16,Menu_Ordonnee/Menu_Facteur_X-32,18,50);
Fenetre_Definir_bouton_normal(1,1,16,16,"A",0,1,SDLK_ESCAPE); // 1
Afficher_curseur();
UpdateRect(16*Menu_Facteur_X,Menu_Ordonnee-32*Menu_Facteur_X,18*Menu_Facteur_X,50*Menu_Facteur_X);
do
{
while(!Get_input())Wait_VBL();
Bouton_clicke = Fenetre_Numero_bouton_clicke();
switch(Bouton_clicke)
{
case 1:
Mode_de_dessin_en_cours++;
if (Mode_de_dessin_en_cours>OPERATION_DESSIN_POINT)
Mode_de_dessin_en_cours=OPERATION_DESSIN_CONTINU;
break;
}
}
while (Mouse_K);
Fermer_popup();
Afficher_sprite_dans_menu(BOUTON_DESSIN,Mode_de_dessin_en_cours);
Demarrer_pile_operation(Mode_de_dessin_en_cours);
Afficher_curseur();
*/
} }
@ -3024,6 +3054,7 @@ byte Bouton_Load_ou_Save(byte Load, byte Image)
// On restaure les données de l'image qui ont certainement été modifiées // On restaure les données de l'image qui ont certainement été modifiées
// par la preview. // par la preview.
memcpy(Principal_Palette,Palette_initiale,sizeof(T_Palette)); memcpy(Principal_Palette,Palette_initiale,sizeof(T_Palette));
Set_palette(Principal_Palette);
Back_color=Back_color_initiale; Back_color=Back_color_initiale;
Principal_Image_modifiee=Image_modifiee_initiale; Principal_Image_modifiee=Image_modifiee_initiale;
Principal_Largeur_image=Largeur_image_initiale; Principal_Largeur_image=Largeur_image_initiale;

View File

@ -1127,17 +1127,14 @@ void Zoomer_une_ligne(byte* Ligne_originale, byte* Ligne_zoomee,
// Indique quelle est la mémoire disponible // Indique quelle est la mémoire disponible
unsigned long Memoire_libre(void) unsigned long Memoire_libre(void)
{ {
// On appelle la fonction qui optimise la mémoire libre afin d'en
// regagner un maximum. Sinon, tous les "free" libèrent une mémoire qui
// n'est pas prise en compte par la fonction, et on se retrouve avec un
// manque alarmant de mémoire.
/*
A revoir, mais est-ce vraiment utile?
_heapmin();
*/
// Memory is no longer relevant. If there is ANY problem or doubt here, // Memory is no longer relevant. If there is ANY problem or doubt here,
// you can simply return 10*1024*1024 (10Mb), to make the "Pages"something // you can simply return 10*1024*1024 (10Mb), to make the "Pages"something
// memory allocation functions happy. // memory allocation functions happy.
// However, it is still a good idea to make a proper function if you can...
// If Grafx2 thinks the memory is full, weird things may happen. And if memory
// ever becomes full and you're still saying there are 10MB free here, the
// program will crash without saving any picture backup ! You've been warned...
#if defined(__WIN32__) #if defined(__WIN32__)
MEMORYSTATUSEX mstt; MEMORYSTATUSEX mstt;
mstt.dwLength = sizeof(MEMORYSTATUSEX); mstt.dwLength = sizeof(MEMORYSTATUSEX);
@ -1156,6 +1153,7 @@ unsigned long Memoire_libre(void)
#elif defined(__BEOS__) || defined(__HAIKU__) || defined(__SKYOS__) || defined(__amigaos4__) #elif defined(__BEOS__) || defined(__HAIKU__) || defined(__SKYOS__) || defined(__amigaos4__)
// No <sys/sysctl.h> on BeOS or Haiku // No <sys/sysctl.h> on BeOS or Haiku
// AvailMem is misleading on os4 (os4 caches stuff in memory that you can still allocate) // AvailMem is misleading on os4 (os4 caches stuff in memory that you can still allocate)
#warning "There is missing code there for your platform ! please check and correct :)"
return 10*1024*1024; return 10*1024*1024;
#elif defined(__AROS__) || defined(__MORPHOS__) #elif defined(__AROS__) || defined(__MORPHOS__)
return AvailMem(MEMF_ANY); return AvailMem(MEMF_ANY);

View File

@ -315,7 +315,10 @@ void Lire_liste_des_lecteurs(void)
} }
// Other platforms: simply read the "static" list of Drives. // Other platforms: simply read the "static" list of Drives.
// This should be made dynamic because in the multitask world, user can mount new drives,
// connect to network ones, and so on, while Grafx2 is running.
#else #else
#warning "Your platform is missing some specific code here ! please check and correct ! :)"
for (Indice=0; Indice<Nb_drives; Indice++) for (Indice=0; Indice<Nb_drives; Indice++)
{ {
// Add the drive's name ("c:\\", "/" etc.) to the list // Add the drive's name ("c:\\", "/" etc.) to the list

View File

@ -593,6 +593,7 @@ bool Verifier_ecriture_possible()
{ {
#ifdef __amigaos4__ #ifdef __amigaos4__
// TODO: Make it work :) // TODO: Make it work :)
#warning "There is some code missing here for your platform ! please check and correct :)"
return 1; return 1;
#else #else
// Doesn't work on OS4. // Doesn't work on OS4.

View File

@ -282,6 +282,7 @@ void Initialiser_mode_video(int Largeur, int Hauteur, int Fullscreen)
} }
// La largeur doit être un multiple de 4 // La largeur doit être un multiple de 4
#ifdef __amigaos4__ #ifdef __amigaos4__
// On AmigaOS the systems adds some more constraints on that ...
Largeur = (Largeur + 15) & 0xFFFFFFF0; Largeur = (Largeur + 15) & 0xFFFFFFF0;
#else #else
Largeur = (Largeur + 3 ) & 0xFFFFFFFC; Largeur = (Largeur + 3 ) & 0xFFFFFFFC;

View File

@ -489,11 +489,14 @@ void Charger_image(byte Image)
{ {
// On peut charger le fichier: // On peut charger le fichier:
Image_24b=0; Image_24b=0;
// Dans certains cas il est possible que le chargement plante
// après avoir modifié la palette. TODO
Format_Load[Format](); Format_Load[Format]();
// FIXME Le déclenchement de cette erreur 0 après lecture ratée d'une image produit un flash rouge, puis restaure la palette de l'image. Il faudrait plutot restaurer la palette qu'il y avait avant d'avoir tout cassé, non ?
if (Erreur_fichier>0) if (Erreur_fichier>0)
{
Erreur(0); Erreur(0);
}
if (Image_24b) if (Image_24b)
{ {

15
main.c
View File

@ -84,13 +84,12 @@ void Erreur_fonction(int Code, const char *Nom_fichier, int Numero_ligne, const
{ {
T_Palette Palette_temporaire; T_Palette Palette_temporaire;
int Indice; int Indice;
printf("Code %d\n", Code); printf("Error number %d occured in file %s, line %d, function %s.\n", Code, Nom_fichier,Numero_ligne,Nom_fonction);
printf("File %s\n", Nom_fichier);
printf("Line %d\n", Numero_ligne);
printf("Function %s\n", Nom_fonction);
if (Code==0) if (Code==0)
{ {
// L'erreur 0 n'est pas une vraie erreur, elle fait seulement un flash rouge de l'écran pour dire qu'il y a un problème.
// Toutes les autres erreurs déclenchent toujours une sortie en catastrophe du programme !
memcpy(Palette_temporaire,Principal_Palette,sizeof(T_Palette)); memcpy(Palette_temporaire,Principal_Palette,sizeof(T_Palette));
for (Indice=0;Indice<=255;Indice++) for (Indice=0;Indice<=255;Indice++)
Palette_temporaire[Indice].R=255; Palette_temporaire[Indice].R=255;
@ -119,11 +118,7 @@ void Erreur_fonction(int Code, const char *Nom_fichier, int Numero_ligne, const
printf("Please run GFXCFG to update this file.\n"); printf("Please run GFXCFG to update this file.\n");
break; break;
case ERREUR_MEMOIRE : printf("Error: Not enough memory!\n\n"); case ERREUR_MEMOIRE : printf("Error: Not enough memory!\n\n");
printf("You should try removing memory drivers and useless TSRs to free some memory.\n\n"); printf("You should try exiting other programs to free some bytes for Grafx2.\n\n");
printf("If it still doesn't work, try running GFX2_MEM.BAT if you have got DOS4GW.EXE\n");
printf("somewhere on your disk (after having edited the batch file).\n");
printf("This also requires 16 free Megabytes on your disk to create the memory cache.\n");
printf("This will slow down the program but, at least, you'll get GrafX2 running.\n");
break; break;
case ERREUR_DRIVER_SOURIS : printf("Error: No mouse detected!\n"); case ERREUR_DRIVER_SOURIS : printf("Error: No mouse detected!\n");
printf("Check if a mouse driver is installed and if your mouse is correctly connected.\n"); printf("Check if a mouse driver is installed and if your mouse is correctly connected.\n");
@ -144,7 +139,7 @@ void Erreur_fonction(int Code, const char *Nom_fichier, int Numero_ligne, const
break; break;
case ERREUR_INI_CORROMPU : printf("Error: File GFX2.INI is corrupt!\n"); case ERREUR_INI_CORROMPU : printf("Error: File GFX2.INI is corrupt!\n");
printf("It contains bad values at line %d.\n",Ligne_INI); printf("It contains bad values at line %d.\n",Ligne_INI);
printf("You can re-generate it by deleting the file and running grafX2 again.\n"); printf("You can re-generate it by deleting the file and running GrafX2 again.\n");
break; break;
case ERREUR_SAUVEGARDE_INI : printf("Error: Cannot rewrite file GFX2.INI!\n"); case ERREUR_SAUVEGARDE_INI : printf("Error: Cannot rewrite file GFX2.INI!\n");
break; break;

125
moteur.c
View File

@ -56,7 +56,7 @@ byte Smooth_Mode_avant_annulation;
byte Tiling_Mode_avant_annulation; byte Tiling_Mode_avant_annulation;
fonction_effet Fonction_effet_avant_annulation; fonction_effet Fonction_effet_avant_annulation;
byte * Fond_fenetre[8]; byte* Fond_fenetre[8];
void Annuler_les_effets(void) void Annuler_les_effets(void)
{ {
@ -145,6 +145,7 @@ char * TITRE_BOUTON[NB_BOUTONS]=
void Sauve_fond(byte **Buffer, int Pos_X, int Pos_Y, int Largeur, int Hauteur) void Sauve_fond(byte **Buffer, int Pos_X, int Pos_Y, int Largeur, int Hauteur)
{ {
int Indice; int Indice;
if(*Buffer != NULL) DEBUG("WARNING : Buffer already allocated !!!",0);
*Buffer=(byte *) malloc(Largeur*Menu_Facteur_X*Hauteur*Menu_Facteur_Y*Pixel_width); *Buffer=(byte *) malloc(Largeur*Menu_Facteur_X*Hauteur*Menu_Facteur_Y*Pixel_width);
for (Indice=0; Indice<(Hauteur*Menu_Facteur_Y); Indice++) for (Indice=0; Indice<(Hauteur*Menu_Facteur_Y); Indice++)
Lire_ligne(Pos_X,Pos_Y+Indice,Largeur*Menu_Facteur_X,(*Buffer)+((int)Indice*Largeur*Menu_Facteur_X*Pixel_width)); Lire_ligne(Pos_X,Pos_Y+Indice,Largeur*Menu_Facteur_X,(*Buffer)+((int)Indice*Largeur*Menu_Facteur_X*Pixel_width));
@ -1109,6 +1110,7 @@ void Fermer_fenetre(void)
else else
{ {
free(Fond_fenetre[Fenetre-1]); free(Fond_fenetre[Fenetre-1]);
Fond_fenetre[Fenetre-1]=NULL;
Fenetre--; Fenetre--;
Cacher_pinceau=Cacher_pinceau_avant_fenetre; Cacher_pinceau=Cacher_pinceau_avant_fenetre;
@ -1444,6 +1446,127 @@ void Fenetre_Definir_bouton_saisie(word Pos_X,word Pos_Y,word Largeur_en_caracte
//----------------------- Ouverture d'un pop-up -----------------------
void Ouvrir_popup(word Pos_X, word Pos_Y, word Largeur,word Hauteur)
// Lors de l'appel à cette procédure, la souris doit être affichée.
// En sortie de cette procedure, la souris est effacée.
// Note : les pop-ups sont gérés comme s'ils étaient des sous-fenêtres, ils ont donc leur propre boucle d'évènements et tout, on peut ajouter des widgets dedans, ...
// Les différences sont surtout graphiques :
// -Possibilité de préciser la position XY
// -Pas de titre
// -Pas de cadre en relief mais seulement un plat, et il est blanc au lieu de noir.
{
Effacer_curseur();
Fenetre++;
Fenetre_Largeur=Largeur;
Fenetre_Hauteur=Hauteur;
Fenetre_Pos_X=Pos_X*Menu_Facteur_X;
Fenetre_Pos_Y=Pos_Y*Menu_Facteur_X;
// Sauvegarde de ce que la fenêtre remplace
Sauve_fond(&(Fond_fenetre[Fenetre-1]), Fenetre_Pos_X, Fenetre_Pos_Y, Largeur*Menu_Facteur_X, Hauteur*Menu_Facteur_X);
// Fenêtre grise
Block(Fenetre_Pos_X+(Menu_Facteur_X),Fenetre_Pos_Y+(Menu_Facteur_Y),(Largeur-2)*Menu_Facteur_X,(Hauteur-2)*Menu_Facteur_Y,CM_Clair);
// Cadre noir puis en relief
Fenetre_Afficher_cadre_mono(0,0,Largeur,Hauteur,CM_Blanc);
if (Fenetre == 1)
{
Menu_visible_avant_fenetre=Menu_visible;
Menu_visible=0;
Menu_Ordonnee_avant_fenetre=Menu_Ordonnee;
Menu_Ordonnee=Hauteur_ecran;
Forme_curseur_avant_fenetre=Forme_curseur;
Forme_curseur=FORME_CURSEUR_FLECHE;
Cacher_pinceau_avant_fenetre=Cacher_pinceau;
Cacher_pinceau=1;
}
// Initialisation des listes de boutons de la fenêtre
Fenetre_Liste_boutons_normal =NULL;
Fenetre_Liste_boutons_palette =NULL;
Fenetre_Liste_boutons_scroller=NULL;
Fenetre_Liste_boutons_special =NULL;
Nb_boutons_fenetre =0;
}
//----------------------- Fermer une fenêtre d'options -----------------------
void Fermer_popup(void)
// Lors de l'appel à cette procedure, la souris doit être affichée.
// En sortie de cette procedure, la souris est effacée.
{
struct Fenetre_Bouton_normal * Temp1;
struct Fenetre_Bouton_palette * Temp2;
struct Fenetre_Bouton_scroller * Temp3;
struct Fenetre_Bouton_special * Temp4;
Effacer_curseur();
while (Fenetre_Liste_boutons_normal)
{
Temp1=Fenetre_Liste_boutons_normal->Next;
free(Fenetre_Liste_boutons_normal);
Fenetre_Liste_boutons_normal=Temp1;
}
while (Fenetre_Liste_boutons_palette)
{
Temp2=Fenetre_Liste_boutons_palette->Next;
free(Fenetre_Liste_boutons_palette);
Fenetre_Liste_boutons_palette=Temp2;
}
while (Fenetre_Liste_boutons_scroller)
{
Temp3=Fenetre_Liste_boutons_scroller->Next;
free(Fenetre_Liste_boutons_scroller);
Fenetre_Liste_boutons_scroller=Temp3;
}
while (Fenetre_Liste_boutons_special)
{
Temp4=Fenetre_Liste_boutons_special->Next;
free(Fenetre_Liste_boutons_special);
Fenetre_Liste_boutons_special=Temp4;
}
if (Fenetre != 1)
{
// Restore de ce que la fenêtre cachait
Restaure_fond(Fond_fenetre[Fenetre-1], Fenetre_Pos_X, Fenetre_Pos_Y, Fenetre_Largeur, Fenetre_Hauteur);
UpdateRect(Fenetre_Pos_X,Fenetre_Pos_Y,Fenetre_Largeur*Menu_Facteur_X,Fenetre_Hauteur*Menu_Facteur_Y);
Fenetre--;
}
else
{
free(Fond_fenetre[Fenetre-1]);
Fenetre--;
Cacher_pinceau=Cacher_pinceau_avant_fenetre;
Calculer_coordonnees_pinceau();
Menu_Ordonnee=Menu_Ordonnee_avant_fenetre;
Menu_visible=Menu_visible_avant_fenetre;
Forme_curseur=Forme_curseur_avant_fenetre;
Afficher_ecran();
Afficher_menu();
}
Touche=0;
Mouse_K=0;
Old_MX = -1;
Old_MY = -1;
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// // // //
// Mini-MOTEUR utilisé dans les fenêtres (menus des boutons...) // // Mini-MOTEUR utilisé dans les fenêtres (menus des boutons...) //

View File

@ -545,6 +545,8 @@ void Creer_nouvelle_page(S_Page * Nouvelle_page,S_Liste_de_pages * Liste_courant
} }
else else
{ {
// Bon, alors là, on vient de vider toutes les pages et on a toujours pas asez de mémoire... C'est donc qu'un vilain programmeur a oublié de vérifier avec Noiuvelle_page_possible avant de venir ici.
// On sort méchament du programme sans sauvegarde ni rien. De toutes façons, ça ne devrait jamais se produire...
Erreur(ERREUR_SORRY_SORRY_SORRY); Erreur(ERREUR_SORRY_SORRY_SORRY);
} }
} }

View File

@ -57,6 +57,7 @@ int Create_ConfigDirectory(char * Config_Dir)
// Determine which directory contains the executable. // Determine which directory contains the executable.
// IN: Main's argv[0], some platforms need it, some don't. // IN: Main's argv[0], some platforms need it, some don't.
// OUT: Write into Program_Dir. Trailing / or \ is kept. // OUT: Write into Program_Dir. Trailing / or \ is kept.
// Note : in fact this is only used to check for the datafiles and fonts in this same directory.
void Set_Program_Directory(ARG_UNUSED const char * argv0,char * Program_Dir) void Set_Program_Directory(ARG_UNUSED const char * argv0,char * Program_Dir)
{ {
#undef ARG_UNUSED #undef ARG_UNUSED