76 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
		
		
			
		
	
	
			76 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
|  | // Copyright (C) 2019 Nomango
 | |||
|  | 
 | |||
|  | #pragma once
 | |||
|  | 
 | |||
|  | #include "easy2d.h"
 | |||
|  | #include "easy2d-imgui.h"
 | |||
|  | 
 | |||
|  | using namespace easy2d; | |||
|  | 
 | |||
|  | E2D_DECLARE_SMART_PTR(MainScene); | |||
|  | class MainScene | |||
|  | 	: public Scene | |||
|  | { | |||
|  | 	bool show_demo_window = true; | |||
|  | 	bool show_another_window = false; | |||
|  | 	Color clear_color = Color(0.45f, 0.55f, 0.6f, 1.f); | |||
|  | 
 | |||
|  | public: | |||
|  | 	MainScene() | |||
|  | 	{ | |||
|  | 		// <20><><EFBFBD><EFBFBD> ImGui ͼ<><CDBC>
 | |||
|  | 		ImGuiLayerPtr layer = new ImGuiLayer; | |||
|  | 		AddChild(layer); | |||
|  | 
 | |||
|  | 		// <20><><EFBFBD><EFBFBD> ImGui <20>ṩ<EFBFBD><E1B9A9> Demo <20><><EFBFBD><EFBFBD>
 | |||
|  | 		layer->AddItem([=]() { | |||
|  | 			if (show_demo_window) | |||
|  | 				ImGui::ShowDemoWindow(&show_demo_window); | |||
|  | 		}, L"DemoWindow"); | |||
|  | 
 | |||
|  | 		// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><F2B5A5B4><EFBFBD>
 | |||
|  | 		layer->AddItem(Closure(this, &MainScene::SimpleWindow), L"SimpleWindow"); | |||
|  | 
 | |||
|  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 		layer->AddItem(Closure(this, &MainScene::AnotherWindow), L"AnotherWindow"); | |||
|  | 	} | |||
|  | 
 | |||
|  | 	void SimpleWindow() | |||
|  | 	{ | |||
|  | 		static float f = 0.0f; | |||
|  | 		static int counter = 0; | |||
|  | 
 | |||
|  | 		ImGui::Begin("Hello, world!"); | |||
|  | 
 | |||
|  | 		ImGui::Text("This is some useful text."); | |||
|  | 		ImGui::Checkbox("Demo Window", &show_demo_window); | |||
|  | 		ImGui::Checkbox("Another Window", &show_another_window); | |||
|  | 
 | |||
|  | 		ImGui::SliderFloat("float", &f, 0.0f, 1.0f); | |||
|  | 		ImGui::ColorEdit3("clear color", (float*)&clear_color); | |||
|  | 
 | |||
|  | 		if (ImGui::Button("Button")) | |||
|  | 			counter++; | |||
|  | 		ImGui::SameLine(); | |||
|  | 		ImGui::Text("counter = %d", counter); | |||
|  | 
 | |||
|  | 		ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); | |||
|  | 		ImGui::End(); | |||
|  | 
 | |||
|  | 		// <20>Ĵ<DEB8><C4B4>ڱ<EFBFBD><DAB1><EFBFBD>ɫ
 | |||
|  | 		Renderer::Instance().SetClearColor(clear_color); | |||
|  | 	} | |||
|  | 
 | |||
|  | 	void AnotherWindow() | |||
|  | 	{ | |||
|  | 		if (show_another_window) | |||
|  | 		{ | |||
|  | 			ImGui::Begin("Another Window", &show_another_window); | |||
|  | 			ImGui::Text("Hello from another window!"); | |||
|  | 			if (ImGui::Button("Close Me")) | |||
|  | 				show_another_window = false; | |||
|  | 			ImGui::End(); | |||
|  | 		} | |||
|  | 	} | |||
|  | }; |