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.
This commit is contained in:
Tim Allen 2015-06-16 08:16:43 +10:00
parent f0c17ffc0d
commit bb3c69a30d
75 changed files with 1017 additions and 906 deletions

View File

@ -3,7 +3,7 @@
namespace Emulator { namespace Emulator {
static const char Name[] = "higan"; 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 Author[] = "byuu";
static const char License[] = "GPLv3"; static const char License[] = "GPLv3";
static const char Website[] = "http://byuu.org/"; static const char Website[] = "http://byuu.org/";

View File

@ -14,8 +14,8 @@ auto mMenuCheckItem::doToggle() const -> void {
if(state.onToggle) return state.onToggle(); if(state.onToggle) return state.onToggle();
} }
auto mMenuCheckItem::onToggle(const function<void ()>& function) -> type& { auto mMenuCheckItem::onToggle(const function<void ()>& callback) -> type& {
state.onToggle = function; state.onToggle = callback;
return *this; return *this;
} }

View File

@ -14,8 +14,8 @@ auto mMenuItem::icon() const -> image {
return state.icon; return state.icon;
} }
auto mMenuItem::onActivate(const function<void ()>& function) -> type& { auto mMenuItem::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }

View File

@ -18,8 +18,8 @@ auto mMenuRadioItem::group() const -> sGroup {
return state.group; return state.group;
} }
auto mMenuRadioItem::onActivate(const function<void ()>& function) -> type& { auto mMenuRadioItem::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }

View File

@ -35,7 +35,7 @@ auto mMenu::remove(sAction action) -> type& {
signal(remove, *action); signal(remove, *action);
state.actions.remove(action->offset()); state.actions.remove(action->offset());
for(auto n : range(action->offset(), actions())) { for(auto n : range(action->offset(), actions())) {
state.actions[n]->offset(-1); state.actions[n]->adjustOffset(-1);
} }
action->setParent(); action->setParent();
} }

View File

@ -14,8 +14,8 @@ auto Application::name() -> string {
return state.name; return state.name;
} }
auto Application::onMain(const nall::function<void ()>& function) -> void { auto Application::onMain(const function<void ()>& callback) -> void {
state.onMain = function; state.onMain = callback;
} }
auto Application::run() -> void { auto Application::run() -> void {
@ -50,8 +50,8 @@ auto Application::Windows::doModalChange(bool modal) -> void {
if(state.windows.onModalChange) return state.windows.onModalChange(modal); if(state.windows.onModalChange) return state.windows.onModalChange(modal);
} }
auto Application::Windows::onModalChange(const function<void (bool)>& function) -> void { auto Application::Windows::onModalChange(const function<void (bool)>& callback) -> void {
state.windows.onModalChange = function; state.windows.onModalChange = callback;
} }
//Cocoa //Cocoa
@ -73,20 +73,20 @@ auto Application::Cocoa::doQuit() -> void {
if(state.cocoa.onQuit) return state.cocoa.onQuit(); if(state.cocoa.onQuit) return state.cocoa.onQuit();
} }
auto Application::Cocoa::onAbout(const function<void ()>& function) -> void { auto Application::Cocoa::onAbout(const function<void ()>& callback) -> void {
state.cocoa.onAbout = function; state.cocoa.onAbout = callback;
} }
auto Application::Cocoa::onActivate(const function<void ()>& function) -> void { auto Application::Cocoa::onActivate(const function<void ()>& callback) -> void {
state.cocoa.onActivate = function; state.cocoa.onActivate = callback;
} }
auto Application::Cocoa::onPreferences(const function<void ()>& function) -> void { auto Application::Cocoa::onPreferences(const function<void ()>& callback) -> void {
state.cocoa.onPreferences = function; state.cocoa.onPreferences = callback;
} }
auto Application::Cocoa::onQuit(const function<void ()>& function) -> void { auto Application::Cocoa::onQuit(const function<void ()>& callback) -> void {
state.cocoa.onQuit = function; state.cocoa.onQuit = callback;
} }
//Internal //Internal

View File

@ -4,12 +4,8 @@ Color::Color() {
setColor(0, 0, 0, 0); setColor(0, 0, 0, 0);
} }
Color::Color(signed red, signed green, signed blue) { Color::Color(signed red, signed green, signed blue, signed alpha) {
setColor(255, red, green, blue); setColor(red, green, blue, alpha);
}
Color::Color(signed alpha, signed red, signed green, signed blue) {
setColor(alpha, red, green, blue);
} }
Color::operator bool() const { Color::operator bool() const {
@ -17,7 +13,7 @@ Color::operator bool() const {
} }
auto Color::operator==(const Color& source) const -> bool { 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 { auto Color::operator!=(const Color& source) const -> bool {
@ -33,7 +29,7 @@ auto Color::blue() const -> uint8_t {
} }
auto Color::empty() const -> bool { 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 { auto Color::green() const -> uint8_t {
@ -55,18 +51,14 @@ auto Color::setBlue(signed blue) -> type& {
} }
auto Color::setColor(Color color) -> 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& { auto Color::setColor(signed red, signed green, signed blue, signed alpha) -> 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));
state.red = max(0, min(255, red )); state.red = max(0, min(255, red ));
state.green = max(0, min(255, green)); state.green = max(0, min(255, green));
state.blue = max(0, min(255, blue )); state.blue = max(0, min(255, blue ));
state.alpha = max(0, min(255, alpha));
return *this; return *this;
} }

View File

@ -92,7 +92,7 @@ struct Application {
static auto doMain() -> void; static auto doMain() -> void;
static auto font() -> string; static auto font() -> string;
static auto name() -> string; static auto name() -> string;
static auto onMain(const function<void ()>& function = {}) -> void; static auto onMain(const function<void ()>& callback = {}) -> void;
static auto run() -> void; static auto run() -> void;
static auto pendingEvents() -> bool; static auto pendingEvents() -> bool;
static auto processEvents() -> void; static auto processEvents() -> void;
@ -102,7 +102,7 @@ struct Application {
struct Windows { struct Windows {
static auto doModalChange(bool modal) -> void; static auto doModalChange(bool modal) -> void;
static auto onModalChange(const function<void (bool)>& function = {}) -> void; static auto onModalChange(const function<void (bool)>& callback = {}) -> void;
}; };
struct Cocoa { struct Cocoa {
@ -110,10 +110,10 @@ struct Application {
static auto doActivate() -> void; static auto doActivate() -> void;
static auto doPreferences() -> void; static auto doPreferences() -> void;
static auto doQuit() -> void; static auto doQuit() -> void;
static auto onAbout(const function<void ()>& function = {}) -> void; static auto onAbout(const function<void ()>& callback = {}) -> void;
static auto onActivate(const function<void ()>& function = {}) -> void; static auto onActivate(const function<void ()>& callback = {}) -> void;
static auto onPreferences(const function<void ()>& function = {}) -> void; static auto onPreferences(const function<void ()>& callback = {}) -> void;
static auto onQuit(const function<void ()>& function = {}) -> void; static auto onQuit(const function<void ()>& callback = {}) -> void;
}; };
//private: //private:
@ -144,8 +144,7 @@ struct Color {
using type = Color; using type = Color;
Color(); Color();
Color(signed red, signed green, signed blue); Color(signed red, signed green, signed blue, signed alpha = 255);
Color(signed alpha, signed red, signed green, signed blue);
explicit operator bool() const; explicit operator bool() const;
auto operator==(const Color& source) const -> bool; auto operator==(const Color& source) const -> bool;
@ -159,18 +158,17 @@ struct Color {
auto setAlpha(signed alpha) -> type&; auto setAlpha(signed alpha) -> type&;
auto setBlue(signed blue) -> type&; auto setBlue(signed blue) -> type&;
auto setColor(Color color = {}) -> type&; auto setColor(Color color = {}) -> type&;
auto setColor(signed red, signed green, signed blue) -> type&; auto setColor(signed red, signed green, signed blue, signed alpha = 255) -> type&;
auto setColor(signed alpha, signed red, signed green, signed blue) -> type&;
auto setGreen(signed green) -> type&; auto setGreen(signed green) -> type&;
auto setRed(signed red) -> type&; auto setRed(signed red) -> type&;
auto value() const -> uint32_t; auto value() const -> uint32_t;
//private: //private:
struct State { struct State {
signed alpha;
signed red; signed red;
signed green; signed green;
signed blue; signed blue;
signed alpha;
} state; } state;
}; };
#endif #endif
@ -408,12 +406,12 @@ struct mObject {
mObject& operator=(const mObject&) = delete; mObject& operator=(const mObject&) = delete;
auto abstract() const -> bool; auto abstract() const -> bool;
auto adjustOffset(signed displacement) -> type&;
auto enabled(bool recursive = false) const -> bool; auto enabled(bool recursive = false) const -> bool;
virtual auto focused() const -> bool; virtual auto focused() const -> bool;
auto font(bool recursive = false) const -> string; auto font(bool recursive = false) const -> string;
virtual auto group() const -> sGroup; virtual auto group() const -> sGroup;
auto offset() const -> signed; auto offset() const -> signed;
auto offset(signed displacement) -> type&;
auto parent() const -> mObject*; auto parent() const -> mObject*;
auto parentComboButton(bool recursive = false) const -> mComboButton*; auto parentComboButton(bool recursive = false) const -> mComboButton*;
auto parentFrame(bool recursive = false) const -> mFrame*; auto parentFrame(bool recursive = false) const -> mFrame*;
@ -481,8 +479,8 @@ struct mHotkey : mObject {
auto doPress() const -> void; auto doPress() const -> void;
auto doRelease() const -> void; auto doRelease() const -> void;
auto onPress(const function<void ()>& function = {}) -> type&; auto onPress(const function<void ()>& callback = {}) -> type&;
auto onRelease(const function<void ()>& function = {}) -> type&; auto onRelease(const function<void ()>& callback = {}) -> type&;
auto parent() const -> wObject; auto parent() const -> wObject;
auto remove() -> type& override; auto remove() -> type& override;
auto sequence() const -> string; auto sequence() const -> string;
@ -507,7 +505,7 @@ struct mTimer : mObject {
auto doActivate() const -> void; auto doActivate() const -> void;
auto interval() const -> unsigned; auto interval() const -> unsigned;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto setInterval(unsigned interval = 0) -> type&; auto setInterval(unsigned interval = 0) -> type&;
//private: //private:
@ -540,20 +538,19 @@ struct mWindow : mObject {
auto layout() const -> sLayout; auto layout() const -> sLayout;
auto menuBar() const -> sMenuBar; auto menuBar() const -> sMenuBar;
auto modal() const -> bool; auto modal() const -> bool;
auto onClose(const function<void ()>& function = {}) -> type&; auto onClose(const function<void ()>& callback = {}) -> type&;
auto onDrop(const function<void (lstring)>& function = {}) -> type&; auto onDrop(const function<void (lstring)>& callback = {}) -> type&;
auto onKeyPress(const function<void (signed)>& function = {}) -> type&; auto onKeyPress(const function<void (signed)>& callback = {}) -> type&;
auto onKeyRelease(const function<void (signed)>& function = {}) -> type&; auto onKeyRelease(const function<void (signed)>& callback = {}) -> type&;
auto onMove(const function<void ()>& function = {}) -> type&; auto onMove(const function<void ()>& callback = {}) -> type&;
auto onSize(const function<void ()>& function = {}) -> type&; auto onSize(const function<void ()>& callback = {}) -> type&;
auto remove(sLayout layout) -> type&; auto remove(sLayout layout) -> type&;
auto remove(sMenuBar menuBar) -> type&; auto remove(sMenuBar menuBar) -> type&;
auto remove(sStatusBar statusBar) -> type&; auto remove(sStatusBar statusBar) -> type&;
auto reset() -> type& override; auto reset() -> type& override;
auto resizable() const -> bool; auto resizable() const -> bool;
auto setBackgroundColor(Color color = {}) -> type&; 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 setDroppable(bool droppable = true) -> type&;
auto setFrameGeometry(Geometry geometry) -> type&; auto setFrameGeometry(Geometry geometry) -> type&;
auto setFramePosition(Position position) -> type&; auto setFramePosition(Position position) -> type&;
@ -706,7 +703,7 @@ struct mMenuItem : mAction {
auto doActivate() const -> void; auto doActivate() const -> void;
auto icon() const -> image; auto icon() const -> image;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto setIcon(const image& icon = {}) -> type&; auto setIcon(const image& icon = {}) -> type&;
auto setText(const string& text = "") -> type&; auto setText(const string& text = "") -> type&;
auto text() const -> string; auto text() const -> string;
@ -726,7 +723,7 @@ struct mMenuCheckItem : mAction {
auto checked() const -> bool; auto checked() const -> bool;
auto doToggle() const -> void; auto doToggle() const -> void;
auto onToggle(const function<void ()>& function = {}) -> type&; auto onToggle(const function<void ()>& callback = {}) -> type&;
auto setChecked(bool checked = true) -> type&; auto setChecked(bool checked = true) -> type&;
auto setText(const string& text = "") -> type&; auto setText(const string& text = "") -> type&;
auto text() const -> string; auto text() const -> string;
@ -747,7 +744,7 @@ struct mMenuRadioItem : mAction {
auto checked() const -> bool; auto checked() const -> bool;
auto doActivate() const -> void; auto doActivate() const -> void;
auto group() const -> sGroup override; auto group() const -> sGroup override;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto setChecked() -> type&; auto setChecked() -> type&;
auto setGroup(sGroup group = {}) -> type& override; auto setGroup(sGroup group = {}) -> type& override;
auto setText(const string& text = "") -> type&; auto setText(const string& text = "") -> type&;
@ -804,7 +801,7 @@ struct mWidget : mSizable {
Declare(Widget) Declare(Widget)
auto doSize() const -> void; auto doSize() const -> void;
auto onSize(const function<void ()>& function = {}) -> type&; auto onSize(const function<void ()>& callback = {}) -> type&;
auto remove() -> type& override; auto remove() -> type& override;
//private: //private:
@ -821,7 +818,7 @@ struct mButton : mWidget {
auto bordered() const -> bool; auto bordered() const -> bool;
auto doActivate() const -> void; auto doActivate() const -> void;
auto icon() const -> image; auto icon() const -> image;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto orientation() const -> Orientation; auto orientation() const -> Orientation;
auto setBordered(bool bordered = true) -> type&; auto setBordered(bool bordered = true) -> type&;
auto setIcon(const image& icon = {}) -> type&; auto setIcon(const image& icon = {}) -> type&;
@ -854,11 +851,11 @@ struct mCanvas : mWidget {
auto doMouseRelease(Mouse::Button button) const -> void; auto doMouseRelease(Mouse::Button button) const -> void;
auto gradient() const -> vector<Color>; auto gradient() const -> vector<Color>;
auto icon() const -> image; auto icon() const -> image;
auto onDrop(const function<void (lstring)>& function = {}) -> type&; auto onDrop(const function<void (lstring)>& callback = {}) -> type&;
auto onMouseLeave(const function<void ()>& function = {}) -> type&; auto onMouseLeave(const function<void ()>& callback = {}) -> type&;
auto onMouseMove(const function<void (Position)>& function = {}) -> type&; auto onMouseMove(const function<void (Position)>& callback = {}) -> type&;
auto onMousePress(const function<void (Mouse::Button)>& function = {}) -> type&; auto onMousePress(const function<void (Mouse::Button)>& callback = {}) -> type&;
auto onMouseRelease(const function<void (Mouse::Button)>& function = {}) -> type&; auto onMouseRelease(const function<void (Mouse::Button)>& callback = {}) -> type&;
auto setColor(Color color) -> type&; auto setColor(Color color) -> type&;
auto setData(Size size) -> type&; auto setData(Size size) -> type&;
auto setDroppable(bool droppable = true) -> type&; auto setDroppable(bool droppable = true) -> type&;
@ -894,7 +891,7 @@ struct mCheckButton : mWidget {
auto checked() const -> bool; auto checked() const -> bool;
auto doToggle() const -> void; auto doToggle() const -> void;
auto icon() const -> image; auto icon() const -> image;
auto onToggle(const function<void ()>& function = {}) -> type&; auto onToggle(const function<void ()>& callback = {}) -> type&;
auto orientation() const -> Orientation; auto orientation() const -> Orientation;
auto setBordered(bool bordered = true) -> type&; auto setBordered(bool bordered = true) -> type&;
auto setChecked(bool checked = true) -> type&; auto setChecked(bool checked = true) -> type&;
@ -921,7 +918,7 @@ struct mCheckLabel : mWidget {
auto checked() const -> bool; auto checked() const -> bool;
auto doToggle() const -> void; auto doToggle() const -> void;
auto onToggle(const function<void ()>& function = {}) -> type&; auto onToggle(const function<void ()>& callback = {}) -> type&;
auto setChecked(bool checked = true) -> type&; auto setChecked(bool checked = true) -> type&;
auto setText(const string& text = "") -> type&; auto setText(const string& text = "") -> type&;
auto text() const -> string; auto text() const -> string;
@ -944,7 +941,7 @@ struct mComboButton : mWidget {
auto doChange() const -> void; auto doChange() const -> void;
auto item(unsigned position) const -> sComboButtonItem; auto item(unsigned position) const -> sComboButtonItem;
auto items() const -> unsigned; auto items() const -> unsigned;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto remove(sComboButtonItem item) -> type&; auto remove(sComboButtonItem item) -> type&;
auto reset() -> type&; auto reset() -> type&;
auto selected() const -> sComboButtonItem; auto selected() const -> sComboButtonItem;
@ -988,7 +985,7 @@ struct mConsole : mWidget {
auto backgroundColor() const -> Color; auto backgroundColor() const -> Color;
auto doActivate(string) const -> void; auto doActivate(string) const -> void;
auto foregroundColor() const -> Color; auto foregroundColor() const -> Color;
auto onActivate(const function<void (string)>& function = {}) -> type&; auto onActivate(const function<void (string)>& callback = {}) -> type&;
auto print(const string& text) -> type&; auto print(const string& text) -> type&;
auto prompt() const -> string; auto prompt() const -> string;
auto reset() -> type&; auto reset() -> type&;
@ -1040,8 +1037,8 @@ struct mHexEdit : mWidget {
auto foregroundColor() const -> Color; auto foregroundColor() const -> Color;
auto length() const -> unsigned; auto length() const -> unsigned;
auto offset() const -> unsigned; auto offset() const -> unsigned;
auto onRead(const function<uint8_t (unsigned)>& function = {}) -> type&; auto onRead(const function<uint8_t (unsigned)>& callback = {}) -> type&;
auto onWrite(const function<void (unsigned, uint8_t)>& function = {}) -> type&; auto onWrite(const function<void (unsigned, uint8_t)>& callback = {}) -> type&;
auto rows() const -> unsigned; auto rows() const -> unsigned;
auto setBackgroundColor(Color color = {}) -> type&; auto setBackgroundColor(Color color = {}) -> type&;
auto setColumns(unsigned columns = 16) -> type&; auto setColumns(unsigned columns = 16) -> type&;
@ -1071,7 +1068,7 @@ struct mHorizontalScroller : mWidget {
auto doChange() const -> void; auto doChange() const -> void;
auto length() const -> unsigned; auto length() const -> unsigned;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto position() const -> unsigned; auto position() const -> unsigned;
auto setLength(unsigned length = 101) -> type&; auto setLength(unsigned length = 101) -> type&;
auto setPosition(unsigned position = 0) -> type&; auto setPosition(unsigned position = 0) -> type&;
@ -1091,7 +1088,7 @@ struct mHorizontalSlider : mWidget {
auto doChange() const -> void; auto doChange() const -> void;
auto length() const -> unsigned; auto length() const -> unsigned;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto position() const -> unsigned; auto position() const -> unsigned;
auto setLength(unsigned length = 101) -> type&; auto setLength(unsigned length = 101) -> type&;
auto setPosition(unsigned position = 0) -> type&; auto setPosition(unsigned position = 0) -> type&;
@ -1120,9 +1117,9 @@ struct mIconView : mWidget {
auto item(unsigned position) const -> sIconViewItem; auto item(unsigned position) const -> sIconViewItem;
auto items() const -> unsigned; auto items() const -> unsigned;
auto multiSelect() const -> bool; auto multiSelect() const -> bool;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto onContext(const function<void ()>& function = {}) -> type&; auto onContext(const function<void ()>& callback = {}) -> type&;
auto orientation() const -> Orientation; auto orientation() const -> Orientation;
auto remove(sIconViewItem item) -> type&; auto remove(sIconViewItem item) -> type&;
auto reset() -> type&; auto reset() -> type&;
@ -1203,8 +1200,8 @@ struct mLineEdit : mWidget {
auto doChange() const -> void; auto doChange() const -> void;
auto editable() const -> bool; auto editable() const -> bool;
auto foregroundColor() const -> Color; auto foregroundColor() const -> Color;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&; auto setBackgroundColor(Color color = {}) -> type&;
auto setEditable(bool editable = true) -> type&; auto setEditable(bool editable = true) -> type&;
auto setForegroundColor(Color color = {}) -> type&; auto setForegroundColor(Color color = {}) -> type&;
@ -1248,12 +1245,12 @@ struct mListView : mWidget {
auto headerVisible() const -> bool; auto headerVisible() const -> bool;
auto item(unsigned position) const -> sListViewItem; auto item(unsigned position) const -> sListViewItem;
auto items() const -> unsigned; auto items() const -> unsigned;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto onContext(const function<void ()>& function = {}) -> type&; auto onContext(const function<void ()>& callback = {}) -> type&;
auto onEdit(const function<void (sListViewCell)>& function = {}) -> type&; auto onEdit(const function<void (sListViewCell)>& callback = {}) -> type&;
auto onSort(const function<void (sListViewColumn)>& function = {}) -> type&; auto onSort(const function<void (sListViewColumn)>& callback = {}) -> type&;
auto onToggle(const function<void (sListViewItem)>& function = {}) -> type&; auto onToggle(const function<void (sListViewItem)>& callback = {}) -> type&;
auto remove(sListViewColumn column) -> type&; auto remove(sListViewColumn column) -> type&;
auto remove(sListViewItem item) -> type&; auto remove(sListViewItem item) -> type&;
auto reset() -> type&; auto reset() -> type&;
@ -1422,7 +1419,7 @@ struct mRadioButton : mWidget {
auto doActivate() const -> void; auto doActivate() const -> void;
auto group() const -> sGroup override; auto group() const -> sGroup override;
auto icon() const -> image; auto icon() const -> image;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto orientation() const -> Orientation; auto orientation() const -> Orientation;
auto setBordered(bool bordered = true) -> type&; auto setBordered(bool bordered = true) -> type&;
auto setChecked() -> type&; auto setChecked() -> type&;
@ -1452,7 +1449,7 @@ struct mRadioLabel : mWidget {
auto checked() const -> bool; auto checked() const -> bool;
auto doActivate() const -> void; auto doActivate() const -> void;
auto group() const -> sGroup override; auto group() const -> sGroup override;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto setChecked() -> type&; auto setChecked() -> type&;
auto setGroup(sGroup group = {}) -> type& override; auto setGroup(sGroup group = {}) -> type& override;
auto setText(const string& text = "") -> type&; auto setText(const string& text = "") -> type&;
@ -1474,8 +1471,8 @@ struct mSourceEdit : mWidget {
auto doChange() const -> void; auto doChange() const -> void;
auto doMove() const -> void; auto doMove() const -> void;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto onMove(const function<void ()>& function = {}) -> type&; auto onMove(const function<void ()>& callback = {}) -> type&;
auto position() const -> unsigned; auto position() const -> unsigned;
auto setPosition(signed position) -> type&; auto setPosition(signed position) -> type&;
auto setSelected(Position selected) -> type&; auto setSelected(Position selected) -> type&;
@ -1506,9 +1503,9 @@ struct mTabFrame : mWidget {
auto edge() const -> Edge; auto edge() const -> Edge;
auto item(unsigned position) const -> sTabFrameItem; auto item(unsigned position) const -> sTabFrameItem;
auto items() const -> unsigned; auto items() const -> unsigned;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto onClose(const function<void (sTabFrameItem)>& function = {}) -> type&; auto onClose(const function<void (sTabFrameItem)>& callback = {}) -> type&;
auto onMove(const function<void (sTabFrameItem, sTabFrameItem)>& function = {}) -> type&; auto onMove(const function<void (sTabFrameItem, sTabFrameItem)>& callback = {}) -> type&;
auto remove(sTabFrameItem item) -> type&; auto remove(sTabFrameItem item) -> type&;
auto reset() -> type&; auto reset() -> type&;
auto selected() const -> sTabFrameItem; auto selected() const -> sTabFrameItem;
@ -1573,8 +1570,8 @@ struct mTextEdit : mWidget {
auto doMove() const -> void; auto doMove() const -> void;
auto editable() const -> bool; auto editable() const -> bool;
auto foregroundColor() const -> Color; auto foregroundColor() const -> Color;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto onMove(const function<void ()>& function = {}) -> type&; auto onMove(const function<void ()>& callback = {}) -> type&;
auto setBackgroundColor(Color color = {}) -> type&; auto setBackgroundColor(Color color = {}) -> type&;
auto setCursorPosition(unsigned position) -> type&; auto setCursorPosition(unsigned position) -> type&;
auto setEditable(bool editable = true) -> type&; auto setEditable(bool editable = true) -> type&;
@ -1615,10 +1612,10 @@ struct mTreeView : mWidget {
auto foregroundColor() const -> Color; auto foregroundColor() const -> Color;
auto item(const string& path) const -> sTreeViewItem; auto item(const string& path) const -> sTreeViewItem;
auto items() const -> unsigned; auto items() const -> unsigned;
auto onActivate(const function<void ()>& function = {}) -> type&; auto onActivate(const function<void ()>& callback = {}) -> type&;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto onContext(const function<void ()>& function = {}) -> type&; auto onContext(const function<void ()>& callback = {}) -> type&;
auto onToggle(const function<void (sTreeViewItem)>& function = {}) -> type&; auto onToggle(const function<void (sTreeViewItem)>& callback = {}) -> type&;
auto remove(sTreeViewItem item) -> type&; auto remove(sTreeViewItem item) -> type&;
auto reset() -> type&; auto reset() -> type&;
auto selected() const -> sTreeViewItem; auto selected() const -> sTreeViewItem;
@ -1683,7 +1680,7 @@ struct mVerticalScroller : mWidget {
auto doChange() const -> void; auto doChange() const -> void;
auto length() const -> unsigned; auto length() const -> unsigned;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto position() const -> unsigned; auto position() const -> unsigned;
auto setLength(unsigned length = 101) -> type&; auto setLength(unsigned length = 101) -> type&;
auto setPosition(unsigned position = 0) -> type&; auto setPosition(unsigned position = 0) -> type&;
@ -1703,7 +1700,7 @@ struct mVerticalSlider : mWidget {
auto doChange() const -> void; auto doChange() const -> void;
auto length() const -> unsigned; auto length() const -> unsigned;
auto onChange(const function<void ()>& function = {}) -> type&; auto onChange(const function<void ()>& callback = {}) -> type&;
auto position() const -> unsigned; auto position() const -> unsigned;
auto setLength(unsigned length = 101) -> type&; auto setLength(unsigned length = 101) -> type&;
auto setPosition(unsigned position = 0) -> type&; auto setPosition(unsigned position = 0) -> type&;
@ -1728,11 +1725,11 @@ struct mViewport : mWidget {
auto doMouseRelease(Mouse::Button button) const -> void; auto doMouseRelease(Mouse::Button button) const -> void;
auto droppable() const -> bool; auto droppable() const -> bool;
auto handle() const -> uintptr_t; auto handle() const -> uintptr_t;
auto onDrop(const function<void (lstring)>& function = {}) -> type&; auto onDrop(const function<void (lstring)>& callback = {}) -> type&;
auto onMouseLeave(const function<void ()>& function = {}) -> type&; auto onMouseLeave(const function<void ()>& callback = {}) -> type&;
auto onMouseMove(const function<void (Position position)>& function = {}) -> type&; auto onMouseMove(const function<void (Position position)>& callback = {}) -> type&;
auto onMousePress(const function<void (Mouse::Button)>& function = {}) -> type&; auto onMousePress(const function<void (Mouse::Button)>& callback = {}) -> type&;
auto onMouseRelease(const function<void (Mouse::Button)>& function = {}) -> type&; auto onMouseRelease(const function<void (Mouse::Button)>& callback = {}) -> type&;
auto setDroppable(bool droppable = true) -> type&; auto setDroppable(bool droppable = true) -> type&;
//private: //private:

View File

@ -14,13 +14,13 @@ auto mHotkey::doRelease() const -> void {
if(state.onRelease) return state.onRelease(); if(state.onRelease) return state.onRelease();
} }
auto mHotkey::onPress(const function<void ()>& function) -> type& { auto mHotkey::onPress(const function<void ()>& callback) -> type& {
state.onPress = function; state.onPress = callback;
return *this; return *this;
} }
auto mHotkey::onRelease(const function<void ()>& function) -> type& { auto mHotkey::onRelease(const function<void ()>& callback) -> type& {
state.onRelease = function; state.onRelease = callback;
return *this; return *this;
} }

View File

@ -34,7 +34,7 @@ auto mLayout::remove(shared_pointer<mSizable> sizable) -> type& {
sizable->setParent(); sizable->setParent();
state.sizables.remove(offset); state.sizables.remove(offset);
for(auto n : range(offset, sizables())) { for(auto n : range(offset, sizables())) {
state.sizables[n]->offset(-1); state.sizables[n]->adjustOffset(-1);
} }
setGeometry(geometry()); setGeometry(geometry());
return *this; return *this;

View File

@ -37,7 +37,7 @@ auto mMenuBar::remove(shared_pointer<mMenu> menu) -> type& {
signal(remove, *menu); signal(remove, *menu);
state.menus.remove(offset); state.menus.remove(offset);
for(auto n : range(offset, menus())) { for(auto n : range(offset, menus())) {
state.menus[n]->offset(-1); state.menus[n]->adjustOffset(-1);
} }
menu->setParent(); menu->setParent();
return *this; return *this;

View File

@ -47,6 +47,11 @@ auto mObject::abstract() const -> bool {
return true; return true;
} }
auto mObject::adjustOffset(signed displacement) -> type& {
state.offset += displacement;
return *this;
}
auto mObject::enabled(bool recursive) const -> bool { auto mObject::enabled(bool recursive) const -> bool {
if(!recursive || !state.enabled) return state.enabled; if(!recursive || !state.enabled) return state.enabled;
if(auto object = parent()) return object->enabled(true); if(auto object = parent()) return object->enabled(true);
@ -72,11 +77,6 @@ auto mObject::offset() const -> signed {
return state.offset; return state.offset;
} }
auto mObject::offset(signed displacement) -> type& {
state.offset += displacement;
return *this;
}
auto mObject::parent() const -> mObject* { auto mObject::parent() const -> mObject* {
return state.parent; return state.parent;
} }

View File

@ -32,7 +32,7 @@ auto mPopupMenu::remove(sAction action) -> type& {
signal(remove, action); signal(remove, action);
state.actions.remove(offset); state.actions.remove(offset);
for(auto n : range(offset, actions())) { for(auto n : range(offset, actions())) {
state.actions[n]->offset(-1); state.actions[n]->adjustOffset(-1);
} }
action->setParent(); action->setParent();
return *this; return *this;

View File

@ -14,8 +14,8 @@ auto mTimer::interval() const -> unsigned {
return state.interval; return state.interval;
} }
auto mTimer::onActivate(const function<void ()>& function) -> type& { auto mTimer::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }

View File

@ -18,8 +18,8 @@ auto mButton::icon() const -> image {
return state.icon; return state.icon;
} }
auto mButton::onActivate(const function<void ()>& function) -> type& { auto mButton::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }

View File

@ -46,28 +46,28 @@ auto mCanvas::icon() const -> image {
return state.icon; return state.icon;
} }
auto mCanvas::onDrop(const function<void (lstring)>& function) -> type& { auto mCanvas::onDrop(const function<void (lstring)>& callback) -> type& {
state.onDrop = function; state.onDrop = callback;
return *this; return *this;
} }
auto mCanvas::onMouseLeave(const function<void ()>& function) -> type& { auto mCanvas::onMouseLeave(const function<void ()>& callback) -> type& {
state.onMouseLeave = function; state.onMouseLeave = callback;
return *this; return *this;
} }
auto mCanvas::onMouseMove(const function<void (Position)>& function) -> type& { auto mCanvas::onMouseMove(const function<void (Position)>& callback) -> type& {
state.onMouseMove = function; state.onMouseMove = callback;
return *this; return *this;
} }
auto mCanvas::onMousePress(const function<void (Mouse::Button)>& function) -> type& { auto mCanvas::onMousePress(const function<void (Mouse::Button)>& callback) -> type& {
state.onMousePress = function; state.onMousePress = callback;
return *this; return *this;
} }
auto mCanvas::onMouseRelease(const function<void (Mouse::Button)>& function) -> type& { auto mCanvas::onMouseRelease(const function<void (Mouse::Button)>& callback) -> type& {
state.onMouseRelease = function; state.onMouseRelease = callback;
return *this; return *this;
} }

View File

@ -22,8 +22,8 @@ auto mCheckButton::icon() const -> image {
return state.icon; return state.icon;
} }
auto mCheckButton::onToggle(const function<void ()>& function) -> type& { auto mCheckButton::onToggle(const function<void ()>& callback) -> type& {
state.onToggle = function; state.onToggle = callback;
return *this; return *this;
} }

View File

@ -14,8 +14,8 @@ auto mCheckLabel::doToggle() const -> void {
if(state.onToggle) return state.onToggle(); if(state.onToggle) return state.onToggle();
} }
auto mCheckLabel::onToggle(const function<void ()>& function) -> type& { auto mCheckLabel::onToggle(const function<void ()>& callback) -> type& {
state.onToggle = function; state.onToggle = callback;
return *this; return *this;
} }

View File

@ -31,8 +31,8 @@ auto mComboButton::items() const -> unsigned {
return state.items.size(); return state.items.size();
} }
auto mComboButton::onChange(const function<void ()>& function) -> type& { auto mComboButton::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }
@ -40,7 +40,7 @@ auto mComboButton::remove(sComboButtonItem item) -> type& {
signal(remove, item); signal(remove, item);
state.items.remove(item->offset()); state.items.remove(item->offset());
for(auto n : range(item->offset(), items())) { for(auto n : range(item->offset(), items())) {
state.items[n]->offset(-1); state.items[n]->adjustOffset(-1);
} }
item->setParent(); item->setParent();
return *this; return *this;

View File

@ -18,8 +18,8 @@ auto mConsole::foregroundColor() const -> Color {
return state.foregroundColor; return state.foregroundColor;
} }
auto mConsole::onActivate(const function<void (string)>& function) -> type& { auto mConsole::onActivate(const function<void (string)>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }

View File

@ -35,13 +35,13 @@ auto mHexEdit::offset() const -> unsigned {
return state.offset; return state.offset;
} }
auto mHexEdit::onRead(const function<uint8_t (unsigned)>& function) -> type& { auto mHexEdit::onRead(const function<uint8_t (unsigned)>& callback) -> type& {
state.onRead = function; state.onRead = callback;
return *this; return *this;
} }
auto mHexEdit::onWrite(const function<void (unsigned, uint8_t)>& function) -> type& { auto mHexEdit::onWrite(const function<void (unsigned, uint8_t)>& callback) -> type& {
state.onWrite = function; state.onWrite = callback;
return *this; return *this;
} }

View File

@ -14,8 +14,8 @@ auto mHorizontalScroller::length() const -> unsigned {
return state.length; return state.length;
} }
auto mHorizontalScroller::onChange(const function<void ()>& function) -> type& { auto mHorizontalScroller::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }

View File

@ -14,8 +14,8 @@ auto mHorizontalSlider::length() const -> unsigned {
return state.length; return state.length;
} }
auto mHorizontalSlider::onChange(const function<void ()>& function) -> type& { auto mHorizontalSlider::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }

View File

@ -55,18 +55,18 @@ auto mIconView::multiSelect() const -> bool {
return state.multiSelect; return state.multiSelect;
} }
auto mIconView::onActivate(const function<void ()>& function) -> type& { auto mIconView::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }
auto mIconView::onChange(const function<void ()>& function) -> type& { auto mIconView::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }
auto mIconView::onContext(const function<void ()>& function) -> type& { auto mIconView::onContext(const function<void ()>& callback) -> type& {
state.onContext = function; state.onContext = callback;
return *this; return *this;
} }
@ -78,7 +78,7 @@ auto mIconView::remove(shared_pointer<mIconViewItem> item) -> type& {
signal(remove, item); signal(remove, item);
state.items.remove(item->offset()); state.items.remove(item->offset());
for(auto n : range(item->offset(), items())) { for(auto n : range(item->offset(), items())) {
state.items[n]->offset(-1); state.items[n]->adjustOffset(-1);
} }
item->setParent(); item->setParent();
return *this; return *this;

View File

@ -26,13 +26,13 @@ auto mLineEdit::foregroundColor() const -> Color {
return state.foregroundColor; return state.foregroundColor;
} }
auto mLineEdit::onActivate(const function<void ()>& function) -> type& { auto mLineEdit::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }
auto mLineEdit::onChange(const function<void ()>& function) -> type& { auto mLineEdit::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }

View File

@ -43,7 +43,7 @@ auto mListViewItem::remove(sListViewCell cell) -> type& {
signal(remove, cell); signal(remove, cell);
state.cells.remove(cell->offset()); state.cells.remove(cell->offset());
for(auto n : range(cell->offset(), cells())) { for(auto n : range(cell->offset(), cells())) {
state.cells[n]->offset(-1); state.cells[n]->adjustOffset(-1);
} }
cell->setParent(); cell->setParent();
return *this; return *this;

View File

@ -106,33 +106,33 @@ auto mListView::items() const -> unsigned {
return state.items.size(); return state.items.size();
} }
auto mListView::onActivate(const function<void ()>& function) -> type& { auto mListView::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }
auto mListView::onChange(const function<void ()>& function) -> type& { auto mListView::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }
auto mListView::onContext(const function<void ()>& function) -> type& { auto mListView::onContext(const function<void ()>& callback) -> type& {
state.onContext = function; state.onContext = callback;
return *this; return *this;
} }
auto mListView::onEdit(const function<void (sListViewCell)>& function) -> type& { auto mListView::onEdit(const function<void (sListViewCell)>& callback) -> type& {
state.onEdit = function; state.onEdit = callback;
return *this; return *this;
} }
auto mListView::onSort(const function<void (sListViewColumn)>& function) -> type& { auto mListView::onSort(const function<void (sListViewColumn)>& callback) -> type& {
state.onSort = function; state.onSort = callback;
return *this; return *this;
} }
auto mListView::onToggle(const function<void (sListViewItem)>& function) -> type& { auto mListView::onToggle(const function<void (sListViewItem)>& callback) -> type& {
state.onToggle = function; state.onToggle = callback;
return *this; return *this;
} }
@ -142,7 +142,7 @@ auto mListView::remove(sListViewColumn column) -> type& {
state.items.reset(); state.items.reset();
state.columns.remove(column->offset()); state.columns.remove(column->offset());
for(auto n : range(column->offset(), columns())) { for(auto n : range(column->offset(), columns())) {
state.columns[n]->offset(-1); state.columns[n]->adjustOffset(-1);
} }
column->setParent(); column->setParent();
return *this; return *this;
@ -152,7 +152,7 @@ auto mListView::remove(sListViewItem item) -> type& {
signal(remove, item); signal(remove, item);
state.items.remove(item->offset()); state.items.remove(item->offset());
for(auto n : range(item->offset(), items())) { for(auto n : range(item->offset(), items())) {
state.items[n]->offset(-1); state.items[n]->adjustOffset(-1);
} }
item->setParent(); item->setParent();
return *this; return *this;

View File

@ -26,8 +26,8 @@ auto mRadioButton::icon() const -> image {
return state.icon; return state.icon;
} }
auto mRadioButton::onActivate(const function<void ()>& function) -> type& { auto mRadioButton::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }

View File

@ -18,8 +18,8 @@ auto mRadioLabel::group() const -> sGroup {
return state.group; return state.group;
} }
auto mRadioLabel::onActivate(const function<void ()>& function) -> type& { auto mRadioLabel::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }

View File

@ -14,13 +14,13 @@ auto mSourceEdit::doMove() const -> void {
if(state.onMove) return state.onMove(); if(state.onMove) return state.onMove();
} }
auto mSourceEdit::onChange(const function<void ()>& function) -> type& { auto mSourceEdit::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }
auto mSourceEdit::onMove(const function<void ()>& function) -> type& { auto mSourceEdit::onMove(const function<void ()>& callback) -> type& {
state.onMove = function; state.onMove = callback;
return *this; return *this;
} }

View File

@ -43,18 +43,18 @@ auto mTabFrame::items() const -> unsigned {
return state.items.size(); return state.items.size();
} }
auto mTabFrame::onChange(const function<void ()>& function) -> type& { auto mTabFrame::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }
auto mTabFrame::onClose(const function<void (sTabFrameItem)>& function) -> type& { auto mTabFrame::onClose(const function<void (sTabFrameItem)>& callback) -> type& {
state.onClose = function; state.onClose = callback;
return *this; return *this;
} }
auto mTabFrame::onMove(const function<void (sTabFrameItem, sTabFrameItem)>& function) -> type& { auto mTabFrame::onMove(const function<void (sTabFrameItem, sTabFrameItem)>& callback) -> type& {
state.onMove = function; state.onMove = callback;
return *this; return *this;
} }
@ -64,7 +64,7 @@ auto mTabFrame::remove(sTabFrameItem item) -> type& {
signal(remove, item); signal(remove, item);
state.items.remove(item->offset()); state.items.remove(item->offset());
for(auto n : range(offset, items())) { for(auto n : range(offset, items())) {
state.items[n]->offset(-1); state.items[n]->adjustOffset(-1);
} }
return *this; return *this;
} }

View File

@ -30,13 +30,13 @@ auto mTextEdit::foregroundColor() const -> Color {
return state.foregroundColor; return state.foregroundColor;
} }
auto mTextEdit::onChange(const function<void ()>& function) -> type& { auto mTextEdit::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }
auto mTextEdit::onMove(const function<void ()>& function) -> type& { auto mTextEdit::onMove(const function<void ()>& callback) -> type& {
state.onMove = function; state.onMove = callback;
return *this; return *this;
} }

View File

@ -54,7 +54,7 @@ auto mTreeViewItem::remove(sTreeViewItem item) -> type& {
signal(remove, item); signal(remove, item);
state.items.remove(item->offset()); state.items.remove(item->offset());
for(auto n : range(item->offset(), items())) { for(auto n : range(item->offset(), items())) {
state.items[n]->offset(-1); state.items[n]->adjustOffset(-1);
} }
item->setParent(); item->setParent();
return *this; return *this;

View File

@ -69,23 +69,23 @@ auto mTreeView::items() const -> unsigned {
return state.items.size(); return state.items.size();
} }
auto mTreeView::onActivate(const function<void ()>& function) -> type& { auto mTreeView::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = function; state.onActivate = callback;
return *this; return *this;
} }
auto mTreeView::onChange(const function<void ()>& function) -> type& { auto mTreeView::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }
auto mTreeView::onContext(const function<void ()>& function) -> type& { auto mTreeView::onContext(const function<void ()>& callback) -> type& {
state.onContext = function; state.onContext = callback;
return *this; return *this;
} }
auto mTreeView::onToggle(const function<void (sTreeViewItem)>& function) -> type& { auto mTreeView::onToggle(const function<void (sTreeViewItem)>& callback) -> type& {
state.onToggle = function; state.onToggle = callback;
return *this; return *this;
} }
@ -93,7 +93,7 @@ auto mTreeView::remove(sTreeViewItem item) -> type& {
signal(remove, item); signal(remove, item);
state.items.remove(item->offset()); state.items.remove(item->offset());
for(auto n : range(item->offset(), items())) { for(auto n : range(item->offset(), items())) {
state.items[n]->offset(-1); state.items[n]->adjustOffset(-1);
} }
item->setParent(); item->setParent();
return *this; return *this;

View File

@ -14,8 +14,8 @@ auto mVerticalScroller::length() const -> unsigned {
return state.length; return state.length;
} }
auto mVerticalScroller::onChange(const function<void ()>& function) -> type& { auto mVerticalScroller::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }

View File

@ -14,8 +14,8 @@ auto mVerticalSlider::length() const -> unsigned {
return state.length; return state.length;
} }
auto mVerticalSlider::onChange(const function<void ()>& function) -> type& { auto mVerticalSlider::onChange(const function<void ()>& callback) -> type& {
state.onChange = function; state.onChange = callback;
return *this; return *this;
} }

View File

@ -34,28 +34,28 @@ auto mViewport::handle() const -> uintptr_t {
return signal(handle); return signal(handle);
} }
auto mViewport::onDrop(const function<void (lstring)>& function) -> type& { auto mViewport::onDrop(const function<void (lstring)>& callback) -> type& {
state.onDrop = function; state.onDrop = callback;
return *this; return *this;
} }
auto mViewport::onMouseLeave(const function<void ()>& function) -> type& { auto mViewport::onMouseLeave(const function<void ()>& callback) -> type& {
state.onMouseLeave = function; state.onMouseLeave = callback;
return *this; return *this;
} }
auto mViewport::onMouseMove(const function<void (Position)>& function) -> type& { auto mViewport::onMouseMove(const function<void (Position)>& callback) -> type& {
state.onMouseMove = function; state.onMouseMove = callback;
return *this; return *this;
} }
auto mViewport::onMousePress(const function<void (Mouse::Button)>& function) -> type& { auto mViewport::onMousePress(const function<void (Mouse::Button)>& callback) -> type& {
state.onMousePress = function; state.onMousePress = callback;
return *this; return *this;
} }
auto mViewport::onMouseRelease(const function<void (Mouse::Button)>& function) -> type& { auto mViewport::onMouseRelease(const function<void (Mouse::Button)>& callback) -> type& {
state.onMouseRelease = function; state.onMouseRelease = callback;
return *this; return *this;
} }

View File

@ -10,8 +10,8 @@ auto mWidget::doSize() const -> void {
if(state.onSize) return state.onSize(); if(state.onSize) return state.onSize();
} }
auto mWidget::onSize(const function<void ()>& function) -> type& { auto mWidget::onSize(const function<void ()>& callback) -> type& {
state.onSize = function; state.onSize = callback;
return *this; return *this;
} }

View File

@ -13,7 +13,7 @@ auto mWindow::destruct() -> void {
// //
auto mWindow::append(shared_pointer<mLayout> layout) -> type& { auto mWindow::append(sLayout layout) -> type& {
if(auto& layout = state.layout) remove(layout); if(auto& layout = state.layout) remove(layout);
state.layout = layout; state.layout = layout;
layout->setGeometry(geometry().setPosition(0, 0)); layout->setGeometry(geometry().setPosition(0, 0));
@ -23,7 +23,7 @@ auto mWindow::append(shared_pointer<mLayout> layout) -> type& {
return *this; return *this;
} }
auto mWindow::append(shared_pointer<mMenuBar> menuBar) -> type& { auto mWindow::append(sMenuBar menuBar) -> type& {
if(auto& menuBar = state.menuBar) remove(menuBar); if(auto& menuBar = state.menuBar) remove(menuBar);
menuBar->setParent(this, 0); menuBar->setParent(this, 0);
state.menuBar = menuBar; state.menuBar = menuBar;
@ -31,7 +31,7 @@ auto mWindow::append(shared_pointer<mMenuBar> menuBar) -> type& {
return *this; return *this;
} }
auto mWindow::append(shared_pointer<mStatusBar> statusBar) -> type& { auto mWindow::append(sStatusBar statusBar) -> type& {
if(auto& statusBar = state.statusBar) remove(statusBar); if(auto& statusBar = state.statusBar) remove(statusBar);
statusBar->setParent(this, 0); statusBar->setParent(this, 0);
state.statusBar = statusBar; state.statusBar = statusBar;
@ -99,44 +99,44 @@ auto mWindow::modal() const -> bool {
return state.modal; return state.modal;
} }
auto mWindow::onClose(const function<void ()>& function) -> type& { auto mWindow::onClose(const function<void ()>& callback) -> type& {
state.onClose = function; state.onClose = callback;
return *this; return *this;
} }
auto mWindow::onDrop(const function<void (lstring)>& function) -> type& { auto mWindow::onDrop(const function<void (lstring)>& callback) -> type& {
state.onDrop = function; state.onDrop = callback;
return *this; return *this;
} }
auto mWindow::onKeyPress(const function<void (signed)>& function) -> type& { auto mWindow::onKeyPress(const function<void (signed)>& callback) -> type& {
state.onKeyPress = function; state.onKeyPress = callback;
return *this; return *this;
} }
auto mWindow::onKeyRelease(const function<void (signed)>& function) -> type& { auto mWindow::onKeyRelease(const function<void (signed)>& callback) -> type& {
state.onKeyRelease = function; state.onKeyRelease = callback;
return *this; return *this;
} }
auto mWindow::onMove(const function<void ()>& function) -> type& { auto mWindow::onMove(const function<void ()>& callback) -> type& {
state.onMove = function; state.onMove = callback;
return *this; return *this;
} }
auto mWindow::onSize(const function<void ()>& function) -> type& { auto mWindow::onSize(const function<void ()>& callback) -> type& {
state.onSize = function; state.onSize = callback;
return *this; return *this;
} }
auto mWindow::remove(shared_pointer<mLayout> layout) -> type& { auto mWindow::remove(sLayout layout) -> type& {
signal(remove, layout); signal(remove, layout);
layout->setParent(); layout->setParent();
state.layout.reset(); state.layout.reset();
return *this; return *this;
} }
auto mWindow::remove(shared_pointer<mMenuBar> menuBar) -> type& { auto mWindow::remove(sMenuBar menuBar) -> type& {
signal(remove, menuBar); signal(remove, menuBar);
menuBar->reset(); menuBar->reset();
menuBar->setParent(); menuBar->setParent();
@ -144,7 +144,7 @@ auto mWindow::remove(shared_pointer<mMenuBar> menuBar) -> type& {
return *this; return *this;
} }
auto mWindow::remove(shared_pointer<mStatusBar> statusBar) -> type& { auto mWindow::remove(sStatusBar statusBar) -> type& {
signal(remove, statusBar); signal(remove, statusBar);
statusBar->setParent(); statusBar->setParent();
state.statusBar.reset(); state.statusBar.reset();
@ -168,19 +168,8 @@ auto mWindow::setBackgroundColor(Color color) -> type& {
return *this; return *this;
} }
auto mWindow::setCentered() -> type& { auto mWindow::setCentered(sWindow parent) -> type& {
Geometry workspace = Desktop::workspace(); Geometry workspace = parent ? parent->frameGeometry() : 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<mWindow> parent) -> type& {
if(!parent) return setCentered();
Geometry workspace = parent->frameGeometry();
Geometry geometry = frameGeometry(); Geometry geometry = frameGeometry();
signed x = workspace.x(); signed x = workspace.x();
signed y = workspace.y(); signed y = workspace.y();

View File

@ -1,6 +1,6 @@
#if defined(Hiro_FixedLayout) #if defined(Hiro_FixedLayout)
auto mFixedLayout::append(shared_pointer<mSizable> sizable, Geometry geometry) -> type& { auto mFixedLayout::append(sSizable sizable, Geometry geometry) -> type& {
properties.append({geometry}); properties.append({geometry});
mLayout::append(sizable); mLayout::append(sizable);
sizable->setGeometry(geometry); sizable->setGeometry(geometry);
@ -16,7 +16,7 @@ auto mFixedLayout::minimumSize() const -> Size {
return {width, height}; return {width, height};
} }
auto mFixedLayout::remove(shared_pointer<mSizable> sizable) -> type& { auto mFixedLayout::remove(sSizable sizable) -> type& {
properties.remove(sizable->offset()); properties.remove(sizable->offset());
mLayout::remove(sizable); mLayout::remove(sizable);
return *this; return *this;

View File

@ -5,18 +5,18 @@ struct mFixedLayout : mLayout {
using mLayout::append; using mLayout::append;
using mLayout::remove; using mLayout::remove;
auto append(nall::shared_pointer<mSizable> sizable, Geometry geometry) -> type&; auto append(sSizable sizable, Geometry geometry) -> type&;
auto minimumSize() const -> Size override; auto minimumSize() const -> Size override;
auto remove(nall::shared_pointer<mSizable> sizable) -> type& override; auto remove(sSizable sizable) -> type& override;
auto reset() -> type& override; auto reset() -> type& override;
auto setEnabled(bool enabled = true) -> 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; auto setVisible(bool visible = true) ->type& override;
struct Properties { struct Properties {
Geometry geometry; Geometry geometry;
}; };
nall::vector<Properties> properties; vector<Properties> properties;
}; };
#endif #endif

View File

@ -1,6 +1,6 @@
#if defined(Hiro_HorizontalLayout) #if defined(Hiro_HorizontalLayout)
auto mHorizontalLayout::append(shared_pointer<mSizable> 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}); properties.append({size.width(), size.height(), spacing < 0 ? settings.spacing : spacing});
mLayout::append(sizable); mLayout::append(sizable);
return *this; return *this;
@ -31,7 +31,7 @@ auto mHorizontalLayout::minimumSize() const -> Size {
return {settings.margin * 2 + width, settings.margin * 2 + height}; return {settings.margin * 2 + width, settings.margin * 2 + height};
} }
auto mHorizontalLayout::remove(shared_pointer<mSizable> sizable) -> type& { auto mHorizontalLayout::remove(sSizable sizable) -> type& {
properties.remove(sizable->offset()); properties.remove(sizable->offset());
mLayout::remove(sizable); mLayout::remove(sizable);
return *this; return *this;

View File

@ -5,13 +5,13 @@ struct mHorizontalLayout : mLayout {
using mLayout::append; using mLayout::append;
using mLayout::remove; using mLayout::remove;
auto append(nall::shared_pointer<mSizable> sizable, Size size, signed spacing = 5) -> type&; auto append(sSizable sizable, Size size, signed spacing = 5) -> type&;
auto minimumSize() const -> Size override; auto minimumSize() const -> Size override;
auto remove(nall::shared_pointer<mSizable> sizable) -> type& override; auto remove(sSizable sizable) -> type& override;
auto reset() -> type& override; auto reset() -> type& override;
auto setAlignment(double alignment = 0.5) -> type&; auto setAlignment(double alignment = 0.5) -> type&;
auto setEnabled(bool enabled = true) -> 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 setGeometry(Geometry geometry) -> type& override; auto setGeometry(Geometry geometry) -> type& override;
auto setMargin(signed margin = 0) -> type&; auto setMargin(signed margin = 0) -> type&;
auto setSpacing(signed spacing = 5) -> type&; auto setSpacing(signed spacing = 5) -> type&;
@ -28,7 +28,7 @@ struct mHorizontalLayout : mLayout {
signed height; signed height;
signed spacing; signed spacing;
}; };
nall::vector<Property> properties; vector<Property> properties;
}; };
#endif #endif

View File

@ -43,7 +43,7 @@
#define DeclareWidget(Name) \ #define DeclareWidget(Name) \
DeclareSizable(Name) \ DeclareSizable(Name) \
auto doSize() const -> void { return self().doSize(); } \ auto doSize() const -> void { return self().doSize(); } \
auto onSize(const function<void ()>& function = {}) -> type& { return self().onSize(function), *this; } \ auto onSize(const function<void ()>& callback = {}) -> type& { return self().onSize(callback), *this; } \
#if defined(Hiro_Object) #if defined(Hiro_Object)
struct Object : sObject { struct Object : sObject {
@ -78,8 +78,8 @@ struct Hotkey : sHotkey {
auto doPress() const -> void { return self().doPress(); } auto doPress() const -> void { return self().doPress(); }
auto doRelease() const -> void { return self().doRelease(); } auto doRelease() const -> void { return self().doRelease(); }
auto onPress(const function<void ()>& function = {}) -> type& { return self().onPress(function), *this; } auto onPress(const function<void ()>& callback = {}) -> type& { return self().onPress(callback), *this; }
auto onRelease(const function<void ()>& function = {}) -> type& { return self().onRelease(function), *this; } auto onRelease(const function<void ()>& callback = {}) -> type& { return self().onRelease(callback), *this; }
auto parent() const -> wObject { return self().parent(); } auto parent() const -> wObject { return self().parent(); }
auto sequence() const -> string { return self().sequence(); } auto sequence() const -> string { return self().sequence(); }
auto setParent(sObject object) -> type& { return self().setParent(object), *this; } 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 doActivate() const -> void { return self().doActivate(); }
auto interval() const -> unsigned { return self().interval(); } auto interval() const -> unsigned { return self().interval(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto setInterval(unsigned interval = 0) -> type& { return self().setInterval(interval), *this; } auto setInterval(unsigned interval = 0) -> type& { return self().setInterval(interval), *this; }
}; };
#endif #endif
@ -119,20 +119,19 @@ struct Window : sWindow {
auto layout() const -> sLayout { return self().layout(); } auto layout() const -> sLayout { return self().layout(); }
auto menuBar() const -> sMenuBar { return self().menuBar(); } auto menuBar() const -> sMenuBar { return self().menuBar(); }
auto modal() const -> bool { return self().modal(); } auto modal() const -> bool { return self().modal(); }
auto onClose(const function<void ()>& function = {}) -> type& { return self().onClose(function), *this; } auto onClose(const function<void ()>& callback = {}) -> type& { return self().onClose(callback), *this; }
auto onDrop(const function<void (nall::lstring)>& function = {}) -> type& { return self().onDrop(function), *this; } auto onDrop(const function<void (lstring)>& callback = {}) -> type& { return self().onDrop(callback), *this; }
auto onKeyPress(const function<void (signed)>& function = {}) -> type& { return self().onKeyPress(function), *this; } auto onKeyPress(const function<void (signed)>& callback = {}) -> type& { return self().onKeyPress(callback), *this; }
auto onKeyRelease(const function<void (signed)>& function = {}) -> type& { return self().onKeyRelease(function), *this; } auto onKeyRelease(const function<void (signed)>& callback = {}) -> type& { return self().onKeyRelease(callback), *this; }
auto onMove(const function<void ()>& function = {}) -> type& { return self().onMove(function), *this; } auto onMove(const function<void ()>& callback = {}) -> type& { return self().onMove(callback), *this; }
auto onSize(const function<void ()>& function = {}) -> type& { return self().onSize(function), *this; } auto onSize(const function<void ()>& callback = {}) -> type& { return self().onSize(callback), *this; }
auto remove(sLayout layout) -> type& { return self().remove(layout), *this; } auto remove(sLayout layout) -> type& { return self().remove(layout), *this; }
auto remove(sMenuBar menuBar) -> type& { return self().remove(menuBar), *this; } auto remove(sMenuBar menuBar) -> type& { return self().remove(menuBar), *this; }
auto remove(sStatusBar statusBar) -> type& { return self().remove(statusBar), *this; } auto remove(sStatusBar statusBar) -> type& { return self().remove(statusBar), *this; }
auto reset() -> type& { return self().reset(), *this; } auto reset() -> type& { return self().reset(), *this; }
auto resizable() const -> bool { return self().resizable(); } auto resizable() const -> bool { return self().resizable(); }
auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; } 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 setDroppable(bool droppable = true) -> type& { return self().setDroppable(droppable), *this; }
auto setFrameGeometry(Geometry geometry) -> type& { return self().setFrameGeometry(geometry), *this; } auto setFrameGeometry(Geometry geometry) -> type& { return self().setFrameGeometry(geometry), *this; }
auto setFramePosition(Position position) -> type& { return self().setFramePosition(position), *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 doActivate() const -> void { return self().doActivate(); }
auto icon() const -> image { return self().icon(); } auto icon() const -> image { return self().icon(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto setIcon(const image& icon = {}) -> type& { return self().setIcon(icon), *this; } auto setIcon(const image& icon = {}) -> type& { return self().setIcon(icon), *this; }
auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; }
auto text() const -> string { return self().text(); } auto text() const -> string { return self().text(); }
@ -230,7 +229,7 @@ struct MenuCheckItem : sMenuCheckItem {
auto checked() const -> bool { return self().checked(); } auto checked() const -> bool { return self().checked(); }
auto doToggle() const -> void { return self().doToggle(); } auto doToggle() const -> void { return self().doToggle(); }
auto onToggle(const function<void ()>& function = {}) -> type& { return self().onToggle(function), *this; } auto onToggle(const function<void ()>& callback = {}) -> type& { return self().onToggle(callback), *this; }
auto setChecked(bool checked = true) -> type& { return self().setChecked(checked), *this; } auto setChecked(bool checked = true) -> type& { return self().setChecked(checked), *this; }
auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; }
auto text() const -> string { return self().text(); } auto text() const -> string { return self().text(); }
@ -244,7 +243,7 @@ struct MenuRadioItem : sMenuRadioItem {
auto checked() const -> bool { return self().checked(); } auto checked() const -> bool { return self().checked(); }
auto doActivate() const -> void { return self().doActivate(); } auto doActivate() const -> void { return self().doActivate(); }
auto group() const -> sGroup { return self().group(); } auto group() const -> sGroup { return self().group(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto setChecked() -> type& { return self().setChecked(), *this; } auto setChecked() -> type& { return self().setChecked(), *this; }
auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; }
auto text() const -> string { return self().text(); } auto text() const -> string { return self().text(); }
@ -276,7 +275,7 @@ struct Button : sButton {
auto bordered() const -> bool { return self().bordered(); } auto bordered() const -> bool { return self().bordered(); }
auto doActivate() const -> void { return self().doActivate(); } auto doActivate() const -> void { return self().doActivate(); }
auto icon() const -> image { return self().icon(); } auto icon() const -> image { return self().icon(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto orientation() const -> Orientation { return self().orientation(); } auto orientation() const -> Orientation { return self().orientation(); }
auto setBordered(bool bordered = true) -> type& { return self().setBordered(bordered), *this; } auto setBordered(bool bordered = true) -> type& { return self().setBordered(bordered), *this; }
auto setIcon(const image& icon = {}) -> type& { return self().setIcon(icon), *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 doMouseRelease(Mouse::Button button) const -> void { return self().doMouseRelease(button); }
auto gradient() const -> vector<Color> { return self().gradient(); } auto gradient() const -> vector<Color> { return self().gradient(); }
auto icon() const -> image { return self().icon(); } auto icon() const -> image { return self().icon(); }
auto onDrop(const function<void (lstring)>& function = {}) -> type& { return self().onDrop(function), *this; } auto onDrop(const function<void (lstring)>& callback = {}) -> type& { return self().onDrop(callback), *this; }
auto onMouseLeave(const function<void ()>& function = {}) -> type& { return self().onMouseLeave(function), *this; } auto onMouseLeave(const function<void ()>& callback = {}) -> type& { return self().onMouseLeave(callback), *this; }
auto onMouseMove(const function<void (Position)>& function = {}) -> type& { return self().onMouseMove(function), *this; } auto onMouseMove(const function<void (Position)>& callback = {}) -> type& { return self().onMouseMove(callback), *this; }
auto onMousePress(const function<void (Mouse::Button)>& function = {}) -> type& { return self().onMousePress(function), *this; } auto onMousePress(const function<void (Mouse::Button)>& callback = {}) -> type& { return self().onMousePress(callback), *this; }
auto onMouseRelease(const function<void (Mouse::Button)>& function = {}) -> type& { return self().onMouseRelease(function), *this; } auto onMouseRelease(const function<void (Mouse::Button)>& callback = {}) -> type& { return self().onMouseRelease(callback), *this; }
auto setColor(Color color) -> type& { return self().setColor(color), *this; } auto setColor(Color color) -> type& { return self().setColor(color), *this; }
auto setData(Size size) -> type& { return self().setData(size), *this; } auto setData(Size size) -> type& { return self().setData(size), *this; }
auto setDroppable(bool droppable = true) -> type& { return self().setDroppable(droppable), *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 checked() const -> bool { return self().checked(); }
auto doToggle() const -> void { return self().doToggle(); } auto doToggle() const -> void { return self().doToggle(); }
auto icon() const -> image { return self().icon(); } auto icon() const -> image { return self().icon(); }
auto onToggle(const function<void ()>& function = {}) -> type& { return self().onToggle(function), *this; } auto onToggle(const function<void ()>& callback = {}) -> type& { return self().onToggle(callback), *this; }
auto orientation() const -> Orientation { return self().orientation(); } auto orientation() const -> Orientation { return self().orientation(); }
auto setBordered(bool bordered = true) -> type& { return self().setBordered(bordered), *this; } auto setBordered(bool bordered = true) -> type& { return self().setBordered(bordered), *this; }
auto setChecked(bool checked = true) -> type& { return self().setChecked(checked), *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 checked() const -> bool { return self().checked(); }
auto doToggle() const -> void { return self().doToggle(); } auto doToggle() const -> void { return self().doToggle(); }
auto onToggle(const function<void ()>& function = {}) -> type& { return self().onToggle(function), *this; } auto onToggle(const function<void ()>& callback = {}) -> type& { return self().onToggle(callback), *this; }
auto setChecked(bool checked = true) -> type& { return self().setChecked(checked), *this; } auto setChecked(bool checked = true) -> type& { return self().setChecked(checked), *this; }
auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; }
auto text() const -> string { return self().text(); } auto text() const -> string { return self().text(); }
@ -357,7 +356,7 @@ struct ComboButton : sComboButton {
auto doChange() const -> void { return self().doChange(); } auto doChange() const -> void { return self().doChange(); }
auto item(unsigned position) const -> sComboButtonItem { return self().item(position); } auto item(unsigned position) const -> sComboButtonItem { return self().item(position); }
auto items() const -> unsigned { return self().items(); } auto items() const -> unsigned { return self().items(); }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto remove(sComboButtonItem item) -> type& { return self().remove(item), *this; } auto remove(sComboButtonItem item) -> type& { return self().remove(item), *this; }
auto reset() -> type& { return self().reset(), *this; } auto reset() -> type& { return self().reset(), *this; }
auto selected() const -> sComboButtonItem { return self().selected(); } auto selected() const -> sComboButtonItem { return self().selected(); }
@ -385,7 +384,7 @@ struct Console : sConsole {
auto backgroundColor() const -> Color { return self().backgroundColor(); } auto backgroundColor() const -> Color { return self().backgroundColor(); }
auto doActivate(string command) const -> void { return self().doActivate(command); } auto doActivate(string command) const -> void { return self().doActivate(command); }
auto foregroundColor() const -> Color { return self().foregroundColor(); } auto foregroundColor() const -> Color { return self().foregroundColor(); }
auto onActivate(const function<void (string)>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void (string)>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto print(const string& text) -> type& { return self().print(text), *this; } auto print(const string& text) -> type& { return self().print(text), *this; }
auto prompt() const -> string { return self().prompt(); } auto prompt() const -> string { return self().prompt(); }
auto reset() -> type& { return self().reset(), *this; } auto reset() -> type& { return self().reset(), *this; }
@ -419,8 +418,8 @@ struct HexEdit : sHexEdit {
auto foregroundColor() const -> Color { return self().foregroundColor(); } auto foregroundColor() const -> Color { return self().foregroundColor(); }
auto length() const -> unsigned { return self().length(); } auto length() const -> unsigned { return self().length(); }
auto offset() const -> unsigned { return self().offset(); } auto offset() const -> unsigned { return self().offset(); }
auto onRead(const function<uint8_t (unsigned)>& function = {}) -> type& { return self().onRead(function), *this; } auto onRead(const function<uint8_t (unsigned)>& callback = {}) -> type& { return self().onRead(callback), *this; }
auto onWrite(const function<void (unsigned, uint8_t)>& function = {}) -> type& { return self().onWrite(function), *this; } auto onWrite(const function<void (unsigned, uint8_t)>& callback = {}) -> type& { return self().onWrite(callback), *this; }
auto rows() const -> unsigned { return self().rows(); } auto rows() const -> unsigned { return self().rows(); }
auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; } auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; }
auto setColumns(unsigned columns = 16) -> type& { return self().setColumns(columns), *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 doChange() const -> void { return self().doChange(); }
auto length() const -> unsigned { return self().length(); } auto length() const -> unsigned { return self().length(); }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto position() const -> unsigned { return self().position(); } auto position() const -> unsigned { return self().position(); }
auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; } auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; }
auto setPosition(unsigned position = 0) -> type& { return self().setPosition(position), *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 doChange() const -> void { return self().doChange(); }
auto length() const -> unsigned { return self().length(); } auto length() const -> unsigned { return self().length(); }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto position() const -> unsigned { return self().position(); } auto position() const -> unsigned { return self().position(); }
auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; } auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; }
auto setPosition(unsigned position = 0) -> type& { return self().setPosition(position), *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 item(unsigned position) const -> sIconViewItem { return self().item(position); }
auto items() const -> unsigned { return self().items(); } auto items() const -> unsigned { return self().items(); }
auto multiSelect() const -> bool { return self().multiSelect(); } auto multiSelect() const -> bool { return self().multiSelect(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto onContext(const function<void ()>& function = {}) -> type& { return self().onContext(function), *this; } auto onContext(const function<void ()>& callback = {}) -> type& { return self().onContext(callback), *this; }
auto orientation() const -> Orientation { return self().orientation(); } auto orientation() const -> Orientation { return self().orientation(); }
auto remove(sIconViewItem item) -> type& { return self().remove(item), *this; } auto remove(sIconViewItem item) -> type& { return self().remove(item), *this; }
auto reset() -> type& { return self().reset(), *this; } auto reset() -> type& { return self().reset(), *this; }
@ -524,8 +523,8 @@ struct LineEdit : sLineEdit {
auto doChange() const -> void { return self().doChange(); } auto doChange() const -> void { return self().doChange(); }
auto editable() const -> bool { return self().editable(); } auto editable() const -> bool { return self().editable(); }
auto foregroundColor() const -> Color { return self().foregroundColor(); } auto foregroundColor() const -> Color { return self().foregroundColor(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; } auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; }
auto setEditable(bool editable = true) -> type& { return self().setEditable(editable), *this; } auto setEditable(bool editable = true) -> type& { return self().setEditable(editable), *this; }
auto setForegroundColor(Color color = {}) -> type& { return self().setForegroundColor(color), *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 headerVisible() const -> bool { return self().headerVisible(); }
auto item(unsigned position) -> sListViewItem { return self().item(position); } auto item(unsigned position) -> sListViewItem { return self().item(position); }
auto items() const -> unsigned { return self().items(); } auto items() const -> unsigned { return self().items(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto onContext(const function<void ()>& function = {}) -> type& { return self().onContext(function), *this; } auto onContext(const function<void ()>& callback = {}) -> type& { return self().onContext(callback), *this; }
auto onEdit(const function<void (sListViewCell)>& function = {}) -> type& { return self().onEdit(function), *this; } auto onEdit(const function<void (sListViewCell)>& callback = {}) -> type& { return self().onEdit(callback), *this; }
auto onSort(const function<void (sListViewColumn)>& function = {}) -> type& { return self().onSort(function), *this; } auto onSort(const function<void (sListViewColumn)>& callback = {}) -> type& { return self().onSort(callback), *this; }
auto onToggle(const function<void (sListViewItem)>& function = {}) -> type& { return self().onToggle(function), *this; } auto onToggle(const function<void (sListViewItem)>& callback = {}) -> type& { return self().onToggle(callback), *this; }
auto remove(sListViewColumn column) -> type& { return self().remove(column), *this; } auto remove(sListViewColumn column) -> type& { return self().remove(column), *this; }
auto remove(sListViewItem item) -> type& { return self().remove(item), *this; } auto remove(sListViewItem item) -> type& { return self().remove(item), *this; }
auto reset() -> type& { return self().reset(), *this; } auto reset() -> type& { return self().reset(), *this; }
@ -665,7 +664,7 @@ struct RadioButton : sRadioButton {
auto doActivate() const -> void { return self().doActivate(); } auto doActivate() const -> void { return self().doActivate(); }
auto group() const -> sGroup { return self().group(); } auto group() const -> sGroup { return self().group(); }
auto icon() const -> image { return self().icon(); } auto icon() const -> image { return self().icon(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto orientation() const -> Orientation { return self().orientation(); } auto orientation() const -> Orientation { return self().orientation(); }
auto setBordered(bool bordered = true) -> type& { return self().setBordered(bordered), *this; } auto setBordered(bool bordered = true) -> type& { return self().setBordered(bordered), *this; }
auto setChecked() -> type& { return self().setChecked(), *this; } auto setChecked() -> type& { return self().setChecked(), *this; }
@ -683,7 +682,7 @@ struct RadioLabel : sRadioLabel {
auto checked() const -> bool { return self().checked(); } auto checked() const -> bool { return self().checked(); }
auto doActivate() const -> void { return self().doActivate(); } auto doActivate() const -> void { return self().doActivate(); }
auto group() const -> sGroup { return self().group(); } auto group() const -> sGroup { return self().group(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto setChecked() -> type& { return self().setChecked(), *this; } auto setChecked() -> type& { return self().setChecked(), *this; }
auto setText(const string& text = "") -> type& { return self().setText(text), *this; } auto setText(const string& text = "") -> type& { return self().setText(text), *this; }
auto text() const -> string { return self().text(); } auto text() const -> string { return self().text(); }
@ -696,8 +695,8 @@ struct SourceEdit : sSourceEdit {
auto doChange() const -> void { return self().doChange(); } auto doChange() const -> void { return self().doChange(); }
auto doMove() const -> void { return self().doMove(); } auto doMove() const -> void { return self().doMove(); }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto onMove(const function<void ()>& function = {}) -> type& { return self().onMove(function), *this; } auto onMove(const function<void ()>& callback = {}) -> type& { return self().onMove(callback), *this; }
auto position() const -> unsigned { return self().position(); } auto position() const -> unsigned { return self().position(); }
auto setPosition(signed position) -> type& { return self().setPosition(position), *this; } auto setPosition(signed position) -> type& { return self().setPosition(position), *this; }
auto setSelected(Position selected) -> type& { return self().setSelected(selected), *this; } auto setSelected(Position selected) -> type& { return self().setSelected(selected), *this; }
@ -717,9 +716,9 @@ struct TabFrame : sTabFrame {
auto edge() const -> Edge; auto edge() const -> Edge;
auto item(unsigned position) const -> sTabFrameItem { return self().item(position); } auto item(unsigned position) const -> sTabFrameItem { return self().item(position); }
auto items() const -> unsigned { return self().items(); } auto items() const -> unsigned { return self().items(); }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto onClose(const function<void (sTabFrameItem)>& function = {}) -> type& { return self().onClose(function), *this; } auto onClose(const function<void (sTabFrameItem)>& callback = {}) -> type& { return self().onClose(callback), *this; }
auto onMove(const function<void (sTabFrameItem, sTabFrameItem)>& function = {}) -> type& { return self().onMove(function), *this; } auto onMove(const function<void (sTabFrameItem, sTabFrameItem)>& callback = {}) -> type& { return self().onMove(callback), *this; }
auto remove(sTabFrameItem item) -> type& { return self().remove(item), *this; } auto remove(sTabFrameItem item) -> type& { return self().remove(item), *this; }
auto reset() -> type& { return self().reset(), *this; } auto reset() -> type& { return self().reset(), *this; }
auto selected() const -> sTabFrameItem { return self().selected(); } auto selected() const -> sTabFrameItem { return self().selected(); }
@ -758,8 +757,8 @@ struct TextEdit : sTextEdit {
auto doMove() const -> void { return self().doMove(); } auto doMove() const -> void { return self().doMove(); }
auto editable() const -> bool { return self().editable(); } auto editable() const -> bool { return self().editable(); }
auto foregroundColor() const -> Color { return self().foregroundColor(); } auto foregroundColor() const -> Color { return self().foregroundColor(); }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto onMove(const function<void ()>& function = {}) -> type& { return self().onMove(function), *this; } auto onMove(const function<void ()>& callback = {}) -> type& { return self().onMove(callback), *this; }
auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; } auto setBackgroundColor(Color color = {}) -> type& { return self().setBackgroundColor(color), *this; }
auto setCursorPosition(unsigned position) -> type& { return self().setCursorPosition(position), *this; } auto setCursorPosition(unsigned position) -> type& { return self().setCursorPosition(position), *this; }
auto setEditable(bool editable = true) -> type& { return self().setEditable(editable), *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 foregroundColor() const -> Color { return self().foregroundColor(); }
auto item(const string& path) const -> sTreeViewItem { return self().item(path); } auto item(const string& path) const -> sTreeViewItem { return self().item(path); }
auto items() const -> unsigned { return self().items(); } auto items() const -> unsigned { return self().items(); }
auto onActivate(const function<void ()>& function = {}) -> type& { return self().onActivate(function), *this; } auto onActivate(const function<void ()>& callback = {}) -> type& { return self().onActivate(callback), *this; }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto onContext(const function<void ()>& function = {}) -> type& { return self().onContext(function), *this; } auto onContext(const function<void ()>& callback = {}) -> type& { return self().onContext(callback), *this; }
auto onToggle(const function<void (sTreeViewItem)>& function = {}) -> type& { return self().onToggle(function), *this; } auto onToggle(const function<void (sTreeViewItem)>& callback = {}) -> type& { return self().onToggle(callback), *this; }
auto remove(sTreeViewItem item) -> type& { return self().remove(item), *this; } auto remove(sTreeViewItem item) -> type& { return self().remove(item), *this; }
auto reset() -> type& { return self().reset(), *this; } auto reset() -> type& { return self().reset(), *this; }
auto selected() const -> sTreeViewItem { return self().selected(); } auto selected() const -> sTreeViewItem { return self().selected(); }
@ -826,7 +825,7 @@ struct VerticalScroller : sVerticalScroller {
auto doChange() const -> void { return self().doChange(); } auto doChange() const -> void { return self().doChange(); }
auto length() const -> unsigned { return self().length(); } auto length() const -> unsigned { return self().length(); }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto position() const -> unsigned { return self().position(); } auto position() const -> unsigned { return self().position(); }
auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; } auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; }
auto setPosition(unsigned position = 0) -> type& { return self().setPosition(position), *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 doChange() const -> void { return self().doChange(); }
auto length() const -> unsigned { return self().length(); } auto length() const -> unsigned { return self().length(); }
auto onChange(const function<void ()>& function = {}) -> type& { return self().onChange(function), *this; } auto onChange(const function<void ()>& callback = {}) -> type& { return self().onChange(callback), *this; }
auto position() const -> unsigned { return self().position(); } auto position() const -> unsigned { return self().position(); }
auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; } auto setLength(unsigned length = 101) -> type& { return self().setLength(length), *this; }
auto setPosition(unsigned position = 0) -> type& { return self().setPosition(position), *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 doMouseRelease(Mouse::Button button) const -> void { return self().doMouseRelease(button); }
auto droppable() const -> bool { return self().droppable(); } auto droppable() const -> bool { return self().droppable(); }
auto handle() const -> uintptr_t { return self().handle(); } auto handle() const -> uintptr_t { return self().handle(); }
auto onDrop(const function<void (lstring)>& function = {}) -> type& { return self().onDrop(function), *this; } auto onDrop(const function<void (lstring)>& callback = {}) -> type& { return self().onDrop(callback), *this; }
auto onMouseLeave(const function<void ()>& function = {}) -> type& { return self().onMouseLeave(function), *this; } auto onMouseLeave(const function<void ()>& callback = {}) -> type& { return self().onMouseLeave(callback), *this; }
auto onMouseMove(const function<void (Position)>& function = {}) -> type& { return self().onMouseMove(function), *this; } auto onMouseMove(const function<void (Position)>& callback = {}) -> type& { return self().onMouseMove(callback), *this; }
auto onMousePress(const function<void (Mouse::Button)>& function = {}) -> type& { return self().onMousePress(function), *this; } auto onMousePress(const function<void (Mouse::Button)>& callback = {}) -> type& { return self().onMousePress(callback), *this; }
auto onMouseRelease(const function<void (Mouse::Button)>& function = {}) -> type& { return self().onMouseRelease(function), *this; } auto onMouseRelease(const function<void (Mouse::Button)>& callback = {}) -> type& { return self().onMouseRelease(callback), *this; }
auto setDroppable(bool droppable = true) -> type& { return self().setDroppable(droppable), *this; } auto setDroppable(bool droppable = true) -> type& { return self().setDroppable(droppable), *this; }
}; };
#endif #endif

View File

@ -1,6 +1,6 @@
#if defined(Hiro_VerticalLayout) #if defined(Hiro_VerticalLayout)
auto mVerticalLayout::append(shared_pointer<mSizable> 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}); properties.append({size.width(), size.height(), spacing < 0 ? settings.spacing : spacing});
mLayout::append(sizable); mLayout::append(sizable);
return *this; return *this;
@ -31,7 +31,7 @@ auto mVerticalLayout::minimumSize() const -> Size {
return {settings.margin * 2 + width, settings.margin * 2 + height}; return {settings.margin * 2 + width, settings.margin * 2 + height};
} }
auto mVerticalLayout::remove(shared_pointer<mSizable> sizable) -> type& { auto mVerticalLayout::remove(sSizable sizable) -> type& {
properties.remove(sizable->offset()); properties.remove(sizable->offset());
mLayout::remove(sizable); mLayout::remove(sizable);
return *this; return *this;

View File

@ -5,13 +5,13 @@ struct mVerticalLayout : mLayout {
using mLayout::append; using mLayout::append;
using mLayout::remove; using mLayout::remove;
auto append(nall::shared_pointer<mSizable> sizable, Size size, signed spacing = 5) -> type&; auto append(sSizable sizable, Size size, signed spacing = 5) -> type&;
auto minimumSize() const -> Size override; auto minimumSize() const -> Size override;
auto remove(nall::shared_pointer<mSizable> sizable) -> type& override; auto remove(sSizable sizable) -> type& override;
auto reset() -> type& override; auto reset() -> type& override;
auto setAlignment(double alignment = 0.0) -> type&; auto setAlignment(double alignment = 0.0) -> type&;
auto setEnabled(bool enabled = true) -> 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 setGeometry(Geometry geometry) -> type& override; auto setGeometry(Geometry geometry) -> type& override;
auto setMargin(signed margin = 0) -> type&; auto setMargin(signed margin = 0) -> type&;
auto setSpacing(signed spacing = 5) -> type&; auto setSpacing(signed spacing = 5) -> type&;
@ -28,7 +28,7 @@ struct mVerticalLayout : mLayout {
signed height; signed height;
signed spacing; signed spacing;
}; };
nall::vector<Properties> properties; vector<Properties> properties;
}; };
#endif #endif

View File

@ -136,24 +136,30 @@ auto pApplication::initialize() -> void {
static auto Application_keyboardProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> bool { 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; if(msg != WM_KEYDOWN && msg != WM_SYSKEYDOWN && msg != WM_KEYUP && msg != WM_SYSKEYUP) return false;
GUITHREADINFO info; GUITHREADINFO info{sizeof(GUITHREADINFO)};
memset(&info, 0, sizeof(GUITHREADINFO));
info.cbSize = sizeof(GUITHREADINFO);
GetGUIThreadInfo(GetCurrentThreadId(), &info); GetGUIThreadInfo(GetCurrentThreadId(), &info);
auto object = (mObject*)GetWindowLongPtr(info.hwndFocus, GWLP_USERDATA); auto object = (mObject*)GetWindowLongPtr(info.hwndFocus, GWLP_USERDATA);
if(!object) return false; if(!object) return false;
if(auto window = dynamic_cast<mWindow*>(object)) { if(auto window = dynamic_cast<mWindow*>(object)) {
if(pWindow::modal && !pWindow::modal.find(window->self())) return false; if(auto self = window->self()) {
if(!self->_modalityDisabled()) {
if(auto code = pKeyboard::_translate(wparam, lparam)) { if(auto code = pKeyboard::_translate(wparam, lparam)) {
if(msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) window->doKeyPress(code); if(msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) window->doKeyPress(code);
if(msg == WM_KEYUP || msg == WM_SYSKEYUP) window->doKeyRelease(code); if(msg == WM_KEYUP || msg == WM_SYSKEYUP) window->doKeyRelease(code);
}
}
} }
return false; return false;
} }
if(auto window = object->parentWindow(true)) {
if(auto self = window->self()) {
if(self->_modalityDisabled()) return false;
}
}
if(msg == WM_KEYDOWN) { if(msg == WM_KEYDOWN) {
if(0); if(0);
@ -225,23 +231,26 @@ case WM_GETMINMAXINFO: {
*/ */
static auto CALLBACK Application_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT { 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); auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
if(!object) return DefWindowProc(hwnd, msg, wparam, lparam); if(!object) return DefWindowProc(hwnd, msg, wparam, lparam);
auto& window = dynamic_cast<mWindow*>(object) ? (mWindow&)*object : *object->parentWindow(true); auto window = dynamic_cast<mWindow*>(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->_modalityDisabled()) return DefWindowProc(hwnd, msg, wparam, lparam);
if(pWindow::modal && !pWindow::modal.find(window.self())) process = false;
if(Application::state.quit) process = false;
if(!process) return DefWindowProc(hwnd, msg, wparam, lparam);
switch(msg) { switch(msg) {
case WM_CLOSE: window.self()->onClose(); return TRUE; case WM_CLOSE: pWindow->onClose(); return true;
case WM_MOVE: window.self()->onMove(); break; case WM_MOVE: pWindow->onMove(); break;
case WM_SIZE: window.self()->onSize(); break; case WM_SIZE: pWindow->onSize(); break;
case WM_DROPFILES: window.self()->onDrop(wparam); return FALSE; case WM_DROPFILES: pWindow->onDrop(wparam); return false;
case WM_ERASEBKGND: if(window.self()->onEraseBackground()) return true; break; case WM_ERASEBKGND: if(pWindow->onEraseBackground()) return true; break;
case WM_ENTERMENULOOP: case WM_ENTERSIZEMOVE: window.self()->onModalBegin(); return FALSE; case WM_ENTERMENULOOP: case WM_ENTERSIZEMOVE: pWindow->onModalBegin(); return false;
case WM_EXITMENULOOP: case WM_EXITSIZEMOVE: window.self()->onModalEnd(); return FALSE; case WM_EXITMENULOOP: case WM_EXITSIZEMOVE: pWindow->onModalEnd(); return false;
} }
return Shared_windowProc(DefWindowProc, hwnd, msg, wparam, lparam); return Shared_windowProc(DefWindowProc, hwnd, msg, wparam, lparam);

View File

@ -17,6 +17,8 @@ struct AppMessage {
using WindowProc = auto CALLBACK (*)(HWND, UINT, WPARAM, LPARAM) -> LRESULT; using WindowProc = auto CALLBACK (*)(HWND, UINT, WPARAM, LPARAM) -> LRESULT;
static vector<wObject> windows;
} }
#define Declare(Name, Base) \ #define Declare(Name, Base) \

View File

@ -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 { 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); auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
if(!object) return DefWindowProc(hwnd, msg, wparam, lparam); if(!object) return DefWindowProc(hwnd, msg, wparam, lparam);
auto window = dynamic_cast<mWindow*>(object); auto window = dynamic_cast<mWindow*>(object);
if(!window) window = object->parentWindow(true); if(!window) window = object->parentWindow(true);
if(!window) return DefWindowProc(hwnd, msg, wparam, lparam); 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->_modalityDisabled()) return DefWindowProc(hwnd, msg, wparam, lparam);
if(pWindow::modal && !pWindow::modal.find(window->self())) process = false;
if(Application::state.quit) process = false;
if(!process) return DefWindowProc(hwnd, msg, wparam, lparam);
switch(msg) { switch(msg) {
case WM_CTLCOLORBTN: case WM_CTLCOLORBTN:

View File

@ -2,6 +2,25 @@
namespace hiro { 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<mListView*>(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 { auto pListView::construct() -> void {
hwnd = CreateWindowEx( hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE, WC_LISTVIEW, L"", WS_EX_CLIENTEDGE, WC_LISTVIEW, L"",
@ -9,6 +28,8 @@ auto pListView::construct() -> void {
0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0 0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0
); );
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference); 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); ListView_SetExtendedListViewStyle(hwnd, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
pWidget::_setState(); pWidget::_setState();
setBackgroundColor(state().backgroundColor); setBackgroundColor(state().backgroundColor);

View File

@ -38,6 +38,7 @@ struct pListView : pWidget {
auto _setIcons() -> void; auto _setIcons() -> void;
auto _width(unsigned column) -> unsigned; auto _width(unsigned column) -> unsigned;
WindowProc windowProc = nullptr;
HIMAGELIST imageList = 0; HIMAGELIST imageList = 0;
vector<image> icons; vector<image> icons;
}; };

View File

@ -5,9 +5,12 @@ namespace hiro {
static auto CALLBACK TabFrame_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT { static auto CALLBACK TabFrame_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT {
if(auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA)) { if(auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA)) {
if(auto tabFrame = dynamic_cast<mTabFrame*>(object)) { if(auto tabFrame = dynamic_cast<mTabFrame*>(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); return DefWindowProc(hwnd, msg, wparam, lparam);
} }

View File

@ -15,8 +15,9 @@ auto pWidget::destruct() -> void {
DestroyWindow(hwnd); DestroyWindow(hwnd);
} }
auto pWidget::focused() -> bool { auto pWidget::focused() const -> bool {
return GetFocus() == hwnd; auto focused = GetFocus();
return hwnd == focused || IsChild(hwnd, focused);
} }
auto pWidget::minimumSize() -> Size { auto pWidget::minimumSize() -> Size {
@ -44,11 +45,11 @@ auto pWidget::setFont(const string&) -> void {
auto pWidget::setGeometry(Geometry geometry) -> void { auto pWidget::setGeometry(Geometry geometry) -> void {
if(auto parent = _parentWidget()) { if(auto parent = _parentWidget()) {
Position displacement = parent->geometry().position(); auto displacement = parent->self().geometry().position();
geometry.setX(geometry.x() - displacement.x()); geometry.setX(geometry.x() - displacement.x());
geometry.setY(geometry.y() - displacement.y()); 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(); self().doSize();
} }
@ -62,20 +63,24 @@ auto pWidget::setVisible(bool visible) -> void {
// //
auto pWidget::_parentHandle() -> HWND { auto pWidget::_parentHandle() -> HWND {
if(auto parent = _parentWidget()) return parent->self()->hwnd; if(auto parent = _parentWidget()) return parent->hwnd;
if(auto parent = _parentWindow()) return parent->self()->hwnd; if(auto parent = _parentWindow()) return parent->hwnd;
return 0; return nullptr;
} }
auto pWidget::_parentWidget() -> maybe<mWidget&> { auto pWidget::_parentWidget() -> maybe<pWidget&> {
#if defined(Hiro_TabFrame) #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 #endif
return nothing; return nothing;
} }
auto pWidget::_parentWindow() -> maybe<mWindow&> { auto pWidget::_parentWindow() -> maybe<pWindow&> {
if(auto parent = self().parentWindow(true)) return *parent; if(auto parent = self().parentWindow(true)) {
if(auto self = parent->self()) return *self;
}
return nothing; return nothing;
} }

View File

@ -5,7 +5,7 @@ namespace hiro {
struct pWidget : pSizable { struct pWidget : pSizable {
Declare(Widget, Sizable) Declare(Widget, Sizable)
auto focused() -> bool; auto focused() const -> bool override;
virtual auto minimumSize() -> Size; virtual auto minimumSize() -> Size;
auto setEnabled(bool enabled) -> void override; auto setEnabled(bool enabled) -> void override;
auto setFocused() -> void; auto setFocused() -> void;
@ -14,8 +14,8 @@ struct pWidget : pSizable {
auto setVisible(bool visible) -> void override; auto setVisible(bool visible) -> void override;
auto _parentHandle() -> HWND; auto _parentHandle() -> HWND;
auto _parentWidget() -> maybe<mWidget&>; auto _parentWidget() -> maybe<pWidget&>;
auto _parentWindow() -> maybe<mWindow&>; auto _parentWindow() -> maybe<pWindow&>;
auto _setState() -> void; auto _setState() -> void;
bool abstract = false; bool abstract = false;

View File

@ -2,8 +2,6 @@
namespace hiro { namespace hiro {
vector<pWindow*> pWindow::modal;
static const unsigned FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER; 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; 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); SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference);
setDroppable(state().droppable); setDroppable(state().droppable);
setGeometry({128, 128, 256, 256}); setGeometry({128, 128, 256, 256});
windows.append(self().instance);
} }
auto pWindow::destruct() -> void { auto pWindow::destruct() -> void {
if(auto position = windows.find(self().instance)) windows.remove(*position);
if(hbrush) { DeleteObject(hbrush); hbrush = nullptr; } if(hbrush) { DeleteObject(hbrush); hbrush = nullptr; }
DestroyWindow(hwnd); DestroyWindow(hwnd);
} }
@ -28,7 +30,7 @@ auto pWindow::append(sMenuBar menuBar) -> void {
auto pWindow::append(sStatusBar statusBar) -> void { auto pWindow::append(sStatusBar statusBar) -> void {
} }
auto pWindow::focused() const -> bool override { auto pWindow::focused() const -> bool {
return (GetForegroundWindow() == hwnd); return (GetForegroundWindow() == hwnd);
} }
@ -122,7 +124,7 @@ auto pWindow::setGeometry(Geometry geometry) -> void {
auto pWindow::setModal(bool modality) -> void { auto pWindow::setModal(bool modality) -> void {
if(modality) { if(modality) {
modal.appendOnce(this); _modalityUpdate();
while(state().modal) { while(state().modal) {
Application::processEvents(); Application::processEvents();
if(Application::state.onMain) { if(Application::state.onMain) {
@ -131,7 +133,7 @@ auto pWindow::setModal(bool modality) -> void {
usleep(20 * 1000); 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}; 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<mWindow*>(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<mWindow*>(object.data())) {
if(auto self = window->self()) {
bool enabled = !modalWindows || window->modal();
if(IsWindowEnabled(self->hwnd) != enabled) {
EnableWindow(self->hwnd, enabled);
}
}
}
}
}
}
} }
#endif #endif

View File

@ -33,13 +33,14 @@ struct pWindow : pObject {
auto onSize() -> void; auto onSize() -> void;
auto _geometry() -> Geometry; auto _geometry() -> Geometry;
auto _modalityCount() -> unsigned;
auto _modalityDisabled() -> bool;
auto _modalityUpdate() -> void;
HWND hwnd = nullptr; HWND hwnd = nullptr;
HFONT hstatusfont = nullptr; HFONT hstatusfont = nullptr;
HBRUSH hbrush = nullptr; HBRUSH hbrush = nullptr;
COLORREF hbrushColor = 0; COLORREF hbrushColor = 0;
static vector<pWindow*> modal;
}; };
} }

View File

@ -1,9 +1,6 @@
#ifndef NALL_HTTP_SERVER_HPP #ifndef NALL_HTTP_SERVER_HPP
#define NALL_HTTP_SERVER_HPP #define NALL_HTTP_SERVER_HPP
#include <poll.h>
#include <atomic>
#include <nall/service.hpp> #include <nall/service.hpp>
#include <nall/http/role.hpp> #include <nall/http/role.hpp>

View File

@ -56,13 +56,16 @@ namespace nall {
#define PLATFORM_WINDOWS #define PLATFORM_WINDOWS
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Windows; } Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Windows; }
#elif defined(__APPLE__) #elif defined(__APPLE__)
#define PLATFORM_POSIX
#define PLATFORM_MACOSX #define PLATFORM_MACOSX
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::MacOSX; } Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::MacOSX; }
#elif defined(linux) || defined(__linux__) #elif defined(linux) || defined(__linux__)
#define PLATFORM_POSIX
#define PLATFORM_LINUX #define PLATFORM_LINUX
#define PLATFORM_XORG #define PLATFORM_XORG
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Linux; } Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Linux; }
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define PLATFORM_POSIX
#define PLATFORM_BSD #define PLATFORM_BSD
#define PLATFORM_XORG #define PLATFORM_XORG
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::BSD; } Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::BSD; }

View File

@ -51,6 +51,7 @@ namespace Math {
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#include <poll.h>
#endif #endif
#if defined(COMPILER_CL) #if defined(COMPILER_CL)
@ -58,17 +59,40 @@ namespace Math {
#endif #endif
#if defined(PLATFORM_WINDOWS) #if defined(PLATFORM_WINDOWS)
//fight Microsoft's ardent efforts at vendor lock-in
#undef interface #undef interface
#define dllexport __declspec(dllexport) #define dllexport __declspec(dllexport)
#define MSG_NOSIGNAL 0 #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 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 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 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 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 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 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); } 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 #else
#define dllexport #define dllexport
#endif #endif

117
nall/posix/service.hpp Normal file
View File

@ -0,0 +1,117 @@
#ifndef NALL_POSIX_SERVICE_HPP
#define NALL_POSIX_SERVICE_HPP
#include <signal.h>
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

View File

@ -0,0 +1,154 @@
#ifndef NALL_POSIX_SHARED_MEMORY_HPP
#define NALL_POSIX_SHARED_MEMORY_HPP
#include <semaphore.h>
#include <sys/mman.h>
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

View File

@ -3,118 +3,14 @@
//service model template built on top of shared-memory //service model template built on top of shared-memory
#include <signal.h>
#include <nall/shared-memory.hpp> #include <nall/shared-memory.hpp>
namespace nall { #if defined(PLATFORM_POSIX)
#include <nall/posix/service.hpp>
#endif
struct service { #if defined(PLATFORM_WINDOWS)
inline explicit operator bool() const; #include <nall/windows/service.hpp>
inline auto command(const string& name, const string& command) -> bool; #endif
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 #endif

View File

@ -4,154 +4,12 @@
#include <nall/memory.hpp> #include <nall/memory.hpp>
#include <nall/string.hpp> #include <nall/string.hpp>
#include <semaphore.h> #if defined(PLATFORM_POSIX)
#include <sys/mman.h> #include <nall/posix/shared-memory.hpp>
#endif
namespace nall { #if defined(PLATFORM_WINDOWS)
#include <nall/windows/shared-memory.hpp>
struct shared_memory { #endif
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;
};
}
#endif #endif

View File

@ -80,7 +80,7 @@ struct shared_pointer {
reset(); reset();
} }
shared_pointer& operator=(T* source) { auto operator=(T* source) -> shared_pointer& {
reset(); reset();
if(source) { if(source) {
manager = new shared_pointer_manager((void*)source); manager = new shared_pointer_manager((void*)source);
@ -89,7 +89,7 @@ struct shared_pointer {
return *this; return *this;
} }
shared_pointer& operator=(const shared_pointer& source) { auto operator=(const shared_pointer& source) -> shared_pointer& {
if(this != &source) { if(this != &source) {
reset(); reset();
if((bool)source) { if((bool)source) {
@ -100,7 +100,7 @@ struct shared_pointer {
return *this; return *this;
} }
shared_pointer& operator=(shared_pointer&& source) { auto operator=(shared_pointer&& source) -> shared_pointer& {
if(this != &source) { if(this != &source) {
reset(); reset();
manager = source.manager; manager = source.manager;
@ -110,7 +110,7 @@ struct shared_pointer {
} }
template<typename U, typename = enable_if<is_compatible<U>>> template<typename U, typename = enable_if<is_compatible<U>>>
shared_pointer& operator=(const shared_pointer<U>& source) { auto operator=(const shared_pointer<U>& source) -> shared_pointer& {
if((uintptr_t)this != (uintptr_t)&source) { if((uintptr_t)this != (uintptr_t)&source) {
reset(); reset();
if((bool)source) { if((bool)source) {
@ -122,7 +122,7 @@ struct shared_pointer {
} }
template<typename U, typename = enable_if<is_compatible<U>>> template<typename U, typename = enable_if<is_compatible<U>>>
shared_pointer& operator=(shared_pointer&& source) { auto operator=(shared_pointer&& source) -> shared_pointer& {
if((uintptr_t)this != (uintptr_t)&source) { if((uintptr_t)this != (uintptr_t)&source) {
reset(); reset();
manager = source.manager; manager = source.manager;
@ -132,7 +132,7 @@ struct shared_pointer {
} }
template<typename U, typename = enable_if<is_compatible<U>>> template<typename U, typename = enable_if<is_compatible<U>>>
shared_pointer& operator=(const shared_pointer_weak<U>& source) { auto operator=(const shared_pointer_weak<U>& source) -> shared_pointer& {
reset(); reset();
if((bool)source) { if((bool)source) {
manager = source.manager; manager = source.manager;
@ -141,32 +141,32 @@ struct shared_pointer {
return *this; return *this;
} }
T* data() { auto data() -> T* {
if(manager) return (T*)manager->pointer; if(manager) return (T*)manager->pointer;
return nullptr; return nullptr;
} }
const T* data() const { auto data() const -> const T* {
if(manager) return (T*)manager->pointer; if(manager) return (T*)manager->pointer;
return nullptr; return nullptr;
} }
T* operator->() { return data(); } auto operator->() -> T* { return data(); }
const T* operator->() const { return data(); } auto operator->() const -> const T* { return data(); }
T& operator*() { return *data(); } auto operator*() -> T& { return *data(); }
const T& operator*() const { return *data(); } auto operator*() const -> const T& { return *data(); }
T& operator()() { return *data(); } auto operator()() -> T& { return *data(); }
const T& operator()() const { return *data(); } auto operator()() const -> const T& { return *data(); }
template<typename U> template<typename U>
bool operator==(const shared_pointer<U>& source) const { auto operator==(const shared_pointer<U>& source) const -> bool {
return manager == source.manager; return manager == source.manager;
} }
template<typename U> template<typename U>
bool operator!=(const shared_pointer<U>& source) const { auto operator!=(const shared_pointer<U>& source) const -> bool {
return manager != source.manager; return manager != source.manager;
} }
@ -174,15 +174,15 @@ struct shared_pointer {
return !empty(); return !empty();
} }
bool empty() const { auto empty() const -> bool {
return !manager || !manager->strong; return !manager || !manager->strong;
} }
bool unique() const { auto unique() const -> bool {
return manager && manager->strong == 1; return manager && manager->strong == 1;
} }
void reset() { auto reset() -> void {
if(manager && manager->strong) { if(manager && manager->strong) {
//pointer may contain weak references; if strong==0 it may destroy manager //pointer may contain weak references; if strong==0 it may destroy manager
//as such, we must destroy strong before decrementing it to zero //as such, we must destroy strong before decrementing it to zero
@ -204,7 +204,7 @@ struct shared_pointer {
} }
template<typename U> template<typename U>
shared_pointer<U> cast() { auto cast() -> shared_pointer<U> {
if(auto pointer = dynamic_cast<U*>(data())) { if(auto pointer = dynamic_cast<U*>(data())) {
return {*this, pointer}; return {*this, pointer};
} }
@ -224,7 +224,7 @@ struct shared_pointer_weak {
operator=(source); operator=(source);
} }
shared_pointer_weak& operator=(const shared_pointer<T>& source) { auto operator=(const shared_pointer<T>& source) -> shared_pointer_weak& {
reset(); reset();
if(manager = source.manager) manager->weak++; if(manager = source.manager) manager->weak++;
return *this; return *this;
@ -234,19 +234,27 @@ struct shared_pointer_weak {
reset(); 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 { explicit operator bool() const {
return !empty(); return !empty();
} }
bool empty() const { auto empty() const -> bool {
return !manager || !manager->strong; return !manager || !manager->strong;
} }
shared_pointer<T> acquire() const { auto acquire() const -> shared_pointer<T> {
return shared_pointer<T>(*this); return shared_pointer<T>(*this);
} }
void reset() { auto reset() -> void {
if(manager && --manager->weak == 0) { if(manager && --manager->weak == 0) {
if(manager->strong == 0) { if(manager->strong == 0) {
delete manager; delete manager;

16
nall/windows/service.hpp Normal file
View File

@ -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

View File

@ -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

View File

@ -1,66 +1,66 @@
//audio.alsa (2009-11-30)
//authors: BearOso, byuu, Nach, RedDwarf
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
namespace ruby { namespace ruby {
class pAudioALSA { struct pAudioALSA {
public:
struct { struct {
snd_pcm_t* handle; snd_pcm_t* handle = nullptr;
snd_pcm_format_t format; snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE;
snd_pcm_uframes_t buffer_size; snd_pcm_uframes_t buffer_size;
snd_pcm_uframes_t period_size; snd_pcm_uframes_t period_size;
int channels; int channels = 2;
const char* name; const char* name = "default";
} device; } device;
struct { struct {
uint32_t* data; uint32_t* data = nullptr;
unsigned length; unsigned length = 0;
} buffer; } buffer;
struct { struct {
bool synchronize; bool synchronize = false;
unsigned frequency; unsigned frequency = 22050;
unsigned latency; unsigned latency = 60;
} settings; } settings;
bool cap(const string& name) { ~pAudioALSA() {
term();
}
auto cap(const string& name) -> bool {
if(name == Audio::Synchronize) return true; if(name == Audio::Synchronize) return true;
if(name == Audio::Frequency) return true; if(name == Audio::Frequency) return true;
if(name == Audio::Latency) return true; if(name == Audio::Latency) return true;
return false; return false;
} }
any get(const string& name) { auto get(const string& name) -> any {
if(name == Audio::Synchronize) return settings.synchronize; if(name == Audio::Synchronize) return settings.synchronize;
if(name == Audio::Frequency) return settings.frequency; if(name == Audio::Frequency) return settings.frequency;
if(name == Audio::Latency) return settings.latency; if(name == Audio::Latency) return settings.latency;
return false; return {};
} }
bool set(const string& name, const any& value) { auto set(const string& name, const any& value) -> bool {
if(name == Audio::Synchronize) { if(name == Audio::Synchronize && value.is<bool>()) {
if(settings.synchronize != any_cast<bool>(value)) { if(settings.synchronize != value.get<bool>()) {
settings.synchronize = any_cast<bool>(value); settings.synchronize = value.get<bool>();
if(device.handle) init(); if(device.handle) init();
} }
return true; return true;
} }
if(name == Audio::Frequency) { if(name == Audio::Frequency && value.is<unsigned>()) {
if(settings.frequency != any_cast<unsigned>(value)) { if(settings.frequency != value.get<unsigned>()) {
settings.frequency = any_cast<unsigned>(value); settings.frequency = value.get<unsigned>();
if(device.handle) init(); if(device.handle) init();
} }
return true; return true;
} }
if(name == Audio::Latency) { if(name == Audio::Latency && value.is<unsigned>()) {
if(settings.latency != any_cast<unsigned>(value)) { if(settings.latency != value.get<unsigned>()) {
settings.latency = any_cast<unsigned>(value); settings.latency = value.get<unsigned>();
if(device.handle) init(); if(device.handle) init();
} }
return true; return true;
@ -69,7 +69,7 @@ public:
return false; return false;
} }
void sample(uint16_t left, uint16_t right) { auto sample(uint16_t left, uint16_t right) -> void {
if(!device.handle) return; if(!device.handle) return;
buffer.data[buffer.length++] = left + (right << 16); buffer.data[buffer.length++] = left + (right << 16);
@ -123,10 +123,10 @@ public:
} }
} }
void clear() { auto clear() -> void {
} }
bool init() { auto init() -> bool {
term(); term();
if(snd_pcm_open(&device.handle, device.name, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) { if(snd_pcm_open(&device.handle, device.name, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) {
@ -203,7 +203,7 @@ public:
return true; return true;
} }
void term() { auto term() -> void {
if(device.handle) { if(device.handle) {
//snd_pcm_drain(device.handle); //prevents popping noise; but causes multi-second lag //snd_pcm_drain(device.handle); //prevents popping noise; but causes multi-second lag
snd_pcm_close(device.handle); snd_pcm_close(device.handle);
@ -215,24 +215,6 @@ public:
buffer.data = 0; 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) DeclareAudio(ALSA)

View File

@ -1,35 +1,38 @@
/*
audio.ao (2008-06-01)
authors: Nach, RedDwarf
*/
#include <ao/ao.h> #include <ao/ao.h>
namespace ruby { namespace ruby {
class pAudioAO { struct pAudioAO {
public:
int driver_id; int driver_id;
ao_sample_format driver_format; ao_sample_format driver_format;
ao_device* audio_device; ao_device* audio_device = nullptr;
struct { struct {
unsigned frequency; unsigned frequency = 22050;
} settings; } 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; if(name == Audio::Frequency) return true;
return false; return false;
} }
any get(const string& name) { auto get(const string& name) -> any {
if(name == Audio::Frequency) return settings.frequency; if(name == Audio::Frequency) return settings.frequency;
return false; return {};
} }
bool set(const string& name, const any& value) { auto set(const string& name, const any& value) -> bool {
if(name == Audio::Frequency) { if(name == Audio::Frequency && value.is<unsigned>()) {
settings.frequency = any_cast<unsigned>(value); settings.frequency = value.get<unsigned>();
if(audio_device) init(); if(audio_device) init();
return true; return true;
} }
@ -37,15 +40,15 @@ public:
return false; 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); 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 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(); term();
driver_id = ao_default_driver_id(); //ao_driver_id((const char*)driver) driver_id = ao_default_driver_id(); //ao_driver_id((const char*)driver)
@ -69,24 +72,12 @@ public:
return true; return true;
} }
void term() { auto term() -> void {
if(audio_device) { if(audio_device) {
ao_close(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) DeclareAudio(AO)

View File

@ -1,70 +1,74 @@
//audio.pulseaudio (2010-01-05)
//author: RedDwarf
#include <pulse/pulseaudio.h> #include <pulse/pulseaudio.h>
namespace ruby { namespace ruby {
class pAudioPulseAudio { struct pAudioPulseAudio {
public:
struct { struct {
pa_mainloop* mainloop; pa_mainloop* mainloop = nullptr;
pa_context* context; pa_context* context = nullptr;
pa_stream* stream; pa_stream* stream = nullptr;
pa_sample_spec spec; pa_sample_spec spec;
pa_buffer_attr buffer_attr; pa_buffer_attr buffer_attr;
bool first; bool first;
} device; } device;
struct { struct {
uint32_t* data; uint32_t* data = nullptr;
size_t size; size_t size;
unsigned offset; unsigned offset;
} buffer; } buffer;
struct { struct {
bool synchronize; bool synchronize = false;
unsigned frequency; unsigned frequency = 22050;
unsigned latency; unsigned latency = 60;
} settings; } settings;
bool cap(const string& name) { ~pAudioPulseAudio() {
term();
}
auto cap(const string& name) -> bool {
if(name == Audio::Synchronize) return true; if(name == Audio::Synchronize) return true;
if(name == Audio::Frequency) return true; if(name == Audio::Frequency) return true;
if(name == Audio::Latency) 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::Synchronize) return settings.synchronize;
if(name == Audio::Frequency) return settings.frequency; if(name == Audio::Frequency) return settings.frequency;
if(name == Audio::Latency) return settings.latency; if(name == Audio::Latency) return settings.latency;
return {};
} }
bool set(const string& name, const any& value) { auto set(const string& name, const any& value) -> bool {
if(name == Audio::Synchronize) { if(name == Audio::Synchronize && value.is<bool>()) {
settings.synchronize = any_cast<bool>(value); settings.synchronize = value.get<bool>();
return true; return true;
} }
if(name == Audio::Frequency) { if(name == Audio::Frequency && value.is<unsigned>()) {
settings.frequency = any_cast<unsigned>(value); settings.frequency = value.get<unsigned>();
if(device.stream) { if(device.stream) {
pa_operation_unref(pa_stream_update_sample_rate(device.stream, settings.frequency, NULL, NULL)); pa_operation_unref(pa_stream_update_sample_rate(device.stream, settings.frequency, NULL, NULL));
} }
return true; return true;
} }
if(name == Audio::Latency) { if(name == Audio::Latency && value.is<unsigned>()) {
settings.latency = any_cast<unsigned>(value); settings.latency = value.get<unsigned>();
if(device.stream) { if(device.stream) {
device.buffer_attr.tlength = pa_usec_to_bytes(settings.latency * PA_USEC_PER_MSEC, &device.spec); 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); pa_stream_set_buffer_attr(device.stream, &device.buffer_attr, NULL, NULL);
} }
return true; 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); pa_stream_begin_write(device.stream, (void**)&buffer.data, &buffer.size);
buffer.data[buffer.offset++] = left + (right << 16); buffer.data[buffer.offset++] = left + (right << 16);
if((buffer.offset + 1) * pa_frame_size(&device.spec) <= buffer.size) return; if((buffer.offset + 1) * pa_frame_size(&device.spec) <= buffer.size) return;
@ -89,10 +93,10 @@ public:
buffer.offset = 0; buffer.offset = 0;
} }
void clear() { auto clear() -> void {
} }
bool init() { auto init() -> bool {
device.mainloop = pa_mainloop_new(); device.mainloop = pa_mainloop_new();
device.context = pa_context_new(pa_mainloop_get_api(device.mainloop), "ruby::pulseaudio"); device.context = pa_context_new(pa_mainloop_get_api(device.mainloop), "ruby::pulseaudio");
@ -133,43 +137,29 @@ public:
return true; return true;
} }
void term() { auto term() -> void {
if(buffer.data) { if(buffer.data) {
pa_stream_cancel_write(device.stream); pa_stream_cancel_write(device.stream);
buffer.data = 0; buffer.data = nullptr;
} }
if(device.stream) { if(device.stream) {
pa_stream_disconnect(device.stream); pa_stream_disconnect(device.stream);
pa_stream_unref(device.stream); pa_stream_unref(device.stream);
device.stream = 0; device.stream = nullptr;
} }
if(device.context) { if(device.context) {
pa_context_disconnect(device.context); pa_context_disconnect(device.context);
pa_context_unref(device.context); pa_context_unref(device.context);
device.context = 0; device.context = nullptr;
} }
if(device.mainloop) { if(device.mainloop) {
pa_mainloop_free(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) DeclareAudio(PulseAudio)

View File

@ -1,40 +1,40 @@
//audio.pulseaudiosimple (2010-01-05)
//author: byuu
#include <pulse/simple.h> #include <pulse/simple.h>
#include <pulse/error.h> #include <pulse/error.h>
namespace ruby { namespace ruby {
class pAudioPulseAudioSimple { struct pAudioPulseAudioSimple {
public:
struct { struct {
pa_simple* handle; pa_simple* handle = nullptr;
pa_sample_spec spec; pa_sample_spec spec;
} device; } device;
struct { struct {
uint32_t* data; uint32_t* data = nullptr;
unsigned offset; unsigned offset = 0;
} buffer; } buffer;
struct { struct {
unsigned frequency; unsigned frequency = 22050;
} settings; } settings;
bool cap(const string& name) { ~pAudioPulseAudioSimple() {
term();
}
auto cap(const string& name) -> bool {
if(name == Audio::Frequency) return true; if(name == Audio::Frequency) return true;
return false; return false;
} }
any get(const string& name) { auto get(const string& name) -> any {
if(name == Audio::Frequency) return settings.frequency; if(name == Audio::Frequency) return settings.frequency;
return false; return {};
} }
bool set(const string& name, const any& value) { auto set(const string& name, const any& value) -> bool {
if(name == Audio::Frequency) { if(name == Audio::Frequency && value.is<unsigned>()) {
settings.frequency = any_cast<unsigned>(value); settings.frequency = value.get<unsigned>();
if(device.handle) init(); if(device.handle) init();
return true; return true;
} }
@ -42,7 +42,7 @@ public:
return false; return false;
} }
void sample(uint16_t left, uint16_t right) { auto sample(uint16_t left, uint16_t right) -> void {
if(!device.handle) return; if(!device.handle) return;
buffer.data[buffer.offset++] = left + (right << 16); buffer.data[buffer.offset++] = left + (right << 16);
@ -53,10 +53,10 @@ public:
} }
} }
void clear() { auto clear() -> void {
} }
bool init() { auto init() -> bool {
term(); term();
device.spec.format = PA_SAMPLE_S16LE; device.spec.format = PA_SAMPLE_S16LE;
@ -85,7 +85,7 @@ public:
return true; return true;
} }
void term() { auto term() -> void {
if(device.handle) { if(device.handle) {
int error; int error;
pa_simple_flush(device.handle, &error); pa_simple_flush(device.handle, &error);
@ -98,16 +98,6 @@ public:
buffer.data = nullptr; buffer.data = nullptr;
} }
} }
pAudioPulseAudioSimple() {
device.handle = nullptr;
buffer.data = nullptr;
settings.frequency = 22050;
}
~pAudioPulseAudioSimple() {
term();
}
}; };
DeclareAudio(PulseAudioSimple) DeclareAudio(PulseAudioSimple)

View File

@ -8,39 +8,39 @@ struct pInputCarbon {
vector<Key> keys; vector<Key> keys;
struct Keyboard { struct Keyboard {
HID::Keyboard hid; shared_pointer<HID::Keyboard> hid{new HID::Keyboard};
} kb; } kb;
bool cap(const string& name) { auto cap(const string& name) -> bool {
if(name == Input::KeyboardSupport) return true; if(name == Input::KeyboardSupport) return true;
return false; 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; return false;
} }
bool set(const string& name, const any& value) { auto acquire() -> bool { return false; }
return false; auto unacquire() -> bool { return false; }
auto acquired() -> bool { return false; }
auto assign(shared_pointer<HID::Device> 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; } auto poll() -> vector<shared_pointer<HID::Device>> {
bool unacquire() { return false; } vector<shared_pointer<HID::Device>> devices;
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<HID::Device*> poll() {
vector<HID::Device*> devices;
KeyMap keymap; KeyMap keymap;
GetKeys(keymap); GetKeys(keymap);
uint8_t* buffer = (uint8_t*)keymap; auto buffer = (uint8_t*)keymap;
unsigned inputID = 0; unsigned inputID = 0;
for(auto& key : keys) { for(auto& key : keys) {
@ -48,15 +48,15 @@ struct pInputCarbon {
assign(kb.hid, HID::Keyboard::GroupID::Button, inputID++, value); assign(kb.hid, HID::Keyboard::GroupID::Button, inputID++, value);
} }
devices.append(&kb.hid); devices.append(kb.hid);
return devices; return devices;
} }
bool rumble(uint64_t id, bool enable) { auto rumble(uint64_t id, bool enable) -> bool {
return false; return false;
} }
bool init() { auto init() -> bool {
keys.append({0x35, "Escape"}); keys.append({0x35, "Escape"});
keys.append({0x7a, "F1"}); keys.append({0x7a, "F1"});
keys.append({0x78, "F2"}); keys.append({0x78, "F2"});
@ -170,13 +170,13 @@ struct pInputCarbon {
keys.append({0x3a, "Alt"}); keys.append({0x3a, "Alt"});
keys.append({0x37, "Super"}); keys.append({0x37, "Super"});
kb.hid.id = 1; kb.hid->setID(1);
for(auto& key : keys) kb.hid.button().append({key.name}); for(auto& key : keys) kb.hid->buttons().append(key.name);
return true; return true;
} }
void term() { auto term() -> void {
} }
}; };

View File

@ -24,7 +24,7 @@ struct InputJoypadUdev {
}; };
struct Joypad { struct Joypad {
HID::Joypad hid; shared_pointer<HID::Joypad> hid{new HID::Joypad};
int fd = -1; int fd = -1;
dev_t device = 0; dev_t device = 0;
@ -52,14 +52,14 @@ struct InputJoypadUdev {
}; };
vector<Joypad> joypads; vector<Joypad> joypads;
void assign(HID::Joypad& hid, unsigned groupID, unsigned inputID, int16_t value) { auto assign(shared_pointer<HID::Joypad> hid, unsigned groupID, unsigned inputID, int16_t value) -> void {
auto& group = hid.group[groupID]; auto& group = hid->group(groupID);
if(group.input[inputID].value == value) return; if(group.input(inputID).value() == value) return;
if(input.onChange) input.onChange(hid, groupID, inputID, group.input[inputID].value, value); if(input.onChange) input.onChange(hid, groupID, inputID, group.input(inputID).value(), value);
group.input[inputID].value = value; group.input(inputID).setValue(value);
} }
void poll(vector<HID::Device*>& devices) { auto poll(vector<shared_pointer<HID::Device>>& devices) -> void {
while(hotplugDevicesAvailable()) hotplugDevice(); while(hotplugDevicesAvailable()) hotplugDevice();
for(auto& jp : joypads) { 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) { for(auto& jp : joypads) {
if(jp.hid.id != id) continue; if(jp.hid->id() != id) continue;
if(jp.hid.rumble == false) continue; if(!jp.hid->rumble()) continue;
input_event play; input_event play;
memset(&play, 0, sizeof(input_event)); memset(&play, 0, sizeof(input_event));
@ -113,7 +113,7 @@ struct InputJoypadUdev {
return false; return false;
} }
bool init() { auto init() -> bool {
context = udev_new(); context = udev_new();
if(context == nullptr) return false; if(context == nullptr) return false;
@ -140,19 +140,19 @@ struct InputJoypadUdev {
return true; return true;
} }
void term() { auto term() -> void {
if(enumerator) { udev_enumerate_unref(enumerator); enumerator = nullptr; } if(enumerator) { udev_enumerate_unref(enumerator); enumerator = nullptr; }
} }
private: private:
bool hotplugDevicesAvailable() { auto hotplugDevicesAvailable() -> bool {
pollfd fd = {0}; pollfd fd = {0};
fd.fd = udev_monitor_get_fd(monitor); fd.fd = udev_monitor_get_fd(monitor);
fd.events = POLLIN; fd.events = POLLIN;
return (::poll(&fd, 1, 0) == 1) && (fd.revents & POLLIN); return (::poll(&fd, 1, 0) == 1) && (fd.revents & POLLIN);
} }
void hotplugDevice() { auto hotplugDevice() -> void {
udev_device* device = udev_monitor_receive_device(monitor); udev_device* device = udev_monitor_receive_device(monitor);
if(device == nullptr) return; 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; Joypad jp;
jp.deviceNode = deviceNode; jp.deviceNode = deviceNode;
@ -254,17 +254,17 @@ private:
#undef testBit #undef testBit
} }
void createJoypadHID(Joypad& jp) { auto createJoypadHID(Joypad& jp) -> void {
uint64_t pathID = Hash::CRC32(jp.deviceName.data(), jp.deviceName.size()).value(); 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.axes.size(); n++) jp.hid->axes().append(n);
for(unsigned n = 0; n < jp.hats.size(); n++) jp.hid.hat().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.button().append({n}); for(unsigned n = 0; n < jp.buttons.size(); n++) jp.hid->buttons().append(n);
jp.hid.rumble = jp.rumble; 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++) { for(unsigned n = 0; n < joypads.size(); n++) {
if(joypads[n].deviceNode == deviceNode) { if(joypads[n].deviceNode == deviceNode) {
close(joypads[n].fd); close(joypads[n].fd);

View File

@ -23,7 +23,7 @@ struct pInputUdev {
uintptr_t handle = 0; uintptr_t handle = 0;
} settings; } settings;
bool cap(const string& name) { auto cap(const string& name) -> bool {
if(name == Input::Handle) return true; if(name == Input::Handle) return true;
if(name == Input::KeyboardSupport) return true; if(name == Input::KeyboardSupport) return true;
if(name == Input::MouseSupport) return true; if(name == Input::MouseSupport) return true;
@ -32,51 +32,51 @@ struct pInputUdev {
return false; return false;
} }
any get(const string& name) { auto get(const string& name) -> any {
if(name == Input::Handle) return (uintptr_t)settings.handle; if(name == Input::Handle) return settings.handle;
return false; return {};
} }
bool set(const string& name, const any& value) { auto set(const string& name, const any& value) -> bool {
if(name == Input::Handle) { if(name == Input::Handle && value.is<uintptr_t>()) {
settings.handle = any_cast<uintptr_t>(value); settings.handle = value.get<uintptr_t>();
return true; return true;
} }
return false; return false;
} }
bool acquire() { auto acquire() -> bool {
return xlibMouse.acquire(); return xlibMouse.acquire();
} }
bool unacquire() { auto unacquire() -> bool {
return xlibMouse.unacquire(); return xlibMouse.unacquire();
} }
bool acquired() { auto acquired() -> bool {
return xlibMouse.acquired(); return xlibMouse.acquired();
} }
vector<HID::Device*> poll() { auto poll() -> vector<shared_pointer<HID::Device>> {
vector<HID::Device*> devices; vector<shared_pointer<HID::Device>> devices;
xlibKeyboard.poll(devices); xlibKeyboard.poll(devices);
xlibMouse.poll(devices); xlibMouse.poll(devices);
udev.poll(devices); udev.poll(devices);
return devices; return devices;
} }
bool rumble(uint64_t id, bool enable) { auto rumble(uint64_t id, bool enable) -> bool {
return udev.rumble(id, enable); return udev.rumble(id, enable);
} }
bool init() { auto init() -> bool {
if(xlibKeyboard.init() == false) return false; if(xlibKeyboard.init() == false) return false;
if(xlibMouse.init(settings.handle) == false) return false; if(xlibMouse.init(settings.handle) == false) return false;
if(udev.init() == false) return false; if(udev.init() == false) return false;
return true; return true;
} }
void term() { auto term() -> void {
xlibKeyboard.term(); xlibKeyboard.term();
xlibMouse.term(); xlibMouse.term();
udev.term(); udev.term();

View File

@ -1,7 +1,7 @@
#include "opengl/opengl.hpp" #include "opengl/opengl.hpp"
namespace ruby { namespace ruby {
class pVideoCGL; struct pVideoCGL;
} }
@interface RubyVideoCGL : NSOpenGLView { @interface RubyVideoCGL : NSOpenGLView {
@ -20,11 +20,15 @@ struct pVideoCGL : OpenGL {
struct { struct {
NSView* handle = nullptr; NSView* handle = nullptr;
bool synchronize = false; bool synchronize = false;
unsigned filter = 0; unsigned filter = Video::FilterNearest;
string shader; string shader;
} settings; } settings;
bool cap(const string& name) { ~pVideoCGL() {
term();
}
auto cap(const string& name) -> bool {
if(name == Video::Handle) return true; if(name == Video::Handle) return true;
if(name == Video::Synchronize) return true; if(name == Video::Synchronize) return true;
if(name == Video::Filter) return true; if(name == Video::Filter) return true;
@ -32,22 +36,22 @@ struct pVideoCGL : OpenGL {
return false; 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::Handle) return (uintptr_t)settings.handle;
if(name == Video::Synchronize) return settings.synchronize; if(name == Video::Synchronize) return settings.synchronize;
if(name == Video::Filter) return settings.filter; if(name == Video::Filter) return settings.filter;
return false; return {};
} }
bool set(const string& name, const any& value) { auto set(const string& name, const any& value) -> bool {
if(name == Video::Handle) { if(name == Video::Handle && value.is<uintptr_t>()) {
settings.handle = (NSView*)any_cast<uintptr_t>(value); settings.handle = (NSView*)value.get<uintptr_t>();
return true; return true;
} }
if(name == Video::Synchronize) { if(name == Video::Synchronize && value.is<bool>()) {
if(settings.synchronize != any_cast<bool>(value)) { if(settings.synchronize != value.get<bool>()) {
settings.synchronize = any_cast<bool>(value); settings.synchronize = value.get<bool>();
if(view) { if(view) {
@autoreleasepool { @autoreleasepool {
@ -60,34 +64,34 @@ struct pVideoCGL : OpenGL {
return true; return true;
} }
if(name == Video::Filter) { if(name == Video::Filter && value.is<unsigned>()) {
settings.filter = any_cast<unsigned>(value); settings.filter = value.get<unsigned>();
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 true;
} }
if(name == Video::Shader) { if(name == Video::Shader && value.is<string>()) {
settings.shader = any_cast<const char*>(value); settings.shader = value.get<string>();
@autoreleasepool { @autoreleasepool {
[[view openGLContext] makeCurrentContext]; [[view openGLContext] makeCurrentContext];
} }
OpenGL::shader(settings.shader); 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 true;
} }
return false; 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); OpenGL::size(width, height);
return OpenGL::lock(data, pitch); return OpenGL::lock(data, pitch);
} }
void unlock() { auto unlock() -> void {
} }
void clear() { auto clear() -> void {
@autoreleasepool { @autoreleasepool {
[view lockFocus]; [view lockFocus];
OpenGL::clear(); OpenGL::clear();
@ -96,7 +100,7 @@ struct pVideoCGL : OpenGL {
} }
} }
void refresh() { auto refresh() -> void {
@autoreleasepool { @autoreleasepool {
if([view lockFocusIfCanDraw]) { if([view lockFocusIfCanDraw]) {
auto area = [view frame]; auto area = [view frame];
@ -108,7 +112,7 @@ struct pVideoCGL : OpenGL {
} }
} }
bool init() { auto init() -> bool {
term(); term();
@autoreleasepool { @autoreleasepool {
@ -146,7 +150,7 @@ struct pVideoCGL : OpenGL {
return true; return true;
} }
void term() { auto term() -> void {
OpenGL::term(); OpenGL::term();
@autoreleasepool { @autoreleasepool {
@ -155,10 +159,6 @@ struct pVideoCGL : OpenGL {
view = nil; view = nil;
} }
} }
~pVideoCGL() {
term();
}
}; };
DeclareVideo(CGL) DeclareVideo(CGL)

View File

@ -25,7 +25,7 @@ else ifeq ($(platform),macosx)
else ifeq ($(platform),linux) else ifeq ($(platform),linux)
ruby += video.glx video.xv video.xshm video.sdl ruby += video.glx video.xv video.xshm video.sdl
ruby += audio.alsa audio.openal audio.oss audio.pulseaudio audio.pulseaudiosimple audio.ao 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) else ifeq ($(platform),bsd)
ruby += video.glx video.xv video.xshm video.sdl ruby += video.glx video.xv video.xshm video.sdl
ruby += audio.openal audio.oss ruby += audio.openal audio.oss