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_world() const

Get the currently visible bounds of the world.

inline rectangle get_screen() const

Get the dimensions of the screen.

inline rectangle get_widget() const

Get the dimensions of the widget.

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.

void reset_world(rectangle new_world)

Reset the world coordinates

Used by change_canvas_world_coordinates().

inline point2d get_world_scale_factor() const

Get the screen to world scaling factor.

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.

void update_scale_factors()

Update the scaling factors.

Private Members

rectangle m_widget = {{0, 0}, 1.0, 1.0}
rectangle m_world
rectangle m_screen
rectangle m_initial_world
point2d m_world_to_widget = {1.0, 1.0}
point2d m_widget_to_screen = {1.0, 1.0}
point2d m_screen_to_world = {1.0, 1.0}

Friends

friend class canvas