Пример #1
0
// Show a message-overlay on screen
void MenuSystem::ShowMessage(Message *message)
{
	// Init overlay text-item and box
	OverlayInit(message->title, message->message);

	// Some helpful variables for setting up button
	Vec2 wSize, bSize;
	wSize = Vec2(Context::getWindowWidth(), Context::getWindowHeight());
	bSize = OVERLAY_BUTTONSIZE;

	// Setup "Okay"-button
	overlayButton1->SetSize(bSize);
	overlayButton1->SetText("Okay", MenuItem::CENTER);
	overlayButton1->SetPosition(Vec2((wSize.x - bSize.x) / 2, (wSize.y + overlayBox->GetSize().y) / 2 - bSize.y - 25));
	this->onOverlayButton1 = message->onButton1;

	// Hide the other button
	overlayButton2->active = false;
	overlayButton2->visible = false;

	// Render the overlay
	RenderOverlay();

	// Render the overlay-items rendertarget
	RenderOverlayItems();
}
Пример #2
0
// Show a question on screen, with two options
void MenuSystem::ShowQuestion(Message *message)
{
	// Init overlay text-item and box
	OverlayInit(message->title, message->message);

	// Some helpful variables for setting up buttons
	Vec2 wSize, bSize;
	wSize = Vec2(Context::getWindowWidth(), Context::getWindowHeight());
	bSize = OVERLAY_BUTTONSIZE;

	// Setup "Yes"-button
	overlayButton1->SetSize(bSize);
	overlayButton1->SetText("Yes", MenuItem::CENTER);
	overlayButton1->SetPosition(Vec2((wSize.x - bSize.x) / 2 - 70, (wSize.y + overlayBox->GetSize().y) / 2 - bSize.y - 25));
	this->onOverlayButton1 = message->onButton1;

	// Setup "No" button
	overlayButton2->SetSize(bSize);
	overlayButton2->SetText("No", MenuItem::CENTER);
	overlayButton2->SetPosition(Vec2((wSize.x - bSize.x) / 2 + 70, (wSize.y + overlayBox->GetSize().y) / 2 - bSize.y - 25));
	this->onOverlayButton2 = message->onButton2;

	// Make sure the "No" button is visible and active
	overlayButton2->active = true;
	overlayButton2->visible = true;

	// Render the overlay
	RenderOverlay();

	// Render the overlay-items rendertarget
	RenderOverlayItems();
}
Пример #3
0
int WINAPI WinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int nCmdShow)
{
	RECT rc;
	int nWidth;
	int nHeight;

	HWND hWndTS = FindTSWindow();
	if(hWndTS != NULL) {
		GetWindowRect(hWndTS, &rc);
		nWidth = rc.right - rc.left;
		nHeight = rc.bottom - rc.top;
	} else {
		ExitProcess(0);
	}

	bool bUseJoystick = true;
	int nArgCount;
	LPSTR *pArgList;

	pArgList = CommandLineToArgvA(GetCommandLine(), &nArgCount);
	for (int i = 0; i < nArgCount; ++i)
	{
		if (pArgList[i][0] != '-')
			continue;

		if (strcmp(pArgList[i]+1, "j") == 0)
			bUseJoystick = !bUseJoystick;

		if (strcmp(pArgList[i]+1, "v") == 0)
			ToggleDisplaySection(0);

		if (strcmp(pArgList[i]+1, "f") == 0)
			ToggleFontOutline();

		if (strcmp(pArgList[i]+1, "s") == 0)
			ToggleSpeedLimitOnly();

		if (pArgList[i][1] == 'm')
		{
			if (isdigit(pArgList[i][2]))
			{
				int nSection = atoi(pArgList[i]+2);
				if (nSection >= 1 && nSection <= 12)
					ToggleDisplaySection(nSection);
			}
		}

		if (pArgList[i][1] == 's')
		{
			if (isdigit(pArgList[i][2]))
			{
				int nSection = atoi(pArgList[i]+2);
				if (nSection >= 1 && nSection <= 12)
					ToggleDisplaySection(nSection + 12);
			}
		}
	}

	margin.cxRightWidth = nWidth;
	margin.cyBottomHeight = nHeight;

	WNDCLASSEX wc;
	ZeroMemory(&wc, sizeof(WNDCLASSEX));

	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WindowProc;
	wc.hInstance = hInstance;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)RGB(0,0,0);
	wc.lpszClassName = "WindowClass";

	RegisterClassEx(&wc);

	hWnd = CreateWindowEx(0,
		"WindowClass",
		"TrainSim Helper",
		WS_EX_TOPMOST | WS_POPUP,
		rc.left, rc.top,
		nWidth, nHeight,
		NULL,
		NULL,
		hInstance,
		NULL);

	SetWindowLong(hWnd, GWL_EXSTYLE,(int)GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED |WS_EX_TRANSPARENT);
	SetLayeredWindowAttributes(hWnd, RGB(0,0,0), 255, ULW_COLORKEY | LWA_ALPHA);

	ShowWindow(hWnd, nCmdShow);

	InitD3D(hWnd, nWidth, nHeight);
	MSG msg;
	::SetWindowPos(hWndTS, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

	// V for the whole overlay
	RegisterHotKey(hWnd, 0, MOD_SHIFT | MOD_ALT, 0x56 /* V key */);

	// F1-F12 for the main overlay
	for (int i = 1; i <= 12; ++i)
		RegisterHotKey(hWnd, i, MOD_SHIFT | MOD_ALT, VK_F1 + i - 1);

	// F1-F12 for the steam overlay
	for (int i = 13; i <= 24; ++i)
		RegisterHotKey(hWnd, i, MOD_SHIFT | MOD_CONTROL, VK_F1 + i - 13);

	// 0-9 digits for the countdown
	for (int i = 100; i <= 109; ++i)
		RegisterHotKey(hWnd, i, MOD_SHIFT | MOD_ALT, 0x30 + i - 100);

	// R for the countdown reset
	RegisterHotKey(hWnd, 110, MOD_SHIFT | MOD_ALT, 0x52 /* R key */);

	// D for driving direction
	RegisterHotKey(hWnd, 201, MOD_SHIFT | MOD_ALT, 0x44 /* D key */);

	// F for font outline
	RegisterHotKey(hWnd, 202, MOD_SHIFT | MOD_ALT, 0x46 /* F key */);

	// S for speed limit only
	RegisterHotKey(hWnd, 203, MOD_SHIFT | MOD_ALT, 0x53 /* S key */);

	if (bUseJoystick)
		if (FAILED(InitDirectInput()))
			ExitProcess(0);

	bool fDone = false;

	while(!fDone)
	{
		hWndTS = FindTSWindow();
		if (!hWndTS)
		{
			msg.wParam = 0;
			break;
		}

		RECT rcNew;
		GetWindowRect(hWndTS, &rcNew);
		if (rcNew.left != rc.left || rcNew.top != rc.top)
		{
			rc = rcNew;
			MoveWindow(hWnd, rc.left, rc.top, nWidth, nHeight, FALSE);
		}

		::SetWindowPos(hWnd, HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		Sleep(10);

		RenderOverlay();
		if (bUseJoystick)
			UpdateJoystick();

		while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);

			switch(msg.message)
			{
			case WM_QUIT:
				fDone = true;
				break;
			}
		}
	}

	if (bUseJoystick)
		FreeDirectInput();

	return msg.wParam;
}
Пример #4
0
void tRenderer::Render()
{    
    if (m_xRenderSystem != 0)
    {
        if (m_RenderSystemInitialized == false)
        {
            InitializeScene();
        }

        m_xRenderSystem->BeginScene();

    #ifdef DEBUG_RENDER_TIMING
        DbgPrintf("Time to execute m_xRenderSystem->BeginScene():  %lf", timer.ElapsedMs());
        timer.Reset();
    #endif

        // Render the Scene.
        m_xRenderSystem->SetViewport(m_pRenderTarget->x(), m_pRenderTarget->y(), m_pRenderTarget->width(), m_pRenderTarget->height());

        RenderScene();
    
        // Render Cursor
        if (m_CursorRenderFunction != 0)
        {
            m_CursorRenderFunction();

        #ifdef DEBUG_RENDER_TIMING
            m_xRenderSystem->Flush();
            DbgPrintf("Time to Render Cursor:  %lf", timer.ElapsedMs());
            timer.Reset();
        #endif
        }

        if (m_OverlaysUpdated == true)
        {
            UpdateSceneOverlays();
        }

        // Draw Overlays
        if (m_Overlays.size() > 0)
        {
            m_xRenderSystem->SetOrthographicProjection(m_pRenderTarget->x(), m_pRenderTarget->y(), m_pRenderTarget->width(), m_pRenderTarget->height());

            unsigned long numRenderables = static_cast<unsigned long>(m_Overlays.size());

            for (unsigned long renderIndex = 0; renderIndex < numRenderables; ++renderIndex)
            {
                RenderOverlay(m_Overlays[renderIndex]);
                
            #ifdef DEBUG_RENDER_TIMING
                m_xRenderSystem->Flush();
                DbgPrintf("Time to Render Overlay #%d:  %lf", renderIndex, timer.ElapsedMs());
                timer.Reset();
            #endif
            }
        }

        m_xRenderSystem->EndScene();
    }

    emit RenderCompleted();
}