From bb3c69a30da8bbeb9362d7ab3af21eba5b25e2f7 Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Tue, 16 Jun 2015 08:16:43 +1000 Subject: [PATCH] Update to v094r25 release. byuu says: Windows port should run mostly well now, although exiting fullscreen breaks the application in a really bizarre way. (clicking on the window makes it sink to background rather than come to the foreground o_O) I also need to add the doModalChange => audio.clear() thing for the accursed menu stuttering with DirectSound. I also finished porting all of the ruby drivers over to the newer API changes from nall. Since I can't compile the Linux or OS X drivers, I have no idea if there are any typos that will result in compilation errors. If so, please let me know where they're at and I'll try and fix them. If they're simple, please try and fix them on your end to test further if you can. I'm hopeful the udev crash will be gone now that nall::string checks for null char* values passed to its stringify function. Of course, it's a problem it's getting a null value in the first place, so it may not work at all. If you can compile on Linux (or by some miracle, OS X), please test each video/audio/input driver if you don't mind, to make sure there's no "compiles okay but still typos exist" bugs. --- emulator/emulator.hpp | 2 +- hiro/core/action/menu-check-item.cpp | 4 +- hiro/core/action/menu-item.cpp | 4 +- hiro/core/action/menu-radio-item.cpp | 4 +- hiro/core/action/menu.cpp | 2 +- hiro/core/application.cpp | 24 ++-- hiro/core/color.cpp | 22 ++-- hiro/core/core.hpp | 141 ++++++++++----------- hiro/core/hotkey.cpp | 8 +- hiro/core/layout.cpp | 2 +- hiro/core/menu-bar.cpp | 2 +- hiro/core/object.cpp | 10 +- hiro/core/popup-menu.cpp | 2 +- hiro/core/timer.cpp | 4 +- hiro/core/widget/button.cpp | 4 +- hiro/core/widget/canvas.cpp | 20 +-- hiro/core/widget/check-button.cpp | 4 +- hiro/core/widget/check-label.cpp | 4 +- hiro/core/widget/combo-button.cpp | 6 +- hiro/core/widget/console.cpp | 4 +- hiro/core/widget/hex-edit.cpp | 8 +- hiro/core/widget/horizontal-scroller.cpp | 4 +- hiro/core/widget/horizontal-slider.cpp | 4 +- hiro/core/widget/icon-view.cpp | 14 +-- hiro/core/widget/line-edit.cpp | 8 +- hiro/core/widget/list-view-item.cpp | 2 +- hiro/core/widget/list-view.cpp | 28 ++--- hiro/core/widget/radio-button.cpp | 4 +- hiro/core/widget/radio-label.cpp | 4 +- hiro/core/widget/source-edit.cpp | 8 +- hiro/core/widget/tab-frame.cpp | 14 +-- hiro/core/widget/text-edit.cpp | 8 +- hiro/core/widget/tree-view-item.cpp | 2 +- hiro/core/widget/tree-view.cpp | 18 +-- hiro/core/widget/vertical-scroller.cpp | 4 +- hiro/core/widget/vertical-slider.cpp | 4 +- hiro/core/widget/viewport.cpp | 20 +-- hiro/core/widget/widget.cpp | 4 +- hiro/core/window.cpp | 51 +++----- hiro/extension/fixed-layout.cpp | 4 +- hiro/extension/fixed-layout.hpp | 8 +- hiro/extension/horizontal-layout.cpp | 4 +- hiro/extension/horizontal-layout.hpp | 8 +- hiro/extension/shared.hpp | 119 +++++++++--------- hiro/extension/vertical-layout.cpp | 4 +- hiro/extension/vertical-layout.hpp | 8 +- hiro/windows/application.cpp | 51 ++++---- hiro/windows/platform.hpp | 2 + hiro/windows/utility.cpp | 9 +- hiro/windows/widget/list-view.cpp | 21 ++++ hiro/windows/widget/list-view.hpp | 1 + hiro/windows/widget/tab-frame.cpp | 5 +- hiro/windows/widget/widget.cpp | 27 ++-- hiro/windows/widget/widget.hpp | 6 +- hiro/windows/window.cpp | 45 ++++++- hiro/windows/window.hpp | 5 +- nall/http/server.hpp | 3 - nall/intrinsics.hpp | 3 + nall/platform.hpp | 24 ++++ nall/posix/service.hpp | 117 +++++++++++++++++ nall/posix/shared-memory.hpp | 154 +++++++++++++++++++++++ nall/service.hpp | 116 +---------------- nall/shared-memory.hpp | 154 +---------------------- nall/shared-pointer.hpp | 56 +++++---- nall/windows/service.hpp | 16 +++ nall/windows/shared-memory.hpp | 30 +++++ ruby/audio/alsa.cpp | 80 +++++------- ruby/audio/ao.cpp | 55 ++++---- ruby/audio/pulseaudio.cpp | 76 +++++------ ruby/audio/pulseaudiosimple.cpp | 48 +++---- ruby/input/carbon.cpp | 50 ++++---- ruby/input/joypad/udev.cpp | 46 +++---- ruby/input/udev.cpp | 30 ++--- ruby/video/cgl.cpp | 54 ++++---- target-tomoko/GNUmakefile | 2 +- 75 files changed, 1017 insertions(+), 906 deletions(-) create mode 100644 nall/posix/service.hpp create mode 100644 nall/posix/shared-memory.hpp create mode 100644 nall/windows/service.hpp create mode 100644 nall/windows/shared-memory.hpp diff --git a/emulator/emulator.hpp b/emulator/emulator.hpp index 2a2237b8..1c9d1022 100644 --- a/emulator/emulator.hpp +++ b/emulator/emulator.hpp @@ -3,7 +3,7 @@ namespace Emulator { static const char Name[] = "higan"; - static const char Version[] = "094.24"; + static const char Version[] = "094.25"; static const char Author[] = "byuu"; static const char License[] = "GPLv3"; static const char Website[] = "http://byuu.org/"; diff --git a/hiro/core/action/menu-check-item.cpp b/hiro/core/action/menu-check-item.cpp index d0535cc5..e341288e 100644 --- a/hiro/core/action/menu-check-item.cpp +++ b/hiro/core/action/menu-check-item.cpp @@ -14,8 +14,8 @@ auto mMenuCheckItem::doToggle() const -> void { if(state.onToggle) return state.onToggle(); } -auto mMenuCheckItem::onToggle(const function& function) -> type& { - state.onToggle = function; +auto mMenuCheckItem::onToggle(const function& callback) -> type& { + state.onToggle = callback; return *this; } diff --git a/hiro/core/action/menu-item.cpp b/hiro/core/action/menu-item.cpp index 50dd2d91..8f5ce5fe 100644 --- a/hiro/core/action/menu-item.cpp +++ b/hiro/core/action/menu-item.cpp @@ -14,8 +14,8 @@ auto mMenuItem::icon() const -> image { return state.icon; } -auto mMenuItem::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mMenuItem::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } diff --git a/hiro/core/action/menu-radio-item.cpp b/hiro/core/action/menu-radio-item.cpp index ec1e3e28..73916523 100644 --- a/hiro/core/action/menu-radio-item.cpp +++ b/hiro/core/action/menu-radio-item.cpp @@ -18,8 +18,8 @@ auto mMenuRadioItem::group() const -> sGroup { return state.group; } -auto mMenuRadioItem::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mMenuRadioItem::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } diff --git a/hiro/core/action/menu.cpp b/hiro/core/action/menu.cpp index ca17b392..6882ffd6 100644 --- a/hiro/core/action/menu.cpp +++ b/hiro/core/action/menu.cpp @@ -35,7 +35,7 @@ auto mMenu::remove(sAction action) -> type& { signal(remove, *action); state.actions.remove(action->offset()); for(auto n : range(action->offset(), actions())) { - state.actions[n]->offset(-1); + state.actions[n]->adjustOffset(-1); } action->setParent(); } diff --git a/hiro/core/application.cpp b/hiro/core/application.cpp index 71eac1af..1e8f84d1 100644 --- a/hiro/core/application.cpp +++ b/hiro/core/application.cpp @@ -14,8 +14,8 @@ auto Application::name() -> string { return state.name; } -auto Application::onMain(const nall::function& function) -> void { - state.onMain = function; +auto Application::onMain(const function& callback) -> void { + state.onMain = callback; } auto Application::run() -> void { @@ -50,8 +50,8 @@ auto Application::Windows::doModalChange(bool modal) -> void { if(state.windows.onModalChange) return state.windows.onModalChange(modal); } -auto Application::Windows::onModalChange(const function& function) -> void { - state.windows.onModalChange = function; +auto Application::Windows::onModalChange(const function& callback) -> void { + state.windows.onModalChange = callback; } //Cocoa @@ -73,20 +73,20 @@ auto Application::Cocoa::doQuit() -> void { if(state.cocoa.onQuit) return state.cocoa.onQuit(); } -auto Application::Cocoa::onAbout(const function& function) -> void { - state.cocoa.onAbout = function; +auto Application::Cocoa::onAbout(const function& callback) -> void { + state.cocoa.onAbout = callback; } -auto Application::Cocoa::onActivate(const function& function) -> void { - state.cocoa.onActivate = function; +auto Application::Cocoa::onActivate(const function& callback) -> void { + state.cocoa.onActivate = callback; } -auto Application::Cocoa::onPreferences(const function& function) -> void { - state.cocoa.onPreferences = function; +auto Application::Cocoa::onPreferences(const function& callback) -> void { + state.cocoa.onPreferences = callback; } -auto Application::Cocoa::onQuit(const function& function) -> void { - state.cocoa.onQuit = function; +auto Application::Cocoa::onQuit(const function& callback) -> void { + state.cocoa.onQuit = callback; } //Internal diff --git a/hiro/core/color.cpp b/hiro/core/color.cpp index 81287896..012545c9 100644 --- a/hiro/core/color.cpp +++ b/hiro/core/color.cpp @@ -4,12 +4,8 @@ Color::Color() { setColor(0, 0, 0, 0); } -Color::Color(signed red, signed green, signed blue) { - setColor(255, red, green, blue); -} - -Color::Color(signed alpha, signed red, signed green, signed blue) { - setColor(alpha, red, green, blue); +Color::Color(signed red, signed green, signed blue, signed alpha) { + setColor(red, green, blue, alpha); } Color::operator bool() const { @@ -17,7 +13,7 @@ Color::operator bool() const { } auto Color::operator==(const Color& source) const -> bool { - return alpha() == source.alpha() && red() == source.red() && green() == source.green() && blue() == source.blue(); + return red() == source.red() && green() == source.green() && blue() == source.blue() && alpha() == source.alpha(); } auto Color::operator!=(const Color& source) const -> bool { @@ -33,7 +29,7 @@ auto Color::blue() const -> uint8_t { } auto Color::empty() const -> bool { - return state.alpha == 0 && state.red == 0 && state.green == 0 && state.blue == 0; + return state.red == 0 && state.green == 0 && state.blue == 0 && state.alpha == 0; } auto Color::green() const -> uint8_t { @@ -55,18 +51,14 @@ auto Color::setBlue(signed blue) -> type& { } auto Color::setColor(Color color) -> type& { - return setColor(color.alpha(), color.red(), color.green(), color.blue()); + return setColor(color.red(), color.green(), color.blue(), color.alpha()); } -auto Color::setColor(signed red, signed green, signed blue) -> type& { - return setColor(255, red, green, blue); -} - -auto Color::setColor(signed alpha, signed red, signed green, signed blue) -> type& { - state.alpha = max(0, min(255, alpha)); +auto Color::setColor(signed red, signed green, signed blue, signed alpha) -> type& { state.red = max(0, min(255, red )); state.green = max(0, min(255, green)); state.blue = max(0, min(255, blue )); + state.alpha = max(0, min(255, alpha)); return *this; } diff --git a/hiro/core/core.hpp b/hiro/core/core.hpp index 4ba043db..9eb41b83 100644 --- a/hiro/core/core.hpp +++ b/hiro/core/core.hpp @@ -92,7 +92,7 @@ struct Application { static auto doMain() -> void; static auto font() -> string; static auto name() -> string; - static auto onMain(const function& function = {}) -> void; + static auto onMain(const function& callback = {}) -> void; static auto run() -> void; static auto pendingEvents() -> bool; static auto processEvents() -> void; @@ -102,7 +102,7 @@ struct Application { struct Windows { static auto doModalChange(bool modal) -> void; - static auto onModalChange(const function& function = {}) -> void; + static auto onModalChange(const function& callback = {}) -> void; }; struct Cocoa { @@ -110,10 +110,10 @@ struct Application { static auto doActivate() -> void; static auto doPreferences() -> void; static auto doQuit() -> void; - static auto onAbout(const function& function = {}) -> void; - static auto onActivate(const function& function = {}) -> void; - static auto onPreferences(const function& function = {}) -> void; - static auto onQuit(const function& function = {}) -> void; + static auto onAbout(const function& callback = {}) -> void; + static auto onActivate(const function& callback = {}) -> void; + static auto onPreferences(const function& callback = {}) -> void; + static auto onQuit(const function& callback = {}) -> void; }; //private: @@ -144,8 +144,7 @@ struct Color { using type = Color; Color(); - Color(signed red, signed green, signed blue); - Color(signed alpha, signed red, signed green, signed blue); + Color(signed red, signed green, signed blue, signed alpha = 255); explicit operator bool() const; auto operator==(const Color& source) const -> bool; @@ -159,18 +158,17 @@ struct Color { auto setAlpha(signed alpha) -> type&; auto setBlue(signed blue) -> type&; auto setColor(Color color = {}) -> type&; - auto setColor(signed red, signed green, signed blue) -> type&; - auto setColor(signed alpha, signed red, signed green, signed blue) -> type&; + auto setColor(signed red, signed green, signed blue, signed alpha = 255) -> type&; auto setGreen(signed green) -> type&; auto setRed(signed red) -> type&; auto value() const -> uint32_t; //private: struct State { - signed alpha; signed red; signed green; signed blue; + signed alpha; } state; }; #endif @@ -408,12 +406,12 @@ struct mObject { mObject& operator=(const mObject&) = delete; auto abstract() const -> bool; + auto adjustOffset(signed displacement) -> type&; auto enabled(bool recursive = false) const -> bool; virtual auto focused() const -> bool; auto font(bool recursive = false) const -> string; virtual auto group() const -> sGroup; auto offset() const -> signed; - auto offset(signed displacement) -> type&; auto parent() const -> mObject*; auto parentComboButton(bool recursive = false) const -> mComboButton*; auto parentFrame(bool recursive = false) const -> mFrame*; @@ -481,8 +479,8 @@ struct mHotkey : mObject { auto doPress() const -> void; auto doRelease() const -> void; - auto onPress(const function& function = {}) -> type&; - auto onRelease(const function& function = {}) -> type&; + auto onPress(const function& callback = {}) -> type&; + auto onRelease(const function& callback = {}) -> type&; auto parent() const -> wObject; auto remove() -> type& override; auto sequence() const -> string; @@ -507,7 +505,7 @@ struct mTimer : mObject { auto doActivate() const -> void; auto interval() const -> unsigned; - auto onActivate(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; auto setInterval(unsigned interval = 0) -> type&; //private: @@ -540,20 +538,19 @@ struct mWindow : mObject { auto layout() const -> sLayout; auto menuBar() const -> sMenuBar; auto modal() const -> bool; - auto onClose(const function& function = {}) -> type&; - auto onDrop(const function& function = {}) -> type&; - auto onKeyPress(const function& function = {}) -> type&; - auto onKeyRelease(const function& function = {}) -> type&; - auto onMove(const function& function = {}) -> type&; - auto onSize(const function& function = {}) -> type&; + auto onClose(const function& callback = {}) -> type&; + auto onDrop(const function& callback = {}) -> type&; + auto onKeyPress(const function& callback = {}) -> type&; + auto onKeyRelease(const function& callback = {}) -> type&; + auto onMove(const function& callback = {}) -> type&; + auto onSize(const function& callback = {}) -> type&; auto remove(sLayout layout) -> type&; auto remove(sMenuBar menuBar) -> type&; auto remove(sStatusBar statusBar) -> type&; auto reset() -> type& override; auto resizable() const -> bool; auto setBackgroundColor(Color color = {}) -> type&; - auto setCentered() -> type&; - auto setCentered(sWindow parent) -> type&; + auto setCentered(sWindow parent = {}) -> type&; auto setDroppable(bool droppable = true) -> type&; auto setFrameGeometry(Geometry geometry) -> type&; auto setFramePosition(Position position) -> type&; @@ -706,7 +703,7 @@ struct mMenuItem : mAction { auto doActivate() const -> void; auto icon() const -> image; - auto onActivate(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; auto setIcon(const image& icon = {}) -> type&; auto setText(const string& text = "") -> type&; auto text() const -> string; @@ -726,7 +723,7 @@ struct mMenuCheckItem : mAction { auto checked() const -> bool; auto doToggle() const -> void; - auto onToggle(const function& function = {}) -> type&; + auto onToggle(const function& callback = {}) -> type&; auto setChecked(bool checked = true) -> type&; auto setText(const string& text = "") -> type&; auto text() const -> string; @@ -747,7 +744,7 @@ struct mMenuRadioItem : mAction { auto checked() const -> bool; auto doActivate() const -> void; auto group() const -> sGroup override; - auto onActivate(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; auto setChecked() -> type&; auto setGroup(sGroup group = {}) -> type& override; auto setText(const string& text = "") -> type&; @@ -804,7 +801,7 @@ struct mWidget : mSizable { Declare(Widget) auto doSize() const -> void; - auto onSize(const function& function = {}) -> type&; + auto onSize(const function& callback = {}) -> type&; auto remove() -> type& override; //private: @@ -821,7 +818,7 @@ struct mButton : mWidget { auto bordered() const -> bool; auto doActivate() const -> void; auto icon() const -> image; - auto onActivate(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; auto orientation() const -> Orientation; auto setBordered(bool bordered = true) -> type&; auto setIcon(const image& icon = {}) -> type&; @@ -854,11 +851,11 @@ struct mCanvas : mWidget { auto doMouseRelease(Mouse::Button button) const -> void; auto gradient() const -> vector; auto icon() const -> image; - auto onDrop(const function& function = {}) -> type&; - auto onMouseLeave(const function& function = {}) -> type&; - auto onMouseMove(const function& function = {}) -> type&; - auto onMousePress(const function& function = {}) -> type&; - auto onMouseRelease(const function& function = {}) -> type&; + auto onDrop(const function& callback = {}) -> type&; + auto onMouseLeave(const function& callback = {}) -> type&; + auto onMouseMove(const function& callback = {}) -> type&; + auto onMousePress(const function& callback = {}) -> type&; + auto onMouseRelease(const function& callback = {}) -> type&; auto setColor(Color color) -> type&; auto setData(Size size) -> type&; auto setDroppable(bool droppable = true) -> type&; @@ -894,7 +891,7 @@ struct mCheckButton : mWidget { auto checked() const -> bool; auto doToggle() const -> void; auto icon() const -> image; - auto onToggle(const function& function = {}) -> type&; + auto onToggle(const function& callback = {}) -> type&; auto orientation() const -> Orientation; auto setBordered(bool bordered = true) -> type&; auto setChecked(bool checked = true) -> type&; @@ -921,7 +918,7 @@ struct mCheckLabel : mWidget { auto checked() const -> bool; auto doToggle() const -> void; - auto onToggle(const function& function = {}) -> type&; + auto onToggle(const function& callback = {}) -> type&; auto setChecked(bool checked = true) -> type&; auto setText(const string& text = "") -> type&; auto text() const -> string; @@ -944,7 +941,7 @@ struct mComboButton : mWidget { auto doChange() const -> void; auto item(unsigned position) const -> sComboButtonItem; auto items() const -> unsigned; - auto onChange(const function& function = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; auto remove(sComboButtonItem item) -> type&; auto reset() -> type&; auto selected() const -> sComboButtonItem; @@ -988,7 +985,7 @@ struct mConsole : mWidget { auto backgroundColor() const -> Color; auto doActivate(string) const -> void; auto foregroundColor() const -> Color; - auto onActivate(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; auto print(const string& text) -> type&; auto prompt() const -> string; auto reset() -> type&; @@ -1040,8 +1037,8 @@ struct mHexEdit : mWidget { auto foregroundColor() const -> Color; auto length() const -> unsigned; auto offset() const -> unsigned; - auto onRead(const function& function = {}) -> type&; - auto onWrite(const function& function = {}) -> type&; + auto onRead(const function& callback = {}) -> type&; + auto onWrite(const function& callback = {}) -> type&; auto rows() const -> unsigned; auto setBackgroundColor(Color color = {}) -> type&; auto setColumns(unsigned columns = 16) -> type&; @@ -1071,7 +1068,7 @@ struct mHorizontalScroller : mWidget { auto doChange() const -> void; auto length() const -> unsigned; - auto onChange(const function& function = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; auto position() const -> unsigned; auto setLength(unsigned length = 101) -> type&; auto setPosition(unsigned position = 0) -> type&; @@ -1091,7 +1088,7 @@ struct mHorizontalSlider : mWidget { auto doChange() const -> void; auto length() const -> unsigned; - auto onChange(const function& function = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; auto position() const -> unsigned; auto setLength(unsigned length = 101) -> type&; auto setPosition(unsigned position = 0) -> type&; @@ -1120,9 +1117,9 @@ struct mIconView : mWidget { auto item(unsigned position) const -> sIconViewItem; auto items() const -> unsigned; auto multiSelect() const -> bool; - auto onActivate(const function& function = {}) -> type&; - auto onChange(const function& function = {}) -> type&; - auto onContext(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; + auto onContext(const function& callback = {}) -> type&; auto orientation() const -> Orientation; auto remove(sIconViewItem item) -> type&; auto reset() -> type&; @@ -1203,8 +1200,8 @@ struct mLineEdit : mWidget { auto doChange() const -> void; auto editable() const -> bool; auto foregroundColor() const -> Color; - auto onActivate(const function& function = {}) -> type&; - auto onChange(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; auto setBackgroundColor(Color color = {}) -> type&; auto setEditable(bool editable = true) -> type&; auto setForegroundColor(Color color = {}) -> type&; @@ -1248,12 +1245,12 @@ struct mListView : mWidget { auto headerVisible() const -> bool; auto item(unsigned position) const -> sListViewItem; auto items() const -> unsigned; - auto onActivate(const function& function = {}) -> type&; - auto onChange(const function& function = {}) -> type&; - auto onContext(const function& function = {}) -> type&; - auto onEdit(const function& function = {}) -> type&; - auto onSort(const function& function = {}) -> type&; - auto onToggle(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; + auto onContext(const function& callback = {}) -> type&; + auto onEdit(const function& callback = {}) -> type&; + auto onSort(const function& callback = {}) -> type&; + auto onToggle(const function& callback = {}) -> type&; auto remove(sListViewColumn column) -> type&; auto remove(sListViewItem item) -> type&; auto reset() -> type&; @@ -1422,7 +1419,7 @@ struct mRadioButton : mWidget { auto doActivate() const -> void; auto group() const -> sGroup override; auto icon() const -> image; - auto onActivate(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; auto orientation() const -> Orientation; auto setBordered(bool bordered = true) -> type&; auto setChecked() -> type&; @@ -1452,7 +1449,7 @@ struct mRadioLabel : mWidget { auto checked() const -> bool; auto doActivate() const -> void; auto group() const -> sGroup override; - auto onActivate(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; auto setChecked() -> type&; auto setGroup(sGroup group = {}) -> type& override; auto setText(const string& text = "") -> type&; @@ -1474,8 +1471,8 @@ struct mSourceEdit : mWidget { auto doChange() const -> void; auto doMove() const -> void; - auto onChange(const function& function = {}) -> type&; - auto onMove(const function& function = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; + auto onMove(const function& callback = {}) -> type&; auto position() const -> unsigned; auto setPosition(signed position) -> type&; auto setSelected(Position selected) -> type&; @@ -1506,9 +1503,9 @@ struct mTabFrame : mWidget { auto edge() const -> Edge; auto item(unsigned position) const -> sTabFrameItem; auto items() const -> unsigned; - auto onChange(const function& function = {}) -> type&; - auto onClose(const function& function = {}) -> type&; - auto onMove(const function& function = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; + auto onClose(const function& callback = {}) -> type&; + auto onMove(const function& callback = {}) -> type&; auto remove(sTabFrameItem item) -> type&; auto reset() -> type&; auto selected() const -> sTabFrameItem; @@ -1573,8 +1570,8 @@ struct mTextEdit : mWidget { auto doMove() const -> void; auto editable() const -> bool; auto foregroundColor() const -> Color; - auto onChange(const function& function = {}) -> type&; - auto onMove(const function& function = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; + auto onMove(const function& callback = {}) -> type&; auto setBackgroundColor(Color color = {}) -> type&; auto setCursorPosition(unsigned position) -> type&; auto setEditable(bool editable = true) -> type&; @@ -1615,10 +1612,10 @@ struct mTreeView : mWidget { auto foregroundColor() const -> Color; auto item(const string& path) const -> sTreeViewItem; auto items() const -> unsigned; - auto onActivate(const function& function = {}) -> type&; - auto onChange(const function& function = {}) -> type&; - auto onContext(const function& function = {}) -> type&; - auto onToggle(const function& function = {}) -> type&; + auto onActivate(const function& callback = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; + auto onContext(const function& callback = {}) -> type&; + auto onToggle(const function& callback = {}) -> type&; auto remove(sTreeViewItem item) -> type&; auto reset() -> type&; auto selected() const -> sTreeViewItem; @@ -1683,7 +1680,7 @@ struct mVerticalScroller : mWidget { auto doChange() const -> void; auto length() const -> unsigned; - auto onChange(const function& function = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; auto position() const -> unsigned; auto setLength(unsigned length = 101) -> type&; auto setPosition(unsigned position = 0) -> type&; @@ -1703,7 +1700,7 @@ struct mVerticalSlider : mWidget { auto doChange() const -> void; auto length() const -> unsigned; - auto onChange(const function& function = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; auto position() const -> unsigned; auto setLength(unsigned length = 101) -> type&; auto setPosition(unsigned position = 0) -> type&; @@ -1728,11 +1725,11 @@ struct mViewport : mWidget { auto doMouseRelease(Mouse::Button button) const -> void; auto droppable() const -> bool; auto handle() const -> uintptr_t; - auto onDrop(const function& function = {}) -> type&; - auto onMouseLeave(const function& function = {}) -> type&; - auto onMouseMove(const function& function = {}) -> type&; - auto onMousePress(const function& function = {}) -> type&; - auto onMouseRelease(const function& function = {}) -> type&; + auto onDrop(const function& callback = {}) -> type&; + auto onMouseLeave(const function& callback = {}) -> type&; + auto onMouseMove(const function& callback = {}) -> type&; + auto onMousePress(const function& callback = {}) -> type&; + auto onMouseRelease(const function& callback = {}) -> type&; auto setDroppable(bool droppable = true) -> type&; //private: diff --git a/hiro/core/hotkey.cpp b/hiro/core/hotkey.cpp index 80c8b2c3..6795ad2f 100644 --- a/hiro/core/hotkey.cpp +++ b/hiro/core/hotkey.cpp @@ -14,13 +14,13 @@ auto mHotkey::doRelease() const -> void { if(state.onRelease) return state.onRelease(); } -auto mHotkey::onPress(const function& function) -> type& { - state.onPress = function; +auto mHotkey::onPress(const function& callback) -> type& { + state.onPress = callback; return *this; } -auto mHotkey::onRelease(const function& function) -> type& { - state.onRelease = function; +auto mHotkey::onRelease(const function& callback) -> type& { + state.onRelease = callback; return *this; } diff --git a/hiro/core/layout.cpp b/hiro/core/layout.cpp index 6dc57baf..2298c5a6 100644 --- a/hiro/core/layout.cpp +++ b/hiro/core/layout.cpp @@ -34,7 +34,7 @@ auto mLayout::remove(shared_pointer sizable) -> type& { sizable->setParent(); state.sizables.remove(offset); for(auto n : range(offset, sizables())) { - state.sizables[n]->offset(-1); + state.sizables[n]->adjustOffset(-1); } setGeometry(geometry()); return *this; diff --git a/hiro/core/menu-bar.cpp b/hiro/core/menu-bar.cpp index 48121714..d8c06775 100644 --- a/hiro/core/menu-bar.cpp +++ b/hiro/core/menu-bar.cpp @@ -37,7 +37,7 @@ auto mMenuBar::remove(shared_pointer menu) -> type& { signal(remove, *menu); state.menus.remove(offset); for(auto n : range(offset, menus())) { - state.menus[n]->offset(-1); + state.menus[n]->adjustOffset(-1); } menu->setParent(); return *this; diff --git a/hiro/core/object.cpp b/hiro/core/object.cpp index 1419b1c6..b8623f6e 100644 --- a/hiro/core/object.cpp +++ b/hiro/core/object.cpp @@ -47,6 +47,11 @@ auto mObject::abstract() const -> bool { return true; } +auto mObject::adjustOffset(signed displacement) -> type& { + state.offset += displacement; + return *this; +} + auto mObject::enabled(bool recursive) const -> bool { if(!recursive || !state.enabled) return state.enabled; if(auto object = parent()) return object->enabled(true); @@ -72,11 +77,6 @@ auto mObject::offset() const -> signed { return state.offset; } -auto mObject::offset(signed displacement) -> type& { - state.offset += displacement; - return *this; -} - auto mObject::parent() const -> mObject* { return state.parent; } diff --git a/hiro/core/popup-menu.cpp b/hiro/core/popup-menu.cpp index 0499b8df..bb5bc4f4 100644 --- a/hiro/core/popup-menu.cpp +++ b/hiro/core/popup-menu.cpp @@ -32,7 +32,7 @@ auto mPopupMenu::remove(sAction action) -> type& { signal(remove, action); state.actions.remove(offset); for(auto n : range(offset, actions())) { - state.actions[n]->offset(-1); + state.actions[n]->adjustOffset(-1); } action->setParent(); return *this; diff --git a/hiro/core/timer.cpp b/hiro/core/timer.cpp index 1278cfb1..ac1ae649 100644 --- a/hiro/core/timer.cpp +++ b/hiro/core/timer.cpp @@ -14,8 +14,8 @@ auto mTimer::interval() const -> unsigned { return state.interval; } -auto mTimer::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mTimer::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } diff --git a/hiro/core/widget/button.cpp b/hiro/core/widget/button.cpp index 5240de13..d754ba03 100644 --- a/hiro/core/widget/button.cpp +++ b/hiro/core/widget/button.cpp @@ -18,8 +18,8 @@ auto mButton::icon() const -> image { return state.icon; } -auto mButton::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mButton::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } diff --git a/hiro/core/widget/canvas.cpp b/hiro/core/widget/canvas.cpp index ef5e279d..b0e699a2 100644 --- a/hiro/core/widget/canvas.cpp +++ b/hiro/core/widget/canvas.cpp @@ -46,28 +46,28 @@ auto mCanvas::icon() const -> image { return state.icon; } -auto mCanvas::onDrop(const function& function) -> type& { - state.onDrop = function; +auto mCanvas::onDrop(const function& callback) -> type& { + state.onDrop = callback; return *this; } -auto mCanvas::onMouseLeave(const function& function) -> type& { - state.onMouseLeave = function; +auto mCanvas::onMouseLeave(const function& callback) -> type& { + state.onMouseLeave = callback; return *this; } -auto mCanvas::onMouseMove(const function& function) -> type& { - state.onMouseMove = function; +auto mCanvas::onMouseMove(const function& callback) -> type& { + state.onMouseMove = callback; return *this; } -auto mCanvas::onMousePress(const function& function) -> type& { - state.onMousePress = function; +auto mCanvas::onMousePress(const function& callback) -> type& { + state.onMousePress = callback; return *this; } -auto mCanvas::onMouseRelease(const function& function) -> type& { - state.onMouseRelease = function; +auto mCanvas::onMouseRelease(const function& callback) -> type& { + state.onMouseRelease = callback; return *this; } diff --git a/hiro/core/widget/check-button.cpp b/hiro/core/widget/check-button.cpp index 65759c6d..e67bf17d 100644 --- a/hiro/core/widget/check-button.cpp +++ b/hiro/core/widget/check-button.cpp @@ -22,8 +22,8 @@ auto mCheckButton::icon() const -> image { return state.icon; } -auto mCheckButton::onToggle(const function& function) -> type& { - state.onToggle = function; +auto mCheckButton::onToggle(const function& callback) -> type& { + state.onToggle = callback; return *this; } diff --git a/hiro/core/widget/check-label.cpp b/hiro/core/widget/check-label.cpp index 3ff75c44..968d5b37 100644 --- a/hiro/core/widget/check-label.cpp +++ b/hiro/core/widget/check-label.cpp @@ -14,8 +14,8 @@ auto mCheckLabel::doToggle() const -> void { if(state.onToggle) return state.onToggle(); } -auto mCheckLabel::onToggle(const function& function) -> type& { - state.onToggle = function; +auto mCheckLabel::onToggle(const function& callback) -> type& { + state.onToggle = callback; return *this; } diff --git a/hiro/core/widget/combo-button.cpp b/hiro/core/widget/combo-button.cpp index e92d5303..4f6426e5 100644 --- a/hiro/core/widget/combo-button.cpp +++ b/hiro/core/widget/combo-button.cpp @@ -31,8 +31,8 @@ auto mComboButton::items() const -> unsigned { return state.items.size(); } -auto mComboButton::onChange(const function& function) -> type& { - state.onChange = function; +auto mComboButton::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } @@ -40,7 +40,7 @@ auto mComboButton::remove(sComboButtonItem item) -> type& { signal(remove, item); state.items.remove(item->offset()); for(auto n : range(item->offset(), items())) { - state.items[n]->offset(-1); + state.items[n]->adjustOffset(-1); } item->setParent(); return *this; diff --git a/hiro/core/widget/console.cpp b/hiro/core/widget/console.cpp index 5678f0b6..3b6fcfd3 100644 --- a/hiro/core/widget/console.cpp +++ b/hiro/core/widget/console.cpp @@ -18,8 +18,8 @@ auto mConsole::foregroundColor() const -> Color { return state.foregroundColor; } -auto mConsole::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mConsole::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } diff --git a/hiro/core/widget/hex-edit.cpp b/hiro/core/widget/hex-edit.cpp index 2267a4bd..7c70e6cf 100644 --- a/hiro/core/widget/hex-edit.cpp +++ b/hiro/core/widget/hex-edit.cpp @@ -35,13 +35,13 @@ auto mHexEdit::offset() const -> unsigned { return state.offset; } -auto mHexEdit::onRead(const function& function) -> type& { - state.onRead = function; +auto mHexEdit::onRead(const function& callback) -> type& { + state.onRead = callback; return *this; } -auto mHexEdit::onWrite(const function& function) -> type& { - state.onWrite = function; +auto mHexEdit::onWrite(const function& callback) -> type& { + state.onWrite = callback; return *this; } diff --git a/hiro/core/widget/horizontal-scroller.cpp b/hiro/core/widget/horizontal-scroller.cpp index a730d5fa..038e8041 100644 --- a/hiro/core/widget/horizontal-scroller.cpp +++ b/hiro/core/widget/horizontal-scroller.cpp @@ -14,8 +14,8 @@ auto mHorizontalScroller::length() const -> unsigned { return state.length; } -auto mHorizontalScroller::onChange(const function& function) -> type& { - state.onChange = function; +auto mHorizontalScroller::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } diff --git a/hiro/core/widget/horizontal-slider.cpp b/hiro/core/widget/horizontal-slider.cpp index d569dd4d..9330b43b 100644 --- a/hiro/core/widget/horizontal-slider.cpp +++ b/hiro/core/widget/horizontal-slider.cpp @@ -14,8 +14,8 @@ auto mHorizontalSlider::length() const -> unsigned { return state.length; } -auto mHorizontalSlider::onChange(const function& function) -> type& { - state.onChange = function; +auto mHorizontalSlider::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } diff --git a/hiro/core/widget/icon-view.cpp b/hiro/core/widget/icon-view.cpp index 502757a2..9dc1c762 100644 --- a/hiro/core/widget/icon-view.cpp +++ b/hiro/core/widget/icon-view.cpp @@ -55,18 +55,18 @@ auto mIconView::multiSelect() const -> bool { return state.multiSelect; } -auto mIconView::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mIconView::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } -auto mIconView::onChange(const function& function) -> type& { - state.onChange = function; +auto mIconView::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } -auto mIconView::onContext(const function& function) -> type& { - state.onContext = function; +auto mIconView::onContext(const function& callback) -> type& { + state.onContext = callback; return *this; } @@ -78,7 +78,7 @@ auto mIconView::remove(shared_pointer item) -> type& { signal(remove, item); state.items.remove(item->offset()); for(auto n : range(item->offset(), items())) { - state.items[n]->offset(-1); + state.items[n]->adjustOffset(-1); } item->setParent(); return *this; diff --git a/hiro/core/widget/line-edit.cpp b/hiro/core/widget/line-edit.cpp index 82bc4358..51654cd0 100644 --- a/hiro/core/widget/line-edit.cpp +++ b/hiro/core/widget/line-edit.cpp @@ -26,13 +26,13 @@ auto mLineEdit::foregroundColor() const -> Color { return state.foregroundColor; } -auto mLineEdit::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mLineEdit::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } -auto mLineEdit::onChange(const function& function) -> type& { - state.onChange = function; +auto mLineEdit::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } diff --git a/hiro/core/widget/list-view-item.cpp b/hiro/core/widget/list-view-item.cpp index 4962ec9b..94033df2 100644 --- a/hiro/core/widget/list-view-item.cpp +++ b/hiro/core/widget/list-view-item.cpp @@ -43,7 +43,7 @@ auto mListViewItem::remove(sListViewCell cell) -> type& { signal(remove, cell); state.cells.remove(cell->offset()); for(auto n : range(cell->offset(), cells())) { - state.cells[n]->offset(-1); + state.cells[n]->adjustOffset(-1); } cell->setParent(); return *this; diff --git a/hiro/core/widget/list-view.cpp b/hiro/core/widget/list-view.cpp index 65e3a890..e823080a 100644 --- a/hiro/core/widget/list-view.cpp +++ b/hiro/core/widget/list-view.cpp @@ -106,33 +106,33 @@ auto mListView::items() const -> unsigned { return state.items.size(); } -auto mListView::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mListView::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } -auto mListView::onChange(const function& function) -> type& { - state.onChange = function; +auto mListView::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } -auto mListView::onContext(const function& function) -> type& { - state.onContext = function; +auto mListView::onContext(const function& callback) -> type& { + state.onContext = callback; return *this; } -auto mListView::onEdit(const function& function) -> type& { - state.onEdit = function; +auto mListView::onEdit(const function& callback) -> type& { + state.onEdit = callback; return *this; } -auto mListView::onSort(const function& function) -> type& { - state.onSort = function; +auto mListView::onSort(const function& callback) -> type& { + state.onSort = callback; return *this; } -auto mListView::onToggle(const function& function) -> type& { - state.onToggle = function; +auto mListView::onToggle(const function& callback) -> type& { + state.onToggle = callback; return *this; } @@ -142,7 +142,7 @@ auto mListView::remove(sListViewColumn column) -> type& { state.items.reset(); state.columns.remove(column->offset()); for(auto n : range(column->offset(), columns())) { - state.columns[n]->offset(-1); + state.columns[n]->adjustOffset(-1); } column->setParent(); return *this; @@ -152,7 +152,7 @@ auto mListView::remove(sListViewItem item) -> type& { signal(remove, item); state.items.remove(item->offset()); for(auto n : range(item->offset(), items())) { - state.items[n]->offset(-1); + state.items[n]->adjustOffset(-1); } item->setParent(); return *this; diff --git a/hiro/core/widget/radio-button.cpp b/hiro/core/widget/radio-button.cpp index a509236f..cd6fca67 100644 --- a/hiro/core/widget/radio-button.cpp +++ b/hiro/core/widget/radio-button.cpp @@ -26,8 +26,8 @@ auto mRadioButton::icon() const -> image { return state.icon; } -auto mRadioButton::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mRadioButton::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } diff --git a/hiro/core/widget/radio-label.cpp b/hiro/core/widget/radio-label.cpp index c670c5b2..1607651f 100644 --- a/hiro/core/widget/radio-label.cpp +++ b/hiro/core/widget/radio-label.cpp @@ -18,8 +18,8 @@ auto mRadioLabel::group() const -> sGroup { return state.group; } -auto mRadioLabel::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mRadioLabel::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } diff --git a/hiro/core/widget/source-edit.cpp b/hiro/core/widget/source-edit.cpp index 2406d8f9..ec100116 100644 --- a/hiro/core/widget/source-edit.cpp +++ b/hiro/core/widget/source-edit.cpp @@ -14,13 +14,13 @@ auto mSourceEdit::doMove() const -> void { if(state.onMove) return state.onMove(); } -auto mSourceEdit::onChange(const function& function) -> type& { - state.onChange = function; +auto mSourceEdit::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } -auto mSourceEdit::onMove(const function& function) -> type& { - state.onMove = function; +auto mSourceEdit::onMove(const function& callback) -> type& { + state.onMove = callback; return *this; } diff --git a/hiro/core/widget/tab-frame.cpp b/hiro/core/widget/tab-frame.cpp index 54ea86db..82bbca49 100644 --- a/hiro/core/widget/tab-frame.cpp +++ b/hiro/core/widget/tab-frame.cpp @@ -43,18 +43,18 @@ auto mTabFrame::items() const -> unsigned { return state.items.size(); } -auto mTabFrame::onChange(const function& function) -> type& { - state.onChange = function; +auto mTabFrame::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } -auto mTabFrame::onClose(const function& function) -> type& { - state.onClose = function; +auto mTabFrame::onClose(const function& callback) -> type& { + state.onClose = callback; return *this; } -auto mTabFrame::onMove(const function& function) -> type& { - state.onMove = function; +auto mTabFrame::onMove(const function& callback) -> type& { + state.onMove = callback; return *this; } @@ -64,7 +64,7 @@ auto mTabFrame::remove(sTabFrameItem item) -> type& { signal(remove, item); state.items.remove(item->offset()); for(auto n : range(offset, items())) { - state.items[n]->offset(-1); + state.items[n]->adjustOffset(-1); } return *this; } diff --git a/hiro/core/widget/text-edit.cpp b/hiro/core/widget/text-edit.cpp index 7db7f016..909d7440 100644 --- a/hiro/core/widget/text-edit.cpp +++ b/hiro/core/widget/text-edit.cpp @@ -30,13 +30,13 @@ auto mTextEdit::foregroundColor() const -> Color { return state.foregroundColor; } -auto mTextEdit::onChange(const function& function) -> type& { - state.onChange = function; +auto mTextEdit::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } -auto mTextEdit::onMove(const function& function) -> type& { - state.onMove = function; +auto mTextEdit::onMove(const function& callback) -> type& { + state.onMove = callback; return *this; } diff --git a/hiro/core/widget/tree-view-item.cpp b/hiro/core/widget/tree-view-item.cpp index e75e783a..92616839 100644 --- a/hiro/core/widget/tree-view-item.cpp +++ b/hiro/core/widget/tree-view-item.cpp @@ -54,7 +54,7 @@ auto mTreeViewItem::remove(sTreeViewItem item) -> type& { signal(remove, item); state.items.remove(item->offset()); for(auto n : range(item->offset(), items())) { - state.items[n]->offset(-1); + state.items[n]->adjustOffset(-1); } item->setParent(); return *this; diff --git a/hiro/core/widget/tree-view.cpp b/hiro/core/widget/tree-view.cpp index 1c2738c8..05453d07 100644 --- a/hiro/core/widget/tree-view.cpp +++ b/hiro/core/widget/tree-view.cpp @@ -69,23 +69,23 @@ auto mTreeView::items() const -> unsigned { return state.items.size(); } -auto mTreeView::onActivate(const function& function) -> type& { - state.onActivate = function; +auto mTreeView::onActivate(const function& callback) -> type& { + state.onActivate = callback; return *this; } -auto mTreeView::onChange(const function& function) -> type& { - state.onChange = function; +auto mTreeView::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } -auto mTreeView::onContext(const function& function) -> type& { - state.onContext = function; +auto mTreeView::onContext(const function& callback) -> type& { + state.onContext = callback; return *this; } -auto mTreeView::onToggle(const function& function) -> type& { - state.onToggle = function; +auto mTreeView::onToggle(const function& callback) -> type& { + state.onToggle = callback; return *this; } @@ -93,7 +93,7 @@ auto mTreeView::remove(sTreeViewItem item) -> type& { signal(remove, item); state.items.remove(item->offset()); for(auto n : range(item->offset(), items())) { - state.items[n]->offset(-1); + state.items[n]->adjustOffset(-1); } item->setParent(); return *this; diff --git a/hiro/core/widget/vertical-scroller.cpp b/hiro/core/widget/vertical-scroller.cpp index 7792d10b..7212c00f 100644 --- a/hiro/core/widget/vertical-scroller.cpp +++ b/hiro/core/widget/vertical-scroller.cpp @@ -14,8 +14,8 @@ auto mVerticalScroller::length() const -> unsigned { return state.length; } -auto mVerticalScroller::onChange(const function& function) -> type& { - state.onChange = function; +auto mVerticalScroller::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } diff --git a/hiro/core/widget/vertical-slider.cpp b/hiro/core/widget/vertical-slider.cpp index 982cb1b5..7517f236 100644 --- a/hiro/core/widget/vertical-slider.cpp +++ b/hiro/core/widget/vertical-slider.cpp @@ -14,8 +14,8 @@ auto mVerticalSlider::length() const -> unsigned { return state.length; } -auto mVerticalSlider::onChange(const function& function) -> type& { - state.onChange = function; +auto mVerticalSlider::onChange(const function& callback) -> type& { + state.onChange = callback; return *this; } diff --git a/hiro/core/widget/viewport.cpp b/hiro/core/widget/viewport.cpp index 7962697a..763703b0 100644 --- a/hiro/core/widget/viewport.cpp +++ b/hiro/core/widget/viewport.cpp @@ -34,28 +34,28 @@ auto mViewport::handle() const -> uintptr_t { return signal(handle); } -auto mViewport::onDrop(const function& function) -> type& { - state.onDrop = function; +auto mViewport::onDrop(const function& callback) -> type& { + state.onDrop = callback; return *this; } -auto mViewport::onMouseLeave(const function& function) -> type& { - state.onMouseLeave = function; +auto mViewport::onMouseLeave(const function& callback) -> type& { + state.onMouseLeave = callback; return *this; } -auto mViewport::onMouseMove(const function& function) -> type& { - state.onMouseMove = function; +auto mViewport::onMouseMove(const function& callback) -> type& { + state.onMouseMove = callback; return *this; } -auto mViewport::onMousePress(const function& function) -> type& { - state.onMousePress = function; +auto mViewport::onMousePress(const function& callback) -> type& { + state.onMousePress = callback; return *this; } -auto mViewport::onMouseRelease(const function& function) -> type& { - state.onMouseRelease = function; +auto mViewport::onMouseRelease(const function& callback) -> type& { + state.onMouseRelease = callback; return *this; } diff --git a/hiro/core/widget/widget.cpp b/hiro/core/widget/widget.cpp index 901956ac..3cf4a292 100644 --- a/hiro/core/widget/widget.cpp +++ b/hiro/core/widget/widget.cpp @@ -10,8 +10,8 @@ auto mWidget::doSize() const -> void { if(state.onSize) return state.onSize(); } -auto mWidget::onSize(const function& function) -> type& { - state.onSize = function; +auto mWidget::onSize(const function& callback) -> type& { + state.onSize = callback; return *this; } diff --git a/hiro/core/window.cpp b/hiro/core/window.cpp index c014d363..8d04ec9e 100644 --- a/hiro/core/window.cpp +++ b/hiro/core/window.cpp @@ -13,7 +13,7 @@ auto mWindow::destruct() -> void { // -auto mWindow::append(shared_pointer layout) -> type& { +auto mWindow::append(sLayout layout) -> type& { if(auto& layout = state.layout) remove(layout); state.layout = layout; layout->setGeometry(geometry().setPosition(0, 0)); @@ -23,7 +23,7 @@ auto mWindow::append(shared_pointer layout) -> type& { return *this; } -auto mWindow::append(shared_pointer menuBar) -> type& { +auto mWindow::append(sMenuBar menuBar) -> type& { if(auto& menuBar = state.menuBar) remove(menuBar); menuBar->setParent(this, 0); state.menuBar = menuBar; @@ -31,7 +31,7 @@ auto mWindow::append(shared_pointer menuBar) -> type& { return *this; } -auto mWindow::append(shared_pointer statusBar) -> type& { +auto mWindow::append(sStatusBar statusBar) -> type& { if(auto& statusBar = state.statusBar) remove(statusBar); statusBar->setParent(this, 0); state.statusBar = statusBar; @@ -99,44 +99,44 @@ auto mWindow::modal() const -> bool { return state.modal; } -auto mWindow::onClose(const function& function) -> type& { - state.onClose = function; +auto mWindow::onClose(const function& callback) -> type& { + state.onClose = callback; return *this; } -auto mWindow::onDrop(const function& function) -> type& { - state.onDrop = function; +auto mWindow::onDrop(const function& callback) -> type& { + state.onDrop = callback; return *this; } -auto mWindow::onKeyPress(const function& function) -> type& { - state.onKeyPress = function; +auto mWindow::onKeyPress(const function& callback) -> type& { + state.onKeyPress = callback; return *this; } -auto mWindow::onKeyRelease(const function& function) -> type& { - state.onKeyRelease = function; +auto mWindow::onKeyRelease(const function& callback) -> type& { + state.onKeyRelease = callback; return *this; } -auto mWindow::onMove(const function& function) -> type& { - state.onMove = function; +auto mWindow::onMove(const function& callback) -> type& { + state.onMove = callback; return *this; } -auto mWindow::onSize(const function& function) -> type& { - state.onSize = function; +auto mWindow::onSize(const function& callback) -> type& { + state.onSize = callback; return *this; } -auto mWindow::remove(shared_pointer layout) -> type& { +auto mWindow::remove(sLayout layout) -> type& { signal(remove, layout); layout->setParent(); state.layout.reset(); return *this; } -auto mWindow::remove(shared_pointer menuBar) -> type& { +auto mWindow::remove(sMenuBar menuBar) -> type& { signal(remove, menuBar); menuBar->reset(); menuBar->setParent(); @@ -144,7 +144,7 @@ auto mWindow::remove(shared_pointer menuBar) -> type& { return *this; } -auto mWindow::remove(shared_pointer statusBar) -> type& { +auto mWindow::remove(sStatusBar statusBar) -> type& { signal(remove, statusBar); statusBar->setParent(); state.statusBar.reset(); @@ -168,19 +168,8 @@ auto mWindow::setBackgroundColor(Color color) -> type& { return *this; } -auto mWindow::setCentered() -> type& { - Geometry workspace = Desktop::workspace(); - Geometry geometry = frameGeometry(); - signed x = workspace.x(); - signed y = workspace.y(); - if(workspace.width() > geometry.width()) x += (workspace.width() - geometry.width()) / 2; - if(workspace.height() > geometry.height()) y += (workspace.height() - geometry.height()) / 2; - return setFrameGeometry({x, y, geometry.width(), geometry.height()}); -} - -auto mWindow::setCentered(shared_pointer parent) -> type& { - if(!parent) return setCentered(); - Geometry workspace = parent->frameGeometry(); +auto mWindow::setCentered(sWindow parent) -> type& { + Geometry workspace = parent ? parent->frameGeometry() : Desktop::workspace(); Geometry geometry = frameGeometry(); signed x = workspace.x(); signed y = workspace.y(); diff --git a/hiro/extension/fixed-layout.cpp b/hiro/extension/fixed-layout.cpp index 224c44ee..8db8f5e3 100644 --- a/hiro/extension/fixed-layout.cpp +++ b/hiro/extension/fixed-layout.cpp @@ -1,6 +1,6 @@ #if defined(Hiro_FixedLayout) -auto mFixedLayout::append(shared_pointer sizable, Geometry geometry) -> type& { +auto mFixedLayout::append(sSizable sizable, Geometry geometry) -> type& { properties.append({geometry}); mLayout::append(sizable); sizable->setGeometry(geometry); @@ -16,7 +16,7 @@ auto mFixedLayout::minimumSize() const -> Size { return {width, height}; } -auto mFixedLayout::remove(shared_pointer sizable) -> type& { +auto mFixedLayout::remove(sSizable sizable) -> type& { properties.remove(sizable->offset()); mLayout::remove(sizable); return *this; diff --git a/hiro/extension/fixed-layout.hpp b/hiro/extension/fixed-layout.hpp index 9b9a6da1..3d4c94f8 100644 --- a/hiro/extension/fixed-layout.hpp +++ b/hiro/extension/fixed-layout.hpp @@ -5,18 +5,18 @@ struct mFixedLayout : mLayout { using mLayout::append; using mLayout::remove; - auto append(nall::shared_pointer sizable, Geometry geometry) -> type&; + auto append(sSizable sizable, Geometry geometry) -> type&; auto minimumSize() const -> Size override; - auto remove(nall::shared_pointer sizable) -> type& override; + auto remove(sSizable sizable) -> type& override; auto reset() -> type& override; auto setEnabled(bool enabled = true) -> type& override; - auto setFont(const nall::string& font = "") -> type& override; + auto setFont(const string& font = "") -> type& override; auto setVisible(bool visible = true) ->type& override; struct Properties { Geometry geometry; }; - nall::vector properties; + vector properties; }; #endif diff --git a/hiro/extension/horizontal-layout.cpp b/hiro/extension/horizontal-layout.cpp index ccc0cfd7..fe49974e 100644 --- a/hiro/extension/horizontal-layout.cpp +++ b/hiro/extension/horizontal-layout.cpp @@ -1,6 +1,6 @@ #if defined(Hiro_HorizontalLayout) -auto mHorizontalLayout::append(shared_pointer sizable, Size size, signed spacing) -> type& { +auto mHorizontalLayout::append(sSizable sizable, Size size, signed spacing) -> type& { properties.append({size.width(), size.height(), spacing < 0 ? settings.spacing : spacing}); mLayout::append(sizable); return *this; @@ -31,7 +31,7 @@ auto mHorizontalLayout::minimumSize() const -> Size { return {settings.margin * 2 + width, settings.margin * 2 + height}; } -auto mHorizontalLayout::remove(shared_pointer sizable) -> type& { +auto mHorizontalLayout::remove(sSizable sizable) -> type& { properties.remove(sizable->offset()); mLayout::remove(sizable); return *this; diff --git a/hiro/extension/horizontal-layout.hpp b/hiro/extension/horizontal-layout.hpp index 5269f755..783a2768 100644 --- a/hiro/extension/horizontal-layout.hpp +++ b/hiro/extension/horizontal-layout.hpp @@ -5,13 +5,13 @@ struct mHorizontalLayout : mLayout { using mLayout::append; using mLayout::remove; - auto append(nall::shared_pointer sizable, Size size, signed spacing = 5) -> type&; + auto append(sSizable sizable, Size size, signed spacing = 5) -> type&; auto minimumSize() const -> Size override; - auto remove(nall::shared_pointer sizable) -> type& override; + auto remove(sSizable sizable) -> type& override; auto reset() -> type& override; auto setAlignment(double alignment = 0.5) -> type&; auto setEnabled(bool enabled = true) -> type& override; - auto setFont(const nall::string& font = "") -> type& override; + auto setFont(const string& font = "") -> type& override; auto setGeometry(Geometry geometry) -> type& override; auto setMargin(signed margin = 0) -> type&; auto setSpacing(signed spacing = 5) -> type&; @@ -28,7 +28,7 @@ struct mHorizontalLayout : mLayout { signed height; signed spacing; }; - nall::vector properties; + vector properties; }; #endif diff --git a/hiro/extension/shared.hpp b/hiro/extension/shared.hpp index 57fe6a90..6352192c 100644 --- a/hiro/extension/shared.hpp +++ b/hiro/extension/shared.hpp @@ -43,7 +43,7 @@ #define DeclareWidget(Name) \ DeclareSizable(Name) \ auto doSize() const -> void { return self().doSize(); } \ - auto onSize(const function& function = {}) -> type& { return self().onSize(function), *this; } \ + auto onSize(const function& callback = {}) -> type& { return self().onSize(callback), *this; } \ #if defined(Hiro_Object) struct Object : sObject { @@ -78,8 +78,8 @@ struct Hotkey : sHotkey { auto doPress() const -> void { return self().doPress(); } auto doRelease() const -> void { return self().doRelease(); } - auto onPress(const function& function = {}) -> type& { return self().onPress(function), *this; } - auto onRelease(const function& function = {}) -> type& { return self().onRelease(function), *this; } + auto onPress(const function& callback = {}) -> type& { return self().onPress(callback), *this; } + auto onRelease(const function& callback = {}) -> type& { return self().onRelease(callback), *this; } auto parent() const -> wObject { return self().parent(); } auto sequence() const -> string { return self().sequence(); } auto setParent(sObject object) -> type& { return self().setParent(object), *this; } @@ -93,7 +93,7 @@ struct Timer : sTimer { auto doActivate() const -> void { return self().doActivate(); } auto interval() const -> unsigned { return self().interval(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } auto setInterval(unsigned interval = 0) -> type& { return self().setInterval(interval), *this; } }; #endif @@ -119,20 +119,19 @@ struct Window : sWindow { auto layout() const -> sLayout { return self().layout(); } auto menuBar() const -> sMenuBar { return self().menuBar(); } auto modal() const -> bool { return self().modal(); } - auto onClose(const function& function = {}) -> type& { return self().onClose(function), *this; } - auto onDrop(const function& function = {}) -> type& { return self().onDrop(function), *this; } - auto onKeyPress(const function& function = {}) -> type& { return self().onKeyPress(function), *this; } - auto onKeyRelease(const function& function = {}) -> type& { return self().onKeyRelease(function), *this; } - auto onMove(const function& function = {}) -> type& { return self().onMove(function), *this; } - auto onSize(const function& function = {}) -> type& { return self().onSize(function), *this; } + auto onClose(const function& callback = {}) -> type& { return self().onClose(callback), *this; } + auto onDrop(const function& callback = {}) -> type& { return self().onDrop(callback), *this; } + auto onKeyPress(const function& callback = {}) -> type& { return self().onKeyPress(callback), *this; } + auto onKeyRelease(const function& callback = {}) -> type& { return self().onKeyRelease(callback), *this; } + auto onMove(const function& callback = {}) -> type& { return self().onMove(callback), *this; } + auto onSize(const function& callback = {}) -> type& { return self().onSize(callback), *this; } auto remove(sLayout layout) -> type& { return self().remove(layout), *this; } auto remove(sMenuBar menuBar) -> type& { return self().remove(menuBar), *this; } auto remove(sStatusBar statusBar) -> type& { return self().remove(statusBar), *this; } auto reset() -> type& { return self().reset(), *this; } auto resizable() const -> bool { return self().resizable(); } auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; } - auto setCentered() -> type& { return self().setCentered(), *this; } - auto setCentered(sWindow parent) -> type& { return self().setCentered(parent), *this; } + auto setCentered(sWindow parent = {}) -> type& { return self().setCentered(parent), *this; } auto setDroppable(bool droppable = true) -> type& { return self().setDroppable(droppable), *this; } auto setFrameGeometry(Geometry geometry) -> type& { return self().setFrameGeometry(geometry), *this; } auto setFramePosition(Position position) -> type& { return self().setFramePosition(position), *this; } @@ -217,7 +216,7 @@ struct MenuItem : sMenuItem { auto doActivate() const -> void { return self().doActivate(); } auto icon() const -> image { return self().icon(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } auto setIcon(const image& icon = {}) -> type& { return self().setIcon(icon), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto text() const -> string { return self().text(); } @@ -230,7 +229,7 @@ struct MenuCheckItem : sMenuCheckItem { auto checked() const -> bool { return self().checked(); } auto doToggle() const -> void { return self().doToggle(); } - auto onToggle(const function& function = {}) -> type& { return self().onToggle(function), *this; } + auto onToggle(const function& callback = {}) -> type& { return self().onToggle(callback), *this; } auto setChecked(bool checked = true) -> type& { return self().setChecked(checked), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto text() const -> string { return self().text(); } @@ -244,7 +243,7 @@ struct MenuRadioItem : sMenuRadioItem { auto checked() const -> bool { return self().checked(); } auto doActivate() const -> void { return self().doActivate(); } auto group() const -> sGroup { return self().group(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } auto setChecked() -> type& { return self().setChecked(), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto text() const -> string { return self().text(); } @@ -276,7 +275,7 @@ struct Button : sButton { auto bordered() const -> bool { return self().bordered(); } auto doActivate() const -> void { return self().doActivate(); } auto icon() const -> image { return self().icon(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } auto orientation() const -> Orientation { return self().orientation(); } auto setBordered(bool bordered = true) -> type& { return self().setBordered(bordered), *this; } auto setIcon(const image& icon = {}) -> type& { return self().setIcon(icon), *this; } @@ -300,11 +299,11 @@ struct Canvas : sCanvas { auto doMouseRelease(Mouse::Button button) const -> void { return self().doMouseRelease(button); } auto gradient() const -> vector { return self().gradient(); } auto icon() const -> image { return self().icon(); } - auto onDrop(const function& function = {}) -> type& { return self().onDrop(function), *this; } - auto onMouseLeave(const function& function = {}) -> type& { return self().onMouseLeave(function), *this; } - auto onMouseMove(const function& function = {}) -> type& { return self().onMouseMove(function), *this; } - auto onMousePress(const function& function = {}) -> type& { return self().onMousePress(function), *this; } - auto onMouseRelease(const function& function = {}) -> type& { return self().onMouseRelease(function), *this; } + auto onDrop(const function& callback = {}) -> type& { return self().onDrop(callback), *this; } + auto onMouseLeave(const function& callback = {}) -> type& { return self().onMouseLeave(callback), *this; } + auto onMouseMove(const function& callback = {}) -> type& { return self().onMouseMove(callback), *this; } + auto onMousePress(const function& callback = {}) -> type& { return self().onMousePress(callback), *this; } + auto onMouseRelease(const function& callback = {}) -> type& { return self().onMouseRelease(callback), *this; } auto setColor(Color color) -> type& { return self().setColor(color), *this; } auto setData(Size size) -> type& { return self().setData(size), *this; } auto setDroppable(bool droppable = true) -> type& { return self().setDroppable(droppable), *this; } @@ -325,7 +324,7 @@ struct CheckButton : sCheckButton { auto checked() const -> bool { return self().checked(); } auto doToggle() const -> void { return self().doToggle(); } auto icon() const -> image { return self().icon(); } - auto onToggle(const function& function = {}) -> type& { return self().onToggle(function), *this; } + auto onToggle(const function& callback = {}) -> type& { return self().onToggle(callback), *this; } auto orientation() const -> Orientation { return self().orientation(); } auto setBordered(bool bordered = true) -> type& { return self().setBordered(bordered), *this; } auto setChecked(bool checked = true) -> type& { return self().setChecked(checked), *this; } @@ -342,7 +341,7 @@ struct CheckLabel : sCheckLabel { auto checked() const -> bool { return self().checked(); } auto doToggle() const -> void { return self().doToggle(); } - auto onToggle(const function& function = {}) -> type& { return self().onToggle(function), *this; } + auto onToggle(const function& callback = {}) -> type& { return self().onToggle(callback), *this; } auto setChecked(bool checked = true) -> type& { return self().setChecked(checked), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto text() const -> string { return self().text(); } @@ -357,7 +356,7 @@ struct ComboButton : sComboButton { auto doChange() const -> void { return self().doChange(); } auto item(unsigned position) const -> sComboButtonItem { return self().item(position); } auto items() const -> unsigned { return self().items(); } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } auto remove(sComboButtonItem item) -> type& { return self().remove(item), *this; } auto reset() -> type& { return self().reset(), *this; } auto selected() const -> sComboButtonItem { return self().selected(); } @@ -385,7 +384,7 @@ struct Console : sConsole { auto backgroundColor() const -> Color { return self().backgroundColor(); } auto doActivate(string command) const -> void { return self().doActivate(command); } auto foregroundColor() const -> Color { return self().foregroundColor(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } auto print(const string& text) -> type& { return self().print(text), *this; } auto prompt() const -> string { return self().prompt(); } auto reset() -> type& { return self().reset(), *this; } @@ -419,8 +418,8 @@ struct HexEdit : sHexEdit { auto foregroundColor() const -> Color { return self().foregroundColor(); } auto length() const -> unsigned { return self().length(); } auto offset() const -> unsigned { return self().offset(); } - auto onRead(const function& function = {}) -> type& { return self().onRead(function), *this; } - auto onWrite(const function& function = {}) -> type& { return self().onWrite(function), *this; } + auto onRead(const function& callback = {}) -> type& { return self().onRead(callback), *this; } + auto onWrite(const function& callback = {}) -> type& { return self().onWrite(callback), *this; } auto rows() const -> unsigned { return self().rows(); } auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; } auto setColumns(unsigned columns = 16) -> type& { return self().setColumns(columns), *this; } @@ -438,7 +437,7 @@ struct HorizontalScroller : sHorizontalScroller { auto doChange() const -> void { return self().doChange(); } auto length() const -> unsigned { return self().length(); } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } auto position() const -> unsigned { return self().position(); } auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; } auto setPosition(unsigned position = 0) -> type& { return self().setPosition(position), *this; } @@ -451,7 +450,7 @@ struct HorizontalSlider : sHorizontalSlider { auto doChange() const -> void { return self().doChange(); } auto length() const -> unsigned { return self().length(); } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } auto position() const -> unsigned { return self().position(); } auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; } auto setPosition(unsigned position = 0) -> type& { return self().setPosition(position), *this; } @@ -472,9 +471,9 @@ struct IconView : sIconView { auto item(unsigned position) const -> sIconViewItem { return self().item(position); } auto items() const -> unsigned { return self().items(); } auto multiSelect() const -> bool { return self().multiSelect(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } - auto onContext(const function& function = {}) -> type& { return self().onContext(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } + auto onContext(const function& callback = {}) -> type& { return self().onContext(callback), *this; } auto orientation() const -> Orientation { return self().orientation(); } auto remove(sIconViewItem item) -> type& { return self().remove(item), *this; } auto reset() -> type& { return self().reset(), *this; } @@ -524,8 +523,8 @@ struct LineEdit : sLineEdit { auto doChange() const -> void { return self().doChange(); } auto editable() const -> bool { return self().editable(); } auto foregroundColor() const -> Color { return self().foregroundColor(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; } auto setEditable(bool editable = true) -> type& { return self().setEditable(editable), *this; } auto setForegroundColor(Color color = {}) -> type& { return self().setForegroundColor(color), *this; } @@ -558,12 +557,12 @@ struct ListView : sListView { auto headerVisible() const -> bool { return self().headerVisible(); } auto item(unsigned position) -> sListViewItem { return self().item(position); } auto items() const -> unsigned { return self().items(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } - auto onContext(const function& function = {}) -> type& { return self().onContext(function), *this; } - auto onEdit(const function& function = {}) -> type& { return self().onEdit(function), *this; } - auto onSort(const function& function = {}) -> type& { return self().onSort(function), *this; } - auto onToggle(const function& function = {}) -> type& { return self().onToggle(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } + auto onContext(const function& callback = {}) -> type& { return self().onContext(callback), *this; } + auto onEdit(const function& callback = {}) -> type& { return self().onEdit(callback), *this; } + auto onSort(const function& callback = {}) -> type& { return self().onSort(callback), *this; } + auto onToggle(const function& callback = {}) -> type& { return self().onToggle(callback), *this; } auto remove(sListViewColumn column) -> type& { return self().remove(column), *this; } auto remove(sListViewItem item) -> type& { return self().remove(item), *this; } auto reset() -> type& { return self().reset(), *this; } @@ -665,7 +664,7 @@ struct RadioButton : sRadioButton { auto doActivate() const -> void { return self().doActivate(); } auto group() const -> sGroup { return self().group(); } auto icon() const -> image { return self().icon(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } auto orientation() const -> Orientation { return self().orientation(); } auto setBordered(bool bordered = true) -> type& { return self().setBordered(bordered), *this; } auto setChecked() -> type& { return self().setChecked(), *this; } @@ -683,7 +682,7 @@ struct RadioLabel : sRadioLabel { auto checked() const -> bool { return self().checked(); } auto doActivate() const -> void { return self().doActivate(); } auto group() const -> sGroup { return self().group(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } auto setChecked() -> type& { return self().setChecked(), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto text() const -> string { return self().text(); } @@ -696,8 +695,8 @@ struct SourceEdit : sSourceEdit { auto doChange() const -> void { return self().doChange(); } auto doMove() const -> void { return self().doMove(); } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } - auto onMove(const function& function = {}) -> type& { return self().onMove(function), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } + auto onMove(const function& callback = {}) -> type& { return self().onMove(callback), *this; } auto position() const -> unsigned { return self().position(); } auto setPosition(signed position) -> type& { return self().setPosition(position), *this; } auto setSelected(Position selected) -> type& { return self().setSelected(selected), *this; } @@ -717,9 +716,9 @@ struct TabFrame : sTabFrame { auto edge() const -> Edge; auto item(unsigned position) const -> sTabFrameItem { return self().item(position); } auto items() const -> unsigned { return self().items(); } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } - auto onClose(const function& function = {}) -> type& { return self().onClose(function), *this; } - auto onMove(const function& function = {}) -> type& { return self().onMove(function), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } + auto onClose(const function& callback = {}) -> type& { return self().onClose(callback), *this; } + auto onMove(const function& callback = {}) -> type& { return self().onMove(callback), *this; } auto remove(sTabFrameItem item) -> type& { return self().remove(item), *this; } auto reset() -> type& { return self().reset(), *this; } auto selected() const -> sTabFrameItem { return self().selected(); } @@ -758,8 +757,8 @@ struct TextEdit : sTextEdit { auto doMove() const -> void { return self().doMove(); } auto editable() const -> bool { return self().editable(); } auto foregroundColor() const -> Color { return self().foregroundColor(); } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } - auto onMove(const function& function = {}) -> type& { return self().onMove(function), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } + auto onMove(const function& callback = {}) -> type& { return self().onMove(callback), *this; } auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; } auto setCursorPosition(unsigned position) -> type& { return self().setCursorPosition(position), *this; } auto setEditable(bool editable = true) -> type& { return self().setEditable(editable), *this; } @@ -787,10 +786,10 @@ struct TreeView : sTreeView { auto foregroundColor() const -> Color { return self().foregroundColor(); } auto item(const string& path) const -> sTreeViewItem { return self().item(path); } auto items() const -> unsigned { return self().items(); } - auto onActivate(const function& function = {}) -> type& { return self().onActivate(function), *this; } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } - auto onContext(const function& function = {}) -> type& { return self().onContext(function), *this; } - auto onToggle(const function& function = {}) -> type& { return self().onToggle(function), *this; } + auto onActivate(const function& callback = {}) -> type& { return self().onActivate(callback), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } + auto onContext(const function& callback = {}) -> type& { return self().onContext(callback), *this; } + auto onToggle(const function& callback = {}) -> type& { return self().onToggle(callback), *this; } auto remove(sTreeViewItem item) -> type& { return self().remove(item), *this; } auto reset() -> type& { return self().reset(), *this; } auto selected() const -> sTreeViewItem { return self().selected(); } @@ -826,7 +825,7 @@ struct VerticalScroller : sVerticalScroller { auto doChange() const -> void { return self().doChange(); } auto length() const -> unsigned { return self().length(); } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } auto position() const -> unsigned { return self().position(); } auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; } auto setPosition(unsigned position = 0) -> type& { return self().setPosition(position), *this; } @@ -839,7 +838,7 @@ struct VerticalSlider : sVerticalSlider { auto doChange() const -> void { return self().doChange(); } auto length() const -> unsigned { return self().length(); } - auto onChange(const function& function = {}) -> type& { return self().onChange(function), *this; } + auto onChange(const function& callback = {}) -> type& { return self().onChange(callback), *this; } auto position() const -> unsigned { return self().position(); } auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; } auto setPosition(unsigned position = 0) -> type& { return self().setPosition(position), *this; } @@ -857,11 +856,11 @@ struct Viewport : sViewport { auto doMouseRelease(Mouse::Button button) const -> void { return self().doMouseRelease(button); } auto droppable() const -> bool { return self().droppable(); } auto handle() const -> uintptr_t { return self().handle(); } - auto onDrop(const function& function = {}) -> type& { return self().onDrop(function), *this; } - auto onMouseLeave(const function& function = {}) -> type& { return self().onMouseLeave(function), *this; } - auto onMouseMove(const function& function = {}) -> type& { return self().onMouseMove(function), *this; } - auto onMousePress(const function& function = {}) -> type& { return self().onMousePress(function), *this; } - auto onMouseRelease(const function& function = {}) -> type& { return self().onMouseRelease(function), *this; } + auto onDrop(const function& callback = {}) -> type& { return self().onDrop(callback), *this; } + auto onMouseLeave(const function& callback = {}) -> type& { return self().onMouseLeave(callback), *this; } + auto onMouseMove(const function& callback = {}) -> type& { return self().onMouseMove(callback), *this; } + auto onMousePress(const function& callback = {}) -> type& { return self().onMousePress(callback), *this; } + auto onMouseRelease(const function& callback = {}) -> type& { return self().onMouseRelease(callback), *this; } auto setDroppable(bool droppable = true) -> type& { return self().setDroppable(droppable), *this; } }; #endif diff --git a/hiro/extension/vertical-layout.cpp b/hiro/extension/vertical-layout.cpp index e2d0bd90..8bce011b 100644 --- a/hiro/extension/vertical-layout.cpp +++ b/hiro/extension/vertical-layout.cpp @@ -1,6 +1,6 @@ #if defined(Hiro_VerticalLayout) -auto mVerticalLayout::append(shared_pointer sizable, Size size, signed spacing) -> type& { +auto mVerticalLayout::append(sSizable sizable, Size size, signed spacing) -> type& { properties.append({size.width(), size.height(), spacing < 0 ? settings.spacing : spacing}); mLayout::append(sizable); return *this; @@ -31,7 +31,7 @@ auto mVerticalLayout::minimumSize() const -> Size { return {settings.margin * 2 + width, settings.margin * 2 + height}; } -auto mVerticalLayout::remove(shared_pointer sizable) -> type& { +auto mVerticalLayout::remove(sSizable sizable) -> type& { properties.remove(sizable->offset()); mLayout::remove(sizable); return *this; diff --git a/hiro/extension/vertical-layout.hpp b/hiro/extension/vertical-layout.hpp index bd45d599..f8dc968d 100644 --- a/hiro/extension/vertical-layout.hpp +++ b/hiro/extension/vertical-layout.hpp @@ -5,13 +5,13 @@ struct mVerticalLayout : mLayout { using mLayout::append; using mLayout::remove; - auto append(nall::shared_pointer sizable, Size size, signed spacing = 5) -> type&; + auto append(sSizable sizable, Size size, signed spacing = 5) -> type&; auto minimumSize() const -> Size override; - auto remove(nall::shared_pointer sizable) -> type& override; + auto remove(sSizable sizable) -> type& override; auto reset() -> type& override; auto setAlignment(double alignment = 0.0) -> type&; auto setEnabled(bool enabled = true) -> type& override; - auto setFont(const nall::string& font = "") -> type& override; + auto setFont(const string& font = "") -> type& override; auto setGeometry(Geometry geometry) -> type& override; auto setMargin(signed margin = 0) -> type&; auto setSpacing(signed spacing = 5) -> type&; @@ -28,7 +28,7 @@ struct mVerticalLayout : mLayout { signed height; signed spacing; }; - nall::vector properties; + vector properties; }; #endif diff --git a/hiro/windows/application.cpp b/hiro/windows/application.cpp index b3d174df..67d29081 100644 --- a/hiro/windows/application.cpp +++ b/hiro/windows/application.cpp @@ -136,24 +136,30 @@ auto pApplication::initialize() -> void { static auto Application_keyboardProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> bool { if(msg != WM_KEYDOWN && msg != WM_SYSKEYDOWN && msg != WM_KEYUP && msg != WM_SYSKEYUP) return false; - GUITHREADINFO info; - memset(&info, 0, sizeof(GUITHREADINFO)); - info.cbSize = sizeof(GUITHREADINFO); + GUITHREADINFO info{sizeof(GUITHREADINFO)}; GetGUIThreadInfo(GetCurrentThreadId(), &info); + auto object = (mObject*)GetWindowLongPtr(info.hwndFocus, GWLP_USERDATA); if(!object) return false; if(auto window = dynamic_cast(object)) { - if(pWindow::modal && !pWindow::modal.find(window->self())) return false; - - if(auto code = pKeyboard::_translate(wparam, lparam)) { - if(msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) window->doKeyPress(code); - if(msg == WM_KEYUP || msg == WM_SYSKEYUP) window->doKeyRelease(code); + if(auto self = window->self()) { + if(!self->_modalityDisabled()) { + if(auto code = pKeyboard::_translate(wparam, lparam)) { + if(msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) window->doKeyPress(code); + if(msg == WM_KEYUP || msg == WM_SYSKEYUP) window->doKeyRelease(code); + } + } } - return false; } + if(auto window = object->parentWindow(true)) { + if(auto self = window->self()) { + if(self->_modalityDisabled()) return false; + } + } + if(msg == WM_KEYDOWN) { if(0); @@ -225,23 +231,26 @@ case WM_GETMINMAXINFO: { */ static auto CALLBACK Application_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT { + if(Application::state.quit) return DefWindowProc(hwnd, msg, wparam, lparam); + auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if(!object) return DefWindowProc(hwnd, msg, wparam, lparam); - auto& window = dynamic_cast(object) ? (mWindow&)*object : *object->parentWindow(true); + auto window = dynamic_cast(object); + if(!window) window = object->parentWindow(true); + if(!window) return DefWindowProc(hwnd, msg, wparam, lparam); + auto pWindow = window->self(); + if(!pWindow) return DefWindowProc(hwnd, msg, wparam, lparam); - bool process = true; - if(pWindow::modal && !pWindow::modal.find(window.self())) process = false; - if(Application::state.quit) process = false; - if(!process) return DefWindowProc(hwnd, msg, wparam, lparam); + if(pWindow->_modalityDisabled()) return DefWindowProc(hwnd, msg, wparam, lparam); switch(msg) { - case WM_CLOSE: window.self()->onClose(); return TRUE; - case WM_MOVE: window.self()->onMove(); break; - case WM_SIZE: window.self()->onSize(); break; - case WM_DROPFILES: window.self()->onDrop(wparam); return FALSE; - case WM_ERASEBKGND: if(window.self()->onEraseBackground()) return true; break; - case WM_ENTERMENULOOP: case WM_ENTERSIZEMOVE: window.self()->onModalBegin(); return FALSE; - case WM_EXITMENULOOP: case WM_EXITSIZEMOVE: window.self()->onModalEnd(); return FALSE; + case WM_CLOSE: pWindow->onClose(); return true; + case WM_MOVE: pWindow->onMove(); break; + case WM_SIZE: pWindow->onSize(); break; + case WM_DROPFILES: pWindow->onDrop(wparam); return false; + case WM_ERASEBKGND: if(pWindow->onEraseBackground()) return true; break; + case WM_ENTERMENULOOP: case WM_ENTERSIZEMOVE: pWindow->onModalBegin(); return false; + case WM_EXITMENULOOP: case WM_EXITSIZEMOVE: pWindow->onModalEnd(); return false; } return Shared_windowProc(DefWindowProc, hwnd, msg, wparam, lparam); diff --git a/hiro/windows/platform.hpp b/hiro/windows/platform.hpp index 4cbd5649..94515a7b 100644 --- a/hiro/windows/platform.hpp +++ b/hiro/windows/platform.hpp @@ -17,6 +17,8 @@ struct AppMessage { using WindowProc = auto CALLBACK (*)(HWND, UINT, WPARAM, LPARAM) -> LRESULT; +static vector windows; + } #define Declare(Name, Base) \ diff --git a/hiro/windows/utility.cpp b/hiro/windows/utility.cpp index 0898e4a4..430da703 100644 --- a/hiro/windows/utility.cpp +++ b/hiro/windows/utility.cpp @@ -145,16 +145,17 @@ static auto CALLBACK Menu_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM } static auto CALLBACK Shared_windowProc(WindowProc windowProc, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT { + if(Application::state.quit) return DefWindowProc(hwnd, msg, wparam, lparam); + auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if(!object) return DefWindowProc(hwnd, msg, wparam, lparam); auto window = dynamic_cast(object); if(!window) window = object->parentWindow(true); if(!window) return DefWindowProc(hwnd, msg, wparam, lparam); + auto pWindow = window->self(); + if(!pWindow) return DefWindowProc(hwnd, msg, wparam, lparam); - bool process = true; - if(pWindow::modal && !pWindow::modal.find(window->self())) process = false; - if(Application::state.quit) process = false; - if(!process) return DefWindowProc(hwnd, msg, wparam, lparam); + if(pWindow->_modalityDisabled()) return DefWindowProc(hwnd, msg, wparam, lparam); switch(msg) { case WM_CTLCOLORBTN: diff --git a/hiro/windows/widget/list-view.cpp b/hiro/windows/widget/list-view.cpp index 2f8a6c3a..8d781a39 100644 --- a/hiro/windows/widget/list-view.cpp +++ b/hiro/windows/widget/list-view.cpp @@ -2,6 +2,25 @@ namespace hiro { +static auto CALLBACK ListView_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT { + if(auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA)) { + if(auto listView = dynamic_cast(object)) { + if(auto self = listView->self()) { + if(!listView->enabled(true)) { + if(msg == WM_KEYDOWN || msg == WM_KEYUP || msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP) { + //WC_LISTVIEW responds to key messages even when its HWND is disabled + //the control should be inactive when disabled; so we intercept the messages here + return false; + } + } + return self->windowProc(hwnd, msg, wparam, lparam); + } + } + } + + return DefWindowProc(hwnd, msg, wparam, lparam); +} + auto pListView::construct() -> void { hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, WC_LISTVIEW, L"", @@ -9,6 +28,8 @@ auto pListView::construct() -> void { 0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0 ); SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference); + windowProc = (WindowProc)GetWindowLongPtr(hwnd, GWLP_WNDPROC); + SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)&ListView_windowProc); ListView_SetExtendedListViewStyle(hwnd, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES); pWidget::_setState(); setBackgroundColor(state().backgroundColor); diff --git a/hiro/windows/widget/list-view.hpp b/hiro/windows/widget/list-view.hpp index 32b171e7..107e8f8a 100644 --- a/hiro/windows/widget/list-view.hpp +++ b/hiro/windows/widget/list-view.hpp @@ -38,6 +38,7 @@ struct pListView : pWidget { auto _setIcons() -> void; auto _width(unsigned column) -> unsigned; + WindowProc windowProc = nullptr; HIMAGELIST imageList = 0; vector icons; }; diff --git a/hiro/windows/widget/tab-frame.cpp b/hiro/windows/widget/tab-frame.cpp index 5c9e3700..22efbc66 100644 --- a/hiro/windows/widget/tab-frame.cpp +++ b/hiro/windows/widget/tab-frame.cpp @@ -5,9 +5,12 @@ namespace hiro { static auto CALLBACK TabFrame_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT { if(auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA)) { if(auto tabFrame = dynamic_cast(object)) { - return Shared_windowProc(tabFrame->self()->windowProc, hwnd, msg, wparam, lparam); + if(auto self = tabFrame->self()) { + return Shared_windowProc(self->windowProc, hwnd, msg, wparam, lparam); + } } } + return DefWindowProc(hwnd, msg, wparam, lparam); } diff --git a/hiro/windows/widget/widget.cpp b/hiro/windows/widget/widget.cpp index 7b79f8ff..2d2a8afb 100644 --- a/hiro/windows/widget/widget.cpp +++ b/hiro/windows/widget/widget.cpp @@ -15,8 +15,9 @@ auto pWidget::destruct() -> void { DestroyWindow(hwnd); } -auto pWidget::focused() -> bool { - return GetFocus() == hwnd; +auto pWidget::focused() const -> bool { + auto focused = GetFocus(); + return hwnd == focused || IsChild(hwnd, focused); } auto pWidget::minimumSize() -> Size { @@ -44,11 +45,11 @@ auto pWidget::setFont(const string&) -> void { auto pWidget::setGeometry(Geometry geometry) -> void { if(auto parent = _parentWidget()) { - Position displacement = parent->geometry().position(); + auto displacement = parent->self().geometry().position(); geometry.setX(geometry.x() - displacement.x()); geometry.setY(geometry.y() - displacement.y()); } - SetWindowPos(hwnd, NULL, geometry.x(), geometry.y(), geometry.width(), geometry.height(), SWP_NOZORDER); + SetWindowPos(hwnd, nullptr, geometry.x(), geometry.y(), geometry.width(), geometry.height(), SWP_NOZORDER); self().doSize(); } @@ -62,20 +63,24 @@ auto pWidget::setVisible(bool visible) -> void { // auto pWidget::_parentHandle() -> HWND { - if(auto parent = _parentWidget()) return parent->self()->hwnd; - if(auto parent = _parentWindow()) return parent->self()->hwnd; - return 0; + if(auto parent = _parentWidget()) return parent->hwnd; + if(auto parent = _parentWindow()) return parent->hwnd; + return nullptr; } -auto pWidget::_parentWidget() -> maybe { +auto pWidget::_parentWidget() -> maybe { #if defined(Hiro_TabFrame) - if(auto parent = self().parentTabFrame(true)) return *parent; + if(auto parent = self().parentTabFrame(true)) { + if(auto self = parent->self()) return *self; + } #endif return nothing; } -auto pWidget::_parentWindow() -> maybe { - if(auto parent = self().parentWindow(true)) return *parent; +auto pWidget::_parentWindow() -> maybe { + if(auto parent = self().parentWindow(true)) { + if(auto self = parent->self()) return *self; + } return nothing; } diff --git a/hiro/windows/widget/widget.hpp b/hiro/windows/widget/widget.hpp index c613f554..e8350116 100644 --- a/hiro/windows/widget/widget.hpp +++ b/hiro/windows/widget/widget.hpp @@ -5,7 +5,7 @@ namespace hiro { struct pWidget : pSizable { Declare(Widget, Sizable) - auto focused() -> bool; + auto focused() const -> bool override; virtual auto minimumSize() -> Size; auto setEnabled(bool enabled) -> void override; auto setFocused() -> void; @@ -14,8 +14,8 @@ struct pWidget : pSizable { auto setVisible(bool visible) -> void override; auto _parentHandle() -> HWND; - auto _parentWidget() -> maybe; - auto _parentWindow() -> maybe; + auto _parentWidget() -> maybe; + auto _parentWindow() -> maybe; auto _setState() -> void; bool abstract = false; diff --git a/hiro/windows/window.cpp b/hiro/windows/window.cpp index c05230fa..4ecd7893 100644 --- a/hiro/windows/window.cpp +++ b/hiro/windows/window.cpp @@ -2,8 +2,6 @@ namespace hiro { -vector pWindow::modal; - static const unsigned FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER; static const unsigned ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME; @@ -12,9 +10,13 @@ auto pWindow::construct() -> void { SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference); setDroppable(state().droppable); setGeometry({128, 128, 256, 256}); + + windows.append(self().instance); } auto pWindow::destruct() -> void { + if(auto position = windows.find(self().instance)) windows.remove(*position); + if(hbrush) { DeleteObject(hbrush); hbrush = nullptr; } DestroyWindow(hwnd); } @@ -28,7 +30,7 @@ auto pWindow::append(sMenuBar menuBar) -> void { auto pWindow::append(sStatusBar statusBar) -> void { } -auto pWindow::focused() const -> bool override { +auto pWindow::focused() const -> bool { return (GetForegroundWindow() == hwnd); } @@ -122,7 +124,7 @@ auto pWindow::setGeometry(Geometry geometry) -> void { auto pWindow::setModal(bool modality) -> void { if(modality) { - modal.appendOnce(this); + _modalityUpdate(); while(state().modal) { Application::processEvents(); if(Application::state.onMain) { @@ -131,7 +133,7 @@ auto pWindow::setModal(bool modality) -> void { usleep(20 * 1000); } } - if(auto position = modal.find(this)) modal.remove(position()); + _modalityUpdate(); } } @@ -225,6 +227,39 @@ auto pWindow::_geometry() -> Geometry { return {x, y, width, height}; } +auto pWindow::_modalityCount() -> unsigned { + unsigned modalWindows = 0; + for(auto& weak : windows) { + if(auto object = weak.acquire()) { + if(auto window = dynamic_cast(object.data())) { + if(window->modal()) modalWindows++; + } + } + } + return modalWindows; +} + +auto pWindow::_modalityDisabled() -> bool { + if(_modalityCount() == 0) return false; + return !state().modal; +} + +auto pWindow::_modalityUpdate() -> void { + unsigned modalWindows = _modalityCount(); + for(auto& weak : windows) { + if(auto object = weak.acquire()) { + if(auto window = dynamic_cast(object.data())) { + if(auto self = window->self()) { + bool enabled = !modalWindows || window->modal(); + if(IsWindowEnabled(self->hwnd) != enabled) { + EnableWindow(self->hwnd, enabled); + } + } + } + } + } +} + } #endif diff --git a/hiro/windows/window.hpp b/hiro/windows/window.hpp index e22448b9..ad91a34b 100644 --- a/hiro/windows/window.hpp +++ b/hiro/windows/window.hpp @@ -33,13 +33,14 @@ struct pWindow : pObject { auto onSize() -> void; auto _geometry() -> Geometry; + auto _modalityCount() -> unsigned; + auto _modalityDisabled() -> bool; + auto _modalityUpdate() -> void; HWND hwnd = nullptr; HFONT hstatusfont = nullptr; HBRUSH hbrush = nullptr; COLORREF hbrushColor = 0; - - static vector modal; }; } diff --git a/nall/http/server.hpp b/nall/http/server.hpp index 41a57e07..6718a29f 100644 --- a/nall/http/server.hpp +++ b/nall/http/server.hpp @@ -1,9 +1,6 @@ #ifndef NALL_HTTP_SERVER_HPP #define NALL_HTTP_SERVER_HPP -#include -#include - #include #include diff --git a/nall/intrinsics.hpp b/nall/intrinsics.hpp index eadf33e5..90bd44e1 100644 --- a/nall/intrinsics.hpp +++ b/nall/intrinsics.hpp @@ -56,13 +56,16 @@ namespace nall { #define PLATFORM_WINDOWS Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Windows; } #elif defined(__APPLE__) + #define PLATFORM_POSIX #define PLATFORM_MACOSX Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::MacOSX; } #elif defined(linux) || defined(__linux__) + #define PLATFORM_POSIX #define PLATFORM_LINUX #define PLATFORM_XORG Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Linux; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) + #define PLATFORM_POSIX #define PLATFORM_BSD #define PLATFORM_XORG Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::BSD; } diff --git a/nall/platform.hpp b/nall/platform.hpp index 717cd4a6..d1139b14 100644 --- a/nall/platform.hpp +++ b/nall/platform.hpp @@ -51,6 +51,7 @@ namespace Math { #include #include #include + #include #endif #if defined(COMPILER_CL) @@ -58,17 +59,40 @@ namespace Math { #endif #if defined(PLATFORM_WINDOWS) + //fight Microsoft's ardent efforts at vendor lock-in + #undef interface #define dllexport __declspec(dllexport) #define MSG_NOSIGNAL 0 + extern "C" { + using pollfd = WSAPOLLFD; + } + inline auto access(const char* path, int amode) -> int { return _waccess(nall::utf16_t(path), amode); } inline auto getcwd(char* buf, size_t size) -> char* { wchar_t wpath[PATH_MAX] = L""; if(!_wgetcwd(wpath, size)) return nullptr; strcpy(buf, nall::utf8_t(wpath)); return buf; } inline auto mkdir(const char* path, int mode) -> int { return _wmkdir(nall::utf16_t(path)); } + inline auto poll(struct pollfd fds[], unsigned long nfds, int timeout) -> int { return WSAPoll(fds, nfds, timeout); } inline auto putenv(const char* value) -> int { return _wputenv(nall::utf16_t(value)); } inline auto realpath(const char* file_name, char* resolved_name) -> char* { wchar_t wfile_name[PATH_MAX] = L""; if(!_wfullpath(wfile_name, nall::utf16_t(file_name), PATH_MAX)) return nullptr; strcpy(resolved_name, nall::utf8_t(wfile_name)); return resolved_name; } inline auto rename(const char* oldname, const char* newname) -> int { return _wrename(nall::utf16_t(oldname), nall::utf16_t(newname)); } inline auto usleep(unsigned milliseconds) -> void { Sleep(milliseconds / 1000); } + + namespace nall { + //network functions take void*, not char*. this allows them to be used without casting + + inline auto recv(int socket, void* buffer, size_t length, int flags) -> ssize_t { + return ::recv(socket, (char*)buffer, length, flags); + } + + inline auto send(int socket, const void* buffer, size_t length, int flags) -> ssize_t { + return ::send(socket, (const char*)buffer, length, flags); + } + + inline auto setsockopt(int socket, int level, int option_name, const void* option_value, socklen_t option_len) -> int { + return ::setsockopt(socket, level, option_name, (const char*)option_value, option_len); + } + } #else #define dllexport #endif diff --git a/nall/posix/service.hpp b/nall/posix/service.hpp new file mode 100644 index 00000000..206b2381 --- /dev/null +++ b/nall/posix/service.hpp @@ -0,0 +1,117 @@ +#ifndef NALL_POSIX_SERVICE_HPP +#define NALL_POSIX_SERVICE_HPP + +#include + +namespace nall { + +struct service { + inline explicit operator bool() const; + inline auto command(const string& name, const string& command) -> bool; + inline auto receive() -> string; + inline auto name() const -> string; + inline auto stop() const -> bool; + +private: + shared_memory shared; + string _name; + bool _stop = false; +}; + +service::operator bool() const { + return (bool)shared; +} + +//returns true on new service process creation (false is not necessarily an error) +auto service::command(const string& name, const string& command) -> bool { + if(!name) return false; + if(!command) return print("[{0}] usage: {service} command\n" + "commands:\n" + " status : query whether service is running\n" + " start : start service if it is not running\n" + " stop : stop service if it is running\n" + " remove : remove semaphore lock if service crashed\n" + " {value} : send custom command to service\n" + "", format{name}), false; + + if(shared.open(name, 4096)) { + if(command == "start") { + print("[{0}] already started\n", format{name}); + } else if(command == "status") { + print("[{0}] running\n", format{name}); + } + if(auto data = shared.acquire()) { + if(command == "stop") print("[{0}] stopped\n", format{name}); + memory::copy(data, command.data(), min(command.size(), 4096)); + shared.release(); + } + if(command == "remove") { + shared.remove(); + print("[{0}] removed\n", format{name}); + } + return false; + } + + if(command == "start") { + if(shared.create(name, 4096)) { + print("[{0}] started\n", format{name}); + auto pid = fork(); + if(pid == 0) { + signal(SIGHUP, SIG_IGN); + signal(SIGPIPE, SIG_IGN); + _name = name; + return true; + } + shared.close(); + } else { + print("[{0}] start failed ({1})\n", format{name, strerror(errno)}); + } + return false; + } + + if(command == "status") { + print("[{0}] stopped\n", format{name}); + return false; + } + + return false; +} + +auto service::receive() -> string { + string command; + if(shared) { + if(auto data = shared.acquire()) { + if(*data) { + command.resize(4095); + memory::copy(command.pointer(), data, 4095); + memory::fill(data, 4096); + } + shared.release(); + if(command == "remove") { + _stop = true; + return ""; + } else if(command == "start") { + return ""; + } else if(command == "status") { + return ""; + } else if(command == "stop") { + _stop = true; + shared.remove(); + return ""; + } + } + } + return command; +} + +auto service::name() const -> string { + return _name; +} + +auto service::stop() const -> bool { + return _stop; +} + +} + +#endif diff --git a/nall/posix/shared-memory.hpp b/nall/posix/shared-memory.hpp new file mode 100644 index 00000000..549308d6 --- /dev/null +++ b/nall/posix/shared-memory.hpp @@ -0,0 +1,154 @@ +#ifndef NALL_POSIX_SHARED_MEMORY_HPP +#define NALL_POSIX_SHARED_MEMORY_HPP + +#include +#include + +namespace nall { + +struct shared_memory { + shared_memory() = default; + shared_memory(const shared_memory&) = delete; + auto operator=(const shared_memory&) -> shared_memory& = delete; + + ~shared_memory() { + reset(); + } + + explicit operator bool() const { + return _mode != mode::inactive; + } + + auto empty() const -> bool { + return _mode == mode::inactive; + } + + auto size() const -> unsigned { + return _size; + } + + auto acquired() const -> bool { + return _acquired; + } + + auto acquire() -> uint8_t* { + if(!acquired()) { + sem_wait(_semaphore); + _acquired = true; + } + return _data; + } + + auto release() -> void { + if(acquired()) { + sem_post(_semaphore); + _acquired = false; + } + } + + auto reset() -> void { + release(); + if(_mode == mode::server) return remove(); + if(_mode == mode::client) return close(); + } + + auto create(const string& name, unsigned size) -> bool { + reset(); + + _name = {"/nall::", string{name}.transform("/", ":")}; + _size = size; + + //O_CREAT | O_EXCL seems to throw ENOENT even when semaphore does not exist ... + _semaphore = sem_open(_name, O_CREAT, 0644, 1); + if(_semaphore == SEM_FAILED) return remove(), false; + + _descriptor = shm_open(_name, O_CREAT | O_TRUNC | O_RDWR, 0644); + if(_descriptor < 0) return remove(), false; + + if(ftruncate(_descriptor, _size) != 0) return remove(), false; + + _data = (uint8_t*)mmap(nullptr, _size, PROT_READ | PROT_WRITE, MAP_SHARED, _descriptor, 0); + if(_data == MAP_FAILED) return remove(), false; + + memory::fill(_data, _size); + + _mode = mode::server; + return true; + } + + auto remove() -> void { + if(_data) { + munmap(_data, _size); + _data = nullptr; + } + + if(_descriptor) { + ::close(_descriptor); + shm_unlink(_name); + _descriptor = -1; + } + + if(_semaphore) { + sem_close(_semaphore); + sem_unlink(_name); + _semaphore = nullptr; + } + + _mode = mode::inactive; + _name = ""; + _size = 0; + } + + auto open(const string& name, unsigned size) -> bool { + reset(); + + _name = {"/nall::", string{name}.transform("/", ":")}; + _size = size; + + _semaphore = sem_open(_name, 0, 0644); + if(_semaphore == SEM_FAILED) return close(), false; + + _descriptor = shm_open(_name, O_RDWR, 0644); + if(_descriptor < 0) return close(), false; + + _data = (uint8_t*)mmap(nullptr, _size, PROT_READ | PROT_WRITE, MAP_SHARED, _descriptor, 0); + if(_data == MAP_FAILED) return close(), false; + + _mode = mode::client; + return true; + } + + auto close() -> void { + if(_data) { + munmap(_data, _size); + _data = nullptr; + } + + if(_descriptor) { + ::close(_descriptor); + _descriptor = -1; + } + + if(_semaphore) { + sem_close(_semaphore); + _semaphore = nullptr; + } + + _mode = mode::inactive; + _name = ""; + _size = 0; + } + +private: + enum class mode : unsigned { server, client, inactive } _mode = mode::inactive; + string _name; + sem_t* _semaphore = nullptr; + signed _descriptor = -1; + uint8_t* _data = nullptr; + unsigned _size = 0; + bool _acquired = false; +}; + +} + +#endif diff --git a/nall/service.hpp b/nall/service.hpp index 19b9f072..c0f1774c 100644 --- a/nall/service.hpp +++ b/nall/service.hpp @@ -3,118 +3,14 @@ //service model template built on top of shared-memory -#include #include -namespace nall { +#if defined(PLATFORM_POSIX) + #include +#endif -struct service { - inline explicit operator bool() const; - inline auto command(const string& name, const string& command) -> bool; - inline auto receive() -> string; - inline auto name() const -> string; - inline auto stop() const -> bool; - -private: - shared_memory shared; - string _name; - bool _stop = false; -}; - -service::operator bool() const { - return (bool)shared; -} - -//returns true on new service process creation (false is not necessarily an error) -auto service::command(const string& name, const string& command) -> bool { - if(!name) return false; - if(!command) return print("[{0}] usage: {service} command\n" - "commands:\n" - " status : query whether service is running\n" - " start : start service if it is not running\n" - " stop : stop service if it is running\n" - " remove : remove semaphore lock if service crashed\n" - " {value} : send custom command to service\n" - "", format{name}), false; - - if(shared.open(name, 4096)) { - if(command == "start") { - print("[{0}] already started\n", format{name}); - } else if(command == "status") { - print("[{0}] running\n", format{name}); - } - if(auto data = shared.acquire()) { - if(command == "stop") print("[{0}] stopped\n", format{name}); - memory::copy(data, command.data(), min(command.size(), 4096)); - shared.release(); - } - if(command == "remove") { - shared.remove(); - print("[{0}] removed\n", format{name}); - } - return false; - } - - if(command == "start") { - if(shared.create(name, 4096)) { - print("[{0}] started\n", format{name}); - auto pid = fork(); - if(pid == 0) { - signal(SIGHUP, SIG_IGN); - signal(SIGPIPE, SIG_IGN); - _name = name; - return true; - } - shared.close(); - } else { - print("[{0}] start failed ({1})\n", format{name, strerror(errno)}); - } - return false; - } - - if(command == "status") { - print("[{0}] stopped\n", format{name}); - return false; - } - - return false; -} - -auto service::receive() -> string { - string command; - if(shared) { - if(auto data = shared.acquire()) { - if(*data) { - command.resize(4095); - memory::copy(command.pointer(), data, 4095); - memory::fill(data, 4096); - } - shared.release(); - if(command == "remove") { - _stop = true; - return ""; - } else if(command == "start") { - return ""; - } else if(command == "status") { - return ""; - } else if(command == "stop") { - _stop = true; - shared.remove(); - return ""; - } - } - } - return command; -} - -auto service::name() const -> string { - return _name; -} - -auto service::stop() const -> bool { - return _stop; -} - -} +#if defined(PLATFORM_WINDOWS) + #include +#endif #endif diff --git a/nall/shared-memory.hpp b/nall/shared-memory.hpp index ad237613..f94566cc 100644 --- a/nall/shared-memory.hpp +++ b/nall/shared-memory.hpp @@ -4,154 +4,12 @@ #include #include -#include -#include +#if defined(PLATFORM_POSIX) + #include +#endif -namespace nall { - -struct shared_memory { - shared_memory() = default; - shared_memory(const shared_memory&) = delete; - shared_memory& operator=(const shared_memory&) = delete; - - ~shared_memory() { - reset(); - } - - explicit operator bool() const { - return _mode != mode::inactive; - } - - auto empty() const -> bool { - return _mode == mode::inactive; - } - - auto size() const -> unsigned { - return _size; - } - - auto acquired() const -> bool { - return _acquired; - } - - auto acquire() -> uint8_t* { - if(!acquired()) { - sem_wait(_semaphore); - _acquired = true; - } - return _data; - } - - auto release() -> void { - if(acquired()) { - sem_post(_semaphore); - _acquired = false; - } - } - - auto reset() -> void { - release(); - if(_mode == mode::server) return remove(); - if(_mode == mode::client) return close(); - } - - auto create(const string& name, unsigned size) -> bool { - reset(); - - _name = {"/nall::", string{name}.transform("/", ":")}; - _size = size; - - //O_CREAT | O_EXCL seems to throw ENOENT even when semaphore does not exist ... - _semaphore = sem_open(_name, O_CREAT, 0644, 1); - if(_semaphore == SEM_FAILED) return remove(), false; - - _descriptor = shm_open(_name, O_CREAT | O_TRUNC | O_RDWR, 0644); - if(_descriptor < 0) return remove(), false; - - if(ftruncate(_descriptor, _size) != 0) return remove(), false; - - _data = (uint8_t*)mmap(nullptr, _size, PROT_READ | PROT_WRITE, MAP_SHARED, _descriptor, 0); - if(_data == MAP_FAILED) return remove(), false; - - memory::fill(_data, _size); - - _mode = mode::server; - return true; - } - - auto remove() -> void { - if(_data) { - munmap(_data, _size); - _data = nullptr; - } - - if(_descriptor) { - ::close(_descriptor); - shm_unlink(_name); - _descriptor = -1; - } - - if(_semaphore) { - sem_close(_semaphore); - sem_unlink(_name); - _semaphore = nullptr; - } - - _mode = mode::inactive; - _name = ""; - _size = 0; - } - - auto open(const string& name, unsigned size) -> bool { - reset(); - - _name = {"/nall::", string{name}.transform("/", ":")}; - _size = size; - - _semaphore = sem_open(_name, 0, 0644); - if(_semaphore == SEM_FAILED) return close(), false; - - _descriptor = shm_open(_name, O_RDWR, 0644); - if(_descriptor < 0) return close(), false; - - _data = (uint8_t*)mmap(nullptr, _size, PROT_READ | PROT_WRITE, MAP_SHARED, _descriptor, 0); - if(_data == MAP_FAILED) return close(), false; - - _mode = mode::client; - return true; - } - - auto close() -> void { - if(_data) { - munmap(_data, _size); - _data = nullptr; - } - - if(_descriptor) { - ::close(_descriptor); - _descriptor = -1; - } - - if(_semaphore) { - sem_close(_semaphore); - _semaphore = nullptr; - } - - _mode = mode::inactive; - _name = ""; - _size = 0; - } - -private: - enum class mode : unsigned { server, client, inactive } _mode = mode::inactive; - string _name; - sem_t* _semaphore = nullptr; - signed _descriptor = -1; - uint8_t* _data = nullptr; - unsigned _size = 0; - bool _acquired = false; -}; - -} +#if defined(PLATFORM_WINDOWS) + #include +#endif #endif diff --git a/nall/shared-pointer.hpp b/nall/shared-pointer.hpp index f3e6271a..13706e8e 100644 --- a/nall/shared-pointer.hpp +++ b/nall/shared-pointer.hpp @@ -80,7 +80,7 @@ struct shared_pointer { reset(); } - shared_pointer& operator=(T* source) { + auto operator=(T* source) -> shared_pointer& { reset(); if(source) { manager = new shared_pointer_manager((void*)source); @@ -89,7 +89,7 @@ struct shared_pointer { return *this; } - shared_pointer& operator=(const shared_pointer& source) { + auto operator=(const shared_pointer& source) -> shared_pointer& { if(this != &source) { reset(); if((bool)source) { @@ -100,7 +100,7 @@ struct shared_pointer { return *this; } - shared_pointer& operator=(shared_pointer&& source) { + auto operator=(shared_pointer&& source) -> shared_pointer& { if(this != &source) { reset(); manager = source.manager; @@ -110,7 +110,7 @@ struct shared_pointer { } template>> - shared_pointer& operator=(const shared_pointer& source) { + auto operator=(const shared_pointer& source) -> shared_pointer& { if((uintptr_t)this != (uintptr_t)&source) { reset(); if((bool)source) { @@ -122,7 +122,7 @@ struct shared_pointer { } template>> - shared_pointer& operator=(shared_pointer&& source) { + auto operator=(shared_pointer&& source) -> shared_pointer& { if((uintptr_t)this != (uintptr_t)&source) { reset(); manager = source.manager; @@ -132,7 +132,7 @@ struct shared_pointer { } template>> - shared_pointer& operator=(const shared_pointer_weak& source) { + auto operator=(const shared_pointer_weak& source) -> shared_pointer& { reset(); if((bool)source) { manager = source.manager; @@ -141,32 +141,32 @@ struct shared_pointer { return *this; } - T* data() { + auto data() -> T* { if(manager) return (T*)manager->pointer; return nullptr; } - const T* data() const { + auto data() const -> const T* { if(manager) return (T*)manager->pointer; return nullptr; } - T* operator->() { return data(); } - const T* operator->() const { return data(); } + auto operator->() -> T* { return data(); } + auto operator->() const -> const T* { return data(); } - T& operator*() { return *data(); } - const T& operator*() const { return *data(); } + auto operator*() -> T& { return *data(); } + auto operator*() const -> const T& { return *data(); } - T& operator()() { return *data(); } - const T& operator()() const { return *data(); } + auto operator()() -> T& { return *data(); } + auto operator()() const -> const T& { return *data(); } template - bool operator==(const shared_pointer& source) const { + auto operator==(const shared_pointer& source) const -> bool { return manager == source.manager; } template - bool operator!=(const shared_pointer& source) const { + auto operator!=(const shared_pointer& source) const -> bool { return manager != source.manager; } @@ -174,15 +174,15 @@ struct shared_pointer { return !empty(); } - bool empty() const { + auto empty() const -> bool { return !manager || !manager->strong; } - bool unique() const { + auto unique() const -> bool { return manager && manager->strong == 1; } - void reset() { + auto reset() -> void { if(manager && manager->strong) { //pointer may contain weak references; if strong==0 it may destroy manager //as such, we must destroy strong before decrementing it to zero @@ -204,7 +204,7 @@ struct shared_pointer { } template - shared_pointer cast() { + auto cast() -> shared_pointer { if(auto pointer = dynamic_cast(data())) { return {*this, pointer}; } @@ -224,7 +224,7 @@ struct shared_pointer_weak { operator=(source); } - shared_pointer_weak& operator=(const shared_pointer& source) { + auto operator=(const shared_pointer& source) -> shared_pointer_weak& { reset(); if(manager = source.manager) manager->weak++; return *this; @@ -234,19 +234,27 @@ struct shared_pointer_weak { reset(); } + auto operator==(const shared_pointer_weak& source) const -> bool { + return manager == source.manager; + } + + auto operator!=(const shared_pointer_weak& source) const -> bool { + return manager != source.manager; + } + explicit operator bool() const { return !empty(); } - bool empty() const { + auto empty() const -> bool { return !manager || !manager->strong; } - shared_pointer acquire() const { + auto acquire() const -> shared_pointer { return shared_pointer(*this); } - void reset() { + auto reset() -> void { if(manager && --manager->weak == 0) { if(manager->strong == 0) { delete manager; diff --git a/nall/windows/service.hpp b/nall/windows/service.hpp new file mode 100644 index 00000000..905bd7a8 --- /dev/null +++ b/nall/windows/service.hpp @@ -0,0 +1,16 @@ +#ifndef NALL_WINDOWS_SERVICE_HPP +#define NALL_WINDOWS_SERVICE_HPP + +namespace nall { + +struct service { + explicit operator bool() const { return false; } + auto command(const string& name, const string& command) -> bool { return false; } + auto receive() -> string { return ""; } + auto name() const -> string { return ""; } + auto stop() const -> bool { return false; } +}; + +} + +#endif diff --git a/nall/windows/shared-memory.hpp b/nall/windows/shared-memory.hpp new file mode 100644 index 00000000..efa24d35 --- /dev/null +++ b/nall/windows/shared-memory.hpp @@ -0,0 +1,30 @@ +#ifndef NALL_WINDOWS_SHARED_MEMORY_HPP +#define NALL_WINDOWS_SHARED_MEMORY_HPP + +namespace nall { + +struct shared_memory { + shared_memory() = default; + shared_memory(const shared_memory&) = delete; + auto operator=(const shared_memory&) -> shared_memory& = delete; + + ~shared_memory() { + reset(); + } + + explicit operator bool() const { return false; } + auto empty() const -> bool { return true; } + auto size() const -> unsigned { return 0; } + auto acquired() const -> bool { return false; } + auto acquire() -> uint8_t* { return nullptr; } + auto release() -> void {} + auto reset() -> void {} + auto create(const string& name, unsigned size) -> bool { return false; } + auto remove() -> void {} + auto open(const string& name, unsigned size) -> bool { return false; } + auto close() -> void {} +}; + +} + +#endif diff --git a/ruby/audio/alsa.cpp b/ruby/audio/alsa.cpp index 0c37a5fb..e8adb231 100644 --- a/ruby/audio/alsa.cpp +++ b/ruby/audio/alsa.cpp @@ -1,66 +1,66 @@ -//audio.alsa (2009-11-30) -//authors: BearOso, byuu, Nach, RedDwarf - #include namespace ruby { -class pAudioALSA { -public: +struct pAudioALSA { struct { - snd_pcm_t* handle; - snd_pcm_format_t format; + snd_pcm_t* handle = nullptr; + snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE; snd_pcm_uframes_t buffer_size; snd_pcm_uframes_t period_size; - int channels; - const char* name; + int channels = 2; + const char* name = "default"; } device; struct { - uint32_t* data; - unsigned length; + uint32_t* data = nullptr; + unsigned length = 0; } buffer; struct { - bool synchronize; - unsigned frequency; - unsigned latency; + bool synchronize = false; + unsigned frequency = 22050; + unsigned latency = 60; } settings; - bool cap(const string& name) { + ~pAudioALSA() { + term(); + } + + auto cap(const string& name) -> bool { if(name == Audio::Synchronize) return true; if(name == Audio::Frequency) return true; if(name == Audio::Latency) return true; return false; } - any get(const string& name) { + auto get(const string& name) -> any { if(name == Audio::Synchronize) return settings.synchronize; if(name == Audio::Frequency) return settings.frequency; if(name == Audio::Latency) return settings.latency; - return false; + return {}; } - bool set(const string& name, const any& value) { - if(name == Audio::Synchronize) { - if(settings.synchronize != any_cast(value)) { - settings.synchronize = any_cast(value); + auto set(const string& name, const any& value) -> bool { + if(name == Audio::Synchronize && value.is()) { + if(settings.synchronize != value.get()) { + settings.synchronize = value.get(); if(device.handle) init(); } return true; } - if(name == Audio::Frequency) { - if(settings.frequency != any_cast(value)) { - settings.frequency = any_cast(value); + if(name == Audio::Frequency && value.is()) { + if(settings.frequency != value.get()) { + settings.frequency = value.get(); if(device.handle) init(); } return true; } - if(name == Audio::Latency) { - if(settings.latency != any_cast(value)) { - settings.latency = any_cast(value); + if(name == Audio::Latency && value.is()) { + if(settings.latency != value.get()) { + settings.latency = value.get(); if(device.handle) init(); } return true; @@ -69,7 +69,7 @@ public: return false; } - void sample(uint16_t left, uint16_t right) { + auto sample(uint16_t left, uint16_t right) -> void { if(!device.handle) return; buffer.data[buffer.length++] = left + (right << 16); @@ -123,10 +123,10 @@ public: } } - void clear() { + auto clear() -> void { } - bool init() { + auto init() -> bool { term(); if(snd_pcm_open(&device.handle, device.name, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) { @@ -203,7 +203,7 @@ public: return true; } - void term() { + auto term() -> void { if(device.handle) { //snd_pcm_drain(device.handle); //prevents popping noise; but causes multi-second lag snd_pcm_close(device.handle); @@ -215,24 +215,6 @@ public: buffer.data = 0; } } - - pAudioALSA() { - device.handle = 0; - device.format = SND_PCM_FORMAT_S16_LE; - device.channels = 2; - device.name = "default"; - - buffer.data = 0; - buffer.length = 0; - - settings.synchronize = false; - settings.frequency = 22050; - settings.latency = 60; - } - - ~pAudioALSA() { - term(); - } }; DeclareAudio(ALSA) diff --git a/ruby/audio/ao.cpp b/ruby/audio/ao.cpp index 32bee07d..0d2d4fff 100644 --- a/ruby/audio/ao.cpp +++ b/ruby/audio/ao.cpp @@ -1,35 +1,38 @@ -/* - audio.ao (2008-06-01) - authors: Nach, RedDwarf -*/ - #include namespace ruby { -class pAudioAO { -public: +struct pAudioAO { int driver_id; ao_sample_format driver_format; - ao_device* audio_device; + ao_device* audio_device = nullptr; struct { - unsigned frequency; + unsigned frequency = 22050; } settings; - bool cap(const string& name) { + pAudioAO() { + ao_initialize(); + } + + ~pAudioAO() { + term(); + //ao_shutdown(); //FIXME: this is causing a segfault for some reason when called ... + } + + auto cap(const string& name) -> bool { if(name == Audio::Frequency) return true; return false; } - any get(const string& name) { + auto get(const string& name) -> any { if(name == Audio::Frequency) return settings.frequency; - return false; + return {}; } - bool set(const string& name, const any& value) { - if(name == Audio::Frequency) { - settings.frequency = any_cast(value); + auto set(const string& name, const any& value) -> bool { + if(name == Audio::Frequency && value.is()) { + settings.frequency = value.get(); if(audio_device) init(); return true; } @@ -37,15 +40,15 @@ public: return false; } - void sample(uint16_t l_sample, uint16_t r_sample) { + auto sample(uint16_t l_sample, uint16_t r_sample) -> void { uint32_t samp = (l_sample << 0) + (r_sample << 16); ao_play(audio_device, (char*)&samp, 4); //This may need to be byte swapped for Big Endian } - void clear() { + auto clear() -> void { } - bool init() { + auto init() -> bool { term(); driver_id = ao_default_driver_id(); //ao_driver_id((const char*)driver) @@ -69,24 +72,12 @@ public: return true; } - void term() { + auto term() -> void { if(audio_device) { ao_close(audio_device); - audio_device = 0; + audio_device = nullptr; } } - - pAudioAO() { - audio_device = 0; - ao_initialize(); - - settings.frequency = 22050; - } - - ~pAudioAO() { - term(); - //ao_shutdown(); //FIXME: this is causing a segfault for some reason when called ... - } }; DeclareAudio(AO) diff --git a/ruby/audio/pulseaudio.cpp b/ruby/audio/pulseaudio.cpp index e248bccf..3f995f19 100644 --- a/ruby/audio/pulseaudio.cpp +++ b/ruby/audio/pulseaudio.cpp @@ -1,70 +1,74 @@ -//audio.pulseaudio (2010-01-05) -//author: RedDwarf - #include namespace ruby { -class pAudioPulseAudio { -public: +struct pAudioPulseAudio { struct { - pa_mainloop* mainloop; - pa_context* context; - pa_stream* stream; + pa_mainloop* mainloop = nullptr; + pa_context* context = nullptr; + pa_stream* stream = nullptr; pa_sample_spec spec; pa_buffer_attr buffer_attr; bool first; } device; struct { - uint32_t* data; + uint32_t* data = nullptr; size_t size; unsigned offset; } buffer; struct { - bool synchronize; - unsigned frequency; - unsigned latency; + bool synchronize = false; + unsigned frequency = 22050; + unsigned latency = 60; } settings; - bool cap(const string& name) { + ~pAudioPulseAudio() { + term(); + } + + auto cap(const string& name) -> bool { if(name == Audio::Synchronize) return true; if(name == Audio::Frequency) return true; if(name == Audio::Latency) return true; + return false; } - any get(const string& name) { + auto get(const string& name) -> any { if(name == Audio::Synchronize) return settings.synchronize; if(name == Audio::Frequency) return settings.frequency; if(name == Audio::Latency) return settings.latency; + return {}; } - bool set(const string& name, const any& value) { - if(name == Audio::Synchronize) { - settings.synchronize = any_cast(value); + auto set(const string& name, const any& value) -> bool { + if(name == Audio::Synchronize && value.is()) { + settings.synchronize = value.get(); return true; } - if(name == Audio::Frequency) { - settings.frequency = any_cast(value); + if(name == Audio::Frequency && value.is()) { + settings.frequency = value.get(); if(device.stream) { pa_operation_unref(pa_stream_update_sample_rate(device.stream, settings.frequency, NULL, NULL)); } return true; } - if(name == Audio::Latency) { - settings.latency = any_cast(value); + if(name == Audio::Latency && value.is()) { + settings.latency = value.get(); if(device.stream) { device.buffer_attr.tlength = pa_usec_to_bytes(settings.latency * PA_USEC_PER_MSEC, &device.spec); pa_stream_set_buffer_attr(device.stream, &device.buffer_attr, NULL, NULL); } return true; } + + return false; } - void sample(uint16_t left, uint16_t right) { + auto sample(uint16_t left, uint16_t right) -> void { pa_stream_begin_write(device.stream, (void**)&buffer.data, &buffer.size); buffer.data[buffer.offset++] = left + (right << 16); if((buffer.offset + 1) * pa_frame_size(&device.spec) <= buffer.size) return; @@ -89,10 +93,10 @@ public: buffer.offset = 0; } - void clear() { + auto clear() -> void { } - bool init() { + auto init() -> bool { device.mainloop = pa_mainloop_new(); device.context = pa_context_new(pa_mainloop_get_api(device.mainloop), "ruby::pulseaudio"); @@ -133,43 +137,29 @@ public: return true; } - void term() { + auto term() -> void { if(buffer.data) { pa_stream_cancel_write(device.stream); - buffer.data = 0; + buffer.data = nullptr; } if(device.stream) { pa_stream_disconnect(device.stream); pa_stream_unref(device.stream); - device.stream = 0; + device.stream = nullptr; } if(device.context) { pa_context_disconnect(device.context); pa_context_unref(device.context); - device.context = 0; + device.context = nullptr; } if(device.mainloop) { pa_mainloop_free(device.mainloop); - device.mainloop = 0; + device.mainloop = nullptr; } } - - pAudioPulseAudio() { - device.mainloop = 0; - device.context = 0; - device.stream = 0; - buffer.data = 0; - settings.synchronize = false; - settings.frequency = 22050; - settings.latency = 60; - } - - ~pAudioPulseAudio() { - term(); - } }; DeclareAudio(PulseAudio) diff --git a/ruby/audio/pulseaudiosimple.cpp b/ruby/audio/pulseaudiosimple.cpp index 5815c6d7..26c2696f 100644 --- a/ruby/audio/pulseaudiosimple.cpp +++ b/ruby/audio/pulseaudiosimple.cpp @@ -1,40 +1,40 @@ -//audio.pulseaudiosimple (2010-01-05) -//author: byuu - #include #include namespace ruby { -class pAudioPulseAudioSimple { -public: +struct pAudioPulseAudioSimple { struct { - pa_simple* handle; + pa_simple* handle = nullptr; pa_sample_spec spec; } device; struct { - uint32_t* data; - unsigned offset; + uint32_t* data = nullptr; + unsigned offset = 0; } buffer; struct { - unsigned frequency; + unsigned frequency = 22050; } settings; - bool cap(const string& name) { + ~pAudioPulseAudioSimple() { + term(); + } + + auto cap(const string& name) -> bool { if(name == Audio::Frequency) return true; return false; } - any get(const string& name) { + auto get(const string& name) -> any { if(name == Audio::Frequency) return settings.frequency; - return false; + return {}; } - bool set(const string& name, const any& value) { - if(name == Audio::Frequency) { - settings.frequency = any_cast(value); + auto set(const string& name, const any& value) -> bool { + if(name == Audio::Frequency && value.is()) { + settings.frequency = value.get(); if(device.handle) init(); return true; } @@ -42,7 +42,7 @@ public: return false; } - void sample(uint16_t left, uint16_t right) { + auto sample(uint16_t left, uint16_t right) -> void { if(!device.handle) return; buffer.data[buffer.offset++] = left + (right << 16); @@ -53,10 +53,10 @@ public: } } - void clear() { + auto clear() -> void { } - bool init() { + auto init() -> bool { term(); device.spec.format = PA_SAMPLE_S16LE; @@ -85,7 +85,7 @@ public: return true; } - void term() { + auto term() -> void { if(device.handle) { int error; pa_simple_flush(device.handle, &error); @@ -98,16 +98,6 @@ public: buffer.data = nullptr; } } - - pAudioPulseAudioSimple() { - device.handle = nullptr; - buffer.data = nullptr; - settings.frequency = 22050; - } - - ~pAudioPulseAudioSimple() { - term(); - } }; DeclareAudio(PulseAudioSimple) diff --git a/ruby/input/carbon.cpp b/ruby/input/carbon.cpp index 329f4a6e..64aa8a85 100644 --- a/ruby/input/carbon.cpp +++ b/ruby/input/carbon.cpp @@ -8,39 +8,39 @@ struct pInputCarbon { vector keys; struct Keyboard { - HID::Keyboard hid; + shared_pointer hid{new HID::Keyboard}; } kb; - bool cap(const string& name) { + auto cap(const string& name) -> bool { if(name == Input::KeyboardSupport) return true; return false; } - any get(const string& name) { + auto get(const string& name) -> any { + return {}; + } + + auto set(const string& name, const any& value) -> bool { return false; } - bool set(const string& name, const any& value) { - return false; + auto acquire() -> bool { return false; } + auto unacquire() -> bool { return false; } + auto acquired() -> bool { return false; } + + auto assign(shared_pointer hid, unsigned groupID, unsigned inputID, int16_t value) -> void { + auto& group = hid->group(groupID); + if(group.input(inputID).value() == value) return; + if(input.onChange) input.onChange(hid, groupID, inputID, group.input(inputID).value(), value); + group.input(inputID).setValue(value); } - bool acquire() { return false; } - bool unacquire() { return false; } - bool acquired() { return false; } - - void assign(HID::Device& hid, unsigned groupID, unsigned inputID, int16_t value) { - auto& group = hid.group[groupID]; - if(group.input[inputID].value == value) return; - if(input.onChange) input.onChange(hid, groupID, inputID, group.input[inputID].value, value); - group.input[inputID].value = value; - } - - vector poll() { - vector devices; + auto poll() -> vector> { + vector> devices; KeyMap keymap; GetKeys(keymap); - uint8_t* buffer = (uint8_t*)keymap; + auto buffer = (uint8_t*)keymap; unsigned inputID = 0; for(auto& key : keys) { @@ -48,15 +48,15 @@ struct pInputCarbon { assign(kb.hid, HID::Keyboard::GroupID::Button, inputID++, value); } - devices.append(&kb.hid); + devices.append(kb.hid); return devices; } - bool rumble(uint64_t id, bool enable) { + auto rumble(uint64_t id, bool enable) -> bool { return false; } - bool init() { + auto init() -> bool { keys.append({0x35, "Escape"}); keys.append({0x7a, "F1"}); keys.append({0x78, "F2"}); @@ -170,13 +170,13 @@ struct pInputCarbon { keys.append({0x3a, "Alt"}); keys.append({0x37, "Super"}); - kb.hid.id = 1; - for(auto& key : keys) kb.hid.button().append({key.name}); + kb.hid->setID(1); + for(auto& key : keys) kb.hid->buttons().append(key.name); return true; } - void term() { + auto term() -> void { } }; diff --git a/ruby/input/joypad/udev.cpp b/ruby/input/joypad/udev.cpp index 8693ec17..17340d34 100644 --- a/ruby/input/joypad/udev.cpp +++ b/ruby/input/joypad/udev.cpp @@ -24,7 +24,7 @@ struct InputJoypadUdev { }; struct Joypad { - HID::Joypad hid; + shared_pointer hid{new HID::Joypad}; int fd = -1; dev_t device = 0; @@ -52,14 +52,14 @@ struct InputJoypadUdev { }; vector joypads; - void assign(HID::Joypad& hid, unsigned groupID, unsigned inputID, int16_t value) { - auto& group = hid.group[groupID]; - if(group.input[inputID].value == value) return; - if(input.onChange) input.onChange(hid, groupID, inputID, group.input[inputID].value, value); - group.input[inputID].value = value; + auto assign(shared_pointer hid, unsigned groupID, unsigned inputID, int16_t value) -> void { + auto& group = hid->group(groupID); + if(group.input(inputID).value() == value) return; + if(input.onChange) input.onChange(hid, groupID, inputID, group.input(inputID).value(), value); + group.input(inputID).setValue(value); } - void poll(vector& devices) { + auto poll(vector>& devices) -> void { while(hotplugDevicesAvailable()) hotplugDevice(); for(auto& jp : joypads) { @@ -92,14 +92,14 @@ struct InputJoypadUdev { } } - devices.append(&jp.hid); + devices.append(jp.hid); } } - bool rumble(uint64_t id, bool enable) { + auto rumble(uint64_t id, bool enable) -> bool { for(auto& jp : joypads) { - if(jp.hid.id != id) continue; - if(jp.hid.rumble == false) continue; + if(jp.hid->id() != id) continue; + if(!jp.hid->rumble()) continue; input_event play; memset(&play, 0, sizeof(input_event)); @@ -113,7 +113,7 @@ struct InputJoypadUdev { return false; } - bool init() { + auto init() -> bool { context = udev_new(); if(context == nullptr) return false; @@ -140,19 +140,19 @@ struct InputJoypadUdev { return true; } - void term() { + auto term() -> void { if(enumerator) { udev_enumerate_unref(enumerator); enumerator = nullptr; } } private: - bool hotplugDevicesAvailable() { + auto hotplugDevicesAvailable() -> bool { pollfd fd = {0}; fd.fd = udev_monitor_get_fd(monitor); fd.events = POLLIN; return (::poll(&fd, 1, 0) == 1) && (fd.revents & POLLIN); } - void hotplugDevice() { + auto hotplugDevice() -> void { udev_device* device = udev_monitor_receive_device(monitor); if(device == nullptr) return; @@ -169,7 +169,7 @@ private: } } - void createJoypad(udev_device* device, const string& deviceNode) { + auto createJoypad(udev_device* device, const string& deviceNode) -> void { Joypad jp; jp.deviceNode = deviceNode; @@ -254,17 +254,17 @@ private: #undef testBit } - void createJoypadHID(Joypad& jp) { + auto createJoypadHID(Joypad& jp) -> void { uint64_t pathID = Hash::CRC32(jp.deviceName.data(), jp.deviceName.size()).value(); - jp.hid.id = pathID << 32 | hex(jp.vendorID) << 16 | hex(jp.productID) << 0; + jp.hid->setID(pathID << 32 | hex(jp.vendorID) << 16 | hex(jp.productID) << 0); - for(unsigned n = 0; n < jp.axes.size(); n++) jp.hid.axis().append({n}); - for(unsigned n = 0; n < jp.hats.size(); n++) jp.hid.hat().append({n}); - for(unsigned n = 0; n < jp.buttons.size(); n++) jp.hid.button().append({n}); - jp.hid.rumble = jp.rumble; + for(unsigned n = 0; n < jp.axes.size(); n++) jp.hid->axes().append(n); + for(unsigned n = 0; n < jp.hats.size(); n++) jp.hid->hats().append(n); + for(unsigned n = 0; n < jp.buttons.size(); n++) jp.hid->buttons().append(n); + jp.hid->setRumble(jp.rumble); } - void removeJoypad(udev_device* device, const string& deviceNode) { + auto removeJoypad(udev_device* device, const string& deviceNode) -> void { for(unsigned n = 0; n < joypads.size(); n++) { if(joypads[n].deviceNode == deviceNode) { close(joypads[n].fd); diff --git a/ruby/input/udev.cpp b/ruby/input/udev.cpp index a53d95d5..a0006771 100644 --- a/ruby/input/udev.cpp +++ b/ruby/input/udev.cpp @@ -23,7 +23,7 @@ struct pInputUdev { uintptr_t handle = 0; } settings; - bool cap(const string& name) { + auto cap(const string& name) -> bool { if(name == Input::Handle) return true; if(name == Input::KeyboardSupport) return true; if(name == Input::MouseSupport) return true; @@ -32,51 +32,51 @@ struct pInputUdev { return false; } - any get(const string& name) { - if(name == Input::Handle) return (uintptr_t)settings.handle; - return false; + auto get(const string& name) -> any { + if(name == Input::Handle) return settings.handle; + return {}; } - bool set(const string& name, const any& value) { - if(name == Input::Handle) { - settings.handle = any_cast(value); + auto set(const string& name, const any& value) -> bool { + if(name == Input::Handle && value.is()) { + settings.handle = value.get(); return true; } return false; } - bool acquire() { + auto acquire() -> bool { return xlibMouse.acquire(); } - bool unacquire() { + auto unacquire() -> bool { return xlibMouse.unacquire(); } - bool acquired() { + auto acquired() -> bool { return xlibMouse.acquired(); } - vector poll() { - vector devices; + auto poll() -> vector> { + vector> devices; xlibKeyboard.poll(devices); xlibMouse.poll(devices); udev.poll(devices); return devices; } - bool rumble(uint64_t id, bool enable) { + auto rumble(uint64_t id, bool enable) -> bool { return udev.rumble(id, enable); } - bool init() { + auto init() -> bool { if(xlibKeyboard.init() == false) return false; if(xlibMouse.init(settings.handle) == false) return false; if(udev.init() == false) return false; return true; } - void term() { + auto term() -> void { xlibKeyboard.term(); xlibMouse.term(); udev.term(); diff --git a/ruby/video/cgl.cpp b/ruby/video/cgl.cpp index b1f4fd1e..7b4e2e50 100644 --- a/ruby/video/cgl.cpp +++ b/ruby/video/cgl.cpp @@ -1,7 +1,7 @@ #include "opengl/opengl.hpp" namespace ruby { - class pVideoCGL; + struct pVideoCGL; } @interface RubyVideoCGL : NSOpenGLView { @@ -20,11 +20,15 @@ struct pVideoCGL : OpenGL { struct { NSView* handle = nullptr; bool synchronize = false; - unsigned filter = 0; + unsigned filter = Video::FilterNearest; string shader; } settings; - bool cap(const string& name) { + ~pVideoCGL() { + term(); + } + + auto cap(const string& name) -> bool { if(name == Video::Handle) return true; if(name == Video::Synchronize) return true; if(name == Video::Filter) return true; @@ -32,22 +36,22 @@ struct pVideoCGL : OpenGL { return false; } - any get(const string& name) { + auto get(const string& name) -> any { if(name == Video::Handle) return (uintptr_t)settings.handle; if(name == Video::Synchronize) return settings.synchronize; if(name == Video::Filter) return settings.filter; - return false; + return {}; } - bool set(const string& name, const any& value) { - if(name == Video::Handle) { - settings.handle = (NSView*)any_cast(value); + auto set(const string& name, const any& value) -> bool { + if(name == Video::Handle && value.is()) { + settings.handle = (NSView*)value.get(); return true; } - if(name == Video::Synchronize) { - if(settings.synchronize != any_cast(value)) { - settings.synchronize = any_cast(value); + if(name == Video::Synchronize && value.is()) { + if(settings.synchronize != value.get()) { + settings.synchronize = value.get(); if(view) { @autoreleasepool { @@ -60,34 +64,34 @@ struct pVideoCGL : OpenGL { return true; } - if(name == Video::Filter) { - settings.filter = any_cast(value); - if(settings.shader.empty()) OpenGL::filter = settings.filter ? GL_LINEAR : GL_NEAREST; + if(name == Video::Filter && value.is()) { + settings.filter = value.get(); + if(!settings.shader) OpenGL::filter = settings.filter ? GL_LINEAR : GL_NEAREST; return true; } - if(name == Video::Shader) { - settings.shader = any_cast(value); + if(name == Video::Shader && value.is()) { + settings.shader = value.get(); @autoreleasepool { [[view openGLContext] makeCurrentContext]; } OpenGL::shader(settings.shader); - if(settings.shader.empty()) OpenGL::filter = settings.filter ? GL_LINEAR : GL_NEAREST; + if(!settings.shader) OpenGL::filter = settings.filter ? GL_LINEAR : GL_NEAREST; return true; } return false; } - bool lock(uint32_t*& data, unsigned& pitch, unsigned width, unsigned height) { + auto lock(uint32_t*& data, unsigned& pitch, unsigned width, unsigned height) -> bool { OpenGL::size(width, height); return OpenGL::lock(data, pitch); } - void unlock() { + auto unlock() -> void { } - void clear() { + auto clear() -> void { @autoreleasepool { [view lockFocus]; OpenGL::clear(); @@ -96,7 +100,7 @@ struct pVideoCGL : OpenGL { } } - void refresh() { + auto refresh() -> void { @autoreleasepool { if([view lockFocusIfCanDraw]) { auto area = [view frame]; @@ -108,7 +112,7 @@ struct pVideoCGL : OpenGL { } } - bool init() { + auto init() -> bool { term(); @autoreleasepool { @@ -146,7 +150,7 @@ struct pVideoCGL : OpenGL { return true; } - void term() { + auto term() -> void { OpenGL::term(); @autoreleasepool { @@ -155,10 +159,6 @@ struct pVideoCGL : OpenGL { view = nil; } } - - ~pVideoCGL() { - term(); - } }; DeclareVideo(CGL) diff --git a/target-tomoko/GNUmakefile b/target-tomoko/GNUmakefile index 7022cab1..6dc8442b 100644 --- a/target-tomoko/GNUmakefile +++ b/target-tomoko/GNUmakefile @@ -25,7 +25,7 @@ else ifeq ($(platform),macosx) else ifeq ($(platform),linux) ruby += video.glx video.xv video.xshm video.sdl ruby += audio.alsa audio.openal audio.oss audio.pulseaudio audio.pulseaudiosimple audio.ao - ruby += input.sdl input.xlib #input.udev + ruby += input.udev input.sdl input.xlib else ifeq ($(platform),bsd) ruby += video.glx video.xv video.xshm video.sdl ruby += audio.openal audio.oss