Activity *MouseFocusTracker::Click(uint /*button*/, uint /*count*/, int x, int y) // ---------------------------------------------------------------------------- // Track focus when mouse click // ---------------------------------------------------------------------------- { uint current = ObjectAtPoint(x, widget->height() - y); IFTRACE(widgets) std::cerr << "MouseFocusTracker::Click Focus " << current << std::endl; if (current != previous) { if (current > 0) { // Forward 'focus-in' to current item widget->focusId = current; } else if (previous > 0) { // Forward 'focus-out' to previous item widget->focusId = 0; } widget->updateGL(); } previous = current; return next; }
void ObjectView::MouseDown(BPoint point) { GLObject* object = NULL; BMessage *msg = Window()->CurrentMessage(); uint32 buttons = msg->FindInt32("buttons"); object = reinterpret_cast<GLObject*>(fObjects.ItemAt(ObjectAtPoint(point))); if (object != NULL){ if (buttons == B_PRIMARY_MOUSE_BUTTON || buttons == B_SECONDARY_MOUSE_BUTTON) { fTrackingInfo.pickedObject = object; fTrackingInfo.buttons = buttons; fTrackingInfo.isTracking = true; fTrackingInfo.lastX = point.x; fTrackingInfo.lastY = point.y; fTrackingInfo.lastDx = 0.0f; fTrackingInfo.lastDy = 0.0f; fTrackingInfo.pickedObject->Spin(0.0f, 0.0f); SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); BCursor grabbingCursor(B_CURSOR_ID_GRABBING); SetViewCursor(&grabbingCursor); } else { ConvertToScreen(&point); object->MenuInvoked(point); } } }
void ObjectView::MouseMoved(BPoint point, uint32 transit, const BMessage *msg) { if (fTrackingInfo.isTracking && fTrackingInfo.pickedObject != NULL) { float dx = point.x - fTrackingInfo.lastX; float dy = point.y - fTrackingInfo.lastY; fTrackingInfo.lastX = point.x; fTrackingInfo.lastY = point.y; if (fTrackingInfo.buttons == B_PRIMARY_MOUSE_BUTTON) { fTrackingInfo.pickedObject->Spin(0.0f, 0.0f); fTrackingInfo.pickedObject->RotateWorldSpace(dx,dy); fTrackingInfo.lastDx = dx; fTrackingInfo.lastDy = dy; setEvent(drawEvent); } else if (fTrackingInfo.buttons == B_SECONDARY_MOUSE_BUTTON) { float xinc = (dx * 2 * displayScale / Bounds().Width()); float yinc = (-dy * 2 * displayScale / Bounds().Height()); float zinc = 0; if (fPersp) { zinc = yinc * (fTrackingInfo.pickedObject->z / displayScale); xinc *= -(fTrackingInfo.pickedObject->z * 4 / zRatio); yinc *= -(fTrackingInfo.pickedObject->z * 4 / zRatio); } fTrackingInfo.pickedObject->x += xinc; if (modifiers() & B_SHIFT_KEY) fTrackingInfo.pickedObject->z += zinc; else fTrackingInfo.pickedObject->y += yinc; fForceRedraw = true; setEvent(drawEvent); } } else { void* object = fObjects.ItemAt(ObjectAtPoint(point)); BCursor cursor(object != NULL ? B_CURSOR_ID_GRAB : B_CURSOR_ID_SYSTEM_DEFAULT); SetViewCursor(&cursor); } }
Activity *MouseFocusTracker::MouseMove(int x, int y, bool active) // ---------------------------------------------------------------------------- // Track focus as mouse moves // ---------------------------------------------------------------------------- { if (active) return next; IFTRACE(widgets) std::cerr << "MouseFocusTracker::MouseMove " << x << ", " << y << std::endl; uint current = ObjectAtPoint(x, widget->height() - y); widget->shapeAction("mouseover", current, x, y); previous = current; return next; }