Edge++ Library Reference
Version 1.0, 1999

General Notes: The Edge++ library is designed to allow "event driven" applications, rather than traditional "main loop" type applications. What this means is that a programmer defines functions and ties them to "events", such as EdgeButton hits and mouse clicks, rather writing out a while loop and a big switch statement. This is much the same as programming for popular GUI environments, such as Windows 9x/NT. This results in "main" functions that are quite small as compared to other types of traditional programs. In the Main function, the programmer must define specify all EdgeButtons they wish to use, set up any "handler" functions, and then call EdgeInit. A typical main function migh be as follows:

void main()
{

EdgeAddButton(1, 1, 150, 45, "Select Points", SelectPtsButton, GLUT_BITMAP_HELVETICA_18, EdgeColor(1,1,1), EdgeColor(1,0,0));
EdgeAddButton(152, 1, 150, 45, "Draw Circle", DrawCircleButton, GLUT_BITMAP_HELVETICA_18, EdgeColor(1,1,1), EdgeColor(0,1,0));
EdgeAddButton(303, 1, 150, 45, "Clear All", ClearAllButton, GLUT_BITMAP_HELVETICA_18, EdgeColor(1,1,1), EdgeColor(0,0,1));
EdgeAddButton(454, 1, 150, 45, "Exit", AppExitButton, GLUT_BITMAP_HELVETICA_18, EdgeColor(1,1,1), EdgeColor(0,0.5,1));
EdgeSetMouseHandler(MouseInput);
EdgeInit(640, 480, "Testing Edge");

}

In this style of event driven design, the great majority of code resides in the functions tied to events, in this example: "SelectPtsButton", "DrawCircleButton", "ClearAllButton", "AppExitButton", and "MouseInput".

The Edge++ library also provides a fairly extensive set of classes for common 3d math operations, such as EngeVector, EdgeColor, and EdgeMatrix. Full documentation of these classes will be forthcoming.


Setup Functions: These functions allow users of the Edge++ library to create "handler" functions for things such as keyboard and mouse input. All of these functions are optional.

void EdgeSetMainLoop(void (*MainProgLoop)(void));
Parameters: Pointer to user defined function (which takes no parameters) that is to be executed every drawing loop.

void EdgeSetMouseHandler(void (*MouseFunc)(int button, int state, int x, int y));
Parameters: Pointer to user defined function (with parameters int button, int state, int x, int y) which is executed when a mouse button is pressed or released. The button variable stores which button has been pressed, i.e. 0 = Left, 1 = Middle, 3 = Right. The state variable stores a 0 if the button has been pressed, and a 1 if it has been released. x and y store the mouse's position, with respect to the upper-left corner of the Edge window.

void EdgeSetKBHandler(void (*KBFunc)(unsigned char key));
Parameters: Pointer to user defined function (with parameters unsigned char key) which is executed when a key is pressed (and focus is in the Edge window). The key variable stores the hexadecimal token associated with the key that has been pressed.

void EdgeAddButton(int x, int y, int w, int h, char *Title, void (*FunctionPtr)(void), void* NewFont, EdgeColor ButtonColor = EdgeColor(1,1,1), EdgeColor TextColor = EdgeColor(0,0,0));
Parameters: x and y specify the location of the upper-left corner of the button that is to be created. w and h are the width and height of the new button. Title is the string that is printed in the center of the button. FunctionPtr is a pointer to the function that is to be executed when the button is clicked on. NewFont (optional) sets the font of the button's text. This defaults to 18 point Helvetica, and can be any one of the enumerated GLUT bitmap fonts:

GLUT_BITMAP_9_BY_15
GLUT_BITMAP_8_BY_13
GLUT_BITMAP_TIMES_ROMAN_10
GLUT_BITMAP_TIMES_ROMAN_24
GLUT_BITMAP_HELVETICA_10
GLUT_BITMAP_HELVETICA_12
GLUT_BITMAP_HELVETICA_18

ButtonColor (optional) can be used to set the background color of the button, and TextColor (optional) can be used to set the color of the buttons text. These two parameters default to white and black, respectively.

Initialization:

void EdgeInit(int w, int h, char* Title, EdgeColor BackGroundColor = EdgeColor(0,0,0));
Parameters: w and h are the width and height of the Edge window that is to be created. Title is the string that is to appear on the top border of the Edge window. BackGroundColor (optional) sets the base color of the Edge window, and defaults to black. Note: Once this function is called, the program enters "message processing" mode, and the only code that is executed is that which is associated with a button which has been set by one of the other three functions above.

Drawing Commands: These functions are used to draw primitives to the Edge window. The function names pretty much speak for themselves.

void EdgeDrawPoint(int x, int y, EdgeColor PointColor = EdgeColor(0,0,1));
Parameters: x and y specify the location of the point to be drawn, PointColor (optional) specifies the color of the point to be drawn and defaults to blue.

void EdgeDrawLine(int x1, int y1, int x2, int y2, EdgeColor LineColor1 = EdgeColor(0,0,1));
Parameters: x1 and y1 specify the starting location of the line to be drawn, x1 and y1 specify the line's endpoint. LineColor1 (optional) specifies the color of the line.

void EdgeDrawLine(int x1, int y1, int x2, int y2, EdgeColor LineColor1, EdgeColor LineColor2);
Notes: This function is just an overloaded version of the above function that takes two colors for a line and interpolates between them across the line.

void EdgeDrawScanline(int x, int y, EdgeColor* Scanline, int NumPixels);
Notes: This function "blits" a scanline from memory to the Edge window.
Parameters:
x and y specify where the scanline is to be drawn, Scanline is simply a pointer to a block of EdgeColor variables that hold the scanline data. NumPixels is the length of the scanline.

void EdgeDrawText(int x, int y, char *Text, EdgeColor TextColor = EdgeColor(0,0,1), void* Font = GLUT_BITMAP_TIMES_ROMAN_10);
Parameters: x and y specify the upper left corner of where the text is to be drawn. Text is simply the string that is to be printed. TextColor (optional) is the color of the text, and defaults to blue. Font (optional) sets the font of the text, and can be any of the GLUT fonts, listed above at the EdgeAddButton function description. The font defaults to 10 point Times Roman.

void EdgeClearArea(int Left, int Top, int Right, int Bottom, EdgeColor ClearColor = EdgeColor(0,0,0));
Notes: This function clears the rectangle defined by Left, Top, Right, and Bottom to the color specified by ClearColor (optional). If none is specified, the default is black.

void EdgeClearAll(EdgeColor ClearColor = EdgeColor(0,0,0));
Notes: This function clears the entire Edge window to the color specified by ClearColor (optional). If none is specified, the default is black.

void EdgeWritePPM(char* Filename);
Notes: This function creates a PPM image file of the entire Edge window. Filename specifies the PPM file's name.

void EdgeDrawTextToConsole(char *Text, EdgeColor TextColor = EdgeColor(1,0,0), void* Font = GLUT_BITMAP_HELVETICA_18);
Notes: This function works just like EdgeDrawText, except it writes text to the "console" area at the bottom of the Edge window. Before the text is drawn, the console area is cleared, so any text already there is deleted. This is useful for prompting the user, debugging, etc.

EdgeColor EdgeGetPixel(int x, int y);
Notes: This function returns the color of the pixel location specified by parameters x and y.

int EdgeIsPointSafe(int x, int y);
Notes: This function checks if the point specified by parameters x and y falls within an already specified button or the console. Essentially, it returns 1 if the location is "safe" to draw in, and 0 if not.

 

The Edge++ Library and this document were created by Will Gee. Please feel free to direct any questions or comments to wgee@microprose.com