Adding window demo.

This commit is contained in:
Ben Vanik 2015-11-07 10:37:46 -08:00
parent fdf59fec5f
commit f065872241
6 changed files with 254 additions and 131 deletions

View File

@ -71,9 +71,13 @@ project("xenia-gpu-gl4-trace-viewer")
})
filter("platforms:Windows")
debugdir(project_root)
debugargs({
"--flagfile=scratch/flags.txt",
"2>&1",
"1>scratch/stdout-trace-viewer.txt",
})
-- Only create the .user file if it doesn't already exist.
local user_file = project_root.."/build/xenia-gpu-gl4-trace-viewer.vcxproj.user"
if not os.isfile(user_file) then
debugdir(project_root)
debugargs({
"--flagfile=scratch/flags.txt",
"2>&1",
"1>scratch/stdout-trace-viewer.txt",
})
end

View File

@ -1,94 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Checked|x64">
<Configuration>Checked</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{21DDCB81-68A3-4AB2-8CB0-C2B051B9FDDC}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>xegputraceviewer</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\build\Xenia.Cpp.x64.Common.props" />
<Import Project="..\..\..\build\Xenia.Cpp.x64.Debug.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\build\Xenia.Cpp.x64.Common.props" />
<Import Project="..\..\..\build\Xenia.Cpp.x64.Release.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>libgflags.lib;libglew.lib;libimgui.lib;libxenia.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<PreprocessorDefinitions>_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>libgflags.lib;libglew.lib;libimgui.lib;libxenia.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Checked|x64'">
<Link>
<AdditionalDependencies>libgflags.lib;libglew.lib;libimgui.lib;libxenia.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\base\main_win.cc" />
<ClCompile Include="trace_viewer_main.cc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\base\main.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{e3dfb6f1-ec4a-4b58-9a57-0d6eeadd01af}</UniqueIdentifier>
</Filter>
<Filter Include="src\xenia">
<UniqueIdentifier>{be07fbff-bc38-4314-9ba0-821ae4e46026}</UniqueIdentifier>
</Filter>
<Filter Include="src\xenia\base">
<UniqueIdentifier>{13989fe7-adab-418c-be97-298171bea0ec}</UniqueIdentifier>
</Filter>
<Filter Include="src\xenia\gpu">
<UniqueIdentifier>{06641461-811b-44ff-be49-f013a39eb662}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\base\main_win.cc">
<Filter>src\xenia\base</Filter>
</ClCompile>
<ClCompile Include="trace_viewer_main.cc">
<Filter>src\xenia\gpu</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\base\main.h">
<Filter>src\xenia\base</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -17,3 +17,41 @@ project("xenia-ui")
project_root.."/build_tools/third_party/gflags/src",
})
local_platform_files()
group("demos")
project("xenia-ui-window-demo")
uuid("e0a687e5-d1f4-4c18-b2f7-012c53ec1ee4")
kind("WindowedApp")
language("C++")
links({
"elemental-forms",
"gflags",
"glew",
"imgui",
"xenia-base",
"xenia-core",
"xenia-ui",
"xenia-ui-gl",
})
flags({
"WinMain", -- Use WinMain instead of main.
})
defines({
"GLEW_STATIC=1",
"GLEW_MX=1",
})
includedirs({
project_root.."/third_party/elemental-forms/src",
project_root.."/build_tools/third_party/gflags/src",
})
files({
"window_demo.cc",
"../base/main_"..platform_suffix..".cc",
})
files({
project_root.."/third_party/elemental-forms/resources.rc",
})
resincludedirs({
project_root,
project_root.."/third_party/elemental-forms",
})

View File

@ -144,7 +144,7 @@ bool Window::MakeReady() {
root_element_->set_background_skin(TBIDC("background"));
root_element_->set_rect({0, 0, width(), height()});
el::util::ShowDebugInfoSettingsForm(root_element_.get());
// el::util::ShowDebugInfoSettingsForm(root_element_.get());
return true;
}

205
src/xenia/ui/window_demo.cc Normal file
View File

@ -0,0 +1,205 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <gflags/gflags.h>
#include <cstring>
#include "third_party/elemental-forms/src/el/util/debug.h"
#include "third_party/imgui/imgui.h"
#include "xenia/base/clock.h"
#include "xenia/base/logging.h"
#include "xenia/base/main.h"
#include "xenia/base/platform_win.h"
#include "xenia/base/threading.h"
#include "xenia/profiling.h"
#include "xenia/ui/gl/gl_context.h"
#include "xenia/ui/imgui_drawer.h"
#include "xenia/ui/window.h"
namespace xe {
namespace ui {
std::unique_ptr<xe::ui::ImGuiDrawer> imgui_drawer_;
int window_demo_main(const std::vector<std::wstring>& args) {
Profiler::Initialize();
Profiler::ThreadEnter("main");
// Create run loop and the window.
auto loop = ui::Loop::Create();
auto window = xe::ui::Window::Create(loop.get(), L"xenia-ui-window-demo");
loop->PostSynchronous([&window]() {
xe::threading::set_name("Win32 Loop");
xe::Profiler::ThreadEnter("Win32 Loop");
if (!window->Initialize()) {
FatalError("Failed to initialize main window");
return;
}
});
window->on_closed.AddListener([&loop](xe::ui::UIEvent* e) {
loop->Quit();
XELOGI("User-initiated death!");
imgui_drawer_.reset();
exit(1);
});
loop->on_quit.AddListener([&window](xe::ui::UIEvent* e) { window.reset(); });
// Main menu.
auto main_menu = MenuItem::Create(MenuItem::Type::kNormal);
auto file_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&File");
{
file_menu->AddChild(MenuItem::Create(MenuItem::Type::kString, L"&Close",
L"Alt+F4",
[&window]() { window->Close(); }));
}
main_menu->AddChild(std::move(file_menu));
auto debug_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&Debug");
{
debug_menu->AddChild(MenuItem::Create(MenuItem::Type::kString,
L"Toggle Profiler &Display", L"F3",
[]() { Profiler::ToggleDisplay(); }));
debug_menu->AddChild(MenuItem::Create(MenuItem::Type::kString,
L"&Pause/Resume Profiler", L"`",
[]() { Profiler::TogglePause(); }));
}
main_menu->AddChild(std::move(debug_menu));
window->set_main_menu(std::move(main_menu));
// Initial size setting, done here so that it knows the menu exists.
window->Resize(1920, 1200);
// Create the graphics context used for drawing and setup the window.
loop->PostSynchronous([&window]() {
// Create context and give it to the window.
// The window will finish initialization wtih the context (loading
// resources, etc).
auto context = xe::ui::gl::GLContext::Create(window.get());
window->set_context(std::move(context));
// Setup the profiler display.
GraphicsContextLock context_lock(window->context());
Profiler::set_window(window.get());
// Initialize the ImGui renderer we'll use.
imgui_drawer_ = std::make_unique<xe::ui::ImGuiDrawer>(window.get());
// Show the elemental-forms debug UI so we can see it working.
el::util::ShowDebugInfoSettingsForm(window->root_element());
});
window->on_key_char.AddListener([](xe::ui::KeyEvent* e) {
auto& io = ImGui::GetIO();
if (e->key_code() > 0 && e->key_code() < 0x10000) {
io.AddInputCharacter(e->key_code());
}
e->set_handled(true);
});
window->on_key_down.AddListener([](xe::ui::KeyEvent* e) {
auto& io = ImGui::GetIO();
io.KeysDown[e->key_code()] = true;
switch (e->key_code()) {
case 0x72: { // F3
Profiler::ToggleDisplay();
} break;
case 16: {
io.KeyShift = true;
} break;
case 17: {
io.KeyCtrl = true;
} break;
}
});
window->on_key_up.AddListener([](xe::ui::KeyEvent* e) {
auto& io = ImGui::GetIO();
io.KeysDown[e->key_code()] = false;
switch (e->key_code()) {
case 16: {
io.KeyShift = false;
} break;
case 17: {
io.KeyCtrl = false;
} break;
}
});
window->on_mouse_down.AddListener([](xe::ui::MouseEvent* e) {
auto& io = ImGui::GetIO();
io.MousePos = ImVec2(float(e->x()), float(e->y()));
switch (e->button()) {
case xe::ui::MouseEvent::Button::kLeft: {
io.MouseDown[0] = true;
} break;
case xe::ui::MouseEvent::Button::kRight: {
io.MouseDown[1] = true;
} break;
}
});
window->on_mouse_move.AddListener([](xe::ui::MouseEvent* e) {
auto& io = ImGui::GetIO();
io.MousePos = ImVec2(float(e->x()), float(e->y()));
});
window->on_mouse_up.AddListener([](xe::ui::MouseEvent* e) {
auto& io = ImGui::GetIO();
io.MousePos = ImVec2(float(e->x()), float(e->y()));
switch (e->button()) {
case xe::ui::MouseEvent::Button::kLeft: {
io.MouseDown[0] = false;
} break;
case xe::ui::MouseEvent::Button::kRight: {
io.MouseDown[1] = false;
} break;
}
});
window->on_mouse_wheel.AddListener([](xe::ui::MouseEvent* e) {
auto& io = ImGui::GetIO();
io.MousePos = ImVec2(float(e->x()), float(e->y()));
io.MouseWheel += float(e->dy() / 120.0f);
});
window->on_painting.AddListener([&](xe::ui::UIEvent* e) {
auto& io = ImGui::GetIO();
auto current_tick_count = Clock::QueryHostTickCount();
static uint64_t last_draw_tick_count = 0;
io.DeltaTime = (current_tick_count - last_draw_tick_count) /
static_cast<float>(Clock::host_tick_frequency());
last_draw_tick_count = current_tick_count;
io.DisplaySize = ImVec2(static_cast<float>(window->width()),
static_cast<float>(window->height()));
ImGui::NewFrame();
ImGui::ShowTestWindow();
ImGui::ShowMetricsWindow();
ImGui::Render();
// Continuous paint.
window->Invalidate();
});
window->Invalidate();
// Wait until we are exited.
loop->AwaitQuit();
imgui_drawer_.reset();
window.reset();
loop.reset();
Profiler::Dump();
Profiler::Shutdown();
return 0;
}
} // namespace ui
} // namespace xe
DEFINE_ENTRY_POINT(L"xenia-ui-window-demo", L"xenia-ui-window-demo",
xe::ui::window_demo_main);