init
This commit is contained in:
		
							
								
								
									
										70
									
								
								third/imgui/imgui_helper.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								third/imgui/imgui_helper.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
			
		||||
#include "imgui.h"
 | 
			
		||||
#include <functional>
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "imgui_impl_dx11.h"
 | 
			
		||||
#include "imgui_impl_win32.h"
 | 
			
		||||
#include <d3d11.h>
 | 
			
		||||
#include <tchar.h>
 | 
			
		||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
 | 
			
		||||
class ImGuiHelper
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    int window_width, window_height;
 | 
			
		||||
    wchar_t windowTitle;
 | 
			
		||||
    ID3D11Device *g_pd3dDevice = nullptr;
 | 
			
		||||
    ID3D11DeviceContext *g_pd3dDeviceContext = nullptr;
 | 
			
		||||
    IDXGISwapChain *g_pSwapChain = nullptr;
 | 
			
		||||
    static UINT g_ResizeWidth, g_ResizeHeight;
 | 
			
		||||
    ID3D11RenderTargetView *g_pMainRenderTargetView = nullptr;
 | 
			
		||||
    ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
 | 
			
		||||
    HWND hWnd = nullptr;
 | 
			
		||||
    WNDCLASSEX wc;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    bool CreateDeviceD3d(HWND hWnd);
 | 
			
		||||
    void CleanupDeviceD3d();
 | 
			
		||||
    void CreateRenderTarget();
 | 
			
		||||
    void CleanupRenderTarget();
 | 
			
		||||
    static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    ImGuiHelper(int width = 1280 , int height = 800,const char* windowTitle = "Window");
 | 
			
		||||
    ~ImGuiHelper();
 | 
			
		||||
    ImGuiHelper(ImGuiHelper &&helper) = default;
 | 
			
		||||
    ImGuiHelper(const ImGuiHelper &helper) = default;
 | 
			
		||||
    ImGuiHelper &operator=(const ImGuiHelper &helper) = default;
 | 
			
		||||
    ImGuiHelper &operator=(ImGuiHelper &&helper) = default;
 | 
			
		||||
    void Render(const std::function<void()> &context, bool &isRunning);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#elif __linux
 | 
			
		||||
#ifndef __ImGuiHelper_H
 | 
			
		||||
#define __ImGuiHelper_H
 | 
			
		||||
 | 
			
		||||
#include <GLFW/glfw3.h>
 | 
			
		||||
#include "imgui_impl_glfw.h"
 | 
			
		||||
#include "imgui_impl_opengl3.h"
 | 
			
		||||
 | 
			
		||||
class ImGuiHelper{
 | 
			
		||||
private:
 | 
			
		||||
    static const char* glsl_version;
 | 
			
		||||
    std::string windowTitle;
 | 
			
		||||
    GLFWwindow* window = nullptr;
 | 
			
		||||
    ImGuiIO* io;
 | 
			
		||||
    int width, height;
 | 
			
		||||
public:
 | 
			
		||||
    ImGuiHelper(int width = 1280, int height = 720, const std::string& windowTitle = "Window");
 | 
			
		||||
    ~ImGuiHelper();
 | 
			
		||||
    ImGuiHelper(ImGuiHelper &&helper) = default;
 | 
			
		||||
    ImGuiHelper(const ImGuiHelper& helper) = default;
 | 
			
		||||
    ImGuiHelper& operator=(ImGuiHelper&& helper) = default;
 | 
			
		||||
    ImGuiHelper& operator=(const ImGuiHelper& helper) = default;
 | 
			
		||||
    void Render(const std::function<void()>& context, bool &isRunning);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user