Beispiel #1
0
bool MWindow::isMouseOverWindow(void)
{
	MMouse * mouse = MMouse::getInstance();
	int x = mouse->getXPosition();
	int y = mouse->getYPosition();

	if(x >= 0 && y >= 0 && x < (int)getWidth() && y < (int)getHeight())
		return true;

	return false;
}
Beispiel #2
0
MVector2 MGui2d::getMouseLocalPosition(void)
{
	MVector2 mousePosition;
	MMouse * mouse = MMouse::getInstance();

	if(m_parentWindow)
	{
		if(isScrollAffected())
		{
			mousePosition.set(
				mouse->getXPosition() - m_parentWindow->getPosition().x - m_parentWindow->getScroll().x, 
				mouse->getYPosition() - m_parentWindow->getPosition().y - m_parentWindow->getScroll().y
				);
		}
		else
		{
			mousePosition.set(
				mouse->getXPosition() - m_parentWindow->getPosition().x, 
				mouse->getYPosition() - m_parentWindow->getPosition().y
				);
		}
	}
	else{
		mousePosition.set((float)mouse->getXPosition(), (float)mouse->getYPosition());
	}

	return mousePosition;
}
Beispiel #3
0
void MWindow::sendEvents(MWinEvent * events)
{
	MKeyboard * keyboard = MKeyboard::getInstance();
	MMouse * mouse = MMouse::getInstance();

	switch(events->type)
	{
		case MWIN_EVENT_KEY_DOWN:
			keyboard->onKeyDown(events->data[0]);
			break;

		case MWIN_EVENT_KEY_UP:
			keyboard->onKeyUp(events->data[0]);
			break;

		case MWIN_EVENT_WINDOW_RESIZE:
			m_width = (unsigned int)events->data[0];
			m_height = (unsigned int)events->data[1];
			break;

		case MWIN_EVENT_WINDOW_MOVE:
			m_position[0] = events->data[0];
			m_position[1] = events->data[1];
			break;

		case MWIN_EVENT_MOUSE_BUTTON_DOWN:
			mouse->downButton(events->data[0]);
			break;

		case MWIN_EVENT_MOUSE_BUTTON_UP:
			mouse->upButton(events->data[0]);
			break;

		case MWIN_EVENT_MOUSE_WHEEL_MOVE:
			mouse->setWheelDirection(events->data[0]);
			break;

		case MWIN_EVENT_MOUSE_MOVE:
			mouse->setPosition(events->data[0], events->data[1]);
			break;
	}

	if(m_pointerEvent)
		m_pointerEvent(events);
}
Beispiel #4
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 #5
0
void MGuiEditText::onEvent(MWinEvent * windowEvent)
{
	MGuiWindow * parent = getParentWindow();

	MMouse * mouse = MMouse::getInstance();

	switch(windowEvent->type)
	{
	case MWIN_EVENT_MOUSE_WHEEL_MOVE:
	case MWIN_EVENT_MOUSE_MOVE:
		if(parent->isHighLight() && 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);
			}

			// break events
			if(parent->breakEvents())
				return;
		}
		else
		{
			setHighLight(false);
		}

		if(isPressed() && mouse->isLeftButtonPushed())
		{
			m_endSelectionId = getFont()->findPointedCharacter(
				getText(),
				getPosition(),
				getTextSize(),
				getMouseLocalPosition()
			);

			autoScrolling();
		}
		break;
	case MWIN_EVENT_MOUSE_BUTTON_DOWN:
		if(isHighLight())
		{
			if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT)
			{
				// unpress all edit text
				unsigned int i;
				unsigned int size = parent->getEditTextsNumber();
				for(i=0; i<size; i++)
					parent->getEditText(i)->setPressed(false);

				setPressed(true);

				setCharId(
					getFont()->findPointedCharacter(
						getText(),
						getPosition(),
						getTextSize(),
						getMouseLocalPosition()
					)
				);

				// start select
				setSelection(getCharId(), getCharId());
			}

			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);
			}
		}
		else
		{
			if(isPressed() && windowEvent->data[0] == MMOUSE_BUTTON_LEFT)
			{
				setPressed(false);
				sendVariable();
			}
		}
		break;
	case MWIN_EVENT_CHAR:
	case MWIN_EVENT_KEY_DOWN:
		if(isPressed())
		{
			editText(windowEvent);
			autoScrolling();
		}
		break;
	}
}
Beispiel #6
0
bool MWindow::onEvents(void)
{
	JOYCAPS	caps;
	MWindow * window = MWindow::getInstance();

	// joystick 1
	if(joyGetDevCaps(JOYSTICKID1, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR)
	{
		JOYINFOEX joyinfo;
		MJoystick * joystick = window->getJoystick1();

		joyinfo.dwSize = sizeof(JOYINFOEX);
		memset(&(joyinfo.dwFlags), 0, sizeof(JOYINFOEX) - sizeof(DWORD));
		joyinfo.dwFlags = JOY_RETURNALL;

		joyGetPosEx(JOYSTICKID1, &joyinfo);
		updateJoystick(joystick, &caps, &joyinfo);

		MWinEvent events;
		events.type = MWIN_EVENT_JOYSTICK1_UPDATE;
		window->sendEvents(&events);

		joystick->flush();
	}

	// joystick 2
	if(joyGetDevCaps(JOYSTICKID2, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR)
	{
		JOYINFOEX joyinfo;
		MJoystick * joystick = window->getJoystick2();

		joyinfo.dwSize = sizeof(JOYINFOEX);
		memset(&(joyinfo.dwFlags), 0, sizeof(JOYINFOEX) - sizeof(DWORD));
		joyinfo.dwFlags = JOY_RETURNALL;

		joyGetPosEx(JOYSTICKID2, &joyinfo);
		updateJoystick(joystick, &caps, &joyinfo);

		MWinEvent events;
		events.type = MWIN_EVENT_JOYSTICK2_UPDATE;
		window->sendEvents(&events);

		joystick->flush();
	}

	// mouse move event
	{
		POINT p;
		MWinEvent events;
		MMouse * mouse = MMouse::getInstance();

		GetCursorPos(&p);
		p.x -= window->getXPosition();
		p.y -= window->getYPosition();

		int dx = p.x - mouse->getXPosition();
		int dy = p.y - mouse->getYPosition();
		if((dx != 0) || (dy != 0))
		{
			mouse->setPosition(p.x, p.y);

			events.type = MWIN_EVENT_MOUSE_MOVE;
			events.data[0] = p.x;
			events.data[1] = p.y;
			window->sendEvents(&events);
		}
	}

	MSG msg;
	if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
		return false;
	}

	return true;
}
void MGuiSlide::onEvent(MWinEvent * windowEvent)
{
	MGuiWindow * parent = getParentWindow();

	MMouse * mouse = MMouse::getInstance();

	switch(windowEvent->type)
	{
	case MWIN_EVENT_MOUSE_WHEEL_MOVE:
	case MWIN_EVENT_MOUSE_MOVE:
		if(parent->isHighLight() && m_button.isPointInside(getMouseLocalPosition()) && (! mouse->isLeftButtonPushed()) && (! mouse->isMiddleButtonPushed()) && (! mouse->isRightButtonPushed()))
		{
			setHighLight(true);

			if(m_pointerEvent) // send 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);
			}

			// break events
			if(parent->breakEvents())
				return;
		}
		else{
			setHighLight(false);
		}

		if(isPressed())
		{
			float value = getValueFromPoint(getMouseLocalPosition());
			setValue(value);
		}
		break;
	case MWIN_EVENT_MOUSE_BUTTON_DOWN:
		if(isHighLight())
		{
			if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT){
				setPressed(true);
				m_offset = getMouseLocalPosition() - m_button.getPosition();
			}

			if(m_pointerEvent) // send 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_LEFT)
		{
			setPressed(false);
		}
		break;
	}
}
Beispiel #8
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);
}