Code cleanup: moving poly::ui to xe::ui

This commit is contained in:
Ben Vanik 2015-05-02 01:50:19 -07:00
parent 4d15b2296e
commit f7ca026db0
25 changed files with 134 additions and 142 deletions

View File

@ -62,6 +62,5 @@
],
'includes': [
'ui/sources.gypi',
],
}

View File

@ -1,20 +0,0 @@
# Copyright 2014 Ben Vanik. All Rights Reserved.
{
'sources': [
'control.cc',
'control.h',
'loop.h',
'menu_item.cc',
'menu_item.h',
'ui_event.h',
'window.h',
],
'conditions': [
['OS == "win"', {
'includes': [
'win32/sources.gypi',
],
}],
],
}

View File

@ -142,7 +142,8 @@ GL4ProfilerDisplay::GL4ProfilerDisplay(WGLControl* control)
vao_(0),
font_texture_(0),
font_handle_(0),
vertex_buffer_(MICROPROFILE_MAX_VERTICES * sizeof(Vertex) * 10, sizeof(Vertex)),
vertex_buffer_(MICROPROFILE_MAX_VERTICES * sizeof(Vertex) * 10,
sizeof(Vertex)),
draw_command_count_(0) {
if (!SetupFont() || !SetupState() || !SetupShaders()) {
// Hrm.
@ -150,32 +151,32 @@ GL4ProfilerDisplay::GL4ProfilerDisplay(WGLControl* control)
}
// Pass through mouse events.
control->on_mouse_down.AddListener([](poly::ui::MouseEvent& e) {
Profiler::OnMouseDown(e.button() == poly::ui::MouseEvent::Button::kLeft,
e.button() == poly::ui::MouseEvent::Button::kRight);
control->on_mouse_down.AddListener([](xe::ui::MouseEvent& e) {
Profiler::OnMouseDown(e.button() == xe::ui::MouseEvent::Button::kLeft,
e.button() == xe::ui::MouseEvent::Button::kRight);
e.set_handled(true);
});
control->on_mouse_up.AddListener([](poly::ui::MouseEvent& e) {
control->on_mouse_up.AddListener([](xe::ui::MouseEvent& e) {
Profiler::OnMouseUp();
e.set_handled(true);
});
control->on_mouse_move.AddListener([](poly::ui::MouseEvent& e) {
control->on_mouse_move.AddListener([](xe::ui::MouseEvent& e) {
Profiler::OnMouseMove(e.x(), e.y());
e.set_handled(true);
});
control->on_mouse_wheel.AddListener([](poly::ui::MouseEvent& e) {
control->on_mouse_wheel.AddListener([](xe::ui::MouseEvent& e) {
Profiler::OnMouseWheel(e.x(), e.y(), -e.dy());
e.set_handled(true);
});
// Watch for toggle/mode keys and such.
control->on_key_down.AddListener([](poly::ui::KeyEvent& e) {
control->on_key_down.AddListener([](xe::ui::KeyEvent& e) {
Profiler::OnKeyDown(e.key_code());
//e.set_handled(true);
// e.set_handled(true);
});
control->on_key_up.AddListener([](poly::ui::KeyEvent& e) {
control->on_key_up.AddListener([](xe::ui::KeyEvent& e) {
Profiler::OnKeyUp(e.key_code());
//e.set_handled(true);
// e.set_handled(true);
});
}
@ -258,7 +259,7 @@ struct VertexData { \n\
};\n\
";
const std::string vertex_shader_source = header +
"\n\
"\n\
layout(location = 0) uniform mat4 projection_matrix; \n\
struct VertexFetch { \n\
vec2 pos; \n\
@ -274,7 +275,7 @@ void main() { \n\
} \n\
";
const std::string fragment_shader_source = header +
"\n\
"\n\
layout(location = 1, bindless_sampler) uniform sampler2D font_texture; \n\
layout(location = 2) uniform float font_height; \n\
layout(location = 0) in VertexData vtx; \n\

View File

@ -21,8 +21,8 @@ namespace gl4 {
extern "C" GLEWContext* glewGetContext();
extern "C" WGLEWContext* wglewGetContext();
WGLControl::WGLControl(poly::ui::Loop* loop)
: poly::ui::win32::Win32Control(Flags::kFlagOwnPaint), loop_(loop) {}
WGLControl::WGLControl(xe::ui::Loop* loop)
: xe::ui::win32::Win32Control(Flags::kFlagOwnPaint), loop_(loop) {}
WGLControl::~WGLControl() = default;
@ -70,7 +70,7 @@ bool WGLControl::Create() {
return true;
}
void WGLControl::OnLayout(poly::ui::UIEvent& e) { Control::ResizeToFill(); }
void WGLControl::OnLayout(xe::ui::UIEvent& e) { Control::ResizeToFill(); }
LRESULT WGLControl::WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) {
@ -89,7 +89,7 @@ LRESULT WGLControl::WndProc(HWND hWnd, UINT message, WPARAM wParam,
current_paint_callback_ = nullptr;
}
poly::ui::UIEvent e(this);
xe::ui::UIEvent e(this);
OnPaint(e);
// TODO(benvanik): profiler present.

View File

@ -13,17 +13,17 @@
#include <functional>
#include "poly/threading.h"
#include "poly/ui/loop.h"
#include "poly/ui/win32/win32_control.h"
#include "xenia/gpu/gl4/gl_context.h"
#include "xenia/ui/loop.h"
#include "xenia/ui/win32/win32_control.h"
namespace xe {
namespace gpu {
namespace gl4 {
class WGLControl : public poly::ui::win32::Win32Control {
class WGLControl : public xe::ui::win32::Win32Control {
public:
WGLControl(poly::ui::Loop* loop);
WGLControl(xe::ui::Loop* loop);
~WGLControl() override;
GLContext* context() { return &context_; }
@ -33,13 +33,13 @@ class WGLControl : public poly::ui::win32::Win32Control {
protected:
bool Create() override;
void OnLayout(poly::ui::UIEvent& e) override;
void OnLayout(xe::ui::UIEvent& e) override;
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) override;
private:
poly::ui::Loop* loop_;
xe::ui::Loop* loop_;
GLContext context_;
std::function<void()> current_paint_callback_;
};

View File

@ -767,7 +767,7 @@ class TraceReader {
class TracePlayer : public TraceReader {
public:
TracePlayer(poly::ui::Loop* loop, GraphicsSystem* graphics_system)
TracePlayer(xe::ui::Loop* loop, GraphicsSystem* graphics_system)
: loop_(loop),
graphics_system_(graphics_system),
current_frame_index_(0),
@ -827,7 +827,7 @@ class TracePlayer : public TraceReader {
}
private:
poly::ui::Loop* loop_;
xe::ui::Loop* loop_;
GraphicsSystem* graphics_system_;
int current_frame_index_;
int current_command_index_;
@ -2213,7 +2213,7 @@ int trace_viewer_main(std::vector<std::wstring>& args) {
}
auto control = window->child(0);
control->on_key_char.AddListener([graphics_system](poly::ui::KeyEvent& e) {
control->on_key_char.AddListener([graphics_system](xe::ui::KeyEvent& e) {
auto& io = ImGui::GetIO();
if (e.key_code() > 0 && e.key_code() < 0x10000) {
if (e.key_code() == 0x74 /* VK_F5 */) {
@ -2224,41 +2224,41 @@ int trace_viewer_main(std::vector<std::wstring>& args) {
}
e.set_handled(true);
});
control->on_mouse_down.AddListener([](poly::ui::MouseEvent& e) {
control->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 poly::ui::MouseEvent::Button::kLeft:
case xe::ui::MouseEvent::Button::kLeft:
io.MouseDown[0] = true;
break;
case poly::ui::MouseEvent::Button::kRight:
case xe::ui::MouseEvent::Button::kRight:
io.MouseDown[1] = true;
break;
}
});
control->on_mouse_move.AddListener([](poly::ui::MouseEvent& e) {
control->on_mouse_move.AddListener([](xe::ui::MouseEvent& e) {
auto& io = ImGui::GetIO();
io.MousePos = ImVec2(float(e.x()), float(e.y()));
});
control->on_mouse_up.AddListener([](poly::ui::MouseEvent& e) {
control->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 poly::ui::MouseEvent::Button::kLeft:
case xe::ui::MouseEvent::Button::kLeft:
io.MouseDown[0] = false;
break;
case poly::ui::MouseEvent::Button::kRight:
case xe::ui::MouseEvent::Button::kRight:
io.MouseDown[1] = false;
break;
}
});
control->on_mouse_wheel.AddListener([](poly::ui::MouseEvent& e) {
control->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);
});
control->on_paint.AddListener([&](poly::ui::UIEvent& e) {
control->on_paint.AddListener([&](xe::ui::UIEvent& e) {
static bool imgui_setup = false;
if (!imgui_setup) {
ImImpl_Setup();

View File

@ -7,11 +7,11 @@
******************************************************************************
*/
#include "poly/ui/control.h"
#include "xenia/ui/control.h"
#include "poly/assert.h"
namespace poly {
namespace xe {
namespace ui {
Control::Control(uint32_t flags)
@ -129,4 +129,4 @@ void Control::OnMouseWheel(MouseEvent& e) {
}
} // namespace ui
} // namespace poly
} // namespace xe

View File

@ -7,16 +7,16 @@
******************************************************************************
*/
#ifndef POLY_UI_CONTROL_H_
#define POLY_UI_CONTROL_H_
#ifndef XENIA_UI_CONTROL_H_
#define XENIA_UI_CONTROL_H_
#include <memory>
#include <vector>
#include "poly/delegate.h"
#include "poly/ui/ui_event.h"
#include "xenia/ui/ui_event.h"
namespace poly {
namespace xe {
namespace ui {
class Control {
@ -129,6 +129,6 @@ class Control {
};
} // namespace ui
} // namespace poly
} // namespace xe
#endif // POLY_UI_CONTROL_H_
#endif // XENIA_UI_CONTROL_H_

View File

@ -7,12 +7,12 @@
******************************************************************************
*/
#ifndef POLY_UI_LOOP_H_
#define POLY_UI_LOOP_H_
#ifndef XENIA_UI_LOOP_H_
#define XENIA_UI_LOOP_H_
#include <functional>
namespace poly {
namespace xe {
namespace ui {
class Loop {
@ -27,6 +27,6 @@ class Loop {
};
} // namespace ui
} // namespace poly
} // namespace xe
#endif // POLY_UI_LOOP_H_
#endif // XENIA_UI_LOOP_H_

View File

@ -46,7 +46,7 @@ bool MainWindow::Initialize() {
return false;
}
Resize(1280, 720);
on_key_down.AddListener([this](poly::ui::KeyEvent& e) {
on_key_down.AddListener([this](KeyEvent& e) {
bool handled = true;
switch (e.key_code()) {
case 0x73: { // VK_F4

View File

@ -10,12 +10,12 @@
#ifndef XENIA_UI_MAIN_WINDOW_H_
#define XENIA_UI_MAIN_WINDOW_H_
#include "poly/ui/window.h"
#include "xenia/ui/window.h"
#include "xenia/xbox.h"
// TODO(benvanik): only on windows.
#include "poly/ui/win32/win32_loop.h"
#include "poly/ui/win32/win32_window.h"
#include "xenia/ui/win32/win32_loop.h"
#include "xenia/ui/win32/win32_window.h"
namespace xe {
class Emulator;
@ -24,8 +24,8 @@ class Emulator;
namespace xe {
namespace ui {
using PlatformLoop = poly::ui::win32::Win32Loop;
using PlatformWindow = poly::ui::win32::Win32Window;
using PlatformLoop = xe::ui::win32::Win32Loop;
using PlatformWindow = xe::ui::win32::Win32Window;
class MainWindow : public PlatformWindow {
public:

View File

@ -7,9 +7,9 @@
******************************************************************************
*/
#include "poly/ui/menu_item.h"
#include "xenia/ui/menu_item.h"
namespace poly {
namespace xe {
namespace ui {
MenuItem::MenuItem(Type type) : type_(type), parent_item_(nullptr) {}
@ -41,9 +41,7 @@ void MenuItem::RemoveChild(MenuItem* child_item) {
}
}
void MenuItem::OnSelected(UIEvent& e) {
on_selected(e);
}
void MenuItem::OnSelected(UIEvent& e) { on_selected(e); }
} // namespace ui
} // namespace poly
} // namespace xe

View File

@ -7,16 +7,16 @@
******************************************************************************
*/
#ifndef POLY_UI_MENU_ITEM_H_
#define POLY_UI_MENU_ITEM_H_
#ifndef XENIA_UI_MENU_ITEM_H_
#define XENIA_UI_MENU_ITEM_H_
#include <memory>
#include <vector>
#include "poly/delegate.h"
#include "poly/ui/ui_event.h"
#include "xenia/ui/ui_event.h"
namespace poly {
namespace xe {
namespace ui {
class Window;
@ -56,6 +56,6 @@ class MenuItem {
};
} // namespace ui
} // namespace poly
} // namespace xe
#endif // POLY_UI_MENU_ITEM_H_
#endif // XENIA_UI_MENU_ITEM_H_

View File

@ -1,7 +1,22 @@
# Copyright 2014 Ben Vanik. All Rights Reserved.
{
'sources': [
'control.cc',
'control.h',
'loop.h',
'main_window.cc',
'main_window.h',
'menu_item.cc',
'menu_item.h',
'ui_event.h',
'window.h',
],
'conditions': [
['OS == "win"', {
'includes': [
'win32/sources.gypi',
],
}],
],
}

View File

@ -7,10 +7,10 @@
******************************************************************************
*/
#ifndef POLY_UI_UI_EVENT_H_
#define POLY_UI_UI_EVENT_H_
#ifndef XENIA_UI_UI_EVENT_H_
#define XENIA_UI_UI_EVENT_H_
namespace poly {
namespace xe {
namespace ui {
class Control;
@ -84,6 +84,6 @@ class MouseEvent : public UIEvent {
};
} // namespace ui
} // namespace poly
} // namespace xe
#endif // POLY_UI_UI_EVENT_H_
#endif // XENIA_UI_UI_EVENT_H_

View File

@ -7,9 +7,9 @@
******************************************************************************
*/
#include "poly/ui/win32/win32_control.h"
#include "xenia/ui/win32/win32_control.h"
namespace poly {
namespace xe {
namespace ui {
namespace win32 {
@ -182,7 +182,7 @@ LRESULT CALLBACK Win32Control::WndProcThunk(HWND hWnd, UINT message,
if (message == WM_NCCREATE) {
auto create_struct = reinterpret_cast<LPCREATESTRUCT>(lParam);
control = reinterpret_cast<Win32Control*>(create_struct->lpCreateParams);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (__int3264)(LONG_PTR)control);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (__int3264)(LONG_PTR) control);
} else {
control =
reinterpret_cast<Win32Control*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
@ -365,4 +365,4 @@ bool Win32Control::HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam) {
} // namespace win32
} // namespace ui
} // namespace poly
} // namespace xe

View File

@ -7,15 +7,15 @@
******************************************************************************
*/
#ifndef POLY_UI_WIN32_WIN32_CONTROL_H_
#define POLY_UI_WIN32_WIN32_CONTROL_H_
#ifndef XENIA_UI_WIN32_WIN32_CONTROL_H_
#define XENIA_UI_WIN32_WIN32_CONTROL_H_
#include <windows.h>
#include <windowsx.h>
#include "poly/ui/control.h"
#include "xenia/ui/control.h"
namespace poly {
namespace xe {
namespace ui {
namespace win32 {
@ -52,7 +52,7 @@ class Win32Control : public Control {
void OnResize(UIEvent& e) override;
static LRESULT CALLBACK
WndProcThunk(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
WndProcThunk(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam);
@ -65,6 +65,6 @@ class Win32Control : public Control {
} // namespace win32
} // namespace ui
} // namespace poly
} // namespace xe
#endif // POLY_UI_WIN32_WIN32_CONTROL_H_
#endif // XENIA_UI_WIN32_WIN32_CONTROL_H_

View File

@ -7,11 +7,11 @@
******************************************************************************
*/
#include "poly/ui/win32/win32_loop.h"
#include "xenia/ui/win32/win32_loop.h"
#include "poly/assert.h"
namespace poly {
namespace xe {
namespace ui {
namespace win32 {
@ -89,4 +89,4 @@ void Win32Loop::AwaitQuit() { quit_fence_.Wait(); }
} // namespace win32
} // namespace ui
} // namespace poly
} // namespace xe

View File

@ -7,8 +7,8 @@
******************************************************************************
*/
#ifndef POLY_UI_WIN32_WIN32_LOOP_H_
#define POLY_UI_WIN32_WIN32_LOOP_H_
#ifndef XENIA_UI_WIN32_WIN32_LOOP_H_
#define XENIA_UI_WIN32_WIN32_LOOP_H_
#include <windows.h>
#include <windowsx.h>
@ -19,9 +19,9 @@
#include <thread>
#include "poly/threading.h"
#include "poly/ui/loop.h"
#include "xenia/ui/loop.h"
namespace poly {
namespace xe {
namespace ui {
namespace win32 {
@ -45,6 +45,6 @@ class Win32Loop : public Loop {
} // namespace win32
} // namespace ui
} // namespace poly
} // namespace xe
#endif // POLY_UI_WIN32_WIN32_LOOP_H_
#endif // XENIA_UI_WIN32_WIN32_LOOP_H_

View File

@ -7,9 +7,9 @@
******************************************************************************
*/
#include "poly/ui/win32/win32_menu_item.h"
#include "xenia/ui/win32/win32_menu_item.h"
namespace poly {
namespace xe {
namespace ui {
namespace win32 {
@ -34,4 +34,4 @@ void Win32MenuItem::OnChildRemoved(MenuItem* generic_child_item) {
} // namespace win32
} // namespace ui
} // namespace poly
} // namespace xe

View File

@ -7,15 +7,15 @@
******************************************************************************
*/
#ifndef POLY_UI_WIN32_WIN32_MENU_ITEM_H_
#define POLY_UI_WIN32_WIN32_MENU_ITEM_H_
#ifndef XENIA_UI_WIN32_WIN32_MENU_ITEM_H_
#define XENIA_UI_WIN32_WIN32_MENU_ITEM_H_
#include <windows.h>
#include <windowsx.h>
#include "poly/ui/menu_item.h"
#include "xenia/ui/menu_item.h"
namespace poly {
namespace xe {
namespace ui {
namespace win32 {
@ -35,6 +35,6 @@ class Win32MenuItem : public MenuItem {
} // namespace win32
} // namespace ui
} // namespace poly
} // namespace xe
#endif // POLY_UI_WIN32_WIN32_MENU_ITEM_H_
#endif // XENIA_UI_WIN32_WIN32_MENU_ITEM_H_

View File

@ -7,7 +7,7 @@
******************************************************************************
*/
#include "poly/ui/win32/win32_window.h"
#include "xenia/ui/win32/win32_window.h"
#include <dwmapi.h>
#include <tpcshrd.h>
@ -15,7 +15,7 @@
#include "poly/logging.h"
namespace poly {
namespace xe {
namespace ui {
namespace win32 {
@ -58,9 +58,8 @@ bool Win32Window::Create() {
// Create window.
hwnd_ = CreateWindowEx(window_ex_style, L"XeniaWindowClass", L"Xenia",
window_style, rc.left, rc.top,
rc.right - rc.left, rc.bottom - rc.top, nullptr,
nullptr, hInstance, this);
window_style, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, nullptr, nullptr, hInstance, this);
if (!hwnd_) {
PLOGE("CreateWindow failed");
return false;
@ -210,4 +209,4 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
} // namespace win32
} // namespace ui
} // namespace poly
} // namespace xe

View File

@ -7,15 +7,15 @@
******************************************************************************
*/
#ifndef POLY_UI_WIN32_WIN32_WINDOW_H_
#define POLY_UI_WIN32_WIN32_WINDOW_H_
#ifndef XENIA_UI_WIN32_WIN32_WINDOW_H_
#define XENIA_UI_WIN32_WIN32_WINDOW_H_
#include <string>
#include "poly/ui/win32/win32_control.h"
#include "poly/ui/window.h"
#include "xenia/ui/win32/win32_control.h"
#include "xenia/ui/window.h"
namespace poly {
namespace xe {
namespace ui {
namespace win32 {
@ -50,6 +50,6 @@ class Win32Window : public Window<Win32Control> {
} // namespace win32
} // namespace ui
} // namespace poly
} // namespace xe
#endif // POLY_UI_WIN32_WIN32_WINDOW_H_
#endif // XENIA_UI_WIN32_WIN32_WINDOW_H_

View File

@ -7,16 +7,16 @@
******************************************************************************
*/
#ifndef POLY_UI_WINDOW_H_
#define POLY_UI_WINDOW_H_
#ifndef XENIA_UI_WINDOW_H_
#define XENIA_UI_WINDOW_H_
#include <string>
#include "poly/delegate.h"
#include "poly/ui/control.h"
#include "poly/ui/ui_event.h"
#include "xenia/ui/control.h"
#include "xenia/ui/ui_event.h"
namespace poly {
namespace xe {
namespace ui {
template <typename T>
@ -79,6 +79,6 @@ class Window : public T {
};
} // namespace ui
} // namespace poly
} // namespace xe
#endif // POLY_UI_WINDOW_H_
#endif // XENIA_UI_WINDOW_H_