demo03.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. program demo03;
  2. {$I zglCustomConfig.cfg}
  3. uses
  4. zgl_main,
  5. zgl_screen,
  6. zgl_window,
  7. zgl_timers,
  8. zgl_touch,
  9. zgl_keyboard,
  10. zgl_primitives_2d,
  11. zgl_font,
  12. zgl_text,
  13. zgl_textures_png,
  14. zgl_math_2d,
  15. zgl_collision_2d,
  16. zgl_utils
  17. ;
  18. var
  19. dirRes : UTF8String = 'data/';
  20. fntMain : zglPFont;
  21. userInput : UTF8String;
  22. trackInput : Boolean;
  23. inputRect : zglTRect;
  24. lineAlpha : Byte;
  25. procedure Init;
  26. begin
  27. zgl_Enable( CORRECT_RESOLUTION );
  28. scr_CorrectResolution( 800, 600 );
  29. fntMain := font_LoadFromFile( dirRes + 'font.zfi' );
  30. inputRect.X := 400 - 192;
  31. inputRect.Y := 300 - 100 - 32;
  32. inputRect.W := 384;
  33. inputRect.H := 96;
  34. end;
  35. procedure Draw;
  36. var
  37. w : Single;
  38. begin
  39. // RU: Координаты "пальцев" можно получить при помощи функций touch_X и touch_Y.
  40. // EN: "Finger" coordinates can be got using functions touch_X and touch_Y.
  41. text_Draw( fntMain, 0, 0, 'First finger X, Y: ' + u_IntToStr( touch_X( 0 ) ) + '; ' + u_IntToStr( touch_Y( 0 ) ) );
  42. text_Draw( fntMain, 0, 16, 'Second finger X, Y: ' + u_IntToStr( touch_X( 1 ) ) + '; ' + u_IntToStr( touch_Y( 1 ) ) );
  43. // RU: Выводим введённый пользователем текст.
  44. // EN: Show the inputted text.
  45. pr2d_Rect( inputRect.X, inputRect.Y, inputRect.W, inputRect.H, $FFFFFF, 255 );
  46. if trackInput Then
  47. begin
  48. text_Draw( fntMain, 400, 300 - 100, 'Press Done to stop track text input:', TEXT_HALIGN_CENTER );
  49. w := text_GetWidth( fntMain, userInput );
  50. pr2d_Rect( 400 + w / 2 + 2, 300 - 70, 10, 20, $FFFFFF, lineAlpha, PR2D_FILL );
  51. end else
  52. text_Draw( fntMain, 400, 300 - 100, 'Tap here to enter text(maximum - 24 symbols):', TEXT_HALIGN_CENTER );
  53. text_Draw( fntMain, 400, 300 - 70, userInput, TEXT_HALIGN_CENTER );
  54. end;
  55. procedure Timer;
  56. begin
  57. if lineAlpha > 5 Then
  58. DEC( lineAlpha, 10 )
  59. else
  60. lineAlpha := 255;
  61. // RU: Проверить тапнул ли пользователь в пределах inputRect и начать отслеживать ввод текста.
  62. // EN: Check if there was tap inside inputRect and start to track text input.
  63. if touch_Tap( 0 ) and col2d_PointInRect( touch_X( 0 ), touch_Y( 0 ), inputRect ) Then
  64. begin
  65. trackInput := TRUE;
  66. key_BeginReadText( userInput, 24 );
  67. end;
  68. // RU: Если была нажата кнопка Done прекращаем отслеживать ввод текста.
  69. // EN: Finish to track text input if Done was pressed.
  70. if key_Press( K_ENTER ) Then
  71. begin
  72. trackInput := FALSE;
  73. key_EndReadText();
  74. end;
  75. // RU: Получаем введённый пользователем текст.
  76. // EN: Get inputted by user text.
  77. if trackInput Then
  78. userInput := key_GetText();
  79. // RU: Обязательно очищаем состояния всех подсистем ввода.
  80. // EN: Necessarily clear all the states of input subsystems.
  81. touch_ClearState();
  82. key_ClearState();
  83. end;
  84. Begin
  85. timer_Add( @Timer, 16 );
  86. zgl_Reg( SYS_LOAD, @Init );
  87. zgl_Reg( SYS_DRAW, @Draw );
  88. scr_SetOptions( 800, 600, REFRESH_MAXIMUM, TRUE, TRUE );
  89. zgl_Init();
  90. End.