/* Function: GetMouseClick * Usage: loc = GetMouseClick(); * ------------------------------ * Waits for the user to click somewhere on the graphics window * and returns the coordinate of where the click took place. */ coordT GetMouseClick() { coordT where; WaitForMouseDown(); WaitForMouseUp(); where.x = GetMouseX(); where.y = GetMouseY(); return where; }
void PathfinderEventLoop() { while (true) { WaitForMouseDown(); int downButtonIndex = FindButtonIndex(GetMouseX(), GetMouseY()); if (downButtonIndex != -1) { buttons[downButtonIndex].highlighted = true; DrawButton(buttons[downButtonIndex]); UpdateDisplay(); } bool isDown = true; while (isDown) { isDown = MouseButtonIsDown(); int index = FindButtonIndex(GetMouseX(), GetMouseY()); if (index != downButtonIndex) { if (downButtonIndex != -1) { buttons[downButtonIndex].highlighted = false; DrawButton(buttons[downButtonIndex]); } if (index != -1 && isDown) { buttons[index].highlighted = true; DrawButton(buttons[index]); } downButtonIndex = index; UpdateDisplay(); } } if (downButtonIndex != -1) { buttons[downButtonIndex].highlighted = false; DrawButton(buttons[downButtonIndex]); UpdateDisplay(); buttons[downButtonIndex].callback->apply(); } else { pointT pt; pt.x = int(GetMouseX()); pt.y = int(GetMouseY()); if (pt.y < WINDOW_HEIGHT && clickHook != NULL) { clickHook->apply(pt); } } } }