demo06.dpr 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. program demo06;
  2. {$I zglCustomConfig.cfg}
  3. {$R *.res}
  4. uses
  5. zgl_screen,
  6. zgl_window,
  7. zgl_timers,
  8. zgl_keyboard,
  9. zgl_render_2d,
  10. zgl_fx,
  11. zgl_primitives_2d,
  12. zgl_textures,
  13. zgl_textures_png,
  14. zgl_font,
  15. zgl_text,
  16. zgl_types,
  17. zgl_utils,
  18. AsctoUtf; // äëÿ ïåðåâîäà òåêñòà â UTF-8
  19. var
  20. dirRes : UTF8String {$IFNDEF MACOSX} = '../data/' {$ENDIF};
  21. fntMain : Byte;
  22. TimeStart: Byte;
  23. MyText: UTF8String;
  24. procedure Init;
  25. //var
  26. // i : Integer;
  27. begin
  28. // RU: Çàãðóæàåì äàííûå î øðèôòå.
  29. // EN: Load the font.
  30. fntMain := font_LoadFromFile( dirRes + 'font.zfi' );
  31. // RU: Åñëè æå òåêñòóðû èìåíóþòñÿ áåç èñïîëüçîâàíèÿ ìàñêè âèäà "$(èìÿ_øðèôòà)FontName-page$(íîìåð).$(ðàñøèðåíèå)", òî çàãðóçêó ìîæíî ïðîèçâåñòè ñëåäóþùèì îáðàçîì(äëÿ png):
  32. // EN: If textures were named without special mask - "$(font_name)-page$(number).$(extension)", then use this method to load them(for png):
  33. //for i := 0 to fntMain.Count.Pages - 1 do
  34. // fntMain.Pages[ i ] := tex_LoadFromFile( dirRes + 'font-page' + u_IntToStr( i ) + '.png' );
  35. MyText := AscToUtf8Rus('Ýòî òåêñò äëÿ âûâîäà åãî â êâàäðàòå');
  36. end;
  37. procedure Draw;
  38. var
  39. r : zglTRect;
  40. s : UTF8String;
  41. begin
  42. // batch2d_Begin(); íóæíî òîëüêî äëÿ ìîáèëüíûõ ñèñòåì íà äàííîå âðåìÿ
  43. // RU: ZenGL ðàáîòàåò èñêëþ÷èòåëüíî ñ êîäèðîâêîé UTF-8, ïîýòîìó âåñü òåêñò äîëæåí áûòü â UTF-8. Åñëè íåîáõîäèìî âûâåñòè êàêîé-ëèáî òåêñò(íå àíãëèéñêèé)
  44. // èñïîëüçóÿ ñòðîêè âíóòðè pas-ôàéëîâ è Delphi âåðñèè íèæå 2009 - èñïîëüçóéòå âíåøíèå ôàéëû ñî ñòðîêàìè â êîäèðîâêå UTF-8 è òèï UTF8String äëÿ íèõ.
  45. // EN: ZenGL works only with UTF-8 encoding, so all text should be encoded with UTF-8. If you want to write some text(not English) using strings
  46. // inside pas-files and version of Delphi is lower than 2009, then you need to use external files with UTF-8 strings inside and type UTF8String.
  47. setTextScale(20, fntMain); // øðèôò ðàçìåðíîñòü 20 pix
  48. text_Draw( fntMain, 400, 65, 'Scaling', TEXT_HALIGN_CENTER );
  49. setTextScale(15, fntMain); // øðèôò ðàçìåðíîñòü 15 pix
  50. text_Draw( fntMain, 400, 25, 'String with center alignment', TEXT_HALIGN_CENTER );
  51. fx2d_SetVCA( $FF0000, $00FF00, $0000FF, $FFFFFF, 255, 255, 255, 255 );
  52. text_Draw( fntMain, 400, 125, 'Gradient color for every symbol', TEXT_FX_VCA or TEXT_HALIGN_CENTER );
  53. r.X := 0;
  54. r.Y := 300 - 128;
  55. r.W := 192;
  56. r.H := 256;
  57. text_DrawInRect( fntMain, r, 'Simple text rendering in rectangle. ' + MyText);
  58. pr2d_Rect( r.X, r.Y, r.W, r.H, $FF0000 );
  59. r.X := 800 - 192;
  60. r.Y := 300 - 128;
  61. r.W := 192;
  62. r.H := 256;
  63. text_DrawInRect( fntMain, r, 'Text rendering using horizontal right alignment and vertical bottom alignment', TEXT_HALIGN_RIGHT or TEXT_VALIGN_BOTTOM );
  64. pr2d_Rect( r.X, r.Y, r.W, r.H, $FF0000 );
  65. r.X := 400 - 192;
  66. r.Y := 300 - 128;
  67. r.W := 384;
  68. r.H := 256;
  69. text_DrawInRect( fntMain, r, 'This text uses justify alignment and centered vertically. Text which doesn''t fit inside the rectangle will be cropped.',
  70. TEXT_HALIGN_JUSTIFY or TEXT_VALIGN_CENTER );
  71. pr2d_Rect( r.X, r.Y, r.W, r.H, $FF0000 );
  72. r.X := 400 - 320;
  73. r.Y := 300 + 160;
  74. r.W := 640;
  75. r.H := 128;
  76. text_DrawInRect( fntMain, r, 'For starting new line LF symbol can be used' + #10 + 'code of which is equal to 10 and named in Unicode as "Line Feed"',
  77. TEXT_HALIGN_CENTER or TEXT_VALIGN_CENTER );
  78. pr2d_Rect( r.X, r.Y, r.W, r.H, $FF0000 );
  79. // RU: Âûâîäèì êîëè÷åñòâî FPS â ïðàâîì óãëó, èñïîëüçóÿ text_GetWidth.
  80. // EN: Render FPS in the top right corner using text_GetWidth.
  81. s := 'FPS: ' + u_IntToStr( zgl_Get( RENDER_FPS ) );
  82. text_Draw( fntMain, 800 - text_GetWidth( fntMain, s ), 0, s );
  83. // batch2d_End();
  84. end;
  85. procedure Timer;
  86. begin
  87. key_ClearState();
  88. end;
  89. Begin
  90. randomize();
  91. TimeStart := timer_Add( @Timer, 16, Start );
  92. zgl_Reg( SYS_LOAD, @Init );
  93. zgl_Reg( SYS_DRAW, @Draw );
  94. wnd_SetCaption(utf8_Copy('06 - Text'));
  95. zgl_Init();
  96. End.