Next: , Previous: , Up: Top   [Contents][Index]


6 Using the Screen utility

The screen utility provides functions to manipulate the screen colors, clearing the screen, and positioning of the cursor. It also defines values for the screen size. The member variables of the screen utility (defined in "screen.h") are:

 int SCREEN_W;
 int SCREEN_H;

Both these variables are filled with their proper values after a call to getScreenSize().

 int FG_COLOR[color_components];
 int BG_COLOR[color_components];

The color_components is a macro defined with a value of 6. The possible values for color_components which is an index into arrays of colors determining what color is assigned to which component (i.e., dialogs, buttons, ...) are:

 COLOR_WINDOW    0
 COLOR_HIGHLIGHT_TEXT 1
 COLOR_MENU_BAR  2
 COLOR_STATUS_BAR 3
 COLOR_BUTTONS   4
 COLOR_HBUTTONS  5

You can define the colors in the color arrays by using integer values, although using macro names (as discussed below) is recommended. Initializing the arrays can be done with code like:

  FG_COLOR[COLOR_WINDOW] = 37;
  FG_COLOR[COLOR_HIGHLIGHT_TEXT] = 34;
  FG_COLOR[COLOR_MENU_BAR] = 34;
  FG_COLOR[COLOR_STATUS_BAR] = 34;
  FG_COLOR[COLOR_BUTTONS] = 37;
  FG_COLOR[COLOR_HBUTTONS] = 32;
  BG_COLOR[COLOR_WINDOW] = 44;
  BG_COLOR[COLOR_HIGHLIGHT_TEXT] = 47;
  BG_COLOR[COLOR_MENU_BAR] = 47;
  BG_COLOR[COLOR_STATUS_BAR] = 47;
  BG_COLOR[COLOR_BUTTONS] = 41;
  BG_COLOR[COLOR_HBUTTONS] = 41;

For convenience, the names of colors used in screen utility functions can be retrieved from the array screen_colors[] after a call to getScreenColors():

 getScreenColors();
 for(int i = 0; i < 16; i++)
   printf("%s\n", screen_colors[i]);

To set the screen colors (e.g. before clearing the screen,), use the function:

 void setScreenColors(int FG, int BG);

where FG is the foreground color, BG is the background color. Color values are defined as macros in the (screen.h) file:

 #define BLACK      30      //set black foreground
 #define RED        31      //set red foreground
 #define GREEN      32      //set green foreground
 #define BROWN      33      //set brown foreground
 #define BLUE       34      //set blue foreground
 #define MAGENTA    35      //set magenta foreground
 #define CYAN       36      //set cyan foreground
 #define WHITE      37      //set white foreground
 #define BGBLACK    40      //set black background
 #define BGRED      41      //set red background
 #define BGGREEN    42      //set green background
 #define BGBROWN    43      //set brown background
 #define BGBLUE     44      //set blue background
 #define BGMAGENTA  45      //set magenta background
 #define BGCYAN     46      //set cyan background
 #define BGWHITE    47      //set white background
 #define BGDEFAULT  49      //set default background color

To get the size of screen coordinates, use function:

 void getScreenSize();

which will fill the values into SCREEN_W and SCREEN_H global variables.
The functions

 void clearScreen();
 void clearScreenC(int FG, int BG);

basically do the same thing, except clearScreen() uses whatever colors where passed into previous call of setScreenColors(), and clearScreenC() takes the values of colors to use when clearing the screen. Last color function is

 void loadDefaultColors();

which resets the color arrays into default values.
To reposition the cursor, use:

 void locate(int row, int col);

giving the row and column as int values. Remember the screen has top-left based coordinates, meaning position 1-1 is at the top-left corner, position 25-80 is at the bottom-right (for a 25x80 screen size).

To show/hide the cursor:

/* Turn on the cursor */
void showCursor();
/* Turn off the cursor */
void hideCursor();

Next: , Previous: , Up: Top   [Contents][Index]