This repository was archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewport.h
More file actions
68 lines (55 loc) · 1.69 KB
/
Viewport.h
File metadata and controls
68 lines (55 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Created by abdoulayedia on 09.01.2023
//
#pragma once
#include "Layer.h"
#include "constants.h"
namespace sse {
// Viewport
class Viewport: public Layer {
public:
// Viewport() = default;
Viewport(sf::RenderTexture& renderTexture): _renderTexture(renderTexture) {}
~Viewport() = default;
void OnAttach() override;
bool OnHandleEvents(sf::Event& event) override;
void OnUpdate(float dt) override;
void OnRenderUI() override;
private:
// Viewport
ImRect _viewportRect;
// Rendering
sf::RenderTexture& _renderTexture;
sf::Texture _texture;
float _cellSize = 25.f;
// View
sf::View _view;
sf::Vector2f _viewportMousePos;
sf::Vector2f _viewMousePos;
// Camera movement and zoom
float _viewSpeed = 500.f;
float _zoom = 1.f;
float _targetZoom = 1.f;
float _zoomSpeed = 2.f;
float _zoomDeltaMultiplier = 0.5f;
bool _snapMovement = false;
bool _snapZoom = false;
bool _showGrid = true;
bool _showDebug = false;
// Events
sf::FloatRect _selectionRect;
float smoothstep(float edge0, float edge1, float x);
float lerp(float left, float right, float x);
template<typename T>
inline sf::Vector2<T> lerp(sf::Vector2<T> left, sf::Vector2<T> right, float x) {
return sf::Vector2<T>(lerp(left.x, right.x, x), lerp(left.y, right.y, x));
}
void RenderViewport();
void RenderDebug();
void RenderToolbox();
void RenderGrid(sf::RenderTarget& target, float cellSize = 25.f, sf::Color color = sf::Color::White);
void RenderSelection();
template<typename Callback>
static void RenderOverlay(Callback&& callback, const char* id = "Overlay");
};
} // namespace sse