Browse Source

Implement Settings in Window

master
Rick van Vonderen 5 years ago
parent
commit
9c2ceea7e2
  1. 4
      inferno/src/inferno/settings.cpp
  2. 4
      inferno/src/inferno/settings.h
  3. 10
      inferno/src/inferno/window.cpp
  4. 2
      inferno/src/inferno/window.h

4
inferno/src/inferno/settings.cpp

@ -29,7 +29,7 @@ namespace Inferno {
nlohmann::json m_json = this->load(); nlohmann::json m_json = this->load();
try { try {
m_properties.title = m_json["window"]["title"].get<std::string>().c_str(); m_properties.title = strdup(m_json["window"]["title"].get<std::string>().c_str());
m_properties.width = m_json["window"]["width"].get<int>(); m_properties.width = m_json["window"]["width"].get<int>();
m_properties.height = m_json["window"]["height"].get<int>(); m_properties.height = m_json["window"]["height"].get<int>();
} }
@ -40,6 +40,8 @@ namespace Inferno {
void Settings::destroy() void Settings::destroy()
{ {
// Delete const char*s created by strdup()
delete m_properties.title;
} }
nlohmann::json Settings::load() const nlohmann::json Settings::load() const

4
inferno/src/inferno/settings.h

@ -7,8 +7,8 @@ namespace Inferno {
struct SettingsProperties { struct SettingsProperties {
const char* title = "Inferno default"; const char* title = "Inferno default";
int width = 1280; unsigned int width = 1280;
int height = 720; unsigned int height = 720;
}; };
class Settings { class Settings {

10
inferno/src/inferno/window.cpp

@ -4,15 +4,21 @@
#include "inferno/core.h" #include "inferno/core.h"
#include "inferno/event/applicationevent.h" #include "inferno/event/applicationevent.h"
#include "inferno/log.h" #include "inferno/log.h"
#include "inferno/settings.h"
#include "inferno/window.h" #include "inferno/window.h"
namespace Inferno { namespace Inferno {
unsigned char Window::s_windowCount = 0; unsigned char Window::s_windowCount = 0;
Window::Window(const WindowProperties &properties) : Window::Window()
m_windowProperties(properties)
{ {
m_windowProperties = {
Settings::get().properties().title,
Settings::get().properties().width,
Settings::get().properties().height,
};
this->initialize(); this->initialize();
} }

2
inferno/src/inferno/window.h

@ -17,7 +17,7 @@ namespace Inferno {
class Window { class Window {
public: public:
Window(const WindowProperties &properties = WindowProperties()); Window();
virtual ~Window(); virtual ~Window();
void initialize(); void initialize();

Loading…
Cancel
Save