Пример #1
0
/**
 * Removes a thing from the container.
 * @param child The thing to be contained.
 */
void Container::removeChild(Contained* child) {
	DEBUG_M("Entering function removeChild...");
	if(!child) {
		return;
	}

	DEBUG_H("\tRemoving object from container object vector.");
	ChildrenIterator found = find(getChildBegin(), getChildEnd(), child);
	//while((found = find(getChildBegin(), getChildEnd(), child)) != getChildEnd()) {
		if(found != getChildEnd()) {
			//Object* object = dynamic_cast<Object*>(*found);

			if(*found && ((*found) == child)) {
				//DEBUG_H("\t\tFound '%s'... Removing...", object->getTag().c_str());
				children_.erase(found);
			}
		}
	//}

	DEBUG_H("\tRemoving object from container tag list.");
	ChildrenTagIterator iter = tags_.begin();
	while(iter != tags_.end()) {
		Contained* contained = dynamic_cast<Object*>(iter->second);
		if(contained  && contained == child) {
			//DEBUG_H("\t\tFound '%s'... Removing...", object->getTag().c_str());
			tags_.erase(iter);
			iter = tags_.begin();
		} else {
			iter++;
		}
	}

	DEBUG_H("\tExiting function...");
	#warning ['TODO']: This...
}
Пример #2
0
/**
 * Adds a thing to the container.
 * @param child The thing to be contained.
 */
void Container::addChild(Contained* child) {
	DEBUG_M("Entering function addChild...");
	if(!child) {
		DEBUG_H("\tNo child...");
		return;
	}

	// Stop adding the child more than once
	ChildrenIterator found = find(getChildBegin(), getChildEnd(), child);
	if(found != getChildEnd()) {
		DEBUG_H("\tChild alread in list...");
		return;
	}

	DEBUG_H("Child adding to list...");
	child->setParent(this);
	children_.push_back(child);

	//DEBUG_H("Child adding to list...");
	Tagged* tagged = dynamic_cast<Tagged*>(child);
	if(!tagged) {
		return;
	}

	tags_.insert(ChildrenTagPair(tagged->getTag(), tagged));
}
Пример #3
0
/**
 * Adds a thing to the container.
 * @param child The thing to be contained.
 */
void Container::add(Contained* child) {
   if(!child) {
      return;
   }

   // Stop adding the child more than once
   ChildrenIterator found = find(getChildBegin(), getChildEnd(), child);
   if(found != getChildEnd()) {
      return;
   }

   child->setParent(this);
   children_.push_back(child);
}
Пример #4
0
/**
 * Removes a thing from the container.
 * @param child The thing to be contained.
 */
void Container::remove(Contained* child) {
   //DEBUG_M("Entering function remove...");
   if(!child) {
      return;
   }

   //DEBUG_H("\tRemoving object from container object vector.");
   ChildrenIterator found = find(getChildBegin(), getChildEnd(), child);

   if(found != getChildEnd()) {
      if(*found && ((*found) == child)) {
         children_.erase(found);
      }
   }
}
Пример #5
0
	void FlowLayout::resizeToContents()
	{
		int maxX = 0;
		int maxY = 0;
    int minX = 0;
    int minY = 0;

    WidgetArray::const_iterator it = getChildBegin();
    if (it != getChildEnd())
    {
      minX = (*it)->getLocation().getX();
      minY = (*it)->getLocation().getY();
    }

		for(WidgetArray::const_iterator it = getChildBegin();
			it != getChildEnd(); ++it)
		{
			int tempX = (*it)->getLocation().getX() + (*it)->getWidth();
			if(tempX > maxX)
			{
				maxX = tempX;
			}

      tempX = (*it)->getLocation().getX();
      if (tempX < minX)
        minX = tempX;

			int tempY = (*it)->getLocation().getY() + (*it)->getHeight();
			if(tempY > maxY)
			{
				maxY = tempY;
			}
      
      tempY = (*it)->getLocation().getY();
      if (tempY < minY)
        minY = tempY;
		}

    for(WidgetArray::const_iterator it = getChildBegin();
		  	it != getChildEnd(); ++it)
    {
      (*it)->setLocation((*it)->getLocation().getX() - minX,
                         (*it)->getLocation().getY() - minY);
    }

		setSize(getMargin(SIDE_LEFT) + getMargin(SIDE_RIGHT) + maxX - minX,
			getMargin(SIDE_TOP) + getMargin(SIDE_BOTTOM) + maxY - minY);
	}
Пример #6
0
	HScrollBar::~HScrollBar(void)
	{
		for(std::vector<HScrollBarListener*>::iterator it = 
			hScrollListeners.begin();
			it != hScrollListeners.end(); ++it)
		{
			if((*it))
				(*it)->death(this);
		}

		for(WidgetArray::iterator it = getPrivateChildBegin(); it != 
			getPrivateChildEnd(); ++it)
		{
			(*it)->removeMouseListener(this);
		}
		for(WidgetArray::iterator it = getChildBegin(); it != 
			getChildEnd(); ++it)
		{
			(*it)->removeMouseListener(this);
		}

		if(isMaintainingThumb)
			delete pChildThumb;

		if(isMaintainingLeftArrow)
			delete pChildLeftArrow;

		if(isMaintainingRightArrow)
			delete pChildRightArrow;
	}
Пример #7
0
DFFFrame::~DFFFrame()
{
	ChildIterator it;

	for (it = getChildBegin() ; it != getChildEnd() ; it++) {
		(*it)->reparent(NULL);
		delete *it;
	}

	delete modelMatrix;

	if (ltm)
		delete ltm;
}
Пример #8
0
Object* Container::getNearestObjectByTag(Location& location, const string tag) {
	Object* closest = NULL;
	for(ChildrenIterator iter = getChildBegin(); iter != getChildEnd(); iter++) {
		Object* object = dynamic_cast<Object*>(*iter);
		if(!object) {
			continue;
		}

		if(tag == "" || tag ==object->getTag()) {
			if(closest == NULL) {
				closest = object;
			}

			if(object->getDistanceTo(location) < closest->getDistanceTo(location)) {
				closest = object;
			}
		}
	}
	return closest;
}
Пример #9
0
	void FlowLayout::layoutChildren()
	{
			int curX = 0;
			int curY = 0;

			int highestWidget = 0;
			int numWidgets = 0;
			int rlOffset = 0;
			int btOffset = 0;
			int numRows = 1;
			int numOnRow = 0;

			std::vector<Widget*> curRow;
			Widget* firstWidget = NULL;

			int lowestPoint = 0;
			for(WidgetArray::iterator it = getChildBegin(); 
				it != getChildEnd(); ++it)
			{
				if(!(*it)->isVisible() && isFilteringVisibility())
				{
					continue;
				}

				if(!firstWidget)
				{
					firstWidget = (*it);
				}

				if(isResizingRowToWidth())
				{
					(*it)->setSize(getInnerWidth(),(*it)->getHeight());
				}

				if((maxOnRow > 0 && numOnRow >= maxOnRow) || isResizingRowToWidth() ||
					(curX + (*it)->getWidth() > getInnerWidth() && numWidgets > 0 && !singleRow))
				{
					numRows++;
					numOnRow = 0;
					curX = 0;
					curY += highestWidget + getVerticalSpacing();
					highestWidget = 0;

					if(center && !curRow.empty())
					{
						int x1 = curRow[0]->getLocation().getX();
						int x2 = curRow.back()->getLocation().getX() +
							curRow.back()->getWidth();

						int w = x2 - x1;
						int centerOffset = (getInnerWidth() - w) / 2;

						for(size_t i = 0; i < curRow.size(); ++i)
						{
							curRow[i]->setLocation(
								curRow[i]->getLocation().getX() + centerOffset,
								curRow[i]->getLocation().getY());
						}
					}

					curRow.clear();
				}
				numOnRow++;

				if(!topToBottom)
				{
					btOffset = getInnerHeight() - (*it)->getHeight() - (curY + curY);
				}
				if(!leftToRight && !center)
				{
					rlOffset = getInnerWidth() - (*it)->getWidth() - (curX + curX);
				}
				(*it)->setLocation(curX + rlOffset,curY + btOffset);
				curX += (*it)->getWidth() + getHorizontalSpacing();
				numWidgets++;

				if((*it)->getHeight() > highestWidget)
				{
					highestWidget = (*it)->getHeight();
				}

				curRow.push_back((*it));

				//find the content height
				int l = (*it)->getLocation().getY() + (*it)->getHeight();
				if(l > lowestPoint)
				{
					lowestPoint = l;
				}
		}

			//code duplication, I know :(
			if(center && !curRow.empty())
			{
				if(alignLastRow && numRows > 1 && firstWidget)
				{
					int x1 = curRow[0]->getLocation().getX();
					int x2 = firstWidget->getLocation().getX();
					int diff = x2 - x1;

					for(size_t i = 0; i < curRow.size(); ++i)
					{
						curRow[i]->setLocation(
							curRow[i]->getLocation().getX() + diff,
							curRow[i]->getLocation().getY());
					}
				}

				else
				{
					int x1 = curRow[0]->getLocation().getX();
					int x2 = curRow.back()->getLocation().getX() +
						curRow.back()->getWidth();

					int w = x2 - x1;
					int centerOffset = (getInnerWidth() - w) / 2;

					for(size_t i = 0; i < curRow.size(); ++i)
					{
						curRow[i]->setLocation(
							curRow[i]->getLocation().getX() + centerOffset,
							curRow[i]->getLocation().getY());
					}
				}
			}

			//set content height
			contentHSz = lowestPoint + getMargin(SIDE_TOP) + getMargin(SIDE_BOTTOM);
	}
Пример #10
0
/**
 * Sets the size of the area.
 * @param width The width.
 * @param height The heigh.
 */
void Area::setSize(int width, int height) {
    DEBUG_M("Entering function...");

    int old_width = width_;
    int old_height = height_;

#warning ['TODO']: Decide when tiles are unloaded
    DEBUG_H("\tUnloading dropped tiles...");
    // Unload any tiles that are dropped
    if(width < old_width) {
        DEBUG_H("\tWidth is less than old width, scrubbing lost tiles...");
        for(int y = 0; y < height; y++) {
            for(int x = old_width; x < width; x++) {
                delete getTile(x, y);
                setSolid(x, y, false);
            }
        }
    }
    if(height < old_height) {
        DEBUG_H("\tHeight is less than old width, scrubbing lost tiles...");
        for(int y = old_height; y < height; y++) {
            for(int x = 0; x < old_width; x++) {
                delete getTile(x, y);
                setSolid(x, y, false);
            }
        }
    }

    width_ = width;
    height_ = height;

    DEBUG_H("\tRealPosition tile space...");
    tiles_ = (Tile***)regrowArray_((void***)tiles_, old_width, old_height, width, height);
    DEBUG_H("\tRealPosition blocker space...");
    walkblockers_ = (RigidBody***)regrowArray_((void***)walkblockers_, old_width, old_height, width, height);
    DEBUG_H("\tAllocated...");

    // If we are freeing the Area
    if(!width || !height) {
        return;
    }

    if(!tiles_) {
        ERROR("Failed to allocate memory for tile map.");
        return;
    }

#warning ['TODO']: This function should be split up some more, also shouldn't need to NULL tiles befoure setting them.
    // Set new tiles to default
    if(width > old_width) {
        DEBUG_H("\tWidth is > than old width, making new tiles...");
        for(int y = 0; y < height; y++) {
            for(int x = old_width; x < width; x++) {
                DEBUG_H("\t\tsetting %dx%d...", x, y);
                tiles_[x][y] = NULL;
                walkblockers_[x][y] = NULL;
            }
        }
    }
    if(height > old_height) {
        DEBUG_H("\theight is > than old height, making new tiles...");
        for(int y = old_height; y < height; y++) {
            for(int x = 0; x < width; x++) {
                DEBUG_H("\t\tsetting %dx%d...", x, y);
                tiles_[x][y] = NULL;
                walkblockers_[x][y] = NULL;
            }
        }
    }

    float x_offset = (old_width - width_) * (TILEWIDTH / 2.0f);
    float z_offset = (old_height - height_) * (TILEWIDTH / 2.0f);
    for(ChildrenIterator iter = getChildBegin(); iter != getChildEnd(); iter++) {
        Object* object = dynamic_cast<Object*>(*iter);
        if(!object) {
            continue;
        }
        object->setX(object->getX() - x_offset);
        object->setZ(object->getZ() - z_offset);
    }

    DEBUG_H("\tFunction finished, area now %d, %d...", getWidth(), getHeight());
}