More string conversion.

This commit is contained in:
Ben Vanik
2014-08-16 02:50:08 -07:00
parent a4dfc23abc
commit 66d2336e38
11 changed files with 94 additions and 121 deletions

View File

@@ -53,7 +53,8 @@ Win32Window::~Win32Window() {
}
}
int Win32Window::Initialize(const char* title, uint32_t width, uint32_t height) {
int Win32Window::Initialize(const std::wstring& title, uint32_t width,
uint32_t height) {
int result = Window::Initialize(title, width, height);
if (result) {
return result;
@@ -164,11 +165,11 @@ void Win32Window::EnableMMCSS() {
FreeLibrary(hLibrary);
}
bool Win32Window::set_title(const char* title) {
bool Win32Window::set_title(const std::wstring& title) {
if (!Window::set_title(title)) {
return false;
}
XEIGNORE(SetWindowTextA(handle_, title));
XEIGNORE(SetWindowText(handle_, title.c_str()));
return true;
}

View File

@@ -10,46 +10,45 @@
#ifndef XENIA_UI_WIN32_WIN32_WINDOW_H_
#define XENIA_UI_WIN32_WIN32_WINDOW_H_
#include <string>
#include <xenia/core.h>
#include <xenia/ui/window.h>
namespace xe {
namespace ui {
namespace win32 {
class Win32Window : public Window {
public:
public:
Win32Window(xe_run_loop_ref run_loop);
virtual ~Win32Window();
~Win32Window() override;
virtual int Initialize(const char* title, uint32_t width, uint32_t height);
int Initialize(const std::wstring& title, uint32_t width,
uint32_t height) override;
virtual bool set_title(const char* title);
virtual bool set_cursor_visible(bool value);
bool set_title(const std::wstring& title) override;
bool set_cursor_visible(bool value) override;
HWND handle() const { return handle_; }
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
protected:
virtual bool SetSize(uint32_t width, uint32_t height);
virtual void OnClose();
protected:
bool SetSize(uint32_t width, uint32_t height) override;
void OnClose() override;
private:
private:
void EnableMMCSS();
bool HandleMouse(UINT message, WPARAM wParam, LPARAM lParam);
bool HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam);
HWND handle_;
bool closing_;
HWND handle_;
bool closing_;
};
} // namespace win32
} // namespace ui
} // namespace xe
#endif // XENIA_UI_WIN32_WIN32_WINDOW_H_

View File

@@ -9,39 +9,33 @@
#include <xenia/ui/window.h>
using namespace xe;
using namespace xe::ui;
Window::Window(xe_run_loop_ref run_loop) :
title_(0), is_visible_(true), is_cursor_visible_(true),
width_(0), height_(0) {
Window::Window(xe_run_loop_ref run_loop)
: title_(L"Window"),
is_visible_(true),
is_cursor_visible_(true),
width_(0),
height_(0) {
run_loop_ = xe_run_loop_retain(run_loop);
}
Window::~Window() {
if (title_) {
xe_free(title_);
}
xe_run_loop_release(run_loop_);
}
Window::~Window() { xe_run_loop_release(run_loop_); }
int Window::Initialize(const char* title, uint32_t width, uint32_t height) {
title_ = xestrdupa(title);
int Window::Initialize(const std::wstring& title, uint32_t width,
uint32_t height) {
title_ = title;
width_ = width;
height_ = height;
return 0;
}
bool Window::set_title(const char* title) {
bool Window::set_title(const std::wstring& title) {
if (title == title_) {
return false;
}
if (title_) {
xe_free(title_);
}
title_ = xestrdupa(title);
title_ = title;
return true;
}
@@ -74,7 +68,7 @@ void Window::OnHide() {
void Window::Resize(uint32_t width, uint32_t height) {
BeginResizing();
SetSize(width, height);
OnResize(width, height); // redundant?
OnResize(width, height); // redundant?
EndResizing();
}
@@ -116,5 +110,4 @@ void Window::Close() {
closed(e);
}
void Window::OnClose() {
}
void Window::OnClose() {}

View File

@@ -10,27 +10,28 @@
#ifndef XENIA_UI_WINDOW_H_
#define XENIA_UI_WINDOW_H_
#include <string>
#include <xenia/core.h>
#include <alloy/delegate.h>
#include <xenia/ui/ui_event.h>
namespace xe {
namespace ui {
class Window {
public:
public:
Window(xe_run_loop_ref run_loop);
virtual ~Window();
virtual int Initialize(const char* title, uint32_t width, uint32_t height);
virtual int Initialize(const std::wstring& title, uint32_t width,
uint32_t height);
xe_run_loop_ref run_loop() const { return run_loop_; }
const char* title() const { return title_; }
virtual bool set_title(const char* title);
const std::wstring& title() const { return title_; }
virtual bool set_title(const std::wstring& title);
bool is_visible() const { return is_visible_; }
bool is_cursor_visible() const { return is_cursor_visible_; }
virtual bool set_cursor_visible(bool value);
@@ -40,7 +41,7 @@ public:
void Close();
public:
public:
alloy::Delegate<UIEvent> shown;
alloy::Delegate<UIEvent> hidden;
alloy::Delegate<UIEvent> resizing;
@@ -56,7 +57,7 @@ public:
alloy::Delegate<MouseEvent> mouse_up;
alloy::Delegate<MouseEvent> mouse_wheel;
protected:
protected:
void OnShow();
void OnHide();
@@ -67,19 +68,17 @@ protected:
virtual void OnClose();
private:
private:
xe_run_loop_ref run_loop_;
char* title_;
bool is_visible_;
bool is_cursor_visible_;
bool resizing_;
uint32_t width_;
uint32_t height_;
std::wstring title_;
bool is_visible_;
bool is_cursor_visible_;
bool resizing_;
uint32_t width_;
uint32_t height_;
};
} // namespace ui
} // namespace xe
#endif // XENIA_UI_WINDOW_H_