Beispiel #1
0
void LevelManager::update(sf::Time _deltaTime)
{
	sf::Vector2f mousePos = sf::Vector2f(sf::Mouse::getPosition(*GetGameWindow()));
	sf::Vector2f newMousePosition = GetGameWindow()->mapPixelToCoords(sf::Vector2i(mousePos.x, mousePos.y), GetGameWindow()->getView());
	mousePos = sf::Vector2f(newMousePosition.x, newMousePosition.y);

	//cout << "X: " << mousePos.x << " Y: " << mousePos.y << endl;
	//quad[0].position = topL + diamondOffSet + screenOffset;    //TL
	//quad[1].position = topR + diamondOffSet + screenOffset;    //TR
	//quad[2].position = bottomR + diamondOffSet + screenOffset; //BR
	//quad[3].position = bottomL + diamondOffSet + screenOffset; //BL
	//sf::Vertex* quad = &_floorVertices[0];
	//for (int x = 0; x < _mapSize.x; x++)
	//{
	//	for (int y = 0; y < _mapSize.y; y++)
	//	{
	//		quad = &_floorVertices[(x + y * _mapSize.x) * 4];

	//		if(mousePos.x >= quad[0].position.x && mousePos.x <= quad[1].position.x &&
	//			mousePos.y >= quad[0].position.y && mousePos.y <= quad[2].position.y)
	//		{
	//			quad[0].color = sf::Color::Red;
	//			quad[1].color = sf::Color::Red;
	//			quad[2].color = sf::Color::Red;
	//			quad[3].color = sf::Color::Red;
	//		}
	//		else
	//		{
	//			if(quad[0].color != sf::Color::Transparent)
	//			{
	//				quad[0].color = sf::Color::White;
	//				quad[1].color = sf::Color::White;
	//				quad[2].color = sf::Color::White;
	//				quad[3].color = sf::Color::White;	
	//			}
	//		}
	//	}
	//}


}
Beispiel #2
0
    LRESULT CALLBACK GameWindow::Internal::WindowProcedure(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
            case WM_PAINT:
                if (GetGameWindow(windowHandle)->OnPaint())
                    return 0;

                break;
            case WM_KEYDOWN:
                {
                    const bool previousKeyState = (lParam & (1 << 30)) != 0;
                    if (previousKeyState == false)
                        GetGameWindow(windowHandle)->RaiseKeyDownEvent(static_cast<Key::Code>(wParam));
                }
                return 0;
            case WM_KEYUP:
                GetGameWindow(windowHandle)->RaiseKeyUpEvent(static_cast<Key::Code>(wParam));
                return 0;
            case WM_MOUSEMOVE:
                GetGameWindow(windowHandle)->RaiseMouseMoveEvent(LOWORD(lParam), HIWORD(lParam));
                return 0;
            case WM_LBUTTONDOWN:
                GetGameWindow(windowHandle)->RaiseMouseLeftButtonDownEvent(LOWORD(lParam), HIWORD(lParam));
                return 0;
            case WM_LBUTTONUP:
                GetGameWindow(windowHandle)->RaiseMouseLeftButtonUpEvent(LOWORD(lParam), HIWORD(lParam));
                return 0;
            case WM_MBUTTONDOWN:
                GetGameWindow(windowHandle)->RaiseMouseMiddleButtonDownEvent(LOWORD(lParam), HIWORD(lParam));
                return 0;
            case WM_MBUTTONUP:
                GetGameWindow(windowHandle)->RaiseMouseMiddleButtonUpEvent(LOWORD(lParam), HIWORD(lParam));
                return 0;
            case WM_RBUTTONDOWN:
                GetGameWindow(windowHandle)->RaiseMouseRightButtonDownEvent(LOWORD(lParam), HIWORD(lParam));
                return 0;
            case WM_RBUTTONUP:
                GetGameWindow(windowHandle)->RaiseMouseRightButtonUpEvent(LOWORD(lParam), HIWORD(lParam));
                return 0;
            case WM_MOUSEWHEEL:
                GetGameWindow(windowHandle)->RaiseMouseWheelEvent(GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA);
                return 0;
            case WM_HOTKEY:
                if (wParam == IDHOT_SNAPDESKTOP ||
                    wParam == IDHOT_SNAPWINDOW)
                {
                    GetGameWindow(windowHandle)->OnSnapShot();
                    return 0;
                }
                break;
            case WM_SYSKEYUP:
                if (wParam == VK_MENU)
                    return 0;
                break;
            case WM_COMMAND:
                {
                    const int commandID = HIWORD(wParam);
                    const int controlID = LOWORD(wParam);
                    void* handle = reinterpret_cast<void*>(lParam);
                    if (GetGameWindow(windowHandle)->OnCommand(commandID, controlID, handle))
                        return 0;
                }
                break;
            case WM_ENTERSIZEMOVE:
                GetGameWindow(windowHandle)->isUserSizing = true;
                return 0;
            case WM_EXITSIZEMOVE:
                {
                    RECT clientRect = { 0, 0, 0, 0 };
                    ::GetClientRect(windowHandle, &clientRect);
                    const Point2 newSize = Point2(clientRect.right - clientRect.left,
                                                  clientRect.bottom - clientRect.top);
                    GameWindow* o = GetGameWindow(windowHandle);
                    o->isUserSizing = false;
                    if (o->size != newSize)
                    {
                        o->size = newSize;
                        o->RaiseResizedEvent();
                    }
                }
                return 0;
            case WM_MOVE:
                {
                    RECT windowRect;
                    ::GetWindowRect(windowHandle, &windowRect);

                    GameWindow* o = GetGameWindow(windowHandle);
                    o->position = Point2(windowRect.left, windowRect.top);
                }
                return 0;
            case WM_SIZE:
                {
                    GameWindow* o = GetGameWindow(windowHandle);
                    if (wParam != SIZE_MINIMIZED)
                    {
                        if (wParam != SIZE_RESTORED ||
                            o->isUserSizing == false)
                        {
                            o->size = Point2(LOWORD(lParam), HIWORD(lParam));
                            o->RaiseResizedEvent();
                        }
                    }
                }
                return 0;
            case WM_DROPFILES:
                {
                    HDROP dropHandle = reinterpret_cast<HDROP>(wParam);
                    const int count = static_cast<int>(::DragQueryFile(dropHandle, 0xFFFFFFFF, nullptr, 0));

                    int maxLength = 0;
                    for (int i = 0; i < count; i++)
                        maxLength = Math::Max(maxLength, static_cast<int>(::DragQueryFile(dropHandle, i, nullptr, 0)));

                    std::vector<char> filename(maxLength);

                    GameWindow* o = GetGameWindow(windowHandle);
                    for (int i = 0; i < count; i++)
                    {
                        ::DragQueryFile(dropHandle, i, &filename[0], maxLength);
                        o->RaiseDropFileEvent(&filename[0]);
                    }

                    ::DragFinish(dropHandle);
                }
                return 0;
            case WM_CREATE:
                {
                     const CREATESTRUCT* createStruct = reinterpret_cast<const CREATESTRUCT*>(lParam);

                    GameWindow* o = reinterpret_cast<GameWindow*>(createStruct->lpCreateParams);
                    SetGameWindow(windowHandle, o);
                    o->OnCreated();

                    // RegisterHotKey(windowHandle, IDHOT_SNAPDESKTOP, 0,       VK_SNAPSHOT);
                    // RegisterHotKey(windowHandle, IDHOT_SNAPWINDOW,  MOD_ALT, VK_SNAPSHOT);
                }
                return 0;
            case WM_DESTROY:
                // UnregisterHotKey(windowHandle, IDHOT_SNAPWINDOW);
                // UnregisterHotKey(windowHandle, IDHOT_SNAPDESKTOP);

                GameWindow* o = GetGameWindow(windowHandle);
                o->OnDestroy();
                RemoveProp(windowHandle, nullptr);
                PostQuitMessage(0);
                return 0;
        }

        return DefWindowProc(windowHandle, message, wParam, lParam);
    }