Magic_Game/samples/ImGuiSample/MainScene.h

76 lines
1.7 KiB
C
Raw Normal View History

// Copyright (C) 2019 Nomango
#pragma once
2019-04-11 14:40:54 +08:00
#include "kiwano.h"
#include "kiwano-imgui.h"
2019-04-11 14:40:54 +08:00
using namespace kiwano;
2019-04-11 14:40:54 +08:00
KGE_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 = ImGuiView::Instance().CreateLayer(this);
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(MakeClosure(this, &MainScene::SimpleWindow), L"SimpleWindow");
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
layer->AddItem(MakeClosure(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();
}
}
};