// Handles mouse->Object related type thingies void ObjectManager::CheckMouseEvent(Event* myEvent,EventType type) { // Convert to mouse event. MouseEvent* myMouseEvent = reinterpret_cast(myEvent); std::vector vobjects = GetVisualObjects(); // Loop through objects. for (int oi = 0 ; oi < vobjects.size() ; oi++) { // Check if any objects are currently being dragged. if (vobjects[oi]->IsDragging()) { // Is the mouse still dragging? If so, keep the drag events comming, otherwise knock it off. if (type == EVT_DRAG) { vobjects[oi]->OnDrag(myMouseEvent); } else { if (type == EVT_MOUSE_UP_LEFT) vobjects[oi]->OnStopDrag(); } } // Check if mouse is over any of our objects. If so, pass event to object. int x1 = vobjects[oi]->GetPosition().GetX(); int y1 = vobjects[oi]->GetPosition().GetY(); int x2 = x1 + vobjects[oi]->GetWidth(); int y2 = y1 + vobjects[oi]->GetHeight(); // check if the mouse position falls within these rectuangular coordinates. if ((myMouseEvent->GetPosition().GetX() > x1)&& (myMouseEvent->GetPosition().GetX() < x2)&& (myMouseEvent->GetPosition().GetY() > y1)&& (myMouseEvent->GetPosition().GetY() < y2)) { // Mouse is over object, so pass the mouseover event to that object. switch(type) { case EVT_MOUSE_OVER: vobjects[oi]->OnMouseOver(myMouseEvent);break; case EVT_MOUSE_DOWN_LEFT: vobjects[oi]->OnMouseDown(myMouseEvent);break; case EVT_MOUSE_DOWN_RIGHT: vobjects[oi]->OnMouseDown(myMouseEvent);break; case EVT_MOUSE_UP_LEFT: vobjects[oi]->OnMouseUp(myMouseEvent);break; case EVT_MOUSE_UP_RIGHT: vobjects[oi]->OnMouseUp(myMouseEvent);break; } } } }