Subversion Repositories Kolibri OS

Rev

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

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