Camera¶
-
namespace ezgl
A library for creating a graphical user interface.
-
class camera¶
- #include <camera.hpp>
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.
Public 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.
-
inline rectangle get_initial_world() const¶
Get the initial bounds of the world. Needed for zoom_fit
-
void set_world(rectangle new_world)¶
Update the visible bounds of the world.
Used in panning and zooming.
Protected Functions
-
explicit camera(rectangle bounds)¶
Create a camera.
- Parameters:
bounds – The initial bounds of the coordinate system.
-
void update_widget(int width, int height)¶
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.
See also
-
void update_scale_factors()¶
Update the scaling factors.
Private Members
Friends
- friend class canvas
-
point2d world_to_screen(point2d world_coordinates) const¶
-
class camera¶