forked from Kolyah35/minecraft-pe-0.6.1
77 lines
2.7 KiB
C++
Executable File
77 lines
2.7 KiB
C++
Executable File
#include "GuiElementContainer.h"
|
|
#include <algorithm>
|
|
GuiElementContainer::GuiElementContainer( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
|
: GuiElement(active, visible, x, y, width, height) {
|
|
|
|
}
|
|
|
|
GuiElementContainer::~GuiElementContainer() {
|
|
while(!children.empty()) {
|
|
GuiElement* element = children.back();
|
|
children.pop_back();
|
|
delete element;
|
|
}
|
|
}
|
|
|
|
void GuiElementContainer::render( Minecraft* minecraft, int xm, int ym ) {
|
|
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
|
(*it)->render(minecraft, xm, ym);
|
|
}
|
|
}
|
|
|
|
void GuiElementContainer::setupPositions() {
|
|
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
|
(*it)->setupPositions();
|
|
}
|
|
}
|
|
|
|
void GuiElementContainer::addChild( GuiElement* element ) {
|
|
children.push_back(element);
|
|
}
|
|
|
|
void GuiElementContainer::removeChild( GuiElement* element ) {
|
|
std::vector<GuiElement*>::iterator it = std::find(children.begin(), children.end(), element);
|
|
if(it != children.end())
|
|
children.erase(it);
|
|
}
|
|
|
|
bool GuiElementContainer::containsPointInChildren(int x, int y) const {
|
|
for (std::vector<GuiElement*>::const_iterator it = children.begin(); it != children.end(); ++it) {
|
|
GuiElement* child = *it;
|
|
if (child == NULL || !child->visible) continue;
|
|
if (child->pointInside(x, y)) return true;
|
|
const GuiElementContainer* container = dynamic_cast<const GuiElementContainer*>(child);
|
|
if (container != NULL && container->containsPointInChildren(x, y)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void GuiElementContainer::tick( Minecraft* minecraft ) {
|
|
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
|
(*it)->tick(minecraft);
|
|
}
|
|
}
|
|
|
|
void GuiElementContainer::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
|
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
|
(*it)->mouseClicked(minecraft, x, y, buttonNum);
|
|
}
|
|
}
|
|
|
|
void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
|
|
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
|
(*it)->mouseReleased(minecraft, x, y, buttonNum);
|
|
}
|
|
}
|
|
|
|
void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) {
|
|
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
|
(*it)->keyPressed(minecraft, key);
|
|
}
|
|
}
|
|
|
|
void GuiElementContainer::charPressed(Minecraft* minecraft, char key) {
|
|
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
|
(*it)->charPressed(minecraft, key);
|
|
}
|
|
} |