Subversion Repositories Kolibri OS

Rev

Rev 9601 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 1024*30
  2. #define ENTRY_POINT #main
  3.  
  4. #include "../lib/kfont.h"
  5. #include "../lib/gui.h"
  6.  
  7. #define BARH 28
  8. #define WINW 528
  9. #define WINH 315
  10.  
  11. char active_tab = 0;
  12. char colored = true;
  13. dword checkbox_flag;
  14.  
  15. void main()
  16. {  
  17.         proc_info Form;
  18.  
  19.         mem_init();
  20.         checkbox_flag = memopen("CHECKBOX", NULL, SHM_READ);
  21.  
  22.         if (!param) strcpy(#param, DEFAULT_FONT);
  23.         kfont.init(#param);
  24.         strcpy(#title, "Font preview: ");
  25.         strcat(#title, #param);
  26.  
  27.         loop() switch(@WaitEvent())
  28.         {
  29.                 case evKey:
  30.                         @GetKey();
  31.                         EAX >>= 16;
  32.                         if (AL == SCAN_CODE_ESC) ExitProcess();
  33.                         if (AL == SCAN_CODE_TAB) {
  34.                                 active_tab^=1;
  35.                                 goto _DRAW_WINDOW_CONTENT;
  36.                         }
  37.                         break;
  38.  
  39.                 case evButton:
  40.                         @GetButtonID();
  41.                         if (EAX==1) ExitProcess();
  42.                         if (EAX==2) kfont.bold^=1;
  43.                         if (EAX==3) kfont.smooth^=1;
  44.                         if (EAX==4) colored^=1;
  45.                         if (EAX==5) active_tab=0;
  46.                         if (EAX==6) active_tab=1;
  47.                         GOTO _DRAW_WINDOW_CONTENT;
  48.  
  49.                 case evReDraw:
  50.                         sc.get();
  51.                         DefineAndDrawWindow(215,100,WINW+9,WINH+GetSkinHeight()+4,0x74,0xFFFFFF,#title,0);
  52.                         GetProcessInfo(#Form, SelfInfo);
  53.                         if (Form.status_window&ROLLED_UP) break;
  54.                         _DRAW_WINDOW_CONTENT:
  55.  
  56.                         DrawBar(0, 0, WINW, BARH-1, sc.work);
  57.                         DrawBar(0, BARH-1,WINW,1,sc.line);
  58.  
  59.                         if (!kfont.font) {
  60.                                 DrawBar(0, BARH, WINW, WINH - BARH, 0xFFFfff);
  61.                                 WriteText(10, 50, 0x82, 0xFF00FF, "Font is not loaded.");
  62.                         } else {
  63.                                 draw_checkbox(9, kfont.bold);
  64.                                 draw_checkbox(81, kfont.smooth);
  65.                                 draw_checkbox(169, colored);
  66.                                 WriteText(30, 8, 0x90, sc.work_text, "Bold     Smooth     Colored            Phrase   Chars");
  67.                                 UnsafeDefineButton(0, 3, 70, 24, 2+BT_HIDE+BT_NOFRAME, ESI);
  68.                                 $inc edx //11
  69.                                 $add ebx, 80 << 16
  70.                                 $int 64
  71.                                 $inc edx //12
  72.                                 $add ebx, 88 << 16
  73.                                 $int 64
  74.                                 $inc edx //13
  75.                                 $add ebx, 162 << 16
  76.                                 $int 64
  77.                                 $inc edx //14
  78.                                 $add ebx, 70 << 16
  79.                                 $int 64
  80.                                 DrawBar(active_tab*70+335, BARH-4, 60, 4, 0xE44C9C);
  81.                                 if (!active_tab) DrawPreviewPhrase(); else DrawPreviewChars();
  82.                         }
  83.         }
  84. }
  85.  
  86. dword pal[] = { 0x4E4153, 0x57417C, 0x89633B, 0x819156, 0x00CCCC, 0x2AD266,
  87.         0xE000CC, 0x0498F9, 0xC3A9F5, 0xFFC200, 0xFF5836, 0xA086BA, 0 };
  88.  
  89. void DrawPreviewPhrase()
  90. {
  91.         dword i, y=12;
  92.         dword line[64];
  93.         kfont.raw_size = free(kfont.raw);
  94.         for (i=10; i<22; i++) //not flexible, need to calculate font count and max line length
  95.         {
  96.                 strcpy(#line, " §¬¥à èà¨äâ /font size is ");
  97.                 itoa_(#line+27, i);
  98.                 strcat(#line, " ¯¨ªá¥«¥©/px.");
  99.                 kfont.WriteIntoBuffer(14,y,WINW,WINH-BARH, 0xFFFFFF, pal[i-10]*colored, i, #line);
  100.                 y+=kfont.height+3;
  101.         }
  102.         DrawBuf();
  103. }
  104.  
  105. void DrawPreviewChars()
  106. {
  107.         dword i, x=20, y=0;
  108.         char line[2];
  109.         kfont.raw_size = free(kfont.raw);
  110.         for (i=0; i<255; i++)
  111.         {
  112.                 line[0]=i;
  113.                 kfont.WriteIntoBuffer(x,y,WINW,WINH-BARH, 0xFFFFFF, 0, 16, #line);
  114.                 x+= kfont.height+2;
  115.                 if (x>=WINW-30) {
  116.                         x=20;
  117.                         y+=kfont.height+2;
  118.                 }
  119.         }
  120.         DrawBuf();
  121. }
  122.  
  123. void DrawBuf()
  124. {
  125.         if (kfont.smooth) kfont.ApplySmooth();
  126.         kfont.ShowBuffer(0, BARH);
  127. }
  128.  
  129. void draw_checkbox(dword _x, _checked)
  130. {
  131.         #define SIZE 14
  132.         #define CHBOXY 7
  133.         DrawRectangle3D(_x, CHBOXY, SIZE, SIZE, sc.line, sc.line);
  134.         if (_checked == false)
  135.         {
  136.                 DrawRectangle3D(_x+1, CHBOXY+1, SIZE-2, SIZE-2, 0xDDDddd, 0xffffff);
  137.                 DrawBar(_x+2, CHBOXY+2, SIZE-3, SIZE-3, 0xffffff);
  138.         } else {
  139.                 if (checkbox_flag) PutImage(_x+1, CHBOXY+1, 13, 13, checkbox_flag);
  140.         }
  141.         DrawRectangle3D(_x-1,CHBOXY-1,SIZE+2,SIZE+2,sc.dark,sc.light);
  142. }
  143.  
  144. char title[PATHLEN];