Example #1
0
bool viewprt::checkForWindow(s32 element, s32 x, s32 y)
{
   IGUIEnvironment* env = device->getGUIEnvironment();
   IGUIElement* root = env->getRootGUIElement();
   IGUIElement* e = root->getElementFromId(element, true);
   if (e) {
            core::rect< s32 > infos;
            infos=e->getAbsolutePosition();
            return infos.isPointInside(position2d<s32>(x,y));
      }
   return false;
}
Example #2
0
//! called if an event happened.
bool CGUIIcon::OnEvent(const SEvent& event)
{
    switch(event.EventType)
    {
		
        case EET_GUI_EVENT:
        {
			if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
				{
					if (event.GUIEvent.Caller == (IGUIElement*)this)
					//Dragging = false;
					//printf("On h, on focus EET_GUI_EVENT ");
					return true;					
				}
				else
				if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED)
				{
					/*if (Parent && ((event.GUIEvent.Caller == this) || isMyChild(event.GUIEvent.Caller)))
						Parent->bringToFront(this);*/
				}		
        }
        case EET_MOUSE_INPUT_EVENT:
        {
            switch(event.MouseInput.Event)
            {
			
                //the mouse left button is pressed
                case EMIE_LMOUSE_PRESSED_DOWN:
                {
				
					//printf("Press down\n");
                    //get the move position for dragging
                    DragStart.X = event.MouseInput.X;
                    DragStart.Y = event.MouseInput.Y;

                    //if the icon isn't in focus - put it in focus
                    if (!Environment->hasFocus(this))
                    {
						//set the focus
                        Environment->setFocus(this);
					}
					{
						//printf("Dragging\n");

                        //if the icon is moveable - dragging is enabled
                        Dragging = true*Moveable;

                        

                        if(Parent)
                        {
                            //bring the icon to the front
                            Parent->bringToFront(this);

                            //if the icon is in a slot (if the parent isn't the gui root element)
                            if(!(Parent == Environment->getRootGUIElement()))
                            {
								//printf("Parent == Environment->getRootGUIElement \n");

                                //make the icon a child of the root element (removing it from the slot)
                                Environment->getRootGUIElement()->addChild(this);
                                //the current position
                                core::rect<s32> currPos = getAbsolutePosition();
                                //move the icon the the right position (ready for dragging)
                                move(core::position2d<s32>(event.MouseInput.X - (event.MouseInput.X-currPos.UpperLeftCorner.X),
                                                           event.MouseInput.Y - (event.MouseInput.Y-currPos.UpperLeftCorner.Y)));
                            }
                        }
                    }
                    return true;
                }

                //the mouse left button is released
                case EMIE_LMOUSE_LEFT_UP:
                {
					//printf("Press up\n");

                    //the icon is no longer being draged
                    Dragging = false;

                    //the icon is no longer in focus
                    Environment->removeFocus(this);
					if(this->getParent())
						Environment->removeFocus(this->getParent());

                    //bool to check if the icon is dropped in a slot
                    bool movedToSlot = false;

                    //is the icon droped in a useable slot's rect
                    u32 size = UsableSlots->size();
                    IGUIElement *slot = 0;
                    for(u32 i = 0; i < size; i++)
                    {
                        //get the slot
                        slot = (*UsableSlots)[i];

                        if(slot)
                        {
                            //get the slot rect
                            core::rect<s32> slotRect = slot->getAbsolutePosition();

                            //if the position the icon is dropped in, is inside the rect
                            if(slotRect.isPointInside(DragStart))
                            {
                                //move the icon to the slot
                                moveToSlot(slot);
                                movedToSlot = true;
                            }
                        }

                    }

                    //if the icon is dropped outside a slot, and it's not supposed to
                    if(!movedToSlot && !CanBeOutsideSlot)
                    {
                        if(Slot)
                        {
                            //move it back to where it came from
                            moveToSlot(Slot);
                        }
                    }

                    return true;
                }
                //the mouse is moved
                case EMIE_MOUSE_MOVED:
                {
					//printf("Mouse move\n");
                    //if the icon is being dragged
                    if (Dragging)
                    {
						//printf("Draging when mouse move\n");

                        //move the icon
                        move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y));

						//update the position
                        DragStart.X = event.MouseInput.X;
                        DragStart.Y = event.MouseInput.Y;

						return true;
                    }
                    break;
                }
                //just to keep the compiler from posting warnings
                default:{}
            }//switch mouse input
            break;
        }//case mouse input event
        //just to keep the compiler from posting warnings
        default:{}
    }//switch event type

    return Parent ? Parent->OnEvent(event) : false;
}//end function OnEvent