Exemplo n.º 1
0
bool CDirectWriteRenderer::Initialize(HWND hwnd)
{
	Finalize();

	if (hwnd == nullptr)
		return false;

	ID2D1Factory *pFactory = m_System.GetD2DFactory();

	if (pFactory == nullptr)
		return false;

	D2D1_RENDER_TARGET_PROPERTIES Props = D2D1::RenderTargetProperties(
		D2D1_RENDER_TARGET_TYPE_DEFAULT,
		D2D1::PixelFormat(
			DXGI_FORMAT_B8G8R8A8_UNORM,
			D2D1_ALPHA_MODE_IGNORE),
		96.0f,
		96.0f,
		D2D1_RENDER_TARGET_USAGE_NONE,
		D2D1_FEATURE_LEVEL_DEFAULT);
	ID2D1DCRenderTarget *pRenderTarget;
	HRESULT hr = pFactory->CreateDCRenderTarget(&Props, &pRenderTarget);
	if (SUCCEEDED(hr)) {
		m_pRenderTarget = pRenderTarget;
		m_hwnd = hwnd;
		OnWindowPosChanged();
	}

	pFactory->Release();

	return SUCCEEDED(hr);
}
Exemplo n.º 2
0
PauseGameState::PauseGameState(MainGameState* pMainGameState, ID2D1HwndRenderTarget* pRenderTarget, IDWriteFactory* pWriteFactory, GameStateManager* pGameStateManager)
{
	this->pGameStateManager = pGameStateManager;
	this->pMainGameState = pMainGameState;
	this->pRenderTarget = pRenderTarget;
	ID2D1Factory* pFactory = NULL;
	RECT rect;
	HWND hWnd = pRenderTarget->GetHwnd();
	this->pRenderTarget->GetFactory(&pFactory);

	GetClientRect(hWnd, &rect);
	int width = rect.right - rect.left;
	int height = rect.bottom - rect.top;

	pFactory->CreateRectangleGeometry(D2D1::RectF(0, 0, (float)width, (float)height), &pRect);

	pTextFormat = NULL;
	pWriteFactory->CreateTextFormat(L"Comic Sans MS", NULL, DWRITE_FONT_WEIGHT_BOLD, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 20, L"", &pTextFormat);
	pWriteFactory->CreateTextFormat(L"Comic Sans MS", NULL, DWRITE_FONT_WEIGHT_BOLD, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 30, L"", &pTitleFormat);
	TextButtonBase* button1 = new TextButtonBase(L"Resume Game", pTextFormat);
	TextButtonBase* button2 = new TextButtonBase(L"Restart Game", pTextFormat);
	TextButtonBase* button3 = new TextButtonBase(L"Return Menu", pTextFormat);
	button1->SetRect(D2D1::RectF(0, 0, 150, -25));
	button2->SetRect(D2D1::RectF(0, 0, 150, -25));
	button3->SetRect(D2D1::RectF(0, 0, 150, -25));
	pMenu = new TextVerticalMenu();
	pMenu->SetCenterX(0);
	pMenu->SetTop(50);
	pMenu->SetGad(20);
	pMenu->AddTextButton(button1);
	pMenu->AddTextButton(button2);
	pMenu->AddTextButton(button3);
}
Exemplo n.º 3
0
void GraphicsCanvas::createDeviceResources()
{
	RECT rc;
	GetClientRect(mWindowHandle, &rc);

	D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);
	mViewportDimensions = Vector2(float(size.width), float(size.height));

	// Create render target
	ID2D1Factory* factory = GraphicsManager::getInstance()->getD2DFactory();
	SafeCall(factory->CreateHwndRenderTarget(D2D1::RenderTargetProperties(), D2D1::HwndRenderTargetProperties(mWindowHandle, size), &mRenderTarget));

	//mRenderTarget->SetAntialiasMode(D2D1_ANTIALIAS_MODE_FORCE_DWORD);
	mRenderTarget->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE);
}
Exemplo n.º 4
0
HRESULT MainWindow::CreateGraphicsResources()
{
	HRESULT hr = S_OK;
	if (pRenderTarget == NULL)
	{
		RECT rc;
		GetClientRect(m_hwnd, &rc);

		D2D1_SIZE_U size = D2D1::SizeU(rc.right, rc.bottom);

		hr = pFactory->CreateHwndRenderTarget(
			D2D1::RenderTargetProperties(),
			D2D1::HwndRenderTargetProperties(m_hwnd, size),
			&pRenderTarget);

		if (SUCCEEDED(hr))
		{
			const D2D1_COLOR_F color = D2D1::ColorF(1.0f, 1.0f, 0);
			hr = pRenderTarget->CreateSolidColorBrush(color, &pBrush);

			if (SUCCEEDED(hr))
			{
				CalculateLayout();
			}
		}
	}
	return hr;
}
Exemplo n.º 5
0
void MWinDeviceImpl::Save()
{
	ID2D1DrawingStateBlock* state;
	THROW_IF_HRESULT_ERROR(sD2DFactory->CreateDrawingStateBlock(&state));
	mRenderTarget->SaveDrawingState(state);
	mState.push(state);
}
Exemplo n.º 6
0
HRESULT CreateDrawingResources(HWND hwnd)
{
    HRESULT hr = S_OK;
    RECT rcClient = { 0 };

    ID2D1Factory *pFactory = NULL;
    ID2D1HwndRenderTarget *pRenderTarget = NULL;

    GetClientRect(hwnd, &rcClient);

    hr = D2D1CreateFactory(
        D2D1_FACTORY_TYPE_SINGLE_THREADED,
        &pFactory
        );


    if (SUCCEEDED(hr))
    {
        hr = pFactory->CreateHwndRenderTarget(
            D2D1::RenderTargetProperties(),
            D2D1::HwndRenderTargetProperties(
                hwnd,
                D2D1::SizeU(rcClient.right, rcClient.bottom)
                ),
            &pRenderTarget
            );
    }

    if (SUCCEEDED(hr))
    {
        g_pRT = pRenderTarget;
        g_pRT->AddRef();
    }

    SafeRelease(&pFactory);
    SafeRelease(&pRenderTarget);
    return hr;
}
    void createLayout (TextLayout& layout, const AttributedString& text, IDWriteFactory& directWriteFactory,
                       ID2D1Factory& direct2dFactory, IDWriteFontCollection& fontCollection)
    {
        // To add color to text, we need to create a D2D render target
        // Since we are not actually rendering to a D2D context we create a temporary GDI render target

        D2D1_RENDER_TARGET_PROPERTIES d2dRTProp = D2D1::RenderTargetProperties (D2D1_RENDER_TARGET_TYPE_SOFTWARE,
                                                                                D2D1::PixelFormat (DXGI_FORMAT_B8G8R8A8_UNORM,
                                                                                                   D2D1_ALPHA_MODE_IGNORE),
                                                                                0, 0,
                                                                                D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE,
                                                                                D2D1_FEATURE_LEVEL_DEFAULT);
        ComSmartPtr<ID2D1DCRenderTarget> renderTarget;
        HRESULT hr = direct2dFactory.CreateDCRenderTarget (&d2dRTProp, renderTarget.resetAndGetPointerAddress());

        ComSmartPtr<IDWriteTextLayout> dwTextLayout;

        if (! setupLayout (text, layout.getWidth(), layout.getHeight(), *renderTarget,
                           directWriteFactory, fontCollection, dwTextLayout))
            return;

        UINT32 actualLineCount = 0;
        hr = dwTextLayout->GetLineMetrics (nullptr, 0, &actualLineCount);

        layout.ensureStorageAllocated (actualLineCount);

        {
            ComSmartPtr<CustomDirectWriteTextRenderer> textRenderer (new CustomDirectWriteTextRenderer (fontCollection, text));
            hr = dwTextLayout->Draw (&layout, textRenderer, 0, 0);
        }

        HeapBlock<DWRITE_LINE_METRICS> dwLineMetrics (actualLineCount);
        hr = dwTextLayout->GetLineMetrics (dwLineMetrics, actualLineCount, &actualLineCount);
        int lastLocation = 0;
        const int numLines = jmin ((int) actualLineCount, layout.getNumLines());
        float yAdjustment = 0;
        const float extraLineSpacing = text.getLineSpacing();

        for (int i = 0; i < numLines; ++i)
        {
            TextLayout::Line& line = layout.getLine (i);
            line.stringRange = Range<int> (lastLocation, (int) lastLocation + dwLineMetrics[i].length);
            line.lineOrigin.y += yAdjustment;
            yAdjustment += extraLineSpacing;
            lastLocation += dwLineMetrics[i].length;
        }
    }
Exemplo n.º 8
0
BOOL WinControl::Create(
        DWORD style, 
        RECT* rc, 
        HWND parent, 
        HMENU hmenu,
        AEffEditor* eff)
{
    pParent_ = (WinControl*)::GetWindowLongPtr(parent, GWLP_USERDATA);
    Editor_ = eff;

    HINSTANCE hInst = (HINSTANCE) GetWindowLongPtr(parent, GWLP_HINSTANCE);

    if ( hInst != ::Class.GethInstance() )
    {
        pParent_ = 0;
    }

    if (::Class.Register())
    {
#ifndef USE_GDI
        FLOAT dpiX, dpiY;

        ID2D1Factory *fac = ::Class.GetD2DFactory();
        fac->GetDesktopDpi(&dpiX, &dpiY);

        hWindow_ = CreateWindow(
            ::Class.GetWinClassName(),
            WindowTitle_,
            style,
            static_cast<UINT>(rc->left * dpiX / 96.f), 
            static_cast<UINT>(rc->top * dpiY/ 96.f), 
            static_cast<UINT>((rc->right - rc->left) * dpiX / 96.f), 
            static_cast<UINT>((rc->bottom - rc->top) * dpiY / 96.f),
            parent, hmenu, ::Class.GethInstance(), NULL);
#else
        hWindow_ = CreateWindow(
            ::Class.GetWinClassName(),
            WindowTitle_,
            style,
            rc->left,
            rc->top,
            rc->right - rc->left,
            rc->bottom - rc->top,
            parent, hmenu, ::Class.GethInstance(), NULL);
#endif
    
        if (hWindow_)
        {
            ::SetWindowLongPtr(
                hWindow_,
                GWLP_USERDATA,
                (LONG_PTR) this
                );

#ifndef USE_GDI
            if ( SUCCEEDED(CreateDeviceDependantResources()) )
            {
                Show(SW_SHOWNORMAL);
                Update();

                return TRUE;
            }
#else
            Show(SW_SHOWNORMAL);
            Update();

            return TRUE;
#endif
        }
    }

    return FALSE;
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd) {

	xxd.SetScreenResolution(ScreenWidth, ScreenHeight);

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

	pencere.cbClsExtra = NULL;
	pencere.cbSize = sizeof(WNDCLASSEX);
	pencere.cbWndExtra = NULL;
	pencere.hCursor = LoadCursor(NULL, IDC_ARROW);
	pencere.hIcon = NULL;
	pencere.hIconSm = NULL;
	pencere.hInstance = hInst;
	pencere.lpfnWndProc = (WNDPROC)WinProc;
	pencere.lpszClassName = "Pencere";
	pencere.lpszMenuName = NULL;
	pencere.style = CS_HREDRAW | CS_VREDRAW;

	RegisterClassEx(&pencere);

	ID2D1Factory* directx = NULL;
	D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,&directx);

	HWND hWnd = NULL;
	hWnd = CreateWindowEx(NULL, "Pencere", "Direct2D",WS_POPUP | WS_EX_TOPMOST, 0, 0, ScreenWidth, ScreenHeight, NULL, NULL, hInst, NULL);
	
	ShowWindow(hWnd, nShowCmd);

	/*D2D1Rect*/

	RECT rect;
	GetClientRect(hWnd, &rect);

	ID2D1HwndRenderTarget* RenderTarget = NULL;
	directx->CreateHwndRenderTarget(
		D2D1::RenderTargetProperties(),
		D2D1::HwndRenderTargetProperties(hWnd,D2D1::SizeU(rect.right - rect.left, rect.bottom - rect.top)),
		&RenderTarget);

	/*D2D1Rect*/
	/* D2D1Brush */

	/*ID2D1SolidColorBrush* Brush = NULL;
	RenderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &Brush);*/

	/* D2D1Brush */

	MSG msg;
	ZeroMemory(&msg, sizeof(MSG));

	/*D2D1_ELLIPSE ellipse = D2D1::Ellipse(
		D2D1::Point2F(100.f, 100.f),
		50.f,
		50.f
	);*/

	/*POINT pts;
	pts.x = (ScreenWidth/2) - 25;
	float gravity = 1.0f;
	float y = 20;
	int alo = 0;
	pts.y = (ScreenHeight/2) - 80;*/

	ID2D1Bitmap* Bitmap = NULL;
	IWICImagingFactory* ImagingFactory = NULL;
	CoInitializeEx(NULL, COINIT_MULTITHREADED);
	CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&ImagingFactory);
	/*lb.LoadBitmapFromFile(RenderTarget, ImagingFactory, L"Oyuncu/Dokular/Aylak/ön.png", &Bitmap);
	D2D1_SIZE_F size = Bitmap->GetSize();
	D2D1_POINT_2F upperLeftCorner;*/

	btn.InitFactory(ImagingFactory);
	btn.InitTarget(RenderTarget);
	btn.setPos(100, 100);
	btn.getImages();
	btn.InitText(L"Buton Bura Oglim");

	Bush trn;
	trn.InitGadgets(RenderTarget,ImagingFactory);
	trn.InitImage();
	trn.CalcThat();
	trn.InitThat();

	Player plyr;
	plyr.InitFactories(ImagingFactory,RenderTarget);
	plyr.InitIdleImages();
	plyr.InitMoveImages();

	DWORD baslangic_noktasi;
	float deltaTime, oldTime = 0;
	while (TRUE){
		baslangic_noktasi = GetTickCount();
		deltaTime = baslangic_noktasi - oldTime;
		oldTime = baslangic_noktasi;

		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
			if (msg.message == WM_QUIT) {
				break;
			}

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		//KEY
		if (TUS(VK_SPACE)) {
			//alo = 1;
		}
		if (TUS(VK_LEFT)) {
			tp.x += 2;
			//pts.x -= 2;
		}
		if (TUS(VK_RIGHT)) {
			tp.x -= 2;
			//pts.x += 2;
		}
		if (TUS(VK_UP)) {
			tp.y += 2;
			//pts.y -= 2;
		}
		if (TUS(VK_DOWN)) {
			tp.y -= 2;
			//pts.y += 2;
		}

		plyr.HandleKeysForIdle();
		plyr.HandleKeysForMove(deltaTime);

		/*if (alo == 1) {
			y -= gravity;
			pts.y -= y;
			if (y == -19) {
				alo = 0;
				y = 20.f;
			}
		}*/

		/*if (clps.x != 0 && clps.y!= 0) {
			text.setPos(clps.x, clps.y);
		}*/
		/*upperLeftCorner = D2D1::Point2F(pts.x, pts.y);*/

		//text.setFont(L"Comic Sans MS");
		//LOOP
		RenderTarget->BeginDraw();
		RenderTarget->Clear(D2D1::ColorF(0.25f,0.80f,0.22f,1.f));

		/*Terrain*/
		trn.drawBush();
		/*Terrain*/
		
		//RenderTarget->DrawRectangle(D2D1::RectF(100,100,200,300), Brush);
		//RenderTarget->DrawEllipse(ellipse, Brush, 2.f);
		RenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(0 + tp.x,0 + tp.y));
		/*RenderTarget->DrawBitmap(
			Bitmap,
			D2D1::RectF(
				upperLeftCorner.x,
				upperLeftCorner.y,
				upperLeftCorner.x + 50,
				upperLeftCorner.y + 160),
				1.0,
				D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR
			);*/
		//text.drawatext(50,L"Merhaba",RenderTarget,Brush);

		plyr.Render();

		btn.RenderIt(cups, clk, tp);

		RenderTarget->EndDraw();
		/*if (TUS(VK_ESCAPE)) {
			break;
			PostMessage(hWnd, WM_DESTROY, 0, 0);
		}*/
		//
	}

	directx->Release();
	RenderTarget->Release();
	/*Brush->Release();*/
	Bitmap->Release();
	ImagingFactory->Release();
	xxd.RestoreScreenResolution();
	return 0;
}