~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/widgets/IconBase.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: IconBase
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
 
8
//
 
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.
 
13
// 
 
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.
 
18
// 
 
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.//
 
22
//
 
23
#ifdef HAVE_CONFIG_H
 
24
#include "config.h"
 
25
#endif
 
26
 
 
27
#include "IconBase.h"
 
28
 
 
29
#include <CEGUIImagesetManager.h> 
 
30
#include <CEGUIImageset.h> 
 
31
#include <elements/CEGUIFrameWindow.h>
 
32
#include "../GUIManager.h"
 
33
 
 
34
using namespace CEGUI;
 
35
namespace EmberOgre {
 
36
namespace Gui {
 
37
 
 
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)
 
40
{
 
41
 
 
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));
 
49
 
 
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);
 
55
        
 
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));
 
60
        
 
61
        mContainer->addChildWindow(mButton);
 
62
        
 
63
        mButton->render();
 
64
 
 
65
 
 
66
}
 
67
 
 
68
IconBase::~IconBase()
 
69
{
 
70
        CEGUI::WindowManager::getSingleton().destroyWindow(mButton);
 
71
        CEGUI::WindowManager::getSingleton().destroyWindow(mContainer);
 
72
}
 
73
 
 
74
Window* IconBase::getContainer()
 
75
{
 
76
        return mContainer;
 
77
}
 
78
 
 
79
PushButton * IconBase::getButton()
 
80
{
 
81
        return mButton;
 
82
}
 
83
 
 
84
void IconBase::setForeground(const Image* image)
 
85
{
 
86
        mButton->setProperty("FrontImage", PropertyHelper::imageToString(image));
 
87
}
 
88
 
 
89
 
 
90
const Image* IconBase::loadImageFromImageset(const std::string & imagesetName, const std::string & image)
 
91
{
 
92
        Imageset* imageSet;
 
93
        if (!ImagesetManager::getSingleton().isImagesetPresent(imagesetName)) {
 
94
                try {
 
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());
 
99
                        return 0;
 
100
                } catch (const CEGUI::Exception& ex) {
 
101
                        S_LOG_WARNING("Error when loading imageset " << imagesetName << ": " << ex.getMessage().c_str());
 
102
                        return 0;
 
103
                }
 
104
        } else {
 
105
                imageSet = ImagesetManager::getSingleton().getImageset(imagesetName);
 
106
        }
 
107
        
 
108
        return &imageSet->getImage(image);
 
109
 
 
110
}
 
111
}
 
112
 
 
113
}