void Event::notifyMousePressed(MouseEvent* e) {
Component* cmp = Component::getActive();
if (cmp) {
mouseFocus = cmp->getComponentAt(e->getX(), e->getY());
if (mouseFocus) mouseFocus->mousePressed(e);
}
}
/// Component.cpp //////////////////////////
/* If x, y is within this component then return it, otherwise NULL */
Component* Component::getComponentAt(int x, int y) {
return (inBounds(x, y) ? this : NULL);
}
/// Container.cpp //////////////////////////
/* Drill down through this container's children until we have found */
/* one which is at the x, y coords. If there is no children then */
/* this is returned, if this is not at x, y then NULL is returned. */
Component* Container::getComponentAt(int x, int y) {
Component* child = NULL;
if (inBounds(x, y)) {
for (unsigned int i = 0; i < components.size(); i++) {
child = components->getComponentAt(x, y);
if (child) return child;
}
return this;
}
return NULL;
}