~ubuntu-branches/ubuntu/trusty/grafx2/trusty

« back to all changes in this revision

Viewing changes to buttons.c

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2009-09-21 14:24:19 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090921142419-lhpqq102buior0ol
Tags: 2.1-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <stdlib.h>
24
24
#include <unistd.h>
25
25
#include <ctype.h>
 
26
#include <sys/stat.h>
26
27
#include <SDL.h>
27
28
 
28
29
#include "const.h"
50
51
#include "windows.h"
51
52
#include "brush.h"
52
53
#include "input.h"
 
54
#include "special.h"
 
55
 
 
56
#if defined(__amigaos4__) || defined(__AROS__) || defined(__MORPHOS__) || defined(__amigaos__)
 
57
    #include <proto/dos.h>
 
58
    #include <dirent.h>
 
59
    #define isHidden(x) (0)
 
60
#elif defined(__WIN32__)
 
61
    #include <dirent.h>
 
62
    #include <windows.h>
 
63
    #define isHidden(x) (GetFileAttributesA((x)->d_name)&FILE_ATTRIBUTE_HIDDEN)
 
64
#else
 
65
    #include <dirent.h>
 
66
    #define isHidden(x) ((x)->d_name[0]=='.')
 
67
#endif
53
68
 
54
69
extern char Program_version[]; // generated in pversion.c
55
70
 
112
127
 
113
128
void Button_Message_initial(void)
114
129
{
115
 
  char  str[21];
 
130
  char  str[30];
116
131
  int   x_pos,offs_y,x,y;
117
132
 
118
 
  sprintf(str,"GrafX2 version %s",Program_version);
 
133
  strcpy(str,"GrafX2 version ");
 
134
  strcat(str,Program_version);
119
135
  Open_window(260,172,str);
120
136
 
121
137
  Window_display_frame_in(10,20,239,62);
124
140
        Menu_factor_X*237,Menu_factor_Y*60,MC_Black);
125
141
  for (y=23,offs_y=0; y<79; offs_y+=231,y++)
126
142
    for (x=14,x_pos=0; x_pos<231; x_pos++,x++)
127
 
      Pixel_in_window(x,y,GFX_logo_grafx2[offs_y+x_pos]);
 
143
      Pixel_in_window(x,y,Gfx->Logo_grafx2[offs_y+x_pos]);
128
144
 
129
 
  Print_in_window(130-4*21,88,"Copyright (c) 2007 by",MC_Dark,MC_Light);
 
145
  Print_in_window(130-4*26,88,"Copyright (c) 2007-2009 by",MC_Dark,MC_Light);
130
146
  Print_in_window(130-4*23,96,"the Grafx2 project team",MC_Black,MC_Light);
131
 
  Print_in_window(130-4*26,112,"Copyright (c) 1996-1999 by",MC_Dark,MC_Light);
 
147
  Print_in_window(130-4*26,112,"Copyright (c) 1996-2001 by",MC_Dark,MC_Light);
132
148
  Print_in_window(130-4*13,120,"Sunset Design",MC_Black,MC_Light);
133
149
  //Print_in_window( 120-4*13,128,"(placeholder)",MC_Dark,MC_Light);
134
150
  Print_in_window(130-4*28,136,"http://grafx2.googlecode.com",MC_Dark,MC_Light);
287
303
  if (color == Fore_color)
288
304
  {
289
305
    // Check if it's a double-click    
290
 
    if (time_click - time_previous < 500)
 
306
    if (time_click - time_previous < Config.Double_click_speed)
291
307
    {
292
308
        // Open palette window
293
309
        Button_Palette();
413
429
    clicked_button=Window_clicked_button();
414
430
    if (Is_shortcut(Key,0x100+BUTTON_HELP))
415
431
      Window_help(BUTTON_QUIT, NULL);
 
432
    else if (Is_shortcut(Key,0x100+BUTTON_QUIT))
 
433
      clicked_button=1;
416
434
  }
417
435
  while (clicked_button<=0);
418
436
 
490
508
  else
491
509
    Hide_current_image(0);
492
510
  Display_all_screen();
 
511
  End_of_modification();
493
512
  Unselect_button(BUTTON_CLEAR);
494
513
  Display_cursor();
495
514
}
503
522
  else
504
523
    Hide_current_image(Back_color);
505
524
  Display_all_screen();
 
525
  End_of_modification();
506
526
  Unselect_button(BUTTON_CLEAR);
507
527
  Display_cursor();
508
528
}
509
529
 
510
530
//---------- Menu dans lequel on tagge des couleurs (genre Stencil) ----------
511
 
void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section)
 
531
void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section, word close_shortcut)
512
532
{
513
533
  short clicked_button;
514
534
  byte backup_table[256];
608
628
        Key=0;
609
629
        break;
610
630
      }
 
631
      else if (Is_shortcut(Key,close_shortcut))
 
632
      {
 
633
        clicked_button=4;
 
634
      }
611
635
    }
612
636
  }
613
637
  while (clicked_button<4);
646
670
 
647
671
void Button_Stencil_menu(void)
648
672
{
649
 
  Menu_tag_colors("Stencil",Stencil,&Stencil_mode,1, "STENCIL");
 
673
  Menu_tag_colors("Stencil",Stencil,&Stencil_mode,1, "STENCIL", SPECIAL_STENCIL_MENU);
650
674
}
651
675
 
652
676
 
659
683
 
660
684
void Button_Mask_menu(void)
661
685
{
662
 
  Menu_tag_colors("Mask",Mask_table,&Mask_mode,1, "MASK");
 
686
  Menu_tag_colors("Mask",Mask_table,&Mask_mode,1, "MASK", SPECIAL_MASK_MENU);
663
687
}
664
688
 
665
689
 
697
721
  Print_in_window( 91, 99,(conf->Clear_palette)?YES:NO,MC_Black,MC_Light);
698
722
  Print_in_window( 91,114,(conf->Maximize_preview)?YES:NO,MC_Black,MC_Light);
699
723
  Print_in_window( 91,129,(conf->Backup)?YES:NO,MC_Black,MC_Light);
 
724
  /*
700
725
  switch (conf->Cursor)
701
726
  {
702
727
    case 0 : Print_in_window(67,144," Solid",MC_Black,MC_Light); break;
703
728
    case 1 : Print_in_window(67,144,"Transp",MC_Black,MC_Light); break;
704
729
    default: Print_in_window(67,144,"  Thin",MC_Black,MC_Light);
705
730
  }
 
731
  */
706
732
 
 
733
  /*
707
734
  if (conf->Font)
708
735
  { // Fun
709
736
    Print_in_window(  8,31," ",MC_Black,MC_Light);
718
745
    Print_in_window(  8,31,"\020",MC_Black,MC_Light);
719
746
    Print_in_window( 78,31,"\021",MC_Black,MC_Light);
720
747
  }
 
748
  */
721
749
 
722
750
  Print_in_window(155,166,(conf->Auto_save)?YES:NO,MC_Black,MC_Light);
723
751
 
757
785
  Open_window(307,182,"Settings");
758
786
 
759
787
  // On commence par dessiner tous les Cadres
760
 
  Window_display_frame(  5, 16,157,30); // Font
761
788
  Window_display_frame(  5, 47,157,17); // Nb UNDO
762
789
  Window_display_frame(163, 16,139,48); // Show in filelist
763
790
  Window_display_frame(253, 77, 49,82); // Mouse sens.
772
799
  Pixel_in_window(160,77,MC_Dark);
773
800
*/
774
801
  // On affiche maintenant tout le blabla
775
 
  Print_in_window( 69, 19,"Font"            ,MC_Dark,MC_Light);
776
802
  Print_in_window(169, 19,"Show in filelist",MC_Dark,MC_Light);
777
803
  Print_in_window(  9, 52,"Nb of UNDO pages",MC_Dark,MC_Light);
778
804
  Print_in_window( 80, 70,"Miscellaneous"   ,MC_Dark,MC_Light);
781
807
  Print_in_window(256,123,"X"               ,MC_Dark,MC_Light);
782
808
  Print_in_window(292,123,"Y"               ,MC_Dark,MC_Light);
783
809
 
784
 
  // Boutons de fontes
785
 
  Window_set_normal_button(17,28,59,14,"Classic",0,1,SDLK_LAST); // 1
786
 
  Window_set_normal_button(91,28,59,14,"Fun"    ,0,1,SDLK_LAST); // 2
787
810
 
788
811
  // Button Show/Hide dans le fileselect
789
 
  Window_set_normal_button(167, 28,131,14,"Hidden files:   ",0,1,SDLK_LAST); // 3
790
 
  Window_set_normal_button(167, 43,131,14,"Hidden dir. :   ",0,1,SDLK_LAST); // 4
791
 
//  Window_set_normal_button(167, 58,131,14,"System dir. :   ",0,1,SDLK_LAST); // 5
 
812
  Window_set_normal_button(167, 28,131,14,"Hidden files:   ",0,1,SDLK_LAST); // 1
 
813
  Window_set_normal_button(167, 43,131,14,"Hidden dir. :   ",0,1,SDLK_LAST); // 2
 
814
//  Window_set_normal_button(167, 58,131,14,"System dir. :   ",0,1,SDLK_LAST);
792
815
 
793
816
  // Button Show/Hide Picture limits
794
 
  Window_set_normal_button(  9, 81,107,14,"Limits   :   ",0,1,SDLK_LAST); // 6
795
 
  // Button Show/Hide Picture limits
796
 
  Window_set_normal_button(  9, 96,107,14,"Clear pal:   ",0,1,SDLK_LAST); // 7
797
 
  // Button Show/Hide Picture limits
798
 
  Window_set_normal_button(  9,111,107,14,"Max prev.:   ",0,1,SDLK_LAST); // 8
 
817
  Window_set_normal_button(  9, 81,107,14,"Limits   :   ",0,1,SDLK_LAST); // 3
 
818
  // Button Show/Hide Picture limits
 
819
  Window_set_normal_button(  9, 96,107,14,"Clear pal:   ",0,1,SDLK_LAST); // 4
 
820
  // Button Show/Hide Picture limits
 
821
  Window_set_normal_button(  9,111,107,14,"Max prev.:   ",0,1,SDLK_LAST); // 5
799
822
  // Button Effectuer des backups � chaque sauvegarde
800
 
  Window_set_normal_button(  9,126,107,14,"Backup   :   ",0,1,SDLK_LAST); // 9
801
 
  // Button item du curseur
802
 
  Window_set_normal_button(  9,141,107,14,"Cursor:      ",0,1,SDLK_LAST); // 10
 
823
  Window_set_normal_button(  9,126,107,14,"Backup   :   ",0,1,SDLK_LAST); // 6
803
824
 
804
825
  // Button Safety colors
805
 
  Window_set_normal_button(117, 81,131,14,"Safe. colors:   ",0,1,SDLK_LAST); // 11
 
826
  Window_set_normal_button(117, 81,131,14,"Safe. colors:   ",0,1,SDLK_LAST); // 7
806
827
  // Button Adjust Brush Pick
807
 
  Window_set_normal_button(117, 96,131,14,"AdjBrushPick:   ",0,1,SDLK_LAST); // 12
 
828
  Window_set_normal_button(117, 96,131,14,"AdjBrushPick:   ",0,1,SDLK_LAST); // 8
808
829
  // Button Separate colors
809
 
  Window_set_normal_button(117,111,131,14,"Separate col:   ",0,1,SDLK_LAST); // 13
 
830
  Window_set_normal_button(117,111,131,14,"Separate col:   ",0,1,SDLK_LAST); // 9
810
831
  // Button Passer dans la r�solution appropri�e apr�s un chargement
811
 
  Window_set_normal_button(117,126,131,14,"Auto-set res:   ",0,1,SDLK_LAST); // 14
 
832
  Window_set_normal_button(117,126,131,14,"Auto-set res:   ",0,1,SDLK_LAST); // 10
812
833
  // Button Adapter la palette apr�s un chargement (<=> Shift+BkSpc)
813
 
  Window_set_normal_button(117,141,131,14,"Coords:         ",0,1,SDLK_LAST); // 15
 
834
  Window_set_normal_button(117,141,131,14,"Coords:         ",0,1,SDLK_LAST); // 11
814
835
 
815
836
    // Button Reload
816
 
  Window_set_normal_button(  6,163, 51,14,"Reload"       ,0,1,SDLK_LAST); // 16
 
837
  Window_set_normal_button(  6,163, 51,14,"Reload"       ,0,1,SDLK_LAST); // 12
817
838
    // Button Auto-save
818
 
  Window_set_normal_button( 73,163,107,14,"Auto-save:   ",0,1,SDLK_LAST); // 17
 
839
  Window_set_normal_button( 73,163,107,14,"Auto-save:   ",0,1,SDLK_LAST); // 13
819
840
    // Button Save
820
 
  Window_set_normal_button(183,163, 51,14,"Save"         ,0,1,SDLK_LAST); // 18
 
841
  Window_set_normal_button(183,163, 51,14,"Save"         ,0,1,SDLK_LAST); // 14
821
842
    // Button Close
822
 
  Window_set_normal_button(250,163, 51,14,"Close"        ,0,1,KEY_ESC); // 19
 
843
  Window_set_normal_button(250,163, 51,14,"Close"        ,0,1,KEY_ESC); // 15
823
844
 
824
845
  // Jauges de sensibilit� de la souris (X puis Y)
825
 
  Window_set_scroller_button(265,99,56,4,1,0); // 20
826
 
  Window_set_scroller_button(279,99,56,4,1,0); // 21
 
846
  Window_set_scroller_button(265,99,56,4,1,0); // 16
 
847
  Window_set_scroller_button(279,99,56,4,1,0); // 17
827
848
 
828
849
  // Zone de saisie du nb de pages de Undo
829
 
  Window_set_input_button(140,50,2);           // 22
 
850
  Window_set_input_button(140,50,2);           // 18
830
851
 
831
852
  Update_window_area(0,0,Window_width, Window_height);
832
853
 
841
862
 
842
863
    switch(clicked_button)
843
864
    {
844
 
      case  1 : // Classic
845
 
        Config_choisie.Font=0;
846
 
        break;
847
 
      case  2 : // Fun
848
 
        Config_choisie.Font=1;
849
 
        break;
850
 
      case  3 : // Hidden files
 
865
      case  1 : // Hidden files
851
866
        Config_choisie.Show_hidden_files=(Config_choisie.Show_hidden_files)?0:-1;
852
867
        break;
853
 
      case  4 : // Hidden dir.
 
868
      case  2 : // Hidden dir.
854
869
        Config_choisie.Show_hidden_directories=(Config_choisie.Show_hidden_directories)?0:-1;
855
870
        break;
856
871
//      case  5 : // System dir.
857
872
//        Config_choisie.Show_system_directories=(Config_choisie.Show_system_directories)?0:-1;
858
873
//        break;
859
 
      case  5 : // Draw limits
 
874
      case  3 : // Draw limits
860
875
        Config_choisie.Display_image_limits=!Config_choisie.Display_image_limits;
861
876
        break;
862
 
      case  6 : // Clear palette
 
877
      case  4 : // Clear palette
863
878
        Config_choisie.Clear_palette=!Config_choisie.Clear_palette;
864
879
        break;
865
 
      case  7 : // Maximize preview
 
880
      case  5 : // Maximize preview
866
881
        Config_choisie.Maximize_preview=!Config_choisie.Maximize_preview;
867
882
        break;
868
 
      case  8 : // Backup
 
883
      case  6 : // Backup
869
884
        Config_choisie.Backup=!Config_choisie.Backup;
870
885
        break;
871
 
      case 9 : // Cursor
872
 
        Config_choisie.Cursor=(Config_choisie.Cursor+1)%3;
873
 
        break;
874
 
      case 10 : // Safety colors
 
886
      case 7 : // Safety colors
875
887
        Config_choisie.Safety_colors=!Config_choisie.Safety_colors;
876
888
        break;
877
 
      case 11 : // Adjust brush pick
 
889
      case 8 : // Adjust brush pick
878
890
        Config_choisie.Adjust_brush_pick=!Config_choisie.Adjust_brush_pick;
879
891
        break;
880
 
      case 12 : // Separate colors
 
892
      case 9 : // Separate colors
881
893
        Config_choisie.Separate_colors=!Config_choisie.Separate_colors;
882
894
        break;
883
 
      case 13 : // Auto-set resolution
 
895
      case 10 : // Auto-set resolution
884
896
        Config_choisie.Auto_set_res=!Config_choisie.Auto_set_res;
885
897
        break;
886
 
      case 14 : // Coordonn�es
 
898
      case 11 : // Coordonn�es
887
899
        Config_choisie.Coords_rel=!Config_choisie.Coords_rel;
888
900
        break;
889
 
      case 15 : // Reload
 
901
      case 12 : // Reload
890
902
        Settings_load_config(&Config_choisie);
891
903
        config_is_reloaded=1;
892
904
        break;
893
 
      case 16 : // Auto-save
 
905
      case 13 : // Auto-save
894
906
        Config_choisie.Auto_save=!Config_choisie.Auto_save;
895
907
        break;
896
 
      case 17 : // Save
 
908
      case 14 : // Save
897
909
        Settings_save_config(&Config_choisie);
898
910
        break;
899
 
      // 18 : OK
900
 
      case 19 : // X Sensib.
 
911
      // 15 : OK
 
912
      case 16 : // X Sensib.
901
913
        Config_choisie.Mouse_sensitivity_index_x=Window_attribute2+1;
902
914
        break;
903
 
      case 20 : // Y Sensib.
 
915
      case 17 : // Y Sensib.
904
916
        Config_choisie.Mouse_sensitivity_index_y=Window_attribute2+1;
905
917
        break;
906
 
      case 21 : // Nb pages Undo
 
918
      case 18 : // Nb pages Undo
907
919
        Num2str(Config_choisie.Max_undo_pages,str,2);
908
920
        Readline(142,52,str,2,1);
909
921
        Config_choisie.Max_undo_pages=atoi(str);
933
945
      Spare_fileselector_offset=0;
934
946
    }
935
947
 
936
 
    if ((clicked_button>=1) && (clicked_button<=18))
 
948
    if ((clicked_button>=1) && (clicked_button<15))
937
949
      Settings_display_config(&Config_choisie);
938
950
      
939
951
    if (Is_shortcut(Key,0x100+BUTTON_HELP))
940
952
      Window_help(BUTTON_SETTINGS, NULL);
 
953
    else if (Is_shortcut(Key,0x100+BUTTON_SETTINGS))
 
954
      clicked_button=15;
941
955
  }
942
 
  while ( (clicked_button!=18) && (Key!=SDLK_RETURN) );
 
956
  while ( (clicked_button!=15) && (Key!=SDLK_RETURN) );
943
957
 
944
958
  Config=Config_choisie;
945
959
 
946
 
  // Font selection
947
 
  if (Config.Font)
948
 
    Menu_font=GFX_fun_font;
949
 
  else
950
 
    Menu_font=GFX_system_font;
951
 
 
952
960
  if (config_is_reloaded)
953
961
    Compute_optimal_menu_colors(Main_palette);
954
962
 
955
963
  Close_window();
956
964
  Unselect_button(BUTTON_SETTINGS);
957
 
  // Raffichage du menu pour que les inscriptions qui y figurent soient retrac�es avec la nouvelle fonte
 
965
  // Raffichage du menu pour que les inscriptions qui y figurent soient 
 
966
  // retrac�es avec la nouvelle fonte
958
967
  Display_menu();
959
968
  Display_cursor();
960
969
 
962
971
  Set_number_of_backups(Config.Max_undo_pages);
963
972
}
964
973
 
 
974
// Data for skin selector
 
975
T_Fileselector Skin_files_list;
 
976
 
 
977
 
 
978
// Data for font selector
 
979
T_Fileselector Font_files_list;
 
980
 
 
981
//
 
982
char * Format_font_filename(const char * fname)
 
983
{
 
984
  static char result[12];
 
985
  int c;
 
986
  int length;
 
987
  
 
988
  fname+=5; // Assume "font_" prefix
 
989
  length=strlen(fname) - 4; // assume .png extension
 
990
  
 
991
  for (c=0;c<11 && c<length ;c++)
 
992
  {
 
993
    result[c]=fname[c];
 
994
  }
 
995
  result[c]='\0';
 
996
  if (length>11)
 
997
    result[10] = ELLIPSIS_CHARACTER;
 
998
 
 
999
  return result;
 
1000
}
 
1001
 
 
1002
// Add a skin to the list
 
1003
void Add_font_or_skin(const char *name)
 
1004
{
 
1005
  const char * fname;
 
1006
  int namelength;
 
1007
  
 
1008
  // Cut the long name to keep only filename (no directory)
 
1009
  fname = Find_last_slash(name);
 
1010
  if (fname)
 
1011
    fname++;
 
1012
  else
 
1013
    fname=name;
 
1014
  namelength = strlen(fname);
 
1015
  if (namelength>=10 && fname[0]!='_' && !strncasecmp(fname, "skin_", 5)
 
1016
        && (!strcasecmp(fname+namelength-4,".png") 
 
1017
                || !strcasecmp(fname+namelength-4,".gif")))
 
1018
  {
 
1019
    Add_element_to_list(&Skin_files_list, name, 0);  
 
1020
    
 
1021
    if (fname[0]=='\0')
 
1022
      return;
 
1023
 
 
1024
    // Remove directory from full name
 
1025
    strcpy(Skin_files_list.First->Full_name, fname);
 
1026
    // Reformat the short name differently
 
1027
    strcpy(Skin_files_list.First->Short_name,
 
1028
                Format_filename(Skin_files_list.First->Full_name, 0)
 
1029
        );
 
1030
  }
 
1031
  else if (namelength>=10 && !strncasecmp(fname, "font_", 5) && (!strcasecmp(fname+namelength-4,".png")))
 
1032
  {
 
1033
    Add_element_to_list(&Font_files_list, name, 0);  
 
1034
    
 
1035
    if (fname[0]=='\0')
 
1036
      return;
 
1037
 
 
1038
    // Remove directory from full name
 
1039
    strcpy(Font_files_list.First->Full_name, fname);
 
1040
    // Reformat the short name differently
 
1041
    strcpy(Font_files_list.First->Short_name,Format_font_filename(Font_files_list.First->Full_name));
 
1042
  }
 
1043
   
 
1044
}
 
1045
 
 
1046
// Callback to display a skin name in the list
 
1047
void Draw_one_skin_name(word x, word y, word index, byte highlighted)
 
1048
{
 
1049
  T_Fileselector_item * current_item;
 
1050
 
 
1051
  if (Skin_files_list.Nb_elements)
 
1052
  {
 
1053
    current_item = Get_item_by_index(&Skin_files_list, index);    
 
1054
    Print_in_window(x,y,current_item->Short_name, MC_Black, (highlighted)?MC_Dark:MC_Light);
 
1055
  }
 
1056
}
 
1057
 
 
1058
/// Skin selector window
 
1059
void Button_Skins(void)
 
1060
{
 
1061
  short clicked_button;
 
1062
  short temp;
 
1063
  char skinsdir[MAX_PATH_CHARACTERS];
 
1064
  T_Dropdown_button * font_dropdown;
 
1065
  T_Dropdown_button * cursor_dropdown;
 
1066
  T_List_button * skin_list;
 
1067
  T_Scroller_button * file_scroller;
 
1068
  int selected_font=0;
 
1069
  int selected_cursor=Config.Cursor;
 
1070
  
 
1071
  char * cursors[] = { "Solid", "Transparent", "Thin" };
 
1072
 
 
1073
  #define FILESEL_Y 52
 
1074
 
 
1075
  // --- Read the contents of skins/ directory ------------------
 
1076
  
 
1077
  // Here we use the same data container as the fileselectors.
 
1078
  // Reinitialize the list
 
1079
  Free_fileselector_list(&Skin_files_list);
 
1080
  Free_fileselector_list(&Font_files_list);
 
1081
  // Browse the "skins" directory
 
1082
  strcpy(skinsdir,Data_directory);
 
1083
  strcat(skinsdir,"skins");
 
1084
  // Add each found file to the list
 
1085
  For_each_file(skinsdir, Add_font_or_skin);
 
1086
  // Sort it
 
1087
  Sort_list_of_files(&Skin_files_list);
 
1088
  Sort_list_of_files(&Font_files_list);
 
1089
  
 
1090
  selected_font = Find_file_in_fileselector(&Font_files_list, Config.Font_file);
 
1091
  
 
1092
  // --------------------------------------------------------------
 
1093
 
 
1094
  Open_window(178,155,"Skins");
 
1095
 
 
1096
  // Frames
 
1097
  Window_display_frame_in(6,FILESEL_Y-2,148,84); // File selector
 
1098
 
 
1099
  // Texts
 
1100
  Print_in_window( 6, 21,"Font"            ,MC_Black,MC_Light);
 
1101
  Print_in_window( 6, 36,"Cursor"          ,MC_Black,MC_Light);
 
1102
 
 
1103
  // Ok button
 
1104
  Window_set_normal_button(6,136, 51,14,"OK"         ,0,1,SDLK_RETURN); // 1
 
1105
 
 
1106
  // List of skins
 
1107
  skin_list = Window_set_list_button(
 
1108
    // Fileselector
 
1109
    Window_set_special_button(8,FILESEL_Y+1,144,80), // 2
 
1110
    // Scroller for the fileselector
 
1111
    (file_scroller = Window_set_scroller_button(160,FILESEL_Y+1,82,
 
1112
                Skin_files_list.Nb_elements,10,0)), // 3
 
1113
    Draw_one_skin_name); // 4
 
1114
  
 
1115
  skin_list->Cursor_position = Find_file_in_fileselector(&Skin_files_list, Config.Skin_file);
 
1116
 
 
1117
  // Buttons to choose a font
 
1118
  font_dropdown = Window_set_dropdown_button(60,19,104,11,0, Get_item_by_index(&Font_files_list,selected_font)->Short_name,1,0,1,RIGHT_SIDE|LEFT_SIDE); // 5
 
1119
  for (temp=0; temp<Font_files_list.Nb_files; temp++)
 
1120
    Window_dropdown_add_item(font_dropdown,temp,Get_item_by_index(&Font_files_list,temp)->Short_name);
 
1121
 
 
1122
  // Cancel
 
1123
  Window_set_normal_button(62,136, 51,14,"Cancel",0,1,SDLK_ESCAPE); // 6
 
1124
 
 
1125
  // Dropdown list to choose cursor type
 
1126
  cursor_dropdown = Window_set_dropdown_button(60,34,104,11,0,cursors[selected_cursor],1,0,1,RIGHT_SIDE|LEFT_SIDE); // 7
 
1127
  for (temp=0; temp<3; temp++)
 
1128
    Window_dropdown_add_item(cursor_dropdown,temp,cursors[temp]);
 
1129
  
 
1130
  Window_redraw_list(skin_list);
 
1131
 
 
1132
  Update_window_area(0,0,Window_width, Window_height);
 
1133
 
 
1134
  Display_cursor();
 
1135
 
 
1136
  do
 
1137
  {
 
1138
    clicked_button=Window_clicked_button();
 
1139
 
 
1140
    switch(clicked_button)
 
1141
    {
 
1142
            case 1 : // OK
 
1143
              break;
 
1144
      case 2 : // doesn't happen
 
1145
        break;
 
1146
      case 3 : // doesn't happen
 
1147
        break;
 
1148
      case 4 : // a file is selected
 
1149
        break;
 
1150
      case  5 : // Font dropdown
 
1151
        selected_font=Window_attribute2; // Get the index of the chosen font.
 
1152
        break;
 
1153
          // 5: Cancel
 
1154
       case 7 : // Cursor
 
1155
       selected_cursor = Window_attribute2;
 
1156
        break;
 
1157
    }
 
1158
 
 
1159
    switch (Key)
 
1160
    {
 
1161
      case SDLK_UNKNOWN : break;
 
1162
                                                  /*
 
1163
      case SDLK_DOWN : // Bas
 
1164
        *quicksearch_filename=0;
 
1165
        Hide_cursor();
 
1166
        Selector_scroll_down(&Main_fileselector_position,&Main_fileselector_offset);
 
1167
                if (file_scroller->Position!=Main_fileselector_position)
 
1168
                {
 
1169
          // Si c'est le cas, il faut mettre � jour la jauge
 
1170
          file_scroller->Position=Main_fileselector_position;
 
1171
          Window_draw_slider(file_scroller);
 
1172
                }
 
1173
        Key=0;
 
1174
        break;
 
1175
      case SDLK_UP : // Haut
 
1176
        *quicksearch_filename=0;
 
1177
        Hide_cursor();
 
1178
        Selector_scroll_up(&Main_fileselector_position,&Main_fileselector_offset);
 
1179
                if (file_scroller->Position!=Main_fileselector_position)
 
1180
                {
 
1181
          // Si c'est le cas, il faut mettre � jour la jauge
 
1182
          file_scroller->Position=Main_fileselector_position;
 
1183
          Window_draw_slider(file_scroller);
 
1184
                }
 
1185
        Key=0;
 
1186
        break;
 
1187
      case SDLK_PAGEDOWN : // PageDown
 
1188
      case KEY_MOUSEWHEELDOWN :
 
1189
        *quicksearch_filename=0;
 
1190
        Hide_cursor();
 
1191
        Selector_page_down(&Main_fileselector_position,&Main_fileselector_offset,9);
 
1192
                if (file_scroller->Position!=Main_fileselector_position)
 
1193
                {
 
1194
          // Si c'est le cas, il faut mettre � jour la jauge
 
1195
          file_scroller->Position=Main_fileselector_position;
 
1196
          Window_draw_slider(file_scroller);
 
1197
                }
 
1198
        Key=0;
 
1199
        break;
 
1200
      case SDLK_PAGEUP : // PageUp
 
1201
      case KEY_MOUSEWHEELUP :
 
1202
        *quicksearch_filename=0;
 
1203
        Hide_cursor();
 
1204
        Selector_page_up(&Main_fileselector_position,&Main_fileselector_offset,9);
 
1205
                if (file_scroller->Position!=Main_fileselector_position)
 
1206
                {
 
1207
          // Si c'est le cas, il faut mettre � jour la jauge
 
1208
          file_scroller->Position=Main_fileselector_position;
 
1209
          Window_draw_slider(file_scroller);
 
1210
                }
 
1211
        Key=0;
 
1212
        break;
 
1213
      case SDLK_END : // End
 
1214
        *quicksearch_filename=0;
 
1215
        Hide_cursor();
 
1216
        Selector_end(&Main_fileselector_position,&Main_fileselector_offset);
 
1217
                if (file_scroller->Position!=Main_fileselector_position)
 
1218
                {
 
1219
          // Si c'est le cas, il faut mettre � jour la jauge
 
1220
          file_scroller->Position=Main_fileselector_position;
 
1221
          Window_draw_slider(file_scroller);
 
1222
                }
 
1223
        Key=0;
 
1224
        break;
 
1225
      case SDLK_HOME : // Home
 
1226
        *quicksearch_filename=0;
 
1227
        Hide_cursor();
 
1228
        Selector_home(&Main_fileselector_position,&Main_fileselector_offset);
 
1229
                if (file_scroller->Position!=Main_fileselector_position)
 
1230
                {
 
1231
          // Si c'est le cas, il faut mettre � jour la jauge
 
1232
          file_scroller->Position=Main_fileselector_position;
 
1233
          Window_draw_slider(file_scroller);
 
1234
                }
 
1235
        Key=0;
 
1236
        break;
 
1237
      default: // Autre => On se place sur le nom de fichier qui correspond
 
1238
        if (clicked_button<=0)
 
1239
        {
 
1240
          if (Is_shortcut(Key,0x100+BUTTON_HELP))
 
1241
          {
 
1242
            Window_help(BUTTON_SETTINGS, NULL);
 
1243
            break;
 
1244
          }
 
1245
          temp=strlen(quicksearch_filename);
 
1246
          if (Key_ANSI>= ' ' && Key_ANSI < 255 && temp<50)
 
1247
          {
 
1248
            quicksearch_filename[temp]=Key_ANSI;
 
1249
            quicksearch_filename[temp+1]='\0';
 
1250
            most_matching_filename=Find_filename_match(Skin_files_list, quicksearch_filename);
 
1251
            if ( (most_matching_filename) )
 
1252
            {
 
1253
              temp=Main_fileselector_position+Main_fileselector_offset;
 
1254
              Hide_cursor();
 
1255
              Highlight_file(most_matching_filename);
 
1256
              Prepare_and_display_filelist(Main_fileselector_position,Main_fileselector_offset,file_scroller);
 
1257
              Display_cursor();
 
1258
              if (temp!=Main_fileselector_position+Main_fileselector_offset)
 
1259
                New_preview_is_needed=1;
 
1260
            }
 
1261
            else
 
1262
              *quicksearch_filename=0;
 
1263
            Key=0;
 
1264
          }
 
1265
        }
 
1266
        else
 
1267
          *quicksearch_filename=0;
 
1268
                */
 
1269
    }
 
1270
  }
 
1271
  while ( (clicked_button!=1) && (clicked_button !=6) && (Key != SDLK_ESCAPE));
 
1272
 
 
1273
  if(clicked_button == 1)
 
1274
  {
 
1275
    T_Gui_skin * gfx;
 
1276
    byte * new_font;
 
1277
 
 
1278
    // (Re-)load GUI graphics from selected skins
 
1279
    strcpy(skinsdir, Get_item_by_index(&Skin_files_list, skin_list->List_start+skin_list->Cursor_position)->Full_name);
 
1280
          gfx=Load_graphics(skinsdir);
 
1281
          if (gfx == NULL) // Error
 
1282
    {
 
1283
      Verbose_error_message(Gui_loading_error_message);
 
1284
          }
 
1285
          else
 
1286
          {
 
1287
      free(Gfx);
 
1288
      Gfx = gfx;
 
1289
      
 
1290
      free(Config.Skin_file);
 
1291
            Config.Skin_file = strdup(skinsdir);
 
1292
    }
 
1293
          // (Re-)load the selected font
 
1294
          new_font = Load_font(Get_item_by_index(&Font_files_list,selected_font)->Full_name);
 
1295
          if (new_font)
 
1296
          {
 
1297
            const char * fname;
 
1298
            
 
1299
            free(Menu_font);
 
1300
            Menu_font = new_font;
 
1301
            fname = Get_item_by_index(&Font_files_list,selected_font)->Full_name;
 
1302
            free(Config.Font_file);
 
1303
            Config.Font_file = strdup(fname);
 
1304
          }
 
1305
    // Confirm the change of cursor shape
 
1306
          Config.Cursor = selected_cursor;
 
1307
  }
 
1308
 
 
1309
  Close_window();
 
1310
  Unselect_button(BUTTON_SETTINGS);
 
1311
  // Raffichage du menu pour que les inscriptions qui y figurent soient retrac�es avec la nouvelle fonte
 
1312
  Display_menu();
 
1313
  Display_cursor();
 
1314
}
 
1315
 
965
1316
 
966
1317
//---------------------------- Changement de page ----------------------------
967
1318
void Button_Page(void)
968
1319
{
969
 
  byte   temp_byte;
970
 
  word   temp_word;
971
 
  short  temp_short;
972
 
  float  temp_float;
 
1320
        byte   factor_index;
973
1321
  char   Temp_buffer[256];
974
1322
 
 
1323
  #define SWAP_BYTES(a,b) { byte c=a; a=b; b=c;}
 
1324
  #define SWAP_WORDS(a,b) { word c=a; a=b; b=c;}
 
1325
  #define SWAP_SHORTS(a,b) { short c=a; a=b; b=c;}
 
1326
  #define SWAP_FLOATS(a,b) { float c=a; a=b; b=c;}
 
1327
  
975
1328
  Hide_cursor();
976
1329
 
977
1330
  // On d�grossit le travail avec les infos des listes de pages
978
1331
  Exchange_main_and_spare();
979
1332
 
980
1333
  // On fait le reste du travail "� la main":
981
 
  temp_short=Spare_offset_X;
982
 
  Spare_offset_X=Main_offset_X;
983
 
  Main_offset_X=temp_short;
984
 
 
985
 
  temp_short=Spare_offset_Y;
986
 
  Spare_offset_Y=Main_offset_Y;
987
 
  Main_offset_Y=temp_short;
988
 
 
989
 
  temp_short=Old_spare_offset_X;
990
 
  Old_spare_offset_X=Old_main_offset_X;
991
 
  Old_main_offset_X=temp_short;
992
 
 
993
 
  temp_short=Old_spare_offset_Y;
994
 
  Old_spare_offset_Y=Old_main_offset_Y;
995
 
  Old_main_offset_Y=temp_short;
996
 
 
997
 
  temp_short=Spare_separator_position;
998
 
  Spare_separator_position=Main_separator_position;
999
 
  Main_separator_position=temp_short;
1000
 
 
1001
 
  temp_short=Spare_X_zoom;
1002
 
  Spare_X_zoom=Main_X_zoom;
1003
 
  Main_X_zoom=temp_short;
1004
 
 
1005
 
  temp_float=Spare_separator_proportion;
1006
 
  Spare_separator_proportion=Main_separator_proportion;
1007
 
  Main_separator_proportion=temp_float;
1008
 
 
1009
 
  temp_byte=Spare_magnifier_mode;
1010
 
  Spare_magnifier_mode=Main_magnifier_mode;
1011
 
  Main_magnifier_mode=temp_byte;
 
1334
  SWAP_SHORTS(Main_offset_X,Spare_offset_X)
 
1335
  SWAP_SHORTS(Main_offset_Y,Spare_offset_Y)
 
1336
  SWAP_SHORTS(Old_main_offset_X,Old_spare_offset_X)
 
1337
  SWAP_SHORTS(Old_main_offset_Y,Old_spare_offset_Y)
 
1338
  SWAP_SHORTS(Main_separator_position,Spare_separator_position)
 
1339
  SWAP_SHORTS(Main_X_zoom,Spare_X_zoom)
 
1340
  SWAP_FLOATS(Main_separator_proportion,Spare_separator_proportion)
 
1341
  SWAP_BYTES (Main_magnifier_mode,Spare_magnifier_mode)
1012
1342
 
1013
1343
  Pixel_preview=(Main_magnifier_mode)?Pixel_preview_magnifier:Pixel_preview_normal;
1014
1344
 
1015
 
  temp_word=Spare_magnifier_factor;
1016
 
  Spare_magnifier_factor=Main_magnifier_factor;
1017
 
  Main_magnifier_factor=temp_word;
1018
 
 
1019
 
  temp_word=Spare_magnifier_height;
1020
 
  Spare_magnifier_height=Main_magnifier_height;
1021
 
  Main_magnifier_height=temp_word;
1022
 
 
1023
 
  temp_word=Spare_magnifier_width;
1024
 
  Spare_magnifier_width=Main_magnifier_width;
1025
 
  Main_magnifier_width=temp_word;
1026
 
 
1027
 
  temp_short=Spare_magnifier_offset_X;
1028
 
  Spare_magnifier_offset_X=Main_magnifier_offset_X;
1029
 
  Main_magnifier_offset_X=temp_short;
1030
 
 
1031
 
  temp_short=Spare_magnifier_offset_Y;
1032
 
  Spare_magnifier_offset_Y=Main_magnifier_offset_Y;
1033
 
  Main_magnifier_offset_Y=temp_short;
1034
 
 
 
1345
  SWAP_WORDS (Main_magnifier_factor,Spare_magnifier_factor)
 
1346
  SWAP_WORDS (Main_magnifier_height,Spare_magnifier_height)
 
1347
  SWAP_WORDS (Main_magnifier_width,Spare_magnifier_width)
 
1348
  SWAP_SHORTS(Main_magnifier_offset_X,Spare_magnifier_offset_X)
 
1349
  SWAP_SHORTS(Main_magnifier_offset_Y,Spare_magnifier_offset_Y)
1035
1350
  // Swap du bool�en "Image modifi�e"
1036
 
  temp_byte        =Spare_image_is_modified;
1037
 
  Spare_image_is_modified=Main_image_is_modified;
1038
 
  Main_image_is_modified=temp_byte;
 
1351
  SWAP_BYTES (Main_image_is_modified,Spare_image_is_modified)
1039
1352
 
1040
1353
  // Swap des infos sur les fileselects
1041
1354
  strcpy(Temp_buffer             ,Spare_current_directory);
1042
1355
  strcpy(Spare_current_directory,Main_current_directory);
1043
1356
  strcpy(Main_current_directory,Temp_buffer             );
1044
1357
 
1045
 
  temp_byte=Spare_format;
1046
 
  Spare_format=Main_format;
1047
 
  Main_format=temp_byte;
1048
 
 
1049
 
  temp_word              =Spare_fileselector_position;
1050
 
  Spare_fileselector_position=Main_fileselector_position;
1051
 
  Main_fileselector_position=temp_word;
1052
 
 
1053
 
  temp_word              =Spare_fileselector_offset;
1054
 
  Spare_fileselector_offset=Main_fileselector_offset;
1055
 
  Main_fileselector_offset=temp_word;
1056
 
 
 
1358
  SWAP_BYTES (Main_format,Spare_format)
 
1359
  SWAP_WORDS (Main_fileselector_position,Spare_fileselector_position)
 
1360
  SWAP_WORDS (Main_fileselector_offset,Spare_fileselector_offset)
 
1361
  
1057
1362
  // A la fin, on affiche l'�cran
1058
 
  for (temp_byte=0; ZOOM_FACTOR[temp_byte]!=Main_magnifier_factor; temp_byte++);
1059
 
  Change_magnifier_factor(temp_byte);
 
1363
  for (factor_index=0; ZOOM_FACTOR[factor_index]!=Main_magnifier_factor; factor_index++);
 
1364
  Change_magnifier_factor(factor_index);
1060
1365
 
1061
1366
  Set_palette(Main_palette);
1062
1367
  Compute_optimal_menu_colors(Main_palette);
1121
1426
  static byte mask_color_to_copy[256]; // static to use less stack
1122
1427
 
1123
1428
  memset(mask_color_to_copy,1,256);
1124
 
  Menu_tag_colors("Tag colors to copy",mask_color_to_copy,&confirmation,0, NULL);
 
1429
  Menu_tag_colors("Tag colors to copy",mask_color_to_copy,&confirmation,0, NULL, 0xFFFF);
1125
1430
 
1126
1431
  if (confirmation &&
1127
1432
    (!Spare_image_is_modified || Confirmation_box("Spare page was modified. Proceed?")))
1158
1463
    clicked_button=Window_clicked_button();
1159
1464
    if (Is_shortcut(Key,0x100+BUTTON_HELP))
1160
1465
      Window_help(BUTTON_PAGE, NULL);
 
1466
    else if (Is_shortcut(Key,0x200+BUTTON_PAGE))
 
1467
      clicked_button=6;
1161
1468
  }
1162
1469
  while (clicked_button<=0);
1163
1470
 
1261
1568
    if (cursor_position!=index)
1262
1569
    {
1263
1570
      background_color =MC_Black;
1264
 
      if ((Video_mode[current_mode].State & 3) != 3)
1265
 
        text_color=MC_Light;
1266
 
      else
 
1571
      if ((Video_mode[current_mode].State & 3) == 3)
1267
1572
        text_color=MC_Dark;
 
1573
      else
 
1574
        text_color=MC_Light;
1268
1575
    }
1269
1576
    else
1270
1577
    {
1271
1578
      background_color =MC_Dark;
1272
 
      if ((Video_mode[current_mode].State & 3) != 3)
 
1579
      if ((Video_mode[current_mode].State & 3) == 3)
 
1580
        text_color=MC_Light;
 
1581
      else
1273
1582
        text_color=MC_White;
1274
 
      else
1275
 
        text_color=MC_Light;
1276
1583
    }
1277
1584
    Num2str(Video_mode[current_mode].Width,str,4);
1278
1585
    str[4]=' ';
1279
1586
    Num2str(Video_mode[current_mode].Height,str+5,4);
1280
1587
 
1281
 
    if(Video_mode[current_mode].Fullscreen == 1)
 
1588
    if(Video_mode[current_mode].Fullscreen == 0)
 
1589
      memcpy(str+9,"   Window          ",20);
 
1590
    else
 
1591
        {
1282
1592
      memcpy(str+9," Fullscreen ",13);
1283
 
    else
1284
 
      memcpy(str+9,"   Window   ",13);
1285
 
 
1286
 
    if (Video_mode[current_mode].Width*3 == Video_mode[current_mode].Height*4)
1287
 
      ratio="    4:3";
1288
 
    else if (Video_mode[current_mode].Width*9 == Video_mode[current_mode].Height*16)
1289
 
      ratio="   16:9";
1290
 
    else if (Video_mode[current_mode].Width*10 == Video_mode[current_mode].Height*16)
1291
 
      ratio="  16:10";
1292
 
    else if (Video_mode[current_mode].Width*145 == Video_mode[current_mode].Height*192)
1293
 
      ratio="192:145";
1294
 
    else if (Video_mode[current_mode].Width*2 == Video_mode[current_mode].Height*3)
1295
 
      ratio="    3:2";
1296
 
    else if (Video_mode[current_mode].Width*3 == Video_mode[current_mode].Height*5)
1297
 
      ratio="    5:3";
1298
 
    else if (Video_mode[current_mode].Width*4 == Video_mode[current_mode].Height*5)
1299
 
      ratio="    5:4";
1300
 
    else if (Video_mode[current_mode].Width*16 == Video_mode[current_mode].Height*25)
1301
 
      ratio="  25:16";
1302
 
    else
1303
 
      ratio="       ";
1304
 
    if (current_mode == 0)
1305
 
      ratio="       ";
1306
 
 
1307
 
    strcat(str,ratio);
 
1593
 
 
1594
          if (Video_mode[current_mode].Width*3 == Video_mode[current_mode].Height*4)
 
1595
                  ratio="    4:3";
 
1596
          else if (Video_mode[current_mode].Width*9 == Video_mode[current_mode].Height*16)
 
1597
                  ratio="   16:9";
 
1598
          else if (Video_mode[current_mode].Width*10 == Video_mode[current_mode].Height*16)
 
1599
                  ratio="  16:10";
 
1600
          else if (Video_mode[current_mode].Width*145 == Video_mode[current_mode].Height*192)
 
1601
                  ratio="192:145";
 
1602
          else if (Video_mode[current_mode].Width*2 == Video_mode[current_mode].Height*3)
 
1603
                  ratio="    3:2";
 
1604
          else if (Video_mode[current_mode].Width*3 == Video_mode[current_mode].Height*5)
 
1605
                  ratio="    5:3";
 
1606
          else if (Video_mode[current_mode].Width*4 == Video_mode[current_mode].Height*5)
 
1607
                  ratio="    5:4";
 
1608
          else if (Video_mode[current_mode].Width*16 == Video_mode[current_mode].Height*25)
 
1609
                  ratio="  25:16";
 
1610
          else
 
1611
                  ratio="       ";
 
1612
 
 
1613
          strcpy(str+21,ratio);
 
1614
        }
1308
1615
 
1309
1616
    Print_in_window(38,y_pos,str,text_color,background_color);
1310
1617
  }
1375
1682
  Window_set_special_button(38,86,225,80);                       // 5
1376
1683
 
1377
1684
  selected_mode=Current_resolution;
1378
 
  if (selected_mode>=MODELIST_LINES/2)
 
1685
  if (selected_mode>=MODELIST_LINES/2 && Nb_video_modes > MODELIST_LINES)
1379
1686
  {
1380
1687
    if (selected_mode<Nb_video_modes-MODELIST_LINES/2)
1381
1688
    {
1506
1813
        
1507
1814
      default: // Boutons de tag des �tats des modes
1508
1815
        temp=list_start+clicked_button-8;
1509
 
        if (temp && // On n'a pas le droit de cocher le mode fen�tr�
 
1816
        if (Video_mode[temp].Fullscreen==1 && // On n'a pas le droit de cocher le mode fen�tr�
1510
1817
            !(Video_mode[temp].State & 128)) // Ni ceux non d�tect�s par SDL
1511
1818
        {
1512
1819
          if (Window_attribute1==LEFT_SIDE)
2073
2380
      default:
2074
2381
        if (Is_shortcut(Key,0x100+BUTTON_HELP))
2075
2382
        {
2076
 
          Window_help(BUTTON_GRADMENU, NULL);
 
2383
          Window_help(BUTTON_GRADRECT, NULL);
2077
2384
          Key=0;
2078
2385
          break;
2079
2386
        }
 
2387
        if (Is_shortcut(Key,0x200+BUTTON_GRADRECT))
 
2388
          clicked_button=6;
2080
2389
    }
2081
2390
  }
2082
2391
  while (clicked_button<6);
2083
2392
 
2084
2393
  Close_window();
2085
 
  Unselect_button(BUTTON_GRADMENU);
 
2394
  // The Grad rect operation uses the same button as Grad menu.
 
2395
  if (Current_operation != OPERATION_GRAD_RECTANGLE)
 
2396
    Unselect_button(BUTTON_GRADRECT);
 
2397
    
2086
2398
  Display_cursor();
2087
2399
 
2088
2400
  Gradient_pixel=Display_pixel;
2182
2494
  short x_pos,y_pos;
2183
2495
  byte index;
2184
2496
 
2185
 
  Open_window(310,155,"Paintbrush menu");
2186
 
 
2187
 
  Window_display_frame(8,21,294,107);
2188
 
 
2189
 
  Window_set_normal_button(122,133,67,14,"Cancel",0,1,KEY_ESC); // 1
 
2497
  Open_window(310,180,"Paintbrush menu");
 
2498
 
 
2499
  Window_display_frame(8,21,294,132);
 
2500
 
 
2501
  Window_set_normal_button(122,158,67,14,"Cancel",0,1,KEY_ESC); // 1
2190
2502
 
2191
2503
  for (index=0; index<NB_PAINTBRUSH_SPRITES; index++)
2192
2504
  {
2193
 
    x_pos=13+((index%12)*24);
2194
 
    y_pos=27+((index/12)*25);
 
2505
    x_pos=13+(index%12)*24;
 
2506
    y_pos=27+(index/12)*25;
2195
2507
    Window_set_normal_button(x_pos  ,y_pos  ,20,20,"",0,1,SDLK_LAST);
2196
2508
    Display_paintbrush_in_window(x_pos+2,y_pos+2,index);
2197
2509
  }
 
2510
  for (index=0; index<BRUSH_CONTAINER_COLUMNS*BRUSH_CONTAINER_ROWS; index++)
 
2511
  {
 
2512
    x_pos=13+((index+NB_PAINTBRUSH_SPRITES)%12)*24;
 
2513
    y_pos=27+((index+NB_PAINTBRUSH_SPRITES)/12)*25;
 
2514
    Window_set_normal_button(x_pos  ,y_pos  ,20,20,"",0,1,SDLK_LAST);
 
2515
    Display_stored_brush_in_window(x_pos+2, y_pos+2, index);
 
2516
  }
 
2517
  
2198
2518
  Update_window_area(0,0,Window_width, Window_height);
2199
2519
 
2200
2520
  Display_cursor();
2204
2524
    clicked_button=Window_clicked_button();
2205
2525
    if (Is_shortcut(Key,0x100+BUTTON_HELP))
2206
2526
      Window_help(BUTTON_PAINTBRUSHES, NULL);
2207
 
  }
2208
 
  while (clicked_button<=0);
2209
 
 
2210
 
  Close_window();
2211
 
 
2212
 
  if (clicked_button!=1) // pas Cancel
2213
 
  {
2214
 
    index=clicked_button-2;
2215
 
    Paintbrush_shape=Paintbrush_type[index];
2216
 
    Paintbrush_width=Preset_paintbrush_width[index];
2217
 
    Paintbrush_height=Preset_paintbrush_height[index];
2218
 
    Paintbrush_offset_X=Preset_paintbrush_offset_X[index];
2219
 
    Paintbrush_offset_Y=Preset_paintbrush_offset_Y[index];
2220
 
    for (y_pos=0; y_pos<Paintbrush_height; y_pos++)
2221
 
      for (x_pos=0; x_pos<Paintbrush_width; x_pos++)
2222
 
        Paintbrush_sprite[(y_pos*MAX_PAINTBRUSH_SIZE)+x_pos]=GFX_paintbrush_sprite[index][y_pos][x_pos];
2223
 
    Change_paintbrush_shape(Paintbrush_type[index]);
2224
 
  }
 
2527
    // Brush container
 
2528
    if (clicked_button>(NB_PAINTBRUSH_SPRITES+1))
 
2529
    {
 
2530
      index = clicked_button-NB_PAINTBRUSH_SPRITES-2;
 
2531
      
 
2532
      if (Window_attribute1==RIGHT_SIDE)
 
2533
      {
 
2534
        // Store
 
2535
        
 
2536
        x_pos=13+((index+NB_PAINTBRUSH_SPRITES)%12)*24;
 
2537
        y_pos=27+((index+NB_PAINTBRUSH_SPRITES)/12)*25;
 
2538
      
 
2539
        Store_brush(index);
 
2540
        Hide_cursor();
 
2541
        Display_stored_brush_in_window(x_pos+2, y_pos+2, index);
 
2542
        Display_cursor();
 
2543
      }
 
2544
      else
 
2545
      {
 
2546
        // Restore and exit
 
2547
      
 
2548
        if (Restore_brush(index))
 
2549
        {
 
2550
          Close_window();
 
2551
          break;
 
2552
        }
 
2553
      }
 
2554
    
 
2555
    }
 
2556
    else if (clicked_button>1 && Window_attribute1==LEFT_SIDE)
 
2557
    // Standard paintbrushes
 
2558
    {
 
2559
      Close_window();
 
2560
      index=clicked_button-2;
 
2561
      Paintbrush_shape=Gfx->Paintbrush_type[index];
 
2562
      Paintbrush_width=Gfx->Preset_paintbrush_width[index];
 
2563
      Paintbrush_height=Gfx->Preset_paintbrush_height[index];
 
2564
      Paintbrush_offset_X=Gfx->Preset_paintbrush_offset_X[index];
 
2565
      Paintbrush_offset_Y=Gfx->Preset_paintbrush_offset_Y[index];
 
2566
      for (y_pos=0; y_pos<Paintbrush_height; y_pos++)
 
2567
        for (x_pos=0; x_pos<Paintbrush_width; x_pos++)
 
2568
          Paintbrush_sprite[(y_pos*MAX_PAINTBRUSH_SIZE)+x_pos]=Gfx->Paintbrush_sprite[index][y_pos][x_pos];
 
2569
      Change_paintbrush_shape(Gfx->Paintbrush_type[index]);
 
2570
      
 
2571
      break;
 
2572
    }
 
2573
    else if (clicked_button==1 || Is_shortcut(Key,0x100+BUTTON_PAINTBRUSHES))
 
2574
    {
 
2575
      Close_window();
 
2576
      break;
 
2577
    }
 
2578
  }
 
2579
  while (1);
2225
2580
 
2226
2581
  Unselect_button(BUTTON_PAINTBRUSHES);
2227
2582
  Display_cursor();
2392
2747
      use_brush_palette=Confirmation_box("Use the palette of the brush?");
2393
2748
  }
2394
2749
 
 
2750
  // do_not_restore is modified inside the first if, that's why we check it
 
2751
  // again here
2395
2752
  if (do_not_restore)
2396
2753
  {
2397
2754
    old_cursor_shape=Cursor_shape;
2421
2778
 
2422
2779
      if (File_error==3) // On ne peut pas allouer la brosse
2423
2780
      {
2424
 
        if (Brush) free(Brush);
 
2781
        free(Brush);
2425
2782
        Brush=(byte *)malloc(1*1);
2426
2783
        Brush_height=1;
2427
2784
        Brush_width=1;
2428
2785
        *Brush=Fore_color;
2429
2786
 
2430
 
        if (Smear_brush) free(Smear_brush);
 
2787
        free(Smear_brush);
2431
2788
        Smear_brush=(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE);
2432
2789
        Smear_brush_height=MAX_PAINTBRUSH_SIZE;
2433
2790
        Smear_brush_width=MAX_PAINTBRUSH_SIZE;
2485
2842
        }
2486
2843
 
2487
2844
        new_mode=Best_video_mode();
2488
 
        // TODO : Utiliser i�i Ratio_of_loaded_image pour passer dans la
2489
 
        // bonne taille de pixels.
2490
2845
        if ((Config.Auto_set_res) && (new_mode!=Current_resolution))
2491
2846
        {
2492
2847
          Init_mode_video(
2496
2851
            Pixel_ratio);
2497
2852
          Display_menu();
2498
2853
        }
 
2854
        // In window mode, activate wide or tall pixels if the image says so.
 
2855
        else if (!Video_mode[Current_resolution].Fullscreen &&
 
2856
          ((Ratio_of_loaded_image == PIXEL_WIDE &&
 
2857
            Pixel_ratio != PIXEL_WIDE && Pixel_ratio != PIXEL_WIDE2) ||
 
2858
            (Ratio_of_loaded_image == PIXEL_TALL &&
 
2859
            Pixel_ratio != PIXEL_TALL && Pixel_ratio != PIXEL_TALL2)))
 
2860
        {
 
2861
          Init_mode_video(
 
2862
            Video_mode[Current_resolution].Width,
 
2863
            Video_mode[Current_resolution].Height,
 
2864
            Video_mode[Current_resolution].Fullscreen,
 
2865
            Ratio_of_loaded_image);
 
2866
            Display_menu();
 
2867
        }
2499
2868
        else
2500
2869
        {
2501
2870
          Main_offset_X=0;
2515
2884
    Display_cursor();
2516
2885
  }
2517
2886
 
2518
 
  if (!image)
2519
 
    free(initial_palette);
 
2887
  free(initial_palette);
2520
2888
 
2521
2889
  if (!do_not_restore)
2522
2890
  {
2576
2944
        Main_magnifier_mode=0;
2577
2945
      }
2578
2946
 
2579
 
      new_mode=Best_video_mode();
2580
 
      // TODO : Utiliser i�i Ratio_of_loaded_image pour passer dans la
2581
 
      // bonne taille de pixels.      
 
2947
      new_mode=Best_video_mode();     
2582
2948
      if ( ((Config.Auto_set_res) && (new_mode!=Current_resolution)) &&
2583
2949
           (!Resolution_in_command_line) )
2584
2950
      {
2589
2955
        Pixel_ratio);
2590
2956
        Display_menu();
2591
2957
      }
 
2958
      // In window mode, activate wide or tall pixels if the image says so.
 
2959
      else if (!Video_mode[Current_resolution].Fullscreen &&
 
2960
        ((Ratio_of_loaded_image == PIXEL_WIDE &&
 
2961
          Pixel_ratio != PIXEL_WIDE && Pixel_ratio != PIXEL_WIDE2) ||
 
2962
          (Ratio_of_loaded_image == PIXEL_TALL &&
 
2963
          Pixel_ratio != PIXEL_TALL && Pixel_ratio != PIXEL_TALL2)))
 
2964
      {
 
2965
        Init_mode_video(
 
2966
          Video_mode[Current_resolution].Width,
 
2967
          Video_mode[Current_resolution].Height,
 
2968
          Video_mode[Current_resolution].Fullscreen,
 
2969
          Ratio_of_loaded_image);
 
2970
          Display_menu();
 
2971
      }
2592
2972
      else
2593
2973
      {
2594
2974
        Main_offset_X=0;
3026
3406
    clicked_button=Window_clicked_button();
3027
3407
    if (Is_shortcut(Key,0x100+BUTTON_HELP))
3028
3408
      Window_help(BUTTON_MAGNIFIER, NULL);
 
3409
    else if (Is_shortcut(Key,0x200+BUTTON_MAGNIFIER))
 
3410
      clicked_button=1;
3029
3411
  }
3030
3412
  while (clicked_button<=0);
3031
3413
 
3255
3637
  Display_cursor();
3256
3638
}
3257
3639
 
 
3640
void Button_Show_grid(void)
 
3641
{
 
3642
  Show_grid = !Show_grid;
 
3643
  Hide_cursor();
 
3644
  Display_all_screen();
 
3645
  Display_cursor();
 
3646
3258
3647
 
3259
3648
// ----------------------- Modifications de brosse ---------------------------
3260
3649
 
3339
3728
      Key=0;
3340
3729
      Window_help(BUTTON_BRUSH_EFFECTS, NULL);
3341
3730
    }
 
3731
    else if (Is_shortcut(Key,0x100+BUTTON_BRUSH_EFFECTS))
 
3732
    {
 
3733
      clicked_button=1;
 
3734
    }
3342
3735
  }
3343
3736
  while (clicked_button<=0);
3344
3737
 
3513
3906
    }
3514
3907
    if (Is_shortcut(Key,0x100+BUTTON_HELP))
3515
3908
      Window_help(BUTTON_EFFECTS, "SMOOTH");
 
3909
    else if (Is_shortcut(Key,SPECIAL_SMOOTH_MENU))
 
3910
      clicked_button=2;
3516
3911
  }
3517
3912
  while ((clicked_button!=1) && (clicked_button!=2));
3518
3913
 
3544
3939
  Smear_mode=!Smear_mode;
3545
3940
}
3546
3941
 
3547
 
 
3548
3942
// -- Mode Colorize ---------------------------------------------------------
3549
3943
void Compute_colorize_table(void)
3550
3944
{
3679
4073
    }
3680
4074
    if (Is_shortcut(Key,0x100+BUTTON_HELP))
3681
4075
      Window_help(BUTTON_EFFECTS, "TRANSPARENCY");
 
4076
      else if (Is_shortcut(Key,SPECIAL_COLORIZE_MENU))
 
4077
        clicked_button=6;
3682
4078
  }
3683
4079
  while (clicked_button<5);
3684
4080
 
3792
4188
  Display_cursor();
3793
4189
}
3794
4190
 
 
4191
// -- All modes off ---------------------------------------------------------
 
4192
void Effects_off(void)
 
4193
{
 
4194
  Effect_function=No_effect;
 
4195
  Shade_mode=0;
 
4196
  Quick_shade_mode=0;
 
4197
  Colorize_mode=0;
 
4198
  Smooth_mode=0;
 
4199
  Tiling_mode=0;
 
4200
  Smear_mode=0;
 
4201
  Stencil_mode=0;
 
4202
  Mask_mode=0;
 
4203
  Sieve_mode=0;
 
4204
  Snap_mode=0;  
 
4205
}
 
4206
 
 
4207
void Transparency_set(byte amount)
 
4208
{
 
4209
  const int doubleclick_delay = Config.Double_key_speed;
 
4210
  static long time_click = 0;
 
4211
  long time_previous;
 
4212
  
 
4213
  if (!Colorize_mode)
 
4214
  {
 
4215
    // Activate mode
 
4216
    switch(Colorize_current_mode)
 
4217
    {
 
4218
      case 0 :
 
4219
        Effect_function=Effect_interpolated_colorize;
 
4220
        break;
 
4221
      case 1 :
 
4222
        Effect_function=Effect_additive_colorize;
 
4223
        break;
 
4224
      case 2 :
 
4225
        Effect_function=Effect_substractive_colorize;
 
4226
    }
 
4227
    Shade_mode=0;
 
4228
    Quick_shade_mode=0;
 
4229
    Smooth_mode=0;
 
4230
    Tiling_mode=0;
 
4231
 
 
4232
    Colorize_mode=1;
 
4233
  }
 
4234
 
 
4235
  time_previous = time_click;
 
4236
  time_click = SDL_GetTicks();
 
4237
 
 
4238
  // Check if it's a quick re-press
 
4239
  if (time_click - time_previous < doubleclick_delay)
 
4240
  {
 
4241
    // Use the typed amount as units, keep the tens.
 
4242
    Colorize_opacity = ((Colorize_opacity%100) /10 *10) + amount;
 
4243
    if (Colorize_opacity == 0)
 
4244
      Colorize_opacity = 100;
 
4245
  }
 
4246
  else
 
4247
  {
 
4248
    // Use 10% units: "1"=10%, ... "0"=100%
 
4249
    if (amount == 0)
 
4250
      Colorize_opacity = 100;
 
4251
    else
 
4252
      Colorize_opacity = amount*10;
 
4253
  }
 
4254
  Compute_colorize_table();
 
4255
}
3795
4256
 
3796
4257
//---------------------------- Courbes de B�zier ----------------------------
3797
4258
 
4149
4610
        Key=0;
4150
4611
        break;
4151
4612
      }
4152
 
        
 
4613
      if (Is_shortcut(Key,0x200+BUTTON_AIRBRUSH))
 
4614
      {
 
4615
        clicked_button=2;
 
4616
        break;
 
4617
      }
4153
4618
    }
4154
4619
  }
4155
4620
  while ( (clicked_button!=1) && (clicked_button!=2) );
4246
4711
      for (i=0; i<16*Menu_factor_X/Zoom; i++)
4247
4712
        Block(((index*23+10)*Menu_factor_X)+i*Zoom+Window_pos_X,
4248
4713
          (22*Menu_factor_Y)+j*Zoom+Window_pos_Y,Zoom,Zoom,
4249
 
          ((GFX_sieve_pattern[index][j&0xF]>>(15-(i&0xF)))&1)?MC_White:MC_Black);
 
4714
          ((Gfx->Sieve_pattern[index][j&0xF]>>(15-(i&0xF)))&1)?MC_White:MC_Black);
4250
4715
 
4251
4716
  Update_rect(ToWinX(10),ToWinY(22),ToWinL(12*23+16),ToWinH(16));
4252
4717
}
4258
4723
 
4259
4724
  for (j=0; j<16; j++)
4260
4725
    for (i=0; i<16; i++)
4261
 
      Sieve[i][j]=(GFX_sieve_pattern[index][j]>>(15-i))&1;
 
4726
      Sieve[i][j]=(Gfx->Sieve_pattern[index][j]>>(15-i))&1;
4262
4727
  Sieve_width=16;
4263
4728
  Sieve_height=16;
4264
4729
}
4456
4921
        break;
4457
4922
 
4458
4923
      case  7 : // Transfer to brush
4459
 
        if (Brush)
4460
 
          free(Brush);
4461
4924
        Brush_width=Sieve_width;
4462
4925
        Brush_height=Sieve_height;
 
4926
        free(Brush);
4463
4927
        Brush=(byte *)malloc(((long)Brush_height)*Brush_width);
4464
4928
        for (y_pos=0; y_pos<Sieve_height; y_pos++)
4465
4929
          for (x_pos=0; x_pos<Sieve_width; x_pos++)
4686
5150
 
4687
5151
  for (y=0,y_pos=start_y;y<MENU_SPRITE_HEIGHT;y++,y_pos++)
4688
5152
    for (x=0,x_pos=start_x;x<MENU_SPRITE_WIDTH;x++,x_pos++)
4689
 
      Pixel_in_window(x_pos,y_pos,GFX_effect_sprite[sprite_number][y][x]);
 
5153
      Pixel_in_window(x_pos,y_pos,Gfx->Effect_sprite[sprite_number][y][x]);
4690
5154
 
4691
5155
  Update_rect(ToWinX(start_x),ToWinY(start_y),MENU_SPRITE_WIDTH*Menu_factor_X,MENU_SPRITE_HEIGHT*Menu_factor_Y);
4692
5156
}
4767
5231
  {
4768
5232
    clicked_button=Window_clicked_button();
4769
5233
 
4770
 
    if (Key==KEY_ESC)
 
5234
    if (Key==KEY_ESC || Is_shortcut(Key,0x100+BUTTON_EFFECTS))
4771
5235
    {
4772
5236
      clicked_button=11;
4773
5237
      Key=0;
4774
5238
    }
4775
5239
    else if (Is_shortcut(Key,0x100+BUTTON_HELP))
4776
5240
    {
4777
 
      Key=0;
4778
5241
      // Aide contextuelle
4779
5242
      switch(Window_get_clicked_button())
4780
5243
      {
4811
5274
        default:
4812
5275
          Window_help(BUTTON_EFFECTS, NULL);
4813
5276
      }
4814
 
      continue;  
 
5277
      // Hack because we have used Window_get_clicked_button()
 
5278
      Input_sticky_control=0;
 
5279
      //
4815
5280
    }
4816
5281
 
4817
5282
    switch (clicked_button)
4970
5435
        exit_by_close_button=1;
4971
5436
        break;
4972
5437
      case 12 : // All off
4973
 
        Effect_function=No_effect;
4974
 
        Shade_mode=0;
4975
 
        Quick_shade_mode=0;
4976
 
        Colorize_mode=0;
4977
 
        Smooth_mode=0;
4978
 
        Tiling_mode=0;
4979
 
        Smear_mode=0;
4980
 
        Stencil_mode=0;
4981
 
        Mask_mode=0;
4982
 
        Sieve_mode=0;
4983
 
        Snap_mode=0;
 
5438
        Effects_off();
4984
5439
        Hide_cursor();
4985
5440
        Display_effect_states();
4986
5441
        Display_cursor();
5009
5464
  Display_cursor();
5010
5465
}
5011
5466
 
5012
 
// Affiche tout le selecteur de fontes
5013
 
void Draw_font_selector(short x, short y, short list_start, short cursor_position, short nb_visibles)
 
5467
// Callback to display a font name in the list
 
5468
void Draw_one_font_name(word x, word y, word index, byte highlighted)
5014
5469
{
5015
 
  int index;
5016
 
  for (index=0; index < nb_visibles; index++)
5017
 
  {
5018
 
    Print_in_window(x,y+index*8,Font_label(index+list_start), MC_Black, (cursor_position==index)?MC_Dark:MC_Light);
5019
 
  }
 
5470
  Print_in_window(x,y,Font_label(index), MC_Black, (highlighted)?MC_Dark:MC_Light);
5020
5471
}
5021
5472
 
5022
5473
void Button_Text()
5026
5477
  static int antialias=1;
5027
5478
  static short list_start=0; // index de le premiere fonte dans le selector
5028
5479
  static short cursor_position=0; // index de la ligne active dans le selector
 
5480
  static short selected_font_index=0;
5029
5481
  static short is_bold=0;
5030
5482
  static short is_italic=0;
5031
5483
 
5038
5490
  T_Special_button * input_size_button;
5039
5491
  T_Special_button * input_text_button;
5040
5492
  T_Special_button * preview_button;
 
5493
  T_Special_button * font_list_button;
5041
5494
  T_Scroller_button * font_scroller;
 
5495
  T_List_button * font_list;
 
5496
  
5042
5497
  byte redraw_is_needed=1;
5043
5498
  byte preview_is_needed=1;
5044
 
  short temp;
5045
5499
  
5046
5500
  Open_window(288,180,"Text");
5047
5501
 
5065
5519
  // Scroller des fontes
5066
5520
  font_scroller = Window_set_scroller_button(165,35,NB_FONTS*8,Nb_fonts,NB_FONTS,list_start); // 5
5067
5521
  // Liste des fontes disponibles
5068
 
  Window_set_special_button(8,35,152,NB_FONTS*8); // 6
 
5522
  font_list_button = Window_set_special_button(8,35,152,NB_FONTS*8); // 6
5069
5523
  Window_display_frame_in(7, 33, 154, NB_FONTS*8+4);
5070
5524
  
5071
5525
  // Taille texte
5079
5533
  
5080
5534
  Window_set_normal_button(8,160,40,14,"OK",0,1,SDLK_RETURN); // 11
5081
5535
  Window_set_normal_button(54,160,60,14,"Cancel",0,1,KEY_ESC); // 12
 
5536
  
 
5537
  // List of fonts
 
5538
  font_list = Window_set_list_button(font_list_button, font_scroller, Draw_one_font_name); // 13
 
5539
  // Restore its settings from last passage in screen
 
5540
  font_list->List_start = list_start;
 
5541
  font_list->Cursor_position = cursor_position;
 
5542
  
 
5543
  Window_redraw_list(font_list);
 
5544
  
5082
5545
  Update_window_area(0,0,Window_width, Window_height);
5083
5546
  
5084
5547
  // str texte
5094
5557
      // Taille
5095
5558
      Num2str(font_size,size_buffer,3);
5096
5559
      Window_input_content(input_size_button,size_buffer);
5097
 
      // Selecteur de fonte
5098
 
      Draw_font_selector(8, 35, list_start, cursor_position, NB_FONTS);
5099
5560
    }
5100
5561
    if (preview_is_needed)
5101
5562
    {
5102
5563
      const char * preview_string = "AaBbCcDdEeFf012345";
5103
5564
      if (str[0])
5104
5565
        preview_string=str;
5105
 
      if (new_brush)
5106
 
      {
5107
 
        free(new_brush);
5108
 
      }
5109
5566
      Window_rectangle(8, 106, 273, 50,Back_color);
5110
 
      new_brush = Render_text(preview_string, cursor_position+list_start, font_size, antialias, is_bold, is_italic, &new_width, &new_height);
 
5567
      free(new_brush);
 
5568
      new_brush = Render_text(preview_string, selected_font_index, font_size, antialias, is_bold, is_italic, &new_width, &new_height);
5111
5569
      if (new_brush)
5112
5570
      {
5113
5571
        Display_brush(
5137
5595
    clicked_button=Window_clicked_button();
5138
5596
    if (clicked_button==0)
5139
5597
    {
5140
 
      if (Key==SDLK_UP && (cursor_position+list_start)>0)
5141
 
      {
5142
 
        Key=0;
5143
 
        Hide_cursor();
5144
 
        cursor_position--;
5145
 
        if (cursor_position<0)
5146
 
        {
5147
 
          list_start=list_start+cursor_position;
5148
 
          cursor_position=0;
5149
 
          // Mise � jour du scroller
5150
 
          font_scroller->Position=list_start;
5151
 
          Window_draw_slider(font_scroller);
5152
 
        }
5153
 
        redraw_is_needed=1;
5154
 
        preview_is_needed=1;
5155
 
      }
5156
 
      if (Key==SDLK_DOWN && (cursor_position+list_start)<(Nb_fonts-1))
5157
 
      {
5158
 
        Key=0;
5159
 
        Hide_cursor();
5160
 
        cursor_position++;
5161
 
        if (cursor_position>(NB_FONTS-1))
5162
 
        {
5163
 
          list_start=list_start+cursor_position-(NB_FONTS-1);
5164
 
          cursor_position=(NB_FONTS-1);
5165
 
          // Mise � jour du scroller
5166
 
          font_scroller->Position=list_start;
5167
 
          Window_draw_slider(font_scroller);
5168
 
        }
5169
 
        redraw_is_needed=1;
5170
 
        preview_is_needed=1;
5171
 
      }
5172
 
      if (Key==SDLK_HOME && (cursor_position!=0 || list_start!=0))
5173
 
      {
5174
 
        Key=0;
5175
 
        Hide_cursor();
5176
 
        cursor_position=0;
5177
 
        list_start=0;
5178
 
        // Mise � jour du scroller
5179
 
        font_scroller->Position=list_start;
5180
 
        Window_draw_slider(font_scroller);
5181
 
        redraw_is_needed=1;
5182
 
        preview_is_needed=1;
5183
 
      }
5184
 
      if (Key==SDLK_END && (cursor_position+list_start)<(Nb_fonts-1))
5185
 
      {
5186
 
        Key=0;
5187
 
        Hide_cursor();
5188
 
        cursor_position=(Nb_fonts-1)-list_start;
5189
 
        if (cursor_position>(NB_FONTS-1))
5190
 
        {
5191
 
          list_start=list_start+cursor_position-(NB_FONTS-1);
5192
 
          cursor_position=(NB_FONTS-1);
5193
 
          // Mise � jour du scroller
5194
 
          font_scroller->Position=list_start;
5195
 
          Window_draw_slider(font_scroller);
5196
 
        }
5197
 
        redraw_is_needed=1;
5198
 
        preview_is_needed=1;
5199
 
      }
5200
 
      if (Key==SDLK_PAGEDOWN && (cursor_position+list_start)<(Nb_fonts-1))
5201
 
      {
5202
 
        Key=0;
5203
 
        Hide_cursor();
5204
 
        if (Nb_fonts<NB_FONTS)
5205
 
        {
5206
 
          cursor_position=Nb_fonts-1;
5207
 
        }
5208
 
        else if(cursor_position!=NB_FONTS-1)
5209
 
        {
5210
 
          cursor_position=NB_FONTS-1;
5211
 
        }
5212
 
        else
5213
 
        {
5214
 
          list_start+=NB_FONTS;
5215
 
          if (list_start+NB_FONTS>Nb_fonts)
5216
 
          {
5217
 
            list_start=Nb_fonts-NB_FONTS;
5218
 
          }
5219
 
          // Mise � jour du scroller
5220
 
          font_scroller->Position=list_start;
5221
 
          Window_draw_slider(font_scroller);
5222
 
        }
5223
 
        redraw_is_needed=1;
5224
 
        preview_is_needed=1;
5225
 
      }
5226
 
      if (Key==SDLK_PAGEUP && (cursor_position+list_start)>0)
5227
 
      {
5228
 
        Key=0;
5229
 
        Hide_cursor();
5230
 
        if(cursor_position!=0)
5231
 
        {
5232
 
          cursor_position=0;
5233
 
        }
5234
 
        else
5235
 
        {
5236
 
          list_start-=NB_FONTS;
5237
 
          if (list_start<0)
5238
 
          {
5239
 
            list_start=0;
5240
 
          }
5241
 
          // Mise � jour du scroller
5242
 
          font_scroller->Position=list_start;
5243
 
          Window_draw_slider(font_scroller);
5244
 
        }
5245
 
        redraw_is_needed=1;
5246
 
        preview_is_needed=1;
5247
 
      }
5248
 
      if (Key == KEY_MOUSEWHEELUP && list_start>0)
5249
 
      {
5250
 
        cursor_position+=list_start;
5251
 
        if (list_start>=3)
5252
 
          list_start-=3;
5253
 
        else
5254
 
          list_start=0;
5255
 
        cursor_position-=list_start;
5256
 
        // On affiche � nouveau la liste
5257
 
        Hide_cursor();
5258
 
        redraw_is_needed=1;
5259
 
        // Mise � jour du scroller
5260
 
        font_scroller->Position=list_start;
5261
 
        Window_draw_slider(font_scroller);
5262
 
      }
5263
 
      if (Key==KEY_MOUSEWHEELDOWN && list_start<Nb_fonts-NB_FONTS)
5264
 
      {
5265
 
        cursor_position+=list_start;
5266
 
        list_start+=3;
5267
 
        if (list_start+NB_FONTS>Nb_fonts)
5268
 
        {
5269
 
          list_start=Nb_fonts-NB_FONTS;
5270
 
        }          
5271
 
        cursor_position-=list_start;
5272
 
        // On affiche � nouveau la liste
5273
 
        Hide_cursor();
5274
 
        redraw_is_needed=1;
5275
 
        // Mise � jour du scroller
5276
 
        font_scroller->Position=list_start;
5277
 
        Window_draw_slider(font_scroller);
5278
 
      }
5279
5598
      if (Is_shortcut(Key,0x100+BUTTON_HELP))
5280
5599
        Window_help(BUTTON_TEXT, NULL);
 
5600
      else if (Is_shortcut(Key,0x100+BUTTON_TEXT))
 
5601
        clicked_button=12;
5281
5602
    }
5282
5603
    switch(clicked_button)
5283
5604
    {
5308
5629
      break;
5309
5630
      
5310
5631
      case 5: // Scroller des fontes
5311
 
      if (list_start!=Window_attribute2)
5312
 
      {
5313
 
        cursor_position+=list_start;
5314
 
        list_start=Window_attribute2;
5315
 
        cursor_position-=list_start;
5316
 
        // On affiche � nouveau la liste
5317
 
        Hide_cursor();
5318
 
        redraw_is_needed=1;
5319
 
      }
 
5632
      /* Cannot happen, event is catched by the list control */
5320
5633
      break;
5321
5634
      
5322
5635
      case 6: // Selecteur de fonte
5323
 
      temp=(((Mouse_Y-Window_pos_Y)/Menu_factor_Y)-35)>>3;
5324
 
      if (temp!=cursor_position && temp < Nb_fonts)
5325
 
      {
5326
 
        cursor_position=temp;
5327
 
        // On affiche � nouveau la liste
 
5636
      /* Cannot happen, event is catched by the list control */
 
5637
      break;
 
5638
      
 
5639
      case 13: // Font selection
 
5640
        selected_font_index = Window_attribute2;
5328
5641
        Hide_cursor();
5329
 
        redraw_is_needed=1;
5330
5642
        preview_is_needed=1;
5331
 
      }
5332
5643
      break;
5333
 
            
 
5644
                  
5334
5645
      case 7: // Taille du texte (nombre)
5335
5646
      Readline(222,45,size_buffer,3,1);
5336
5647
      font_size=atoi(size_buffer);
5369
5680
      
5370
5681
    
5371
5682
      case 11: // OK
 
5683
      // Save the selector settings
 
5684
      list_start = font_list->List_start;
 
5685
      cursor_position = font_list->Cursor_position;
 
5686
      
5372
5687
      if (!new_brush)
5373
5688
      {
5374
5689
        // Si echec de rendu
5378
5693
        Error(0);
5379
5694
        return;
5380
5695
      }
5381
 
      if (Brush) free(Brush);
 
5696
      free(Brush);
5382
5697
    
5383
5698
      Brush=new_brush;
5384
5699
      Brush_width=new_width;
5392
5707
      
5393
5708
      // On passe en brosse:
5394
5709
      Display_cursor();
5395
 
      if (antialias || !TrueType_font(cursor_position+list_start))
 
5710
      if (antialias || !TrueType_font(selected_font_index))
5396
5711
        Change_paintbrush_shape(PAINTBRUSH_SHAPE_COLOR_BRUSH);
5397
5712
      else
5398
5713
        Change_paintbrush_shape(PAINTBRUSH_SHAPE_MONO_BRUSH);
5408
5723
      return;
5409
5724
      
5410
5725
      case 12: // Cancel
5411
 
      if (new_brush)
5412
 
        free(new_brush);
 
5726
      // Save the selector settings
 
5727
      list_start = font_list->List_start;
 
5728
      cursor_position = font_list->Cursor_position;
 
5729
      
 
5730
      free(new_brush);
 
5731
          new_brush = NULL;
5413
5732
      Close_window();
5414
5733
      Unselect_button(BUTTON_TEXT);
5415
5734
      Display_cursor();
5418
5737
  }
5419
5738
}
5420
5739
 
5421
 
 
5422
 
 
5423
 
/*
5424
 
BUTTON_GRADRECT
5425
 
-BUTTON_SPHERES       (Ellipses d�grad�es � am�liorer)
5426
 
BUTTON_TEXT
5427
 
-BUTTON_ADJUST       (Effets sur l'image)
5428
 
-BUTTON_BRUSH_EFFECTS (Distort, Rot. any angle)
5429
 
*/
 
5740
void Display_stored_brush_in_window(word x_pos,word y_pos,int index)
 
5741
{
 
5742
  if (Brush_container[index].Paintbrush_shape < PAINTBRUSH_SHAPE_MAX)
 
5743
  {
 
5744
    int x,y;
 
5745
    int offset_x=0, offset_y=0;
 
5746
    //int brush_offset_x=0, brush_offset_y=0;
 
5747
    
 
5748
    // Determine draw offset (small brushes are stacked on corner of their preview)
 
5749
    if (Brush_container[index].Width<BRUSH_CONTAINER_PREVIEW_WIDTH)
 
5750
      offset_x = (BRUSH_CONTAINER_PREVIEW_WIDTH-Brush_container[index].Width)/2;
 
5751
    if (Brush_container[index].Height<BRUSH_CONTAINER_PREVIEW_HEIGHT)
 
5752
      offset_y = (BRUSH_CONTAINER_PREVIEW_HEIGHT-Brush_container[index].Height)/2;
 
5753
    // Determine corner pixel of paintbrush to draw (if bigger than preview area) 
 
5754
    //
 
5755
    
 
5756
    // Clear
 
5757
    Window_rectangle(x_pos,y_pos,BRUSH_CONTAINER_PREVIEW_WIDTH,BRUSH_CONTAINER_PREVIEW_HEIGHT,MC_Light);
 
5758
    
 
5759
    // Draw up to 16x16
 
5760
    for (y=0; y<Brush_container[index].Height && y<BRUSH_CONTAINER_PREVIEW_HEIGHT; y++)
 
5761
    {
 
5762
      for (x=0; x<Brush_container[index].Width && x<BRUSH_CONTAINER_PREVIEW_WIDTH; x++)
 
5763
      {
 
5764
        byte color;
 
5765
        if (Brush_container[index].Paintbrush_shape <= PAINTBRUSH_SHAPE_MISC)
 
5766
          color = Brush_container[index].Thumbnail[y][x]?MC_Black:MC_Light;
 
5767
        else
 
5768
          color = Brush_container[index].Thumbnail[y][x];
 
5769
        Pixel_in_window(x_pos+x+offset_x,y_pos+y+offset_y,color);
 
5770
      }
 
5771
    }
 
5772
    Update_window_area(x_pos,y_pos,BRUSH_CONTAINER_PREVIEW_WIDTH,BRUSH_CONTAINER_PREVIEW_HEIGHT);
 
5773
    
 
5774
  }
 
5775
}
 
5776
 
 
5777
void Store_brush(int index)
 
5778
{
 
5779
  if (Brush_container[index].Paintbrush_shape < PAINTBRUSH_SHAPE_MAX)
 
5780
  {
 
5781
    // Free previous stored brush
 
5782
    Brush_container[index].Paintbrush_shape = PAINTBRUSH_SHAPE_MAX;
 
5783
    free(Brush_container[index].Brush);
 
5784
    Brush_container[index].Brush = NULL;
 
5785
  }
 
5786
 
 
5787
  // Store a mono brush
 
5788
  if (Paintbrush_shape <= PAINTBRUSH_SHAPE_MISC)
 
5789
  {
 
5790
    int x,y;
 
5791
    int brush_offset_x=0, brush_offset_y=0;
 
5792
    
 
5793
    Brush_container[index].Paintbrush_shape=Paintbrush_shape;
 
5794
    Brush_container[index].Width=Paintbrush_width;
 
5795
    Brush_container[index].Height=Paintbrush_height;
 
5796
    //memcpy(Brush_container[index].Palette,Main_palette,sizeof(T_Palette));
 
5797
    // Preview: pick center for big mono brush
 
5798
    if (Paintbrush_width>BRUSH_CONTAINER_PREVIEW_WIDTH)
 
5799
      brush_offset_x = (Paintbrush_width-BRUSH_CONTAINER_PREVIEW_WIDTH)/2;
 
5800
    if (Paintbrush_height>BRUSH_CONTAINER_PREVIEW_HEIGHT)
 
5801
      brush_offset_y = (Paintbrush_height-BRUSH_CONTAINER_PREVIEW_HEIGHT)/2;
 
5802
 
 
5803
    for (y=0; y<BRUSH_CONTAINER_PREVIEW_HEIGHT && y<Paintbrush_height; y++)
 
5804
      for (x=0; x<BRUSH_CONTAINER_PREVIEW_WIDTH && x<Paintbrush_width; x++)
 
5805
        Brush_container[index].Thumbnail[y][x]=Paintbrush_sprite[((y+brush_offset_y)*MAX_PAINTBRUSH_SIZE)+x+brush_offset_x];
 
5806
    // Re-init the rest
 
5807
    Brush_container[index].Transp_color=0;
 
5808
  }
 
5809
  if (Paintbrush_shape == PAINTBRUSH_SHAPE_COLOR_BRUSH ||
 
5810
     Paintbrush_shape == PAINTBRUSH_SHAPE_MONO_BRUSH)
 
5811
  {
 
5812
    Brush_container[index].Brush=(byte *)malloc(Brush_width*Brush_height);
 
5813
    if (Brush_container[index].Brush)
 
5814
    {
 
5815
      Brush_container[index].Paintbrush_shape=Paintbrush_shape;
 
5816
      Brush_container[index].Width=Brush_width;
 
5817
      Brush_container[index].Height=Brush_height;
 
5818
 
 
5819
      memcpy(Brush_container[index].Brush, Brush,Brush_height*Brush_width);
 
5820
 
 
5821
      // Scale for preview
 
5822
      if (Brush_width>BRUSH_CONTAINER_PREVIEW_WIDTH ||
 
5823
          Brush_height>BRUSH_CONTAINER_PREVIEW_HEIGHT)
 
5824
      {
 
5825
        // Scale
 
5826
        Rescale(Brush, Brush_width, Brush_height, (byte *)(Brush_container[index].Thumbnail), BRUSH_CONTAINER_PREVIEW_WIDTH, BRUSH_CONTAINER_PREVIEW_HEIGHT, 0, 0);
 
5827
      }
 
5828
      else
 
5829
      {
 
5830
        // Direct copy
 
5831
        Copy_part_of_image_to_another(Brush, 0,0,Brush_width, Brush_height,Brush_width,(byte *)(Brush_container[index].Thumbnail),0,0,BRUSH_CONTAINER_PREVIEW_WIDTH);
 
5832
      }
 
5833
    }
 
5834
    else
 
5835
    {
 
5836
      Error(0);
 
5837
    }
 
5838
  }
 
5839
}
 
5840
 
 
5841
byte Restore_brush(int index)
 
5842
{
 
5843
  byte shape;
 
5844
  word x_pos;
 
5845
  word y_pos;
 
5846
  
 
5847
  shape = Brush_container[index].Paintbrush_shape;
 
5848
  
 
5849
  if (shape == PAINTBRUSH_SHAPE_MAX)
 
5850
    return 0;
 
5851
  // Mono brushes
 
5852
  if (shape <= PAINTBRUSH_SHAPE_MISC)
 
5853
  {
 
5854
    Paintbrush_shape=shape;
 
5855
    Paintbrush_width=Brush_container[index].Width;
 
5856
    Paintbrush_height=Brush_container[index].Height;
 
5857
    if (shape == PAINTBRUSH_SHAPE_HORIZONTAL_BAR)
 
5858
      Paintbrush_height=1;
 
5859
    else if (shape == PAINTBRUSH_SHAPE_VERTICAL_BAR)
 
5860
      Paintbrush_width=1;
 
5861
    
 
5862
    if (Paintbrush_width <= BRUSH_CONTAINER_PREVIEW_WIDTH &&
 
5863
        Paintbrush_height <= BRUSH_CONTAINER_PREVIEW_HEIGHT)
 
5864
    {
 
5865
      // Manually copy the "pixels"
 
5866
      for (y_pos=0; y_pos<Paintbrush_height; y_pos++)
 
5867
        for (x_pos=0; x_pos<Paintbrush_width; x_pos++)
 
5868
          Paintbrush_sprite[(y_pos*MAX_PAINTBRUSH_SIZE)+x_pos]=Brush_container[index].Thumbnail[y_pos][x_pos];
 
5869
          
 
5870
      Paintbrush_offset_X=Paintbrush_width>>1;
 
5871
      Paintbrush_offset_Y=Paintbrush_height>>1;
 
5872
    }
 
5873
    else
 
5874
    {
 
5875
      // Recreate the brush pixels from its shape and dimensions
 
5876
      Set_paintbrush_size(Paintbrush_width,Paintbrush_height);
 
5877
    }
 
5878
  }
 
5879
  // Color brushes
 
5880
  if (shape == PAINTBRUSH_SHAPE_COLOR_BRUSH ||
 
5881
     shape == PAINTBRUSH_SHAPE_MONO_BRUSH)
 
5882
  {
 
5883
    Paintbrush_shape=shape;
 
5884
    Realloc_brush(Brush_container[index].Width,Brush_container[index].Height);
 
5885
    // Realloc sets Brush_width and Brush_height to new size.
 
5886
    memcpy(Brush, Brush_container[index].Brush, Brush_height*Brush_width);
 
5887
    
 
5888
    Brush_offset_X=Brush_width>>1;
 
5889
    Brush_offset_Y=Brush_height>>1;
 
5890
 
 
5891
  }
 
5892
  Change_paintbrush_shape(shape);
 
5893
 
 
5894
  return 1;
 
5895
}
 
5896
 
 
5897
void Button_Brush_container(void)
 
5898
{
 
5899
  short clicked_button;
 
5900
  short x_pos,y_pos;
 
5901
  byte index;
 
5902
 
 
5903
  Open_window(BRUSH_CONTAINER_COLUMNS*(BRUSH_CONTAINER_PREVIEW_WIDTH+8)+8,
 
5904
    BRUSH_CONTAINER_ROWS*(BRUSH_CONTAINER_PREVIEW_HEIGHT+8)+40,
 
5905
    "Brushes");
 
5906
 
 
5907
  Window_set_normal_button(
 
5908
    (BRUSH_CONTAINER_COLUMNS*(BRUSH_CONTAINER_PREVIEW_WIDTH+8)-59)/2,
 
5909
    (BRUSH_CONTAINER_ROWS)*(BRUSH_CONTAINER_PREVIEW_HEIGHT+8)+18,
 
5910
    67,14,"Cancel",0,1,KEY_ESC); // 1
 
5911
 
 
5912
  index=0;
 
5913
  for (index=0; index < BRUSH_CONTAINER_ROWS*BRUSH_CONTAINER_COLUMNS; index++)
 
5914
  {
 
5915
    x_pos = (index % BRUSH_CONTAINER_COLUMNS)*(BRUSH_CONTAINER_PREVIEW_WIDTH+8)+7;
 
5916
    y_pos = (index / BRUSH_CONTAINER_COLUMNS)*(BRUSH_CONTAINER_PREVIEW_HEIGHT+8)+18;
 
5917
    Window_set_normal_button(
 
5918
      x_pos,
 
5919
      y_pos,
 
5920
      BRUSH_CONTAINER_PREVIEW_WIDTH+2,
 
5921
      BRUSH_CONTAINER_PREVIEW_HEIGHT+2,
 
5922
      "",0,1,SDLK_LAST);
 
5923
    Display_stored_brush_in_window(x_pos+1, y_pos+1, index);
 
5924
  }
 
5925
  Update_window_area(0,0,Window_width, Window_height);
 
5926
 
 
5927
  Display_cursor();
 
5928
 
 
5929
  do
 
5930
  {
 
5931
    clicked_button=Window_clicked_button();
 
5932
    //if (Is_shortcut(Key,0x100+BUTTON_HELP))
 
5933
    //  Window_help(BUTTON_PAINTBRUSHES, NULL);
 
5934
    
 
5935
    if (clicked_button == 1)
 
5936
      break;
 
5937
      
 
5938
    if (clicked_button>1)
 
5939
    {
 
5940
      index = clicked_button-2;
 
5941
      
 
5942
      if (Window_attribute1==RIGHT_SIDE)
 
5943
      {
 
5944
        // Store
 
5945
        
 
5946
        x_pos = (index % BRUSH_CONTAINER_COLUMNS)*(BRUSH_CONTAINER_PREVIEW_WIDTH+8)+7;
 
5947
        y_pos = (index / BRUSH_CONTAINER_COLUMNS)*(BRUSH_CONTAINER_PREVIEW_HEIGHT+8)+18;
 
5948
      
 
5949
        Store_brush(index);
 
5950
        Hide_cursor();
 
5951
        Display_stored_brush_in_window(x_pos+1, y_pos+1, index);
 
5952
        Display_cursor();
 
5953
      }
 
5954
      else
 
5955
      {
 
5956
        // Restore and exit
 
5957
      
 
5958
        if (Restore_brush(index))
 
5959
          break;
 
5960
      }
 
5961
    }
 
5962
  }
 
5963
  while (1);
 
5964
  Close_window();
 
5965
 
 
5966
  //Unselect_button(BUTTON_PAINTBRUSHES);
 
5967
  Display_cursor();
 
5968
}
 
 
b'\\ No newline at end of file'