void DragContainer::onDragPositionChanged(WindowEventArgs& e)
    {
        fireEvent(EventDragPositionChanged, e, EventNamespace);

        Window* root;

        if (0 != (root = getGUIContext().getRootWindow()))
        {
            // this hack with the 'enabled' state is so that getChildAtPosition
            // returns something useful instead of a pointer back to 'this'.
            // This hack is only acceptable because I am CrazyEddie!
            bool wasEnabled = d_enabled;
            d_enabled = false;
            // find out which child of root window has the mouse in it
            Window* eventWindow = root->getTargetChildAtPosition(
                getGUIContext().getMouseCursor().getPosition());
            d_enabled = wasEnabled;

            // use root itself if no child was hit
            if (!eventWindow)
            {
                eventWindow = root;
            }

            // if the window with the mouse is different to current drop target
            if (eventWindow != d_dropTarget)
            {
                DragDropEventArgs args(eventWindow);
                args.dragDropItem = this;
                onDragDropTargetChanged(args);
            }
        }
    }
Пример #2
0
/*************************************************************************
	Handler for mouse button release events
*************************************************************************/
void PushButton::onMouseButtonUp(MouseEventArgs& e)
{
	if ((e.button == LeftButton) && isPushed())
	{
		Window* sheet = getGUIContext().getRootWindow();

		if (sheet)
		{
			// if mouse was released over this widget
            // (use position from mouse, as e.position has been unprojected)
			if (this == sheet->getTargetChildAtPosition(
                getGUIContext().getMouseCursor().getPosition()))
			{
				// fire event
				WindowEventArgs args(this);
				onClicked(args);
			}

		}

		++e.handled;
	}

	// default handling
	ButtonBase::onMouseButtonUp(e);
}
Пример #3
0
/*************************************************************************
	Set the appropriate mouse cursor for the given window-relative pixel
	point.
*************************************************************************/
void FrameWindow::setCursorForPoint(const Vector2f& pt) const
{
	switch(getSizingBorderAtPoint(pt))
	{
	case SizingTop:
	case SizingBottom:
		getGUIContext().
            getMouseCursor().setImage(d_nsSizingCursor);
		break;

	case SizingLeft:
	case SizingRight:
		getGUIContext().
            getMouseCursor().setImage(d_ewSizingCursor);
		break;

	case SizingTopLeft:
	case SizingBottomRight:
		getGUIContext().
            getMouseCursor().setImage(d_nwseSizingCursor);
		break;

	case SizingTopRight:
	case SizingBottomLeft:
		getGUIContext().
            getMouseCursor().setImage(d_neswSizingCursor);
		break;

	default:
		getGUIContext().
            getMouseCursor().setImage(getMouseCursor());
		break;
	}

}
Пример #4
0
void TabButton::onCursorActivate(CursorInputEventArgs& e)
{
    if ((e.source == CIS_Left) && isPushed())
	{
		Window* sheet = getGUIContext().getRootWindow();

		if (sheet)
		{
            // if cursor was released over this widget
            // (use cursor position, as e.position has been unprojected)
			if (this == sheet->getTargetChildAtPosition(
                                    getGUIContext().getCursor().getPosition()))
			{
				// fire event
				WindowEventArgs args(this);
				onClicked(args);
			}
		}

		++e.handled;
    }
    else if (e.source == CIS_Middle)
    {
        d_dragging = false;
        releaseInput ();
        ++e.handled;
    }

	// default handling
    ButtonBase::onCursorActivate(e);
}
Пример #5
0
/*************************************************************************
	Handler called whenever the mouse moves while dragging a segment
*************************************************************************/
bool ListHeader::segmentDragHandler(const EventArgs&)
{
	// what we do here is monitor the position and scroll if we can when mouse is outside area.

	// get mouse position as something local
    const Vector2f localMousePos(CoordConverter::screenToWindow(*this,
        getUnprojectedPosition(getGUIContext().
            getMouseCursor().getPosition())));

	// scroll left?
	if (localMousePos.d_x < 0.0f)
	{
		if (d_segmentOffset > 0.0f)
		{
			setSegmentOffset(ceguimax(0.0f, d_segmentOffset - ScrollSpeed));
		}
	}
	// scroll right?
	else if (localMousePos.d_x >= d_pixelSize.d_width)
	{
		float maxOffset = ceguimax(0.0f, getTotalSegmentsPixelExtent() - d_pixelSize.d_width);

		// if we have not scrolled to the limit
		if (d_segmentOffset < maxOffset)
		{
			// scroll, but never beyond the limit
			setSegmentOffset(ceguimin(maxOffset, d_segmentOffset + ScrollSpeed));
		}

	}

	return true;
}
Пример #6
0
//----------------------------------------------------------------------------//
void ColourPicker::onColourRectClicked(WindowEventArgs& e)
{
    if (d_colourPickerControlsWindow)
    {
        if (d_colourPickerControlsWindow->getParent() == 0)
        {
            getGUIContext().getRootWindow()->
                addChild(d_colourPickerControlsWindow);

            d_colourPickerControlsWindow->setCallingColourPicker(this);
            d_colourPickerControlsWindow->setColours(d_selectedColour);
            d_colourPickerControlsWindow->setPreviousColour(d_selectedColour);
            d_colourPickerControlsWindow->refreshAllElements();
            fireEvent(EventOpenedPicker, e, EventNamespace);
        }
        else
        {
            if (d_colourPickerControlsWindow->getParent() != 0)
            {
                d_colourPickerControlsWindow->getParent()->
                removeChild(d_colourPickerControlsWindow);

                d_colourPickerControlsWindow->setCallingColourPicker(0);
                fireEvent(EventClosedPicker, e, EventNamespace);
            }
        }
    }
}
Пример #7
0
/*************************************************************************
	Handler for mouse move events
*************************************************************************/
void FrameWindow::onMouseMove(MouseEventArgs& e)
{
	// default processing (this is now essential as it controls event firing).
	Window::onMouseMove(e);

	// if we are not the window containing the mouse, do NOT change the cursor
	if (getGUIContext().getWindowContainingMouse() != this)
	{
		return;
	}

	if (isSizingEnabled())
	{
		Vector2f localMousePos(CoordConverter::screenToWindow(*this, e.position));

		if (d_beingSized)
		{
			SizingLocation dragEdge = getSizingBorderAtPoint(d_dragPoint);

			// calculate sizing deltas...
			float	deltaX = localMousePos.d_x - d_dragPoint.d_x;
			float	deltaY = localMousePos.d_y - d_dragPoint.d_y;

            URect new_area(d_area);
            bool top_left_sizing = false;
			// size left or right edges
			if (isLeftSizingLocation(dragEdge))
			{
				top_left_sizing |= moveLeftEdge(deltaX, new_area);
			}
			else if (isRightSizingLocation(dragEdge))
			{
				top_left_sizing |= moveRightEdge(deltaX, new_area);
			}

			// size top or bottom edges
			if (isTopSizingLocation(dragEdge))
			{
				top_left_sizing |= moveTopEdge(deltaY, new_area);
			}
			else if (isBottomSizingLocation(dragEdge))
			{
				top_left_sizing |= moveBottomEdge(deltaY, new_area);
			}

            setArea_impl(new_area.d_min, new_area.getSize(), top_left_sizing);
		}
		else
		{
			setCursorForPoint(localMousePos);
		}

	}

	// mark event as handled
	++e.handled;
}
Пример #8
0
//----------------------------------------------------------------------------//
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;
}
Пример #9
0
/*************************************************************************
	Handler for mouse button press events
*************************************************************************/
void Titlebar::onMouseButtonDown(MouseEventArgs& e)
{
	// Base class processing
	Window::onMouseButtonDown(e);

	if (e.button == LeftButton)
	{
		if ((d_parent != 0) && d_dragEnabled)
		{
			// we want all mouse inputs from now on
			if (captureInput())
			{
				// initialise the dragging state
				d_dragging = true;
				d_dragPoint = CoordConverter::screenToWindow(*this, e.position);

                // store old constraint area
                d_oldCursorArea = getGUIContext().
                    getMouseCursor().getConstraintArea();

				// setup new constraint area to be the intersection of the old area and our grand-parent's clipped inner-area
				Rectf constrainArea;

				if ((d_parent == 0) || (getParent()->getParent() == 0))
				{
                    Rectf screen(Vector2f(0, 0), getRootContainerSize());
					constrainArea = screen.getIntersection(d_oldCursorArea);
				}
				else 
				{
					constrainArea = getParent()->getParent()->getInnerRectClipper().getIntersection(d_oldCursorArea);
				}

                getGUIContext().getMouseCursor().
                    setConstraintArea(&constrainArea);
			}
		}

		++e.handled;
	}
}
Пример #10
0
/*************************************************************************
    Handler for when cursor capture is lost
*************************************************************************/
void ButtonBase::onCaptureLost(WindowEventArgs& e)
{
	// Default processing
	Window::onCaptureLost(e);

	d_pushed = false;
    getGUIContext().updateWindowContainingCursor();
	invalidate();

	// event was handled by us.
	++e.handled;
}
Пример #11
0
/*************************************************************************
	Handler for if the window loses capture of the mouse.
*************************************************************************/
void Titlebar::onCaptureLost(WindowEventArgs& e)
{
	// Base class processing
	Window::onCaptureLost(e);

	// when we lose out hold on the mouse inputs, we are no longer dragging.
	d_dragging = false;

	// restore old constraint area
	getGUIContext().
        getMouseCursor().setConstraintArea(&d_oldCursorArea);
}
Пример #12
0
//----------------------------------------------------------------------------//
void ButtonBase::setPushedState(const bool pushed)
{
    d_pushed = pushed;

    if (!pushed)
	    updateInternalState(getUnprojectedPosition(
            getGUIContext().getCursor().getPosition()));
    else
        d_hovering = true;

    invalidate();
}
Пример #13
0
/*************************************************************************
    Handler for when mouse capture is lost
*************************************************************************/
void MenuItem::onCaptureLost(WindowEventArgs& e)
{
    // Default processing
    ItemEntry::onCaptureLost(e);

    d_pushed = false;
    updateInternalState(getUnprojectedPosition(
                            getGUIContext().getMouseCursor().getPosition()));
    invalidate();

    // event was handled by us.
    ++e.handled;
}
Пример #14
0
/*************************************************************************
	Toggles the state of the window between rolled-up (shaded) and normal
	sizes.  This requires roll-up to be enabled.	
*************************************************************************/
void FrameWindow::toggleRollup(void)
{
    if (isRollupEnabled())
    {
        d_rolledup ^= true;
        
        // event notification.
        WindowEventArgs args(this);
        onRollupToggled(args);

        getGUIContext().updateWindowContainingMouse();
    }

}
Пример #15
0
/************************************************************************
    Notify item clicked
************************************************************************/
void ItemListbox::notifyItemClicked(ItemEntry* li)
{
    bool sel_state = !(li->isSelected() && d_multiSelect);
    bool skip = false;

    // multiselect enabled
    if (d_multiSelect)
    {
        uint syskeys = getGUIContext().getSystemKeys().get();
        ItemEntry* last = d_lastSelected;

        // no Control? clear others
        if (!(syskeys & Control))
        {
            clearAllSelections();
            if (!sel_state)
            {
                sel_state=true;
            }
        }

        // select range if Shift if held, and we have a 'last selection'
        if (last && (syskeys & Shift))
        {
            selectRange(getItemIndex(last),getItemIndex(li));
            skip = true;
        }
    }
    else
    {
        clearAllSelections();
    }

    if (!skip)
    {
        li->setSelected_impl(sel_state,false);
        if (sel_state)
        {
            d_lastSelected = li;
        }
        else if (d_lastSelected == li)
        {
            d_lastSelected = 0;
        }
    }

    WindowEventArgs e(this);
    onSelectionChanged(e);
}
Пример #16
0
/************************************************************************
    Handle key down event
************************************************************************/
void ItemListbox::onKeyDown(KeyEventArgs& e)
{
    ScrolledItemListBase::onKeyDown(e);

    // select all (if allowed) on Ctrl+A
    if (d_multiSelect)
    {
        uint sysKeys = getGUIContext().getSystemKeys().get();
        if (e.scancode == Key::A && (sysKeys&Control))
        {
            selectAllItems();
            ++e.handled;
        }
    }
}
Пример #17
0
/*************************************************************************
    Handler for mouse button release events
*************************************************************************/
void MenuItem::onMouseButtonUp(MouseEventArgs& e)
{
    // default processing
    ItemEntry::onMouseButtonUp(e);

    if (e.button == LeftButton)
    {
        releaseInput();

        // was the button released over this window?
        // (use mouse position, as e.position in args has been unprojected)
        if (!d_popupWasClosed &&
                getGUIContext().getRootWindow()->getTargetChildAtPosition(
                    getGUIContext().getMouseCursor().getPosition()) == this)
        {
            WindowEventArgs we(this);
            onClicked(we);
        }

        // event was handled by us.
        ++e.handled;
    }

}
Пример #18
0
//----------------------------------------------------------------------------//
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;
}
Пример #19
0
/*************************************************************************
	Handler method for when a segment is dragged & dropped.
*************************************************************************/
bool ListHeader::segmentMovedHandler(const EventArgs& e)
{
	const Vector2f mousePos(getUnprojectedPosition(
        getGUIContext().getMouseCursor().getPosition()));

	// segment must be dropped within the window
	if (isHit(mousePos))
	{
		// get mouse position as something local
		Vector2f localMousePos(CoordConverter::screenToWindow(*this, mousePos));

		// set up to allow for current offsets
		float currwidth = -d_segmentOffset;

		// calculate column where dragged segment was dropped
        uint col;
		for (col = 0; col < getColumnCount(); ++col)
		{
			currwidth += d_segments[col]->getPixelSize().d_width;

			if (localMousePos.d_x < currwidth)
			{
				// this is the column, exit loop early
				break;
			}

		}

		// find original column for dragged segment.
		ListHeaderSegment* seg = ((ListHeaderSegment*)((WindowEventArgs&)e).window);
		uint curcol = getColumnFromSegment(*seg);

		// move column
		moveColumn(curcol, col);
	}

	return true;
}
Пример #20
0
/*************************************************************************
	Handler for when
*************************************************************************/
void Combobox::onDroplistRemoved(WindowEventArgs& e)
{
    getGUIContext().updateWindowContainingMouse();
    getPushButton()->setPushedState(false);
	fireEvent(EventDropListRemoved, e, EventNamespace);
}
Пример #21
0
 void DragContainer::updateActiveMouseCursor(void) const
 {
     getGUIContext().getMouseCursor().
         setImage(d_dragging ? getDragCursorImage() : getMouseCursor());
 }