v101r02
This commit is contained in:
parent
252f89d17e
commit
8cc9b803da
12 changed files with 128 additions and 107 deletions
|
@ -1,5 +1,4 @@
|
|||
#include <nall/platform.hpp>
|
||||
#include <nall/config.hpp>
|
||||
#include <nall/directory.hpp>
|
||||
#include <nall/function.hpp>
|
||||
#include <nall/image.hpp>
|
||||
|
|
|
@ -42,9 +42,6 @@ auto pApplication::initialize() -> void {
|
|||
display = XOpenDisplay(nullptr);
|
||||
#endif
|
||||
|
||||
settings = new Settings;
|
||||
settings->load();
|
||||
|
||||
//set WM_CLASS to Application::name()
|
||||
if(Application::state.name) gdk_set_program_class(Application::state.name);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ auto pKeyboard::poll() -> vector<bool> {
|
|||
#if defined(DISPLAY_XORG)
|
||||
XQueryKeymap(pApplication::display, state);
|
||||
#endif
|
||||
for(auto& code : settings->keycodes) {
|
||||
for(auto& code : settings.keycodes) {
|
||||
result.append(_pressed(state, code));
|
||||
}
|
||||
return result;
|
||||
|
@ -227,7 +227,7 @@ auto pKeyboard::initialize() -> void {
|
|||
lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::display, lo) : 0;
|
||||
hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::display, hi) : 0;
|
||||
#endif
|
||||
settings->keycodes.append(lo | (hi << 8));
|
||||
settings.keycodes.append(lo | (hi << 8));
|
||||
};
|
||||
|
||||
#define map(name, ...) if(key == name) { append(__VA_ARGS__); continue; }
|
||||
|
|
|
@ -1,26 +1,38 @@
|
|||
namespace hiro {
|
||||
|
||||
Settings::Settings() {
|
||||
geometry.append(geometry.frameX = 4, "FrameX");
|
||||
geometry.append(geometry.frameY = 24, "FrameY");
|
||||
geometry.append(geometry.frameWidth = 8, "FrameWidth");
|
||||
geometry.append(geometry.frameHeight = 28, "FrameHeight");
|
||||
geometry.append(geometry.menuHeight = 20, "MenuHeight");
|
||||
geometry.append(geometry.statusHeight = 20, "StatusHeight");
|
||||
append(geometry, "Geometry");
|
||||
window.append(window.backgroundColor = 0xedeceb, "BackgroundColor");
|
||||
append(window, "Window");
|
||||
string path = {Path::local(), "hiro/"};
|
||||
auto document = BML::unserialize(file::read({path, "gtk.bml"}));
|
||||
|
||||
auto get = [&](string_view name) {
|
||||
return document[name];
|
||||
};
|
||||
|
||||
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 {
|
||||
string path = {Path::config(), "hiro/"};
|
||||
Configuration::Document::load({path, "gtk.bml"});
|
||||
}
|
||||
|
||||
auto Settings::save() -> void {
|
||||
string path = {Path::config(), "hiro/"};
|
||||
Settings::~Settings() {
|
||||
string path = {Path::local(), "hiro/"};
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
namespace hiro {
|
||||
|
||||
struct Settings : Configuration::Document {
|
||||
struct Settings {
|
||||
Settings();
|
||||
~Settings();
|
||||
|
||||
vector<uint16_t> keycodes;
|
||||
|
||||
struct Geometry : Configuration::Node {
|
||||
signed frameX;
|
||||
signed frameY;
|
||||
signed frameWidth;
|
||||
signed frameHeight;
|
||||
signed menuHeight;
|
||||
signed statusHeight;
|
||||
struct Geometry {
|
||||
int frameX = 4;
|
||||
int frameY = 24;
|
||||
int frameWidth = 8;
|
||||
int frameHeight = 28;
|
||||
int menuHeight = 20;
|
||||
int statusHeight = 20;
|
||||
} geometry;
|
||||
|
||||
struct Window : Configuration::Node {
|
||||
unsigned backgroundColor;
|
||||
} window;
|
||||
|
||||
Settings();
|
||||
auto load() -> void;
|
||||
auto save() -> void;
|
||||
};
|
||||
|
||||
static Settings* settings = nullptr;
|
||||
static Settings settings;
|
||||
|
||||
}
|
||||
|
|
|
@ -48,11 +48,10 @@ static auto Window_configure(GtkWidget* widget, GdkEvent* event, pWindow* p) ->
|
|||
|
||||
if(!p->state().fullScreen) {
|
||||
//update geometry settings
|
||||
settings->geometry.frameX = client.x - border.x;
|
||||
settings->geometry.frameY = client.y - border.y;
|
||||
settings->geometry.frameWidth = border.width - client.width;
|
||||
settings->geometry.frameHeight = border.height - client.height;
|
||||
settings->save();
|
||||
settings.geometry.frameX = client.x - border.x;
|
||||
settings.geometry.frameY = client.y - border.y;
|
||||
settings.geometry.frameWidth = border.width - client.width;
|
||||
settings.geometry.frameHeight = border.height - client.height;
|
||||
}
|
||||
|
||||
Geometry geometry = {
|
||||
|
@ -212,10 +211,10 @@ auto pWindow::frameMargin() const -> Geometry {
|
|||
};
|
||||
|
||||
return {
|
||||
settings->geometry.frameX,
|
||||
settings->geometry.frameY + _menuHeight(),
|
||||
settings->geometry.frameWidth,
|
||||
settings->geometry.frameHeight + _menuHeight() + _statusHeight()
|
||||
settings.geometry.frameX,
|
||||
settings.geometry.frameY + _menuHeight(),
|
||||
settings.geometry.frameWidth,
|
||||
settings.geometry.frameHeight + _menuHeight() + _statusHeight()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -328,13 +327,13 @@ auto pWindow::setVisible(bool visible) -> void {
|
|||
if(gtk_widget_get_visible(gtkMenu)) {
|
||||
GtkAllocation allocation;
|
||||
gtk_widget_get_allocation(gtkMenu, &allocation);
|
||||
settings->geometry.menuHeight = allocation.height;
|
||||
settings.geometry.menuHeight = allocation.height;
|
||||
}
|
||||
|
||||
if(gtk_widget_get_visible(gtkStatus)) {
|
||||
GtkAllocation 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 {
|
||||
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 {
|
||||
|
@ -414,7 +413,7 @@ auto pWindow::_setStatusVisible(bool visible) -> void {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,9 +41,6 @@ auto pApplication::syncX() -> void {
|
|||
auto pApplication::initialize() -> void {
|
||||
display = XOpenDisplay(0);
|
||||
|
||||
settings = new Settings;
|
||||
settings->load();
|
||||
|
||||
static int argc = 1;
|
||||
static char* argv[] = {new char[8], nullptr};
|
||||
strcpy(argv[0], "hiro");
|
||||
|
|
|
@ -6,7 +6,7 @@ auto pKeyboard::poll() -> vector<bool> {
|
|||
vector<bool> result;
|
||||
char state[256];
|
||||
XQueryKeymap(pApplication::display, state);
|
||||
for(auto& code : settings->keycodes) {
|
||||
for(auto& code : settings.keycodes) {
|
||||
result.append(_pressed(state, code));
|
||||
}
|
||||
return result;
|
||||
|
@ -32,7 +32,7 @@ auto pKeyboard::initialize() -> void {
|
|||
auto append = [](unsigned lo, unsigned hi = 0) {
|
||||
lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::display, lo) : 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; }
|
||||
|
|
|
@ -1,26 +1,38 @@
|
|||
namespace hiro {
|
||||
|
||||
static Settings* settings = nullptr;
|
||||
|
||||
Settings::Settings() {
|
||||
geometry.append(geometry.frameX = 4, "FrameX");
|
||||
geometry.append(geometry.frameY = 24, "FrameY");
|
||||
geometry.append(geometry.frameWidth = 8, "FrameWidth");
|
||||
geometry.append(geometry.frameHeight = 28, "FrameHeight");
|
||||
geometry.append(geometry.menuHeight = 20, "MenuHeight");
|
||||
geometry.append(geometry.statusHeight = 20, "StatusHeight");
|
||||
append(geometry, "Geometry");
|
||||
string path = {Path::local(), "hiro/"};
|
||||
auto document = BML::unserialize(file::read({path, "qt.bml"}));
|
||||
|
||||
auto get = [&](string_view name) {
|
||||
return document[name];
|
||||
};
|
||||
|
||||
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 {
|
||||
string path{Path::config(), "hiro/"};
|
||||
Configuration::Document::load({path, "qt.bml"});
|
||||
}
|
||||
|
||||
auto Settings::save() -> void {
|
||||
string path{Path::config(), "hiro/"};
|
||||
Settings::~Settings() {
|
||||
string path = {Path::local(), "hiro/"};
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
namespace hiro {
|
||||
|
||||
struct Settings : Configuration::Document {
|
||||
struct Settings {
|
||||
Settings();
|
||||
~Settings();
|
||||
|
||||
vector<uint16_t> keycodes;
|
||||
|
||||
struct Geometry : Configuration::Node {
|
||||
signed frameX;
|
||||
signed frameY;
|
||||
signed frameWidth;
|
||||
signed frameHeight;
|
||||
signed menuHeight;
|
||||
signed statusHeight;
|
||||
struct Geometry {
|
||||
int frameX = 4;
|
||||
int frameY = 24;
|
||||
int frameWidth = 8;
|
||||
int frameHeight = 28;
|
||||
int menuHeight = 20;
|
||||
int statusHeight = 20;
|
||||
} geometry;
|
||||
|
||||
Settings();
|
||||
auto load() -> void;
|
||||
auto save() -> void;
|
||||
};
|
||||
|
||||
static Settings settings;
|
||||
|
||||
}
|
||||
|
|
|
@ -70,10 +70,10 @@ auto pWindow::frameMargin() const -> Geometry {
|
|||
0, _menuHeight() + _statusHeight()
|
||||
};
|
||||
return {
|
||||
settings->geometry.frameX,
|
||||
settings->geometry.frameY + _menuHeight(),
|
||||
settings->geometry.frameWidth,
|
||||
settings->geometry.frameHeight + _menuHeight() + _statusHeight()
|
||||
settings.geometry.frameX,
|
||||
settings.geometry.frameY + _menuHeight(),
|
||||
settings.geometry.frameWidth,
|
||||
settings.geometry.frameHeight + _menuHeight() + _statusHeight()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -215,11 +215,11 @@ auto pWindow::_append(mWidget& widget) -> void {
|
|||
}
|
||||
|
||||
auto pWindow::_menuHeight() const -> signed {
|
||||
return qtMenuBar->isVisible() ? settings->geometry.menuHeight : 0;
|
||||
return qtMenuBar->isVisible() ? settings.geometry.menuHeight : 0;
|
||||
}
|
||||
|
||||
auto pWindow::_statusHeight() const -> signed {
|
||||
return qtStatusBar->isVisible() ? settings->geometry.statusHeight : 0;
|
||||
return qtStatusBar->isVisible() ? settings.geometry.statusHeight : 0;
|
||||
}
|
||||
|
||||
auto pWindow::_updateFrameGeometry() -> void {
|
||||
|
@ -227,22 +227,20 @@ auto pWindow::_updateFrameGeometry() -> void {
|
|||
QRect border = qtWindow->frameGeometry();
|
||||
QRect client = qtWindow->geometry();
|
||||
|
||||
settings->geometry.frameX = client.x() - border.x();
|
||||
settings->geometry.frameY = client.y() - border.y();
|
||||
settings->geometry.frameWidth = border.width() - client.width();
|
||||
settings->geometry.frameHeight = border.height() - client.height();
|
||||
settings.geometry.frameX = client.x() - border.x();
|
||||
settings.geometry.frameY = client.y() - border.y();
|
||||
settings.geometry.frameWidth = border.width() - client.width();
|
||||
settings.geometry.frameHeight = border.height() - client.height();
|
||||
|
||||
if(qtMenuBar->isVisible()) {
|
||||
pApplication::syncX();
|
||||
settings->geometry.menuHeight = qtMenuBar->height();
|
||||
settings.geometry.menuHeight = qtMenuBar->height();
|
||||
}
|
||||
|
||||
if(qtStatusBar->isVisible()) {
|
||||
pApplication::syncX();
|
||||
settings->geometry.statusHeight = qtStatusBar->height();
|
||||
settings.geometry.statusHeight = qtStatusBar->height();
|
||||
}
|
||||
|
||||
settings->save();
|
||||
}
|
||||
|
||||
auto QtWindow::closeEvent(QCloseEvent* event) -> void {
|
||||
|
@ -305,8 +303,8 @@ auto QtWindow::resizeEvent(QResizeEvent*) -> void {
|
|||
auto QtWindow::sizeHint() const -> QSize {
|
||||
unsigned width = p.state().geometry.width();
|
||||
unsigned height = p.state().geometry.height();
|
||||
if(p.qtMenuBar->isVisible()) height += settings->geometry.menuHeight;
|
||||
if(p.qtStatusBar->isVisible()) height += settings->geometry.statusHeight;
|
||||
if(p.qtMenuBar->isVisible()) height += settings.geometry.menuHeight;
|
||||
if(p.qtStatusBar->isVisible()) height += settings.geometry.statusHeight;
|
||||
return QSize(width, height);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,19 +44,30 @@ static auto CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
|
|||
BeginPaint(hwnd, &ps);
|
||||
RECT 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);
|
||||
}
|
||||
SetBkMode(ps.hdc, TRANSPARENT);
|
||||
SelectObject(ps.hdc, label->self()->hfont);
|
||||
unsigned length = GetWindowTextLength(hwnd);
|
||||
uint length = GetWindowTextLength(hwnd);
|
||||
wchar_t text[length + 1];
|
||||
GetWindowText(hwnd, text, length + 1);
|
||||
text[length] = 0;
|
||||
DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS);
|
||||
unsigned height = rc.bottom;
|
||||
uint height = rc.bottom;
|
||||
GetClientRect(hwnd, &rc);
|
||||
rc.top = (rc.bottom - height) / 2;
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue