Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | |
| 45 | -- test effects of overlapping windows |
| 46 | |
| 47 | procedure ncurses2.overlap_test is |
| 48 | |
| 49 | procedure fillwin (win : Window; ch : Character); |
| 50 | procedure crosswin (win : Window; ch : Character); |
| 51 | |
| 52 | procedure fillwin (win : Window; ch : Character) is |
| 53 | y1 : Line_Position; |
| 54 | x1 : Column_Position; |
| 55 | begin |
| 56 | Get_Size (win, y1, x1); |
| 57 | for y in 0 .. y1 - 1 loop |
| 58 | Move_Cursor (win, y, 0); |
| 59 | for x in 0 .. x1 - 1 loop |
| 60 | Add (win, Ch => ch); |
| 61 | end loop; |
| 62 | end loop; |
| 63 | exception |
| 64 | when Curses_Exception => null; |
| 65 | -- write to lower right corner |
| 66 | end fillwin; |
| 67 | |
| 68 | procedure crosswin (win : Window; ch : Character) is |
| 69 | y1 : Line_Position; |
| 70 | x1 : Column_Position; |
| 71 | begin |
| 72 | Get_Size (win, y1, x1); |
| 73 | for y in 0 .. y1 - 1 loop |
| 74 | for x in 0 .. x1 - 1 loop |
| 75 | if ((x > (x1 - 1) / 3) and (x <= (2 * (x1 - 1)) / 3)) |
| 76 | or (((y > (y1 - 1) / 3) and (y <= (2 * (y1 - 1)) / 3))) then |
| 77 | Move_Cursor (win, y, x); |
| 78 | Add (win, Ch => ch); |
| 79 | end if; |
| 80 | end loop; |
| 81 | end loop; |
| 82 | end crosswin; |
| 83 | |
| 84 | -- In a 24x80 screen like some xterms are, the instructions will |
| 85 | -- be overwritten. |
| 86 | ch : Character; |
| 87 | win1 : Window := New_Window (9, 20, 3, 3); |
| 88 | win2 : Window := New_Window (9, 20, 9, 16); |
| 89 | begin |
| 90 | Set_Raw_Mode (SwitchOn => True); |
| 91 | Refresh; |
| 92 | Move_Cursor (Line => 0, Column => 0); |
| 93 | Add (Str => "This test shows the behavior of wnoutrefresh() with " & |
| 94 | "respect to"); |
| 95 | Add (Ch => newl); |
| 96 | Add (Str => "the shared region of two overlapping windows A and B. "& |
| 97 | "The cross"); |
| 98 | Add (Ch => newl); |
| 99 | Add (Str => "pattern in each window does not overlap the other."); |
| 100 | Add (Ch => newl); |
| 101 | |
| 102 | Move_Cursor (Line => 18, Column => 0); |
| 103 | Add (Str => "a = refresh A, then B, then doupdate. b = refresh B, " & |
| 104 | "then A, then doupdaute"); |
| 105 | Add (Ch => newl); |
| 106 | Add (Str => "c = fill window A with letter A. d = fill window B " & |
| 107 | "with letter B."); |
| 108 | Add (Ch => newl); |
| 109 | Add (Str => "e = cross pattern in window A. f = cross pattern " & |
| 110 | "in window B."); |
| 111 | Add (Ch => newl); |
| 112 | Add (Str => "g = clear window A. h = clear window B."); |
| 113 | Add (Ch => newl); |
| 114 | Add (Str => "i = overwrite A onto B. j = overwrite " & |
| 115 | "B onto A."); |
| 116 | Add (Ch => newl); |
| 117 | Add (Str => "^Q/ESC = terminate test."); |
| 118 | |
| 119 | loop |
| 120 | ch := Code_To_Char (Getchar); |
| 121 | exit when ch = CTRL ('Q') or ch = CTRL ('['); -- QUIT or ESCAPE |
| 122 | case ch is |
| 123 | when 'a' => -- refresh window A first, then B |
| 124 | Refresh_Without_Update (win1); |
| 125 | Refresh_Without_Update (win2); |
| 126 | Update_Screen; |
| 127 | when 'b' => -- refresh window B first, then A |
| 128 | Refresh_Without_Update (win2); |
| 129 | Refresh_Without_Update (win1); |
| 130 | Update_Screen; |
| 131 | when 'c' => -- fill window A so it's visible |
| 132 | fillwin (win1, 'A'); |
| 133 | when 'd' => -- fill window B so it's visible |
| 134 | fillwin (win2, 'B'); |
| 135 | when 'e' => -- cross test pattern in window A |
| 136 | crosswin (win1, 'A'); |
| 137 | when 'f' => -- cross test pattern in window B |
| 138 | crosswin (win2, 'B'); |
| 139 | when 'g' => -- clear window A |
| 140 | Clear (win1); |
| 141 | Move_Cursor (win1, 0, 0); |
| 142 | when 'h' => -- clear window B |
| 143 | Clear (win2); |
| 144 | Move_Cursor (win2, 0, 0); |
| 145 | when 'i' => -- overwrite A onto B |
| 146 | Overwrite (win1, win2); |
| 147 | when 'j' => -- overwrite B onto A |
| 148 | Overwrite (win2, win1); |
| 149 | when others => null; |
| 150 | end case; |
| 151 | end loop; |
| 152 | |
| 153 | Delete (win2); |
| 154 | Delete (win1); |
| 155 | Erase; |
| 156 | End_Windows; |
| 157 | end ncurses2.overlap_test; |