ncurses2-overlap_test.adb 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ------------------------------------------------------------------------------
  2. -- --
  3. -- GNAT ncurses Binding Samples --
  4. -- --
  5. -- ncurses --
  6. -- --
  7. -- B O D Y --
  8. -- --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 2000,2004 Free Software Foundation, Inc. --
  11. -- --
  12. -- Permission is hereby granted, free of charge, to any person obtaining a --
  13. -- copy of this software and associated documentation files (the --
  14. -- "Software"), to deal in the Software without restriction, including --
  15. -- without limitation the rights to use, copy, modify, merge, publish, --
  16. -- distribute, distribute with modifications, sublicense, and/or sell --
  17. -- copies of the Software, and to permit persons to whom the Software is --
  18. -- furnished to do so, subject to the following conditions: --
  19. -- --
  20. -- The above copyright notice and this permission notice shall be included --
  21. -- in all copies or substantial portions of the Software. --
  22. -- --
  23. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
  24. -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
  25. -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
  26. -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
  27. -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
  28. -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
  29. -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
  30. -- --
  31. -- Except as contained in this notice, the name(s) of the above copyright --
  32. -- holders shall not be used in advertising or otherwise to promote the --
  33. -- sale, use or other dealings in this Software without prior written --
  34. -- authorization. --
  35. ------------------------------------------------------------------------------
  36. -- Author: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000
  37. -- Version Control
  38. -- $Revision: 1.4 $
  39. -- $Date: 2004/08/21 21:37:00 $
  40. -- Binding Version 01.00
  41. ------------------------------------------------------------------------------
  42. with ncurses2.util; use ncurses2.util;
  43. with Terminal_Interface.Curses; use Terminal_Interface.Curses;
  44. -- test effects of overlapping windows
  45. procedure ncurses2.overlap_test is
  46. procedure fillwin (win : Window; ch : Character);
  47. procedure crosswin (win : Window; ch : Character);
  48. procedure fillwin (win : Window; ch : Character) is
  49. y1 : Line_Position;
  50. x1 : Column_Position;
  51. begin
  52. Get_Size (win, y1, x1);
  53. for y in 0 .. y1 - 1 loop
  54. Move_Cursor (win, y, 0);
  55. for x in 0 .. x1 - 1 loop
  56. Add (win, Ch => ch);
  57. end loop;
  58. end loop;
  59. exception
  60. when Curses_Exception => null;
  61. -- write to lower right corner
  62. end fillwin;
  63. procedure crosswin (win : Window; ch : Character) is
  64. y1 : Line_Position;
  65. x1 : Column_Position;
  66. begin
  67. Get_Size (win, y1, x1);
  68. for y in 0 .. y1 - 1 loop
  69. for x in 0 .. x1 - 1 loop
  70. if ((x > (x1 - 1) / 3) and (x <= (2 * (x1 - 1)) / 3))
  71. or (((y > (y1 - 1) / 3) and (y <= (2 * (y1 - 1)) / 3))) then
  72. Move_Cursor (win, y, x);
  73. Add (win, Ch => ch);
  74. end if;
  75. end loop;
  76. end loop;
  77. end crosswin;
  78. -- In a 24x80 screen like some xterms are, the instructions will
  79. -- be overwritten.
  80. ch : Character;
  81. win1 : Window := New_Window (9, 20, 3, 3);
  82. win2 : Window := New_Window (9, 20, 9, 16);
  83. begin
  84. Set_Raw_Mode (SwitchOn => True);
  85. Refresh;
  86. Move_Cursor (Line => 0, Column => 0);
  87. Add (Str => "This test shows the behavior of wnoutrefresh() with " &
  88. "respect to");
  89. Add (Ch => newl);
  90. Add (Str => "the shared region of two overlapping windows A and B. "&
  91. "The cross");
  92. Add (Ch => newl);
  93. Add (Str => "pattern in each window does not overlap the other.");
  94. Add (Ch => newl);
  95. Move_Cursor (Line => 18, Column => 0);
  96. Add (Str => "a = refresh A, then B, then doupdate. b = refresh B, " &
  97. "then A, then doupdaute");
  98. Add (Ch => newl);
  99. Add (Str => "c = fill window A with letter A. d = fill window B " &
  100. "with letter B.");
  101. Add (Ch => newl);
  102. Add (Str => "e = cross pattern in window A. f = cross pattern " &
  103. "in window B.");
  104. Add (Ch => newl);
  105. Add (Str => "g = clear window A. h = clear window B.");
  106. Add (Ch => newl);
  107. Add (Str => "i = overwrite A onto B. j = overwrite " &
  108. "B onto A.");
  109. Add (Ch => newl);
  110. Add (Str => "^Q/ESC = terminate test.");
  111. loop
  112. ch := Code_To_Char (Getchar);
  113. exit when ch = CTRL ('Q') or ch = CTRL ('['); -- QUIT or ESCAPE
  114. case ch is
  115. when 'a' => -- refresh window A first, then B
  116. Refresh_Without_Update (win1);
  117. Refresh_Without_Update (win2);
  118. Update_Screen;
  119. when 'b' => -- refresh window B first, then A
  120. Refresh_Without_Update (win2);
  121. Refresh_Without_Update (win1);
  122. Update_Screen;
  123. when 'c' => -- fill window A so it's visible
  124. fillwin (win1, 'A');
  125. when 'd' => -- fill window B so it's visible
  126. fillwin (win2, 'B');
  127. when 'e' => -- cross test pattern in window A
  128. crosswin (win1, 'A');
  129. when 'f' => -- cross test pattern in window B
  130. crosswin (win2, 'B');
  131. when 'g' => -- clear window A
  132. Clear (win1);
  133. Move_Cursor (win1, 0, 0);
  134. when 'h' => -- clear window B
  135. Clear (win2);
  136. Move_Cursor (win2, 0, 0);
  137. when 'i' => -- overwrite A onto B
  138. Overwrite (win1, win2);
  139. when 'j' => -- overwrite B onto A
  140. Overwrite (win2, win1);
  141. when others => null;
  142. end case;
  143. end loop;
  144. Delete (win2);
  145. Delete (win1);
  146. Erase;
  147. End_Windows;
  148. end ncurses2.overlap_test;