ezgl  1.0.1
An Easy Graphics & GUI Library
Public Member Functions | Protected Member Functions | Friends | List of all members
ezgl::camera Class Reference

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ camera()

ezgl::camera::camera ( rectangle  bounds)
explicitprotected

Create a camera.

Parameters
boundsThe initial bounds of the coordinate system.

Member Function Documentation

◆ get_initial_world()

rectangle ezgl::camera::get_initial_world ( ) const
inline

Get the initial bounds of the world.

Needed for zoom_fit

◆ reset_world()

void ezgl::camera::reset_world ( rectangle  new_world)

Reset the world coordinates.

Used by change_canvas_world_coordinates().

◆ set_world()

void ezgl::camera::set_world ( rectangle  new_world)

Update the visible bounds of the world.

Used in panning and zooming.

◆ update_widget()

void ezgl::camera::update_widget ( int  width,
int  height 
)
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.

See also
canvas::configure_event

The documentation for this class was generated from the following file: