ncurses2-demo_panels.adb 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. ------------------------------------------------------------------------------
  2. -- --
  3. -- GNAT ncurses Binding Samples --
  4. -- --
  5. -- ncurses --
  6. -- --
  7. -- B O D Y --
  8. -- --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 2000-2004,2008 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.6 $
  39. -- $Date: 2008/08/30 23:35:01 $
  40. -- Binding Version 01.00
  41. ------------------------------------------------------------------------------
  42. with ncurses2.util; use ncurses2.util;
  43. with Terminal_Interface.Curses; use Terminal_Interface.Curses;
  44. with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
  45. with Terminal_Interface.Curses.Panels.User_Data;
  46. with ncurses2.genericPuts;
  47. procedure ncurses2.demo_panels (nap_mseci : Integer) is
  48. use Int_IO;
  49. function mkpanel (color : Color_Number;
  50. rows : Line_Count;
  51. cols : Column_Count;
  52. tly : Line_Position;
  53. tlx : Column_Position) return Panel;
  54. procedure rmpanel (pan : in out Panel);
  55. procedure pflush;
  56. procedure wait_a_while (msec : Integer);
  57. procedure saywhat (text : String);
  58. procedure fill_panel (pan : Panel);
  59. nap_msec : Integer := nap_mseci;
  60. function mkpanel (color : Color_Number;
  61. rows : Line_Count;
  62. cols : Column_Count;
  63. tly : Line_Position;
  64. tlx : Column_Position) return Panel is
  65. win : Window;
  66. pan : Panel := Null_Panel;
  67. begin
  68. win := New_Window (rows, cols, tly, tlx);
  69. if Null_Window /= win then
  70. pan := New_Panel (win);
  71. if pan = Null_Panel then
  72. Delete (win);
  73. elsif Has_Colors then
  74. declare
  75. fg, bg : Color_Number;
  76. begin
  77. if color = Blue then
  78. fg := White;
  79. else
  80. fg := Black;
  81. end if;
  82. bg := color;
  83. Init_Pair (Color_Pair (color), fg, bg);
  84. Set_Background (win, (Ch => ' ',
  85. Attr => Normal_Video,
  86. Color => Color_Pair (color)));
  87. end;
  88. else
  89. Set_Background (win, (Ch => ' ',
  90. Attr => (Bold_Character => True,
  91. others => False),
  92. Color => Color_Pair (color)));
  93. end if;
  94. end if;
  95. return pan;
  96. end mkpanel;
  97. procedure rmpanel (pan : in out Panel) is
  98. win : Window := Panel_Window (pan);
  99. begin
  100. Delete (pan);
  101. Delete (win);
  102. end rmpanel;
  103. procedure pflush is
  104. begin
  105. Update_Panels;
  106. Update_Screen;
  107. end pflush;
  108. procedure wait_a_while (msec : Integer) is
  109. begin
  110. -- The C version had some #ifdef blocks here
  111. if msec = 1 then
  112. Getchar;
  113. else
  114. Nap_Milli_Seconds (msec);
  115. end if;
  116. end wait_a_while;
  117. procedure saywhat (text : String) is
  118. begin
  119. Move_Cursor (Line => Lines - 1, Column => 0);
  120. Clear_To_End_Of_Line;
  121. Add (Str => text);
  122. end saywhat;
  123. -- from sample-curses_demo.adb
  124. type User_Data is new String (1 .. 2);
  125. type User_Data_Access is access all User_Data;
  126. package PUD is new Panels.User_Data (User_Data, User_Data_Access);
  127. use PUD;
  128. procedure fill_panel (pan : Panel) is
  129. win : constant Window := Panel_Window (pan);
  130. num : constant Character := Get_User_Data (pan) (2);
  131. tmp6 : String (1 .. 6) := "-panx-";
  132. maxy : Line_Count;
  133. maxx : Column_Count;
  134. begin
  135. Move_Cursor (win, 1, 1);
  136. tmp6 (5) := num;
  137. Add (win, Str => tmp6);
  138. Clear_To_End_Of_Line (win);
  139. Box (win);
  140. Get_Size (win, maxy, maxx);
  141. for y in 2 .. maxy - 3 loop
  142. for x in 1 .. maxx - 3 loop
  143. Move_Cursor (win, y, x);
  144. Add (win, num);
  145. end loop;
  146. end loop;
  147. exception
  148. when Curses_Exception => null;
  149. end fill_panel;
  150. modstr : constant array (0 .. 5) of String (1 .. 5) :=
  151. ("test ",
  152. "TEST ",
  153. "(**) ",
  154. "*()* ",
  155. "<--> ",
  156. "LAST "
  157. );
  158. package p is new ncurses2.genericPuts (1024);
  159. use p;
  160. use p.BS;
  161. -- the C version said register int y, x;
  162. tmpb : BS.Bounded_String;
  163. begin
  164. Refresh;
  165. for y in 0 .. Integer (Lines - 2) loop
  166. for x in 0 .. Integer (Columns - 1) loop
  167. myPut (tmpb, (y + x) mod 10);
  168. myAdd (Str => tmpb);
  169. end loop;
  170. end loop;
  171. for y in 0 .. 4 loop
  172. declare
  173. p1, p2, p3, p4, p5 : Panel;
  174. U1 : constant User_Data_Access := new User_Data'("p1");
  175. U2 : constant User_Data_Access := new User_Data'("p2");
  176. U3 : constant User_Data_Access := new User_Data'("p3");
  177. U4 : constant User_Data_Access := new User_Data'("p4");
  178. U5 : constant User_Data_Access := new User_Data'("p5");
  179. begin
  180. p1 := mkpanel (Red, Lines / 2 - 2, Columns / 8 + 1, 0, 0);
  181. Set_User_Data (p1, U1);
  182. p2 := mkpanel (Green, Lines / 2 + 1, Columns / 7, Lines / 4,
  183. Columns / 10);
  184. Set_User_Data (p2, U2);
  185. p3 := mkpanel (Yellow, Lines / 4, Columns / 10, Lines / 2,
  186. Columns / 9);
  187. Set_User_Data (p3, U3);
  188. p4 := mkpanel (Blue, Lines / 2 - 2, Columns / 8, Lines / 2 - 2,
  189. Columns / 3);
  190. Set_User_Data (p4, U4);
  191. p5 := mkpanel (Magenta, Lines / 2 - 2, Columns / 8, Lines / 2,
  192. Columns / 2 - 2);
  193. Set_User_Data (p5, U5);
  194. fill_panel (p1);
  195. fill_panel (p2);
  196. fill_panel (p3);
  197. fill_panel (p4);
  198. fill_panel (p5);
  199. Hide (p4);
  200. Hide (p5);
  201. pflush;
  202. saywhat ("press any key to continue");
  203. wait_a_while (nap_msec);
  204. saywhat ("h3 s1 s2 s4 s5; press any key to continue");
  205. Move (p1, 0, 0);
  206. Hide (p3);
  207. Show (p1);
  208. Show (p2);
  209. Show (p4);
  210. Show (p5);
  211. pflush;
  212. wait_a_while (nap_msec);
  213. saywhat ("s1; press any key to continue");
  214. Show (p1);
  215. pflush;
  216. wait_a_while (nap_msec);
  217. saywhat ("s2; press any key to continue");
  218. Show (p2);
  219. pflush;
  220. wait_a_while (nap_msec);
  221. saywhat ("m2; press any key to continue");
  222. Move (p2, Lines / 3 + 1, Columns / 8);
  223. pflush;
  224. wait_a_while (nap_msec);
  225. saywhat ("s3;");
  226. Show (p3);
  227. pflush;
  228. wait_a_while (nap_msec);
  229. saywhat ("m3; press any key to continue");
  230. Move (p3, Lines / 4 + 1, Columns / 15);
  231. pflush;
  232. wait_a_while (nap_msec);
  233. saywhat ("b3; press any key to continue");
  234. Bottom (p3);
  235. pflush;
  236. wait_a_while (nap_msec);
  237. saywhat ("s4; press any key to continue");
  238. Show (p4);
  239. pflush;
  240. wait_a_while (nap_msec);
  241. saywhat ("s5; press any key to continue");
  242. Show (p5);
  243. pflush;
  244. wait_a_while (nap_msec);
  245. saywhat ("t3; press any key to continue");
  246. Top (p3);
  247. pflush;
  248. wait_a_while (nap_msec);
  249. saywhat ("t1; press any key to continue");
  250. Top (p1);
  251. pflush;
  252. wait_a_while (nap_msec);
  253. saywhat ("t2; press any key to continue");
  254. Top (p2);
  255. pflush;
  256. wait_a_while (nap_msec);
  257. saywhat ("t3; press any key to continue");
  258. Top (p3);
  259. pflush;
  260. wait_a_while (nap_msec);
  261. saywhat ("t4; press any key to continue");
  262. Top (p4);
  263. pflush;
  264. wait_a_while (nap_msec);
  265. for itmp in 0 .. 5 loop
  266. declare
  267. w4 : constant Window := Panel_Window (p4);
  268. w5 : constant Window := Panel_Window (p5);
  269. begin
  270. saywhat ("m4; press any key to continue");
  271. Move_Cursor (w4, Lines / 8, 1);
  272. Add (w4, modstr (itmp));
  273. Move (p4, Lines / 6, Column_Position (itmp) * (Columns / 8));
  274. Move_Cursor (w5, Lines / 6, 1);
  275. Add (w5, modstr (itmp));
  276. pflush;
  277. wait_a_while (nap_msec);
  278. saywhat ("m5; press any key to continue");
  279. Move_Cursor (w4, Lines / 6, 1);
  280. Add (w4, modstr (itmp));
  281. Move (p5, Lines / 3 - 1, (Column_Position (itmp) * 10) + 6);
  282. Move_Cursor (w5, Lines / 8, 1);
  283. Add (w5, modstr (itmp));
  284. pflush;
  285. wait_a_while (nap_msec);
  286. end;
  287. end loop;
  288. saywhat ("m4; press any key to continue");
  289. Move (p4, Lines / 6, 6 * (Columns / 8));
  290. -- Move(p4, Lines / 6, itmp * (Columns / 8));
  291. pflush;
  292. wait_a_while (nap_msec);
  293. saywhat ("t5; press any key to continue");
  294. Top (p5);
  295. pflush;
  296. wait_a_while (nap_msec);
  297. saywhat ("t2; press any key to continue");
  298. Top (p2);
  299. pflush;
  300. wait_a_while (nap_msec);
  301. saywhat ("t1; press any key to continue");
  302. Top (p1);
  303. pflush;
  304. wait_a_while (nap_msec);
  305. saywhat ("d2; press any key to continue");
  306. rmpanel (p2);
  307. pflush;
  308. wait_a_while (nap_msec);
  309. saywhat ("h3; press any key to continue");
  310. Hide (p3);
  311. pflush;
  312. wait_a_while (nap_msec);
  313. saywhat ("d1; press any key to continue");
  314. rmpanel (p1);
  315. pflush;
  316. wait_a_while (nap_msec);
  317. saywhat ("d4; press any key to continue");
  318. rmpanel (p4);
  319. pflush;
  320. wait_a_while (nap_msec);
  321. saywhat ("d5; press any key to continue");
  322. rmpanel (p5);
  323. pflush;
  324. wait_a_while (nap_msec);
  325. if nap_msec = 1 then
  326. exit;
  327. else
  328. nap_msec := 100;
  329. end if;
  330. end;
  331. end loop;
  332. Erase;
  333. End_Windows;
  334. end ncurses2.demo_panels;