Polyphase Game Engine
Loading...
Searching...
No Matches
ViewportModule.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include "../../PreferencesModule.h"
6#include "Maths.h"
7
8class ViewportModule : public PreferencesModule
9{
10public:
11 DECLARE_PREFERENCES_MODULE(ViewportModule)
12
13 ViewportModule();
14 virtual ~ViewportModule();
15
16 virtual const char* GetName() const override { return GetStaticName(); }
17 virtual const char* GetParentPath() const override { return GetStaticParentPath(); }
18 virtual void Render() override;
19 virtual void LoadSettings(const rapidjson::Document& doc) override;
20 virtual void SaveSettings(rapidjson::Document& doc) override;
21
22 // Settings accessors
23 glm::vec4 GetBackgroundColor() const { return mBackgroundColor; }
24 bool GetShowGrid() const { return mShowGrid; }
25 glm::vec4 GetGridColor() const { return mGridColor; }
26 float GetGridSize() const { return mGridSize; }
27 glm::vec4 GetSelectedColor() const { return mSelectedColor; }
28 float GetSelectedCheckerSize() const { return mSelectedCheckerSize; }
29 float GetMenuBarPadding() const { return mMenuBarPadding; }
30 bool GetShowGizmosInPreview() const { return mShowGizmosInPreview; }
31 void SetShowGizmosInPreview(bool show);
32 // 0 = Auto (50% on Intel/AMD integrated GPUs driving a HiDPI window,
33 // else 100%), 1 = 100%, 2 = 75%, 3 = 50%.
34 int GetResolutionScaleMode() const { return mResolutionScaleMode; }
35 // Pushes the mode's scale to the renderer. Auto depends on the window's
36 // pixel size, so EditorState::Update calls this whenever that changes.
37 void ApplyResolutionScale() const;
38
39 // Transform snapping. Mode: 0 = Increment, 1 = Vertex, 2 = Edge, 3 = Face.
40 bool GetSnapEnabled() const { return mSnapEnabled; }
41 void SetSnapEnabled(bool enabled);
42 int GetSnapMode() const { return mSnapMode; }
43 void SetSnapMode(int mode);
44 float GetSnapTranslate() const { return mSnapTranslate; }
45 float GetSnapRotate() const { return mSnapRotate; }
46 float GetSnapScale() const { return mSnapScale; }
47 float GetSnapWidgetPixels() const { return mSnapWidgetPixels; }
48 float GetSnapPixelThreshold() const { return mSnapPixelThreshold; }
49 float GetPrecisionNormal() const { return mPrecisionNormal; }
50 float GetPrecisionCtrl() const { return mPrecisionCtrl; }
51
52 static ViewportModule* Get();
53 static void HandleExternalGridToggle(bool enabled);
54
55private:
56 void ApplyBackgroundColorToRenderer() const;
57 void ApplyGridVisibility();
58 void ApplySelectedOverlay() const;
59
60 int mResolutionScaleMode = 0;
61 glm::vec4 mBackgroundColor = glm::vec4(0.1f, 0.1f, 0.1f, 1.0f);
62 bool mShowGrid = true;
63 glm::vec4 mGridColor = glm::vec4(0.3f, 0.3f, 0.3f, 1.0f);
64 float mGridSize = 1.0f;
65 glm::vec4 mSelectedColor = glm::vec4(0.2f, 0.1f, 1.0f, 0.6f);
66 float mSelectedCheckerSize = 8.0f;
67 float mMenuBarPadding = 8.0f;
68 bool mShowGizmosInPreview = false;
69
70 bool mSnapEnabled = false;
71 int mSnapMode = 0;
72 float mSnapTranslate = 1.0f;
73 float mSnapRotate = 15.0f;
74 float mSnapScale = 0.1f;
75 float mSnapWidgetPixels = 8.0f;
76 float mSnapPixelThreshold = 16.0f;
77 float mPrecisionNormal = 1.0f;
78 float mPrecisionCtrl = 0.1f;
79
80 static ViewportModule* sInstance;
81 static bool sSyncingGridState;
82};
83
84#endif
glm::vec4 GetGridColor()
Definition JsonHelpers.h:15