void ButtonBase::updateInternalState(const Point& mouse_pos) { // This code is rewritten and has a slightly different behaviour // it is no longer fully "correct", as overlapping windows will not be // considered if the widget is currently captured. // On the other hand it's alot faster, so I believe it's a worthy // tradeoff bool oldstate = d_hovering; // assume not hovering d_hovering = false; // if input is captured, but not by 'this', then we never hover highlight const Window* capture_wnd = getCaptureWindow(); if (capture_wnd == 0) { System* sys = System::getSingletonPtr(); if (sys->getWindowContainingMouse() == this && isHit(mouse_pos)) { d_hovering = true; } } else if (capture_wnd == this && isHit(mouse_pos)) { d_hovering = true; } // if state has changed, trigger a re-draw if (oldstate != d_hovering) { requestRedraw(); } }
/************************************************************************* Update the internal state of the Widget *************************************************************************/ void ButtonBase::updateInternalState(const Point& mouse_pos) { bool oldstate = d_hovering; // assume not hovering d_hovering = false; // if input is captured, but not by 'this', then we never hover highlight const Window* capture_wnd = getCaptureWindow(); if ((capture_wnd == NULL) || (capture_wnd == this)) { Window* sheet = System::getSingleton().getGUISheet(); if (sheet != NULL) { // check if hovering highlight is required, which is basically ("mouse over widget" XOR "widget pushed"). if ((this == sheet->getChildAtPosition(mouse_pos)) != d_pushed) { d_hovering = true; } } } // if state has changed, trigger a re-draw if (oldstate != d_hovering) { requestRedraw(); } }
//----------------------------------------------------------------------------// bool ButtonBase::calculateCurrentHoverState(const glm::vec2& cursor_pos) { if (const Window* capture_wnd = getCaptureWindow()) return (capture_wnd == this || (capture_wnd->distributesCapturedInputs() && isAncestor(capture_wnd))) && isHit(cursor_pos); else return getGUIContext().getWindowContainingCursor() == this; }
//----------------------------------------------------------------------------// bool DragContainer::pickUp(const bool force_sticky /*= false*/) { // check if we're already picked up or if dragging is disabled. if (d_pickedUp || !d_draggingEnabled) return true; // see if we need to force sticky mode switch if (!d_stickyMode && force_sticky) setStickyModeEnabled(true); // can only pick up if sticky if (d_stickyMode) { // force immediate release of any current input capture (unless it's us) if (getCaptureWindow() && getCaptureWindow() != this) getCaptureWindow()->releaseInput(); // activate ourselves and try to capture input activate(); if (captureInput()) { // set the dragging point to the centre of the container. d_dragPoint.d_x = cegui_absdim(d_pixelSize.d_width / 2); d_dragPoint.d_y = cegui_absdim(d_pixelSize.d_height / 2); // initialise the dragging state initialiseDragging(); // get position of mouse as co-ordinates local to this window. const Vector2f localMousePos(CoordConverter::screenToWindow(*this, getGUIContext().getMouseCursor().getPosition())); doDragging(localMousePos); d_pickedUp = true; } } return d_pickedUp; }