mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-10-05 04:32:00 +02:00
byuu says: This WIP substantially restructures the ruby API for the first time since that project started. It is my hope that with this restructuring, destruction of the ruby objects should now be deterministic, which should fix the crashing on closing the emulator on Linux. We'll see I guess ... either way, it removed two layers of wrappers from ruby, so it's a pretty nice code cleanup. It won't compile on Windows due to a few issues I didn't see until uploading the WIP, too lazy to upload another. But I fixed all the compilation issues locally, so it'll work on Windows again with the next WIP (unless I break something else.) (Kind of annoying that Linux defines glActiveTexture but Windows doesn't.)
71 lines
1.6 KiB
C++
71 lines
1.6 KiB
C++
#if defined(Hiro_ComboButton)
|
|
|
|
auto mComboButton::allocate() -> pObject* {
|
|
return new pComboButton(*this);
|
|
}
|
|
|
|
auto mComboButton::destruct() -> void {
|
|
for(auto& item : state.items) item->destruct();
|
|
mWidget::destruct();
|
|
}
|
|
|
|
//
|
|
|
|
auto mComboButton::append(sComboButtonItem item) -> type& {
|
|
state.items.append(item);
|
|
item->setParent(this, items() - 1);
|
|
signal(append, item);
|
|
return *this;
|
|
}
|
|
|
|
auto mComboButton::doChange() const -> void {
|
|
if(state.onChange) return state.onChange();
|
|
}
|
|
|
|
auto mComboButton::item(unsigned position) const -> ComboButtonItem {
|
|
if(position < items()) return state.items[position];
|
|
return {};
|
|
}
|
|
|
|
auto mComboButton::items() const -> unsigned {
|
|
return state.items.size();
|
|
}
|
|
|
|
auto mComboButton::onChange(const function<void ()>& callback) -> type& {
|
|
state.onChange = callback;
|
|
return *this;
|
|
}
|
|
|
|
auto mComboButton::remove(sComboButtonItem item) -> type& {
|
|
signal(remove, item);
|
|
state.items.remove(item->offset());
|
|
for(auto n : range(item->offset(), items())) {
|
|
state.items[n]->adjustOffset(-1);
|
|
}
|
|
item->setParent();
|
|
return *this;
|
|
}
|
|
|
|
auto mComboButton::reset() -> type& {
|
|
signal(reset);
|
|
for(auto& item : state.items) item->setParent();
|
|
state.items.reset();
|
|
return *this;
|
|
}
|
|
|
|
auto mComboButton::selected() const -> ComboButtonItem {
|
|
for(auto& item : state.items) {
|
|
if(item->selected()) return item;
|
|
}
|
|
return {};
|
|
}
|
|
|
|
auto mComboButton::setParent(mObject* parent, signed offset) -> type& {
|
|
for(auto& item : state.items) item->destruct();
|
|
mObject::setParent(parent, offset);
|
|
for(auto& item : state.items) item->setParent(this, item->offset());
|
|
return *this;
|
|
}
|
|
|
|
#endif
|