-
Notifications
You must be signed in to change notification settings - Fork 8
Documentation
Table of Contents
A struct to store points and coordinates
Point(int x, int y);
Create a Point object. Please note that the y coordinate has a different behaviour in the computer world, than in the math world. The y coordinates grows downwards in computer graphics; Meaning that if a point has a higher y, it will be drawn lower in the screen.
Example:
Point P(10, 20);
A struct representing a rectangle, mainly used to specify where images must be drawn.
Rectangle(int x, int y, int w, int h)
Constructs a rectangle with (x,y) as its top-left corner, w as its width, and h as its height.
Rectangle(Point top_left, int w, int h)
Constructs a rectangle with top_left
as its top-left corner, w as its width, and h as its height. handy in case you already have a Point representing the top-left of the rectangle.
Rectangle(Point top_left, Point bottom_right)
Pretty self-explanatory! handy if you already have the two Points and don't want to unpack them.
A struct to store colors in Red-Green-Blue format
RGB(int r, int g, int b)
Create an RGB object.
Example:
RGB PERSIAN_BLUE(28, 57, 187);
draw_img(string filename, Point src = Point(0, 0), Point size = Point(0, 0), double angle = 0, bool flip_horizontal = false, bool flip_vertical = false);
Draws an image file with the specified properties. Top-left corner of image will be at src
, so bottom-right corner of it will be at src + size
. You can specify an angle
in degree to rotate picture around its center clockwise. Also, you can flip picture horizontally or vertically.
Example:
win.draw_bmp("myimage.bmp", Point(0, 0), Point(10, 10));
show_text(string input, Point src, RGB color = WHITE, string fontAddress = "FreeSans.ttf", int size = 24);
Shows the input string starting from src
with specified color, font and size.
Example:
win.show_text("Hello", Point(100, 100), RED, "FreeSans.ttf", 14);
draw_point(Point p, RGB color = WHITE);
Draws a point with specified color.
Example:
win.draw_point(Point(100, 100), BLUE);
draw_line(Point src, Point dst, RGB color = WHITE);
Draws a line from point src
to point dst
with specified color.
Example:
win.draw_line(Point(0, 0), Point(100, 100), RED);
draw_rect(Point src, Point size, RGB color = WHITE, unsigned int line_width = 4);
Draws a rectangle with specified line_width and color. Top-left corner of rectangle will be at src
, so bottom-right corner of it will be at src + size
.
Example:
win.draw_rect(Point(100, 100), Point(50, 100), BLUE);
fill_rect(Point src, Point size, RGB color = WHITE);
Draws a filled rectangle with specified color. Top-left corner of rectangle will be at src
, so bottom-right corner of it will be at src + size
.
Example:
win.fill_rect(Point(100, 100), Point(50, 100), BLUE);
fill_circle(Point center, int radius, RGB color);
Draws a filled circle with specified color, center and radius.
Example:
win.fill_circle(Point(100, 100), 10, BLUE);
update_screen();
Updates the window to the drawings. Call this method after all of your calls to draw or fill methods to update the screen.
Example:
win.update_screen();
clear();
Clears the entire screen.
Example:
win.clear();
poll_for_event();
Returns the last event happened in window.
Example:
Event event = win.poll_for_event();
Event objects are returned by window poll_for_event method
You can get event data or event type from event.
get_type();
Returns type of event.
It can be one the following types:
-
NA
: Returned when no event has been happened in window. -
LCLICK
: Returned when mouse left button clicked. -
RCLICK
: Returned when mouse right button clicked. -
LRELEASE
: Returned when mouse left button released. -
RRELEASE
: Returned when mouse right button released. -
MMOTION
: Returned when mouse cursor moved. -
KEY_PRESS
: Returned when a keyboard key pressed. -
QUIT
: Returned when a quit from program command was issued.
get_mouse_position();
Returns the recent mouse vertical location in window.
Returns relative valuse if event is a mouse motion.
Returns -1
if event is a keyboard key press.
Example:
int mouse_y_location;
if(event.get_type() == Event::LCLICK )
Point p = event.get_mouse_position();
get_pressed_key();
Returns the character of pressed keyboard key.
Returns -1
if event is not a keyboard key press.
Example:
char pressedChar;
if(event.get_type() == Event::KEY_PRESS )
pressedChar = event.get_pressed_key();
delay(int millisecond);
Delays for given time in millisecond.
Example:
delay(40); // equals 25fps