1 #include "TexToolItem.h" 2 3 namespace textool { 4 addChild(TexToolItem * child)5void TexToolItem::addChild(TexToolItem* child) { 6 _children.push_back(child); 7 } 8 getChildren()9TexToolItemVec& TexToolItem::getChildren() { 10 return _children; 11 } 12 foreachItem(ItemVisitor & visitor)13void TexToolItem::foreachItem(ItemVisitor& visitor) { 14 for (unsigned int i = 0; i < _children.size(); i++) { 15 // Visit the children 16 visitor.visit(_children[i]); 17 18 // Propagate the visitor class down the hierarchy 19 _children[i]->foreachItem(visitor); 20 } 21 } 22 getSelectableChildren(const Rectangle & rectangle)23TexToolItemVec TexToolItem::getSelectableChildren(const Rectangle& rectangle) { 24 TexToolItemVec returnVector; 25 26 for (unsigned int i = 0; i < _children.size(); i++) { 27 // Add every children to the list 28 if (_children[i]->testSelect(rectangle)) { 29 returnVector.push_back(_children[i]); 30 } 31 } 32 33 return returnVector; 34 } 35 transform(const Matrix4 & matrix)36void TexToolItem::transform(const Matrix4& matrix) { 37 // Cycle through all the children and ask them to render themselves 38 for (unsigned int i = 0; i < _children.size(); i++) { 39 _children[i]->transform(matrix); 40 } 41 update(); 42 } 43 transformSelected(const Matrix4 & matrix)44void TexToolItem::transformSelected(const Matrix4& matrix) { 45 // If this object is selected, transform <self> 46 if (_selected) { 47 transform(matrix); 48 } 49 else { 50 // Object is not selected, propagate the call to the children 51 for (unsigned int i = 0; i < _children.size(); i++) { 52 _children[i]->transformSelected(matrix); 53 } 54 } 55 update(); 56 } 57 flipSelected(const int & axis)58void TexToolItem::flipSelected(const int& axis) { 59 // Default behaviour: Propagate the call to the children 60 for (unsigned int i = 0; i < _children.size(); i++) { 61 _children[i]->flipSelected(axis); 62 } 63 update(); 64 } 65 snapSelectedToGrid(float grid)66void TexToolItem::snapSelectedToGrid(float grid) { 67 // Default behaviour: Propagate the call to the children 68 for (unsigned int i = 0; i < _children.size(); i++) { 69 _children[i]->snapSelectedToGrid(grid); 70 } 71 update(); 72 } 73 getExtents()74AABB TexToolItem::getExtents() { 75 AABB returnValue; 76 77 // Cycle through all the children and include their AABB 78 for (unsigned int i = 0; i < _children.size(); i++) { 79 returnValue.includeAABB(_children[i]->getExtents()); 80 } 81 82 return returnValue; 83 } 84 getSelectedExtents()85AABB TexToolItem::getSelectedExtents() { 86 AABB returnValue; 87 88 // Add <self> to the resulting AABB if <self> is selected 89 if (_selected) { 90 returnValue.includeAABB(getExtents()); 91 } 92 93 // Cycle through all the children and include their AABB 94 for (unsigned int i = 0; i < _children.size(); i++) { 95 if (_children[i]->isSelected()) { 96 returnValue.includeAABB(_children[i]->getExtents()); 97 } 98 } 99 100 return returnValue; 101 } 102 moveSelectedTo(const Vector2 & targetCoords)103void TexToolItem::moveSelectedTo(const Vector2& targetCoords) { 104 // Default: Cycle through all children and move the selected 105 for (unsigned int i = 0; i < _children.size(); i++) { 106 _children[i]->moveSelectedTo(targetCoords); 107 } 108 update(); 109 } 110 render()111void TexToolItem::render() { 112 // Cycle through all the children and ask them to render themselves 113 for (unsigned int i = 0; i < _children.size(); i++) { 114 _children[i]->render(); 115 } 116 } 117 beginTransformation()118void TexToolItem::beginTransformation() { 119 // Cycle through all the children and pass the call 120 for (unsigned int i = 0; i < _children.size(); i++) { 121 _children[i]->beginTransformation(); 122 } 123 } 124 endTransformation()125void TexToolItem::endTransformation() { 126 // Cycle through all the children and pass the call 127 for (unsigned int i = 0; i < _children.size(); i++) { 128 _children[i]->endTransformation(); 129 } 130 update(); 131 } 132 update()133void TexToolItem::update() { 134 // Default: Cycle through all the children and pass the call 135 for (unsigned int i = 0; i < _children.size(); i++) { 136 _children[i]->update(); 137 } 138 } 139 140 } // namespace textool 141