Simple Graphics Library
0.9.5
SGL API
|
Classes | |
class | BitmapObject |
class | Color |
class | CompositeObject |
class | DisplayDigit |
class | DoubleDigit |
class | GraphicalObject |
class | Multidigit |
class | ObjectWindow |
class | OGLWindow |
class | Pixmap |
struct | Point |
class | PopupMenu |
class | ProceduralWindow |
class | SevenSegmentDigit |
class | Stopwatch |
class | TimeDisplay |
class | Window |
Typedefs | |
using | MenuItemFunction = std::function< void()> |
Enumerations | |
enum | MouseButton { Left = 0, Right = 2, Unknown = -1 } |
enum | SpecialKey { F1_KEY = 10001, F2_KEY, F3_KEY, F4_KEY, F5_KEY, F6_KEY, F7_KEY, F8_KEY, F9_KEY, F10_KEY, F11_KEY, F12_KEY, LEFT_KEY = 10100, UP_KEY, RIGHT_KEY, DOWN_KEY, PAGE_UP_KEY, PAGE_DOWN_KEY, HOME_KEY, END_KEY, INSERT_KEY } |
enum | CursorShape { Right_arrow = 0, Left_arrow, Info, Destroy, Help, Cycle, Spray, Wait, Text, Crosshair, Up_down, Left_right, Top_side, Bottom_side, Left_side, Right_side, Top_left_corner, Top_right_corner, Bottom_right_corner, Bottom_left_corner, Inherit = 100, None, Full_crosshair } |
enum | KeyModifier { NO_KEY = 0, SHIFT_KEY = 1, CTRL_KEY = 2, ALT_KEY = 4 } |
Functions | |
void | initialize_graphics (unsigned int mode) |
void | initialize_graphics () |
bool | intersect (const GraphicalObject &obj1, const GraphicalObject &obj2) |
void | draw_point (double x, double y) |
void | draw_point (const Point &pt) |
void | set_point_size (int point_size) |
void | draw_line (double x0, double y0, double x1, double y1) |
void | draw_dashed_line (double x0, double y0, double x1, double y1, int pattern=0x00FF) |
void | draw_rectangle (double x, double y, double width, double height) |
void | fill_rectangle (double x, double y, double width, double height) |
void | draw_circle (double x, double y, double radius) |
void | fill_circle (double x, double y, double radius) |
void | draw_polygon (const std::vector< Point > &pts) |
void | draw_polygon (const Point *pts, int n) |
void | fill_polygon (const std::vector< Point > &pts) |
void | fill_polygon (const Point *pts, int n) |
void | draw_text (const std::string &text, double x, double y, int font_size) |
void | draw_text (const std::string &text, double x, double y, double scale) |
double | text_width (const std::string &text, int font_size) |
void | draw_function (double(*f)(double), double begin_x, double end_x, double delta) |
void | set_color (const Color &color) |
void | set_color (double r, double g, double b) |
void | set_line_width (double width) |
template<typename T , typename... Args> | |
void | run (Args &&... args) |
template<typename T , typename... Args> | |
T * | make_window (Args &&... args) |
int | get_screen_width () |
int | get_screen_height () |
void | set_random_seed (int seed=-1) |
int | random (int begin, int end) |
int | random (int n) |
void | pause (int msec) |
bool | equals (double d1, double d2, double delta) |
std::string | version () |
void | create_window (const std::string &title, int x, int y, int width, int height) |
void | run_window () |
void | update_window () |
void | set_paint_function (const std::function< void()> &f) |
void | set_mouse_pressed_function (const std::function< void(double, double, MouseButton)> &f) |
void | set_mouse_released_function (const std::function< void(double, double, MouseButton)> &f) |
void | set_mouse_moved_function (const std::function< void(double, double)> &f) |
void | set_mouse_dragged_function (const std::function< void(double, double)> &f) |
void | set_key_pressed_function (const std::function< void(int, double, double)> &f) |
void | set_window_background (const Color &c) |
void | set_window_title (const std::string &str) |
const Color | BLACK (0.0, 0.0, 0.0) |
const Color | RED (1.0, 0.0, 0.0) |
const Color | GREEN (0.0, 1.0, 0.0) |
const Color | BLUE (0.0, 0.0, 1.0) |
const Color | YELLOW (1.0, 1.0, 0.0) |
const Color | MAGENTA (1.0, 0.0, 1.0) |
const Color | CYAN (0.0, 1.0, 1.0) |
const Color | DARK_RED (0.75, 0.0, 0.0) |
const Color | DARK_GREEN (0.0, 0.75, 0.0) |
const Color | DARK_BLUE (0.0, 0.0, 0.75) |
const Color | LIGHT_RED (1.0, 0.75, 0.75) |
const Color | LIGHT_GREEN (0.75, 1.0, 0.75) |
const Color | LIGHT_BLUE (0.75, 0.75, 1.0) |
const Color | GRAY (0.5, 0.5, 0.5) |
const Color | LIGHT_GRAY (0.8, 0.8, 0.8) |
const Color | DARK_GRAY (0.2, 0.2, 0.2) |
const Color | WHITE (1.0, 1.0, 1.0) |
void | procedural_default_paint_function () |
void | procedural_default_mouse_pressed_function (double, double, MouseButton) |
void | procedural_default_mouse_released_function (double, double, MouseButton) |
void | procedural_default_mouse_moved_function (double, double) |
void | procedural_default_mouse_dragged_function (double, double) |
void | procedural_default_key_pressed_function (int, double, double) |
Variables | |
const Color | BLACK |
const Color | RED |
const Color | GREEN |
const Color | BLUE |
const Color | YELLOW |
const Color | MAGENTA |
const Color | CYAN |
const Color | WHITE |
const Color | DARK_RED |
const Color | DARK_GREEN |
const Color | DARK_BLUE |
const Color | LIGHT_RED |
const Color | LIGHT_GREEN |
const Color | LIGHT_BLUE |
const Color | GRAY |
const Color | LIGHT_GRAY |
const Color | DARK_GRAY |
const int | MAX_WINDOWS = 10 |
All client accessible classes, functions, and constants reside in the sgl namespace.
using sgl::MenuItemFunction = typedef std::function<void()> |
A type for menu item event handling.
|
strong |
Cursor shapes map directly to the GLUT equivalents.
|
strong |
KeyModifer is an enumerated type that maps directly to the GLUT equivalents for the corresponding key modifers: SHIFT, CRTL, and ALT. These can be combined with bitwise OR to represent combinations such as CTRL-ALT.
|
strong |
MouseButton is an enumerated type that maps directly to the GLUT equivalents for the corresponding mouse buttons.
enum sgl::SpecialKey |
SpecialKey is an enumerated type that maps directly to the GLUT equivalents for the corresponding special keys.
void sgl::create_window | ( | const std::string & | title, |
int | x, | ||
int | y, | ||
int | width, | ||
int | height | ||
) |
Creates a graphics window for the SGL's procedural interface. Clients need not derive a custom Window class and override methods. Clients using the procedural interface control the application's state through global variables rather than instance variables. Clients must call this function before registering any callbacks and before calling run_window
.
title | the text to appear in the window's title bar |
x | the x component of the (x, y) location of the window's left-top corner |
y | the y component of the (x, y) location of the window's left-top corner |
width | the window's width |
height | the window's height |
void sgl::draw_circle | ( | double | x, |
double | y, | ||
double | radius | ||
) |
Draws a circle in the current drawing color.
x | the x coordinate in the viewport coordinate system of the circle's center |
y | the y coordinate in the viewport coordinate system of the circle's center |
radius | the radius of the circle in viewport coordinates |
void sgl::draw_dashed_line | ( | double | x0, |
double | y0, | ||
double | x1, | ||
double | y1, | ||
int | pattern = 0x00FF |
||
) |
Draws a strippled line in the current drawing color.
x0 | the x coordinate in viewport coordinates of the first point |
y0 | the y coordinate in viewport coordinates of the first point |
x1 | the x coordinate in viewport coordinates of the second point |
y1 | the y coordinate in viewport coordinates of the second point |
pattern | a 32-bit pattern used to render the line; defaults to dashes: 0x00FF |
void sgl::draw_function | ( | double(*)(double) | f, |
double | begin_x, | ||
double | end_x, | ||
double | delta | ||
) |
Draws a 2-D mathematical function, f(x). Plots the line segments joining (begin_x, f(begin_x)), (begin_x + delta, f(begin_x + delta)), (begin_x + delta + delta, f(begin_x + delta + delta)), ..., (end_x, f(end_x)).
f | a pointer to a function that accepts a single double-precision floating-point value |
begin_x | the lowest x argument to evaluate |
end_x | the highest x argument to evaluate |
delta | the change in x; first begin_x will be evaluated, then begin_x + delta, then begin_x + delta + delta, ..., until end_x is reached. |
void sgl::draw_line | ( | double | x0, |
double | y0, | ||
double | x1, | ||
double | y1 | ||
) |
Draws a line in the current drawing color.
x0 | the x coordinate in viewport coordinates of the first point |
y0 | the y coordinate in viewport coordinates of the first point |
x1 | the x coordinate in viewport coordinates of the second point |
y1 | the y coordinate in viewport coordinates of the second point |
void sgl::draw_point | ( | double | x, |
double | y | ||
) |
Draws the point (x,y) in the current drawing color.
x | the x coordinate of the (x,y) location. |
y | the y coordinate of the (x,y) location. |
void sgl::draw_point | ( | const Point & | pt | ) |
void sgl::draw_polygon | ( | const std::vector< Point > & | pts | ) |
Draws the outline of a polygon specified by the points in a std::vector of Points. The points adjacent in the polygon also must be adjacent in the vector.
pts | a std::vector of Point objects that comprise the vertices of the polygon. Adjacent vertices in the polygon must adjacent in the vector. |
void sgl::draw_polygon | ( | const Point * | pts, |
int | n | ||
) |
Draws the outline of a polygon specified by the points in an array of Point objects. The points adjacent in the polygon also must be adjacent in the vector.
pts | a std::vector of Point objects that comprise the vertices of the polygon. Adjacent vertices in the polygon must adjacent in the vector. |
n | the number of points in the array. |
void sgl::draw_rectangle | ( | double | x, |
double | y, | ||
double | width, | ||
double | height | ||
) |
Draws a rectangular frame in the current drawing color.
x | the x coordinate in the viewport coordinate system of the left-bottom corner of the rectangle |
y | the y coordinate in the viewport coordinate system of the left-bottom corner of the rectangle |
width | the width in viewport coordinates of the rectangle |
height | the height in viewport coordinates of the rectangle |
void sgl::draw_text | ( | const std::string & | text, |
double | x, | ||
double | y, | ||
int | font_size | ||
) |
Draw a piece of graphical text in the window. The provided (x,y) location specifies the left-bottom portion of the text. This version of draw_text uses fixed-size bitmap fonts.
text | the string of text to display |
x | the x coordinate in the viewport coordinate system of the text's left-most extent |
y | the y coordinate in the viewport coordinate system of the text's baseline |
font_size | the size of the font: 10, 12, or 18. |
void sgl::draw_text | ( | const std::string & | text, |
double | x, | ||
double | y, | ||
double | scale | ||
) |
Draw a piece of graphical text in the window. This version of draw_text uses a scalable stroke font. The provided (x,y) location specifies the left-bottom portion of the text.
text | the string of text to display |
x | the x coordinate in the viewport coordinate system of the text's left-most extent |
y | the y coordinate in the viewport coordinate system of the text's baseline |
scale | the scale of the font; this generally will be value less than one (for example, 0.1 or 0.25). |
bool sgl::equals | ( | double | d1, |
double | d2, | ||
double | delta | ||
) |
Determines if two floating-point numbers are close enough in value to be considered "equal." The call equals(a, b, c) returns true if |a - b| < c; otherwise, it returns true.
d1 | the first value to compare |
d2 | the second value to compare |
delta | the tolerance factor: the distance between d1 and d2 must be less than delta for d1 and d2 to be considered "equal" |
void sgl::fill_circle | ( | double | x, |
double | y, | ||
double | radius | ||
) |
Draws a filled circle in the current drawing color.
x | the x coordinate in the viewport coordinate system of the circle's center |
y | the y coordinate in the viewport coordinate system of the circle's center |
radius | the radius of the circle in viewport coordinates |
void sgl::fill_polygon | ( | const std::vector< Point > & | pts | ) |
Draws a filled polygon specified by the points in a std::vector of Points. The points adjacent in the polygon also must be adjacent in the vector.
pts | a std::vector of Point objects that comprise the vertices of the polygon. Adjacent vertices in the polygon must adjacent in the vector. |
void sgl::fill_polygon | ( | const Point * | pts, |
int | n | ||
) |
Draws a filled polygon specified by the points in an array of Point objects. The points adjacent in the polygon also must be adjacent in the vector.
pts | an array of Point objects that comprise the vertices of the polygon. Adjacent vertices in the polygon must adjacent in the vector. |
n | the number of points in the array. |
void sgl::fill_rectangle | ( | double | x, |
double | y, | ||
double | width, | ||
double | height | ||
) |
Draws a filled rectangle in the current drawing color.
x | the x coordinate in the viewport coordinate system of the left-bottom corner of the rectangle |
y | the y coordinate in the viewport coordinate system of the left-bottom corner of the rectangle |
width | the width in viewport coordinates of the rectangle |
height | the height in viewport coordinates of the rectangle |
int sgl::get_screen_height | ( | ) |
Gets the height of the screen in pixels.
int sgl::get_screen_width | ( | ) |
Gets the width of the screen in pixels.
void sgl::initialize_graphics | ( | unsigned int | mode | ) |
Global inialization function, called once per program execution. This version allows the client to specify a initial display mode. All SGL programs should call this function or its overloaded equivalent before creating and using a graphical window.
mode | the initial display mode |
void sgl::initialize_graphics | ( | ) |
Global inialization function, called once per program execution. This version provides double buffering, RGBA mode, and no depth buffer. All SGL programs should call this function or its overloaded equivalent before creating and using a graphical window.
bool sgl::intersect | ( | const GraphicalObject & | obj1, |
const GraphicalObject & | obj2 | ||
) |
Determines if the bounding boxes of two graphical objects overlap.
obj1 | one of the graphical objects |
obj2 | the other graphical object |
|
inline |
Creates an SGL window of type T passing the arguments found in the Args parameter to the window's constructor. Does NOT call the window's run method to start the application.
T | the type of SGL window to create |
Args | the argument pack to pass to the window's constructor |
args | the instantiated parameters to pass to the window's constructor |
Creates an SGL window of type T passing the arguments found in the Args parameter to the window's constructor. Does NOT call the window's run method to start the application.
T | the type of SGL window to create |
Args | the argument pack to pass to the window's constructor |
args | the instantiated parameters to pass to the window's constructor |
void sgl::pause | ( | int | msec | ) |
Pauses the program's execution for a period of milliseconds.
msec | the number of milliseconds to pause |
void sgl::procedural_default_paint_function | ( | ) |
Converts an integer to a string so it can be displayed with draw_text.
i | the integer to convert |
d | the double to convert |
int sgl::random | ( | int | begin, |
int | end | ||
) |
Returns a pseudorandom number in the specified range.
begin | the lowest integer in the set of potential return values. |
end | the highest integer in the set of potential return values. |
int sgl::random | ( | int | n | ) |
Returns a pseudorandom number in the range 0...n - 1.
n | the number of distinct potential pseudorandom values. |
|
inline |
Creates an SGL window of type T passing the arguments found in the Args parameter to the window's constructor. Calls the window's run method to start the application.
T | the type of SGL window to create |
Args | the argument pack to pass to the window's constructor |
args | the instantiated parameters to pass to the window's constructor |
void sgl::run_window | ( | ) |
Starts the graphical event loop for a window created via create_window. Used for the SGL's procedural interface.
void sgl::set_color | ( | const Color & | color | ) |
Sets the current drawing color.
color | the color to use for subsequent drawing operations. |
void sgl::set_color | ( | double | r, |
double | g, | ||
double | b | ||
) |
Sets the current drawing color according to the given RGB values.
r | the intensity of red to use for subsequent drawing operations. |
g | the intensity of green to use for subsequent drawing operations. |
b | the intensity of blue to use for subsequent drawing operations. |
void sgl::set_key_pressed_function | ( | const std::function< void(int, double, double)> & | f | ) |
Registers the client's custom keypress callback function with the graphical window. Used for the SGL's procedural interface.
f | the client's callback function |
void sgl::set_line_width | ( | double | width | ) |
Sets the current line width.
width | the width to use for subsequent line drawing operations. |
void sgl::set_mouse_dragged_function | ( | const std::function< void(double, double)> & | f | ) |
Registers the client's custom mouse dragged callback function with the graphical window. Used for the SGL's procedural interface.
f | the client's callback function |
void sgl::set_mouse_moved_function | ( | const std::function< void(double, double)> & | f | ) |
Registers the client's custom mouse moved callback function with the graphical window. Used for the SGL's procedural interface.
f | the client's callback function |
void sgl::set_mouse_pressed_function | ( | const std::function< void(double, double, MouseButton)> & | f | ) |
Registers the client's custom mouse pressed callback function with the graphical window. Used for the SGL's procedural interface.
f | the client's callback function |
void sgl::set_mouse_released_function | ( | const std::function< void(double, double, MouseButton)> & | f | ) |
Registers the client's custom mouse released callback function with the graphical window. Used for the SGL's procedural interface.
f | the client's callback function |
void sgl::set_paint_function | ( | const std::function< void()> & | f | ) |
Registers the client's custom painting callback function with the graphical window. Used for the SGL's procedural interface.
f | the client's callback function |
void sgl::set_point_size | ( | int | point_size | ) |
Sets the size of a rendred point
the | point size |
void sgl::set_random_seed | ( | int | seed = -1 | ) |
Sets the pseudorandom number generator seed.
seed | the pseudorandom number seed. If omitted, the seed is generated pseudorandomly from the operating system's time. |
void sgl::set_window_background | ( | const Color & | c | ) |
Changes the background color of the graphics window. Client must call update_window
to force the repainting for it to take effect. Used for the SGL's procedural interface.
c | the desired background color |
void sgl::set_window_title | ( | const std::string & | str | ) |
Sets the title of the window. Used for the SGL's procedural interface.
str | the text of the new title |
double sgl::text_width | ( | const std::string & | text, |
int | font_size | ||
) |
Returns the length of the graphical text in units of the viewport coordinate system.
text | the text string to measure |
font_size | the size of the font: 10, 12, or 18. |
void sgl::update_window | ( | ) |
Requests the graphical framework to repaint the window. Used for the SGL's procedural interface. Schedules the application's painting callback for execution.
std::string sgl::version | ( | ) |
Converts an integer to a string so it can be displayed with draw_text.
i | the integer to convert |
d | the double to convert |
const Color sgl::BLACK(0.0, 0.0, 0.0) |
Some commonly used colors