Subversion Repositories Kolibri OS

Rev

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