1 /* cmover: moves a character over the screen using curses */
6 static void quit (void);
7 static void update_screen (void);
8 static void update_mainview (void);
9 static void update_statusline (void);
10 static void check_size (void);
11 static void create_windows (void);
12 static int can_move (int, int);
13 static WINDOW
* mainview
= NULL
;
14 static WINDOW
* statusline
= NULL
;
15 static unsigned int lines
, cols
; /* size to work with */
16 static unsigned int x
, y
; /* coordinates */
17 static char c
='X'; /* character to use */
19 int main (int argc
, char ** argv
)
39 input
= wgetch (mainview
);
79 if ((mv_x
|| mv_y
) && can_move (mv_x
, mv_y
)) {
89 static void quit (void)
92 printf ("exiting...\n");
95 static void check_size (void)
97 if (LINES
!= lines
|| COLS
!= cols
) {
102 if (y
>= lines
-1) y
= lines
-2;
103 if (x
>= cols
) x
= cols
-1;
108 /* (re)creates the two windows. this is needed after resizing the screen */
109 static void create_windows (void)
111 if (mainview
) delwin (mainview
);
112 if (statusline
) delwin (statusline
);
113 mainview
= newwin (lines
-1, 0, 0, 0);
114 statusline
= newwin (0, 0, lines
-1, 0);
115 keypad (mainview
, TRUE
); /* make arrow keys usable */
118 static void update_screen (void)
121 update_statusline ();
124 static void update_mainview (void)
126 waddch (mainview
, ' ');
127 mvwaddch (mainview
, y
, x
, c
);
128 wmove (mainview
, y
, x
);
132 /* width and height are the size of the whole terminal, not just the mainview. */
133 static void update_statusline (void)
135 mvwprintw (statusline
, 0, 0, "x: %i, y: %i, width: %i, height: %i",
137 wclrtoeol (statusline
);
138 wrefresh (statusline
);
141 static int can_move (const int mv_x
, const int mv_y
)
143 return (mv_x
+x
<cols
&& mv_y
+y
<lines
-1);