Beispiel #1
0
// draw
void draw(void)
{
	MMouse * mouse = MMouse::getInstance();
	MRenderingContext * render = MEngine::getInstance()->getRenderingContext();
	Maratis::getInstance()->graphicLoop();

	if(logo)
	{
		set2dMode(render);
		render->setBlendingMode(M_BLENDING_ALPHA);
		render->enableTexture();
		render->setColor4(MVector4(1.0f));
		drawLogo();
	}

	if(mouse->isLeftButtonPushed() || mouse->isMiddleButtonPushed() || (mouse->getWheelDirection() != 0))
		logo = false;

	MWindow::getInstance()->swapBuffer();
}
Beispiel #2
0
void MGuiWindow::onEvent(MWinEvent * windowEvent)
{
	MMouse * mouse = MMouse::getInstance();

	switch(windowEvent->type)
	{
	case MWIN_EVENT_WINDOW_RESIZE:
		if(m_pointerEvent) // send gui event
		{
			MGuiEvent guiEvent;
			guiEvent.type = MGUI_EVENT_RESIZE;
			m_pointerEvent(this, &guiEvent);
		}
		resizeScroll();
		break;
	case MWIN_EVENT_KEY_DOWN:
		switch(windowEvent->data[0])
		{
			case MKEY_TAB:
				{
					// editTexts
					unsigned int eSize = m_editTexts.size();
					unsigned int i;

					// select next edit text
					for(i=0; i<eSize; i++)
					{
						if(m_editTexts[i]->isSingleLine() && m_editTexts[i]->isPressed())
						{
							m_editTexts[i]->setPressed(false);
							m_editTexts[i]->sendVariable();
							unsigned int nextId = i + 1;

							if(nextId >= eSize)
								nextId = 0;

							m_editTexts[nextId]->setPressed(true);
							m_editTexts[nextId]->setCharId(0);
							m_editTexts[nextId]->setSelection(0, strlen(m_editTexts[nextId]->getText()));

							return;
						}
					}

					break;
				}
			case MKEY_DOWN:
				{
					// editTexts
					unsigned int eSize = m_editTexts.size();
					unsigned int i;

					// select next edit text
					for(i=0; i<eSize; i++)
					{
						if(m_editTexts[i]->isSingleLine() && m_editTexts[i]->isPressed())
						{
							m_editTexts[i]->setPressed(false);
							m_editTexts[i]->sendVariable();
							unsigned int nextId = i + 1;

							if(nextId >= eSize)
								nextId = 0;

							m_editTexts[nextId]->setPressed(true);
							m_editTexts[nextId]->setCharId(m_editTexts[i]->getCharId());

							return;
						}
					}

					break;
				}
			case MKEY_UP:
				{
					// editTexts
					unsigned int eSize = m_editTexts.size();
					unsigned int i;

					// select previous edit text
					for(i=0; i<eSize; i++)
					{
						if(m_editTexts[i]->isSingleLine() && m_editTexts[i]->isPressed())
						{
							m_editTexts[i]->setPressed(false);
							m_editTexts[i]->sendVariable();
							int nextId = i - 1;

							if(nextId < 0)
								nextId = eSize - 1;

							m_editTexts[nextId]->setPressed(true);
							m_editTexts[nextId]->setCharId(m_editTexts[i]->getCharId());

							return;
						}
					}

					break;
				}
		}
		break;
	case MWIN_EVENT_MOUSE_WHEEL_MOVE:
		if(isHighLight())
			moveScroll(MVector2(0, mouse->getWheelDirection() * (getTextSize() * 3)));

		break;
	case MWIN_EVENT_MOUSE_MOVE:
		if(isScrolled())
			moveScroll(MVector2((float)mouse->getXDirection(), (float)mouse->getYDirection()));

		if(isMouseInside()){
			setHighLight(true);

			if(m_pointerEvent) // send mouse move gui event
			{
				MGuiEvent guiEvent;

				guiEvent.type = MGUI_EVENT_MOUSE_MOVE;
				guiEvent.data[0] = windowEvent->data[0];
				guiEvent.data[1] = windowEvent->data[1];

				m_pointerEvent(this, &guiEvent);
			}
		}
		else{
		    setHighLight(false);
		}
		break;
	case MWIN_EVENT_MOUSE_BUTTON_DOWN:

		if(isHighLight())
		{
			if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT){
				setPressed(true);
			}

			if(windowEvent->data[0] == MMOUSE_BUTTON_MIDDLE){
				resizeScroll();
				setScrolled(true);
			}
		}
			
		if(m_pointerEvent) // send mouse button down gui event
		{
			MGuiEvent guiEvent;
				
			guiEvent.type = MGUI_EVENT_MOUSE_BUTTON_DOWN;
			guiEvent.data[0] = windowEvent->data[0];
				
			m_pointerEvent(this, &guiEvent);
		}

		break;
	case MWIN_EVENT_MOUSE_BUTTON_UP:

		if(windowEvent->data[0] == MMOUSE_BUTTON_MIDDLE)
			setScrolled(false);

		if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT)
			setPressed(false);

		if(isHighLight())
		{
			if(m_pointerEvent) // send mouse button up gui event
			{
				MGuiEvent guiEvent;

				guiEvent.type = MGUI_EVENT_MOUSE_BUTTON_UP;
				guiEvent.data[0] = windowEvent->data[0];

				m_pointerEvent(this, &guiEvent);
			}
		}

		break;
	}

	internalEvent(windowEvent);
}