-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add generic initialization mechanism in AlienWindow
- Loading branch information
Showing
35 changed files
with
138 additions
and
140 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,29 +1,108 @@ | ||
#pragma once | ||
|
||
#include <imgui.h> | ||
|
||
#include "Base/GlobalSettings.h" | ||
|
||
#include "Definitions.h" | ||
#include "StyleRepository.h" | ||
#include "ShutdownInterface.h" | ||
#include "ShutdownController.h" | ||
#include "WindowController.h" | ||
|
||
template<typename ...Dependencies> | ||
class AlienWindow : public ShutdownInterface | ||
{ | ||
public: | ||
AlienWindow(std::string const& title, std::string const& settingsNode, bool defaultOn); | ||
|
||
void init(Dependencies... dependencies); | ||
|
||
void process(); | ||
|
||
bool isOn() const; | ||
void setOn(bool value); | ||
|
||
|
||
protected: | ||
virtual void initIntern(Dependencies... dependencies) {} | ||
virtual void shutdownIntern() {} | ||
virtual void processIntern() = 0; | ||
virtual void processBackground() {} | ||
virtual void processActivated() {} | ||
|
||
bool _sizeInitialized = false; | ||
bool _on = false; | ||
bool _defaultOn = false; | ||
std::string _title; | ||
std::string _settingsNode; | ||
|
||
private: | ||
void shutdown() override; | ||
}; | ||
}; | ||
|
||
/************************************************************************/ | ||
/* Implementation */ | ||
/************************************************************************/ | ||
|
||
template <typename ... Dependencies> | ||
AlienWindow<Dependencies...>::AlienWindow(std::string const& title, std::string const& settingsNode, bool defaultOn) | ||
: _title(title) | ||
, _settingsNode(settingsNode) | ||
, _defaultOn(defaultOn) | ||
{} | ||
|
||
template <typename ... Dependencies> | ||
void AlienWindow<Dependencies...>::init(Dependencies... dependencies) | ||
{ | ||
_on = GlobalSettings::get().getBool(_settingsNode + ".active", _defaultOn); | ||
ShutdownController::get().registerObject(this); | ||
initIntern(dependencies...); | ||
} | ||
|
||
template <typename ... Dependencies> | ||
void AlienWindow<Dependencies...>::process() | ||
{ | ||
processBackground(); | ||
|
||
if (!_on) { | ||
return; | ||
} | ||
ImGui::PushID(_title.c_str()); | ||
|
||
ImGui::SetNextWindowBgAlpha(Const::WindowAlpha * ImGui::GetStyle().Alpha); | ||
if (ImGui::Begin(_title.c_str(), &_on)) { | ||
if (!_sizeInitialized) { | ||
auto size = ImGui::GetWindowSize(); | ||
auto factor = WindowController::get().getContentScaleFactor() / WindowController::get().getLastContentScaleFactor(); | ||
ImGui::SetWindowSize({size.x * factor, size.y * factor}); | ||
_sizeInitialized = true; | ||
} | ||
processIntern(); | ||
} | ||
ImGui::End(); | ||
|
||
ImGui::PopID(); | ||
} | ||
|
||
template <typename ... Dependencies> | ||
bool AlienWindow<Dependencies...>::isOn() const | ||
{ | ||
return _on; | ||
} | ||
|
||
template <typename ... Dependencies> | ||
void AlienWindow<Dependencies...>::setOn(bool value) | ||
{ | ||
_on = value; | ||
if (value) { | ||
processActivated(); | ||
} | ||
} | ||
|
||
template <typename ... Dependencies> | ||
void AlienWindow<Dependencies...>::shutdown() | ||
{ | ||
shutdownIntern(); | ||
GlobalSettings::get().setBool(_settingsNode + ".active", _on); | ||
} |
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
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
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
Oops, something went wrong.