1
/***********************************************************************
2
filename: CEGUIRenderedStringWidgetComponent.cpp
5
*************************************************************************/
6
/***************************************************************************
7
* Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
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:
17
* The above copyright notice and this permission notice shall be
18
* included in all copies or substantial portions of the Software.
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"
33
// Start of CEGUI namespace section
36
//----------------------------------------------------------------------------//
37
RenderedStringWidgetComponent::RenderedStringWidgetComponent() :
42
//----------------------------------------------------------------------------//
43
RenderedStringWidgetComponent::RenderedStringWidgetComponent(
44
const String& widget_name) :
45
d_window(WindowManager::getSingleton().getWindow(widget_name))
49
//----------------------------------------------------------------------------//
50
RenderedStringWidgetComponent::RenderedStringWidgetComponent(Window* widget) :
55
//----------------------------------------------------------------------------//
56
void RenderedStringWidgetComponent::setWindow(const String& widget_name)
58
d_window = WindowManager::getSingleton().getWindow(widget_name);
61
//----------------------------------------------------------------------------//
62
void RenderedStringWidgetComponent::setWindow(Window* widget)
67
//----------------------------------------------------------------------------//
68
const Window* RenderedStringWidgetComponent::getWindow() const
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
84
// HACK: re-adjust for inner-rect of parent
85
float x_adj = 0, y_adj = 0;
86
Window* parent = d_window->getParent();
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;
95
// HACK: re-adjust for inner-rect of parent (Ends)
97
Vector2 final_pos(position);
98
// handle formatting options
99
switch (d_verticalFormatting)
101
case VF_BOTTOM_ALIGNED:
102
final_pos.d_y += vertical_space - getPixelSize().d_height;
106
Logger::getSingleton().logEvent("RenderedStringWidgetComponent::draw: "
107
"VF_STRETCHED specified but is unsupported for Widget types; "
108
"defaulting to VF_CENTRE_ALIGNED instead.");
110
// intentional fall-through.
112
case VF_CENTRE_ALIGNED:
113
final_pos.d_y += (vertical_space - getPixelSize().d_height) / 2 ;
118
// nothing additional to do for this formatting option.
122
CEGUI_THROW(InvalidRequestException("RenderedStringTextComponent::draw: "
123
"unknown VerticalFormatting option specified."));
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));
130
d_window->setPosition(wpos);
133
//----------------------------------------------------------------------------//
134
Size RenderedStringWidgetComponent::getPixelSize() const
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);
148
//----------------------------------------------------------------------------//
149
bool RenderedStringWidgetComponent::canSplit() const
154
//----------------------------------------------------------------------------//
155
RenderedStringWidgetComponent* RenderedStringWidgetComponent::split(
156
float /*split_point*/, bool /*first_component*/)
158
CEGUI_THROW(InvalidRequestException(
159
"RenderedStringWidgetComponent::split: this "
160
"component does not support being split."));
163
//----------------------------------------------------------------------------//
164
RenderedStringWidgetComponent* RenderedStringWidgetComponent::clone() const
166
return new RenderedStringWidgetComponent(*this);
169
//----------------------------------------------------------------------------//
170
size_t RenderedStringWidgetComponent::getSpaceCount() const
172
// widgets do not have spaces
176
//----------------------------------------------------------------------------//
178
} // End of CEGUI namespace section