ezgl
1.0.1
An Easy Graphics & GUI Library
|
Manages the transformations between coordinate systems. More...
#include <camera.hpp>
Public Member Functions | |
point2d | world_to_screen (point2d world_coordinates) const |
Convert a point in world coordinates to screen coordinates. | |
point2d | widget_to_screen (point2d widget_coordinates) const |
Convert a point in widget coordinates to screen coordinates. | |
point2d | widget_to_world (point2d widget_coordinates) const |
Convert a point in widget coordinates to world coordinates. | |
rectangle | get_world () const |
Get the currently visible bounds of the world. | |
rectangle | get_screen () const |
Get the dimensions of the screen. | |
rectangle | get_widget () const |
Get the dimensions of the widget. | |
rectangle | get_initial_world () const |
Get the initial bounds of the world. More... | |
void | set_world (rectangle new_world) |
Update the visible bounds of the world. More... | |
void | reset_world (rectangle new_world) |
Reset the world coordinates. More... | |
point2d | get_world_scale_factor () const |
Get the screen to world scaling factor. | |
Protected Member Functions | |
camera (rectangle bounds) | |
Create a camera. More... | |
void | update_widget (int width, int height) |
Update the dimensions of the widget. More... | |
void | update_scale_factors () |
Update the scaling factors. | |
Friends | |
class | canvas |
Manages the transformations between coordinate systems.
Application code doesn't (and can't) call these functions; they are for ezgl internal use.
The camera class manages transformations between a GTK widget, world, and "screen" coordinate system. A GTK widget has dimensions that change based on the user, and its aspect ratio may not match the world coordinate system. The camera maintains a "screen" within the widget that keeps the same aspect ratio as the world coordinate system, regardless of the dimensions of the widget.
A camera object can only be created by an ezgl::canvas object, who has the responsibility of updating the camera with changes to the widget's dimensions. The only state that can be mutated outside the library is the camera's world coordinate system.
|
explicitprotected |
Create a camera.
bounds | The initial bounds of the coordinate system. |
|
inline |
Get the initial bounds of the world.
Needed for zoom_fit
void ezgl::camera::reset_world | ( | rectangle | new_world | ) |
Reset the world coordinates.
Used by change_canvas_world_coordinates().
void ezgl::camera::set_world | ( | rectangle | new_world | ) |
Update the visible bounds of the world.
Used in panning and zooming.
|
protected |
Update the dimensions of the widget.
This will change the screen where the world is projected. The screen will maintain the aspect ratio of the world's coordinate system while being centered within the screen.