Skip to content

Commit

Permalink
GUI2/Settings: bunch of cleanup and minor refactoring
Browse files Browse the repository at this point in the history
Notable changes:
* get_window_builder now returns a const reference instead of an iterator.
* gui_definition and builder_window (not the one in window.cpp) now take a config reference directly
  and call read() from their ctors instead of requiring that be called manually.
* Added some more documentation.
* Made variable names more accurate.
* Removed some unused static variables
* Removed the unused non-class load_widget_definitions function (the gui_definition member of the same
  name remains.
  • Loading branch information
Vultraz committed May 29, 2017
1 parent 13fb9fb commit 4d00a81
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 136 deletions.
12 changes: 3 additions & 9 deletions src/gui/core/window_builder.cpp
Expand Up @@ -125,9 +125,8 @@ window* build(CVideo& video, const builder_window::window_resolution* definition

window* build(CVideo& video, const std::string& type)
{
std::vector<builder_window::window_resolution>::const_iterator definition
= get_window_builder(type);
window* window = build(video, &*definition);
const builder_window::window_resolution& definition = get_window_builder(type);
window* window = build(video, &definition);
window->set_id(type);
return window;
}
Expand Down Expand Up @@ -251,11 +250,8 @@ builder_widget_ptr create_builder_widget(const config& cfg)
*
*
*/
const std::string& builder_window::read(const config& cfg)
void builder_window::read(const config& cfg)
{
id_ = cfg["id"].str();
description_ = cfg["description"].str();

VALIDATE(!id_.empty(), missing_mandatory_wml_key("window", "id"));
VALIDATE(!description_.empty(),
missing_mandatory_wml_key("window", "description"));
Expand All @@ -268,8 +264,6 @@ const std::string& builder_window::read(const config& cfg)
{
resolutions.emplace_back(i);
}

return id_;
}

/*WIKI
Expand Down
10 changes: 7 additions & 3 deletions src/gui/core/window_builder.hpp
Expand Up @@ -150,12 +150,14 @@ typedef std::shared_ptr<const builder_grid> builder_grid_const_ptr;
class builder_window
{
public:
builder_window() : resolutions(), id_(), description_()
explicit builder_window(const config& cfg)
: resolutions()
, id_(cfg["id"])
, description_(cfg["description"])
{
read(cfg);
}

const std::string& read(const config& cfg);

struct window_resolution
{
public:
Expand Down Expand Up @@ -203,6 +205,8 @@ class builder_window
std::vector<window_resolution> resolutions;

private:
void read(const config& cfg);

std::string id_;
std::string description_;
};
Expand Down
2 changes: 2 additions & 0 deletions src/gui/widgets/helper.cpp
Expand Up @@ -33,13 +33,15 @@ static bool initialized_ = false;

bool init()
{
const size_t start = SDL_GetTicks();
if(initialized_) {
return true;
}

load_settings();

initialized_ = true;
std::cout << "GUI2 init took " << (SDL_GetTicks() - start) << " ms" << std::endl;
return initialized_;
}

Expand Down

0 comments on commit 4d00a81

Please sign in to comment.