Guest User

Cursor Animation

a guest
Aug 14th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.03 KB | None | 0 0
  1. {$codepage utf-8}
  2. {$H+}
  3.  
  4. program test_cursor;
  5.    
  6. uses
  7.     BearLibTerminal, sysutils, dateutils;
  8.    
  9. var
  10.     cx, cy: Integer;
  11.  
  12. const
  13.     CURSOR_LAYER = 2;
  14.     ANIMATION_DELAY = 25;
  15.  
  16. procedure on_animation();
  17. var
  18.     previous_layer: Integer;
  19. begin
  20.     previous_layer := terminal_state(TK_LAYER);
  21.     terminal_layer(CURSOR_LAYER);
  22.     terminal_clear_area(0, 0, terminal_state(TK_WIDTH), terminal_state(TK_HEIGHT));
  23.     if MillisecondOfTheDay(Now) mod 1000 > 500 then
  24.         terminal_put(cx, cy, '_')
  25.     else
  26.         terminal_put(cx, cy, 0);
  27.     terminal_layer(previous_layer);
  28. end;
  29.  
  30. function terminal_read_animated(): Integer;
  31. begin
  32.     while not terminal_has_input() do begin
  33.         on_animation();
  34.         terminal_refresh();
  35.         terminal_delay(ANIMATION_DELAY);
  36.     end;
  37.     terminal_read_animated := terminal_read();
  38. end;
  39.  
  40. begin
  41.     terminal_open();   
  42.     terminal_set('input.filter = keyboard, close');
  43.    
  44.     cx := 2; cy := 1;
  45.    
  46.     cx := cx + terminal_print(cx, cy, 'Whatever');
  47.     repeat
  48.         terminal_refresh();
  49.     until (terminal_read_animated() = TK_CLOSE);
  50.    
  51.     terminal_close();
  52. end.
Advertisement
Add Comment
Please, Sign In to add comment