Skip to content

Commit

Permalink
Client: Added Style
Browse files Browse the repository at this point in the history
Style contains all the information about the UI style. It is owned by
WindowSystem and accessible globally inside the client.
  • Loading branch information
skyjake committed May 14, 2013
1 parent 6e2a4f2 commit 194a444
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -355,6 +355,7 @@ DENG_HEADERS += \
include/ui/mouse_qt.h \
include/ui/nativeui.h \
include/ui/p_control.h \
include/ui/style.h \
include/ui/sys_input.h \
include/ui/ui2_main.h \
include/ui/ui_main.h \
Expand Down Expand Up @@ -621,6 +622,7 @@ SOURCES += \
src/ui/mouse_qt.cpp \
src/ui/nativeui.cpp \
src/ui/p_control.cpp \
src/ui/style.cpp \
src/ui/sys_input.cpp \
src/ui/ui2_main.cpp \
src/ui/ui_main.cpp \
Expand Down
51 changes: 51 additions & 0 deletions doomsday/client/include/ui/style.h
@@ -0,0 +1,51 @@
/** @file style.h User interface style.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_STYLE_H
#define DENG_CLIENT_STYLE_H

#include <de/RuleBank>
#include <de/FontBank>
#include <de/ColorBank>
#include <de/ImageBank>

/**
* User interface style.
*/
class Style
{
public:
Style();

/**
* Loads a style from a resource pack.
*
* @param pack Path of a resource pack containing the style.
*/
void load(de::String const &pack);

de::RuleBank const &rules() const;
de::FontBank const &fonts() const;
de::ColorBank const &colors() const;
de::ImageBank const &images() const;

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_STYLE_H
6 changes: 6 additions & 0 deletions doomsday/client/include/ui/windowsystem.h
Expand Up @@ -27,6 +27,7 @@
#include <de/String>

class ClientWindow;
class Style;

/**
* Window management subsystem.
Expand Down Expand Up @@ -90,6 +91,11 @@ class WindowSystem : public de::System
*/
void closeAll();

/**
* Returns the window system's UI style.
*/
Style &style();

// System.
bool processEvent(de::Event const &);
void timeChanged(de::Clock const &);
Expand Down
79 changes: 79 additions & 0 deletions doomsday/client/src/ui/style.cpp
@@ -0,0 +1,79 @@
/** @file style.h User interface style.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "ui/style.h"

using namespace de;

DENG2_PIMPL(Style)
{
String packPath;
RuleBank rules;
FontBank fonts;
ColorBank colors;
ImageBank images;

Instance(Public *i) : Base(i)
{}

void clear()
{
rules.clear();
fonts.clear();
colors.clear();
images.clear();
}

void load(String const &path)
{
packPath = path;
rules.addFromInfo(path / "rules.dei");
fonts.addFromInfo(path / "fonts.dei");
colors.addFromInfo(path / "colors.dei");
images.addFromInfo(path / "images.dei");
}
};

Style::Style() : d(new Instance(this))
{}

void Style::load(String const &pack)
{
d->clear();
d->load(pack);
}

RuleBank const &Style::rules() const
{
return d->rules;
}

FontBank const &Style::fonts() const
{
return d->fonts;
}

ColorBank const &Style::colors() const
{
return d->colors;
}

ImageBank const &Style::images() const
{
return d->images;
}
8 changes: 3 additions & 5 deletions doomsday/client/src/ui/windowsystem.cpp
Expand Up @@ -19,10 +19,9 @@
#include "de_platform.h"
#include "ui/windowsystem.h"
#include "ui/clientwindow.h"
#include "ui/style.h"
#include "clientapp.h"

#include <de/FontBank>

#include <QMap>

using namespace de;
Expand All @@ -31,12 +30,11 @@ DENG2_PIMPL(WindowSystem)
{
typedef QMap<String, ClientWindow *> Windows;
Windows windows;

FontBank fonts;
Style style;

Instance(Public *i) : Base(i)
{
fonts.addFromInfo(App::fileSystem().find("defaultstyle.pack/fonts.dei"));
style.load(App::fileSystem().find("defaultstyle.pack").path());
}

~Instance()
Expand Down

0 comments on commit 194a444

Please sign in to comment.