Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "renderer.hpp"
- #include "../win32/input.hpp"
- namespace horizon::core
- {
- Renderer::~Renderer()
- {
- Destroy();
- }
- auto Renderer::Create( IDirect3DDevice9* direct_device ) -> bool
- {
- auto& input = win32::Input::Instance();
- const auto window = input.GetWindow();
- ImGui::CreateContext();
- ImGui_ImplWin32_Init( window );
- ImGui_ImplDX9_Init( direct_device );
- ImGui::StyleColorsDark();
- return true;
- }
- auto Renderer::Destroy() -> void
- {
- ImGui_ImplDX9_Shutdown();
- ImGui_ImplWin32_Shutdown();
- ImGui::DestroyContext();
- }
- auto Renderer::Begin() -> bool
- {
- ImGui_ImplDX9_NewFrame();
- ImGui_ImplWin32_NewFrame();
- ImGui::NewFrame();
- return true;
- }
- auto Renderer::End() -> void
- {
- }
- auto Renderer::Present() -> void
- {
- ImGui::EndFrame();
- ImGui::Render();
- ImGui_ImplDX9_RenderDrawData( ImGui::GetDrawData() );
- }
- auto Renderer::DeviceLost() -> void
- {
- ImGui_ImplDX9_InvalidateDeviceObjects();
- }
- auto Renderer::DeviceReset( HRESULT result ) -> void
- {
- if( SUCCEEDED( result ) )
- ImGui_ImplDX9_CreateDeviceObjects();
- }
- auto Renderer::DrawQuad( const ImVec2& p0, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImColor& color ) -> void
- {
- auto render = ImGui::GetOverlayDrawList();
- render->AddQuadFilled( { p0[ 0 ], p0[ 1 ] }, { p1[ 0 ], p1[ 1 ] }, { p2[ 0 ], p2[ 1 ] }, { p3[ 0 ], p3[ 1 ] }, color );
- }
- auto Renderer::DrawRect( const ImVec2& begin, const ImVec2& size, const ImColor& color ) -> void
- {
- auto render = ImGui::GetOverlayDrawList();
- render->AddRectFilled( { begin[ 0 ], begin[ 1 ] }, { begin[ 0 ] + size[ 0 ], begin[ 1 ] + size[ 1 ] }, color );
- }
- auto Renderer::DrawLine( const ImVec2& begin, const ImVec2& end, const ImColor& color, float width /*= 1.f*/ ) -> void
- {
- auto render = ImGui::GetOverlayDrawList();
- render->AddLine( { begin[ 0 ], begin[ 1 ] }, { end[ 0 ], end[ 1 ] }, color );
- }
- auto Renderer::DrawText( const ImVec2& begin, unsigned align, const ImColor& color, const char* message, ... ) -> void
- {
- char output[ 1024 ] = { };
- va_list args;
- va_start( args, message );
- vsprintf_s( output, message, args );
- va_end( args );
- auto coord = ImVec2( begin[ 0 ], begin[ 1 ] );
- auto size = ImGui::CalcTextSize( output );
- if( align & TextRight )
- coord.x -= size.x;
- else if( align & TextCenterH )
- coord.x -= size.x / 2.f;
- if( align & TextCenterV )
- coord.y -= size.y / 2.f;
- auto render = ImGui::GetOverlayDrawList();
- auto coord_out = ImVec2{ coord.x + 1.f, coord.y + 1.f };
- render->AddText( coord_out, ImColor{ 0.f, 0.f, 0.f, 1.f }, output );
- render->AddText( coord, color, output );
- }
- auto Renderer::GetTextSize( ImVec2& output, const char* message, ... ) -> void
- {
- char format[ 1024 ] = { };
- va_list args;
- va_start( args, message );
- vsprintf_s( format, message, args );
- va_end( args );
- auto size = ImGui::CalcTextSize( format );
- output = size;
- }
- }
Add Comment
Please, Sign In to add comment