Subversion Repositories Kolibri OS

Rev

Rev 6806 | Rev 7227 | 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.         STRONG_BTN=10, SMOOTH_BTN,
  13.         PHRASE_TAB=20, CHARS_TAB
  14. };
  15.  
  16. _tabs tabs = { 0,0, WIN_W, WIN_H, PHRASE_TAB};
  17.  
  18. rect preview;
  19.  
  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 (btn==STRONG_BTN) kfont.bold ^=1;
  35.                         if (btn==SMOOTH_BTN) kfont.smooth ^=1;
  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.                         CheckBox(10, 8, STRONG_BTN, "Bold",  kfont.bold);
  48.                         CheckBox(83,8, SMOOTH_BTN, "Smooth",  kfont.smooth);
  49.  
  50.                         tabs.draw_button(Form.cwidth-130, PHRASE_TAB, "Phrase");
  51.                         tabs.draw_button(Form.cwidth-60, CHARS_TAB, "Chars");
  52.  
  53.                         preview.x = tabs.x;
  54.                         preview.y = PANELH;
  55.                         preview.w = Form.cwidth;
  56.                         preview.h = Form.cheight - PANELH;
  57.  
  58.                         if (!kfont.font)
  59.                         {
  60.                                 DrawBar(preview.x, preview.y, preview.w, preview.h, 0xFFFfff);
  61.                                 WriteText(10, 50, 0x82, 0xFF00FF, "Font is not loaded.");
  62.                                 break;
  63.                         }
  64.                         if (tabs.active_tab==PHRASE_TAB) DrawPreviewPhrase();
  65.                         if (tabs.active_tab==CHARS_TAB) DrawPreviewChars();
  66.         }
  67. }
  68.  
  69. void DrawPreviewPhrase()
  70. {
  71.         dword i, y;
  72.         char line[256];
  73.         kfont.raw_size = free(kfont.raw);
  74.         for (i=10, y=5; i<22; i++, y+=kfont.height;) //not flexible, need to calculate font count and max line length
  75.         {
  76.                 sprintf(#line," §¬¥à èà¨äâ /size font %d ¯¨ªá¥«¥©.",i);
  77.                 kfont.WriteIntoBuffer(10,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, i, #line);
  78.         }
  79.         if (kfont.smooth) kfont.ApplySmooth();
  80.         kfont.ShowBuffer(preview.x, preview.y);
  81. }
  82.  
  83. void DrawPreviewChars()
  84. {
  85.         dword i, x=20, y=0;
  86.         char line[2];
  87.         line[1]=NULL;
  88.         kfont.raw_size = free(kfont.raw);
  89.         for (i=0; i<255; i++) //not flexible, need to calculate font count and max line length
  90.         {
  91.                 line[0]=i;
  92.                 kfont.WriteIntoBuffer(x,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, 16, #line);
  93.                 x+= kfont.height+2;
  94.                 if (x>=preview.w-30) {
  95.                         x=20;
  96.                         y+=kfont.height+2;
  97.                 }
  98.         }
  99.         if (kfont.smooth) kfont.ApplySmooth();
  100.         kfont.ShowBuffer(preview.x, preview.y);
  101. }
  102.