p6::Context
Summary
Name | |
---|---|
Context(WindowCreationParams window_creation_params = {}) | |
~Context() | |
Context([Context](/reference/Types/context) && ) =default | |
Context & | operator=([Context](/reference/Types/context) && ) =delete |
Context(const [Context](/reference/Types/context) & ) =delete | |
Context & | operator=(const [Context](/reference/Types/context) & ) =delete |
void | background([Color](/reference/Types/color) color)Sets the color and alpha of each pixel of the canvas. |
void | square([FullScreen](/reference/Types/full_screen) )Draws a square. |
void | square([Center](/reference/Types/center) center = {}, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | square([TopLeftCorner](/reference/Types/top_left_corner) corner, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | square([TopRightCorner](/reference/Types/top_right_corner) corner, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | square([BottomLeftCorner](/reference/Types/bottom_left_corner) corner, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | square([BottomRightCorner](/reference/Types/bottom_right_corner) corner, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle([FullScreen](/reference/Types/full_screen) = {})Draws a rectangle. |
void | rectangle([Center](/reference/Types/center) center, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle([TopLeftCorner](/reference/Types/top_left_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle([TopRightCorner](/reference/Types/top_right_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle([BottomLeftCorner](/reference/Types/bottom_left_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle([BottomRightCorner](/reference/Types/bottom_right_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle([Transform2D](/reference/Types/transform2_d) transform) |
void | circle([FullScreen](/reference/Types/full_screen) )Draws a circle. |
void | circle([Center](/reference/Types/center) center = {}, [Radius](/reference/Types/radius) radius = {}) |
void | ellipse([FullScreen](/reference/Types/full_screen) = {})Draws an ellipse. |
void | ellipse([Center](/reference/Types/center) center, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | ellipse([Transform2D](/reference/Types/transform2_d) transform) |
void | equilateral_triangle([Center](/reference/Types/center) center, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {})Draws an equilateral triangle. [Radius]() is the distance between the [Center](/reference/Types/center) and one of the tips of the triangle. |
void | triangle([Point2D](/reference/Types/point2_d) p1, [Point2D](/reference/Types/point2_d) p2, [Point2D](/reference/Types/point2_d) p3, [Center](/reference/Types/center) center = {}, [Rotation](/reference/Types/angle) rotation = {})Draws a triangle between the three points, translated by [Center](/reference/Types/center) and rotated by Rotation . |
void | triangle([Point2D](/reference/Types/point2_d) p1, [Point2D](/reference/Types/point2_d) p2, [Point2D](/reference/Types/point2_d) p3, [Transform2D](/reference/Types/transform2_d) transform)Draws a triangle between the three points, and applies the transform to the triangle. |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [Fit](/reference/Types/fit) = {})Draws an image as big as possible on the screen. This will respect the aspect ratio of the image. |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [FitX](/reference/Types/fit_x) ) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [FitY](/reference/Types/fit_y) ) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [Center](/reference/Types/center) center, [RadiusX](/reference/Types/radius_x) radiusX = {}, [Rotation](/reference/Types/angle) rotation = {})Draws an image. This will respect the aspect ratio of the image. |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [TopLeftCorner](/reference/Types/top_left_corner) corner, [RadiusX](/reference/Types/radius_x) radiusX = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [TopRightCorner](/reference/Types/top_right_corner) corner, [RadiusX](/reference/Types/radius_x) radiusX = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [BottomLeftCorner](/reference/Types/bottom_left_corner) corner, [RadiusX](/reference/Types/radius_x) radiusX = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [BottomRightCorner](/reference/Types/bottom_right_corner) corner, [RadiusX](/reference/Types/radius_x) radiusX = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [Center](/reference/Types/center) center, [RadiusY](/reference/Types/radius_y) radiusY = {}, [Rotation](/reference/Types/angle) rotation = {})Draws an image. This will respect the aspect ratio of the image. |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [TopLeftCorner](/reference/Types/top_left_corner) corner, [RadiusY](/reference/Types/radius_y) radiusY = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [TopRightCorner](/reference/Types/top_right_corner) corner, [RadiusY](/reference/Types/radius_y) radiusY = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [BottomLeftCorner](/reference/Types/bottom_left_corner) corner, [RadiusY](/reference/Types/radius_y) radiusY = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [BottomRightCorner](/reference/Types/bottom_right_corner) corner, [RadiusY](/reference/Types/radius_y) radiusY = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [FullScreen](/reference/Types/full_screen) )Draws an image that takes the entire window. ⚠️ This might distort the image if the window doesn't have the same aspect ratio as the image. |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [Center](/reference/Types/center) center, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {})Draws an image. ⚠️ This might distort the image if radii doesn't have the same aspect ratio as the image. |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [TopLeftCorner](/reference/Types/top_left_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [TopRightCorner](/reference/Types/top_right_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [BottomLeftCorner](/reference/Types/bottom_left_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [BottomRightCorner](/reference/Types/bottom_right_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | image(const [ImageOrCanvas](/reference/Types/image_or_canvas) & img, [Transform2D](/reference/Types/transform2_d) transform) |
void | rectangle_with_shader(const [Shader](/reference/Types/shader) & shader, [FullScreen](/reference/Types/full_screen) = {})Draws a rectangle using a custom fragment shader. |
void | rectangle_with_shader(const [Shader](/reference/Types/shader) & shader, [Center](/reference/Types/center) center, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle_with_shader(const [Shader](/reference/Types/shader) & shader, [TopLeftCorner](/reference/Types/top_left_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle_with_shader(const [Shader](/reference/Types/shader) & shader, [TopRightCorner](/reference/Types/top_right_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle_with_shader(const [Shader](/reference/Types/shader) & shader, [BottomLeftCorner](/reference/Types/bottom_left_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle_with_shader(const [Shader](/reference/Types/shader) & shader, [BottomRightCorner](/reference/Types/bottom_right_corner) corner, [Radii](/reference/Types/radii) radii = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | square_with_shader(const [Shader](/reference/Types/shader) & shader, [Center](/reference/Types/center) center = {}, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | square_with_shader(const [Shader](/reference/Types/shader) & shader, [TopLeftCorner](/reference/Types/top_left_corner) corner, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | square_with_shader(const [Shader](/reference/Types/shader) & shader, [TopRightCorner](/reference/Types/top_right_corner) corner, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | square_with_shader(const [Shader](/reference/Types/shader) & shader, [BottomLeftCorner](/reference/Types/bottom_left_corner) corner, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | square_with_shader(const [Shader](/reference/Types/shader) & shader, [BottomRightCorner](/reference/Types/bottom_right_corner) corner, [Radius](/reference/Types/radius) radius = {}, [Rotation](/reference/Types/angle) rotation = {}) |
void | rectangle_with_shader(const [Shader](/reference/Types/shader) & shader, [Transform2D](/reference/Types/transform2_d) transform) |
void | line(glm::vec2 start, glm::vec2 end)Draws a line between two points. |
void | text(const std::u16string & str, [Center](/reference/Types/center) center, [Rotation](/reference/Types/angle) rotation = {}) |
void | text(const std::u16string & str, [TopLeftCorner](/reference/Types/top_left_corner) corner, [Rotation](/reference/Types/angle) rotation = {}) |
void | text(const std::u16string & str, [TopRightCorner](/reference/Types/top_right_corner) corner, [Rotation](/reference/Types/angle) rotation = {}) |
void | text(const std::u16string & str, [BottomLeftCorner](/reference/Types/bottom_left_corner) corner, [Rotation](/reference/Types/angle) rotation = {}) |
void | text(const std::u16string & str, [BottomRightCorner](/reference/Types/bottom_right_corner) corner, [Rotation](/reference/Types/angle) rotation = {}) |
void | translate(glm::vec2 translation)Applies a translation to all the future drawings. To undo this, see [push_transform()]() and [pop_transform()]() . |
void | rotate([p6::Angle](/reference/Types/angle) angle)Applies a rotation to all the future drawings. To undo this, see [push_transform()]() and [pop_transform()]() . |
void | scale(glm::vec2 scale_factor)Applies a scale to all the future drawings. To undo this, see [push_transform()]() and [pop_transform()]() . |
void | reset_transform() Undoes all the translate / rotate / scale / apply_transform / set_transform. |
void | apply_transform(glm::mat3 additional_transform)Applies a custom transform matrix to all the future drawings. To undo this, see [push_transform()]() and [pop_transform()]() . |
void | set_transform(glm::mat3 transform)Sets the current transform matrix. This will override all the previous translate / rotate / scale / apply_transform. To undo this, see [push_transform()]() and [pop_transform()]() . |
void | push_transform() Saves the current transform state. |
void | pop_transform() Restores the transform to the state it had during the last [push_transform()](/reference/transform#push_transform) that has not been popped yet. |
TransformScopeGuard | transform_scope_guard() Will call push_transform() and pop_transform() automatically. |
glm::mat3 | current_transform() const Returns the current transform matrix that is the combination of all the translate / rotate / scale / apply_transform / set_transform that have been applied. |
void | render_to_canvas([Canvas](/reference/Types/canvas) & canvas)Sets a canvas to be the one that all the drawing commands will draw on, until you call render_to_main_canvas. |
void | render_to_main_canvas() Reset the Context to render to the main canvas. The main canvas is the one that will be displayed in the window. |
Canvas & | main_canvas() |
const Canvas & | main_canvas() const |
Canvas & | current_canvas() |
const Canvas & | current_canvas() const |
float | aspect_ratio() const Returns the aspect ratio (a.k.a. |
float | inverse_aspect_ratio() const Returns the inverse aspect ratio (a.k.a. |
ImageSize | main_canvas_size() const Returns the size of the main canvas (width and height). |
int | main_canvas_width() const Returns the width of the main canvas. |
int | main_canvas_height() const Returns the height of the main canvas. |
ImageSize | current_canvas_size() const Returns the size of the current canvas (width and height). |
int | current_canvas_width() const Returns the width of the current canvas. |
int | current_canvas_height() const Returns the height of the current canvas. |
void | main_canvas_mode(CanvasSizeMode mode)Sets how the size of the main canvas will be computed. |
float | canvas_ratio(const [Canvas](/reference/Types/canvas) & canvas) constReturns the ratio that you need to multiply with in order to match the position and size of the canvas when it is fitted in the window. |
void | save_image(std::filesystem::path path) constSaves the content of the window's main canvas as an image file. |
Color | read_pixel(glm::vec2 position) constReturns the color of the pixel at the given position in the main canvas. |
glm::vec2 | mouse() const Returns the current mouse position. |
glm::vec2 | mouse_delta() const Returns the movement of the mouse since the last update(). |
bool | mouse_is_in_window() const Returns true iff the window is focused and the coordinates returned by mouse() correspond to a position inside the window. |
bool | mouse_button_is_pressed(Button button) constReturns true iff the given mouse button is currently pressed. |
bool | ctrl() const Returns true iff the CTRL key is pressed (or CMD on Mac) |
bool | shift() const Returns true iff the SHIFT key is pressed. |
bool | alt() const Returns true iff the ALT key is pressed. |
bool | key_is_pressed(int key) constReturns true iff the given key is currently pressed. |
bool | window_is_focused() const Returns true iff the window is currently focused. |
void | focus_window() const Focuses the window, making it pop to the foreground. |
void | maximize_window() Maximizes the window. |
void | minimize_window() Minimizes the window. Note that while your window is minimized everything will be frozen and no update, event or anything will happen. |
void | restore_window() Restores the window if it is currently maximized. Does nothing otherwise. |
bool | window_is_maximized() const Returns true iff the window is currently maximized. |
void | go_fullscreen() Makes the window fullscreen. |
void | escape_fullscreen() Exits the fullscreen mode. |
void | toggle_fullscreen() Goes fullscreen if it wasn't, escapes fullscreen if it was. |
bool | window_is_fullscreen() const Returns true iff the window is currently fullscreen. |
GLFWwindow * | underlying_glfw_window() const Advanced function that returns the glfw window pointer. |
float | time() const Returns the time in seconds since the creation of the Context. |
float | delta_time() const Returns an estimate of the time that elapses between two update() calls. |
void | time_perceived_as_realtime() Sets the time mode as realtime. |
void | time_perceived_as_constant_delta_time(float framerate)Sets the time mode as constant delta time. |
void | framerate_synced_with_monitor() Makes sure that the framerate is adapted to your monitor: it will be 60 fps if you have a 60 Hertz monitor (which is the most common), or 120 fps if you have a 120 Hertz monitor, etc. |
void | framerate_as_high_as_possible() Removes any limit on the framerate. update() will be called as fast as possible. |
void | framerate_capped_at(float framerate)Keeps the framerate at the given value. |
void | start() Starts the update() loop. |
void | stop() Stops the update() loop. |
void | pause() Pauses the update() loop. |
void | resume() Resumes the update() loop if it was paused with pause(). |
bool | is_paused() const Returns true iff the update() loop is currently paused. |
std::function< void()> | update This function is called repeatedly. The framerate is controlled by the framerate_xxx() functions. |
std::function< void()> | imgui In this function you can call all the ImGui code you want. |
std::function< void(MouseMove)> | mouse_moved This function is called whenever the mouse is moved. |
std::function< void(MouseDrag)> | mouse_dragged This function is called whenever the mouse is dragged. |
std::function< void(MouseButton)> | mouse_pressed This function is called whenever a mouse button is pressed. |
std::function< void(MouseButton)> | mouse_released This function is called whenever a mouse button is released. |
std::function< void(MouseScroll)> | mouse_scrolled This function is called whenever the mouse wheel is scrolled. |
std::function< void(Key)> | key_pressed This function is called whenever a keyboard key is pressed. |
std::function< void(Key)> | key_released This function is called whenever a keyboard key is released. |
std::function< void(Key)> | key_repeated This function is called repeatedly whenever a keyboard key is held. |
std::function< void(std::string &&)> | on_error This function is called whenever an error occurs. |
std::function< void()> | main_canvas_resized This function is called whenever the main canvas is resized. |
std::function< void(Event)> | on_event This function is called whenever any event occurs (key pressed, mouse moved, etc.). |
Color | fill The color that is used for the interior of the shapes. |
bool | use_fill Whether the shapes will have an interior. |
Color | stroke The color that is used for the boundary of the shapes. |
float | stroke_weight The size of the boundary of the shapes. |
bool | use_stroke Whether there will be a boundary on the shape. |
float | text_size Height of the text. |
float | text_inflating Gives some "boldness" to the text. |
Details
Context()
Context(
WindowCreationParams
window_creation_params ={});
~Context()
~Context();
Context()
Context(
[Context](/reference/Types/context) &&
) =default;
operator=()
[Context](/reference/Types/context) &
operator=([Context](/reference/Types/context) &&
) =delete;
Context()
Context(
const [Context](/reference/Types/context) &
) =delete;
operator=()
[Context](/reference/Types/context) &
operator=(const [Context](/reference/Types/context) &
) =delete;
background()
void
background([Color](/reference/Types/color)
color);
Sets the color and alpha of each pixel of the canvas.
NB: No blending is applied; even if you specify an alpha of 0.5 the old canvas is completely erased. This means that setting an alpha here doesn't matter much. It is only meaningful if you export the canvas as a png, or if you later try to blend the canvas on top of another image.
square()
void
square([FullScreen](/reference/Types/full_screen)
);
Draws a square.
square()
void
square([Center](/reference/Types/center)
center ={},[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
square()
void
square([TopLeftCorner](/reference/Types/top_left_corner)
corner,[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
square()
void
square([TopRightCorner](/reference/Types/top_right_corner)
corner,[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
square()
void
square([BottomLeftCorner](/reference/Types/bottom_left_corner)
corner,[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
square()
void
square([BottomRightCorner](/reference/Types/bottom_right_corner)
corner,[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle()
void
rectangle([FullScreen](/reference/Types/full_screen)
={});
Draws a rectangle.
rectangle()
void
rectangle([Center](/reference/Types/center)
center,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle()
void
rectangle([TopLeftCorner](/reference/Types/top_left_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle()
void
rectangle([TopRightCorner](/reference/Types/top_right_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle()
void
rectangle([BottomLeftCorner](/reference/Types/bottom_left_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle()
void
rectangle([BottomRightCorner](/reference/Types/bottom_right_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle()
void
rectangle([Transform2D](/reference/Types/transform2_d)
transform);
circle()
void
circle([FullScreen](/reference/Types/full_screen)
);
Draws a circle.
circle()
void
circle([Center](/reference/Types/center)
center ={},[Radius](/reference/Types/radius)
radius ={});
ellipse()
void
ellipse([FullScreen](/reference/Types/full_screen)
={});
Draws an ellipse.
ellipse()
void
ellipse([Center](/reference/Types/center)
center,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
ellipse()
void
ellipse([Transform2D](/reference/Types/transform2_d)
transform);
equilateral_triangle()
void
equilateral_triangle([Center](/reference/Types/center)
center,[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
Draws an equilateral triangle. [Radius]()
is the distance between the [Center](/reference/Types/center)
and one of the tips of the triangle.
triangle()
void
triangle([Point2D](/reference/Types/point2_d)
p1,[Point2D](/reference/Types/point2_d)
p2,[Point2D](/reference/Types/point2_d)
p3,[Center](/reference/Types/center)
center ={},[Rotation](/reference/Types/angle)
rotation ={});
Draws a triangle between the three points, translated by [Center](/reference/Types/center)
and rotated by Rotation
.
triangle()
void
triangle([Point2D](/reference/Types/point2_d)
p1,[Point2D](/reference/Types/point2_d)
p2,[Point2D](/reference/Types/point2_d)
p3,[Transform2D](/reference/Types/transform2_d)
transform);
Draws a triangle between the three points, and applies the transform to the triangle.
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[Fit](/reference/Types/fit)
={});
Draws an image as big as possible on the screen. This will respect the aspect ratio of the image.
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[FitX](/reference/Types/fit_x)
);
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[FitY](/reference/Types/fit_y)
);
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[Center](/reference/Types/center)
center,[RadiusX](/reference/Types/radius_x)
radiusX ={},[Rotation](/reference/Types/angle)
rotation ={});
Draws an image. This will respect the aspect ratio of the image.
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[TopLeftCorner](/reference/Types/top_left_corner)
corner,[RadiusX](/reference/Types/radius_x)
radiusX ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[TopRightCorner](/reference/Types/top_right_corner)
corner,[RadiusX](/reference/Types/radius_x)
radiusX ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[BottomLeftCorner](/reference/Types/bottom_left_corner)
corner,[RadiusX](/reference/Types/radius_x)
radiusX ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[BottomRightCorner](/reference/Types/bottom_right_corner)
corner,[RadiusX](/reference/Types/radius_x)
radiusX ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[Center](/reference/Types/center)
center,[RadiusY](/reference/Types/radius_y)
radiusY ={},[Rotation](/reference/Types/angle)
rotation ={});
Draws an image. This will respect the aspect ratio of the image.
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[TopLeftCorner](/reference/Types/top_left_corner)
corner,[RadiusY](/reference/Types/radius_y)
radiusY ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[TopRightCorner](/reference/Types/top_right_corner)
corner,[RadiusY](/reference/Types/radius_y)
radiusY ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[BottomLeftCorner](/reference/Types/bottom_left_corner)
corner,[RadiusY](/reference/Types/radius_y)
radiusY ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[BottomRightCorner](/reference/Types/bottom_right_corner)
corner,[RadiusY](/reference/Types/radius_y)
radiusY ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[FullScreen](/reference/Types/full_screen)
);
Draws an image that takes the entire window. ⚠️ This might distort the image if the window doesn't have the same aspect ratio as the image.
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[Center](/reference/Types/center)
center,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
Draws an image. ⚠️ This might distort the image if radii doesn't have the same aspect ratio as the image.
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[TopLeftCorner](/reference/Types/top_left_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[TopRightCorner](/reference/Types/top_right_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[BottomLeftCorner](/reference/Types/bottom_left_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[BottomRightCorner](/reference/Types/bottom_right_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
image()
void
image(const [ImageOrCanvas](/reference/Types/image_or_canvas) &
img,[Transform2D](/reference/Types/transform2_d)
transform);
rectangle_with_shader()
void
rectangle_with_shader(const [Shader](/reference/Types/shader) &
shader,[FullScreen](/reference/Types/full_screen)
={});
Draws a rectangle using a custom fragment shader.
rectangle_with_shader()
void
rectangle_with_shader(const [Shader](/reference/Types/shader) &
shader,[Center](/reference/Types/center)
center,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle_with_shader()
void
rectangle_with_shader(const [Shader](/reference/Types/shader) &
shader,[TopLeftCorner](/reference/Types/top_left_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle_with_shader()
void
rectangle_with_shader(const [Shader](/reference/Types/shader) &
shader,[TopRightCorner](/reference/Types/top_right_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle_with_shader()
void
rectangle_with_shader(const [Shader](/reference/Types/shader) &
shader,[BottomLeftCorner](/reference/Types/bottom_left_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle_with_shader()
void
rectangle_with_shader(const [Shader](/reference/Types/shader) &
shader,[BottomRightCorner](/reference/Types/bottom_right_corner)
corner,[Radii](/reference/Types/radii)
radii ={},[Rotation](/reference/Types/angle)
rotation ={});
square_with_shader()
void
square_with_shader(const [Shader](/reference/Types/shader) &
shader,[Center](/reference/Types/center)
center ={},[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
square_with_shader()
void
square_with_shader(const [Shader](/reference/Types/shader) &
shader,[TopLeftCorner](/reference/Types/top_left_corner)
corner,[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
square_with_shader()
void
square_with_shader(const [Shader](/reference/Types/shader) &
shader,[TopRightCorner](/reference/Types/top_right_corner)
corner,[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
square_with_shader()
void
square_with_shader(const [Shader](/reference/Types/shader) &
shader,[BottomLeftCorner](/reference/Types/bottom_left_corner)
corner,[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
square_with_shader()
void
square_with_shader(const [Shader](/reference/Types/shader) &
shader,[BottomRightCorner](/reference/Types/bottom_right_corner)
corner,[Radius](/reference/Types/radius)
radius ={},[Rotation](/reference/Types/angle)
rotation ={});
rectangle_with_shader()
void
rectangle_with_shader(const [Shader](/reference/Types/shader) &
shader,[Transform2D](/reference/Types/transform2_d)
transform);
line()
void
line(glm::vec2
start,glm::vec2
end);
Draws a line between two points.
It uses the stroke
color, and stroke_weight
as its thickness.
text()
void
text(const std::u16string &
str,[Center](/reference/Types/center)
center,[Rotation](/reference/Types/angle)
rotation ={});
text()
void
text(const std::u16string &
str,[TopLeftCorner](/reference/Types/top_left_corner)
corner,[Rotation](/reference/Types/angle)
rotation ={});
text()
void
text(const std::u16string &
str,[TopRightCorner](/reference/Types/top_right_corner)
corner,[Rotation](/reference/Types/angle)
rotation ={});
text()
void
text(const std::u16string &
str,[BottomLeftCorner](/reference/Types/bottom_left_corner)
corner,[Rotation](/reference/Types/angle)
rotation ={});
text()
void
text(const std::u16string &
str,[BottomRightCorner](/reference/Types/bottom_right_corner)
corner,[Rotation](/reference/Types/angle)
rotation ={});
translate()
void
translate(glm::vec2
translation);
Applies a translation to all the future drawings. To undo this, see [push_transform()]()
and [pop_transform()]()
.
rotate()
void
rotate([p6::Angle](/reference/Types/angle)
angle);
Applies a rotation to all the future drawings. To undo this, see [push_transform()]()
and [pop_transform()]()
.
scale()
void
scale(glm::vec2
scale_factor);
Applies a scale to all the future drawings. To undo this, see [push_transform()]()
and [pop_transform()]()
.
reset_transform()
void
reset_transform();
Undoes all the translate / rotate / scale / apply_transform / set_transform.
apply_transform()
void
apply_transform(glm::mat3
additional_transform);
Applies a custom transform matrix to all the future drawings. To undo this, see [push_transform()]()
and [pop_transform()]()
.
set_transform()
void
set_transform(glm::mat3
transform);
Sets the current transform matrix. This will override all the previous translate / rotate / scale / apply_transform. To undo this, see [push_transform()]()
and [pop_transform()]()
.
push_transform()
void
push_transform();
Saves the current transform state.
pop_transform()
void
pop_transform();
Restores the transform to the state it had during the last [push_transform()](/reference/transform#push_transform)
that has not been popped yet.
transform_scope_guard()
[TransformScopeGuard](/reference/Types/transform_scope_guard)
transform_scope_guard();
Will call push_transform() and pop_transform() automatically.
Assign the result of this function to a variable and pop_transform() will be called when the variable goes out of scope. push_transform() is called when transform_scope_guard() is called.
current_transform()
glm::mat3
current_transform() const;
Returns the current transform matrix that is the combination of all the translate / rotate / scale / apply_transform / set_transform that have been applied.
render_to_canvas()
void
render_to_canvas([Canvas](/reference/Types/canvas) &
canvas);
Sets a canvas to be the one that all the drawing commands will draw on, until you call render_to_main_canvas.
render_to_main_canvas()
void
render_to_main_canvas();
Reset the Context to render to the main canvas. The main canvas is the one that will be displayed in the window.
main_canvas()
[Canvas](/reference/Types/canvas) &
main_canvas();
main_canvas()
const [Canvas](/reference/Types/canvas) &
main_canvas() const;
current_canvas()
[Canvas](/reference/Types/canvas) &
current_canvas();
current_canvas()
const [Canvas](/reference/Types/canvas) &
current_canvas() const;
aspect_ratio()
float
aspect_ratio() const;
Returns the aspect ratio (a.k.a.
width / height) of the current canvas. This canvas is the window's main canvas by default, unless you called render_to_canvas() in which case it will be the given canvas. When you call render_to_main_canvas() the current canvas goes back to beeing the window's main canvas.
inverse_aspect_ratio()
float
inverse_aspect_ratio() const;
Returns the inverse aspect ratio (a.k.a.
height / width) of the current canvas. This canvas is the window's main canvas by default, unless you called render_to_canvas() in which case it will be the given canvas. When you call render_to_main_canvas() the current canvas goes back to beeing the window's main canvas.
main_canvas_size()
ImageSize
main_canvas_size() const;
Returns the size of the main canvas (width and height).
main_canvas_width()
int
main_canvas_width() const;
Returns the width of the main canvas.
main_canvas_height()
int
main_canvas_height() const;
Returns the height of the main canvas.
current_canvas_size()
ImageSize
current_canvas_size() const;
Returns the size of the current canvas (width and height).
current_canvas_width()
int
current_canvas_width() const;
Returns the width of the current canvas.
current_canvas_height()
int
current_canvas_height() const;
Returns the height of the current canvas.
main_canvas_mode()
void
main_canvas_mode(CanvasSizeMode
mode);
Sets how the size of the main canvas will be computed.
The default mode is CanvasSizeMode_SameAsWindow.
canvas_ratio()
float
canvas_ratio(const [Canvas](/reference/Types/canvas) &
canvas) const;
Returns the ratio that you need to multiply with in order to match the position and size of the canvas
when it is fitted in the window.
save_image()
void
save_image(std::filesystem::path
path) const;
Saves the content of the window's main canvas as an image file.
Supported file types are .png and .jpeg/.jpg Simply use the corresponding extension to save in the desired format. If the path already exists, a number will be appended to the name and the previous file won't be overwritten. If the path is relative, it will be relative to the directory containing your executable. If some directories in the path don't exist yet, they will be created automatically.
read_pixel()
[Color](/reference/Types/color)
read_pixel(glm::vec2
position) const;
Returns the color of the pixel at the given position in the main canvas.
The coordinates are expressed in the usual p6 coordinate system.
mouse()
glm::vec2
mouse() const;
Returns the current mouse position.
mouse_delta()
glm::vec2
mouse_delta() const;
Returns the movement of the mouse since the last update().
mouse_is_in_window()
bool
mouse_is_in_window() const;
Returns true iff the window is focused and the coordinates returned by mouse() correspond to a position inside the window.
mouse_button_is_pressed()
bool
mouse_button_is_pressed(Button
button) const;
Returns true iff the given mouse button is currently pressed.
ctrl()
bool
ctrl() const;
Returns true iff the CTRL key is pressed (or CMD on Mac)
shift()
bool
shift() const;
Returns true iff the SHIFT key is pressed.
alt()
bool
alt() const;
Returns true iff the ALT key is pressed.
key_is_pressed()
bool
key_is_pressed(int
key) const;
Returns true iff the given key
is currently pressed.
key
should be a GLFW_KEY value. See https://www.glfw.org/docs/3.3/keys.html for the complete list. e.g. ctx.key_is_pressed(GLFW_KEY_Q)
/!\ Please note that these are physical keys that don't depend on the current layout. This means that GLFW_KEY_Q will refer to the first key on your keyboard, no matter if you are using QWERTY or AZERTY.
window_is_focused()
bool
window_is_focused() const;
Returns true iff the window is currently focused.
focus_window()
void
focus_window() const;
Focuses the window, making it pop to the foreground.
maximize_window()
void
maximize_window();
Maximizes the window.
minimize_window()
void
minimize_window();
Minimizes the window. Note that while your window is minimized everything will be frozen and no update, event or anything will happen.
restore_window()
void
restore_window();
Restores the window if it is currently maximized. Does nothing otherwise.
window_is_maximized()
bool
window_is_maximized() const;
Returns true iff the window is currently maximized.
go_fullscreen()
void
go_fullscreen();
Makes the window fullscreen.
Does nothing if it was already fullscreen.
escape_fullscreen()
void
escape_fullscreen();
Exits the fullscreen mode.
Does nothing if the window wasn't fullscreen.
toggle_fullscreen()
void
toggle_fullscreen();
Goes fullscreen if it wasn't, escapes fullscreen if it was.
window_is_fullscreen()
bool
window_is_fullscreen() const;
Returns true iff the window is currently fullscreen.
underlying_glfw_window()
GLFWwindow *
underlying_glfw_window() const;
Advanced function that returns the glfw window pointer.
It allows you to call all the glfw functions that are not directly exposed by p6. Note that you might also want to raise an issue to ask us to add that functionality directly into p6 to simplify future uses. We would be very thankful for that.
time()
float
time() const;
Returns the time in seconds since the creation of the Context.
delta_time()
float
delta_time() const;
Returns an estimate of the time that elapses between two update() calls.
time_perceived_as_realtime()
void
time_perceived_as_realtime();
Sets the time mode as realtime.
This means that what is returned by time() and delta_time() corresponds to the actual time that elapsed in the real world. This is ideal when you want to do realtime animation and interactive sketches.
time_perceived_as_constant_delta_time()
void
time_perceived_as_constant_delta_time(float
framerate);
Sets the time mode as constant delta time.
This means that what is returned by time() and delta_time() corresponds to an ideal world where there is exactly 1/framerate
seconds between each updates. This is ideal when you are exporting a video and don't want the long export time to influence your animation. framerate
is expressed in frames per second
framerate_synced_with_monitor()
void
framerate_synced_with_monitor();
Makes sure that the framerate is adapted to your monitor: it will be 60 fps if you have a 60 Hertz monitor (which is the most common), or 120 fps if you have a 120 Hertz monitor, etc.
This is the default framerate mode.
framerate_as_high_as_possible()
void
framerate_as_high_as_possible();
Removes any limit on the framerate. update() will be called as fast as possible.
framerate_capped_at()
void
framerate_capped_at(float
framerate);
Keeps the framerate at the given value.
start()
void
start();
Starts the update() loop.
update() will be called repeatedly, until you close the window or call stop().
stop()
void
stop();
Stops the update() loop.
This is the programatic equivalent of a user closing the window.
pause()
void
pause();
Pauses the update() loop.
No update() will be called, until you call resume(). User inputs are still processed.
resume()
void
resume();
Resumes the update() loop if it was paused with pause().
It has no effect if the loop was already playing.
is_paused()
bool
is_paused() const;
Returns true iff the update() loop is currently paused.
update
std::function< void()> update = []() {
};
This function is called repeatedly. The framerate is controlled by the framerate_xxx() functions.
imgui
std::function< void()> imgui = []() {
};
In this function you can call all the ImGui code you want.
Note that you can also do it during the [update()](/reference/events#update)
function. This [imgui()](/reference/events#imgui)
function is just here to help you organize your code if you want to.
mouse_moved
std::function< void(MouseMove)> mouse_moved = [](MouseMove) {
};
This function is called whenever the mouse is moved.
mouse_dragged
std::function< void(MouseDrag)> mouse_dragged = [](MouseDrag) {
};
This function is called whenever the mouse is dragged.
mouse_pressed
std::function< void(MouseButton)> mouse_pressed = [](MouseButton) {
};
This function is called whenever a mouse button is pressed.
mouse_released
std::function< void(MouseButton)> mouse_released = [](MouseButton) {
};
This function is called whenever a mouse button is released.
mouse_scrolled
std::function< void(MouseScroll)> mouse_scrolled = [](MouseScroll) {
};
This function is called whenever the mouse wheel is scrolled.
key_pressed
std::function< void(Key)> key_pressed = [](Key) {
};
This function is called whenever a keyboard key is pressed.
key_released
std::function< void(Key)> key_released = [](Key) {
};
This function is called whenever a keyboard key is released.
key_repeated
std::function< void(Key)> key_repeated = [](Key) {
};
This function is called repeatedly whenever a keyboard key is held.
(NB: this only starts after holding the key for a little while. The exact behaviour is OS-specific)
⚠️ This is less than ideal to do things like handling the movement of a character. You should rather do, in your update() function:
if (ctx.key_is_pressed(GLFW_KEY_W)) {
character.move_forward(ctx.delta_time());
}
on_error
std::function< void(std::string &&)> on_error = [](std::string&& error_message) {
std::cerr << error_message << '\n';
throw std::runtime_error{error_message};
};
This function is called whenever an error occurs.
main_canvas_resized
std::function< void()> main_canvas_resized = []() {
};
This function is called whenever the main canvas is resized.
If you call main_canvas_size(), main_canvas_width(), main_canvas_height() or aspect_ratio() inside main_canvas_resized() they will already be referring to the new size.
on_event
std::function< void(Event)> on_event = [](Event const&) {
};
This function is called whenever any event occurs (key pressed, mouse moved, etc.).
It can be useful to use this function instead of the more specific ones (key_pressed, mouse_moved, etc.) if for example you want to forward several events to a function that will handle them. For example in order to control a camera you might need to forward the key, mouse and update events to it. Instead of having to put the code inside those three event functions, you can just put it in on_event
and let the camera handle each event as it so pleases.
fill
Color fill {1.f, 1.f, 1.f, 0.5f};
The color that is used for the interior of the shapes.
use_fill
bool use_fill = true;
Whether the shapes will have an interior.
stroke
Color stroke {0.f, 0.f, 0.f};
The color that is used for the boundary of the shapes.
stroke_weight
float stroke_weight = 0.01f;
The size of the boundary of the shapes.
use_stroke
bool use_stroke = true;
Whether there will be a boundary on the shape.
text_size
float text_size = 0.03f;
Height of the text.
text_inflating
float text_inflating = 0.01f;
Gives some "boldness" to the text.
Updated on 2024 October 24