2
// C++ Implementation: IconBase
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
9
// This program is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU General Public License as published by
11
// the Free Software Foundation; either version 2 of the License, or
12
// (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program; if not, write to the Free Software
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
29
#include <CEGUIImagesetManager.h>
30
#include <CEGUIImageset.h>
31
#include <elements/CEGUIFrameWindow.h>
32
#include "../GUIManager.h"
34
using namespace CEGUI;
38
IconBase::IconBase(const std::string& name, const Image* background, const Image* foreground, const Image* borderInactive, const Image* borderActive, UVector2 size)
39
: mContainer(0), mButton(0)
42
mContainer = WindowManager::getSingleton().createWindow("DefaultGUISheet", "icons/" + name + "/container");
43
mContainer->setSize(size);
44
mContainer->setVisible(true);
45
mContainer->setEnabled(true);
46
// mContainer->setFrameEnabled(false);
47
// mContainer->setBackgroundEnabled(false);
48
// mContainer->setBackgroundColours(colour(1,1,1,0));
50
mButton = static_cast<PushButton*>(WindowManager::getSingleton().createWindow(EmberOgre::GUIManager::getSingleton().getDefaultScheme() + "/BorderIconButton", "icons/" + name + "/button"));
51
mButton->setSize(UVector2(UDim(1, 0), UDim(1, 0)));
52
mButton->setPosition(UVector2(UDim(0, 0), UDim(0, 0)));
53
mButton->setVisible(true);
54
mButton->setEnabled(true);
56
mButton->setProperty("BackImage", PropertyHelper::imageToString(background));
57
mButton->setProperty("FrontImage", PropertyHelper::imageToString(foreground));
58
mButton->setProperty("BorderNormalImage", PropertyHelper::imageToString(borderInactive));
59
mButton->setProperty("BorderHoverImage", PropertyHelper::imageToString(borderActive));
61
mContainer->addChildWindow(mButton);
70
CEGUI::WindowManager::getSingleton().destroyWindow(mButton);
71
CEGUI::WindowManager::getSingleton().destroyWindow(mContainer);
74
Window* IconBase::getContainer()
79
PushButton * IconBase::getButton()
84
void IconBase::setForeground(const Image* image)
86
mButton->setProperty("FrontImage", PropertyHelper::imageToString(image));
90
const Image* IconBase::loadImageFromImageset(const std::string & imagesetName, const std::string & image)
93
if (!ImagesetManager::getSingleton().isImagesetPresent(imagesetName)) {
95
std::string imagesetFileName("cegui/datafiles/imagesets/" + imagesetName + ".imageset");
96
imageSet = ImagesetManager::getSingleton().createImageset(imagesetFileName);
97
} catch (const std::exception& ex) {
98
S_LOG_WARNING("Error when loading imageset " << imagesetName << ": " << ex.what());
100
} catch (const CEGUI::Exception& ex) {
101
S_LOG_WARNING("Error when loading imageset " << imagesetName << ": " << ex.getMessage().c_str());
105
imageSet = ImagesetManager::getSingleton().getImageset(imagesetName);
108
return &imageSet->getImage(image);