示例#1
0
void Game::Input(bool isAI)
{
    int xPos, yPos;
    switch (event->type)
    {
        case SDL_QUIT:
            quitGame = true;
            break;
        case SDL_MOUSEBUTTONDOWN:
            if (isAI) break;
            if (currentGameState != GameState::END)
            {
                SDL_GetMouseState(&xPos, &yPos);
                OnMouseButtonDown(xPos, yPos);
            }
            break;
        case SDL_MOUSEBUTTONUP:
            if (isAI) break;
            if (currentGameState != GameState::END)
            {
                SDL_GetMouseState(&xPos, &yPos);
                OnMouseButtonUp(xPos, yPos);
            }
            break;
        default:
            break;
    }
}
示例#2
0
文件: Module.cpp 项目: CYBORUS/SDL2TK
    void Module::OnEvent(const SDL_Event& event)
    {
        switch (event.type)
        {
            case SDL_WINDOWEVENT:
            {
                switch (event.window.event)
                {
                    case SDL_WINDOWEVENT_ENTER: OnMouseFocus(); break;
                    case SDL_WINDOWEVENT_LEAVE: OnMouseBlur(); break;
                    case SDL_WINDOWEVENT_FOCUS_GAINED: OnInputFocus(); break;
                    case SDL_WINDOWEVENT_FOCUS_LOST: OnInputBlur(); break;
                    case SDL_WINDOWEVENT_RESTORED: OnRestore(); break;
                    case SDL_WINDOWEVENT_MINIMIZED: OnMinimize(); break;
                    case SDL_WINDOWEVENT_MAXIMIZED: OnMaximize(); break;
                    case SDL_WINDOWEVENT_EXPOSED: OnExpose(); break;

                    case SDL_WINDOWEVENT_SIZE_CHANGED:
                        OnResize(event.window.data1, event.window.data2);
                        break;

                    default: break;
                }

                break;
            }

            case SDL_KEYDOWN:
                if (event.key.repeat)
                    OnKeyRepeat(event.key.keysym);
                else
                    OnKeyDown(event.key.keysym);
                break;

            case SDL_KEYUP: OnKeyUp(event.key.keysym); break;
            case SDL_MOUSEMOTION: OnMouseMove(event.motion); break;
            case SDL_MOUSEWHEEL: OnMouseWheel(event.wheel); break;
            case SDL_MOUSEBUTTONDOWN: OnMouseButtonDown(event.button); break;
            case SDL_MOUSEBUTTONUP: OnMouseButtonUp(event.button); break;

            case SDL_JOYAXISMOTION: OnJoyAxis(event.jaxis); break;
            case SDL_JOYBALLMOTION: OnJoyBall(event.jball); break;
            case SDL_JOYHATMOTION: OnJoyHat(event.jhat); break;
            case SDL_JOYBUTTONDOWN: OnJoyButtonDown(event.jbutton); break;
            case SDL_JOYBUTTONUP: OnJoyButtonUp(event.jbutton); break;
            case SDL_QUIT: OnExit(); break;
            case SDL_SYSWMEVENT: break;

            default: OnUser(event.user);break;
        }
    }
示例#3
0
	void osgSDLViewer::handleEvents(SDL_Event& event)
	{
		switch(event.type) 
        {
        	case SDL_USEREVENT:
           	//handleUserEvents(&event);
            	break;
                
           	case SDL_KEYDOWN:
             	// Quit when user presses Esc key.
              	switch(event.key.keysym.sym)
				{
					case SDLK_ESCAPE:
						mDone = true;
						break;

					default:
						OnKeyDown( 
							event.key.keysym.sym,
							event.motion.x, 
							event.motion.y, 
							event.motion.xrel, 
							event.motion.yrel);
						break;
				}
                break;
                
			case SDL_KEYUP:
				OnKeyUp( event.key.keysym.sym );
				break;
  
			case SDL_MOUSEMOTION:
				OnMouseMoved(
				event.button.button, 
				event.motion.x, 
				event.motion.y, 
				event.motion.xrel, 
				event.motion.yrel);
				break;
 
			case SDL_MOUSEBUTTONUP:
				OnMouseButtonUp(
					event.button.button, 
					event.motion.x, 
					event.motion.y, 
					event.motion.xrel, 
					event.motion.yrel);
				break;
 
			case SDL_MOUSEBUTTONDOWN:
				OnMouseButtonDown(
					event.button.button, 
					event.motion.x, 
					event.motion.y, 
					event.motion.xrel, 
					event.motion.yrel);
				break;
 
			case SDL_ACTIVEEVENT:
				if ( event.active.state & SDL_APPACTIVE ) {
					if ( event.active.gain ) 
					{
						mMinimized = false;
						OnWindowActive();
					} 
					else 
					{
						mMinimized = true;
						OnWindowInactive();
					}
				}
				break;
                	
			case SDL_VIDEORESIZE:
				{
					resize(event.resize.w, event.resize.h);
				}
				break;
            
            case SDL_QUIT:
                mDone = true;
                break;
                
            default:
                break;
        }   // End switch              
	}
示例#4
0
/**
 * See SWidget::OnMouseButtonDoubleClick.
 *
 * @param MyGeometry The Geometry of the widget receiving the event
 * @param MouseEvent Information about the input event
 *
 * @return Whether the event was handled along with possible requests for the system to take action.
 */
FReply SCheckBox::OnMouseButtonDoubleClick( const FGeometry& InMyGeometry, const FPointerEvent& InMouseEvent )
{
	return OnMouseButtonDown( InMyGeometry, InMouseEvent );
}
FReply SDetailCategoryTableRow::OnMouseButtonDoubleClick( const FGeometry& InMyGeometry, const FPointerEvent& InMouseEvent )
{
	return OnMouseButtonDown(InMyGeometry, InMouseEvent);
}
示例#6
0
FReply UUserWidget::NativeOnMouseButtonDown( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent )
{
	return OnMouseButtonDown( InGeometry, InMouseEvent ).NativeReply;
}
示例#7
0
bool CView::HandleMessage(CMessage* pMessage)
{
	bool bHandled = false;

	if (pMessage)
	{
		switch(pMessage->MessageType())
		{
		case CMessage::APP_PAINT :
			if (pMessage->Destination() == this || pMessage->Destination() == 0)
			{
				vid_plugin->lock();
				SDL_Surface* pFloatingSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, m_pScreenSurface->w,
m_pScreenSurface->h, CApplication::Instance()->GetBitsPerPixel(), 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
				PaintToSurface(*m_pScreenSurface, *pFloatingSurface, CPoint(0, 0));
				// judb use entire application SDL surface (otherwise strange clipping effects occur
				// when moving frames, also clipping of listboxes.)
//				SDL_Rect SourceRect = CRect(m_WindowRect.SizeRect()).SDLRect();
				SDL_Rect SourceRect = CRect(0, 0, m_pScreenSurface->w, m_pScreenSurface->h).SDLRect();
//				SDL_Rect DestRect = CRect(m_WindowRect.SizeRect()).SDLRect();
				SDL_Rect DestRect = CRect(0, 0, m_pScreenSurface->w, m_pScreenSurface->h).SDLRect();
				SDL_BlitSurface(pFloatingSurface, &SourceRect, m_pScreenSurface, &DestRect);
				SDL_FreeSurface(pFloatingSurface);
				//SDL_UpdateRect(m_pScreenSurface, 0, 0, 0, 0);
				vid_plugin->unlock();
				vid_plugin->flip();

				bHandled = true;
			}
			break;
		case CMessage::APP_DESTROY_FRAME:
			if (pMessage->Destination() == this || pMessage->Destination() == 0)
			{
				CFrame* pFrame = dynamic_cast<CFrame*>(const_cast<CMessageClient*>(pMessage->Source()));
				if (pFrame)
				{
					pFrame->SetModal(false);
          pFrame->SetNewParent(0);
					CMessageServer::Instance().QueueMessage(new CMessage(CMessage::APP_PAINT, 0, this));
					delete pFrame;
				}
				bHandled = true;
			}
			break;
		case CMessage::CTRL_RESIZE:
		{
			TPointMessage* pResizeMessage = dynamic_cast<TPointMessage*>(pMessage);
			if (pResizeMessage && pResizeMessage->Source() == CApplication::Instance())
			{
				CWindow::SetWindowRect(CRect(m_WindowRect.TopLeft(), m_WindowRect.TopLeft() + pResizeMessage->Value()));
				Uint32 iFlags = SDL_SWSURFACE | SDL_ANYFORMAT;
				if(m_bResizable)
				{
					iFlags |= SDL_RESIZABLE;
				}

				m_ClientRect = CRect(m_ClientRect.Left(), m_ClientRect.Top(), m_WindowRect.Width(), m_WindowRect.Height());
				m_ClientRect.ClipTo(m_WindowRect.SizeRect());

				m_pScreenSurface = SDL_SetVideoMode(m_WindowRect.Width(), m_WindowRect.Height(), DEFAULT_BPP, iFlags);
				if (m_pScreenSurface == NULL)
					throw( Wg_Ex_SDL(std::string("Could not set video mode : ") + SDL_GetError()) );

				bHandled = true;
			}
			break;
		}
		case CMessage::MOUSE_BUTTONDOWN:
		{
			CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);
			if (pMouseMessage && m_WindowRect.HitTest(pMouseMessage->Point) == CRect::RELPOS_INSIDE)
			{
				if (!m_pFloatingWindow || !m_pFloatingWindow->OnMouseButtonDown(pMouseMessage->Point, pMouseMessage->Button))
				{
					if (pMouseMessage->Destination() == 0)
					{
						OnMouseButtonDown(pMouseMessage->Point, pMouseMessage->Button);
					}
					else if (dynamic_cast<const CWindow*>(pMouseMessage->Destination()))
					{
						const_cast<CWindow*>(static_cast<const CWindow*>(pMouseMessage->Destination()))->
							OnMouseButtonDown(pMouseMessage->Point, pMouseMessage->Button);
					}
				}
			}
			break;
		}
		case CMessage::MOUSE_BUTTONUP:
		{
			CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);
			if (pMouseMessage && m_WindowRect.HitTest(pMouseMessage->Point) == CRect::RELPOS_INSIDE)
			{
				if (!m_pFloatingWindow || !m_pFloatingWindow->OnMouseButtonUp(pMouseMessage->Point, pMouseMessage->Button))
				{
					if (pMouseMessage->Destination() == 0)
					{
						OnMouseButtonUp(pMouseMessage->Point, pMouseMessage->Button);
					}
					else if (dynamic_cast<const CWindow*>(pMouseMessage->Destination()))
					{
						const_cast<CWindow*>(static_cast<const CWindow*>(pMouseMessage->Destination()))->
							OnMouseButtonUp(pMouseMessage->Point, pMouseMessage->Button);
					}
				}
			}
			break;
		}
		default :
			bHandled = CWindow::HandleMessage(pMessage);
			break;
		}
	}

	return bHandled;
}
示例#8
0
bool ListPop::OnList(ListPop *list, int index, gedString &text, int listId)
{
	if(text == LIST_SEPARATOR) return true;

	int realFps = GameControl::Get()->getRealFrameRate();
	if(realFps <= 0) realFps = 1;

	int interval = (int)(1000.0/realFps);
	selectedText.clear();

	if(text[0] == '+')
	{
		//Expand clone names
		PopulateCloneList(&text.c_str()[2]);
		OnMouseButtonDown(GameControl::Get()->getMouseX(), GameControl::Get()->getMouseY(), 255);
	}
	else if(text == MORE_ITENS)
	{
		pCurrentStack->PushFront(firstListItem);
		ResetWork();
		AddTextWork(LESS_ITENS);
		PopulateWorkList(true);
		
		
		OnMouseButtonDown(xMouse, yMouse, 255);
	}
	else if(text == LESS_ITENS)
	{
		firstListItem = pCurrentStack->Front();
		pCurrentStack->PopFront();			
		
		ResetWork();
		if(pCurrentStack->size()) AddTextWork(LESS_ITENS);
		
		PopulateWorkList(false);
		
		
		OnMouseButtonDown(xMouse, yMouse, 255);
	}
	else
	{
		if(!bButtonText) SetListText(text);
		selectedText = text;

		if(listId < 0) listId = listpopId;
		if(index < 0) 
		{
			//Get index from text
			UseMainList();
			
			for(int i = 0; i < pCurrentList->Count(); i++)
			{
				if(text == (*pCurrentList)[i].text)
				{
					index = i;
					break;
				}
			}
			
			if(index >= 0) this->index = index;
		}
		else
		{
			if(firstListItem > 0) index = firstListItem + index - 1; //Work index to all index
			UseMainList();

			//Put after UseMainList() to get the
			//correct clone in the panel of getclone function
			this->index = index;
		}

		
		firstListItem = -1;
		getParent()->OnList(this, index, text, listId);
	}	

	return true;
}