~ubuntu-branches/debian/wheezy/cegui-mk2/wheezy

« back to all changes in this revision

Viewing changes to cegui/src/CEGUIRenderedStringWidgetComponent.cpp

  • Committer: Package Import Robot
  • Author(s): Muammar El Khatib
  • Date: 2011-10-13 12:43:12 UTC
  • mfrom: (10.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20111013124312-qch0o3fayloxgxu3
Tags: 0.7.5-7
Moved to unstable. (Closes: #645109)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***********************************************************************
 
2
    filename:   CEGUIRenderedStringWidgetComponent.cpp
 
3
    created:    27/05/2009
 
4
    author:     Paul Turner
 
5
 *************************************************************************/
 
6
/***************************************************************************
 
7
 *   Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
 
8
 *
 
9
 *   Permission is hereby granted, free of charge, to any person obtaining
 
10
 *   a copy of this software and associated documentation files (the
 
11
 *   "Software"), to deal in the Software without restriction, including
 
12
 *   without limitation the rights to use, copy, modify, merge, publish,
 
13
 *   distribute, sublicense, and/or sell copies of the Software, and to
 
14
 *   permit persons to whom the Software is furnished to do so, subject to
 
15
 *   the following conditions:
 
16
 *
 
17
 *   The above copyright notice and this permission notice shall be
 
18
 *   included in all copies or substantial portions of the Software.
 
19
 *
 
20
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
23
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
24
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
25
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
26
 *   OTHER DEALINGS IN THE SOFTWARE.
 
27
 ***************************************************************************/
 
28
#include "CEGUIRenderedStringWidgetComponent.h"
 
29
#include "CEGUIWindowManager.h"
 
30
#include "CEGUIWindow.h"
 
31
#include "CEGUIExceptions.h"
 
32
 
 
33
// Start of CEGUI namespace section
 
34
namespace CEGUI
 
35
{
 
36
//----------------------------------------------------------------------------//
 
37
RenderedStringWidgetComponent::RenderedStringWidgetComponent() :
 
38
    d_window(0)
 
39
{
 
40
}
 
41
 
 
42
//----------------------------------------------------------------------------//
 
43
RenderedStringWidgetComponent::RenderedStringWidgetComponent(
 
44
        const String& widget_name) :
 
45
    d_window(WindowManager::getSingleton().getWindow(widget_name))
 
46
{
 
47
}
 
48
 
 
49
//----------------------------------------------------------------------------//
 
50
RenderedStringWidgetComponent::RenderedStringWidgetComponent(Window* widget) :
 
51
    d_window(widget)
 
52
{
 
53
}
 
54
 
 
55
//----------------------------------------------------------------------------//
 
56
void RenderedStringWidgetComponent::setWindow(const String& widget_name)
 
57
{
 
58
    d_window = WindowManager::getSingleton().getWindow(widget_name);
 
59
}
 
60
 
 
61
//----------------------------------------------------------------------------//
 
62
void RenderedStringWidgetComponent::setWindow(Window* widget)
 
63
{
 
64
    d_window = widget;
 
65
}
 
66
 
 
67
//----------------------------------------------------------------------------//
 
68
const Window* RenderedStringWidgetComponent::getWindow() const
 
69
{
 
70
    return d_window;
 
71
}
 
72
 
 
73
//----------------------------------------------------------------------------//
 
74
void RenderedStringWidgetComponent::draw(GeometryBuffer& /*buffer*/,
 
75
                                         const Vector2& position,
 
76
                                         const CEGUI::ColourRect* /*mod_colours*/,
 
77
                                         const Rect* /*clip_rect*/,
 
78
                                         const float vertical_space,
 
79
                                         const float /*space_extra*/) const
 
80
{
 
81
    if (!d_window)
 
82
        return;
 
83
 
 
84
    // HACK: re-adjust for inner-rect of parent
 
85
    float x_adj = 0, y_adj = 0;
 
86
    Window* parent = d_window->getParent();
 
87
    
 
88
    if (parent)
 
89
    {
 
90
        const CEGUI::Rect outer(parent->getUnclippedOuterRect());
 
91
        const CEGUI::Rect inner(parent->getUnclippedInnerRect());
 
92
        x_adj = inner.d_left - outer.d_left;
 
93
        y_adj = inner.d_top - outer.d_top;
 
94
    }
 
95
    // HACK: re-adjust for inner-rect of parent (Ends)
 
96
 
 
97
    Vector2 final_pos(position);
 
98
    // handle formatting options
 
99
    switch (d_verticalFormatting)
 
100
    {
 
101
    case VF_BOTTOM_ALIGNED:
 
102
        final_pos.d_y += vertical_space - getPixelSize().d_height;
 
103
        break;
 
104
 
 
105
    case VF_STRETCHED:
 
106
        Logger::getSingleton().logEvent("RenderedStringWidgetComponent::draw: "
 
107
            "VF_STRETCHED specified but is unsupported for Widget types; "
 
108
            "defaulting to VF_CENTRE_ALIGNED instead.");
 
109
        
 
110
        // intentional fall-through.
 
111
        
 
112
    case VF_CENTRE_ALIGNED:
 
113
        final_pos.d_y += (vertical_space - getPixelSize().d_height) / 2 ;
 
114
        break;
 
115
 
 
116
 
 
117
    case VF_TOP_ALIGNED:
 
118
        // nothing additional to do for this formatting option.
 
119
        break;
 
120
 
 
121
    default:
 
122
        CEGUI_THROW(InvalidRequestException("RenderedStringTextComponent::draw: "
 
123
                "unknown VerticalFormatting option specified."));
 
124
    }
 
125
 
 
126
    // we do not actually draw the widget, we just move it into position.
 
127
    const UVector2 wpos(UDim(0, final_pos.d_x + d_padding.d_left - x_adj),
 
128
                        UDim(0, final_pos.d_y + d_padding.d_top - y_adj));
 
129
 
 
130
    d_window->setPosition(wpos);
 
131
}
 
132
 
 
133
//----------------------------------------------------------------------------//
 
134
Size RenderedStringWidgetComponent::getPixelSize() const
 
135
{
 
136
    Size sz(0, 0);
 
137
 
 
138
    if (d_window)
 
139
    {
 
140
        sz = d_window->getPixelSize();
 
141
        sz.d_width += (d_padding.d_left + d_padding.d_right);
 
142
        sz.d_height += (d_padding.d_top + d_padding.d_bottom);
 
143
    }
 
144
 
 
145
    return sz;
 
146
}
 
147
 
 
148
//----------------------------------------------------------------------------//
 
149
bool RenderedStringWidgetComponent::canSplit() const
 
150
{
 
151
    return false;
 
152
}
 
153
 
 
154
//----------------------------------------------------------------------------//
 
155
RenderedStringWidgetComponent* RenderedStringWidgetComponent::split(
 
156
    float /*split_point*/, bool /*first_component*/)
 
157
{
 
158
    CEGUI_THROW(InvalidRequestException(
 
159
        "RenderedStringWidgetComponent::split: this "
 
160
        "component does not support being split."));
 
161
}
 
162
 
 
163
//----------------------------------------------------------------------------//
 
164
RenderedStringWidgetComponent* RenderedStringWidgetComponent::clone() const
 
165
{
 
166
    return new RenderedStringWidgetComponent(*this);
 
167
}
 
168
 
 
169
//----------------------------------------------------------------------------//
 
170
size_t RenderedStringWidgetComponent::getSpaceCount() const
 
171
{
 
172
    // widgets do not have spaces
 
173
    return 0;
 
174
}
 
175
 
 
176
//----------------------------------------------------------------------------//
 
177
 
 
178
} // End of  CEGUI namespace section