-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin to add Canvas and rework elements
- Loading branch information
Showing
9 changed files
with
153 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root | ||
// for more information. | ||
|
||
#ifndef NOVELRT_UI_DEARIMGUI_IMGUICANVAS_H | ||
#define NOVELRT_UI_DEARIMGUI_IMGUICANVAS_H | ||
|
||
#ifndef NOVELRT_UI_DEARIMGUI_H | ||
#error NovelRT does not support including types explicitly by default. Please include UI::DearImGui.h instead for the UI::DearImGui namespace subset. | ||
#endif | ||
|
||
namespace NovelRT::UI::DearImGui | ||
{ | ||
class ImGuiCanvas : public IUICanvas, public ImGuiCommon | ||
{ | ||
public: | ||
ImGuiCanvas() noexcept; | ||
|
||
ImGuiCanvas(const std::string& identifier, | ||
NovelRT::Maths::GeoVector2F position, | ||
NovelRT::Maths::GeoVector2F scale, | ||
NovelRT::Graphics::RGBAColour backgroundColour, | ||
NovelRT::Maths::GeoVector2F screenSize) noexcept; | ||
|
||
void Render(std::shared_ptr<IUIProvider> provider, NovelRT::Maths::GeoVector2F windowSize) final; | ||
|
||
void AddElement(std::shared_ptr<IUIElement> element); | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root | ||
// for more information. | ||
|
||
#ifndef NOVELRT_UI_IUICANVAS_H | ||
#define NOVELRT_UI_IUICANVAS_H | ||
|
||
#ifndef NOVELRT_UI_H | ||
#error NovelRT does not support including types explicitly by default. Please include UI.h instead for the Windowing namespace subset. | ||
#endif | ||
|
||
namespace NovelRT::UI | ||
{ | ||
class IUICanvas : public IUIElement | ||
{ | ||
protected: | ||
NovelRT::Graphics::RGBAColour _colour; | ||
std::list<std::shared_ptr<IUIElement>> _elements; | ||
|
||
public: | ||
IUICanvas(const std::string& identifier, UIElementState state, NovelRT::Maths::GeoVector2F position, | ||
NovelRT::Maths::GeoVector2F scale, NovelRT::Graphics::RGBAColour colour) noexcept : | ||
IUIElement(identifier, state, position, scale), _colour(colour), _elements(std::list<std::shared_ptr<IUIElement>>()){} | ||
|
||
virtual void AddElement(std::shared_ptr<IUIElement> element) = 0; | ||
|
||
[[nodiscard]] inline NovelRT::Graphics::RGBAColour& Colour() | ||
{ | ||
return _colour; | ||
} | ||
|
||
[[nodiscard]] inline const NovelRT::Graphics::RGBAColour& Colour() const | ||
{ | ||
return _colour; | ||
} | ||
}; | ||
} | ||
|
||
#endif // NOVELRT_UI_IUICANVAS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root | ||
// for more information. | ||
|
||
#include <NovelRT/UI/DearImGui/UI.DearImGui.h> | ||
|
||
namespace NovelRT::UI::DearImGui | ||
{ | ||
ImGuiCanvas::ImGuiCanvas() noexcept : ImGuiCanvas("", NovelRT::Maths::GeoVector2F::Zero(), NovelRT::Maths::GeoVector2F::One(), NovelRT::Graphics::RGBAColour(0,0,0,255), NovelRT::Maths::GeoVector2F::Zero()){} | ||
|
||
ImGuiCanvas::ImGuiCanvas(const std::string& identifier, NovelRT::Maths::GeoVector2F position, NovelRT::Maths::GeoVector2F scale, NovelRT::Graphics::RGBAColour Colour, NovelRT::Maths::GeoVector2F screenSize) noexcept : IUICanvas(identifier, UIElementState::Hidden, position, scale, Colour), ImGuiCommon(screenSize, position + (screenSize / 2)){} | ||
|
||
void ImGuiCanvas::Render(std::shared_ptr<IUIProvider> provider, NovelRT::Maths::GeoVector2F windowSize) | ||
{ | ||
if (_state != UIElementState::Shown) | ||
{ | ||
return; | ||
} | ||
if (windowSize != _screenSize) | ||
{ | ||
_screenSize = windowSize; | ||
_translatedPosition = _position + (windowSize / 2); | ||
} | ||
|
||
ImGui::PushStyleColor(ImGuiCol_WindowBg, _colour); | ||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(100, 100)); | ||
ImGui::Begin(_identifier.c_str(), nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize); | ||
ImGui::SetWindowPos(_translatedPosition); | ||
ImGui::SetWindowSize(_scale); | ||
ImGui::PopStyleVar(); | ||
ImGui::PopStyleColor(); | ||
|
||
for(auto&& element : _elements) | ||
{ | ||
element->Render(provider, windowSize); | ||
} | ||
|
||
ImGui::End(); | ||
|
||
} | ||
|
||
void ImGuiCanvas::AddElement(std::shared_ptr<IUIElement> element) | ||
{ | ||
_elements.emplace_back(element); | ||
} | ||
} |