Subversion Repositories Kolibri OS

Rev

Rev 7614 | Rev 7768 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 0x2EE80
  2.  
  3. #include "../lib/kfont.h"
  4. #include "../lib/gui.h"
  5.  
  6. #define PANELH 28
  7. #define WIN_W 490
  8. #define WIN_H 315
  9. proc_info Form;
  10.  
  11. enum {
  12.         PHRASE_TAB=20, CHARS_TAB
  13. };
  14.  
  15. _tabs tabs = { PHRASE_TAB };
  16.  
  17. block preview = { 0, PANELH, WIN_W, WIN_H - PANELH };
  18. checkbox bold = { "Bold", false };
  19. checkbox smooth = { "Smooth", true };
  20. checkbox colored = { "Colored", true };
  21.  
  22. void main()
  23. {  
  24.         int btn;
  25.         char title[4196];
  26.         if (!param) strcpy(#param, DEFAULT_FONT);
  27.         kfont.init(#param);
  28.         strcpy(#title, "Font preview: ");
  29.         strcat(#title, #param);
  30.         loop() switch(WaitEvent())
  31.         {
  32.                 case evButton:
  33.                         btn = GetButtonID();
  34.                         if (btn==1) ExitProcess();
  35.                         bold.click(btn);
  36.                         smooth.click(btn);
  37.                         colored.click(btn);
  38.                         if (btn==PHRASE_TAB) || (btn==CHARS_TAB) tabs.click(btn);
  39.                         goto _DRAW_WINDOW_CONTENT;
  40.                 case evReDraw:
  41.                         system.color.get();
  42.                         DefineAndDrawWindow(215,100,WIN_W+9,WIN_H+skin_height+5,0x74,0xFFFFFF,#title,0);
  43.                         GetProcessInfo(#Form, SelfInfo);
  44.                         if (Form.status_window>2) break;
  45.                         _DRAW_WINDOW_CONTENT:
  46.  
  47.                         kfont.bold = bold.checked;
  48.                         kfont.smooth = smooth.checked;
  49.  
  50.                         DrawBar(0, 0, Form.cwidth, PANELH-1, system.color.work);
  51.                         DrawBar(0, PANELH-1,Form.cwidth,1,system.color.work_graph);
  52.                         bold.draw(10, 8);
  53.                         smooth.draw(83,8);
  54.                         colored.draw(170,8);
  55.  
  56.                         tabs.draw_button(Form.cwidth-130, PHRASE_TAB, "Phrase");
  57.                         tabs.draw_button(Form.cwidth-60, CHARS_TAB, "Chars");
  58.  
  59.                         if (!kfont.font)
  60.                         {
  61.                                 DrawBar(preview.x, preview.y, preview.w, preview.h, 0xFFFfff);
  62.                                 WriteText(10, 50, 0x82, 0xFF00FF, "Font is not loaded.");
  63.                                 break;
  64.                         }
  65.                         if (tabs.active_tab==PHRASE_TAB) DrawPreviewPhrase();
  66.                         if (tabs.active_tab==CHARS_TAB) DrawPreviewChars();
  67.         }
  68. }
  69.  
  70. dword pal[] = { 0x4E4153, 0x57417C, 0x89633B, 0x819156, 0x00CCCC, 0x2AD266,
  71.         0xE000CC, 0x0498F9, 0xC3A9F5, 0xFFC200, 0xFF5836, 0xA086BA,
  72.         0,0,0,0,0 };
  73.  
  74. void DrawPreviewPhrase()
  75. {
  76.         dword i, y;
  77.         dword c;
  78.         char line[256];
  79.         kfont.raw_size = free(kfont.raw);
  80.         for (i=10, y=12; i<22; i++, y+=kfont.height+3;) //not flexible, need to calculate font count and max line length
  81.         {
  82.                 if (colored.checked) c = pal[i-10]; else c=0;
  83.                 sprintf(#line," §¬¥à èà¨äâ /size font %d ¯¨ªá¥«¥©.",i);
  84.                 kfont.WriteIntoBuffer(14,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, c, i, #line);
  85.         }
  86.         if (kfont.smooth) kfont.ApplySmooth();
  87.         kfont.ShowBuffer(preview.x, preview.y);
  88. }
  89.  
  90. void DrawPreviewChars()
  91. {
  92.         dword i, x=20, y=0;
  93.         char line[2];
  94.         line[1]=NULL;
  95.         kfont.raw_size = free(kfont.raw);
  96.         for (i=0; i<255; i++) //not flexible, need to calculate font count and max line length
  97.         {
  98.                 line[0]=i;
  99.                 kfont.WriteIntoBuffer(x,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, 16, #line);
  100.                 x+= kfont.height+2;
  101.                 if (x>=preview.w-30) {
  102.                         x=20;
  103.                         y+=kfont.height+2;
  104.                 }
  105.         }
  106.         if (kfont.smooth) kfont.ApplySmooth();
  107.         kfont.ShowBuffer(preview.x, preview.y);
  108. }
  109.