From 017f9926fcbb37be08cf28952682c8e91908ae7d Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Sun, 27 Feb 2011 20:05:10 +1100 Subject: [PATCH] Update to v075r16 release. byuu says: This has my latest API enhancements, but there are some known issues: - resize on Windows seems to not repaint the buttons properly in rare cases. I may just need to revert to flickering resize. - GTK+ reports the wrong menu height, off by two pixels, prior to the window being realized (made visible) - this results in the main window moving up two pixels after each run of bsnes The menu height bug was actually there previously, it was just that Qt and GTK+ were computing the frame margins incorrectly (ignoring the menu bar) before. On the bright side, ui/settings/input.cpp has been improved by way of the new multi-layout support. The window is no longer forced to an awkward 640 pixels wide, as the mouse axes/buttons can overlap now. The code is also simpler since I am using the Layout::setVisible command to toggle groups on and off instead of doing it for each and every control. --- bsnes/phoenix/core/core.cpp | 49 ++++---- bsnes/phoenix/core/core.hpp | 51 ++++---- bsnes/phoenix/core/state.hpp | 59 ++++----- .../{menu-check-item.cpp => check-item.cpp} | 12 +- .../gtk/action/{menu-item.cpp => item.cpp} | 8 +- .../{menu-radio-item.cpp => radio-item.cpp} | 16 +-- .../{menu-separator.cpp => separator.cpp} | 2 +- bsnes/phoenix/gtk/gtk.cpp | 28 +++-- bsnes/phoenix/gtk/gtk.hpp | 44 +++---- bsnes/phoenix/gtk/widget/list-view.cpp | 66 ++++++---- bsnes/phoenix/gtk/window.cpp | 37 +++--- bsnes/phoenix/qt/action/action.cpp | 48 ++++---- bsnes/phoenix/qt/action/check-item.cpp | 22 ++++ bsnes/phoenix/qt/action/item.cpp | 12 ++ bsnes/phoenix/qt/action/menu-check-item.cpp | 22 ---- bsnes/phoenix/qt/action/menu-item.cpp | 12 -- bsnes/phoenix/qt/action/menu.cpp | 16 +-- .../{menu-radio-item.cpp => radio-item.cpp} | 18 +-- .../{menu-separator.cpp => separator.cpp} | 2 +- bsnes/phoenix/qt/qt.cpp | 24 ++-- bsnes/phoenix/qt/qt.moc | 86 ++++++------- bsnes/phoenix/qt/qt.moc.hpp | 45 ++++--- bsnes/phoenix/qt/widget/list-view.cpp | 38 +++--- bsnes/phoenix/qt/widget/widget.cpp | 4 - bsnes/phoenix/qt/window.cpp | 37 ++---- bsnes/phoenix/reference/action/check-item.cpp | 12 ++ bsnes/phoenix/reference/action/item.cpp | 5 + .../reference/action/menu-check-item.cpp | 12 -- bsnes/phoenix/reference/action/menu-item.cpp | 5 - .../reference/action/menu-radio-item.cpp | 15 --- .../reference/action/menu-separator.cpp | 2 - bsnes/phoenix/reference/action/radio-item.cpp | 15 +++ bsnes/phoenix/reference/action/separator.cpp | 2 + bsnes/phoenix/reference/reference.cpp | 20 +-- bsnes/phoenix/reference/reference.hpp | 44 +++---- bsnes/phoenix/reference/widget/list-view.cpp | 16 ++- bsnes/phoenix/reference/window.cpp | 11 +- bsnes/phoenix/windows/action/check-item.cpp | 14 +++ bsnes/phoenix/windows/action/item.cpp | 6 + .../windows/action/menu-check-item.cpp | 14 --- bsnes/phoenix/windows/action/menu-item.cpp | 6 - .../phoenix/windows/action/menu-separator.cpp | 2 - bsnes/phoenix/windows/action/menu.cpp | 16 +-- .../{menu-radio-item.cpp => radio-item.cpp} | 14 +-- bsnes/phoenix/windows/action/separator.cpp | 2 + bsnes/phoenix/windows/widget/combo-box.cpp | 10 +- bsnes/phoenix/windows/widget/label.cpp | 5 + bsnes/phoenix/windows/widget/list-view.cpp | 48 +++++--- bsnes/phoenix/windows/window.cpp | 46 +++---- bsnes/phoenix/windows/windows.cpp | 60 ++++----- bsnes/phoenix/windows/windows.hpp | 45 ++++--- bsnes/snes/snes.hpp | 2 +- bsnes/ui-gameboy/general/main-window.hpp | 36 +++--- bsnes/ui-gameboy/main.cpp | 4 +- bsnes/ui/debugger/console.cpp | 2 +- bsnes/ui/general/file-browser.cpp | 19 ++- bsnes/ui/general/main-window.cpp | 8 +- bsnes/ui/general/main-window.hpp | 112 ++++++++--------- bsnes/ui/main.cpp | 6 +- bsnes/ui/settings/input.cpp | 114 +++++++++--------- bsnes/ui/settings/input.hpp | 12 +- bsnes/ui/tools/cheat-editor.cpp | 44 +++---- bsnes/ui/tools/state-manager.cpp | 35 +++--- bsnes/ui/utility/utility.cpp | 17 +-- 64 files changed, 817 insertions(+), 799 deletions(-) rename bsnes/phoenix/gtk/action/{menu-check-item.cpp => check-item.cpp} (60%) rename bsnes/phoenix/gtk/action/{menu-item.cpp => item.cpp} (55%) rename bsnes/phoenix/gtk/action/{menu-radio-item.cpp => radio-item.cpp} (63%) rename bsnes/phoenix/gtk/action/{menu-separator.cpp => separator.cpp} (54%) create mode 100755 bsnes/phoenix/qt/action/check-item.cpp create mode 100755 bsnes/phoenix/qt/action/item.cpp delete mode 100755 bsnes/phoenix/qt/action/menu-check-item.cpp delete mode 100755 bsnes/phoenix/qt/action/menu-item.cpp rename bsnes/phoenix/qt/action/{menu-radio-item.cpp => radio-item.cpp} (54%) rename bsnes/phoenix/qt/action/{menu-separator.cpp => separator.cpp} (63%) create mode 100755 bsnes/phoenix/reference/action/check-item.cpp create mode 100755 bsnes/phoenix/reference/action/item.cpp delete mode 100755 bsnes/phoenix/reference/action/menu-check-item.cpp delete mode 100755 bsnes/phoenix/reference/action/menu-item.cpp delete mode 100755 bsnes/phoenix/reference/action/menu-radio-item.cpp delete mode 100755 bsnes/phoenix/reference/action/menu-separator.cpp create mode 100755 bsnes/phoenix/reference/action/radio-item.cpp create mode 100755 bsnes/phoenix/reference/action/separator.cpp create mode 100755 bsnes/phoenix/windows/action/check-item.cpp create mode 100755 bsnes/phoenix/windows/action/item.cpp delete mode 100755 bsnes/phoenix/windows/action/menu-check-item.cpp delete mode 100755 bsnes/phoenix/windows/action/menu-item.cpp delete mode 100755 bsnes/phoenix/windows/action/menu-separator.cpp rename bsnes/phoenix/windows/action/{menu-radio-item.cpp => radio-item.cpp} (58%) create mode 100755 bsnes/phoenix/windows/action/separator.cpp diff --git a/bsnes/phoenix/core/core.cpp b/bsnes/phoenix/core/core.cpp index 8e7a4108..b1f2ac68 100755 --- a/bsnes/phoenix/core/core.cpp +++ b/bsnes/phoenix/core/core.cpp @@ -15,14 +15,14 @@ Object::Object() { OS::initialize(); } -unsigned OS::desktopWidth() { return pOS::desktopWidth(); } -unsigned OS::desktopHeight() { return pOS::desktopHeight(); } +Geometry OS::availableGeometry() { return pOS::availableGeometry(); } +Geometry OS::desktopGeometry() { return pOS::desktopGeometry(); } string OS::fileLoad_(Window &parent, const string &path, const lstring &filter_) { auto filter = filter_; if(filter.size() == 0) filter.append("All files (*)"); return pOS::fileLoad(parent, path, filter); } string OS::fileSave_(Window &parent, const string &path, const lstring &filter_) { auto filter = filter_; if(filter.size() == 0) filter.append("All files (*)"); return pOS::fileSave(parent, path, filter); } string OS::folderSelect(Window &parent, const string &path) { return pOS::folderSelect(parent, path); } void OS::main() { return pOS::main(); } -bool OS::pending() { return pOS::pending(); } -void OS::process() { return pOS::process(); } +bool OS::pendingEvents() { return pOS::pendingEvents(); } +void OS::processEvents() { return pOS::processEvents(); } void OS::quit() { return pOS::quit(); } void OS::initialize() { static bool initialized = false; if(initialized == false) { initialized = true; return pOS::initialize(); } } @@ -42,11 +42,12 @@ Window Window::None; void Window::append(Layout &layout) { state.layout.append(layout); return p.append(layout); } void Window::append(Menu &menu) { state.menu.append(menu); ((Action&)menu).state.parent = this; return p.append(menu); } void Window::append(Widget &widget) { state.widget.append(widget); return p.append(widget); } -Geometry Window::frameGeometry() { return p.frameGeometry(); } +Geometry Window::frameGeometry() { Geometry geometry = p.geometry(), margin = p.frameMargin(); return { geometry.x - margin.x, geometry.y - margin.y, geometry.width + margin.width, geometry.height + margin.height }; } +Geometry Window::frameMargin() { return p.frameMargin(); } bool Window::focused() { return p.focused(); } Geometry Window::geometry() { return p.geometry(); } void Window::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { state.backgroundColor = true; state.backgroundColorRed = red; state.backgroundColorGreen = green; state.backgroundColorBlue = blue; return p.setBackgroundColor(red, green, blue); } -void Window::setFrameGeometry(const Geometry &geometry) { return p.setFrameGeometry(geometry); } +void Window::setFrameGeometry(const Geometry &geometry) { Geometry margin = p.frameMargin(); return setGeometry({ geometry.x + margin.x, geometry.y + margin.y, geometry.width - margin.width, geometry.height - margin.height }); } void Window::setFocused() { return p.setFocused(); } void Window::setFullScreen(bool fullScreen) { state.fullScreen = fullScreen; return p.setFullScreen(fullScreen); } void Window::setGeometry(const Geometry &geometry) { state.geometry = geometry; return p.setGeometry(geometry); } @@ -69,28 +70,29 @@ void Menu::append(Action &action) { state.action.append(action); return p.append void Menu::setText(const string &text) { state.text = text; return p.setText(text); } Menu::Menu() : state(*new State), base_from_member(*new pMenu(*this)), Action(base_from_member::value), p(base_from_member::value) { p.constructor(); } -MenuSeparator::MenuSeparator() : base_from_member(*new pMenuSeparator(*this)), Action(base_from_member::value), p(base_from_member::value) { p.constructor(); } +Separator::Separator() : base_from_member(*new pSeparator(*this)), Action(base_from_member::value), p(base_from_member::value) { p.constructor(); } -void MenuItem::setText(const string &text) { state.text = text; return p.setText(text); } -MenuItem::MenuItem() : state(*new State), base_from_member(*new pMenuItem(*this)), Action(base_from_member::value), p(base_from_member::value) { p.constructor(); } +void Item::setText(const string &text) { state.text = text; return p.setText(text); } +Item::Item() : state(*new State), base_from_member(*new pItem(*this)), Action(base_from_member::value), p(base_from_member::value) { p.constructor(); } -bool MenuCheckItem::checked() { return p.checked(); } -void MenuCheckItem::setChecked(bool checked) { state.checked = checked; return p.setChecked(checked); } -void MenuCheckItem::setText(const string &text) { state.text = text; return p.setText(text); } -MenuCheckItem::MenuCheckItem() : state(*new State), base_from_member(*new pMenuCheckItem(*this)), Action(base_from_member::value), p(base_from_member::value) { p.constructor(); } +bool CheckItem::checked() { return p.checked(); } +void CheckItem::setChecked(bool checked) { state.checked = checked; return p.setChecked(checked); } +void CheckItem::setText(const string &text) { state.text = text; return p.setText(text); } +CheckItem::CheckItem() : state(*new State), base_from_member(*new pCheckItem(*this)), Action(base_from_member::value), p(base_from_member::value) { p.constructor(); } -void MenuRadioItem::group_(const reference_array &list) { foreach(item, list) item.p.setGroup(item.state.group = list); if(list.size()) list[0].setChecked(); } -bool MenuRadioItem::checked() { return p.checked(); } -void MenuRadioItem::setChecked() { foreach(item, state.group) item.state.checked = false; state.checked = true; return p.setChecked(); } -void MenuRadioItem::setText(const string &text) { state.text = text; return p.setText(text); } -MenuRadioItem::MenuRadioItem() : state(*new State), base_from_member(*new pMenuRadioItem(*this)), Action(base_from_member::value), p(base_from_member::value) { p.constructor(); } +void RadioItem::group_(const reference_array &list) { foreach(item, list) item.p.setGroup(item.state.group = list); if(list.size()) list[0].setChecked(); } +bool RadioItem::checked() { return p.checked(); } +void RadioItem::setChecked() { foreach(item, state.group) item.state.checked = false; state.checked = true; return p.setChecked(); } +void RadioItem::setText(const string &text) { state.text = text; return p.setText(text); } +RadioItem::RadioItem() : state(*new State), base_from_member(*new pRadioItem(*this)), Action(base_from_member::value), p(base_from_member::value) { p.constructor(); } -bool Widget::enabled() { return p.enabled(); } +bool Widget::enabled() { return state.enabled; } void Widget::setEnabled(bool enabled) { state.enabled = enabled; return p.setEnabled(enabled); } void Widget::setFocused() { return p.setFocused(); } void Widget::setFont(Font &font) { state.font = &font; return p.setFont(font); } void Widget::setGeometry(const Geometry &geometry) { state.geometry = geometry; return p.setGeometry(geometry); } void Widget::setVisible(bool visible) { state.visible = visible; return p.setVisible(visible); } +bool Widget::visible() { return state.visible; } Widget::Widget() : state(*new State), p(*new pWidget(*this)) { state.abstract = true; p.constructor(); } Widget::Widget(pWidget &p) : state(*new State), p(p) { p.constructor(); } @@ -129,17 +131,18 @@ string LineEdit::text() { return p.text(); } LineEdit::LineEdit() : state(*new State), base_from_member(*new pLineEdit(*this)), Widget(base_from_member::value), p(base_from_member::value) { p.constructor(); } void ListView::append_(const lstring &text) { state.checked.append(false); state.text.append(text); return p.append(text); } -void ListView::autosizeColumns() { return p.autosizeColumns(); } +void ListView::autoSizeColumns() { return p.autoSizeColumns(); } bool ListView::checked(unsigned row) { return p.checked(row); } void ListView::modify_(unsigned row, const lstring &text) { state.text[row] = text; return p.modify(row, text); } -void ListView::modify(unsigned row, unsigned column, const string &text) { state.text[row][column] = text; return p.modify(row, column, text); } void ListView::reset() { state.checked.reset(); state.text.reset(); return p.reset(); } -optional ListView::selection() { return p.selection(); } +bool ListView::selected() { return p.selected(); } +unsigned ListView::selection() { return p.selection(); } void ListView::setCheckable(bool checkable) { state.checkable = checkable; return p.setCheckable(checkable); } void ListView::setChecked(unsigned row, bool checked) { state.checked[row] = checked; return p.setChecked(row, checked); } void ListView::setHeaderText_(const lstring &text) { state.headerText = text; return p.setHeaderText(text); } void ListView::setHeaderVisible(bool visible) { state.headerVisible = visible; return p.setHeaderVisible(visible); } -void ListView::setSelection(unsigned row) { state.selection = { true, row }; return p.setSelection(row); } +void ListView::setSelected(bool selected) { state.selected = selected; return p.setSelected(selected); } +void ListView::setSelection(unsigned row) { state.selected = true; state.selection = row; return p.setSelection(row); } ListView::ListView() : state(*new State), base_from_member(*new pListView(*this)), Widget(base_from_member::value), p(base_from_member::value) { p.constructor(); } void ProgressBar::setPosition(unsigned position) { state.position = position; return p.setPosition(position); } diff --git a/bsnes/phoenix/core/core.hpp b/bsnes/phoenix/core/core.hpp index 3667c6ea..d6ab585d 100755 --- a/bsnes/phoenix/core/core.hpp +++ b/bsnes/phoenix/core/core.hpp @@ -9,10 +9,10 @@ struct pFont; struct pWindow; struct pAction; struct pMenu; -struct pMenuSeparator; -struct pMenuItem; -struct pMenuCheckItem; -struct pMenuRadioItem; +struct pSeparator; +struct pItem; +struct pCheckItem; +struct pRadioItem; struct pLayout; struct pWidget; struct pButton; @@ -44,14 +44,14 @@ struct Object { }; struct OS : Object { - static unsigned desktopWidth(); - static unsigned desktopHeight(); + static Geometry availableGeometry(); + static Geometry desktopGeometry(); template static nall::string fileLoad(Window &parent, const nall::string &path, const Args&... args) { return fileLoad_(parent, path, { args... }); } template static nall::string fileSave(Window &parent, const nall::string &path, const Args&... args) { return fileSave_(parent, path, { args... }); } static nall::string folderSelect(Window &parent, const nall::string &path); static void main(); - static bool pending(); - static void process(); + static bool pendingEvents(); + static void processEvents(); static void quit(); OS(); @@ -105,6 +105,7 @@ struct Window : Object { void append(Menu &menu); void append(Widget &widget); Geometry frameGeometry(); + Geometry frameMargin(); bool focused(); Geometry geometry(); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); @@ -148,36 +149,36 @@ struct Menu : private nall::base_from_member, Action { pMenu &p; }; -struct MenuSeparator : private nall::base_from_member, Action { - MenuSeparator(); - pMenuSeparator &p; +struct Separator : private nall::base_from_member, Action { + Separator(); + pSeparator &p; }; -struct MenuItem : private nall::base_from_member, Action { +struct Item : private nall::base_from_member, Action { nall::function onTick; void setText(const nall::string &text); - MenuItem(); + Item(); struct State; State &state; - pMenuItem &p; + pItem &p; }; -struct MenuCheckItem : private nall::base_from_member, Action { +struct CheckItem : private nall::base_from_member, Action { nall::function onTick; bool checked(); void setChecked(bool checked = true); void setText(const nall::string &text); - MenuCheckItem(); + CheckItem(); struct State; State &state; - pMenuCheckItem &p; + pCheckItem &p; }; -struct MenuRadioItem : private nall::base_from_member, Action { +struct RadioItem : private nall::base_from_member, Action { template static void group(Args&... args) { group_({ args... }); } nall::function onTick; @@ -186,13 +187,13 @@ struct MenuRadioItem : private nall::base_from_member, Action { void setChecked(); void setText(const nall::string &text); - MenuRadioItem(); + RadioItem(); struct State; State &state; - pMenuRadioItem &p; + pRadioItem &p; private: - static void group_(const nall::reference_array &list); + static void group_(const nall::reference_array &list); }; struct Layout : Object { @@ -208,6 +209,7 @@ struct Widget : Object { void setFont(Font &font); void setGeometry(const Geometry &geometry); void setVisible(bool visible = true); + bool visible(); Widget(); Widget(pWidget &p); @@ -312,16 +314,17 @@ struct ListView : private nall::base_from_member, Widget { nall::function onTick; template void append(const Args&... args) { append_({ args... }); } - void autosizeColumns(); + void autoSizeColumns(); bool checked(unsigned row); template void modify(unsigned row, const Args&... args) { modify_(row, { args... }); } - void modify(unsigned row, unsigned column, const nall::string &text); void reset(); - nall::optional selection(); + bool selected(); + unsigned selection(); void setCheckable(bool checkable = true); void setChecked(unsigned row, bool checked = true); template void setHeaderText(const Args&... args) { setHeaderText_({ args... }); } void setHeaderVisible(bool visible = true); + void setSelected(bool selected = true); void setSelection(unsigned row); ListView(); diff --git a/bsnes/phoenix/core/state.hpp b/bsnes/phoenix/core/state.hpp index 0e92a6e3..a4d99bf7 100755 --- a/bsnes/phoenix/core/state.hpp +++ b/bsnes/phoenix/core/state.hpp @@ -1,6 +1,6 @@ struct Font::State { bool bold; - nall::string family; + string family; bool italic; unsigned size; bool underline; @@ -18,17 +18,17 @@ struct Window::State { unsigned backgroundColorRed, backgroundColorGreen, backgroundColorBlue; bool fullScreen; Geometry geometry; - nall::reference_array layout; - nall::reference_array menu; + reference_array layout; + reference_array menu; Font *menuFont; bool menuVisible; bool resizable; Font *statusFont; - nall::string statusText; + string statusText; bool statusVisible; - nall::string title; + string title; bool visible; - nall::reference_array widget; + reference_array widget; Font *widgetFont; State() { @@ -60,27 +60,27 @@ struct Action::State { }; struct Menu::State { - nall::reference_array action; - nall::string text; + reference_array action; + string text; }; -struct MenuItem::State { - nall::string text; +struct Item::State { + string text; }; -struct MenuCheckItem::State { +struct CheckItem::State { bool checked; - nall::string text; + string text; State() { checked = false; } }; -struct MenuRadioItem::State { +struct RadioItem::State { bool checked; - nall::reference_array group; - nall::string text; + reference_array group; + string text; State() { checked = true; @@ -104,7 +104,7 @@ struct Widget::State { }; struct Button::State { - nall::string text; + string text; State() { } @@ -112,7 +112,7 @@ struct Button::State { struct CheckBox::State { bool checked; - nall::string text; + string text; State() { checked = false; @@ -121,7 +121,7 @@ struct CheckBox::State { struct ComboBox::State { unsigned selection; - nall::linear_vector text; + linear_vector text; State() { selection = 0; @@ -153,12 +153,12 @@ struct HorizontalSlider::State { }; struct Label::State { - nall::string text; + string text; }; struct LineEdit::State { bool editable; - nall::string text; + string text; State() { editable = true; @@ -167,15 +167,18 @@ struct LineEdit::State { struct ListView::State { bool checkable; - nall::array checked; - nall::lstring headerText; + array checked; + lstring headerText; bool headerVisible; - nall::optional selection; - nall::linear_vector text; + bool selected; + unsigned selection; + linear_vector text; - State() : selection(false, 0) { + State() { checkable = false; headerVisible = false; + selected = false; + selection = 0; } }; @@ -189,8 +192,8 @@ struct ProgressBar::State { struct RadioBox::State { bool checked; - nall::reference_array group; - nall::string text; + reference_array group; + string text; State() { checked = true; @@ -200,7 +203,7 @@ struct RadioBox::State { struct TextEdit::State { unsigned cursorPosition; bool editable; - nall::string text; + string text; bool wordWrap; State() { diff --git a/bsnes/phoenix/gtk/action/menu-check-item.cpp b/bsnes/phoenix/gtk/action/check-item.cpp similarity index 60% rename from bsnes/phoenix/gtk/action/menu-check-item.cpp rename to bsnes/phoenix/gtk/action/check-item.cpp index dc5c35c2..c3278c1a 100755 --- a/bsnes/phoenix/gtk/action/menu-check-item.cpp +++ b/bsnes/phoenix/gtk/action/check-item.cpp @@ -1,22 +1,22 @@ -static void MenuCheckItem_tick(MenuCheckItem *self) { +static void CheckItem_tick(CheckItem *self) { if(self->p.locked == false && self->onTick) self->onTick(); } -bool pMenuCheckItem::checked() { +bool pCheckItem::checked() { return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); } -void pMenuCheckItem::setChecked(bool checked) { +void pCheckItem::setChecked(bool checked) { locked = true; gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), checked); locked = false; } -void pMenuCheckItem::setText(const string &text) { +void pCheckItem::setText(const string &text) { gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text); } -void pMenuCheckItem::constructor() { +void pCheckItem::constructor() { widget = gtk_check_menu_item_new_with_label(""); - g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(MenuCheckItem_tick), (gpointer)&menuCheckItem); + g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(CheckItem_tick), (gpointer)&checkItem); } diff --git a/bsnes/phoenix/gtk/action/menu-item.cpp b/bsnes/phoenix/gtk/action/item.cpp similarity index 55% rename from bsnes/phoenix/gtk/action/menu-item.cpp rename to bsnes/phoenix/gtk/action/item.cpp index b1adaf33..7afaac37 100755 --- a/bsnes/phoenix/gtk/action/menu-item.cpp +++ b/bsnes/phoenix/gtk/action/item.cpp @@ -1,12 +1,12 @@ -static void MenuItem_tick(MenuItem *self) { +static void Item_tick(Item *self) { if(self->onTick) self->onTick(); } -void pMenuItem::setText(const string &text) { +void pItem::setText(const string &text) { gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text); } -void pMenuItem::constructor() { +void pItem::constructor() { widget = gtk_menu_item_new_with_label(""); - g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(MenuItem_tick), (gpointer)&menuItem); + g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(Item_tick), (gpointer)&item); } diff --git a/bsnes/phoenix/gtk/action/menu-radio-item.cpp b/bsnes/phoenix/gtk/action/radio-item.cpp similarity index 63% rename from bsnes/phoenix/gtk/action/menu-radio-item.cpp rename to bsnes/phoenix/gtk/action/radio-item.cpp index 6ba91d55..d25262b9 100755 --- a/bsnes/phoenix/gtk/action/menu-radio-item.cpp +++ b/bsnes/phoenix/gtk/action/radio-item.cpp @@ -1,19 +1,19 @@ -static void MenuRadioItem_tick(MenuRadioItem *self) { +static void RadioItem_tick(RadioItem *self) { if(self->p.locked == false && self->checked() && self->onTick) self->onTick(); } -bool pMenuRadioItem::checked() { +bool pRadioItem::checked() { return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); } -void pMenuRadioItem::setChecked() { +void pRadioItem::setChecked() { locked = true; - foreach(item, menuRadioItem.state.group) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), false); + foreach(item, radioItem.state.group) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), false); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), true); locked = false; } -void pMenuRadioItem::setGroup(const reference_array &group) { +void pRadioItem::setGroup(const reference_array &group) { foreach(item, group, n) { if(n == 0) continue; GSList *currentGroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[0].p.widget)); @@ -23,11 +23,11 @@ void pMenuRadioItem::setGroup(const reference_array &group) { } } -void pMenuRadioItem::setText(const string &text) { +void pRadioItem::setText(const string &text) { gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text); } -void pMenuRadioItem::constructor() { +void pRadioItem::constructor() { widget = gtk_radio_menu_item_new_with_label(0, ""); - g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(MenuRadioItem_tick), (gpointer)&menuRadioItem); + g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(RadioItem_tick), (gpointer)&radioItem); } diff --git a/bsnes/phoenix/gtk/action/menu-separator.cpp b/bsnes/phoenix/gtk/action/separator.cpp similarity index 54% rename from bsnes/phoenix/gtk/action/menu-separator.cpp rename to bsnes/phoenix/gtk/action/separator.cpp index aef9a727..982ba86d 100755 --- a/bsnes/phoenix/gtk/action/menu-separator.cpp +++ b/bsnes/phoenix/gtk/action/separator.cpp @@ -1,3 +1,3 @@ -void pMenuSeparator::constructor() { +void pSeparator::constructor() { widget = gtk_separator_menu_item_new(); } diff --git a/bsnes/phoenix/gtk/gtk.cpp b/bsnes/phoenix/gtk/gtk.cpp index 37014a83..c34e733f 100755 --- a/bsnes/phoenix/gtk/gtk.cpp +++ b/bsnes/phoenix/gtk/gtk.cpp @@ -7,10 +7,10 @@ #include "action/action.cpp" #include "action/menu.cpp" -#include "action/menu-separator.cpp" -#include "action/menu-item.cpp" -#include "action/menu-check-item.cpp" -#include "action/menu-radio-item.cpp" +#include "action/separator.cpp" +#include "action/item.cpp" +#include "action/check-item.cpp" +#include "action/radio-item.cpp" #include "widget/widget.cpp" #include "widget/button.cpp" @@ -27,12 +27,18 @@ #include "widget/vertical-slider.cpp" #include "widget/viewport.cpp" -unsigned pOS::desktopWidth() { - return gdk_screen_get_width(gdk_screen_get_default()); +Geometry pOS::availableGeometry() { + //TODO: is there a GTK+ function for this? + //should return desktopGeometry() sans panels, toolbars, docks, etc. + return desktopGeometry(); } -unsigned pOS::desktopHeight() { - return gdk_screen_get_height(gdk_screen_get_default()); +Geometry pOS::desktopGeometry() { + return { + 0, 0, + gdk_screen_get_width(gdk_screen_get_default()), + gdk_screen_get_height(gdk_screen_get_default()) + }; } static string pOS_fileDialog(bool save, Window &parent, const string &path, const lstring &filter) { @@ -109,12 +115,12 @@ void pOS::main() { gtk_main(); } -bool pOS::pending() { +bool pOS::pendingEvents() { return gtk_events_pending(); } -void pOS::process() { - while(pending()) gtk_main_iteration_do(false); +void pOS::processEvents() { + while(pendingEvents()) gtk_main_iteration_do(false); } void pOS::quit() { diff --git a/bsnes/phoenix/gtk/gtk.hpp b/bsnes/phoenix/gtk/gtk.hpp index a19d3889..993869bd 100755 --- a/bsnes/phoenix/gtk/gtk.hpp +++ b/bsnes/phoenix/gtk/gtk.hpp @@ -24,14 +24,14 @@ struct pObject { }; struct pOS : public pObject { - static unsigned desktopWidth(); - static unsigned desktopHeight(); + static Geometry availableGeometry(); + static Geometry desktopGeometry(); static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileSave(Window &parent, const string &path, const lstring &filter); static string folderSelect(Window &parent, const string &path); static void main(); - static bool pending(); - static void process(); + static bool pendingEvents(); + static void processEvents(); static void quit(); static void initialize(); @@ -70,11 +70,10 @@ struct pWindow : public pObject { void append(Layout &layout); void append(Menu &menu); void append(Widget &widget); - Geometry frameGeometry(); bool focused(); + Geometry frameMargin(); Geometry geometry(); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); - void setFrameGeometry(const Geometry &geometry); void setFocused(); void setFullScreen(bool fullScreen); void setGeometry(const Geometry &geometry); @@ -117,42 +116,42 @@ struct pMenu : public pAction { void setFont(Font &font); }; -struct pMenuSeparator : public pAction { - MenuSeparator &menuSeparator; +struct pSeparator : public pAction { + Separator &separator; - pMenuSeparator(MenuSeparator &menuSeparator) : pAction(menuSeparator), menuSeparator(menuSeparator) {} + pSeparator(Separator &separator) : pAction(separator), separator(separator) {} void constructor(); }; -struct pMenuItem : public pAction { - MenuItem &menuItem; +struct pItem : public pAction { + Item &item; void setText(const string &text); - pMenuItem(MenuItem &menuItem) : pAction(menuItem), menuItem(menuItem) {} + pItem(Item &item) : pAction(item), item(item) {} void constructor(); }; -struct pMenuCheckItem : public pAction { - MenuCheckItem &menuCheckItem; +struct pCheckItem : public pAction { + CheckItem &checkItem; bool checked(); void setChecked(bool checked); void setText(const string &text); - pMenuCheckItem(MenuCheckItem &menuCheckItem) : pAction(menuCheckItem), menuCheckItem(menuCheckItem) {} + pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} void constructor(); }; -struct pMenuRadioItem : public pAction { - MenuRadioItem &menuRadioItem; +struct pRadioItem : public pAction { + RadioItem &radioItem; bool checked(); void setChecked(); - void setGroup(const reference_array &group); + void setGroup(const reference_array &group); void setText(const string &text); - pMenuRadioItem(MenuRadioItem &menuRadioItem) : pAction(menuRadioItem), menuRadioItem(menuRadioItem) {} + pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} void constructor(); }; @@ -272,16 +271,17 @@ struct pListView : public pWidget { linear_vector column; void append(const lstring &text); - void autosizeColumns(); + void autoSizeColumns(); bool checked(unsigned row); void modify(unsigned row, const lstring &text); - void modify(unsigned row, unsigned column, const string &text); void reset(); - optional selection(); + bool selected(); + unsigned selection(); void setCheckable(bool checkable); void setChecked(unsigned row, bool checked); void setHeaderText(const lstring &text); void setHeaderVisible(bool visible); + void setSelected(bool selected); void setSelection(unsigned row); pListView(ListView &listView) : pWidget(listView), listView(listView) {} diff --git a/bsnes/phoenix/gtk/widget/list-view.cpp b/bsnes/phoenix/gtk/widget/list-view.cpp index 82327a01..9a56fbdc 100755 --- a/bsnes/phoenix/gtk/widget/list-view.cpp +++ b/bsnes/phoenix/gtk/widget/list-view.cpp @@ -1,12 +1,13 @@ static void ListView_activate(ListView *self) { - signed selection = -1; if(self->onActivate) self->onActivate(); } static void ListView_change(ListView *self) { - signed selection = -1; - self->state.selection = self->selection(); - if(self->onChange) self->onChange(); + if(self->state.selected == false || self->state.selection != self->selection()) { + self->state.selected = true; + self->state.selection = self->selection(); + if(self->onChange) self->onChange(); + } } static void ListView_tick(GtkCellRendererToggle *cell, gchar *path_string, ListView *self) { @@ -21,7 +22,7 @@ void pListView::append(const lstring &text) { foreach(item, text, n) gtk_list_store_set(store, &iter, 1 + n, (const char*)item, -1); } -void pListView::autosizeColumns() { +void pListView::autoSizeColumns() { gtk_tree_view_columns_autosize(GTK_TREE_VIEW(subWidget)); } @@ -46,18 +47,9 @@ void pListView::modify(unsigned row, const lstring &text) { foreach(item, text, n) gtk_list_store_set(store, &iter, 1 + n, (const char*)item, -1); } -void pListView::modify(unsigned row, unsigned column, const string &text) { - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); - GtkTreeIter iter; - for(unsigned i = 0; i <= row; i++) { - if(i == 0) gtk_tree_model_get_iter_first(model, &iter); - else gtk_tree_model_iter_next(model, &iter); - } - gtk_list_store_set(store, &iter, 1 + column, (const char*)text, -1); -} - void pListView::reset() { - listView.state.selection = { false, 0 }; + listView.state.selected = false; + listView.state.selection = 0; gtk_list_store_clear(GTK_LIST_STORE(store)); gtk_tree_view_set_model(GTK_TREE_VIEW(subWidget), GTK_TREE_MODEL(store)); //reset gtk_scrolled_window scrollbar position to 0,0 (top-left), as ListView is now empty @@ -65,17 +57,32 @@ void pListView::reset() { gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0); } -optional pListView::selection() { +bool pListView::selected() { GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); GtkTreeIter iter; - if(gtk_tree_model_get_iter_first(model, &iter) == false) return { false, 0 }; - if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return { true, 0 }; + if(gtk_tree_model_get_iter_first(model, &iter) == false) return false; + if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return true; for(unsigned n = 1;; n++) { - if(gtk_tree_model_iter_next(model, &iter) == false) return { false, 0 }; - if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return { true, n }; + if(gtk_tree_model_iter_next(model, &iter) == false) return false; + if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return true; } - return { false, 0 }; + return false; +} + +unsigned pListView::selection() { + if(selected() == false) return listView.state.selection; + + GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); + GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); + GtkTreeIter iter; + if(gtk_tree_model_get_iter_first(model, &iter) == false) return 0; + if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return 0; + for(unsigned n = 1;; n++) { + if(gtk_tree_model_iter_next(model, &iter) == false) return 0; + if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return n; + } + return 0; } void pListView::setCheckable(bool checkable) { @@ -99,9 +106,18 @@ void pListView::setHeaderVisible(bool visible) { gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(subWidget), visible); } +void pListView::setSelected(bool selected) { + if(selected == false) { + GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); + gtk_tree_selection_unselect_all(selection); + } else { + setSelection(listView.state.selection); + } +} + void pListView::setSelection(unsigned row) { signed current = -1; - if(auto position = selection()) current = position(); + if(selected()) current = selection(); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); gtk_tree_selection_unselect_all(selection); @@ -177,8 +193,8 @@ void pListView::create() { setCheckable(listView.state.checkable); foreach(text, listView.state.text) append(text); foreach(checked, listView.state.checked, n) setChecked(n, checked); - if(auto selection = listView.state.selection) setSelection(selection()); - autosizeColumns(); + if(listView.state.selected) setSelection(listView.state.selection); + autoSizeColumns(); gtk_widget_show(subWidget); } diff --git a/bsnes/phoenix/gtk/window.cpp b/bsnes/phoenix/gtk/window.cpp index 677a854c..0b3d002c 100755 --- a/bsnes/phoenix/gtk/window.cpp +++ b/bsnes/phoenix/gtk/window.cpp @@ -65,13 +65,15 @@ void pWindow::append(Widget &widget) { widget.setVisible(); } -Geometry pWindow::frameGeometry() { - if(window.state.fullScreen == true) return { 0, 0, OS::desktopWidth(), OS::desktopHeight() }; +Geometry pWindow::frameMargin() { + unsigned menuHeight = window.state.menuVisible ? menu->allocation.height : 0; + unsigned statusHeight = window.state.statusVisible ? status->allocation.height : 0; + if(window.state.fullScreen) return { 0, menuHeight, 0, menuHeight + statusHeight }; return { - window.state.geometry.x - settings.frameGeometryX, - window.state.geometry.y - settings.frameGeometryY, - window.state.geometry.width + settings.frameGeometryWidth, - window.state.geometry.height + settings.frameGeometryHeight + settings.frameGeometryX, + settings.frameGeometryY + menuHeight, + settings.frameGeometryWidth, + settings.frameGeometryHeight + menuHeight + statusHeight }; } @@ -81,11 +83,10 @@ bool pWindow::focused() { Geometry pWindow::geometry() { if(window.state.fullScreen == true) { - unsigned menuHeight = 0, statusHeight = 0; - if(window.state.menuVisible) menuHeight = menu->allocation.height; - if(window.state.statusVisible) statusHeight = menu->allocation.height; - return { 0, menuHeight, OS::desktopWidth(), OS::desktopHeight() - menuHeight - statusHeight }; - } + unsigned menuHeight = window.state.menuVisible ? menu->allocation.height : 0; + unsigned statusHeight = window.state.statusVisible ? status->allocation.height : 0; + return { 0, menuHeight, OS::desktopGeometry().width, OS::desktopGeometry().height - menuHeight - statusHeight }; + }; return window.state.geometry; } @@ -98,13 +99,6 @@ void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color); } -void pWindow::setFrameGeometry(const Geometry &geometry) { - window.setGeometry({ - geometry.x + settings.frameGeometryX, geometry.y + settings.frameGeometryY, - geometry.width - settings.frameGeometryWidth, geometry.height - settings.frameGeometryHeight - }); -} - void pWindow::setFocused() { gtk_window_present(GTK_WINDOW(widget)); } @@ -118,20 +112,21 @@ void pWindow::setFullScreen(bool fullScreen) { for(unsigned n = 0; n < 4; n++) { setGeometry(window.state.geometry); gtk_widget_set_size_request(widget, -1, -1); - OS::process(); + OS::processEvents(); usleep(2000); } locked = false; } else { gtk_window_fullscreen(GTK_WINDOW(widget)); gtk_window_set_decorated(GTK_WINDOW(widget), false); - gtk_widget_set_size_request(widget, OS::desktopWidth(), OS::desktopHeight()); + gtk_widget_set_size_request(widget, OS::desktopGeometry().width, OS::desktopGeometry().height); gtk_window_set_resizable(GTK_WINDOW(widget), false); } } void pWindow::setGeometry(const Geometry &geometry) { - gtk_window_move(GTK_WINDOW(widget), geometry.x - settings.frameGeometryX, geometry.y - settings.frameGeometryY); + Geometry margin = frameMargin(); + gtk_window_move(GTK_WINDOW(widget), geometry.x - margin.x, geometry.y - margin.y); gtk_window_resize(GTK_WINDOW(widget), 1, 1); gtk_widget_set_size_request(formContainer, geometry.width, geometry.height); foreach(layout, window.state.layout) { diff --git a/bsnes/phoenix/qt/action/action.cpp b/bsnes/phoenix/qt/action/action.cpp index f262edc4..c2cbe42b 100755 --- a/bsnes/phoenix/qt/action/action.cpp +++ b/bsnes/phoenix/qt/action/action.cpp @@ -1,42 +1,42 @@ void pAction::setEnabled(bool enabled) { if(dynamic_cast(&action)) { ((Menu&)action).p.qtMenu->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((MenuSeparator&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((MenuItem&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((MenuCheckItem&)action).p.qtAction->setEnabled(enabled); - } else if(dynamic_cast(&action)) { - ((MenuRadioItem&)action).p.qtAction->setEnabled(enabled); + } else if(dynamic_cast(&action)) { + ((Separator&)action).p.qtAction->setEnabled(enabled); + } else if(dynamic_cast(&action)) { + ((Item&)action).p.qtAction->setEnabled(enabled); + } else if(dynamic_cast(&action)) { + ((CheckItem&)action).p.qtAction->setEnabled(enabled); + } else if(dynamic_cast(&action)) { + ((RadioItem&)action).p.qtAction->setEnabled(enabled); } } void pAction::setFont(Font &font) { if(dynamic_cast(&action)) { ((Menu&)action).p.setFont(font); - } else if(dynamic_cast(&action)) { - ((MenuSeparator&)action).p.qtAction->setFont(*font.p.qtFont); - } else if(dynamic_cast(&action)) { - ((MenuItem&)action).p.qtAction->setFont(*font.p.qtFont); - } else if(dynamic_cast(&action)) { - ((MenuCheckItem&)action).p.qtAction->setFont(*font.p.qtFont); - } else if(dynamic_cast(&action)) { - ((MenuRadioItem&)action).p.qtAction->setFont(*font.p.qtFont); + } else if(dynamic_cast(&action)) { + ((Separator&)action).p.qtAction->setFont(*font.p.qtFont); + } else if(dynamic_cast(&action)) { + ((Item&)action).p.qtAction->setFont(*font.p.qtFont); + } else if(dynamic_cast(&action)) { + ((CheckItem&)action).p.qtAction->setFont(*font.p.qtFont); + } else if(dynamic_cast(&action)) { + ((RadioItem&)action).p.qtAction->setFont(*font.p.qtFont); } } void pAction::setVisible(bool visible) { if(dynamic_cast(&action)) { ((Menu&)action).p.qtMenu->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((MenuSeparator&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((MenuItem&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((MenuCheckItem&)action).p.qtAction->setVisible(visible); - } else if(dynamic_cast(&action)) { - ((MenuRadioItem&)action).p.qtAction->setVisible(visible); + } else if(dynamic_cast(&action)) { + ((Separator&)action).p.qtAction->setVisible(visible); + } else if(dynamic_cast(&action)) { + ((Item&)action).p.qtAction->setVisible(visible); + } else if(dynamic_cast(&action)) { + ((CheckItem&)action).p.qtAction->setVisible(visible); + } else if(dynamic_cast(&action)) { + ((RadioItem&)action).p.qtAction->setVisible(visible); } } diff --git a/bsnes/phoenix/qt/action/check-item.cpp b/bsnes/phoenix/qt/action/check-item.cpp new file mode 100755 index 00000000..19c91f2e --- /dev/null +++ b/bsnes/phoenix/qt/action/check-item.cpp @@ -0,0 +1,22 @@ +bool pCheckItem::checked() { + return qtAction->isChecked(); +} + +void pCheckItem::setChecked(bool checked) { + qtAction->setChecked(checked); +} + +void pCheckItem::setText(const string &text) { + qtAction->setText(QString::fromUtf8(text)); +} + +void pCheckItem::constructor() { + qtAction = new QAction(0); + qtAction->setCheckable(true); + connect(qtAction, SIGNAL(triggered()), SLOT(onTick())); +} + +void pCheckItem::onTick() { + checkItem.state.checked = checked(); + if(checkItem.onTick) checkItem.onTick(); +} diff --git a/bsnes/phoenix/qt/action/item.cpp b/bsnes/phoenix/qt/action/item.cpp new file mode 100755 index 00000000..3b284d7c --- /dev/null +++ b/bsnes/phoenix/qt/action/item.cpp @@ -0,0 +1,12 @@ +void pItem::setText(const string &text) { + qtAction->setText(QString::fromUtf8(text)); +} + +void pItem::constructor() { + qtAction = new QAction(0); + connect(qtAction, SIGNAL(triggered()), SLOT(onTick())); +} + +void pItem::onTick() { + if(item.onTick) item.onTick(); +} diff --git a/bsnes/phoenix/qt/action/menu-check-item.cpp b/bsnes/phoenix/qt/action/menu-check-item.cpp deleted file mode 100755 index e3ae66ad..00000000 --- a/bsnes/phoenix/qt/action/menu-check-item.cpp +++ /dev/null @@ -1,22 +0,0 @@ -bool pMenuCheckItem::checked() { - return qtAction->isChecked(); -} - -void pMenuCheckItem::setChecked(bool checked) { - qtAction->setChecked(checked); -} - -void pMenuCheckItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pMenuCheckItem::constructor() { - qtAction = new QAction(0); - qtAction->setCheckable(true); - connect(qtAction, SIGNAL(triggered()), SLOT(onTick())); -} - -void pMenuCheckItem::onTick() { - menuCheckItem.state.checked = checked(); - if(menuCheckItem.onTick) menuCheckItem.onTick(); -} diff --git a/bsnes/phoenix/qt/action/menu-item.cpp b/bsnes/phoenix/qt/action/menu-item.cpp deleted file mode 100755 index d83baf25..00000000 --- a/bsnes/phoenix/qt/action/menu-item.cpp +++ /dev/null @@ -1,12 +0,0 @@ -void pMenuItem::setText(const string &text) { - qtAction->setText(QString::fromUtf8(text)); -} - -void pMenuItem::constructor() { - qtAction = new QAction(0); - connect(qtAction, SIGNAL(triggered()), SLOT(onTick())); -} - -void pMenuItem::onTick() { - if(menuItem.onTick) menuItem.onTick(); -} diff --git a/bsnes/phoenix/qt/action/menu.cpp b/bsnes/phoenix/qt/action/menu.cpp index 7f6be49c..913fe509 100755 --- a/bsnes/phoenix/qt/action/menu.cpp +++ b/bsnes/phoenix/qt/action/menu.cpp @@ -1,14 +1,14 @@ void pMenu::append(Action &action) { if(dynamic_cast(&action)) { qtMenu->addMenu(((Menu&)action).p.qtMenu); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((MenuSeparator&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((MenuItem&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((MenuCheckItem&)action).p.qtAction); - } else if(dynamic_cast(&action)) { - qtMenu->addAction(((MenuRadioItem&)action).p.qtAction); + } else if(dynamic_cast(&action)) { + qtMenu->addAction(((Separator&)action).p.qtAction); + } else if(dynamic_cast(&action)) { + qtMenu->addAction(((Item&)action).p.qtAction); + } else if(dynamic_cast(&action)) { + qtMenu->addAction(((CheckItem&)action).p.qtAction); + } else if(dynamic_cast(&action)) { + qtMenu->addAction(((RadioItem&)action).p.qtAction); } } diff --git a/bsnes/phoenix/qt/action/menu-radio-item.cpp b/bsnes/phoenix/qt/action/radio-item.cpp similarity index 54% rename from bsnes/phoenix/qt/action/menu-radio-item.cpp rename to bsnes/phoenix/qt/action/radio-item.cpp index 3974a2fd..cdea2d02 100755 --- a/bsnes/phoenix/qt/action/menu-radio-item.cpp +++ b/bsnes/phoenix/qt/action/radio-item.cpp @@ -1,10 +1,10 @@ -bool pMenuRadioItem::checked() { +bool pRadioItem::checked() { return qtAction->isChecked(); } -void pMenuRadioItem::setChecked() { +void pRadioItem::setChecked() { locked = true; - foreach(item, menuRadioItem.state.group) { + foreach(item, radioItem.state.group) { bool checkState = item.p.qtAction == qtAction; item.state.checked = checkState; item.p.qtAction->setChecked(checkState); @@ -12,14 +12,14 @@ void pMenuRadioItem::setChecked() { locked = false; } -void pMenuRadioItem::setGroup(const reference_array &group) { +void pRadioItem::setGroup(const reference_array &group) { } -void pMenuRadioItem::setText(const string &text) { +void pRadioItem::setText(const string &text) { qtAction->setText(QString::fromUtf8(text)); } -void pMenuRadioItem::constructor() { +void pRadioItem::constructor() { qtAction = new QAction(0); qtGroup = new QActionGroup(0); qtAction->setCheckable(true); @@ -28,9 +28,9 @@ void pMenuRadioItem::constructor() { connect(qtAction, SIGNAL(triggered()), SLOT(onTick())); } -void pMenuRadioItem::onTick() { - if(menuRadioItem.state.checked == false) { +void pRadioItem::onTick() { + if(radioItem.state.checked == false) { setChecked(); - if(locked == false && menuRadioItem.onTick) menuRadioItem.onTick(); + if(locked == false && radioItem.onTick) radioItem.onTick(); } } diff --git a/bsnes/phoenix/qt/action/menu-separator.cpp b/bsnes/phoenix/qt/action/separator.cpp similarity index 63% rename from bsnes/phoenix/qt/action/menu-separator.cpp rename to bsnes/phoenix/qt/action/separator.cpp index 55f79e2b..50253c12 100755 --- a/bsnes/phoenix/qt/action/menu-separator.cpp +++ b/bsnes/phoenix/qt/action/separator.cpp @@ -1,4 +1,4 @@ -void pMenuSeparator::constructor() { +void pSeparator::constructor() { qtAction = new QAction(0); qtAction->setSeparator(true); } diff --git a/bsnes/phoenix/qt/qt.cpp b/bsnes/phoenix/qt/qt.cpp index a4e80f8e..b10df857 100755 --- a/bsnes/phoenix/qt/qt.cpp +++ b/bsnes/phoenix/qt/qt.cpp @@ -8,10 +8,10 @@ #include "action/action.cpp" #include "action/menu.cpp" -#include "action/menu-separator.cpp" -#include "action/menu-item.cpp" -#include "action/menu-check-item.cpp" -#include "action/menu-radio-item.cpp" +#include "action/separator.cpp" +#include "action/item.cpp" +#include "action/check-item.cpp" +#include "action/radio-item.cpp" #include "widget/widget.cpp" #include "widget/button.cpp" @@ -30,12 +30,14 @@ QApplication *pOS::application = 0; -unsigned pOS::desktopWidth() { - return QApplication::desktop()->screenGeometry().width(); +Geometry pOS::availableGeometry() { + QRect rect = QApplication::desktop()->availableGeometry(); + return { rect.x(), rect.y(), rect.width(), rect.height() }; } -unsigned pOS::desktopHeight() { - return QApplication::desktop()->screenGeometry().height(); +Geometry pOS::desktopGeometry() { + QRect rect = QApplication::desktop()->screenGeometry(); + return { 0, 0, rect.width(), rect.height() }; } string pOS::fileLoad(Window &parent, const string &path, const lstring &filter) { @@ -100,12 +102,12 @@ void pOS::main() { QApplication::exec(); } -bool pOS::pending() { +bool pOS::pendingEvents() { return QApplication::hasPendingEvents(); } -void pOS::process() { - while(pending()) QApplication::processEvents(); +void pOS::processEvents() { + while(pendingEvents()) QApplication::processEvents(); } void pOS::quit() { diff --git a/bsnes/phoenix/qt/qt.moc b/bsnes/phoenix/qt/qt.moc index 2ddb8e4f..8e1a40fe 100755 --- a/bsnes/phoenix/qt/qt.moc +++ b/bsnes/phoenix/qt/qt.moc @@ -1,7 +1,7 @@ /**************************************************************************** ** Meta object code from reading C++ file 'qt.moc.hpp' ** -** Created: Tue Feb 22 04:37:04 2011 +** Created: Thu Feb 24 07:36:07 2011 ** by: The Qt Meta Object Compiler version 62 (Qt 4.6.2) ** ** WARNING! All changes made in this file will be lost! @@ -67,7 +67,7 @@ int pWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) return _id; return _id; } -static const uint qt_meta_data_pMenuItem[] = { +static const uint qt_meta_data_pItem[] = { // content: 4, // revision @@ -81,40 +81,40 @@ static const uint qt_meta_data_pMenuItem[] = { 0, // signalCount // slots: signature, parameters, type, tag, flags - 11, 10, 10, 10, 0x0a, + 7, 6, 6, 6, 0x0a, 0 // eod }; -static const char qt_meta_stringdata_pMenuItem[] = { - "pMenuItem\0\0onTick()\0" +static const char qt_meta_stringdata_pItem[] = { + "pItem\0\0onTick()\0" }; -const QMetaObject pMenuItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pMenuItem, - qt_meta_data_pMenuItem, 0 } +const QMetaObject pItem::staticMetaObject = { + { &QObject::staticMetaObject, qt_meta_stringdata_pItem, + qt_meta_data_pItem, 0 } }; #ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pMenuItem::getStaticMetaObject() { return staticMetaObject; } +const QMetaObject &pItem::getStaticMetaObject() { return staticMetaObject; } #endif //Q_NO_DATA_RELOCATION -const QMetaObject *pMenuItem::metaObject() const +const QMetaObject *pItem::metaObject() const { return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; } -void *pMenuItem::qt_metacast(const char *_clname) +void *pItem::qt_metacast(const char *_clname) { if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pMenuItem)) - return static_cast(const_cast< pMenuItem*>(this)); + if (!strcmp(_clname, qt_meta_stringdata_pItem)) + return static_cast(const_cast< pItem*>(this)); if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pMenuItem*>(this)); + return static_cast< pAction*>(const_cast< pItem*>(this)); return QObject::qt_metacast(_clname); } -int pMenuItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +int pItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) @@ -128,7 +128,7 @@ int pMenuItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) } return _id; } -static const uint qt_meta_data_pMenuCheckItem[] = { +static const uint qt_meta_data_pCheckItem[] = { // content: 4, // revision @@ -142,40 +142,40 @@ static const uint qt_meta_data_pMenuCheckItem[] = { 0, // signalCount // slots: signature, parameters, type, tag, flags - 16, 15, 15, 15, 0x0a, + 12, 11, 11, 11, 0x0a, 0 // eod }; -static const char qt_meta_stringdata_pMenuCheckItem[] = { - "pMenuCheckItem\0\0onTick()\0" +static const char qt_meta_stringdata_pCheckItem[] = { + "pCheckItem\0\0onTick()\0" }; -const QMetaObject pMenuCheckItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pMenuCheckItem, - qt_meta_data_pMenuCheckItem, 0 } +const QMetaObject pCheckItem::staticMetaObject = { + { &QObject::staticMetaObject, qt_meta_stringdata_pCheckItem, + qt_meta_data_pCheckItem, 0 } }; #ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pMenuCheckItem::getStaticMetaObject() { return staticMetaObject; } +const QMetaObject &pCheckItem::getStaticMetaObject() { return staticMetaObject; } #endif //Q_NO_DATA_RELOCATION -const QMetaObject *pMenuCheckItem::metaObject() const +const QMetaObject *pCheckItem::metaObject() const { return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; } -void *pMenuCheckItem::qt_metacast(const char *_clname) +void *pCheckItem::qt_metacast(const char *_clname) { if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pMenuCheckItem)) - return static_cast(const_cast< pMenuCheckItem*>(this)); + if (!strcmp(_clname, qt_meta_stringdata_pCheckItem)) + return static_cast(const_cast< pCheckItem*>(this)); if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pMenuCheckItem*>(this)); + return static_cast< pAction*>(const_cast< pCheckItem*>(this)); return QObject::qt_metacast(_clname); } -int pMenuCheckItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +int pCheckItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) @@ -189,7 +189,7 @@ int pMenuCheckItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) } return _id; } -static const uint qt_meta_data_pMenuRadioItem[] = { +static const uint qt_meta_data_pRadioItem[] = { // content: 4, // revision @@ -203,40 +203,40 @@ static const uint qt_meta_data_pMenuRadioItem[] = { 0, // signalCount // slots: signature, parameters, type, tag, flags - 16, 15, 15, 15, 0x0a, + 12, 11, 11, 11, 0x0a, 0 // eod }; -static const char qt_meta_stringdata_pMenuRadioItem[] = { - "pMenuRadioItem\0\0onTick()\0" +static const char qt_meta_stringdata_pRadioItem[] = { + "pRadioItem\0\0onTick()\0" }; -const QMetaObject pMenuRadioItem::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_pMenuRadioItem, - qt_meta_data_pMenuRadioItem, 0 } +const QMetaObject pRadioItem::staticMetaObject = { + { &QObject::staticMetaObject, qt_meta_stringdata_pRadioItem, + qt_meta_data_pRadioItem, 0 } }; #ifdef Q_NO_DATA_RELOCATION -const QMetaObject &pMenuRadioItem::getStaticMetaObject() { return staticMetaObject; } +const QMetaObject &pRadioItem::getStaticMetaObject() { return staticMetaObject; } #endif //Q_NO_DATA_RELOCATION -const QMetaObject *pMenuRadioItem::metaObject() const +const QMetaObject *pRadioItem::metaObject() const { return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; } -void *pMenuRadioItem::qt_metacast(const char *_clname) +void *pRadioItem::qt_metacast(const char *_clname) { if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_pMenuRadioItem)) - return static_cast(const_cast< pMenuRadioItem*>(this)); + if (!strcmp(_clname, qt_meta_stringdata_pRadioItem)) + return static_cast(const_cast< pRadioItem*>(this)); if (!strcmp(_clname, "pAction")) - return static_cast< pAction*>(const_cast< pMenuRadioItem*>(this)); + return static_cast< pAction*>(const_cast< pRadioItem*>(this)); return QObject::qt_metacast(_clname); } -int pMenuRadioItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +int pRadioItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) diff --git a/bsnes/phoenix/qt/qt.moc.hpp b/bsnes/phoenix/qt/qt.moc.hpp index 58615140..10f170cc 100755 --- a/bsnes/phoenix/qt/qt.moc.hpp +++ b/bsnes/phoenix/qt/qt.moc.hpp @@ -26,14 +26,14 @@ struct pObject { struct pOS : public pObject { static QApplication *application; - static unsigned desktopWidth(); - static unsigned desktopHeight(); + static Geometry availableGeometry(); + static Geometry desktopGeometry(); static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileSave(Window &parent, const string &path, const lstring &filter); static string folderSelect(Window &parent, const string &path); static void main(); - static bool pending(); - static void process(); + static bool pendingEvents(); + static void processEvents(); static void quit(); static void initialize(); @@ -82,11 +82,10 @@ public: void append(Layout &layout); void append(Menu &menu); void append(Widget &widget); - Geometry frameGeometry(); + Geometry frameMargin(); bool focused(); Geometry geometry(); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); - void setFrameGeometry(const Geometry &geometry); void setFocused(); void setFullScreen(bool fullScreen); void setGeometry(const Geometry &geometry); @@ -128,62 +127,62 @@ struct pMenu : public pAction { void constructor(); }; -struct pMenuSeparator : public pAction { - MenuSeparator &menuSeparator; +struct pSeparator : public pAction { + Separator &separator; QAction *qtAction; - pMenuSeparator(MenuSeparator &menuSeparator) : pAction(menuSeparator), menuSeparator(menuSeparator) {} + pSeparator(Separator &separator) : pAction(separator), separator(separator) {} void constructor(); }; -struct pMenuItem : public QObject, public pAction { +struct pItem : public QObject, public pAction { Q_OBJECT public: - MenuItem &menuItem; + Item &item; QAction *qtAction; void setText(const string &text); - pMenuItem(MenuItem &menuItem) : pAction(menuItem), menuItem(menuItem) {} + pItem(Item &item) : pAction(item), item(item) {} void constructor(); public slots: void onTick(); }; -struct pMenuCheckItem : public QObject, public pAction { +struct pCheckItem : public QObject, public pAction { Q_OBJECT public: - MenuCheckItem &menuCheckItem; + CheckItem &checkItem; QAction *qtAction; bool checked(); void setChecked(bool checked); void setText(const string &text); - pMenuCheckItem(MenuCheckItem &menuCheckItem) : pAction(menuCheckItem), menuCheckItem(menuCheckItem) {} + pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} void constructor(); public slots: void onTick(); }; -struct pMenuRadioItem : public QObject, public pAction { +struct pRadioItem : public QObject, public pAction { Q_OBJECT public: - MenuRadioItem &menuRadioItem; + RadioItem &radioItem; QAction *qtAction; QActionGroup *qtGroup; bool checked(); void setChecked(); - void setGroup(const reference_array &group); + void setGroup(const reference_array &group); void setText(const string &text); - pMenuRadioItem(MenuRadioItem &menuRadioItem) : pAction(menuRadioItem), menuRadioItem(menuRadioItem) {} + pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} void constructor(); public slots: @@ -194,7 +193,6 @@ struct pWidget : public pObject { Widget &widget; QWidget *qtWidget; - bool enabled(); void setEnabled(bool enabled); void setFocused(); void setFont(Font &font); @@ -341,16 +339,17 @@ public: QTreeWidget *qtListView; void append(const lstring &text); - void autosizeColumns(); + void autoSizeColumns(); bool checked(unsigned row); void modify(unsigned row, const lstring &text); - void modify(unsigned row, unsigned column, const string &text); void reset(); - optional selection(); + bool selected(); + unsigned selection(); void setCheckable(bool checkable); void setChecked(unsigned row, bool checked); void setHeaderText(const lstring &text); void setHeaderVisible(bool visible); + void setSelected(bool selected); void setSelection(unsigned row); pListView(ListView &listView) : pWidget(listView), listView(listView) {} diff --git a/bsnes/phoenix/qt/widget/list-view.cpp b/bsnes/phoenix/qt/widget/list-view.cpp index 8d5710d2..fb295d5c 100755 --- a/bsnes/phoenix/qt/widget/list-view.cpp +++ b/bsnes/phoenix/qt/widget/list-view.cpp @@ -10,7 +10,7 @@ void pListView::append(const lstring &text) { locked = false; } -void pListView::autosizeColumns() { +void pListView::autoSizeColumns() { for(unsigned n = 0; n < listView.state.headerText.size(); n++) qtListView->resizeColumnToContents(n); } @@ -29,23 +29,19 @@ void pListView::modify(unsigned row, const lstring &text) { locked = false; } -void pListView::modify(unsigned row, unsigned column, const string &text) { - locked = true; - QTreeWidgetItem *item = qtListView->topLevelItem(row); - if(!item) return; - item->setText(column, QString::fromUtf8(text)); - locked = false; -} - void pListView::reset() { qtListView->clear(); } -optional pListView::selection() { +bool pListView::selected() { QTreeWidgetItem *item = qtListView->currentItem(); - if(item == 0) return { false, 0 }; - if(item->isSelected() == false) return { false, 0 }; - return { true, item->data(0, Qt::UserRole).toUInt() }; + return (item && item->isSelected() == true); +} + +unsigned pListView::selection() { + QTreeWidgetItem *item = qtListView->currentItem(); + if(item == 0) return 0; + return item->data(0, Qt::UserRole).toUInt(); } void pListView::setCheckable(bool checkable) { @@ -69,12 +65,17 @@ void pListView::setHeaderText(const lstring &text) { qtListView->setColumnCount(text.size()); qtListView->setAlternatingRowColors(text.size() >= 2); qtListView->setHeaderLabels(labels); - autosizeColumns(); + autoSizeColumns(); } void pListView::setHeaderVisible(bool visible) { qtListView->setHeaderHidden(!visible); - autosizeColumns(); + autoSizeColumns(); +} + +void pListView::setSelected(bool selected) { + QTreeWidgetItem *item = qtListView->currentItem(); + if(item) item->setSelected(selected); } void pListView::setSelection(unsigned row) { @@ -108,11 +109,8 @@ void pListView::onActivate() { } void pListView::onChange() { - if(auto position = selection()) { - listView.state.selection = { true, position() }; - } else { - listView.state.selection = { false, 0 }; - } + listView.state.selected = selected(); + if(listView.state.selected) listView.state.selection = selection(); if(locked == false && listView.onChange) listView.onChange(); } diff --git a/bsnes/phoenix/qt/widget/widget.cpp b/bsnes/phoenix/qt/widget/widget.cpp index f7f67ddd..99f21526 100755 --- a/bsnes/phoenix/qt/widget/widget.cpp +++ b/bsnes/phoenix/qt/widget/widget.cpp @@ -1,7 +1,3 @@ -bool pWidget::enabled() { - return qtWidget->isEnabled(); -} - void pWidget::setEnabled(bool enabled) { qtWidget->setEnabled(enabled); } diff --git a/bsnes/phoenix/qt/window.cpp b/bsnes/phoenix/qt/window.cpp index 5dd69bba..a11eb58b 100755 --- a/bsnes/phoenix/qt/window.cpp +++ b/bsnes/phoenix/qt/window.cpp @@ -18,13 +18,15 @@ void pWindow::append(Widget &widget) { widget.setVisible(widget.state.visible); } -Geometry pWindow::frameGeometry() { - if(window.state.fullScreen) return { 0, 0, OS::desktopWidth(), OS::desktopHeight() }; +Geometry pWindow::frameMargin() { + unsigned menuHeight = window.state.menuVisible ? qtMenu->height() : 0; + unsigned statusHeight = window.state.statusVisible ? qtStatus->height() : 0; + if(window.state.fullScreen) return { 0, menuHeight, 0, menuHeight + statusHeight }; return { - window.state.geometry.x - settings.frameGeometryX, - window.state.geometry.y - settings.frameGeometryY, - window.state.geometry.width + settings.frameGeometryWidth, - window.state.geometry.height + settings.frameGeometryHeight + settings.frameGeometryX, + settings.frameGeometryY + menuHeight, + settings.frameGeometryWidth, + settings.frameGeometryHeight + menuHeight + statusHeight }; } @@ -36,8 +38,7 @@ Geometry pWindow::geometry() { if(window.state.fullScreen) { unsigned menuHeight = window.state.menuVisible ? qtMenu->height() : 0; unsigned statusHeight = window.state.statusVisible ? qtStatus->height() : 0; - unsigned width = OS::desktopWidth(), height = OS::desktopHeight(); - return { 0, menuHeight, width, height - menuHeight - statusHeight }; + return { 0, menuHeight, OS::desktopGeometry().width, OS::desktopGeometry().height - menuHeight - statusHeight }; } return window.state.geometry; } @@ -49,18 +50,6 @@ void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { qtContainer->setAutoFillBackground(true); } -void pWindow::setFrameGeometry(const Geometry &geometry) { - window.state.geometry = { - geometry.x + settings.frameGeometryX, - geometry.y + settings.frameGeometryY, - geometry.width - settings.frameGeometryWidth, - geometry.height - settings.frameGeometryHeight - }; - if(window.state.menuVisible) window.state.geometry.height -= qtMenu->height(); - if(window.state.statusVisible) window.state.geometry.height -= qtStatus->height(); - setGeometry(window.state.geometry); -} - void pWindow::setFocused() { qtWindow->raise(); qtWindow->activateWindow(); @@ -72,19 +61,19 @@ void pWindow::setFullScreen(bool fullScreen) { qtWindow->showNormal(); qtWindow->adjustSize(); } else { + Geometry geometry = OS::desktopGeometry(), margin = frameMargin(); qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint); - qtContainer->setFixedSize(OS::desktopWidth(), OS::desktopHeight()); + qtContainer->setFixedSize(geometry.width - margin.width, geometry.height - margin.height); qtWindow->showFullScreen(); - if(window.state.statusVisible) setStatusVisible(true); //work around for Qt/Xlib bug } } void pWindow::setGeometry(const Geometry &geometry_) { locked = true; - Geometry geometry = geometry_; + Geometry geometry = geometry_, margin = frameMargin(); setResizable(window.state.resizable); - qtWindow->move(geometry.x - settings.frameGeometryX, geometry.y - settings.frameGeometryY); + qtWindow->move(geometry.x - margin.x, geometry.y - margin.y); qtWindow->adjustSize(); foreach(layout, window.state.layout) { diff --git a/bsnes/phoenix/reference/action/check-item.cpp b/bsnes/phoenix/reference/action/check-item.cpp new file mode 100755 index 00000000..0d15c065 --- /dev/null +++ b/bsnes/phoenix/reference/action/check-item.cpp @@ -0,0 +1,12 @@ +bool pCheckItem::checked() { + return false; +} + +void pCheckItem::setChecked(bool checked) { +} + +void pCheckItem::setText(const string &text) { +} + +void pCheckItem::constructor() { +} diff --git a/bsnes/phoenix/reference/action/item.cpp b/bsnes/phoenix/reference/action/item.cpp new file mode 100755 index 00000000..7e0062e8 --- /dev/null +++ b/bsnes/phoenix/reference/action/item.cpp @@ -0,0 +1,5 @@ +void pItem::setText(const string &text) { +} + +void pItem::constructor() { +} diff --git a/bsnes/phoenix/reference/action/menu-check-item.cpp b/bsnes/phoenix/reference/action/menu-check-item.cpp deleted file mode 100755 index dc227864..00000000 --- a/bsnes/phoenix/reference/action/menu-check-item.cpp +++ /dev/null @@ -1,12 +0,0 @@ -bool pMenuCheckItem::checked() { - return false; -} - -void pMenuCheckItem::setChecked(bool checked) { -} - -void pMenuCheckItem::setText(const string &text) { -} - -void pMenuCheckItem::constructor() { -} diff --git a/bsnes/phoenix/reference/action/menu-item.cpp b/bsnes/phoenix/reference/action/menu-item.cpp deleted file mode 100755 index 1a2b3d44..00000000 --- a/bsnes/phoenix/reference/action/menu-item.cpp +++ /dev/null @@ -1,5 +0,0 @@ -void pMenuItem::setText(const string &text) { -} - -void pMenuItem::constructor() { -} diff --git a/bsnes/phoenix/reference/action/menu-radio-item.cpp b/bsnes/phoenix/reference/action/menu-radio-item.cpp deleted file mode 100755 index fdf83bc1..00000000 --- a/bsnes/phoenix/reference/action/menu-radio-item.cpp +++ /dev/null @@ -1,15 +0,0 @@ -bool pMenuRadioItem::checked() { - return false; -} - -void pMenuRadioItem::setChecked() { -} - -void pMenuRadioItem::setGroup(const reference_array &group) { -} - -void pMenuRadioItem::setText(const string &text) { -} - -void pMenuRadioItem::constructor() { -} diff --git a/bsnes/phoenix/reference/action/menu-separator.cpp b/bsnes/phoenix/reference/action/menu-separator.cpp deleted file mode 100755 index 9cc0ab27..00000000 --- a/bsnes/phoenix/reference/action/menu-separator.cpp +++ /dev/null @@ -1,2 +0,0 @@ -void pMenuSeparator::constructor() { -} diff --git a/bsnes/phoenix/reference/action/radio-item.cpp b/bsnes/phoenix/reference/action/radio-item.cpp new file mode 100755 index 00000000..cb5b457b --- /dev/null +++ b/bsnes/phoenix/reference/action/radio-item.cpp @@ -0,0 +1,15 @@ +bool pRadioItem::checked() { + return false; +} + +void pRadioItem::setChecked() { +} + +void pRadioItem::setGroup(const reference_array &group) { +} + +void pRadioItem::setText(const string &text) { +} + +void pRadioItem::constructor() { +} diff --git a/bsnes/phoenix/reference/action/separator.cpp b/bsnes/phoenix/reference/action/separator.cpp new file mode 100755 index 00000000..782c2ea8 --- /dev/null +++ b/bsnes/phoenix/reference/action/separator.cpp @@ -0,0 +1,2 @@ +void pSeparator::constructor() { +} diff --git a/bsnes/phoenix/reference/reference.cpp b/bsnes/phoenix/reference/reference.cpp index abcb3aed..a70254b6 100755 --- a/bsnes/phoenix/reference/reference.cpp +++ b/bsnes/phoenix/reference/reference.cpp @@ -6,10 +6,10 @@ #include "action/action.cpp" #include "action/menu.cpp" -#include "action/menu-separator.cpp" -#include "action/menu-item.cpp" -#include "action/menu-check-item.cpp" -#include "action/menu-radio-item.cpp" +#include "action/separator.cpp" +#include "action/item.cpp" +#include "action/check-item.cpp" +#include "action/radio-item.cpp" #include "widget/widget.cpp" #include "widget/button.cpp" @@ -26,12 +26,12 @@ #include "widget/vertical-slider.cpp" #include "widget/viewport.cpp" -unsigned pOS::desktopWidth() { - return 0; +Geometry pOS::availableGeometry() { + return { 0, 0, 0, 0 }; } -unsigned pOS::desktopHeight() { - return 0; +Geometry pOS::desktopGeometry() { + return { 0, 0, 0, 0 }; } string pOS::fileLoad(Window &parent, const string &path, const lstring &filter) { @@ -49,11 +49,11 @@ string pOS::folderSelect(Window &parent, const string &path) { void pOS::main() { } -bool pOS::pending() { +bool pOS::pendingEvents() { return false; } -void pOS::process() { +void pOS::processEvents() { } void pOS::quit() { diff --git a/bsnes/phoenix/reference/reference.hpp b/bsnes/phoenix/reference/reference.hpp index 11608a72..5f8ebf59 100755 --- a/bsnes/phoenix/reference/reference.hpp +++ b/bsnes/phoenix/reference/reference.hpp @@ -13,14 +13,14 @@ struct pObject { }; struct pOS : public pObject { - static unsigned desktopWidth(); - static unsigned desktopHeight(); + static Geometry availableGeometry(); + static Geometry desktopGeometry(); static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileSave(Window &parent, const string &path, const lstring &filter); static string folderSelect(Window &parent, const string &path); static void main(); - static bool pending(); - static void process(); + static bool pendingEvents(); + static void processEvents(); static void quit(); static void initialize(); @@ -52,11 +52,10 @@ struct pWindow : public pObject { void append(Layout &layout); void append(Menu &menu); void append(Widget &widget); - Geometry frameGeometry(); bool focused(); + Geometry frameMargin(); Geometry geometry(); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); - void setFrameGeometry(const Geometry &geometry); void setFocused(); void setFullScreen(bool fullScreen); void setGeometry(const Geometry &geometry); @@ -94,42 +93,42 @@ struct pMenu : public pAction { void constructor(); }; -struct pMenuSeparator : public pAction { - MenuSeparator &menuSeparator; +struct pSeparator : public pAction { + Separator &separator; - pMenuSeparator(MenuSeparator &menuSeparator) : pAction(menuSeparator), menuSeparator(menuSeparator) {} + pSeparator(Separator &separator) : pAction(separator), separator(separator) {} void constructor(); }; -struct pMenuItem : public pAction { - MenuItem &menuItem; +struct pItem : public pAction { + Item &item; void setText(const string &text); - pMenuItem(MenuItem &menuItem) : pAction(menuItem), menuItem(menuItem) {} + pItem(Item &item) : pAction(item), item(item) {} void constructor(); }; -struct pMenuCheckItem : public pAction { - MenuCheckItem &menuCheckItem; +struct pCheckItem : public pAction { + CheckItem &checkItem; bool checked(); void setChecked(bool checked); void setText(const string &text); - pMenuCheckItem(MenuCheckItem &menuCheckItem) : pAction(menuCheckItem), menuCheckItem(menuCheckItem) {} + pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} void constructor(); }; -struct pMenuRadioItem : public pAction { - MenuRadioItem &menuRadioItem; +struct pRadioItem : public pAction { + RadioItem &radioItem; bool checked(); void setChecked(); - void setGroup(const reference_array &group); + void setGroup(const reference_array &group); void setText(const string &text); - pMenuRadioItem(MenuRadioItem &menuRadioItem) : pAction(menuRadioItem), menuRadioItem(menuRadioItem) {} + pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} void constructor(); }; @@ -227,16 +226,17 @@ struct pListView : public pWidget { ListView &listView; void append(const lstring &text); - void autosizeColumns(); + void autoSizeColumns(); bool checked(unsigned row); void modify(unsigned row, const lstring &text); - void modify(unsigned row, unsigned column, const string &text); void reset(); - optional selection(); + bool selected(); + unsigned selection(); void setCheckable(bool checkable); void setChecked(unsigned row, bool checked); void setHeaderText(const lstring &text); void setHeaderVisible(bool visible); + void setSelected(bool selected); void setSelection(unsigned row); pListView(ListView &listView) : pWidget(listView), listView(listView) {} diff --git a/bsnes/phoenix/reference/widget/list-view.cpp b/bsnes/phoenix/reference/widget/list-view.cpp index 119e88cd..3170f6bb 100755 --- a/bsnes/phoenix/reference/widget/list-view.cpp +++ b/bsnes/phoenix/reference/widget/list-view.cpp @@ -1,7 +1,7 @@ void pListView::append(const lstring &text) { } -void pListView::autosizeColumns() { +void pListView::autoSizeColumns() { } bool pListView::checked(unsigned row) { @@ -10,14 +10,15 @@ bool pListView::checked(unsigned row) { void pListView::modify(unsigned row, const lstring &text) { } -void pListView::modify(unsigned row, unsigned column, const string &text) { -} - void pListView::reset() { } -optional pListView::selection() { - return { false, 0 }; +bool pListView::selected() { + return false; +} + +unsigned pListView::selection() { + return 0; } void pListView::setCheckable(bool checkable) { @@ -32,6 +33,9 @@ void pListView::setHeaderText(const lstring &text) { void pListView::setHeaderVisible(bool visible) { } +void pListView::setSelected(bool selected) { +} + void pListView::setSelection(unsigned row) { } diff --git a/bsnes/phoenix/reference/window.cpp b/bsnes/phoenix/reference/window.cpp index 18c4a14e..a31ce464 100755 --- a/bsnes/phoenix/reference/window.cpp +++ b/bsnes/phoenix/reference/window.cpp @@ -7,14 +7,14 @@ void pWindow::append(Menu &menu) { void pWindow::append(Widget &widget) { } -Geometry pWindow::frameGeometry() { - return { 0, 0, 0, 0 }; -} - bool pWindow::focused() { return false; } +Geometry pWindow::frameMargin() { + return { 0, 0, 0, 0 }; +} + Geometry pWindow::geometry() { return { 0, 0, 0, 0 }; } @@ -22,9 +22,6 @@ Geometry pWindow::geometry() { void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { } -void pWindow::setFrameGeometry(const Geometry &geometry) { -} - void pWindow::setFocused() { } diff --git a/bsnes/phoenix/windows/action/check-item.cpp b/bsnes/phoenix/windows/action/check-item.cpp new file mode 100755 index 00000000..6f30339f --- /dev/null +++ b/bsnes/phoenix/windows/action/check-item.cpp @@ -0,0 +1,14 @@ +bool pCheckItem::checked() { + return checkItem.state.checked; +} + +void pCheckItem::setChecked(bool checked) { + if(parentMenu) CheckMenuItem(parentMenu, id, checked ? MF_CHECKED : MF_UNCHECKED); +} + +void pCheckItem::setText(const string &text) { + if(parentWindow) parentWindow->p.updateMenu(); +} + +void pCheckItem::constructor() { +} diff --git a/bsnes/phoenix/windows/action/item.cpp b/bsnes/phoenix/windows/action/item.cpp new file mode 100755 index 00000000..2755c425 --- /dev/null +++ b/bsnes/phoenix/windows/action/item.cpp @@ -0,0 +1,6 @@ +void pItem::setText(const string &text) { + if(parentWindow) parentWindow->p.updateMenu(); +} + +void pItem::constructor() { +} diff --git a/bsnes/phoenix/windows/action/menu-check-item.cpp b/bsnes/phoenix/windows/action/menu-check-item.cpp deleted file mode 100755 index ed53cff0..00000000 --- a/bsnes/phoenix/windows/action/menu-check-item.cpp +++ /dev/null @@ -1,14 +0,0 @@ -bool pMenuCheckItem::checked() { - return menuCheckItem.state.checked; -} - -void pMenuCheckItem::setChecked(bool checked) { - if(parentMenu) CheckMenuItem(parentMenu, id, checked ? MF_CHECKED : MF_UNCHECKED); -} - -void pMenuCheckItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenuCheckItem::constructor() { -} diff --git a/bsnes/phoenix/windows/action/menu-item.cpp b/bsnes/phoenix/windows/action/menu-item.cpp deleted file mode 100755 index ef6aa8eb..00000000 --- a/bsnes/phoenix/windows/action/menu-item.cpp +++ /dev/null @@ -1,6 +0,0 @@ -void pMenuItem::setText(const string &text) { - if(parentWindow) parentWindow->p.updateMenu(); -} - -void pMenuItem::constructor() { -} diff --git a/bsnes/phoenix/windows/action/menu-separator.cpp b/bsnes/phoenix/windows/action/menu-separator.cpp deleted file mode 100755 index 9cc0ab27..00000000 --- a/bsnes/phoenix/windows/action/menu-separator.cpp +++ /dev/null @@ -1,2 +0,0 @@ -void pMenuSeparator::constructor() { -} diff --git a/bsnes/phoenix/windows/action/menu.cpp b/bsnes/phoenix/windows/action/menu.cpp index 452571bc..8e3763dc 100755 --- a/bsnes/phoenix/windows/action/menu.cpp +++ b/bsnes/phoenix/windows/action/menu.cpp @@ -27,18 +27,18 @@ void pMenu::update(Window &parentWindow, HMENU parentMenu) { Menu &item = (Menu&)action; item.p.update(parentWindow, hmenu); AppendMenu(hmenu, MF_STRING | MF_POPUP | enabled, (UINT_PTR)item.p.hmenu, utf16_t(item.state.text)); - } else if(dynamic_cast(&action)) { - MenuSeparator &item = (MenuSeparator&)action; + } else if(dynamic_cast(&action)) { + Separator &item = (Separator&)action; if(action.state.visible) AppendMenu(hmenu, MF_SEPARATOR | enabled, item.p.id, L""); - } else if(dynamic_cast(&action)) { - MenuItem &item = (MenuItem&)action; + } else if(dynamic_cast(&action)) { + Item &item = (Item&)action; if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); - } else if(dynamic_cast(&action)) { - MenuCheckItem &item = (MenuCheckItem&)action; + } else if(dynamic_cast(&action)) { + CheckItem &item = (CheckItem&)action; if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); if(item.state.checked) item.setChecked(); - } else if(dynamic_cast(&action)) { - MenuRadioItem &item = (MenuRadioItem&)action; + } else if(dynamic_cast(&action)) { + RadioItem &item = (RadioItem&)action; if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); if(item.state.checked) item.setChecked(); } diff --git a/bsnes/phoenix/windows/action/menu-radio-item.cpp b/bsnes/phoenix/windows/action/radio-item.cpp similarity index 58% rename from bsnes/phoenix/windows/action/menu-radio-item.cpp rename to bsnes/phoenix/windows/action/radio-item.cpp index 3d69a389..b887623f 100755 --- a/bsnes/phoenix/windows/action/menu-radio-item.cpp +++ b/bsnes/phoenix/windows/action/radio-item.cpp @@ -1,9 +1,9 @@ -bool pMenuRadioItem::checked() { - return menuRadioItem.state.checked; +bool pRadioItem::checked() { + return radioItem.state.checked; } -void pMenuRadioItem::setChecked() { - foreach(item, menuRadioItem.state.group) { +void pRadioItem::setChecked() { + foreach(item, radioItem.state.group) { //CheckMenuRadioItem takes: lo, hi, id; checking only id when lo <= id <= hi //phoenix does not force IDs to be linear, so to uncheck id, we use: lo == hi == id + 1 (out of range) //to check id, we use: lo == hi == id (only ID, but in range) @@ -11,12 +11,12 @@ void pMenuRadioItem::setChecked() { } } -void pMenuRadioItem::setGroup(const reference_array &group) { +void pRadioItem::setGroup(const reference_array &group) { } -void pMenuRadioItem::setText(const string &text) { +void pRadioItem::setText(const string &text) { if(parentWindow) parentWindow->p.updateMenu(); } -void pMenuRadioItem::constructor() { +void pRadioItem::constructor() { } diff --git a/bsnes/phoenix/windows/action/separator.cpp b/bsnes/phoenix/windows/action/separator.cpp new file mode 100755 index 00000000..782c2ea8 --- /dev/null +++ b/bsnes/phoenix/windows/action/separator.cpp @@ -0,0 +1,2 @@ +void pSeparator::constructor() { +} diff --git a/bsnes/phoenix/windows/widget/combo-box.cpp b/bsnes/phoenix/windows/widget/combo-box.cpp index c574abb0..8c49d02a 100755 --- a/bsnes/phoenix/windows/widget/combo-box.cpp +++ b/bsnes/phoenix/windows/widget/combo-box.cpp @@ -20,11 +20,11 @@ void pComboBox::constructor() { } void pComboBox::setGeometry(const Geometry &geometry) { - SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 200, SWP_NOZORDER); - RECT rc; - GetWindowRect(hwnd, &rc); - unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0)); - SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight); + SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 1, SWP_NOZORDER); +//RECT rc; +//GetWindowRect(hwnd, &rc); +//unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0)); +//SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight); } void pComboBox::setParent(Window &parent) { diff --git a/bsnes/phoenix/windows/widget/label.cpp b/bsnes/phoenix/windows/widget/label.cpp index 64bf5994..0c827952 100755 --- a/bsnes/phoenix/windows/widget/label.cpp +++ b/bsnes/phoenix/windows/widget/label.cpp @@ -20,6 +20,11 @@ static LRESULT CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPA Label *label = (Label*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if(!window || !label) return DefWindowProc(hwnd, msg, wparam, lparam); + if(msg == WM_ERASEBKGND) { + //background is erased during WM_PAINT to prevent flickering + return TRUE; + } + if(msg == WM_PAINT) { PAINTSTRUCT ps; RECT rc; diff --git a/bsnes/phoenix/windows/widget/list-view.cpp b/bsnes/phoenix/windows/widget/list-view.cpp index 402463c5..484193a1 100755 --- a/bsnes/phoenix/windows/widget/list-view.cpp +++ b/bsnes/phoenix/windows/widget/list-view.cpp @@ -17,7 +17,7 @@ void pListView::append(const lstring &list) { if(listView.state.headerText.size() <= 1) ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER); } -void pListView::autosizeColumns() { +void pListView::autoSizeColumns() { for(unsigned n = 0; n < listView.state.headerText.size(); n++) { ListView_SetColumnWidth(hwnd, n, LVSCW_AUTOSIZE_USEHEADER); } @@ -35,22 +35,24 @@ void pListView::modify(unsigned row, const lstring &list) { if(listView.state.headerText.size() <= 1) ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER); } -void pListView::modify(unsigned row, unsigned column, const string &text) { - utf16_t wtext(text); - ListView_SetItemText(hwnd, row, column, wtext); - if(listView.state.headerText.size() <= 1) ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER); -} - void pListView::reset() { ListView_DeleteAllItems(hwnd); } -optional pListView::selection() { +bool pListView::selected() { unsigned count = ListView_GetItemCount(hwnd); for(unsigned n = 0; n < count; n++) { - if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return { true, n }; + if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return true; } - return { false, 0 }; + return false; +} + +unsigned pListView::selection() { + unsigned count = ListView_GetItemCount(hwnd); + for(unsigned n = 0; n < count; n++) { + if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return n; + } + return listView.state.selection; } void pListView::setCheckable(bool checkable) { @@ -78,7 +80,7 @@ void pListView::setHeaderText(const lstring &list) { column.pszText = headerText; ListView_InsertColumn(hwnd, n, &column); } - autosizeColumns(); + autoSizeColumns(); } void pListView::setHeaderVisible(bool visible) { @@ -89,12 +91,20 @@ void pListView::setHeaderVisible(bool visible) { ); } -void pListView::setSelection(unsigned row) { - unsigned count = ListView_GetItemCount(hwnd); - for(unsigned n = 0; n < count; n++) { - ListView_SetItemState(hwnd, n, LVIS_FOCUSED, (n == row ? LVIS_FOCUSED : 0)); - ListView_SetItemState(hwnd, n, LVIS_SELECTED, (n == row ? LVIS_SELECTED : 0)); +void pListView::setSelected(bool selected) { + locked = true; + if(selected == false) { + ListView_SetItemState(hwnd, -1, 0, LVIS_FOCUSED | LVIS_SELECTED); + } else { + setSelection(listView.state.selection); } + locked = false; +} + +void pListView::setSelection(unsigned row) { + locked = true; + ListView_SetItemState(hwnd, row, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); + locked = false; } void pListView::constructor() { @@ -104,7 +114,7 @@ void pListView::constructor() { void pListView::setGeometry(const Geometry &geometry) { pWidget::setGeometry(geometry); - autosizeColumns(); + autoSizeColumns(); } void pListView::setParent(Window &parent) { @@ -121,6 +131,6 @@ void pListView::setParent(Window &parent) { setCheckable(listView.state.checkable); foreach(text, listView.state.text) append(text); foreach(checked, listView.state.checked, n) setChecked(n, checked); - if(auto selection = listView.state.selection) setSelection(selection()); - autosizeColumns(); + if(listView.state.selected) setSelection(listView.state.selection); + autoSizeColumns(); } diff --git a/bsnes/phoenix/windows/window.cpp b/bsnes/phoenix/windows/window.cpp index c77df815..740bd287 100755 --- a/bsnes/phoenix/windows/window.cpp +++ b/bsnes/phoenix/windows/window.cpp @@ -1,5 +1,5 @@ -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 FixedStyle = WS_CLIPCHILDREN | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER; +static const unsigned ResizableStyle = WS_CLIPCHILDREN | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME; void pWindow::append(Layout &layout) { layout.setParent(window); @@ -16,16 +16,24 @@ void pWindow::append(Widget &widget) { widget.p.setParent(window); } -Geometry pWindow::frameGeometry() { - RECT rc; - GetWindowRect(hwnd, &rc); - return { rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top }; -} - bool pWindow::focused() { return (GetForegroundWindow() == hwnd); } +Geometry pWindow::frameMargin() { + unsigned style = window.state.resizable ? ResizableStyle : FixedStyle; + if(window.state.fullScreen) style = 0; + RECT rc = { 0, 0, 640, 480 }; + AdjustWindowRect(&rc, style, window.state.menuVisible); + unsigned statusHeight = 0; + if(window.state.statusVisible) { + RECT src; + GetClientRect(hstatus, &src); + statusHeight = src.bottom - src.top; + } + return { abs(rc.left), abs(rc.top), (rc.right - rc.left) - 640, (rc.bottom - rc.top) + statusHeight - 480 }; +} + Geometry pWindow::geometry() { Geometry margin = frameMargin(); RECT rc; @@ -45,14 +53,6 @@ void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { brush = CreateSolidBrush(brushColor); } -void pWindow::setFrameGeometry(const Geometry &geometry) { - Geometry margin = frameMargin(); - window.setGeometry({ - geometry.x + margin.x, geometry.y + margin.y, - geometry.width - margin.width, geometry.height - margin.height - }); -} - void pWindow::setFocused() { if(window.state.visible == false) setVisible(true); SetFocus(hwnd); @@ -147,20 +147,6 @@ void pWindow::constructor() { setGeometry({ 128, 128, 256, 256 }); } -Geometry pWindow::frameMargin() { - unsigned style = window.state.resizable ? ResizableStyle : FixedStyle; - if(window.state.fullScreen) style = 0; - RECT rc = { 0, 0, 640, 480 }; - AdjustWindowRect(&rc, style, window.state.menuVisible); - unsigned statusHeight = 0; - if(window.state.statusVisible) { - RECT src; - GetClientRect(hstatus, &src); - statusHeight = src.bottom - src.top; - } - return { abs(rc.left), abs(rc.top), (rc.right - rc.left) - 640, (rc.bottom - rc.top) + statusHeight - 480 }; -} - void pWindow::updateMenu() { if(hmenu) DestroyMenu(hmenu); hmenu = CreateMenu(); diff --git a/bsnes/phoenix/windows/windows.cpp b/bsnes/phoenix/windows/windows.cpp index 4ee4ebe3..f5385659 100755 --- a/bsnes/phoenix/windows/windows.cpp +++ b/bsnes/phoenix/windows/windows.cpp @@ -7,10 +7,10 @@ #include "action/action.cpp" #include "action/menu.cpp" -#include "action/menu-separator.cpp" -#include "action/menu-item.cpp" -#include "action/menu-check-item.cpp" -#include "action/menu-radio-item.cpp" +#include "action/separator.cpp" +#include "action/item.cpp" +#include "action/check-item.cpp" +#include "action/radio-item.cpp" #include "widget/widget.cpp" #include "widget/button.cpp" @@ -32,12 +32,14 @@ static LRESULT CALLBACK OS_windowProc(HWND, UINT, WPARAM, LPARAM); pOS::State *pOS::state = 0; -unsigned pOS::desktopWidth() { - return GetSystemMetrics(SM_CXSCREEN); +Geometry pOS::availableGeometry() { + RECT rc; + SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); + return { rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top }; } -unsigned pOS::desktopHeight() { - return GetSystemMetrics(SM_CYSCREEN); +Geometry pOS::desktopGeometry() { + return { 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) }; } static string pOS_fileDialog(bool save, Window &parent, const string &path, const lstring &filter) { @@ -135,13 +137,13 @@ void pOS::main() { } } -bool pOS::pending() { +bool pOS::pendingEvents() { MSG msg; return PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE); } -void pOS::process() { - while(pending()) { +void pOS::processEvents() { + while(pendingEvents()) { MSG msg; if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if(msg.message == WM_KEYDOWN || msg.message == WM_KEYUP) { @@ -178,7 +180,7 @@ void pOS::initialize() { wc.lpfnWndProc = OS_windowProc; wc.lpszClassName = L"phoenix_window"; wc.lpszMenuName = 0; - wc.style = CS_HREDRAW | CS_VREDRAW; + wc.style = 0; RegisterClass(&wc); wc.cbClsExtra = 0; @@ -303,18 +305,18 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM if(control == 0) { pObject *object = (pObject*)pObject::find(id); if(!object) break; - if(dynamic_cast(object)) { - MenuItem &menuItem = ((pMenuItem*)object)->menuItem; - if(menuItem.onTick) menuItem.onTick(); - } else if(dynamic_cast(object)) { - MenuCheckItem &menuCheckItem = ((pMenuCheckItem*)object)->menuCheckItem; - menuCheckItem.setChecked(!menuCheckItem.state.checked); - if(menuCheckItem.onTick) menuCheckItem.onTick(); - } else if(dynamic_cast(object)) { - MenuRadioItem &menuRadioItem = ((pMenuRadioItem*)object)->menuRadioItem; - if(menuRadioItem.state.checked == false) { - menuRadioItem.setChecked(); - if(menuRadioItem.onTick) menuRadioItem.onTick(); + if(dynamic_cast(object)) { + Item &item = ((pItem*)object)->item; + if(item.onTick) item.onTick(); + } else if(dynamic_cast(object)) { + CheckItem &checkItem = ((pCheckItem*)object)->checkItem; + checkItem.setChecked(!checkItem.state.checked); + if(checkItem.onTick) checkItem.onTick(); + } else if(dynamic_cast(object)) { + RadioItem &radioItem = ((pRadioItem*)object)->radioItem; + if(radioItem.state.checked == false) { + radioItem.setChecked(); + if(radioItem.onTick) radioItem.onTick(); } } } else { @@ -374,9 +376,13 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM listView.p.lostFocus = true; } else { if(!(nmlistview->uOldState & LVIS_SELECTED) && (nmlistview->uNewState & LVIS_SELECTED)) { - if(listView.onChange) listView.onChange(); - } else if(listView.p.lostFocus == false && listView.selection() == false) { - if(listView.onChange) listView.onChange(); + listView.state.selected = true; + listView.state.selection = listView.selection(); + if(listView.p.locked == false && listView.onChange) listView.onChange(); + } else if(listView.p.lostFocus == false && listView.selected() == false) { + listView.state.selected = true; + listView.state.selection = listView.selection(); + if(listView.p.locked == false && listView.onChange) listView.onChange(); } listView.p.lostFocus = false; } diff --git a/bsnes/phoenix/windows/windows.hpp b/bsnes/phoenix/windows/windows.hpp index bd9fb565..2e641308 100755 --- a/bsnes/phoenix/windows/windows.hpp +++ b/bsnes/phoenix/windows/windows.hpp @@ -20,14 +20,14 @@ struct pOS : public pObject { }; static State *state; - static unsigned desktopWidth(); - static unsigned desktopHeight(); + static Geometry availableGeometry(); + static Geometry desktopGeometry(); static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileSave(Window &parent, const string &path, const lstring &filter); static string folderSelect(Window &parent, const string &path); static void main(); - static bool pending(); - static void process(); + static bool pendingEvents(); + static void processEvents(); static void quit(); static void initialize(); @@ -65,11 +65,10 @@ struct pWindow : public pObject { void append(Layout &layout); void append(Menu &menu); void append(Widget &widget); - Geometry frameGeometry(); bool focused(); + Geometry frameMargin(); Geometry geometry(); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); - void setFrameGeometry(const Geometry &geometry); void setFocused(); void setFullScreen(bool fullScreen); void setGeometry(const Geometry &geometry); @@ -85,7 +84,6 @@ struct pWindow : public pObject { pWindow(Window &window) : window(window) {} void constructor(); - Geometry frameMargin(); void updateMenu(); }; @@ -113,42 +111,42 @@ struct pMenu : public pAction { void update(Window &parentWindow, HMENU parentMenu); }; -struct pMenuSeparator : public pAction { - MenuSeparator &menuSeparator; +struct pSeparator : public pAction { + Separator &separator; - pMenuSeparator(MenuSeparator &menuSeparator) : pAction(menuSeparator), menuSeparator(menuSeparator) {} + pSeparator(Separator &separator) : pAction(separator), separator(separator) {} void constructor(); }; -struct pMenuItem : public pAction { - MenuItem &menuItem; +struct pItem : public pAction { + Item &item; void setText(const string &text); - pMenuItem(MenuItem &menuItem) : pAction(menuItem), menuItem(menuItem) {} + pItem(Item &item) : pAction(item), item(item) {} void constructor(); }; -struct pMenuCheckItem : public pAction { - MenuCheckItem &menuCheckItem; +struct pCheckItem : public pAction { + CheckItem &checkItem; bool checked(); void setChecked(bool checked); void setText(const string &text); - pMenuCheckItem(MenuCheckItem &menuCheckItem) : pAction(menuCheckItem), menuCheckItem(menuCheckItem) {} + pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {} void constructor(); }; -struct pMenuRadioItem : public pAction { - MenuRadioItem &menuRadioItem; +struct pRadioItem : public pAction { + RadioItem &radioItem; bool checked(); void setChecked(); - void setGroup(const reference_array &group); + void setGroup(const reference_array &group); void setText(const string &text); - pMenuRadioItem(MenuRadioItem &menuRadioItem) : pAction(menuRadioItem), menuRadioItem(menuRadioItem) {} + pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {} void constructor(); }; @@ -260,16 +258,17 @@ struct pListView : public pWidget { bool lostFocus; void append(const lstring &text); - void autosizeColumns(); + void autoSizeColumns(); bool checked(unsigned row); void modify(unsigned row, const lstring &text); - void modify(unsigned row, unsigned column, const string &text); void reset(); - optional selection(); + bool selected(); + unsigned selection(); void setCheckable(bool checkable); void setChecked(unsigned row, bool checked); void setHeaderText(const lstring &text); void setHeaderVisible(bool visible); + void setSelected(bool selected); void setSelection(unsigned row); pListView(ListView &listView) : pWidget(listView), listView(listView) {} diff --git a/bsnes/snes/snes.hpp b/bsnes/snes/snes.hpp index a8233025..13241683 100755 --- a/bsnes/snes/snes.hpp +++ b/bsnes/snes/snes.hpp @@ -1,7 +1,7 @@ namespace SNES { namespace Info { static const char Name[] = "bsnes"; - static const char Version[] = "075.15"; + static const char Version[] = "075.16"; static const unsigned SerializerVersion = 18; } } diff --git a/bsnes/ui-gameboy/general/main-window.hpp b/bsnes/ui-gameboy/general/main-window.hpp index 0e834187..4c1bd71d 100755 --- a/bsnes/ui-gameboy/general/main-window.hpp +++ b/bsnes/ui-gameboy/general/main-window.hpp @@ -1,31 +1,31 @@ struct MainWindow : Window { Menu system; - MenuItem systemLoadCartridge; - MenuSeparator systemSeparator1; - MenuItem systemPower; + Item systemLoadCartridge; + Separator systemSeparator1; + Item systemPower; Menu settings; - MenuCheckItem settingsVideoSync; - MenuCheckItem settingsAudioSync; + CheckItem settingsVideoSync; + CheckItem settingsAudioSync; Menu tools; Menu toolsSaveState; - MenuItem toolsSaveState1; - MenuItem toolsSaveState2; - MenuItem toolsSaveState3; - MenuItem toolsSaveState4; - MenuItem toolsSaveState5; + Item toolsSaveState1; + Item toolsSaveState2; + Item toolsSaveState3; + Item toolsSaveState4; + Item toolsSaveState5; Menu toolsLoadState; - MenuItem toolsLoadState1; - MenuItem toolsLoadState2; - MenuItem toolsLoadState3; - MenuItem toolsLoadState4; - MenuItem toolsLoadState5; - MenuSeparator toolsSeparator1; - MenuCheckItem toolsTraceCPU; + Item toolsLoadState1; + Item toolsLoadState2; + Item toolsLoadState3; + Item toolsLoadState4; + Item toolsLoadState5; + Separator toolsSeparator1; + CheckItem toolsTraceCPU; Menu help; - MenuItem helpAbout; + Item helpAbout; FixedLayout layout; Viewport viewport; diff --git a/bsnes/ui-gameboy/main.cpp b/bsnes/ui-gameboy/main.cpp index 6e4c8d9f..4cd18582 100755 --- a/bsnes/ui-gameboy/main.cpp +++ b/bsnes/ui-gameboy/main.cpp @@ -32,7 +32,7 @@ void Application::main(int argc, char **argv) { mainWindow.create(); mainWindow.setVisible(); - OS::process(); + OS::processEvents(); #if defined(PHOENIX_WINDOWS) video.driver("Direct3D"); @@ -69,7 +69,7 @@ void Application::main(int argc, char **argv) { GameBoy::system.init(&interface); while(quit == false) { - OS::process(); + OS::processEvents(); if(GameBoy::cartridge.loaded()) { do { diff --git a/bsnes/ui/debugger/console.cpp b/bsnes/ui/debugger/console.cpp index ccde174f..026a7b99 100755 --- a/bsnes/ui/debugger/console.cpp +++ b/bsnes/ui/debugger/console.cpp @@ -45,7 +45,7 @@ void Console::write(const string &text, bool echo) { buffer.append(text); output.setText(buffer); output.setCursorPosition(~0); - OS::process(); + OS::processEvents(); } if(traceToFile.checked() && logfile.open()) { logfile.print(string(text, "\n")); diff --git a/bsnes/ui/general/file-browser.cpp b/bsnes/ui/general/file-browser.cpp index 604e128d..5cd995fc 100755 --- a/bsnes/ui/general/file-browser.cpp +++ b/bsnes/ui/general/file-browser.cpp @@ -113,18 +113,17 @@ void FileBrowser::folderUp() { } void FileBrowser::fileActivate() { - if(auto position = contentsBox.selection()) { - string filename = contents[position()]; - if(strend(filename, "/")) { - string cartridgeName = cartridgeFolder(filename); - if(cartridgeName == "") { - setFolder({ folder, filename }); - } else { - loadFile({ folder, cartridgeName }); - } + if(contentsBox.selected() == false) return; + string filename = contents[contentsBox.selection()]; + if(strend(filename, "/")) { + string cartridgeName = cartridgeFolder(filename); + if(cartridgeName == "") { + setFolder({ folder, filename }); } else { - loadFile({ folder, filename }); + loadFile({ folder, cartridgeName }); } + } else { + loadFile({ folder, filename }); } } diff --git a/bsnes/ui/general/main-window.cpp b/bsnes/ui/general/main-window.cpp index 3ca22e4e..b64bf681 100755 --- a/bsnes/ui/general/main-window.cpp +++ b/bsnes/ui/general/main-window.cpp @@ -54,7 +54,7 @@ void MainWindow::create() { systemPort1Mouse.setText("Mouse"); systemPort1.append(systemPort1Mouse); - MenuRadioItem::group( + RadioItem::group( systemPort1None, systemPort1Gamepad, systemPort1Multitap, systemPort1Mouse ); @@ -82,7 +82,7 @@ void MainWindow::create() { systemPort2Justifiers.setText("Justifiers"); systemPort2.append(systemPort2Justifiers); - MenuRadioItem::group( + RadioItem::group( systemPort2None, systemPort2Gamepad, systemPort2Multitap, systemPort2Mouse, systemPort2SuperScope, systemPort2Justifier, systemPort2Justifiers ); @@ -109,7 +109,7 @@ void MainWindow::create() { settingsVideoMode5x.setText("Scale 5x"); settingsVideoMode.append(settingsVideoMode5x); - MenuRadioItem::group( + RadioItem::group( settingsVideoMode1x, settingsVideoMode2x, settingsVideoMode3x, settingsVideoMode4x, settingsVideoMode5x ); @@ -126,7 +126,7 @@ void MainWindow::create() { settingsVideoModePAL.setText("PAL"); settingsVideoMode.append(settingsVideoModePAL); - MenuRadioItem::group( + RadioItem::group( settingsVideoModeNTSC, settingsVideoModePAL ); diff --git a/bsnes/ui/general/main-window.hpp b/bsnes/ui/general/main-window.hpp index 118ce41b..c6a5b1d6 100755 --- a/bsnes/ui/general/main-window.hpp +++ b/bsnes/ui/general/main-window.hpp @@ -1,75 +1,75 @@ struct MainWindow : TopLevelWindow { Menu system; - MenuItem systemLoadCartridge; + Item systemLoadCartridge; Menu systemLoadCartridgeSpecial; - MenuItem systemLoadCartridgeBsxSlotted; - MenuItem systemLoadCartridgeBsx; - MenuItem systemLoadCartridgeSufamiTurbo; - MenuItem systemLoadCartridgeSuperGameBoy; - MenuSeparator systemSeparator1; - MenuItem systemPower; - MenuItem systemReset; - MenuSeparator systemSeparator2; + Item systemLoadCartridgeBsxSlotted; + Item systemLoadCartridgeBsx; + Item systemLoadCartridgeSufamiTurbo; + Item systemLoadCartridgeSuperGameBoy; + Separator systemSeparator1; + Item systemPower; + Item systemReset; + Separator systemSeparator2; Menu systemPort1; - MenuRadioItem systemPort1None; - MenuRadioItem systemPort1Gamepad; - MenuRadioItem systemPort1Multitap; - MenuRadioItem systemPort1Mouse; + RadioItem systemPort1None; + RadioItem systemPort1Gamepad; + RadioItem systemPort1Multitap; + RadioItem systemPort1Mouse; Menu systemPort2; - MenuRadioItem systemPort2None; - MenuRadioItem systemPort2Gamepad; - MenuRadioItem systemPort2Multitap; - MenuRadioItem systemPort2Mouse; - MenuRadioItem systemPort2SuperScope; - MenuRadioItem systemPort2Justifier; - MenuRadioItem systemPort2Justifiers; + RadioItem systemPort2None; + RadioItem systemPort2Gamepad; + RadioItem systemPort2Multitap; + RadioItem systemPort2Mouse; + RadioItem systemPort2SuperScope; + RadioItem systemPort2Justifier; + RadioItem systemPort2Justifiers; Menu settings; Menu settingsVideoMode; - MenuRadioItem settingsVideoMode1x; - MenuRadioItem settingsVideoMode2x; - MenuRadioItem settingsVideoMode3x; - MenuRadioItem settingsVideoMode4x; - MenuRadioItem settingsVideoMode5x; - MenuSeparator settingsVideoModeSeparator1; - MenuCheckItem settingsVideoModeAspectRatioCorrection; - MenuSeparator settingsVideoModeSeparator2; - MenuRadioItem settingsVideoModeNTSC; - MenuRadioItem settingsVideoModePAL; - MenuCheckItem settingsSmoothVideo; - MenuSeparator settingsSeparator1; - MenuCheckItem settingsSynchronizeVideo; - MenuCheckItem settingsSynchronizeAudio; - MenuCheckItem settingsMuteAudio; - MenuSeparator settingsSeparator2; - MenuItem settingsVideo; - MenuItem settingsAudio; - MenuItem settingsInput; - MenuItem settingsAdvanced; + RadioItem settingsVideoMode1x; + RadioItem settingsVideoMode2x; + RadioItem settingsVideoMode3x; + RadioItem settingsVideoMode4x; + RadioItem settingsVideoMode5x; + Separator settingsVideoModeSeparator1; + CheckItem settingsVideoModeAspectRatioCorrection; + Separator settingsVideoModeSeparator2; + RadioItem settingsVideoModeNTSC; + RadioItem settingsVideoModePAL; + CheckItem settingsSmoothVideo; + Separator settingsSeparator1; + CheckItem settingsSynchronizeVideo; + CheckItem settingsSynchronizeAudio; + CheckItem settingsMuteAudio; + Separator settingsSeparator2; + Item settingsVideo; + Item settingsAudio; + Item settingsInput; + Item settingsAdvanced; Menu tools; Menu toolsStateSave; - MenuItem toolsStateSave1; - MenuItem toolsStateSave2; - MenuItem toolsStateSave3; - MenuItem toolsStateSave4; - MenuItem toolsStateSave5; + Item toolsStateSave1; + Item toolsStateSave2; + Item toolsStateSave3; + Item toolsStateSave4; + Item toolsStateSave5; Menu toolsStateLoad; - MenuItem toolsStateLoad1; - MenuItem toolsStateLoad2; - MenuItem toolsStateLoad3; - MenuItem toolsStateLoad4; - MenuItem toolsStateLoad5; - MenuSeparator toolsSeparator1; - MenuItem toolsCheatEditor; - MenuItem toolsStateManager; + Item toolsStateLoad1; + Item toolsStateLoad2; + Item toolsStateLoad3; + Item toolsStateLoad4; + Item toolsStateLoad5; + Separator toolsSeparator1; + Item toolsCheatEditor; + Item toolsStateManager; #if defined(DEBUGGER) - MenuSeparator toolsSeparator2; - MenuItem toolsDebugger; + Separator toolsSeparator2; + Item toolsDebugger; #endif Menu help; - MenuItem helpAbout; + Item helpAbout; FixedLayout layout; Viewport viewport; diff --git a/bsnes/ui/main.cpp b/bsnes/ui/main.cpp index 65423582..fd156d11 100755 --- a/bsnes/ui/main.cpp +++ b/bsnes/ui/main.cpp @@ -67,7 +67,7 @@ void Application::main(int argc, char **argv) { utility.setScale(config.video.scale); mainWindow.setVisible(); - OS::process(); + OS::processEvents(); video.driver(config.video.driver); video.set(Video::Handle, mainWindow.viewport.handle()); @@ -108,7 +108,7 @@ void Application::main(int argc, char **argv) { if(argc == 2) cartridge.loadNormal(argv[1]); while(quit == false) { - OS::process(); + OS::processEvents(); inputMapper.poll(); utility.updateStatus(); @@ -130,7 +130,7 @@ void Application::main(int argc, char **argv) { cartridge.unload(); saveGeometry(); foreach(window, windows) window->setVisible(false); - OS::process(); + OS::processEvents(); SNES::system.term(); config.save(); diff --git a/bsnes/ui/settings/input.cpp b/bsnes/ui/settings/input.cpp index 28e56ec7..1dd10288 100755 --- a/bsnes/ui/settings/input.cpp +++ b/bsnes/ui/settings/input.cpp @@ -16,12 +16,12 @@ void InputSettings::create() { deviceLabel.setText("Device:"); mappingList.setHeaderText("Name", "Mapping"); mappingList.setHeaderVisible(true); + clearButton.setText("Clear"); mouseXaxis.setText("Mouse X-axis"); mouseYaxis.setText("Mouse Y-axis"); mouseLeft.setText("Mouse Left"); mouseMiddle.setText("Mouse Middle"); mouseRight.setText("Mouse Right"); - clearButton.setText("Clear"); layout.setMargin(5); selectionLayout.append(portLabel, 50, 0, 5); @@ -30,23 +30,30 @@ void InputSettings::create() { selectionLayout.append(deviceBox, 0, 0); layout.append(selectionLayout, 0, Style::ComboBoxHeight, 5); layout.append(mappingList, 0, 0, 5); - mapLayout.append(mouseXaxis, 100, 0, 5); - mapLayout.append(mouseYaxis, 100, 0, 5); - mapLayout.append(mouseLeft, 100, 0, 5); - mapLayout.append(mouseMiddle, 100, 0, 5); - mapLayout.append(mouseRight, 100, 0, 5); - mapLayout.append(spacer, 0, 0); - mapLayout.append(clearButton, 80, 0); + mapLayout.append(spacer, 0, 0); + mapLayout.append(clearButton, 80, 0); layout.append(mapLayout, 0, Style::ButtonHeight); - setGeometry({ 0, 0, 640, layout.minimumHeight() + 250 }); - append(layout); + axisLayout.setMargin(5); + axisLayout.append(axisSpacer, 0, 0); + axisControlLayout.append(mouseXaxis, 100, 0, 5); + axisControlLayout.append(mouseYaxis, 100, 0, 5); + axisLayout.append(axisControlLayout, 0, Style::ButtonHeight); - mouseXaxis.setVisible(false); - mouseYaxis.setVisible(false); - mouseLeft.setVisible(false); - mouseMiddle.setVisible(false); - mouseRight.setVisible(false); + buttonLayout.setMargin(5); + buttonLayout.append(buttonSpacer, 0, 0); + buttonControlLayout.append(mouseLeft, 100, 0, 5); + buttonControlLayout.append(mouseMiddle, 100, 0, 5); + buttonControlLayout.append(mouseRight, 100, 0, 5); + buttonLayout.append(buttonControlLayout, 0, Style::ButtonHeight); + + setGeometry({ 0, 0, 480, layout.minimumHeight() + 250 }); + append(layout); + append(axisLayout); + append(buttonLayout); + + axisLayout.setVisible(false); + buttonLayout.setVisible(false); portChanged(); portBox.onChange = { &InputSettings::portChanged, this }; @@ -90,7 +97,7 @@ void InputSettings::deviceChanged() { if(mapping == "") mapping = "None"; mappingList.append(controller[i]->name, mapping); } - mappingList.autosizeColumns(); + mappingList.autoSizeColumns(); } void InputSettings::mappingChanged() { @@ -106,53 +113,45 @@ void InputSettings::mappingChanged() { if(mapping == "") mapping = "None"; mappingList.modify(i, controller[i]->name, mapping); } - mappingList.autosizeColumns(); + mappingList.autoSizeColumns(); } void InputSettings::assignInput() { - if(auto position = mappingList.selection()) { - InputMapper::ControllerPort &port = ( - portBox.selection() == 0 - ? (InputMapper::ControllerPort&)inputMapper.port1 - : (InputMapper::ControllerPort&)inputMapper.port2 - ); - InputMapper::Controller &controller = (InputMapper::Controller&)*port[deviceBox.selection()]; + if(mappingList.selected() == false) return; + InputMapper::ControllerPort &port = ( + portBox.selection() == 0 + ? (InputMapper::ControllerPort&)inputMapper.port1 + : (InputMapper::ControllerPort&)inputMapper.port2 + ); + InputMapper::Controller &controller = (InputMapper::Controller&)*port[deviceBox.selection()]; - portBox.setEnabled(false); - deviceBox.setEnabled(false); - mappingList.setEnabled(false); - inputMapper.poll(); //flush any pending keypresses - activeInput = controller[position()]; - setStatusText({ "Set assignment for [", activeInput->name, "] ..." }); - if(dynamic_cast(activeInput)) { - mouseLeft.setVisible(false); - mouseMiddle.setVisible(false); - mouseRight.setVisible(false); - mouseXaxis.setVisible(true); - mouseYaxis.setVisible(true); - } else { - mouseXaxis.setVisible(false); - mouseYaxis.setVisible(false); - mouseLeft.setVisible(true); - mouseMiddle.setVisible(true); - mouseRight.setVisible(true); - } + portBox.setEnabled(false); + deviceBox.setEnabled(false); + mappingList.setEnabled(false); + inputMapper.poll(); //flush any pending keypresses + activeInput = controller[mappingList.selection()]; + setStatusText({ "Set assignment for [", activeInput->name, "] ..." }); + if(dynamic_cast(activeInput)) { + axisLayout.setVisible(true); + buttonLayout.setVisible(false); + } else { + axisLayout.setVisible(false); + buttonLayout.setVisible(true); } } void InputSettings::clearInput() { - if(auto position = mappingList.selection()) { - InputMapper::ControllerPort &port = ( - portBox.selection() == 0 - ? (InputMapper::ControllerPort&)inputMapper.port1 - : (InputMapper::ControllerPort&)inputMapper.port2 - ); - InputMapper::Controller &controller = (InputMapper::Controller&)*port[deviceBox.selection()]; + if(mappingList.selected() == false) return; + InputMapper::ControllerPort &port = ( + portBox.selection() == 0 + ? (InputMapper::ControllerPort&)inputMapper.port1 + : (InputMapper::ControllerPort&)inputMapper.port2 + ); + InputMapper::Controller &controller = (InputMapper::Controller&)*port[deviceBox.selection()]; - controller[position()]->mapping = ""; - inputMapper.bind(); - endAssignment(); - } + controller[mappingList.selection()]->mapping = ""; + inputMapper.bind(); + endAssignment(); } void InputSettings::setMapping(const string &mapping) { @@ -167,11 +166,8 @@ void InputSettings::endAssignment() { deviceBox.setEnabled(true); mappingList.setEnabled(true); setStatusText(""); - mouseXaxis.setVisible(false); - mouseYaxis.setVisible(false); - mouseLeft.setVisible(false); - mouseMiddle.setVisible(false); - mouseRight.setVisible(false); + axisLayout.setVisible(false); + buttonLayout.setVisible(false); mappingChanged(); mappingList.setFocused(); } diff --git a/bsnes/ui/settings/input.hpp b/bsnes/ui/settings/input.hpp index 9b45848e..7d26d330 100755 --- a/bsnes/ui/settings/input.hpp +++ b/bsnes/ui/settings/input.hpp @@ -7,13 +7,21 @@ struct InputSettings : TopLevelWindow { ComboBox deviceBox; ListView mappingList; HorizontalLayout mapLayout; + Label spacer; + Button clearButton; + + VerticalLayout axisLayout; + Widget axisSpacer; + HorizontalLayout axisControlLayout; Button mouseXaxis; Button mouseYaxis; + + VerticalLayout buttonLayout; + Widget buttonSpacer; + HorizontalLayout buttonControlLayout; Button mouseLeft; Button mouseMiddle; Button mouseRight; - Label spacer; - Button clearButton; void inputEvent(uint16_t scancode, int16_t value); void calibrateJoypads(); diff --git a/bsnes/ui/tools/cheat-editor.cpp b/bsnes/ui/tools/cheat-editor.cpp index 4dc92762..b770cc71 100755 --- a/bsnes/ui/tools/cheat-editor.cpp +++ b/bsnes/ui/tools/cheat-editor.cpp @@ -75,7 +75,7 @@ void CheatEditor::save(string filename) { } cheatList.reset(); - cheatList.autosizeColumns(); + cheatList.autoSizeColumns(); } void CheatEditor::create() { @@ -158,9 +158,9 @@ void CheatEditor::create() { void CheatEditor::synchronize() { findButton.setEnabled(SNES::cartridge.loaded()); clearAllButton.setEnabled(SNES::cartridge.loaded()); - if(auto position = cheatList.selection()) { - codeEdit.setText(cheatText[position()][1]); - descEdit.setText(cheatText[position()][2]); + if(cheatList.selected()) { + codeEdit.setText(cheatText[cheatList.selection()][1]); + descEdit.setText(cheatText[cheatList.selection()][2]); codeEdit.setEnabled(true); descEdit.setEnabled(true); clearButton.setEnabled(true); @@ -184,7 +184,7 @@ void CheatEditor::refresh() { cheatList.setChecked(i, SNES::cheat[i].enabled); cheatList.modify(i, cheatText[i][CheatSlot], cheatCode, cheatText[i][CheatDesc]); } - cheatList.autosizeColumns(); + cheatList.autoSizeColumns(); } void CheatEditor::toggle(unsigned row) { @@ -193,12 +193,12 @@ void CheatEditor::toggle(unsigned row) { } void CheatEditor::bind() { - if(auto position = cheatList.selection()) { - cheatText[position()][CheatCode] = codeEdit.text(); - cheatText[position()][CheatDesc] = descEdit.text(); - SNES::cheat[position()] = cheatText[position()][CheatCode]; - refresh(); - } + if(cheatList.selected() == false) return; + unsigned selection = cheatList.selection(); + cheatText[selection][CheatCode] = codeEdit.text(); + cheatText[selection][CheatDesc] = descEdit.text(); + SNES::cheat[selection] = cheatText[selection][CheatCode]; + refresh(); } void CheatEditor::findCodes() { @@ -289,15 +289,15 @@ void CheatEditor::clearAll() { } void CheatEditor::clear() { - if(auto position = cheatList.selection()) { - SNES::cheat[position()].enabled = false; - SNES::cheat[position()] = ""; - cheatList.setChecked(position(), false); - cheatText[position()][CheatCode] = ""; - cheatText[position()][CheatDesc] = ""; - SNES::cheat.synchronize(); - refresh(); - codeEdit.setText(""); - descEdit.setText(""); - } + if(cheatList.selected() == false) return; + unsigned selection = cheatList.selection(); + SNES::cheat[selection].enabled = false; + SNES::cheat[selection] = ""; + cheatList.setChecked(selection, false); + cheatText[selection][CheatCode] = ""; + cheatText[selection][CheatDesc] = ""; + SNES::cheat.synchronize(); + refresh(); + codeEdit.setText(""); + descEdit.setText(""); } diff --git a/bsnes/ui/tools/state-manager.cpp b/bsnes/ui/tools/state-manager.cpp index d0ba711e..6ee9d315 100755 --- a/bsnes/ui/tools/state-manager.cpp +++ b/bsnes/ui/tools/state-manager.cpp @@ -38,11 +38,10 @@ void StateManager::create() { void StateManager::synchronize() { descEdit.setText(""); descEdit.setEnabled(false); - if(auto position = stateList.selection()) { - if(slot[position()].capacity() > 0) { - descEdit.setText(slotLoadDescription(position())); - descEdit.setEnabled(true); - } + if(stateList.selected() == false) return; + if(slot[stateList.selection()].capacity() > 0) { + descEdit.setText(slotLoadDescription(stateList.selection())); + descEdit.setEnabled(true); } } @@ -50,7 +49,7 @@ void StateManager::refresh() { for(unsigned i = 0; i < 32; i++) { stateList.modify(i, rdecimal<2>(i + 1), slotLoadDescription(i)); } - stateList.autosizeColumns(); + stateList.autoSizeColumns(); } void StateManager::load() { @@ -106,16 +105,15 @@ void StateManager::save() { } void StateManager::slotLoad() { - if(auto position = stateList.selection()) { - serializer s(slot[position()].data(), slot[position()].capacity()); - SNES::system.unserialize(s); - } + if(stateList.selected() == false) return; + serializer s(slot[stateList.selection()].data(), slot[stateList.selection()].capacity()); + SNES::system.unserialize(s); } void StateManager::slotSave() { - if(auto position = stateList.selection()) { + if(stateList.selected()) { SNES::system.runtosave(); - slot[position()] = SNES::system.serialize(); + slot[stateList.selection()] = SNES::system.serialize(); } refresh(); synchronize(); @@ -123,8 +121,8 @@ void StateManager::slotSave() { } void StateManager::slotErase() { - if(auto position = stateList.selection()) { - slot[position()] = serializer(); + if(stateList.selected()) { + slot[stateList.selection()] = serializer(); } refresh(); synchronize(); @@ -138,11 +136,10 @@ string StateManager::slotLoadDescription(unsigned i) { } void StateManager::slotSaveDescription() { - if(auto position = stateList.selection()) { - string text = descEdit.text(); - if(slot[position()].capacity() > 0) { - strlcpy((char*)slot[position()].data() + HeaderLength, (const char*)text, 512); - } + if(stateList.selected() == false) return; + string text = descEdit.text(); + if(slot[stateList.selection()].capacity() > 0) { + strlcpy((char*)slot[stateList.selection()].data() + HeaderLength, (const char*)text, 512); } refresh(); } diff --git a/bsnes/ui/utility/utility.cpp b/bsnes/ui/utility/utility.cpp index 118c55d4..ef24669b 100755 --- a/bsnes/ui/utility/utility.cpp +++ b/bsnes/ui/utility/utility.cpp @@ -92,38 +92,39 @@ void Utility::setFullscreen(bool fullscreen) { setScale(); } else { input.acquire(); + Geometry desktop = OS::desktopGeometry(); unsigned width, height; switch(config.video.fullscreenScale) { default: case 0: { //center (even multiple of base height) unsigned baseHeight = config.video.region == 0 ? 224 : 239; - unsigned heightScale = OS::desktopHeight() / baseHeight; + unsigned heightScale = desktop.height / baseHeight; height = baseHeight * heightScale; width = 256 * heightScale; if(config.video.region == 0 && config.video.aspectRatioCorrection) width *= 54.0 / 47.0; if(config.video.region == 1 && config.video.aspectRatioCorrection) width *= 32.0 / 23.0; - width = min(width, OS::desktopWidth()); + width = min(width, desktop.width); break; } case 1: { //scale (100% screen height, aspect-corrected width) unsigned baseHeight = config.video.region == 0 ? 224 : 239; - height = OS::desktopHeight(); + height = desktop.height; width = 256.0 / baseHeight * height; if(config.video.region == 0 && config.video.aspectRatioCorrection) width *= 54.0 / 47.0; if(config.video.region == 1 && config.video.aspectRatioCorrection) width *= 32.0 / 23.0; - width = min(width, OS::desktopWidth()); + width = min(width, desktop.width); break; } case 2: { //stretch (100% screen width and 100% screen height) - width = OS::desktopWidth(); - height = OS::desktopHeight(); + width = desktop.width; + height = desktop.height; break; } } - viewportX = (OS::desktopWidth() - width) / 2; - viewportY = (OS::desktopHeight() - height) / 2; + viewportX = (desktop.width - width) / 2; + viewportY = (desktop.height - height) / 2; viewportWidth = width; viewportHeight = height;