-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
142 additions
and
8 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
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,67 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <functional> | ||
#include <map> | ||
|
||
#include <glm/glm.hpp> | ||
#include "imgui.h" | ||
|
||
namespace shkyera { | ||
|
||
template<typename EnumType> | ||
class EnumSelector { | ||
public: | ||
EnumSelector(const std::string& title, EnumType value, const std::map<EnumType, std::string>& options) : | ||
_title(title), | ||
_value(value), | ||
_options(options) | ||
{} | ||
|
||
void setUpdateCallback(std::function<void(EnumType value)> callback) | ||
{ | ||
_updateCallback = callback; | ||
} | ||
|
||
void draw() | ||
{ | ||
EnumType oldValue = _value; | ||
ImGui::PushItemWidth(50); | ||
ImGui::TextUnformatted(_title.c_str()); | ||
ImGui::PopItemWidth(); | ||
|
||
ImGui::SameLine(120); | ||
ImGui::PushItemWidth(190); | ||
|
||
if(ImGui::BeginCombo((std::string("##" + _title + "EnumSelectorCombo").c_str()), _options.at(_value).c_str())) | ||
{ | ||
for(const auto& [value, name] : _options) | ||
{ | ||
if (ImGui::Selectable(name.c_str())) | ||
{ | ||
_value = value; | ||
} | ||
} | ||
|
||
ImGui::EndCombo(); | ||
} | ||
|
||
ImGui::PopItemWidth(); | ||
|
||
if(oldValue != _value) | ||
{ | ||
if(_updateCallback) | ||
{ | ||
_updateCallback(_value); | ||
} | ||
} | ||
} | ||
|
||
private: | ||
std::string _title; | ||
EnumType _value; | ||
std::map<EnumType, std::string> _options; | ||
std::function<void(EnumType value)> _updateCallback; | ||
}; | ||
|
||
} |
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,37 @@ | ||
#include "imgui.h" | ||
|
||
#include <glm/glm.hpp> | ||
#include <AssetManager/Image.hpp> | ||
#include <UI/Components/CameraComponentUI.hpp> | ||
|
||
namespace shkyera { | ||
|
||
CameraComponentUI::CameraComponentUI(CameraComponent* cameraComponent) : | ||
_cameraComponent(cameraComponent), | ||
_fovSlider("Field of View", cameraComponent->fov, 5, 160), | ||
_projectionSelector("Projection", cameraComponent->projectionType, { | ||
{ CameraComponent::ProjectionType::Perspective, "Perspective" }, | ||
{ CameraComponent::ProjectionType::Orthographic, "Orthographic" }, | ||
}) | ||
{ | ||
_fovSlider.setUpdateCallback([this](float fov) { | ||
_cameraComponent->fov = fov; | ||
}); | ||
_projectionSelector.setUpdateCallback([this](const auto projection) { | ||
_cameraComponent->projectionType = projection; | ||
}); | ||
} | ||
|
||
void CameraComponentUI::draw() { | ||
ImGui::Image(_icon->getImguiTextureID(), | ||
ImVec2(16, 16)); | ||
ImGui::SameLine(); | ||
if (ImGui::TreeNodeEx("Camera", ImGuiTreeNodeFlags_DefaultOpen)) { | ||
_projectionSelector.draw(); | ||
_fovSlider.draw(); | ||
|
||
ImGui::TreePop(); | ||
} | ||
} | ||
|
||
} |
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,22 @@ | ||
#pragma once | ||
|
||
#include <UI/ComponentUI.hpp> | ||
#include <UI/Common/FloatSlider.hpp> | ||
#include <UI/Common/EnumSelector.hpp> | ||
#include <Components/CameraComponent.hpp> | ||
|
||
namespace shkyera { | ||
|
||
class CameraComponentUI : public ComponentUI { | ||
public: | ||
CameraComponentUI(CameraComponent* cameraComponent); | ||
|
||
void draw() override; | ||
|
||
private: | ||
FloatSlider _fovSlider; | ||
EnumSelector<CameraComponent::ProjectionType> _projectionSelector; | ||
CameraComponent* _cameraComponent; | ||
}; | ||
|
||
} |
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