Go to the documentation of this file.
34 void UIWidget::initBaseStyle()
45 static unsigned long id = 1;
49 void UIWidget::parseBaseStyle(
const OTMLNodePtr& styleNode)
57 std::string funcName = node->tag().substr(1);
58 std::string funcOrigin =
"@" + node->source() +
": [" + node->tag() +
"]";
64 std::string fieldName = node->tag().substr(1);
65 std::string fieldOrigin =
"@" + node->source() +
": [" + node->tag() +
"]";
73 if(node->tag() ==
"color")
75 else if(node->tag() ==
"x")
76 setX(node->value<
int>());
77 else if(node->tag() ==
"y")
78 setY(node->value<
int>());
79 else if(node->tag() ==
"pos")
81 else if(node->tag() ==
"width")
83 else if(node->tag() ==
"height")
85 else if(node->tag() ==
"rect")
87 else if(node->tag() ==
"background")
89 else if(node->tag() ==
"background-color")
91 else if(node->tag() ==
"background-offset-x")
93 else if(node->tag() ==
"background-offset-y")
95 else if(node->tag() ==
"background-offset")
97 else if(node->tag() ==
"background-width")
99 else if(node->tag() ==
"background-height")
101 else if(node->tag() ==
"background-size")
103 else if(node->tag() ==
"background-rect")
105 else if(node->tag() ==
"icon")
107 else if(node->tag() ==
"icon-source")
109 else if(node->tag() ==
"icon-color")
111 else if(node->tag() ==
"icon-offset-x")
113 else if(node->tag() ==
"icon-offset-y")
115 else if(node->tag() ==
"icon-offset")
117 else if(node->tag() ==
"icon-width")
119 else if(node->tag() ==
"icon-height")
121 else if(node->tag() ==
"icon-size")
123 else if(node->tag() ==
"icon-rect")
125 else if(node->tag() ==
"icon-clip")
127 else if(node->tag() ==
"icon-align")
129 else if(node->tag() ==
"opacity")
131 else if(node->tag() ==
"rotation")
133 else if(node->tag() ==
"enabled")
135 else if(node->tag() ==
"visible")
137 else if(node->tag() ==
"checked")
139 else if(node->tag() ==
"draggable")
141 else if(node->tag() ==
"on")
142 setOn(node->value<
bool>());
143 else if(node->tag() ==
"focusable")
145 else if(node->tag() ==
"auto-focus")
147 else if(node->tag() ==
"phantom")
149 else if(node->tag() ==
"size")
151 else if(node->tag() ==
"fixed-size")
153 else if(node->tag() ==
"clipping")
155 else if(node->tag() ==
"border") {
157 if(
split.size() == 2) {
161 throw OTMLException(node,
"border param must have its width followed by its color");
163 else if(node->tag() ==
"border-width")
165 else if(node->tag() ==
"border-width-top")
167 else if(node->tag() ==
"border-width-right")
169 else if(node->tag() ==
"border-width-bottom")
171 else if(node->tag() ==
"border-width-left")
173 else if(node->tag() ==
"border-color")
175 else if(node->tag() ==
"border-color-top")
177 else if(node->tag() ==
"border-color-right")
179 else if(node->tag() ==
"border-color-bottom")
181 else if(node->tag() ==
"border-color-left")
183 else if(node->tag() ==
"margin-top")
185 else if(node->tag() ==
"margin-right")
187 else if(node->tag() ==
"margin-bottom")
189 else if(node->tag() ==
"margin-left")
191 else if(node->tag() ==
"margin") {
192 std::string marginDesc = node->value();
194 if(
split.size() == 4) {
199 }
else if(
split.size() == 3) {
200 int marginTop = stdext::safe_cast<int>(
split[0]);
201 int marginHorizontal = stdext::safe_cast<int>(
split[1]);
202 int marginBottom = stdext::safe_cast<int>(
split[2]);
207 }
else if(
split.size() == 2) {
208 int marginVertical = stdext::safe_cast<int>(
split[0]);
209 int marginHorizontal = stdext::safe_cast<int>(
split[1]);
214 }
else if(
split.size() == 1) {
215 int margin = stdext::safe_cast<int>(
split[0]);
222 else if(node->tag() ==
"padding-top")
224 else if(node->tag() ==
"padding-right")
226 else if(node->tag() ==
"padding-bottom")
228 else if(node->tag() ==
"padding-left")
230 else if(node->tag() ==
"padding") {
231 std::string paddingDesc = node->value();
233 if(
split.size() == 4) {
238 }
else if(
split.size() == 3) {
239 int paddingTop = stdext::safe_cast<int>(
split[0]);
240 int paddingHorizontal = stdext::safe_cast<int>(
split[1]);
241 int paddingBottom = stdext::safe_cast<int>(
split[2]);
246 }
else if(
split.size() == 2) {
247 int paddingVertical = stdext::safe_cast<int>(
split[0]);
248 int paddingHorizontal = stdext::safe_cast<int>(
split[1]);
253 }
else if(
split.size() == 1) {
254 int padding = stdext::safe_cast<int>(
split[0]);
262 else if(node->tag() ==
"layout") {
263 std::string layoutType;
265 layoutType = node->value();
267 layoutType = node->valueAt<std::string>(
"type",
"");
269 if(!layoutType.empty()) {
271 if(layoutType ==
"horizontalBox")
273 else if(layoutType ==
"verticalBox")
275 else if(layoutType ==
"grid")
277 else if(layoutType ==
"anchor")
284 if(node->hasChildren())
292 throw OTMLException(node,
"cannot create anchor, there is no parent widget!");
303 throw OTMLException(node,
"cannot create anchor, the parent widget doesn't use anchor layout!");
305 std::string what = node->tag().substr(8);
308 }
else if(what ==
"centerIn") {
313 if(node->value() ==
"none") {
317 if(
split.size() != 2)
320 std::string hookedWidgetId =
split[0];
329 addAnchor(anchoredEdge, hookedWidgetId, hookedEdge);
339 Rect drawRect = screenCoords;
385 drawRect = screenCoords;
virtual void setColor(const Color &color)
TPoint< T > bottomLeft() const
void resize(const TSize< T > &size)
All OTML errors throw this exception.
void alignIn(const TRect< T > &r, Fw::AlignmentFlag align)
virtual bool isUIAnchorLayout()
TPoint< T > topRight() const
bool starts_with(const std::string &str, const std::string &test)
stdext::shared_object_ptr< UIVerticalLayout > UIVerticalLayoutPtr
TPoint< T > topLeft() const
AutoFocusPolicy translateAutoFocusPolicy(std::string policy)
std::string resolve_path(const std::string &filePath, std::string sourcePath)
Resolve a file path by combining sourcePath with filePath.
stdext::shared_object_ptr< T > static_self_cast()
void luaSetField(const std::string &key)
Sets a field from this lua object, the value must be on the stack.
void moveCenter(const TPoint< T > &p)
TexturePtr getTexture(const std::string &fileName)
std::vector< std::string > split(const std::string &str, const std::string &separators)
AlignmentFlag translateAlignment(std::string aligment)
AnchorEdge translateAnchorEdge(std::string anchorEdge)
stdext::shared_object_ptr< UIGridLayout > UIGridLayoutPtr
stdext::shared_object_ptr< UIAnchorLayout > UIAnchorLayoutPtr
TextureManager g_textures
void loadFunction(const std::string &buffer, const std::string &source="lua function buffer")
stdext::shared_object_ptr< UIHorizontalLayout > UIHorizontalLayoutPtr
virtual void drawFilledRect(const Rect &dest)=0
TPoint< T > center() const
virtual void applyStyle(const OTMLNodePtr &)
virtual void drawTexturedRect(const Rect &dest, const TexturePtr &texture, const Rect &src)=0
void evaluateExpression(const std::string &expression, const std::string &source="lua expression")