C++17ification.

C++17ification!

- Filesystem interaction now uses std::filesystem::path.
- Usage of const char*, std::string have been changed to
  std::string_view where appropriate.
- Usage of printf-style functions changed to use fmt.
This commit is contained in:
gibbed
2020-03-02 09:37:11 -06:00
committed by Rick Gibbed
parent 114cea6fb7
commit 5bf0b34445
220 changed files with 4944 additions and 4294 deletions

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2018 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -28,7 +28,7 @@ namespace ui {
namespace d3d12 {
bool D3D12Provider::IsD3D12APIAvailable() {
HMODULE library_d3d12 = LoadLibrary(L"D3D12.dll");
HMODULE library_d3d12 = LoadLibraryW(L"D3D12.dll");
if (!library_d3d12) {
return false;
}
@@ -82,9 +82,9 @@ D3D12Provider::~D3D12Provider() {
bool D3D12Provider::Initialize() {
// Load the libraries.
library_dxgi_ = LoadLibrary(L"dxgi.dll");
library_d3d12_ = LoadLibrary(L"D3D12.dll");
library_d3dcompiler_ = LoadLibrary(L"D3DCompiler_47.dll");
library_dxgi_ = LoadLibraryW(L"dxgi.dll");
library_d3d12_ = LoadLibraryW(L"D3D12.dll");
library_d3dcompiler_ = LoadLibraryW(L"D3DCompiler_47.dll");
if (library_dxgi_ == nullptr || library_d3d12_ == nullptr ||
library_d3dcompiler_ == nullptr) {
XELOGE("Failed to load dxgi.dll, D3D12.dll and D3DCompiler_47.dll.");

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -10,6 +10,7 @@
#ifndef XENIA_UI_FILE_PICKER_H_
#define XENIA_UI_FILE_PICKER_H_
#include <filesystem>
#include <memory>
#include <string>
#include <utility>
@@ -34,7 +35,7 @@ class FilePicker {
FilePicker()
: mode_(Mode::kOpen),
type_(Type::kFile),
title_(L"Select Files"),
title_("Select Files"),
multi_selection_(false) {}
virtual ~FilePicker() = default;
@@ -44,14 +45,14 @@ class FilePicker {
Type type() const { return type_; }
void set_type(Type type) { type_ = type; }
std::wstring title() const { return title_; }
void set_title(std::wstring title) { title_ = std::move(title); }
const std::string& title() const { return title_; }
void set_title(std::string title) { title_ = std::move(title); }
std::vector<std::pair<std::wstring, std::wstring>> extensions() const {
std::vector<std::pair<std::string, std::string>> extensions() const {
return extensions_;
}
void set_extensions(
std::vector<std::pair<std::wstring, std::wstring>> extensions) {
std::vector<std::pair<std::string, std::string>> extensions) {
extensions_ = std::move(extensions);
}
@@ -60,8 +61,10 @@ class FilePicker {
multi_selection_ = multi_selection;
}
std::vector<std::wstring> selected_files() const { return selected_files_; }
void set_selected_files(std::vector<std::wstring> selected_files) {
std::vector<std::filesystem::path> selected_files() const {
return selected_files_;
}
void set_selected_files(std::vector<std::filesystem::path> selected_files) {
selected_files_ = std::move(selected_files);
}
@@ -70,11 +73,11 @@ class FilePicker {
private:
Mode mode_;
Type type_;
std::wstring title_;
std::vector<std::pair<std::wstring, std::wstring>> extensions_;
std::string title_;
std::vector<std::pair<std::string, std::string>> extensions_;
bool multi_selection_;
std::vector<std::wstring> selected_files_;
std::vector<std::filesystem::path> selected_files_;
};
} // namespace ui

View File

@@ -2,18 +2,23 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/ui/file_picker.h"
#include <codecvt>
#include <locale>
#include <filesystem>
#include <string>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include "xenia/base/assert.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/platform_linux.h"
#include "xenia/base/string.h"
namespace xe {
namespace ui {
@@ -54,10 +59,8 @@ bool GtkFilePicker::Show(void* parent_window_handle) {
if (res == GTK_RESPONSE_ACCEPT) {
GtkFileChooser* chooser = GTK_FILE_CHOOSER(dialog);
filename = gtk_file_chooser_get_filename(chooser);
std::vector<std::wstring> selected_files;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring ws_filename = converter.from_bytes(filename);
selected_files.push_back(ws_filename);
std::vector<std::filesystem::path> selected_files;
selected_files.push_back(xe::to_path(std::string(filename)));
set_selected_files(selected_files);
gtk_widget_destroy(dialog);
return true;

View File

@@ -2,15 +2,15 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/ui/file_picker.h"
#include "xenia/base/assert.h"
#include "xenia/base/platform_win.h"
#include "xenia/base/string.h"
#include "xenia/ui/file_picker.h"
namespace xe {
namespace ui {
@@ -136,7 +136,7 @@ bool Win32FilePicker::Show(void* parent_window_handle) {
return false;
}
hr = file_dialog->SetTitle(title().c_str());
hr = file_dialog->SetTitle((LPCWSTR)xe::to_utf16(title()).c_str());
if (!SUCCEEDED(hr)) {
return false;
}
@@ -159,13 +159,17 @@ bool Win32FilePicker::Show(void* parent_window_handle) {
}
// Set the file types to display only. Notice that this is a 1-based array.
std::vector<COMDLG_FILTERSPEC> save_types;
auto extensions = this->extensions();
for (auto& extension : extensions) {
save_types.push_back({extension.first.c_str(), extension.second.c_str()});
std::vector<std::pair<std::u16string, std::u16string>> file_pairs;
std::vector<COMDLG_FILTERSPEC> file_types;
for (const auto& extension : this->extensions()) {
const auto& file_pair =
file_pairs.emplace_back(std::move(xe::to_utf16(extension.first)),
std::move(xe::to_utf16(extension.second)));
file_types.push_back(
{(LPCWSTR)file_pair.first.c_str(), (LPCWSTR)file_pair.second.c_str()});
}
hr = file_dialog->SetFileTypes(static_cast<UINT>(save_types.size()),
save_types.data());
hr = file_dialog->SetFileTypes(static_cast<UINT>(file_types.size()),
file_types.data());
if (!SUCCEEDED(hr)) {
return false;
}
@@ -209,8 +213,8 @@ bool Win32FilePicker::Show(void* parent_window_handle) {
if (!SUCCEEDED(hr)) {
return false;
}
std::vector<std::wstring> selected_files;
selected_files.push_back(std::wstring(file_path));
std::vector<std::filesystem::path> selected_files;
selected_files.push_back(std::filesystem::path(file_path));
set_selected_files(selected_files);
CoTaskMemFree(file_path);

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -136,7 +136,7 @@ void ImGuiDrawer::SetupFont() {
// TODO(benvanik): jp font on other platforms?
// https://github.com/Koruri/kibitaki looks really good, but is 1.5MiB.
const char* jp_font_path = "C:\\Windows\\Fonts\\msgothic.ttc";
if (xe::filesystem::PathExists(xe::to_wstring(jp_font_path))) {
if (xe::filesystem::PathExists(jp_font_path)) {
ImFontConfig jp_font_config;
jp_font_config.MergeMode = true;
jp_font_config.OversampleH = jp_font_config.OversampleV = 1;

View File

@@ -2,13 +2,16 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/ui/loop_gtk.h"
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include "xenia/base/assert.h"
namespace xe {

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -13,21 +13,20 @@ namespace xe {
namespace ui {
std::unique_ptr<MenuItem> MenuItem::Create(Type type) {
return MenuItem::Create(type, L"", L"", nullptr);
return MenuItem::Create(type, "", "", nullptr);
}
std::unique_ptr<MenuItem> MenuItem::Create(Type type,
const std::wstring& text) {
return MenuItem::Create(type, text, L"", nullptr);
std::unique_ptr<MenuItem> MenuItem::Create(Type type, const std::string& text) {
return MenuItem::Create(type, text, "", nullptr);
}
std::unique_ptr<MenuItem> MenuItem::Create(Type type, const std::wstring& text,
std::unique_ptr<MenuItem> MenuItem::Create(Type type, const std::string& text,
std::function<void()> callback) {
return MenuItem::Create(type, text, L"", std::move(callback));
return MenuItem::Create(type, text, "", std::move(callback));
}
MenuItem::MenuItem(Type type, const std::wstring& text,
const std::wstring& hotkey, std::function<void()> callback)
MenuItem::MenuItem(Type type, const std::string& text,
const std::string& hotkey, std::function<void()> callback)
: type_(type),
parent_item_(nullptr),
text_(text),

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -34,19 +34,19 @@ class MenuItem {
};
static std::unique_ptr<MenuItem> Create(Type type);
static std::unique_ptr<MenuItem> Create(Type type, const std::wstring& text);
static std::unique_ptr<MenuItem> Create(Type type, const std::wstring& text,
static std::unique_ptr<MenuItem> Create(Type type, const std::string& text);
static std::unique_ptr<MenuItem> Create(Type type, const std::string& text,
std::function<void()> callback);
static std::unique_ptr<MenuItem> Create(Type type, const std::wstring& text,
const std::wstring& hotkey,
static std::unique_ptr<MenuItem> Create(Type type, const std::string& text,
const std::string& hotkey,
std::function<void()> callback);
virtual ~MenuItem();
MenuItem* parent_item() const { return parent_item_; }
Type type() { return type_; }
const std::wstring& text() { return text_; }
const std::wstring& hotkey() { return hotkey_; }
const std::string& text() { return text_; }
const std::string& hotkey() { return hotkey_; }
void AddChild(MenuItem* child_item);
void AddChild(std::unique_ptr<MenuItem> child_item);
@@ -58,7 +58,7 @@ class MenuItem {
virtual void DisableMenuItem(Window& window) = 0;
protected:
MenuItem(Type type, const std::wstring& text, const std::wstring& hotkey,
MenuItem(Type type, const std::string& text, const std::string& hotkey,
std::function<void()> callback);
virtual void OnChildAdded(MenuItem* child_item) {}
@@ -69,8 +69,8 @@ class MenuItem {
Type type_;
MenuItem* parent_item_;
std::vector<MenuItemPtr> children_;
std::wstring text_;
std::wstring hotkey_;
std::string text_;
std::string hotkey_;
std::function<void()> callback_;
};

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -54,8 +54,8 @@ class SpirvAssembler {
// The return may have an error set on it if the source text is malformed.
std::unique_ptr<Result> Assemble(const char* source_text,
size_t source_text_length);
std::unique_ptr<Result> Assemble(const std::string& source_text) {
return Assemble(source_text.c_str(), source_text.size());
std::unique_ptr<Result> Assemble(const std::string_view source_text) {
return Assemble(source_text.data(), source_text.size());
}
private:

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -10,6 +10,8 @@
#ifndef XENIA_UI_UI_EVENT_H_
#define XENIA_UI_UI_EVENT_H_
#include <filesystem>
namespace xe {
namespace ui {
@@ -28,14 +30,14 @@ class UIEvent {
class FileDropEvent : public UIEvent {
public:
FileDropEvent(Window* target, const wchar_t* filename)
: UIEvent(target), filename_(filename) {}
FileDropEvent(Window* target, std::filesystem::path filename)
: UIEvent(target), filename_(std::move(filename)) {}
~FileDropEvent() override = default;
const wchar_t* filename() const { return filename_; }
const std::filesystem::path& filename() const { return filename_; }
private:
const wchar_t* filename_ = nullptr;
const std::filesystem::path filename_;
};
class KeyEvent : public UIEvent {

View File

@@ -7,6 +7,7 @@ project("xenia-ui-vulkan")
kind("StaticLib")
language("C++")
links({
"fmt",
"xenia-base",
"xenia-ui",
"xenia-ui-spirv",
@@ -28,6 +29,7 @@ project("xenia-ui-window-vulkan-demo")
kind("WindowedApp")
language("C++")
links({
"fmt",
"imgui",
"volk",
"xenia-base",

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2017 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -27,6 +27,8 @@
#if XE_PLATFORM_LINUX
#include "xenia/ui/window_gtk.h"
#include <X11/Xlib-xcb.h>
#endif
namespace xe {

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2017 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -106,7 +106,7 @@ bool VulkanInstance::EnableRenderDoc() {
// RenderDoc injects itself into our process, so we should be able to get it.
pRENDERDOC_GetAPI get_api = nullptr;
#if XE_PLATFORM_WIN32
auto module_handle = GetModuleHandle(L"renderdoc.dll");
auto module_handle = GetModuleHandleW(L"renderdoc.dll");
if (!module_handle) {
XELOGI("RenderDoc support requested but it is not attached");
return false;

View File

@@ -2,13 +2,14 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/ui/vulkan/vulkan_util.h"
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
@@ -29,8 +30,8 @@ Version Version::Parse(uint32_t value) {
version.major = VK_VERSION_MAJOR(value);
version.minor = VK_VERSION_MINOR(value);
version.patch = VK_VERSION_PATCH(value);
version.pretty_string = xe::format_string("%u.%u.%u", version.major,
version.minor, version.patch);
version.pretty_string =
fmt::format("{}.{}.{}", version.major, version.minor, version.patch);
return version;
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -17,7 +17,7 @@
namespace xe {
namespace ui {
int window_demo_main(const std::vector<std::wstring>& args);
int window_demo_main(const std::vector<std::string>& args);
std::unique_ptr<GraphicsProvider> CreateDemoGraphicsProvider(Window* window) {
return xe::ui::vulkan::VulkanProvider::Create(window);
@@ -26,5 +26,4 @@ std::unique_ptr<GraphicsProvider> CreateDemoGraphicsProvider(Window* window) {
} // namespace ui
} // namespace xe
DEFINE_ENTRY_POINT(L"xenia-ui-window-vulkan-demo", xe::ui::window_demo_main,
"");
DEFINE_ENTRY_POINT("xenia-ui-window-vulkan-demo", xe::ui::window_demo_main, "");

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -31,7 +31,7 @@ constexpr double kDoubleClickDistance = 5;
constexpr int32_t kMouseWheelDetent = 120;
Window::Window(Loop* loop, const std::wstring& title)
Window::Window(Loop* loop, const std::string& title)
: loop_(loop), title_(title) {}
Window::~Window() {

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -30,7 +30,7 @@ class ImGuiDrawer;
class Window {
public:
static std::unique_ptr<Window> Create(Loop* loop, const std::wstring& title);
static std::unique_ptr<Window> Create(Loop* loop, const std::string& title);
virtual ~Window();
@@ -47,8 +47,8 @@ class Window {
virtual void EnableMainMenu() = 0;
virtual void DisableMainMenu() = 0;
const std::wstring& title() const { return title_; }
virtual bool set_title(const std::wstring& title) {
const std::string& title() const { return title_; }
virtual bool set_title(const std::string& title) {
if (title == title_) {
return false;
}
@@ -131,7 +131,7 @@ class Window {
Delegate<MouseEvent*> on_mouse_wheel;
protected:
Window(Loop* loop, const std::wstring& title);
Window(Loop* loop, const std::string& title);
void ForEachListener(std::function<void(WindowListener*)> fn);
void TryForEachListener(std::function<bool(WindowListener*)> fn);
@@ -168,7 +168,7 @@ class Window {
Loop* loop_ = nullptr;
std::unique_ptr<MenuItem> main_menu_;
std::wstring title_;
std::string title_;
int32_t width_ = 0;
int32_t height_ = 0;
bool has_focus_ = true;

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -26,7 +26,7 @@ namespace ui {
// Implemented in one of the window_*_demo.cc files under a subdir.
std::unique_ptr<GraphicsProvider> CreateDemoGraphicsProvider(Window* window);
int window_demo_main(const std::vector<std::wstring>& args) {
int window_demo_main(const std::vector<std::string>& args) {
Profiler::Initialize();
Profiler::ThreadEnter("main");
@@ -44,20 +44,20 @@ int window_demo_main(const std::vector<std::wstring>& args) {
// Main menu.
auto main_menu = MenuItem::Create(MenuItem::Type::kNormal);
auto file_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&File");
auto file_menu = MenuItem::Create(MenuItem::Type::kPopup, "&File");
{
file_menu->AddChild(MenuItem::Create(MenuItem::Type::kString, L"&Close",
L"Alt+F4",
file_menu->AddChild(MenuItem::Create(MenuItem::Type::kString, "&Close",
"Alt+F4",
[&window]() { window->Close(); }));
}
main_menu->AddChild(std::move(file_menu));
auto debug_menu = MenuItem::Create(MenuItem::Type::kPopup, L"&Debug");
auto debug_menu = MenuItem::Create(MenuItem::Type::kPopup, "&Debug");
{
debug_menu->AddChild(MenuItem::Create(MenuItem::Type::kString,
L"Toggle Profiler &Display", L"F3",
"Toggle Profiler &Display", "F3",
[]() { Profiler::ToggleDisplay(); }));
debug_menu->AddChild(MenuItem::Create(MenuItem::Type::kString,
L"&Pause/Resume Profiler", L"`",
"&Pause/Resume Profiler", "`",
[]() { Profiler::TogglePause(); }));
}
main_menu->AddChild(std::move(debug_menu));

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -26,11 +26,11 @@ class FnWrapper {
std::function<void()> fn_;
};
std::unique_ptr<Window> Window::Create(Loop* loop, const std::wstring& title) {
std::unique_ptr<Window> Window::Create(Loop* loop, const std::string& title) {
return std::make_unique<GTKWindow>(loop, title);
}
GTKWindow::GTKWindow(Loop* loop, const std::wstring& title)
GTKWindow::GTKWindow(Loop* loop, const std::string& title)
: Window(loop, title) {}
GTKWindow::~GTKWindow() {
@@ -99,7 +99,7 @@ void GTKWindow::OnClose() {
super::OnClose();
}
bool GTKWindow::set_title(const std::wstring& title) {
bool GTKWindow::set_title(const std::string& title) {
if (!super::set_title(title)) {
return false;
}
@@ -368,8 +368,8 @@ bool GTKWindow::HandleKeyboard(GdkEventKey* event) {
}
std::unique_ptr<ui::MenuItem> MenuItem::Create(Type type,
const std::wstring& text,
const std::wstring& hotkey,
const std::string& text,
const std::string& hotkey,
std::function<void()> callback) {
return std::make_unique<GTKMenuItem>(type, text, hotkey, callback);
}
@@ -380,8 +380,8 @@ static void _menu_activate_callback(GtkWidget* menu, gpointer data) {
delete fn;
}
GTKMenuItem::GTKMenuItem(Type type, const std::wstring& text,
const std::wstring& hotkey,
GTKMenuItem::GTKMenuItem(Type type, const std::string& text,
const std::string& hotkey,
std::function<void()> callback)
: MenuItem(type, text, hotkey, std::move(callback)) {
switch (type) {
@@ -390,7 +390,7 @@ GTKMenuItem::GTKMenuItem(Type type, const std::wstring& text,
menu_ = gtk_menu_bar_new();
break;
case MenuItem::Type::kPopup:
menu_ = gtk_menu_item_new_with_label((gchar*)xe::to_string(text).c_str());
menu_ = gtk_menu_item_new_with_label((gchar*)text.c_str());
break;
case MenuItem::Type::kSeparator:
menu_ = gtk_separator_menu_item_new();
@@ -398,10 +398,9 @@ GTKMenuItem::GTKMenuItem(Type type, const std::wstring& text,
case MenuItem::Type::kString:
auto full_name = text;
if (!hotkey.empty()) {
full_name += L"\t" + hotkey;
full_name += "\t" + hotkey;
}
menu_ = gtk_menu_item_new_with_label(
(gchar*)xe::to_string(full_name).c_str());
menu_ = gtk_menu_item_new_with_label((gchar*)full_name.c_str());
break;
}
if (GTK_IS_MENU_ITEM(menu_))

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -13,6 +13,9 @@
#include <memory>
#include <string>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include "xenia/base/platform_linux.h"
#include "xenia/ui/menu_item.h"
#include "xenia/ui/window.h"
@@ -24,7 +27,7 @@ class GTKWindow : public Window {
using super = Window;
public:
GTKWindow(Loop* loop, const std::wstring& title);
GTKWindow(Loop* loop, const std::string& title);
~GTKWindow() override;
NativePlatformHandle native_platform_handle() const override {
@@ -35,7 +38,7 @@ class GTKWindow : public Window {
void EnableMainMenu() override {}
void DisableMainMenu() override {}
bool set_title(const std::wstring& title) override;
bool set_title(const std::string& title) override;
bool SetIcon(const void* buffer, size_t size) override;
@@ -82,7 +85,7 @@ class GTKWindow : public Window {
class GTKMenuItem : public MenuItem {
public:
GTKMenuItem(Type type, const std::wstring& text, const std::wstring& hotkey,
GTKMenuItem(Type type, const std::string& text, const std::string& hotkey,
std::function<void()> callback);
~GTKMenuItem() override;

View File

@@ -2,27 +2,30 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/ui/window_win.h"
#include <ShellScalingApi.h>
#include <string>
#include "xenia/base/assert.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/logging.h"
#include "xenia/base/platform_win.h"
#include "xenia/ui/window_win.h"
namespace xe {
namespace ui {
std::unique_ptr<Window> Window::Create(Loop* loop, const std::wstring& title) {
std::unique_ptr<Window> Window::Create(Loop* loop, const std::string& title) {
return std::make_unique<Win32Window>(loop, title);
}
Win32Window::Win32Window(Loop* loop, const std::wstring& title)
Win32Window::Win32Window(Loop* loop, const std::string& title)
: Window(loop, title) {}
Win32Window::~Win32Window() {
@@ -48,7 +51,7 @@ bool Win32Window::OnCreate() {
HINSTANCE hInstance = GetModuleHandle(nullptr);
if (!SetProcessDpiAwareness_ || !GetDpiForMonitor_) {
auto shcore = GetModuleHandle(L"shcore.dll");
auto shcore = GetModuleHandleW(L"shcore.dll");
if (shcore) {
SetProcessDpiAwareness_ =
GetProcAddress(shcore, "SetProcessDpiAwareness");
@@ -74,8 +77,8 @@ bool Win32Window::OnCreate() {
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, L"MAINICON");
wcex.hIconSm = NULL; // LoadIcon(hInstance, L"MAINICON");
wcex.hIcon = LoadIconW(hInstance, L"MAINICON");
wcex.hIconSm = NULL; // LoadIconW(hInstance, L"MAINICON");
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = nullptr;
@@ -94,16 +97,18 @@ bool Win32Window::OnCreate() {
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
// Create window.
hwnd_ = CreateWindowEx(window_ex_style, L"XeniaWindowClass", title_.c_str(),
window_style, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, nullptr, nullptr, hInstance, this);
hwnd_ =
CreateWindowExW(window_ex_style, L"XeniaWindowClass",
reinterpret_cast<LPCWSTR>(xe::to_utf16(title_).c_str()),
window_style, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, nullptr, nullptr, hInstance, this);
if (!hwnd_) {
XELOGE("CreateWindow failed");
return false;
}
// Disable flicks.
ATOM atom = GlobalAddAtom(L"MicrosoftTabletPenServiceProperty");
ATOM atom = GlobalAddAtomW(L"MicrosoftTabletPenServiceProperty");
const DWORD_PTR dwHwndTabletProperty =
TABLET_DISABLE_PRESSANDHOLD | // disables press and hold (right-click)
// gesture
@@ -114,8 +119,8 @@ bool Win32Window::OnCreate() {
// drag up)
TABLET_DISABLE_TOUCHSWITCH | TABLET_DISABLE_SMOOTHSCROLLING |
TABLET_DISABLE_TOUCHUIFORCEON | TABLET_ENABLE_MULTITOUCHDATA;
SetProp(hwnd_, L"MicrosoftTabletPenServiceProperty",
reinterpret_cast<HANDLE>(dwHwndTabletProperty));
SetPropW(hwnd_, L"MicrosoftTabletPenServiceProperty",
reinterpret_cast<HANDLE>(dwHwndTabletProperty));
GlobalDeleteAtom(atom);
// Enable DWM elevation.
@@ -140,7 +145,7 @@ bool Win32Window::OnCreate() {
}
void Win32Window::EnableMMCSS() {
HMODULE hLibrary = LoadLibrary(L"DWMAPI.DLL");
HMODULE hLibrary = LoadLibraryW(L"DWMAPI.DLL");
if (!hLibrary) {
return;
}
@@ -193,11 +198,11 @@ void Win32Window::DisableMainMenu() {
}
}
bool Win32Window::set_title(const std::wstring& title) {
bool Win32Window::set_title(const std::string& title) {
if (!super::set_title(title)) {
return false;
}
SetWindowText(hwnd_, title.c_str());
SetWindowTextW(hwnd_, reinterpret_cast<LPCWSTR>(xe::to_utf16(title).c_str()));
return true;
}
@@ -208,11 +213,11 @@ bool Win32Window::SetIcon(const void* buffer, size_t size) {
}
// Reset icon to default.
auto default_icon = LoadIcon(GetModuleHandle(nullptr), L"MAINICON");
SendMessage(hwnd_, WM_SETICON, ICON_BIG,
reinterpret_cast<LPARAM>(default_icon));
SendMessage(hwnd_, WM_SETICON, ICON_SMALL,
reinterpret_cast<LPARAM>(default_icon));
auto default_icon = LoadIconW(GetModuleHandle(nullptr), L"MAINICON");
SendMessageW(hwnd_, WM_SETICON, ICON_BIG,
reinterpret_cast<LPARAM>(default_icon));
SendMessageW(hwnd_, WM_SETICON, ICON_SMALL,
reinterpret_cast<LPARAM>(default_icon));
if (!buffer || !size) {
return true;
}
@@ -223,8 +228,9 @@ bool Win32Window::SetIcon(const void* buffer, size_t size) {
static_cast<DWORD>(size), TRUE, 0x00030000, 0, 0,
LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
if (icon_) {
SendMessage(hwnd_, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(icon_));
SendMessage(hwnd_, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(icon_));
SendMessageW(hwnd_, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(icon_));
SendMessageW(hwnd_, WM_SETICON, ICON_SMALL,
reinterpret_cast<LPARAM>(icon_));
}
return false;
@@ -493,7 +499,7 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
switch (message) {
case WM_DROPFILES: {
HDROP hDrop = reinterpret_cast<HDROP>(wParam);
std::wstring path;
std::u16string path;
// Get required buffer size
UINT buf_size = DragQueryFileW(hDrop, 0, nullptr, 0);
@@ -501,8 +507,8 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
path.resize(buf_size + 1); // Give space for a null terminator
// Only getting first file dropped (other files ignored)
if (DragQueryFileW(hDrop, 0, &path[0], buf_size + 1)) {
auto e = FileDropEvent(this, path.c_str());
if (DragQueryFileW(hDrop, 0, (LPWSTR)&path[0], buf_size + 1)) {
auto e = FileDropEvent(this, xe::to_path(path));
OnFileDrop(&e);
}
}
@@ -512,7 +518,7 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
case WM_NCCREATE: {
// Tell Windows to automatically scale non-client areas on different DPIs.
auto en = (BOOL(WINAPI*)(HWND hwnd))GetProcAddress(
GetModuleHandle(L"user32.dll"), "EnableNonClientDpiScaling");
GetModuleHandleW(L"user32.dll"), "EnableNonClientDpiScaling");
if (en) {
en(hWnd);
}
@@ -716,14 +722,14 @@ bool Win32Window::HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam) {
}
std::unique_ptr<ui::MenuItem> MenuItem::Create(Type type,
const std::wstring& text,
const std::wstring& hotkey,
const std::string& text,
const std::string& hotkey,
std::function<void()> callback) {
return std::make_unique<Win32MenuItem>(type, text, hotkey, callback);
}
Win32MenuItem::Win32MenuItem(Type type, const std::wstring& text,
const std::wstring& hotkey,
Win32MenuItem::Win32MenuItem(Type type, const std::string& text,
const std::string& hotkey,
std::function<void()> callback)
: MenuItem(type, text, hotkey, std::move(callback)) {
switch (type) {
@@ -777,9 +783,9 @@ void Win32MenuItem::OnChildAdded(MenuItem* generic_child_item) {
// Nothing special.
break;
case MenuItem::Type::kPopup:
AppendMenuW(handle_, MF_POPUP,
reinterpret_cast<UINT_PTR>(child_item->handle()),
child_item->text().c_str());
AppendMenuW(
handle_, MF_POPUP, reinterpret_cast<UINT_PTR>(child_item->handle()),
reinterpret_cast<LPCWSTR>(xe::to_utf16(child_item->text()).c_str()));
break;
case MenuItem::Type::kSeparator:
AppendMenuW(handle_, MF_SEPARATOR, UINT_PTR(child_item->handle_), 0);
@@ -787,10 +793,10 @@ void Win32MenuItem::OnChildAdded(MenuItem* generic_child_item) {
case MenuItem::Type::kString:
auto full_name = child_item->text();
if (!child_item->hotkey().empty()) {
full_name += L"\t" + child_item->hotkey();
full_name += "\t" + child_item->hotkey();
}
AppendMenuW(handle_, MF_STRING, UINT_PTR(child_item->handle_),
full_name.c_str());
reinterpret_cast<LPCWSTR>(xe::to_utf16(full_name).c_str()));
break;
}
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -13,6 +13,7 @@
#include <memory>
#include <string>
#include "xenia/base/platform_win.h"
#include "xenia/ui/menu_item.h"
#include "xenia/ui/window.h"
@@ -23,7 +24,7 @@ class Win32Window : public Window {
using super = Window;
public:
Win32Window(Loop* loop, const std::wstring& title);
Win32Window(Loop* loop, const std::string& title);
~Win32Window() override;
NativePlatformHandle native_platform_handle() const override;
@@ -33,7 +34,7 @@ class Win32Window : public Window {
void EnableMainMenu() override;
void DisableMainMenu() override;
bool set_title(const std::wstring& title) override;
bool set_title(const std::string& title) override;
bool SetIcon(const void* buffer, size_t size) override;
@@ -92,7 +93,7 @@ class Win32Window : public Window {
class Win32MenuItem : public MenuItem {
public:
Win32MenuItem(Type type, const std::wstring& text, const std::wstring& hotkey,
Win32MenuItem(Type type, const std::string& text, const std::string& hotkey,
std::function<void()> callback);
~Win32MenuItem() override;