ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

component.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/grim/costume/component.h"
00024 #include "engines/grim/colormap.h"
00025 #include "engines/grim/costume.h"
00026 
00027 namespace Grim {
00028 
00029 Component::Component(Component *p, int parentID, const char *name, tag32 t) :
00030         _visible(true), _tag(t), _parentID(parentID), _name(name),
00031         _previousCmap(nullptr), _cmap(nullptr), _cost(nullptr) {
00032 
00033     setParent(p);
00034 }
00035 
00036 Component::~Component() {
00037     if (_parent)
00038         _parent->removeChild(this);
00039 
00040     Component *child = _child;
00041     while (child) {
00042         child->_parent = nullptr;
00043         child = child->_sibling;
00044     }
00045 }
00046 
00047 void Component::setColormap(CMap *c) {
00048     if (c)
00049         _cmap = c;
00050     if (getCMap()) {
00051         resetHierCMap();
00052     }
00053 }
00054 
00055 bool Component::isVisible() {
00056     if (_visible && _parent)
00057         return _parent->isVisible();
00058     return _visible;
00059 }
00060 
00061 CMap *Component::getCMap() {
00062     if (!_cmap && _previousCmap)
00063         return _previousCmap;
00064     else if (!_cmap && _parent)
00065         return _parent->getCMap();
00066     else if (!_cmap && !_parent && _cost)
00067         return _cost->getCMap();
00068     else
00069         return _cmap;
00070 }
00071 
00072 void Component::setParent(Component *newParent) {
00073     _parent = newParent;
00074     _child = nullptr;
00075     _sibling = nullptr;
00076     if (_parent) {
00077         _sibling = _parent->_child;
00078         _parent->_child = this;
00079     }
00080 }
00081 
00082 void Component::removeChild(Component *child) {
00083     Component **childPos = &_child;
00084     while (*childPos && *childPos != child)
00085         childPos = &(*childPos)->_sibling;
00086     if (*childPos) {
00087         *childPos = child->_sibling;
00088         child->_parent = nullptr;
00089     }
00090 }
00091 
00092 void Component::resetHierCMap() {
00093     resetColormap();
00094 
00095     Component *child = _child;
00096     while (child) {
00097         child->resetHierCMap();
00098         child = child->_sibling;
00099     }
00100 }
00101 
00102 } // end of namespace Grim


Generated on Sat Mar 23 2019 05:01:24 for ResidualVM by doxygen 1.7.1
curved edge   curved edge