Jazz2::Editor::EditorCamera class

Camera of the level editor.

Moves freely over the level at any scale — how many pixels of the view one pixel of the level takes. Zooming goes through steps of round percentages of how large the game shows the level (see GetGameplayScale()), and is animated, keeping still the point it zooms at. A dragged view keeps moving for a while after it's let go, and FlyTo() zooms out and back in on the way to a distant place (the smooth zoom and pan of van Wijk and Nuij).

A position in the view is in pixels from its top left corner.

Constructors, destructors, conversion operators

EditorCamera()

Public functions

void SetView(Vector2i viewSize, float gameplayScale)
Sets the size of the view and the scale at which it shows as much of the level as the game does.
void SetLevelBounds(const Rectf& bounds)
Sets the bounds of the level, the center of the view stays inside of them.
auto GetViewSize() const -> Vector2i
Returns the size of the view.
auto GetCenter() const -> Vector2f
Returns the center of the view in the level.
auto GetScale() const -> float
Returns how many pixels of the view one pixel of the level takes.
auto GetGameplayScale() const -> float
Returns the scale at which the view shows as much of the level as the game does.
auto GetTargetScale() const -> float
Returns the scale the camera is getting to, the same as GetScale() when it's not moving.
auto GetMinScale() const -> float
Returns the smallest scale.
auto GetMaxScale() const -> float
Returns the largest scale.
auto ViewToWorld(Vector2f viewPos) const -> Vector2f
Converts a position in the view to a position in the level.
auto WorldToView(Vector2f worldPos) const -> Vector2f
Converts a position in the level to a position in the view.
void JumpTo(Vector2f center, float scale)
Moves the camera at once, stopping any movement.
void ZoomSteps(Vector2f viewPos, float steps)
Zooms by a number of steps, positive in, keeping still a point of the view.
void ZoomTo(Vector2f viewPos, float scale)
Zooms to a scale, keeping still a point of the view.
void ZoomBy(Vector2f viewPos, float factor)
Zooms by a factor at once, keeping still a point of the view.
void PanBy(Vector2f viewDelta)
Moves the view by a distance in pixels of the view, at once.
void BeginDrag(Vector2f viewPos)
Starts dragging the view at a point.
void DragTo(Vector2f viewPos)
Drags the view, the level under the point where it started follows the pointer.
void EndDrag()
Ends dragging, the view keeps moving as fast as it was dragged for a while.
auto IsDragging() const -> bool
Returns true if the view is being dragged.
void FlyTo(Vector2f center, float scale)
Flies the camera to a place, zooming out on the way if it's far.
void Fit(const Rectf& worldRect, bool animate)
Flies the camera so that a part of the level fills the view, or moves it there at once.
void Stop()
Stops any movement.
auto IsMoving() const -> bool
Returns true if the camera is moving by itself.
void Update(float timeMult)
Advances the movement.
auto SnapScale(float scale, std::int32_t direction) const -> float
Returns the step of the zoom closest to a scale, by direction the next one up or down.

Function documentation

void Jazz2::Editor::EditorCamera::ZoomBy(Vector2f viewPos, float factor)

Zooms by a factor at once, keeping still a point of the view.

Not snapped to the steps, for zooming smoothly by a little every frame, as with a trigger of a gamepad.