UIElement.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #include "UIElement.h"
  2. UIElement::UIElement()
  3. : Framework::ReferenceCounter(),
  4. marginLeft(0),
  5. marginRight(0),
  6. marginTop(0),
  7. marginBottom(0),
  8. width(0),
  9. height(0)
  10. {}
  11. void UIElement::setId(const Framework::Text& id)
  12. {
  13. this->id = id;
  14. }
  15. const Framework::Text& UIElement::getId() const
  16. {
  17. return id;
  18. }
  19. void UIElement::setMarginLeft(int marginLeft)
  20. {
  21. this->marginLeft = marginLeft;
  22. }
  23. int UIElement::getMarginLeft() const
  24. {
  25. return marginLeft;
  26. }
  27. void UIElement::setMarginRight(int marginRight)
  28. {
  29. this->marginRight = marginRight;
  30. }
  31. int UIElement::getMarginRight() const
  32. {
  33. return marginRight;
  34. }
  35. void UIElement::setMarginTop(int marginTop)
  36. {
  37. this->marginTop = marginTop;
  38. }
  39. int UIElement::getMarginTop() const
  40. {
  41. return marginTop;
  42. }
  43. void UIElement::setMarginBottom(int marginBottom)
  44. {
  45. this->marginBottom = marginBottom;
  46. }
  47. int UIElement::getMarginBottom() const
  48. {
  49. return marginBottom;
  50. }
  51. void UIElement::setWidth(int width)
  52. {
  53. this->width = width;
  54. }
  55. int UIElement::getWidth() const
  56. {
  57. return width;
  58. }
  59. void UIElement::setHeight(int height)
  60. {
  61. this->height = height;
  62. }
  63. int UIElement::getHeight() const
  64. {
  65. return height;
  66. }
  67. void UIElement::setAlignLeft(const Framework::Text& alignLeft)
  68. {
  69. this->alignLeft = alignLeft;
  70. }
  71. const Framework::Text& UIElement::getAlignLeft() const
  72. {
  73. return alignLeft;
  74. }
  75. void UIElement::setAlignRight(const Framework::Text& alignRight)
  76. {
  77. this->alignRight = alignRight;
  78. }
  79. const Framework::Text& UIElement::getAlignRight() const
  80. {
  81. return alignRight;
  82. }
  83. void UIElement::setAlignTop(const Framework::Text& alignTop)
  84. {
  85. this->alignTop = alignTop;
  86. }
  87. const Framework::Text& UIElement::getAlignTop() const
  88. {
  89. return alignTop;
  90. }
  91. void UIElement::setAlignBottom(const Framework::Text& alignBottom)
  92. {
  93. this->alignBottom = alignBottom;
  94. }
  95. const Framework::Text& UIElement::getAlignBottom() const
  96. {
  97. return alignBottom;
  98. }
  99. Framework::XML::Element* UIElement::toUIML(
  100. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  101. {
  102. Framework::XML::Element* result = new Framework::XML::Element();
  103. result->setAttribute("id", id);
  104. if (marginLeft != 0)
  105. {
  106. result->setAttribute("marginLeft", Framework::Text(marginLeft));
  107. }
  108. if (marginRight != 0)
  109. {
  110. result->setAttribute("marginRight", Framework::Text(marginRight));
  111. }
  112. if (marginTop != 0)
  113. {
  114. result->setAttribute("marginTop", Framework::Text(marginTop));
  115. }
  116. if (marginBottom != 0)
  117. {
  118. result->setAttribute("marginBottom", Framework::Text(marginBottom));
  119. }
  120. result->setAttribute("width", Framework::Text(width));
  121. result->setAttribute("height", Framework::Text(height));
  122. if (alignLeft.getLength() > 0)
  123. {
  124. result->setAttribute("alignLeft", alignLeft);
  125. }
  126. if (alignRight.getLength() > 0)
  127. {
  128. result->setAttribute("alignRight", alignRight);
  129. }
  130. if (alignTop.getLength() > 0)
  131. {
  132. result->setAttribute("alignTop", alignTop);
  133. }
  134. if (alignBottom.getLength() > 0)
  135. {
  136. result->setAttribute("alignBottom", alignBottom);
  137. }
  138. return result;
  139. }
  140. UIContainerElement::UIContainerElement()
  141. : UIElement()
  142. {}
  143. void UIContainerElement::addChild(UIElement* child)
  144. {
  145. children.add(child);
  146. }
  147. const Framework::RCArray<UIElement>& UIContainerElement::getChildren() const
  148. {
  149. return children;
  150. }
  151. Framework::XML::Element* UIContainerElement::toUIML(
  152. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  153. {
  154. Framework::XML::Element* result = UIElement::toUIML(zTarget, zActor);
  155. for (UIElement* child : children)
  156. {
  157. result->addChild(child->toUIML(zTarget, zActor));
  158. }
  159. return result;
  160. }