This commit is contained in:
Morten Delenk 2016-08-09 20:28:11 +02:00
parent 252f89d17e
commit 8cc9b803da
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
12 changed files with 128 additions and 107 deletions

View file

@ -1,5 +1,4 @@
#include <nall/platform.hpp> #include <nall/platform.hpp>
#include <nall/config.hpp>
#include <nall/directory.hpp> #include <nall/directory.hpp>
#include <nall/function.hpp> #include <nall/function.hpp>
#include <nall/image.hpp> #include <nall/image.hpp>

View file

@ -42,9 +42,6 @@ auto pApplication::initialize() -> void {
display = XOpenDisplay(nullptr); display = XOpenDisplay(nullptr);
#endif #endif
settings = new Settings;
settings->load();
//set WM_CLASS to Application::name() //set WM_CLASS to Application::name()
if(Application::state.name) gdk_set_program_class(Application::state.name); if(Application::state.name) gdk_set_program_class(Application::state.name);

View file

@ -8,7 +8,7 @@ auto pKeyboard::poll() -> vector<bool> {
#if defined(DISPLAY_XORG) #if defined(DISPLAY_XORG)
XQueryKeymap(pApplication::display, state); XQueryKeymap(pApplication::display, state);
#endif #endif
for(auto& code : settings->keycodes) { for(auto& code : settings.keycodes) {
result.append(_pressed(state, code)); result.append(_pressed(state, code));
} }
return result; return result;
@ -227,7 +227,7 @@ auto pKeyboard::initialize() -> void {
lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::display, lo) : 0; lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::display, lo) : 0;
hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::display, hi) : 0; hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::display, hi) : 0;
#endif #endif
settings->keycodes.append(lo | (hi << 8)); settings.keycodes.append(lo | (hi << 8));
}; };
#define map(name, ...) if(key == name) { append(__VA_ARGS__); continue; } #define map(name, ...) if(key == name) { append(__VA_ARGS__); continue; }

View file

@ -1,26 +1,38 @@
namespace hiro { namespace hiro {
Settings::Settings() { Settings::Settings() {
geometry.append(geometry.frameX = 4, "FrameX"); string path = {Path::local(), "hiro/"};
geometry.append(geometry.frameY = 24, "FrameY"); auto document = BML::unserialize(file::read({path, "gtk.bml"}));
geometry.append(geometry.frameWidth = 8, "FrameWidth");
geometry.append(geometry.frameHeight = 28, "FrameHeight"); auto get = [&](string_view name) {
geometry.append(geometry.menuHeight = 20, "MenuHeight"); return document[name];
geometry.append(geometry.statusHeight = 20, "StatusHeight"); };
append(geometry, "Geometry");
window.append(window.backgroundColor = 0xedeceb, "BackgroundColor"); geometry.frameX = get("Geometry/FrameX").integer();
append(window, "Window"); geometry.frameY = get("Geometry/FrameY").integer();
geometry.frameWidth = get("Geometry/FrameWidth").integer();
geometry.frameHeight = get("Geometry/FrameHeight").integer();
geometry.menuHeight = get("Geometry/MenuHeight").integer();
geometry.statusHeight = get("Geometry/StatusHeight").integer();
} }
auto Settings::load() -> void { Settings::~Settings() {
string path = {Path::config(), "hiro/"}; string path = {Path::local(), "hiro/"};
Configuration::Document::load({path, "gtk.bml"});
}
auto Settings::save() -> void {
string path = {Path::config(), "hiro/"};
directory::create(path, 0755); directory::create(path, 0755);
Configuration::Document::save({path, "gtk.bml"});
Markup::Node document;
auto set = [&](string_view name, string_view value) {
document(name).setValue(value);
};
set("Geometry/FrameX", geometry.frameX);
set("Geometry/FrameY", geometry.frameY);
set("Geometry/FrameWidth", geometry.frameWidth);
set("Geometry/FrameHeight", geometry.frameHeight);
set("Geometry/MenuHeight", geometry.menuHeight);
set("Geometry/StatusHeight", geometry.statusHeight);
file::write({path, "gtk.bml"}, BML::serialize(document));
} }
} }

View file

@ -1,26 +1,21 @@
namespace hiro { namespace hiro {
struct Settings : Configuration::Document { struct Settings {
Settings();
~Settings();
vector<uint16_t> keycodes; vector<uint16_t> keycodes;
struct Geometry : Configuration::Node { struct Geometry {
signed frameX; int frameX = 4;
signed frameY; int frameY = 24;
signed frameWidth; int frameWidth = 8;
signed frameHeight; int frameHeight = 28;
signed menuHeight; int menuHeight = 20;
signed statusHeight; int statusHeight = 20;
} geometry; } geometry;
struct Window : Configuration::Node {
unsigned backgroundColor;
} window;
Settings();
auto load() -> void;
auto save() -> void;
}; };
static Settings* settings = nullptr; static Settings settings;
} }

View file

@ -48,11 +48,10 @@ static auto Window_configure(GtkWidget* widget, GdkEvent* event, pWindow* p) ->
if(!p->state().fullScreen) { if(!p->state().fullScreen) {
//update geometry settings //update geometry settings
settings->geometry.frameX = client.x - border.x; settings.geometry.frameX = client.x - border.x;
settings->geometry.frameY = client.y - border.y; settings.geometry.frameY = client.y - border.y;
settings->geometry.frameWidth = border.width - client.width; settings.geometry.frameWidth = border.width - client.width;
settings->geometry.frameHeight = border.height - client.height; settings.geometry.frameHeight = border.height - client.height;
settings->save();
} }
Geometry geometry = { Geometry geometry = {
@ -212,10 +211,10 @@ auto pWindow::frameMargin() const -> Geometry {
}; };
return { return {
settings->geometry.frameX, settings.geometry.frameX,
settings->geometry.frameY + _menuHeight(), settings.geometry.frameY + _menuHeight(),
settings->geometry.frameWidth, settings.geometry.frameWidth,
settings->geometry.frameHeight + _menuHeight() + _statusHeight() settings.geometry.frameHeight + _menuHeight() + _statusHeight()
}; };
} }
@ -328,13 +327,13 @@ auto pWindow::setVisible(bool visible) -> void {
if(gtk_widget_get_visible(gtkMenu)) { if(gtk_widget_get_visible(gtkMenu)) {
GtkAllocation allocation; GtkAllocation allocation;
gtk_widget_get_allocation(gtkMenu, &allocation); gtk_widget_get_allocation(gtkMenu, &allocation);
settings->geometry.menuHeight = allocation.height; settings.geometry.menuHeight = allocation.height;
} }
if(gtk_widget_get_visible(gtkStatus)) { if(gtk_widget_get_visible(gtkStatus)) {
GtkAllocation allocation; GtkAllocation allocation;
gtk_widget_get_allocation(gtkStatus, &allocation); gtk_widget_get_allocation(gtkStatus, &allocation);
settings->geometry.statusHeight = allocation.height; settings.geometry.statusHeight = allocation.height;
} }
} }
@ -358,7 +357,7 @@ auto pWindow::_append(mMenu& menu) -> void {
} }
auto pWindow::_menuHeight() const -> signed { auto pWindow::_menuHeight() const -> signed {
return gtk_widget_get_visible(gtkMenu) ? settings->geometry.menuHeight : 0; return gtk_widget_get_visible(gtkMenu) ? settings.geometry.menuHeight : 0;
} }
auto pWindow::_setIcon(const string& pathname) -> bool { auto pWindow::_setIcon(const string& pathname) -> bool {
@ -414,7 +413,7 @@ auto pWindow::_setStatusVisible(bool visible) -> void {
} }
auto pWindow::_statusHeight() const -> signed { auto pWindow::_statusHeight() const -> signed {
return gtk_widget_get_visible(gtkStatus) ? settings->geometry.statusHeight : 0; return gtk_widget_get_visible(gtkStatus) ? settings.geometry.statusHeight : 0;
} }
} }

View file

@ -41,9 +41,6 @@ auto pApplication::syncX() -> void {
auto pApplication::initialize() -> void { auto pApplication::initialize() -> void {
display = XOpenDisplay(0); display = XOpenDisplay(0);
settings = new Settings;
settings->load();
static int argc = 1; static int argc = 1;
static char* argv[] = {new char[8], nullptr}; static char* argv[] = {new char[8], nullptr};
strcpy(argv[0], "hiro"); strcpy(argv[0], "hiro");

View file

@ -6,7 +6,7 @@ auto pKeyboard::poll() -> vector<bool> {
vector<bool> result; vector<bool> result;
char state[256]; char state[256];
XQueryKeymap(pApplication::display, state); XQueryKeymap(pApplication::display, state);
for(auto& code : settings->keycodes) { for(auto& code : settings.keycodes) {
result.append(_pressed(state, code)); result.append(_pressed(state, code));
} }
return result; return result;
@ -32,7 +32,7 @@ auto pKeyboard::initialize() -> void {
auto append = [](unsigned lo, unsigned hi = 0) { auto append = [](unsigned lo, unsigned hi = 0) {
lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::display, lo) : 0; lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::display, lo) : 0;
hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::display, hi) : 0; hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::display, hi) : 0;
settings->keycodes.append(lo << 0 | hi << 8); settings.keycodes.append(lo << 0 | hi << 8);
}; };
#define map(name, ...) if(key == name) { append(__VA_ARGS__); continue; } #define map(name, ...) if(key == name) { append(__VA_ARGS__); continue; }

View file

@ -1,26 +1,38 @@
namespace hiro { namespace hiro {
static Settings* settings = nullptr;
Settings::Settings() { Settings::Settings() {
geometry.append(geometry.frameX = 4, "FrameX"); string path = {Path::local(), "hiro/"};
geometry.append(geometry.frameY = 24, "FrameY"); auto document = BML::unserialize(file::read({path, "qt.bml"}));
geometry.append(geometry.frameWidth = 8, "FrameWidth");
geometry.append(geometry.frameHeight = 28, "FrameHeight"); auto get = [&](string_view name) {
geometry.append(geometry.menuHeight = 20, "MenuHeight"); return document[name];
geometry.append(geometry.statusHeight = 20, "StatusHeight"); };
append(geometry, "Geometry");
geometry.frameX = get("Geometry/FrameX").integer();
geometry.frameY = get("Geometry/FrameY").integer();
geometry.frameWidth = get("Geometry/FrameWidth").integer();
geometry.frameHeight = get("Geometry/FrameHeight").integer();
geometry.menuHeight = get("Geometry/MenuHeight").integer();
geometry.statusHeight = get("Geometry/StatusHeight").integer();
} }
auto Settings::load() -> void { Settings::~Settings() {
string path{Path::config(), "hiro/"}; string path = {Path::local(), "hiro/"};
Configuration::Document::load({path, "qt.bml"});
}
auto Settings::save() -> void {
string path{Path::config(), "hiro/"};
directory::create(path, 0755); directory::create(path, 0755);
Configuration::Document::save({path, "qt.bml"});
Markup::Node document;
auto set = [&](string_view name, string_view value) {
document(name).setValue(value);
};
set("Geometry/FrameX", geometry.frameX);
set("Geometry/FrameY", geometry.frameY);
set("Geometry/FrameWidth", geometry.frameWidth);
set("Geometry/FrameHeight", geometry.frameHeight);
set("Geometry/MenuHeight", geometry.menuHeight);
set("Geometry/StatusHeight", geometry.statusHeight);
file::write({path, "qt.bml"}, BML::serialize(document));
} }
} }

View file

@ -1,20 +1,21 @@
namespace hiro { namespace hiro {
struct Settings : Configuration::Document { struct Settings {
Settings();
~Settings();
vector<uint16_t> keycodes; vector<uint16_t> keycodes;
struct Geometry : Configuration::Node { struct Geometry {
signed frameX; int frameX = 4;
signed frameY; int frameY = 24;
signed frameWidth; int frameWidth = 8;
signed frameHeight; int frameHeight = 28;
signed menuHeight; int menuHeight = 20;
signed statusHeight; int statusHeight = 20;
} geometry; } geometry;
Settings();
auto load() -> void;
auto save() -> void;
}; };
static Settings settings;
} }

View file

@ -70,10 +70,10 @@ auto pWindow::frameMargin() const -> Geometry {
0, _menuHeight() + _statusHeight() 0, _menuHeight() + _statusHeight()
}; };
return { return {
settings->geometry.frameX, settings.geometry.frameX,
settings->geometry.frameY + _menuHeight(), settings.geometry.frameY + _menuHeight(),
settings->geometry.frameWidth, settings.geometry.frameWidth,
settings->geometry.frameHeight + _menuHeight() + _statusHeight() settings.geometry.frameHeight + _menuHeight() + _statusHeight()
}; };
} }
@ -215,11 +215,11 @@ auto pWindow::_append(mWidget& widget) -> void {
} }
auto pWindow::_menuHeight() const -> signed { auto pWindow::_menuHeight() const -> signed {
return qtMenuBar->isVisible() ? settings->geometry.menuHeight : 0; return qtMenuBar->isVisible() ? settings.geometry.menuHeight : 0;
} }
auto pWindow::_statusHeight() const -> signed { auto pWindow::_statusHeight() const -> signed {
return qtStatusBar->isVisible() ? settings->geometry.statusHeight : 0; return qtStatusBar->isVisible() ? settings.geometry.statusHeight : 0;
} }
auto pWindow::_updateFrameGeometry() -> void { auto pWindow::_updateFrameGeometry() -> void {
@ -227,22 +227,20 @@ auto pWindow::_updateFrameGeometry() -> void {
QRect border = qtWindow->frameGeometry(); QRect border = qtWindow->frameGeometry();
QRect client = qtWindow->geometry(); QRect client = qtWindow->geometry();
settings->geometry.frameX = client.x() - border.x(); settings.geometry.frameX = client.x() - border.x();
settings->geometry.frameY = client.y() - border.y(); settings.geometry.frameY = client.y() - border.y();
settings->geometry.frameWidth = border.width() - client.width(); settings.geometry.frameWidth = border.width() - client.width();
settings->geometry.frameHeight = border.height() - client.height(); settings.geometry.frameHeight = border.height() - client.height();
if(qtMenuBar->isVisible()) { if(qtMenuBar->isVisible()) {
pApplication::syncX(); pApplication::syncX();
settings->geometry.menuHeight = qtMenuBar->height(); settings.geometry.menuHeight = qtMenuBar->height();
} }
if(qtStatusBar->isVisible()) { if(qtStatusBar->isVisible()) {
pApplication::syncX(); pApplication::syncX();
settings->geometry.statusHeight = qtStatusBar->height(); settings.geometry.statusHeight = qtStatusBar->height();
} }
settings->save();
} }
auto QtWindow::closeEvent(QCloseEvent* event) -> void { auto QtWindow::closeEvent(QCloseEvent* event) -> void {
@ -305,8 +303,8 @@ auto QtWindow::resizeEvent(QResizeEvent*) -> void {
auto QtWindow::sizeHint() const -> QSize { auto QtWindow::sizeHint() const -> QSize {
unsigned width = p.state().geometry.width(); unsigned width = p.state().geometry.width();
unsigned height = p.state().geometry.height(); unsigned height = p.state().geometry.height();
if(p.qtMenuBar->isVisible()) height += settings->geometry.menuHeight; if(p.qtMenuBar->isVisible()) height += settings.geometry.menuHeight;
if(p.qtStatusBar->isVisible()) height += settings->geometry.statusHeight; if(p.qtStatusBar->isVisible()) height += settings.geometry.statusHeight;
return QSize(width, height); return QSize(width, height);
} }

View file

@ -44,19 +44,30 @@ static auto CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
BeginPaint(hwnd, &ps); BeginPaint(hwnd, &ps);
RECT rc; RECT rc;
GetClientRect(hwnd, &rc); GetClientRect(hwnd, &rc);
//todo: use DrawThemeParentBackground if Label is inside TabFrame
if(auto brush = window->self()->hbrush) {
FillRect(ps.hdc, &rc, brush);
} else {
DrawThemeParentBackground(hwnd, ps.hdc, &rc); DrawThemeParentBackground(hwnd, ps.hdc, &rc);
}
SetBkMode(ps.hdc, TRANSPARENT); SetBkMode(ps.hdc, TRANSPARENT);
SelectObject(ps.hdc, label->self()->hfont); SelectObject(ps.hdc, label->self()->hfont);
unsigned length = GetWindowTextLength(hwnd); uint length = GetWindowTextLength(hwnd);
wchar_t text[length + 1]; wchar_t text[length + 1];
GetWindowText(hwnd, text, length + 1); GetWindowText(hwnd, text, length + 1);
text[length] = 0; text[length] = 0;
DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS); DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS);
unsigned height = rc.bottom; uint height = rc.bottom;
GetClientRect(hwnd, &rc); GetClientRect(hwnd, &rc);
rc.top = (rc.bottom - height) / 2; rc.top = (rc.bottom - height) / 2;
rc.bottom = rc.top + height; rc.bottom = rc.top + height;
DrawText(ps.hdc, text, -1, &rc, DT_LEFT | DT_END_ELLIPSIS); uint horizontalAlignment = DT_CENTER;
if(label->alignment().horizontal() < 0.333) horizontalAlignment = DT_LEFT;
if(label->alignment().horizontal() > 0.666) horizontalAlignment = DT_RIGHT;
uint verticalAlignment = DT_VCENTER;
if(label->alignment().vertical() < 0.333) verticalAlignment = DT_TOP;
if(label->alignment().vertical() > 0.666) verticalAlignment = DT_BOTTOM;
DrawText(ps.hdc, text, -1, &rc, DT_END_ELLIPSIS | horizontalAlignment | verticalAlignment);
EndPaint(hwnd, &ps); EndPaint(hwnd, &ps);
return false; return false;
} }