Update to v106r47 release.

byuu says:

This is probably the largest code-change diff I've done in years.

I spent four days working 10-16 hours a day reworking layouts in hiro
completely.

The result is we now have TableLayout, which will allow for better
horizontal+vertical combined alignment.

Windows, GTK2, and now GTK3 are fully supported.

Windows is getting the initial window geometry wrong by a bit.

GTK2 and GTK3 work perfectly. I basically abandoned trying to detect
resize signals, and instead keep a list of all hiro windows that are
allocated, and every time the main loop runs, it will query all of them
to see if they've been resized. I'm disgusted that I have to do this,
but after fighting with GTK for years, I'm about sick of it. GTK was
doing this crazy thing where it would trigger another size-allocate
inside of a previous size-allocate, and so my layouts would be halfway
through resizing all the widgets, and then the size-allocate would kick
off another one. That would end up leaving the rest of the first layout
loop with bad widget sizes. And if I detected a second re-entry and
blocked it, then the entire window would end up with the older geometry.
I started trying to build a message queue system to allow the second
layout resize to occur after the first one completed, but this was just
too much madness, so I went with the simpler solution.

Qt4 has some geometry problems, and doesn't show tab frame layouts
properly yet.

Qt5 causes an ICE error and tanks my entire Xorg display server, so ...
something is seriously wrong there, and it's not hiro's fault. Creating
a dummy Qt5 application without even using hiro, just int main() {
TestObject object; } with object performing a dynamic\_cast to a derived
type segfaults. Memory is getting corrupted where GCC allocates the
vtables for classes, just by linking in Qt. Could be somehow related to
the -fPIC requirement that only Qt5 has ... could just be that FreeBSD
10.1 has a buggy implementation of Qt5. I don't know. It's beyond my
ability to debug, so this one's going to stay broken.

The Cocoa port is busted. I'll fix it up to compile again, but that's
about all I'm going to do.

Many optimizations mean bsnes and higan open faster. GTK2 and GTK3 both
resize windows very quickly now.

higan crashes when you load a game, so that's not good. bsnes works
though.

bsnes also has the start of a localization engine now. Still a long way
to go.

The makefiles received a rather substantial restructuring. Including the
ruby and hiro makefiles will add the necessary compilation rules for
you, which also means that moc will run for the qt4 and qt5 targets, and
windres will run for the Windows targets.
This commit is contained in:
Tim Allen
2018-07-14 13:59:29 +10:00
parent 0c55796060
commit 6090c63958
207 changed files with 2864 additions and 1667 deletions

View File

@@ -1,19 +0,0 @@
#if defined(Hiro_Layout)
namespace hiro {
auto pLayout::construct() -> void {
}
auto pLayout::destruct() -> void {
}
auto pLayout::setVisible(bool visible) -> void {
for(auto& sizable : state().sizables) {
if(auto self = sizable->self()) self->setVisible(sizable->visible(true));
}
}
}
#endif

View File

@@ -1,13 +0,0 @@
#if defined(Hiro_Layout)
namespace hiro {
struct pLayout : pSizable {
Declare(Layout, Sizable)
auto setVisible(bool visible) -> void override;
};
}
#endif

View File

@@ -23,6 +23,11 @@ auto pMonitor::primary() -> uint {
return QApplication::desktop()->primaryScreen();
}
auto pMonitor::workspace(uint monitor) -> Geometry {
//TODO: per-monitor?
return pDesktop::workspace();
}
}
#endif

View File

@@ -7,6 +7,7 @@ struct pMonitor {
static auto dpi(uint monitor) -> Position;
static auto geometry(uint monitor) -> Geometry;
static auto primary() -> uint;
static auto workspace(uint monitor) -> Geometry;
};
}

View File

@@ -27,6 +27,9 @@ auto pObject::setFocused() -> void {
auto pObject::setFont(const Font& font) -> void {
}
auto pObject::setParent(mObject* parent, int offset) -> void {
}
auto pObject::setVisible(bool visible) -> void {
}

View File

@@ -2,7 +2,7 @@
namespace hiro {
struct pObject {
struct pObject : mLock {
pObject(mObject& reference) : reference(reference) {}
virtual ~pObject() {}
auto self() const -> mObject& { return (mObject&)reference; }
@@ -16,14 +16,10 @@ struct pObject {
virtual auto setEnabled(bool enabled) -> void;
virtual auto setFocused() -> void;
virtual auto setFont(const Font& font) -> void;
virtual auto setParent(mObject* parent, int offset) -> void;
virtual auto setVisible(bool visible) -> void;
auto locked() const -> bool { return locks != 0 || Application::state.quit; }
auto lock() -> void { locks++; }
auto unlock() -> void { locks--; }
mObject& reference;
signed locks = 0;
};
}

View File

@@ -30,7 +30,6 @@
#include "action/menu-radio-item.cpp"
#include "sizable.cpp"
#include "layout.cpp"
#include "widget/widget.cpp"
#include "widget/button.cpp"

View File

@@ -33,7 +33,6 @@
#include "action/menu-radio-item.hpp"
#include "sizable.hpp"
#include "layout.hpp"
#include "widget/widget.hpp"
#include "widget/button.hpp"

View File

@@ -11,8 +11,8 @@ struct Settings {
int frameY = 24;
int frameWidth = 8;
int frameHeight = 28;
int menuHeight = 20;
int statusHeight = 20;
int menuHeight = 9;
int statusHeight = 9;
} geometry;
};

View File

@@ -40,6 +40,7 @@ auto pComboButtonItem::_parent() -> maybe<pComboButton&> {
auto pComboButtonItem::_setState() -> void {
if(auto parent = _parent()) {
auto lock = parent->acquire();
parent->qtComboButton->setItemIcon(self().offset(), CreateIcon(state().icon));
if(state().selected) parent->qtComboButton->setCurrentIndex(self().offset());
parent->qtComboButton->setItemText(self().offset(), QString::fromUtf8(state().text));

View File

@@ -30,9 +30,8 @@ auto pComboButton::remove(sComboButtonItem item) -> void {
}
auto pComboButton::reset() -> void {
lock();
auto lock = acquire();
while(qtComboButton->count()) qtComboButton->removeItem(0);
unlock();
}
auto QtComboButton::onChange(int offset) -> void {

View File

@@ -22,23 +22,23 @@ auto pFrame::destruct() -> void {
qtWidget = qtFrame = nullptr;
}
auto pFrame::append(sLayout layout) -> void {
auto pFrame::append(sSizable sizable) -> void {
}
auto pFrame::remove(sLayout layout) -> void {
auto pFrame::remove(sSizable sizable) -> void {
}
auto pFrame::setEnabled(bool enabled) -> void {
if(auto layout = state().layout) layout->setEnabled(layout->enabled(true));
if(auto& sizable = state().sizable) sizable->setEnabled(sizable->enabled());
pWidget::setEnabled(enabled);
}
auto pFrame::setGeometry(Geometry geometry) -> void {
pWidget::setGeometry(geometry);
if(auto layout = state().layout) {
if(auto& sizable = state().sizable) {
auto size = pFont::size(qtFrame->font(), state().text);
if(!state().text) size.setHeight(8);
layout->setGeometry({
sizable->setGeometry({
4, size.height(),
geometry.width() - 8,
geometry.height() - size.height() - 4
@@ -51,7 +51,7 @@ auto pFrame::setText(const string& text) -> void {
}
auto pFrame::setVisible(bool visible) -> void {
if(auto layout = state().layout) layout->setVisible(layout->visible(true));
if(auto& sizable = state().sizable) sizable->setVisible(sizable->visible());
pWidget::setVisible(visible);
}

View File

@@ -5,8 +5,8 @@ namespace hiro {
struct pFrame : pWidget {
Declare(Frame, Widget)
auto append(sLayout layout) -> void;
auto remove(sLayout layout) -> void;
auto append(sSizable sizable) -> void;
auto remove(sSizable sizable) -> void;
auto setEnabled(bool enabled) -> void override;
auto setGeometry(Geometry geometry) -> void override;
auto setText(const string& text) -> void;

View File

@@ -15,22 +15,22 @@ auto pTabFrameItem::construct() -> void {
auto pTabFrameItem::destruct() -> void {
}
auto pTabFrameItem::append(sLayout layout) -> void {
auto pTabFrameItem::append(sSizable sizable) -> void {
}
auto pTabFrameItem::remove(sLayout layout) -> void {
auto pTabFrameItem::remove(sSizable sizable) -> void {
}
auto pTabFrameItem::setClosable(bool closable) -> void {
}
auto pTabFrameItem::setGeometry(Geometry geometry) -> void {
if(auto layout = state().layout) {
if(auto& sizable = state().sizable) {
auto offset = qtTabFrameItem->geometry();
geometry.setPosition({0, 0});
geometry.setWidth(geometry.width() - (geometry.width() - offset.width()));
geometry.setHeight(geometry.height() - (geometry.height() - offset.height()));
layout->setGeometry(geometry);
sizable->setGeometry(geometry);
}
}
@@ -65,14 +65,14 @@ auto pTabFrameItem::_setState() -> void {
parent->qtTabFrame->setTabIcon(self().offset(), CreateIcon(state().icon));
if(state().selected) parent->qtTabFrame->setCurrentIndex(self().offset());
parent->qtTabFrame->setTabText(self().offset(), QString::fromUtf8(state().text));
if(auto layout = state().layout) {
if(auto& sizable = state().sizable) {
auto geometry = parent->self().geometry();
auto offset = qtTabFrameItem->geometry();
geometry.setPosition({0, 0});
geometry.setWidth(geometry.width() - (geometry.width() - offset.width()));
geometry.setHeight(geometry.height() - (geometry.height() - offset.height()));
layout->setGeometry(geometry);
layout->setVisible(layout->visible(true));
sizable->setGeometry(geometry);
sizable->setVisible(sizable->visible(true));
}
}
}

View File

@@ -5,8 +5,8 @@ namespace hiro {
struct pTabFrameItem : pObject {
Declare(TabFrameItem, Object)
auto append(sLayout layout) -> void;
auto remove(sLayout layout) -> void;
auto append(sSizable sizable) -> void;
auto remove(sSizable sizable) -> void;
auto setClosable(bool closable) -> void;
auto setIcon(const image& icon) -> void;
auto setGeometry(Geometry geometry) -> void;

View File

@@ -50,7 +50,7 @@ auto pTableViewCell::_parent() -> maybe<pTableViewItem&> {
auto pTableViewCell::_setState() -> void {
if(auto parent = _parent()) {
if(auto grandparent = parent->_parent()) {
grandparent->lock();
auto lock = grandparent->acquire();
parent->qtItem->setBackground(self().offset(), CreateBrush(self().backgroundColor(true)));
if(state().checkable) {
parent->qtItem->setCheckState(self().offset(), state().checked ? Qt::Checked : Qt::Unchecked);
@@ -63,7 +63,6 @@ auto pTableViewCell::_setState() -> void {
parent->qtItem->setIcon(self().offset(), CreateIcon(state().icon));
parent->qtItem->setText(self().offset(), QString::fromUtf8(state().text));
parent->qtItem->setTextAlignment(self().offset(), CalculateAlignment(self().alignment(true)));
grandparent->unlock();
}
}
}

View File

@@ -44,6 +44,10 @@ auto pTableViewColumn::setIcon(const image& icon) -> void {
//unsupported
}
auto pTableViewColumn::setParent(mObject* parent, int offset) -> void {
if(auto header = _parent()) header->_setState();
}
auto pTableViewColumn::setResizable(bool resizable) -> void {
_setState();
}
@@ -78,6 +82,7 @@ auto pTableViewColumn::_parent() -> maybe<pTableViewHeader&> {
auto pTableViewColumn::_setState() -> void {
if(auto header = _parent()) {
if(auto parent = header->_parent()) {
auto lock = parent->acquire();
#if HIRO_QT==4
parent->qtTableView->header()->setResizeMode(self().offset(), state().resizable ? QHeaderView::Interactive : QHeaderView::Fixed);
#elif HIRO_QT==5

View File

@@ -14,6 +14,7 @@ struct pTableViewColumn : pObject {
auto setForegroundColor(Color color) -> void;
auto setHorizontalAlignment(double alignment) -> void;
auto setIcon(const image& icon) -> void;
auto setParent(mObject* parent, int offset) -> void override;
auto setResizable(bool resizable) -> void;
auto setSortable(bool sortable) -> void;
auto setText(const string& text) -> void;

View File

@@ -13,7 +13,6 @@ auto pTableViewHeader::append(sTableViewColumn column) -> void {
}
auto pTableViewHeader::remove(sTableViewColumn column) -> void {
_setState();
}
auto pTableViewHeader::setVisible(bool visible) -> void {
@@ -29,6 +28,7 @@ auto pTableViewHeader::_parent() -> maybe<pTableView&> {
auto pTableViewHeader::_setState() -> void {
if(auto parent = _parent()) {
auto lock = parent->acquire();
//parent->qtTableView->setAlternatingRowColors(self().columnCount() >= 2);
parent->qtTableView->setColumnCount(self().columnCount());
parent->qtTableView->setHeaderHidden(!self().visible());

View File

@@ -6,12 +6,13 @@ auto pTableViewItem::construct() -> void {
}
auto pTableViewItem::destruct() -> void {
if(auto parent = _parent()) parent->lock();
if(qtItem) {
delete qtItem;
qtItem = nullptr;
if(auto parent = _parent()) {
auto lock = parent->acquire();
if(qtItem) {
delete qtItem;
qtItem = nullptr;
}
}
if(auto parent = _parent()) parent->unlock();
}
auto pTableViewItem::append(sTableViewCell cell) -> void {
@@ -51,6 +52,7 @@ auto pTableViewItem::_parent() -> maybe<pTableView&> {
auto pTableViewItem::_setState() -> void {
if(auto parent = _parent()) {
parent->lock();
qtItem->setSelected(state().selected);
if(state().selected) {
parent->qtTableView->setCurrentItem(qtItem);

View File

@@ -146,7 +146,7 @@ auto pTableView::_width(unsigned column) -> unsigned {
unsigned width = 1;
if(!header->column(column).visible()) return width;
if(header->visible()) width = max(width, _widthOfColumn(column));
for(auto row : range(state().items)) {
for(auto row : range(state().items.size())) {
width = max(width, _widthOfCell(row, column));
}
return width;

View File

@@ -51,10 +51,10 @@ auto pWindow::destruct() -> void {
delete qtWindow;
}
auto pWindow::append(sLayout layout) -> void {
auto pWindow::append(sMenuBar menuBar) -> void {
}
auto pWindow::append(sMenuBar menuBar) -> void {
auto pWindow::append(sSizable sizable) -> void {
}
auto pWindow::append(sStatusBar statusBar) -> void {
@@ -77,15 +77,15 @@ auto pWindow::frameMargin() const -> Geometry {
};
}
auto pWindow::remove(sLayout layout) -> void {
}
auto pWindow::remove(sMenuBar menuBar) -> void {
//QMenuBar::removeMenu() does not exist
//qtMenu->clear();
//for(auto& menu : window.state.menu) append(menu);
}
auto pWindow::remove(sSizable sizable) -> void {
}
auto pWindow::remove(sStatusBar statusBar) -> void {
}
@@ -219,12 +219,32 @@ auto pWindow::_append(mWidget& widget) -> void {
}
}
auto pWindow::_menuHeight() const -> signed {
return qtMenuBar->isVisible() ? settings.geometry.menuHeight : 0;
auto pWindow::_menuHeight() const -> uint {
if(!qtMenuBar->isVisible()) return 0;
return settings.geometry.menuHeight + _menuTextHeight();
}
auto pWindow::_statusHeight() const -> signed {
return qtStatusBar->isVisible() ? settings.geometry.statusHeight : 0;
auto pWindow::_menuTextHeight() const -> uint {
uint height = 0;
if(auto& menuBar = state().menuBar) {
for(auto& menu : menuBar->state.menus) {
height = max(height, menu->font(true).size(menu->text()).height());
}
}
return height;
}
auto pWindow::_statusHeight() const -> uint {
if(!qtStatusBar->isVisible()) return 0;
return settings.geometry.statusHeight + _statusTextHeight();
}
auto pWindow::_statusTextHeight() const -> uint {
uint height = 0;
if(auto& statusBar = state().statusBar) {
height = statusBar->font(true).size(statusBar->text()).height();
}
return height;
}
auto pWindow::_updateFrameGeometry() -> void {
@@ -239,12 +259,12 @@ auto pWindow::_updateFrameGeometry() -> void {
if(qtMenuBar->isVisible()) {
pApplication::syncX();
settings.geometry.menuHeight = qtMenuBar->height();
settings.geometry.menuHeight = qtMenuBar->height() - _menuTextHeight();
}
if(qtStatusBar->isVisible()) {
pApplication::syncX();
settings.geometry.statusHeight = qtStatusBar->height();
settings.geometry.statusHeight = qtStatusBar->height() - _statusTextHeight();
}
}
@@ -302,8 +322,8 @@ auto QtWindow::resizeEvent(QResizeEvent*) -> void {
});
}
if(auto& layout = p.state().layout) {
layout->setGeometry(p.self().geometry().setPosition(0, 0));
if(auto& sizable = p.state().sizable) {
sizable->setGeometry(p.self().geometry().setPosition());
}
if(!p.locked()) {
@@ -312,8 +332,8 @@ auto QtWindow::resizeEvent(QResizeEvent*) -> void {
}
auto QtWindow::sizeHint() const -> QSize {
unsigned width = p.state().geometry.width();
unsigned height = p.state().geometry.height();
uint width = p.state().geometry.width();
uint height = p.state().geometry.height();
if(p.qtMenuBar->isVisible()) height += settings.geometry.menuHeight;
if(p.qtStatusBar->isVisible()) height += settings.geometry.statusHeight;
return QSize(width, height);

View File

@@ -5,13 +5,13 @@ namespace hiro {
struct pWindow : pObject {
Declare(Window, Object)
auto append(sLayout layout) -> void;
auto append(sMenuBar menuBar) -> void;
auto append(sSizable sizable) -> void;
auto append(sStatusBar statusBar) -> void;
auto focused() const -> bool override;
auto frameMargin() const -> Geometry;
auto remove(sLayout layout) -> void;
auto remove(sMenuBar menuBar) -> void;
auto remove(sSizable sizable) -> void;
auto remove(sStatusBar statusBar) -> void;
auto setBackgroundColor(Color color) -> void;
auto setDismissable(bool dismissable) -> void;
@@ -30,8 +30,10 @@ struct pWindow : pObject {
auto setVisible(bool visible) -> void;
auto _append(mWidget& widget) -> void;
auto _menuHeight() const -> signed;
auto _statusHeight() const -> signed;
auto _menuHeight() const -> uint;
auto _menuTextHeight() const -> uint;
auto _statusHeight() const -> uint;
auto _statusTextHeight() const -> uint;
auto _updateFrameGeometry() -> void;
QtWindow* qtWindow = nullptr;