University of Calgary

easycurses [C++] help

EASYCURSES [C++ version] HELP:
Easy Curses Library:
** FILES: easycurses.h easycurses.cc

Mar. 01 2000 by E.Nosal
updated: E.Nosal & K.Becker

Utility to faculitate screen I/O
USES STANDARD CURSES LIBRARY

Requires:
<curses.h>
"Const.h"
"Point.h"

Must be linked with: Point.o

Must be linked with: g++ -fguiding_decls -lcurses -o myprog myprog.o

Defines a class called: cursWindow
- you specify the upper left corner (relative to [0,0] of the screen)
- you specify the lower right corner (relative to [0,0] of the screen)


******WARNING! DANGER!!**********************************************
When using easycurses:
If your program blows up the cleanup routine for the window will not have been run so the window may not listen to you (except some control characters)
TO FIX THIS, TYPE:
^j (control 'j')
reset (type this word)
^j (control 'j', again)
This is only necessary if your program blows up.
*****************************************************************************

The easycurses object file makes the use of curses slightly easier.
Easycurses is basically a class redefinition of the major curses routines.

Includes:
-constructors/destructors
-NO COPY CONSTRUCTOR (pass by reference when necessary)
-maxX, maxY (lower-right extent of window)
-clearWin (set to all blanks)
-moveTo (move the WINDOW itself)
-NEXT & PREV functions (get next/prev X or Y with wrap and get next/prev POINT in given direction with wrap)
-print a FRAME around edge of window (leaves bottom line empty for user I/O - next/prev functions know about this)
- PRINT char/int/string at current cursor location
- PUT given char at specified X,Y in window
- PEEK what is character at specified X,Y location?
- getInput read char/string from current cursor location
- PROMPT - print prompt at bottom left of window and retrieve single character from user


NOTES:
1. DO NOT mix normal I/O (like with cin/cout) with window I/O
2. SCREEN origin is (0,0) { TOP LEFT corner of this Xwindow}
WINDOW origin is (x,y) from screen origin
3. X refers to width (it is the cols)
4. Y refers to height (it is the lines)
5. YOU are responsible for making sure you don't reference a point outside your defined window
6. in constructor:
x = how far over (to the right) you want the window to start
y = how far down from top of screen you want window to start
x2 = how far over (to the right) you want the window to extend (relative to left edge of SCREEN)
y2 = how far down you want the window to extend (relative to top of SCREEN)
if x2, y2 are allowed to default (as in second constructor) WINDOW size is 40 X 35
7. maxX() tells us how many columns are in the window
maxY() tells us how many lines are in the window



********** the class cursWindow *************************************

Constructor/Deconstructor
=========================
The constructor is overloaded by two functions:
cursWindow(int x, int y, int x2, int y2)
cursWindow(int x, int y)

The first constructor takes x and y as the top right hand corner, and x2 y2 as the bottom left hand corner of the window to define.
The second constructor again has x and y as the top right hand corner, but it defaults to a window with the size of 40X35.

The deconstructor simply deletes all memory used by the window created.

Create a new window at x,y (from 0,0 of SCREEN) to x2,y2 relative to SCREEN origin
cursWindow(int x, int y, int x2, int y2);
cursWindow(int x, int y);
~cursWindow();

void clearWin(); erase everything in the window


ACCESS METHODS:
===================
int maxX() { return maxx; } tell me # of columns
int maxY() { return maxy; } tell me # of lines


MOVE METHODS
================
Move the window within the SCREEN

This functions takes the window inside the class and moves the top right hand corner to point x, y.

void moveTo(int x, int y);

Move JUST the cursor (doesn't print anything)

void moveCursor( int x, int y);

NEXT METHODS
================
NEXT values based on any X,Y and dimensions of WINDOW
THESE DO NOT CHANGE THEIR ARGUMENTS

int nextX(int x); get the next X value with wrap
int nextY(int y); get the next Y value with wrap
int prevX(int x); get the previous X value with wrap
int prevY(int y); get the previous Y value with wrap

POINT: tell me the next point given the current location ( Point) and the given direction
Point NextP( Point P, int direction );
Point PrevP( Point P, int direction );

OUTPUT METHODS
===================
void frame(); print a frame around edge of window leaving one "blank" line at bottom for input

Print at the current cursor location [single character, a string, or a number]

void print(char letter);
void print(char* string);
void print(int number);

put a character in the window at specified location this time x,y is relative to top left corner of window
leaves cursor at char just printed
void put(int x, int y, char letter);

INPUT METHODS
=================
find out which character is at the given location
leaves cursor where it was before call
char peek( int x, int y );
reads characters typed by user
reads from current cursor location
void getInput(char& inp, bool ech); ech == echo character
void getInput(char* inp);

The former will wait until the user hits one key and stores it into character.
The second flag determines if the kepress is printed to the screen. This flag is defaulted to true, so no argument is required unless one does not want echo.

The latter will take input until the user hits the enter key, and store the resulting string into str. This functions always echos to the screen. The delete key works as it would with cin.


OUTPUT & INPUT
=================
char prompt(char letter); prints a prompt at bottom of screen and
returns the character that the user typed
leaves cursor at location of user input



Updated: August 28, 2005 09:47 AM