diff --git a/bsnes/nall/string/convert.hpp b/bsnes/nall/string/convert.hpp index 9040cb83..ca77db85 100755 --- a/bsnes/nall/string/convert.hpp +++ b/bsnes/nall/string/convert.hpp @@ -65,8 +65,11 @@ intmax_t integer(const char *str) { intmax_t result = 0; bool negate = false; - //check for negation - if(*str == '-') { + //check for sign + if(*str == '+') { + negate = false; + str++; + } else if(*str == '-') { negate = true; str++; } diff --git a/bsnes/nall/string/utility.hpp b/bsnes/nall/string/utility.hpp index 5f17ebf2..8e6c1005 100755 --- a/bsnes/nall/string/utility.hpp +++ b/bsnes/nall/string/utility.hpp @@ -50,7 +50,7 @@ string integer(intmax_t value) { result[x] = buffer[y]; } - return result; + return (const char*)result; } template string linteger(intmax_t value) { @@ -77,7 +77,7 @@ template string linteger(intmax_t value) { result[x] = buffer[y]; } - return result; + return (const char*)result; } template string rinteger(intmax_t value) { @@ -104,7 +104,7 @@ template string rinteger(intmax_t value) { result[x] = buffer[y]; } - return result; + return (const char*)result; } string decimal(uintmax_t value) { @@ -126,7 +126,7 @@ string decimal(uintmax_t value) { result[x] = buffer[y]; } - return result; + return (const char*)result; } template string ldecimal(uintmax_t value) { @@ -149,7 +149,7 @@ template string ldecimal(uintmax_t value) { result[x] = buffer[y]; } - return result; + return (const char*)result; } template string rdecimal(uintmax_t value) { @@ -172,7 +172,7 @@ template string rdecimal(uintmax_t value) { result[x] = buffer[y]; } - return result; + return (const char*)result; } template string hex(uintmax_t value) { @@ -194,7 +194,7 @@ template string hex(uintmax_t value) { result[x] = buffer[y]; } - return result; + return (const char*)result; } template string binary(uintmax_t value) { @@ -216,7 +216,7 @@ template string binary(uintmax_t value) { result[x] = buffer[y]; } - return result; + return (const char*)result; } //using sprintf is certainly not the most ideal method to convert diff --git a/bsnes/phoenix/gtk/action/action.cpp b/bsnes/phoenix/gtk/action/action.cpp new file mode 100755 index 00000000..a4979ba4 --- /dev/null +++ b/bsnes/phoenix/gtk/action/action.cpp @@ -0,0 +1,29 @@ +static void Action_setFont(GtkWidget *widget, gpointer font) { + if(font) { + gtk_widget_modify_font(widget, (PangoFontDescription*)font); + if(GTK_IS_CONTAINER(widget)) { + gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)Action_setFont, (PangoFontDescription*)font); + } + } +} + +bool Action::visible() { + return gtk_widget_get_visible(object->widget); +} + +void Action::setVisible(bool visible) { + gtk_widget_set_visible(object->widget, visible); +} + +bool Action::enabled() { + return gtk_widget_get_sensitive(object->widget); +} + +void Action::setEnabled(bool enabled) { + gtk_widget_set_sensitive(object->widget, enabled); +} + +Action::Action() { + action = new Action::Data; + action->font = 0; +} diff --git a/bsnes/phoenix/gtk/action/menu-check-item.cpp b/bsnes/phoenix/gtk/action/menu-check-item.cpp new file mode 100755 index 00000000..0339d01b --- /dev/null +++ b/bsnes/phoenix/gtk/action/menu-check-item.cpp @@ -0,0 +1,22 @@ +static void MenuCheckItem_tick(MenuCheckItem *self) { + if(self->onTick && self->object->locked == false) self->onTick(); +} + +void MenuCheckItem::setText(const string &text) { + gtk_menu_item_set_label(GTK_MENU_ITEM(object->widget), text); +} + +bool MenuCheckItem::checked() { + return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(object->widget)); +} + +void MenuCheckItem::setChecked(bool state) { + object->locked = true; + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(object->widget), state); + object->locked = false; +} + +MenuCheckItem::MenuCheckItem() { + object->widget = gtk_check_menu_item_new_with_label(""); + g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(MenuCheckItem_tick), (gpointer)this); +} diff --git a/bsnes/phoenix/gtk/action/menu-item.cpp b/bsnes/phoenix/gtk/action/menu-item.cpp new file mode 100755 index 00000000..6f2cc98f --- /dev/null +++ b/bsnes/phoenix/gtk/action/menu-item.cpp @@ -0,0 +1,12 @@ +static void MenuItem_tick(MenuItem *self) { + if(self->onTick) self->onTick(); +} + +void MenuItem::setText(const string &text) { + gtk_menu_item_set_label(GTK_MENU_ITEM(object->widget), text); +} + +MenuItem::MenuItem() { + object->widget = gtk_menu_item_new_with_label(""); + g_signal_connect_swapped(G_OBJECT(object->widget), "activate", G_CALLBACK(MenuItem_tick), (gpointer)this); +} diff --git a/bsnes/phoenix/gtk/action/menu-radio-item.cpp b/bsnes/phoenix/gtk/action/menu-radio-item.cpp new file mode 100755 index 00000000..fab87932 --- /dev/null +++ b/bsnes/phoenix/gtk/action/menu-radio-item.cpp @@ -0,0 +1,31 @@ +static void MenuRadioItem_tick(MenuRadioItem *self) { + if(self->onTick && self->checked() && self->object->locked == false) self->onTick(); +} + +void MenuRadioItem::setParent(MenuRadioItem &parent) { + gtk_radio_menu_item_set_group( + GTK_RADIO_MENU_ITEM(object->widget), + gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(parent.object->widget)) + ); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(object->widget), false); +} + +void MenuRadioItem::setText(const string &text) { + gtk_menu_item_set_label(GTK_MENU_ITEM(object->widget), text); +} + +bool MenuRadioItem::checked() { + return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(object->widget)); +} + +void MenuRadioItem::setChecked() { + object->locked = true; + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(object->widget), true); + object->locked = false; +} + +MenuRadioItem::MenuRadioItem() { + object->widget = gtk_radio_menu_item_new_with_label(0, ""); + setChecked(); + g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(MenuRadioItem_tick), (gpointer)this); +} diff --git a/bsnes/phoenix/gtk/action/menu-separator.cpp b/bsnes/phoenix/gtk/action/menu-separator.cpp new file mode 100755 index 00000000..63d9974e --- /dev/null +++ b/bsnes/phoenix/gtk/action/menu-separator.cpp @@ -0,0 +1,3 @@ +MenuSeparator::MenuSeparator() { + object->widget = gtk_separator_menu_item_new(); +} diff --git a/bsnes/phoenix/gtk/action/menu.cpp b/bsnes/phoenix/gtk/action/menu.cpp new file mode 100755 index 00000000..74e62576 --- /dev/null +++ b/bsnes/phoenix/gtk/action/menu.cpp @@ -0,0 +1,14 @@ +void Menu::append(Action &action) { + gtk_menu_shell_append(GTK_MENU_SHELL(object->menu), action.object->widget); + gtk_widget_show(action.object->widget); +} + +void Menu::setText(const string &text) { + gtk_menu_item_set_label(GTK_MENU_ITEM(object->widget), text); +} + +Menu::Menu() { + object->menu = gtk_menu_new(); + object->widget = gtk_menu_item_new_with_label(""); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(object->widget), object->menu); +} diff --git a/bsnes/phoenix/gtk/gtk.cpp b/bsnes/phoenix/gtk/gtk.cpp index 9ec6007b..3152ff83 100755 --- a/bsnes/phoenix/gtk/gtk.cpp +++ b/bsnes/phoenix/gtk/gtk.cpp @@ -1,3 +1,7 @@ +#include +#include +using namespace nall; + #include #include #include @@ -17,27 +21,35 @@ using namespace nall; namespace phoenix { +#include "settings.cpp" #include "object.cpp" #include "font.cpp" -#include "menu.cpp" -#include "widget.cpp" #include "window.cpp" #include "layout.cpp" -#include "button.cpp" -#include "canvas.cpp" -#include "checkbox.cpp" -#include "combobox.cpp" -#include "editbox.cpp" -#include "hexeditor.cpp" -#include "horizontalslider.cpp" -#include "label.cpp" -#include "listbox.cpp" -#include "progressbar.cpp" -#include "radiobox.cpp" -#include "textbox.cpp" -#include "verticalslider.cpp" -#include "viewport.cpp" -#include "messagewindow.cpp" +#include "message-window.cpp" + +#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 "widget/widget.cpp" +#include "widget/button.cpp" +#include "widget/canvas.cpp" +#include "widget/check-box.cpp" +#include "widget/combo-box.cpp" +#include "widget/edit-box.cpp" +#include "widget/hex-editor.cpp" +#include "widget/horizontal-slider.cpp" +#include "widget/label.cpp" +#include "widget/list-box.cpp" +#include "widget/progress-bar.cpp" +#include "widget/radio-box.cpp" +#include "widget/text-box.cpp" +#include "widget/vertical-slider.cpp" +#include "widget/viewport.cpp" Window Window::None; @@ -46,6 +58,8 @@ void OS::initialize() { if(initialized == true) return; initialized = true; + settings.load(); + int argc = 1; char *argv[2]; argv[0] = new char[8]; @@ -78,6 +92,7 @@ void OS::main() { } void OS::quit() { + settings.save(); gtk_main_quit(); } diff --git a/bsnes/phoenix/gtk/gtk.hpp b/bsnes/phoenix/gtk/gtk.hpp index 16531843..8a1acc8b 100755 --- a/bsnes/phoenix/gtk/gtk.hpp +++ b/bsnes/phoenix/gtk/gtk.hpp @@ -13,10 +13,10 @@ struct Object { }; struct Geometry { - unsigned x, y; + signed x, y; unsigned width, height; inline Geometry() : x(0), y(0), width(0), height(0) {} - inline Geometry(unsigned x, unsigned y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {} + inline Geometry(signed x, signed y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {} }; struct Font : Object { @@ -36,63 +36,24 @@ struct Font : Object { inline Font::Style operator|(Font::Style a, Font::Style b) { return (Font::Style)((unsigned)a | (unsigned)b); } inline Font::Style operator&(Font::Style a, Font::Style b) { return (Font::Style)((unsigned)a & (unsigned)b); } -struct Action : Object { - bool visible(); - void setVisible(bool visible = true); - bool enabled(); - void setEnabled(bool enabled = true); - Action(); -//private: - struct Data; - Data *action; -}; - -struct Menu : Action { - void create(Window &parent, const nall::string &text); - void create(Menu &parent, const nall::string &text); -}; - -struct MenuSeparator : Action { - void create(Menu &parent); -}; - -struct MenuItem : Action { - nall::function onTick; - void create(Menu &parent, const nall::string &text); -}; - -struct MenuCheckItem : Action { - nall::function onTick; - void create(Menu &parent, const nall::string &text); - bool checked(); - void setChecked(bool checked = true); -}; - -struct MenuRadioItem : Action { - nall::function onTick; - void create(Menu &parent, const nall::string &text); - void create(MenuRadioItem &parent, const nall::string &text); - bool checked(); - void setChecked(); -private: - MenuRadioItem *first; -}; - +struct Menu; struct Layout; struct Widget; struct Window : Object { + static Window None; nall::function onClose; nall::function onMove; - nall::function onResize; - void create(unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); + nall::function onSize; + void append(Menu &menu); void setLayout(Layout &layout); void setResizable(bool resizable = true); bool focused(); void setFocused(); Geometry frameGeometry(); Geometry geometry(); - void setGeometry(unsigned x, unsigned y, unsigned width, unsigned height); + void setFrameGeometry(signed x, signed y, unsigned width, unsigned height); + void setGeometry(signed x, signed y, unsigned width, unsigned height); void setDefaultFont(Font &font); void setFont(Font &font); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); @@ -107,13 +68,57 @@ struct Window : Object { //private: struct Data; Data *window; - static Window None; + void updateFrameGeometry(); +}; + +struct Action : Object { + bool visible(); + void setVisible(bool visible = true); + bool enabled(); + void setEnabled(bool enabled = true); + Action(); +//private: + struct Data; + Data *action; +}; + +struct Menu : Action { + void append(Action &action); + void setText(const nall::string &text); + Menu(); +}; + +struct MenuSeparator : Action { + MenuSeparator(); +}; + +struct MenuItem : Action { + nall::function onTick; + void setText(const nall::string &text); + MenuItem(); +}; + +struct MenuCheckItem : Action { + nall::function onTick; + void setText(const nall::string &text); + bool checked(); + void setChecked(bool checked = true); + MenuCheckItem(); +}; + +struct MenuRadioItem : Action { + nall::function onTick; + void setParent(MenuRadioItem &parent); + void setText(const nall::string &text); + bool checked(); + void setChecked(); + MenuRadioItem(); }; struct Layout : Object { virtual void setParent(Window &parent); + virtual void setGeometry(Geometry &geometry) = 0; virtual void append(Widget &widget); - virtual void update(Geometry &geometry) = 0; Layout(); //private: struct Data; @@ -255,8 +260,6 @@ struct RadioBox : Widget { bool checked(); void setChecked(); RadioBox(); -private: - RadioBox *first; }; struct TextBox : Widget { diff --git a/bsnes/phoenix/gtk/menu.cpp b/bsnes/phoenix/gtk/menu.cpp deleted file mode 100755 index fbfc67bc..00000000 --- a/bsnes/phoenix/gtk/menu.cpp +++ /dev/null @@ -1,129 +0,0 @@ -static void Action_setFont(GtkWidget *widget, gpointer font) { - if(font) { - gtk_widget_modify_font(widget, (PangoFontDescription*)font); - if(GTK_IS_CONTAINER(widget)) { - gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)Action_setFont, (PangoFontDescription*)font); - } - } -} - -bool Action::visible() { - return gtk_widget_get_visible(object->widget); -} - -void Action::setVisible(bool visible) { - gtk_widget_set_visible(object->widget, visible); -} - -bool Action::enabled() { - return gtk_widget_get_sensitive(object->widget); -} - -void Action::setEnabled(bool enabled) { - gtk_widget_set_sensitive(object->widget, enabled); -} - -Action::Action() { - action = new Action::Data; - action->font = 0; -} - -void Menu::create(Window &parent, const string &text) { - action->font = parent.window->defaultFont; - object->menu = gtk_menu_new(); - object->widget = gtk_menu_item_new_with_label(text); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(object->widget), object->menu); - if(action->font) Action_setFont(object->widget, action->font->font->font); - gtk_menu_bar_append(parent.object->menu, object->widget); - gtk_widget_show(object->widget); -} - -void Menu::create(Menu &parent, const string &text) { - action->font = parent.action->font; - object->menu = gtk_menu_new(); - object->widget = gtk_menu_item_new_with_label(text); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(object->widget), object->menu); - if(action->font) Action_setFont(object->widget, action->font->font->font); - gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget); - gtk_widget_show(object->widget); -} - -void MenuSeparator::create(Menu &parent) { - action->font = parent.action->font; - object->widget = gtk_separator_menu_item_new(); - if(action->font) Action_setFont(object->widget, action->font->font->font); - gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget); - gtk_widget_show(object->widget); -} - -static void MenuItem_tick(MenuItem *self) { - if(self->onTick) self->onTick(); -} - -void MenuItem::create(Menu &parent, const string &text) { - action->font = parent.action->font; - object->widget = gtk_menu_item_new_with_label(text); - g_signal_connect_swapped(G_OBJECT(object->widget), "activate", G_CALLBACK(MenuItem_tick), (gpointer)this); - if(action->font) Action_setFont(object->widget, action->font->font->font); - gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget); - gtk_widget_show(object->widget); -} - -static void MenuCheckItem_tick(MenuCheckItem *self) { - if(self->onTick && self->object->locked == false) self->onTick(); -} - -void MenuCheckItem::create(Menu &parent, const string &text) { - action->font = parent.action->font; - object->widget = gtk_check_menu_item_new_with_label(text); - g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(MenuCheckItem_tick), (gpointer)this); - if(action->font) Action_setFont(object->widget, action->font->font->font); - gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget); - gtk_widget_show(object->widget); -} - -bool MenuCheckItem::checked() { - return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(object->widget)); -} - -void MenuCheckItem::setChecked(bool state) { - object->locked = true; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(object->widget), state); - object->locked = false; -} - -static void MenuRadioItem_tick(MenuRadioItem *self) { - if(self->onTick && self->checked() && self->object->locked == false) self->onTick(); -} - -void MenuRadioItem::create(Menu &parent, const string &text) { - first = this; - action->font = parent.action->font; - object->parentMenu = &parent; - object->widget = gtk_radio_menu_item_new_with_label(0, text); - g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(MenuRadioItem_tick), (gpointer)this); - if(action->font) Action_setFont(object->widget, action->font->font->font); - gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget); - gtk_widget_show(object->widget); -} - -void MenuRadioItem::create(MenuRadioItem &parent, const string &text) { - first = parent.first; - action->font = parent.action->font; - object->parentMenu = parent.object->parentMenu; - object->widget = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(first->object->widget), text); - g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(MenuRadioItem_tick), (gpointer)this); - if(action->font) Action_setFont(object->widget, action->font->font->font); - gtk_menu_shell_append(GTK_MENU_SHELL(object->parentMenu->object->menu), object->widget); - gtk_widget_show(object->widget); -} - -bool MenuRadioItem::checked() { - return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(object->widget)); -} - -void MenuRadioItem::setChecked() { - object->locked = true; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(object->widget), true); - object->locked = false; -} diff --git a/bsnes/phoenix/gtk/messagewindow.cpp b/bsnes/phoenix/gtk/message-window.cpp similarity index 100% rename from bsnes/phoenix/gtk/messagewindow.cpp rename to bsnes/phoenix/gtk/message-window.cpp diff --git a/bsnes/phoenix/gtk/settings.cpp b/bsnes/phoenix/gtk/settings.cpp new file mode 100755 index 00000000..f90faaac --- /dev/null +++ b/bsnes/phoenix/gtk/settings.cpp @@ -0,0 +1,29 @@ +struct Settings : public configuration { + unsigned frameGeometryX; + unsigned frameGeometryY; + unsigned frameGeometryWidth; + unsigned frameGeometryHeight; + + void load() { + string path = { userpath(), ".config/phoenix/gtk.cfg" }; + configuration::load(path); + } + + void save() { + string path = { userpath(), ".config/" }; + mkdir(path, 0755); + path.append("phoenix/"); + mkdir(path, 0755); + path.append("gtk.cfg"); + configuration::save(path); + } + + Settings() { + attach(frameGeometryX = 0, "frameGeometryX"); + attach(frameGeometryY = 0, "frameGeometryY"); + attach(frameGeometryWidth = 0, "frameGeometryWidth"); + attach(frameGeometryHeight = 0, "frameGeometryHeight"); + } +}; + +static Settings settings; diff --git a/bsnes/phoenix/gtk/button.cpp b/bsnes/phoenix/gtk/widget/button.cpp similarity index 100% rename from bsnes/phoenix/gtk/button.cpp rename to bsnes/phoenix/gtk/widget/button.cpp diff --git a/bsnes/phoenix/gtk/canvas.cpp b/bsnes/phoenix/gtk/widget/canvas.cpp similarity index 100% rename from bsnes/phoenix/gtk/canvas.cpp rename to bsnes/phoenix/gtk/widget/canvas.cpp diff --git a/bsnes/phoenix/gtk/checkbox.cpp b/bsnes/phoenix/gtk/widget/check-box.cpp similarity index 100% rename from bsnes/phoenix/gtk/checkbox.cpp rename to bsnes/phoenix/gtk/widget/check-box.cpp diff --git a/bsnes/phoenix/gtk/combobox.cpp b/bsnes/phoenix/gtk/widget/combo-box.cpp similarity index 100% rename from bsnes/phoenix/gtk/combobox.cpp rename to bsnes/phoenix/gtk/widget/combo-box.cpp diff --git a/bsnes/phoenix/gtk/editbox.cpp b/bsnes/phoenix/gtk/widget/edit-box.cpp similarity index 100% rename from bsnes/phoenix/gtk/editbox.cpp rename to bsnes/phoenix/gtk/widget/edit-box.cpp diff --git a/bsnes/phoenix/gtk/hexeditor.cpp b/bsnes/phoenix/gtk/widget/hex-editor.cpp similarity index 100% rename from bsnes/phoenix/gtk/hexeditor.cpp rename to bsnes/phoenix/gtk/widget/hex-editor.cpp diff --git a/bsnes/phoenix/gtk/horizontalslider.cpp b/bsnes/phoenix/gtk/widget/horizontal-slider.cpp similarity index 100% rename from bsnes/phoenix/gtk/horizontalslider.cpp rename to bsnes/phoenix/gtk/widget/horizontal-slider.cpp diff --git a/bsnes/phoenix/gtk/label.cpp b/bsnes/phoenix/gtk/widget/label.cpp similarity index 100% rename from bsnes/phoenix/gtk/label.cpp rename to bsnes/phoenix/gtk/widget/label.cpp diff --git a/bsnes/phoenix/gtk/listbox.cpp b/bsnes/phoenix/gtk/widget/list-box.cpp similarity index 100% rename from bsnes/phoenix/gtk/listbox.cpp rename to bsnes/phoenix/gtk/widget/list-box.cpp diff --git a/bsnes/phoenix/gtk/progressbar.cpp b/bsnes/phoenix/gtk/widget/progress-bar.cpp similarity index 100% rename from bsnes/phoenix/gtk/progressbar.cpp rename to bsnes/phoenix/gtk/widget/progress-bar.cpp diff --git a/bsnes/phoenix/gtk/radiobox.cpp b/bsnes/phoenix/gtk/widget/radio-box.cpp similarity index 75% rename from bsnes/phoenix/gtk/radiobox.cpp rename to bsnes/phoenix/gtk/widget/radio-box.cpp index 2b13101a..42e07f93 100755 --- a/bsnes/phoenix/gtk/radiobox.cpp +++ b/bsnes/phoenix/gtk/widget/radio-box.cpp @@ -3,7 +3,11 @@ static void RadioBox_tick(RadioBox *self) { } void RadioBox::setParent(RadioBox &parent) { - first = parent.first; + gtk_radio_button_set_group( + GTK_RADIO_BUTTON(object->widget), + gtk_radio_button_get_group(GTK_RADIO_BUTTON(parent.object->widget)) + ); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(object->widget), false); } void RadioBox::setText(const string &text) { @@ -21,7 +25,7 @@ void RadioBox::setChecked() { } RadioBox::RadioBox() { - first = this; object->widget = gtk_radio_button_new_with_label(0, ""); +// setChecked(); g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(RadioBox_tick), (gpointer)this); } diff --git a/bsnes/phoenix/gtk/textbox.cpp b/bsnes/phoenix/gtk/widget/text-box.cpp similarity index 100% rename from bsnes/phoenix/gtk/textbox.cpp rename to bsnes/phoenix/gtk/widget/text-box.cpp diff --git a/bsnes/phoenix/gtk/verticalslider.cpp b/bsnes/phoenix/gtk/widget/vertical-slider.cpp similarity index 100% rename from bsnes/phoenix/gtk/verticalslider.cpp rename to bsnes/phoenix/gtk/widget/vertical-slider.cpp diff --git a/bsnes/phoenix/gtk/viewport.cpp b/bsnes/phoenix/gtk/widget/viewport.cpp similarity index 100% rename from bsnes/phoenix/gtk/viewport.cpp rename to bsnes/phoenix/gtk/widget/viewport.cpp diff --git a/bsnes/phoenix/gtk/widget.cpp b/bsnes/phoenix/gtk/widget/widget.cpp similarity index 100% rename from bsnes/phoenix/gtk/widget.cpp rename to bsnes/phoenix/gtk/widget/widget.cpp diff --git a/bsnes/phoenix/gtk/window.cpp b/bsnes/phoenix/gtk/window.cpp index c15bb4de..8cb59a31 100755 --- a/bsnes/phoenix/gtk/window.cpp +++ b/bsnes/phoenix/gtk/window.cpp @@ -1,3 +1,6 @@ +static void Action_setFont(GtkWidget *widget, gpointer font); +static void Widget_setFont(GtkWidget *widget, gpointer font); + static gint Window_close(Window *window) { if(window->onClose) { if(window->onClose()) window->setVisible(false); @@ -8,58 +11,33 @@ static gint Window_close(Window *window) { } static void Window_configure(GtkWindow *widget, GdkEvent *event, Window *window) { + if(gtk_widget_get_realized(window->object->widget) == false) return; + window->updateFrameGeometry(); + if(window->window->x != event->configure.x || window->window->y != event->configure.y) { window->window->x = event->configure.x; window->window->y = event->configure.y; + if(window->onMove) window->onMove(); } if(window->window->width != event->configure.width || window->window->height != event->configure.height) { window->window->width = event->configure.width; window->window->height = event->configure.height; + Geometry geom = window->geometry(); geom.x = geom.y = 0; - if(window->window->layout) window->window->layout->update(geom); - if(window->onResize) window->onResize(); + if(window->window->layout) window->window->layout->setGeometry(geom); + + if(window->onSize) window->onSize(); } } -void Window::create(unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - window->x = x; - window->y = y; - window->width = width; - window->height = height; - - object->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_move(GTK_WINDOW(object->widget), x, y); - - gtk_window_set_title(GTK_WINDOW(object->widget), text); - gtk_window_set_resizable(GTK_WINDOW(object->widget), true); - gtk_widget_set_app_paintable(object->widget, true); - - g_signal_connect_swapped(G_OBJECT(object->widget), "delete_event", G_CALLBACK(Window_close), (gpointer)this); - g_signal_connect(G_OBJECT(object->widget), "configure_event", G_CALLBACK(Window_configure), (gpointer)this); - - object->menuContainer = gtk_vbox_new(false, 0); - gtk_container_add(GTK_CONTAINER(object->widget), object->menuContainer); - gtk_widget_show(object->menuContainer); - - object->menu = gtk_menu_bar_new(); - gtk_box_pack_start(GTK_BOX(object->menuContainer), object->menu, false, false, 0); - - object->formContainer = gtk_fixed_new(); - gtk_widget_set_size_request(object->formContainer, width, height); - gtk_box_pack_start(GTK_BOX(object->menuContainer), object->formContainer, true, true, 0); - gtk_widget_show(object->formContainer); - - object->statusContainer = gtk_event_box_new(); - object->status = gtk_statusbar_new(); - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(object->status), false); - gtk_container_add(GTK_CONTAINER(object->statusContainer), object->status); - gtk_box_pack_start(GTK_BOX(object->menuContainer), object->statusContainer, false, false, 0); - gtk_widget_show(object->statusContainer); - - gtk_widget_realize(object->widget); +void Window::append(Menu &menu) { + menu.action->font = window->defaultFont; + if(window->defaultFont) Action_setFont(menu.object->widget, window->defaultFont->font->font); + gtk_menu_bar_append(object->menu, menu.object->widget); + gtk_widget_show(menu.object->widget); } void Window::setLayout(Layout &layout) { @@ -67,7 +45,7 @@ void Window::setLayout(Layout &layout) { layout.setParent(*this); Geometry geom = geometry(); geom.x = geom.y = 0; - layout.update(geom); + layout.setGeometry(geom); } void Window::setResizable(bool resizable) { @@ -84,15 +62,31 @@ void Window::setFocused() { } Geometry Window::frameGeometry() { + return { + window->x - settings.frameGeometryX, window->y - settings.frameGeometryY, + window->width + settings.frameGeometryWidth, window->height + settings.frameGeometryHeight + }; } Geometry Window::geometry() { return { window->x, window->y, window->width, window->height }; } -void Window::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height) { - gtk_window_move(GTK_WINDOW(object->widget), window->x = x, window->y = y); - gtk_widget_set_size_request(object->formContainer, window->width = width, window->height = height); +void Window::setFrameGeometry(signed x, signed y, unsigned width, unsigned height) { + setGeometry( + x + settings.frameGeometryX, y + settings.frameGeometryY, + width - settings.frameGeometryWidth, height - settings.frameGeometryHeight + ); +} + +void Window::setGeometry(signed x, signed y, unsigned width, unsigned height) { + window->x = x; + window->y = y; + window->width = width; + window->height = height; + + gtk_window_move(GTK_WINDOW(object->widget), x - settings.frameGeometryX, y - settings.frameGeometryY); + gtk_widget_set_size_request(object->formContainer, width, height); } void Window::setDefaultFont(Font &font) { @@ -156,10 +150,57 @@ Window::Window() { window = new Window::Data; window->layout = 0; window->defaultFont = 0; - window->resizable = false; + window->resizable = true; window->fullscreen = false; - window->x = 0; - window->y = 0; - window->width = 0; - window->height = 0; + window->x = 128; + window->y = 128; + window->width = 256; + window->height = 256; + + object->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_move(GTK_WINDOW(object->widget), window->x, window->y); + + gtk_window_set_resizable(GTK_WINDOW(object->widget), window->resizable); + gtk_widget_set_app_paintable(object->widget, true); + + object->menuContainer = gtk_vbox_new(false, 0); + gtk_container_add(GTK_CONTAINER(object->widget), object->menuContainer); + gtk_widget_show(object->menuContainer); + + object->menu = gtk_menu_bar_new(); + gtk_box_pack_start(GTK_BOX(object->menuContainer), object->menu, false, false, 0); + + object->formContainer = gtk_fixed_new(); + gtk_widget_set_size_request(object->formContainer, window->width, window->height); + gtk_box_pack_start(GTK_BOX(object->menuContainer), object->formContainer, true, true, 0); + gtk_widget_show(object->formContainer); + + object->statusContainer = gtk_event_box_new(); + object->status = gtk_statusbar_new(); + gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(object->status), false); + gtk_container_add(GTK_CONTAINER(object->statusContainer), object->status); + gtk_box_pack_start(GTK_BOX(object->menuContainer), object->statusContainer, false, false, 0); + gtk_widget_show(object->statusContainer); + + g_signal_connect_swapped(G_OBJECT(object->widget), "delete_event", G_CALLBACK(Window_close), (gpointer)this); + g_signal_connect(G_OBJECT(object->widget), "configure_event", G_CALLBACK(Window_configure), (gpointer)this); +} + +//internal + +void Window::updateFrameGeometry() { + Display *display = XOpenDisplay(0); + XWindowAttributes attributes, parentAttributes; + XGetWindowAttributes(display, GDK_WINDOW_XID(object->widget->window), &attributes); + X11Window rootWindow, parentWindow, *childWindow = 0; + unsigned int childCount; + XQueryTree(display, GDK_WINDOW_XID(object->widget->window), &rootWindow, &parentWindow, &childWindow, &childCount); + XGetWindowAttributes(display, parentWindow, &parentAttributes); + if(childWindow) XFree(childWindow); + XCloseDisplay(display); + + settings.frameGeometryX = attributes.x; + settings.frameGeometryY = attributes.y; + settings.frameGeometryWidth = parentAttributes.width - attributes.width; + settings.frameGeometryHeight = parentAttributes.height - attributes.height; } diff --git a/bsnes/phoenix/layout/fixed-layout.cpp b/bsnes/phoenix/layout/fixed-layout.cpp index b442599a..cda1f345 100755 --- a/bsnes/phoenix/layout/fixed-layout.cpp +++ b/bsnes/phoenix/layout/fixed-layout.cpp @@ -10,7 +10,7 @@ void FixedLayout::append(Widget &widget, unsigned x, unsigned y, unsigned width, children.append({ &widget, x, y, width, height }); } -void FixedLayout::update(Geometry &geometry) { +void FixedLayout::setGeometry(Geometry &geometry) { } FixedLayout::FixedLayout() { diff --git a/bsnes/phoenix/layout/fixed-layout.hpp b/bsnes/phoenix/layout/fixed-layout.hpp index c686d6e8..d967ca6c 100755 --- a/bsnes/phoenix/layout/fixed-layout.hpp +++ b/bsnes/phoenix/layout/fixed-layout.hpp @@ -1,7 +1,7 @@ struct FixedLayout : public Layout { void setParent(Window &parent); + void setGeometry(Geometry &geometry); void append(Widget &widget, unsigned x, unsigned y, unsigned width, unsigned height); - void update(Geometry &geometry); FixedLayout(); //private: diff --git a/bsnes/phoenix/layout/horizontal-layout.cpp b/bsnes/phoenix/layout/horizontal-layout.cpp index 5a80c084..49931363 100755 --- a/bsnes/phoenix/layout/horizontal-layout.cpp +++ b/bsnes/phoenix/layout/horizontal-layout.cpp @@ -7,6 +7,8 @@ void HorizontalLayout::setParent(Window &parent) { } void HorizontalLayout::append(VerticalLayout &layout, unsigned width, unsigned height, unsigned spacing) { + layout.width = width; + layout.height = height; children.append({ &layout, 0, width, height, spacing }); } @@ -14,12 +16,15 @@ void HorizontalLayout::append(Widget &widget, unsigned width, unsigned height, u children.append({ 0, &widget, width, height, spacing }); } -void HorizontalLayout::update(Geometry &geometry) { +void HorizontalLayout::setGeometry(Geometry &geometry) { geometry.x += margin; geometry.y += margin; geometry.width -= margin * 2; geometry.height -= margin * 2; + unsigned geometryWidth = width ? width : geometry.width; + unsigned geometryHeight = height ? height : geometry.height; + Geometry baseGeometry = geometry; linear_vector children = this->children; @@ -31,8 +36,8 @@ void HorizontalLayout::update(Geometry &geometry) { if(child.width == 0) autosizeWidgets++; } foreach(child, children) { - if(child.width == 0) child.width = (geometry.width - minimumWidth) / autosizeWidgets; - if(child.height == 0) child.height = geometry.height; + if(child.width == 0) child.width = (geometryWidth - minimumWidth) / autosizeWidgets; + if(child.height == 0) child.height = geometryHeight; } unsigned maxHeight = 0; @@ -42,7 +47,7 @@ void HorizontalLayout::update(Geometry &geometry) { foreach(child, children) { if(child.layout) { - child.layout->update(geometry); + child.layout->setGeometry(geometry); geometry.x += child.spacing; geometry.width -= child.spacing; geometry.y = baseGeometry.y; @@ -64,6 +69,14 @@ void HorizontalLayout::setMargin(unsigned margin_) { margin = margin_; } +unsigned HorizontalLayout::minimumWidth() { + unsigned width = margin * 2; + foreach(child, children) width += child.width + child.spacing; + return width; +} + HorizontalLayout::HorizontalLayout() { margin = 0; + width = 0; + height = 0; } diff --git a/bsnes/phoenix/layout/horizontal-layout.hpp b/bsnes/phoenix/layout/horizontal-layout.hpp index 7c61bdeb..03c8706b 100755 --- a/bsnes/phoenix/layout/horizontal-layout.hpp +++ b/bsnes/phoenix/layout/horizontal-layout.hpp @@ -2,14 +2,17 @@ struct VerticalLayout; struct HorizontalLayout : public Layout { void setParent(Window &parent); + void setGeometry(Geometry &geometry); void append(VerticalLayout &layout, unsigned width, unsigned height, unsigned spacing = 0); void append(Widget &widget, unsigned width, unsigned height, unsigned spacing = 0); - void update(Geometry &geometry); void setMargin(unsigned margin); + unsigned minimumWidth(); HorizontalLayout(); //private: unsigned margin; + unsigned width; + unsigned height; struct Children { VerticalLayout *layout; Widget *widget; diff --git a/bsnes/phoenix/layout/vertical-layout.cpp b/bsnes/phoenix/layout/vertical-layout.cpp index fc07c763..b544ced8 100755 --- a/bsnes/phoenix/layout/vertical-layout.cpp +++ b/bsnes/phoenix/layout/vertical-layout.cpp @@ -7,6 +7,8 @@ void VerticalLayout::setParent(Window &parent) { } void VerticalLayout::append(HorizontalLayout &layout, unsigned width, unsigned height, unsigned spacing) { + layout.width = width; + layout.height = height; children.append({ &layout, 0, width, height, spacing }); } @@ -14,12 +16,15 @@ void VerticalLayout::append(Widget &widget, unsigned width, unsigned height, uns children.append({ 0, &widget, width, height, spacing }); } -void VerticalLayout::update(Geometry &geometry) { +void VerticalLayout::setGeometry(Geometry &geometry) { geometry.x += margin; geometry.y += margin; geometry.width -= margin * 2; geometry.height -= margin * 2; + unsigned geometryWidth = width ? width : geometry.width; + unsigned geometryHeight = height ? height : geometry.height; + Geometry baseGeometry = geometry; linear_vector children = this->children; @@ -31,8 +36,8 @@ void VerticalLayout::update(Geometry &geometry) { if(child.height == 0) autosizeWidgets++; } foreach(child, children) { - if(child.width == 0) child.width = geometry.width; - if(child.height == 0) child.height = (geometry.height - minimumHeight) / autosizeWidgets; + if(child.width == 0) child.width = geometryWidth; + if(child.height == 0) child.height = (geometryHeight - minimumHeight) / autosizeWidgets; } unsigned maxWidth = 0; @@ -42,7 +47,7 @@ void VerticalLayout::update(Geometry &geometry) { foreach(child, children) { if(child.layout) { - child.layout->update(geometry); + child.layout->setGeometry(geometry); geometry.x = baseGeometry.x; geometry.width = baseGeometry.width; geometry.y += child.spacing; @@ -64,6 +69,14 @@ void VerticalLayout::setMargin(unsigned margin_) { margin = margin_; } +unsigned VerticalLayout::minimumHeight() { + unsigned height = margin * 2; + foreach(child, children) height += child.height + child.spacing; + return height; +} + VerticalLayout::VerticalLayout() { margin = 0; + width = 0; + height = 0; } diff --git a/bsnes/phoenix/layout/vertical-layout.hpp b/bsnes/phoenix/layout/vertical-layout.hpp index e1b6b058..33ca253c 100755 --- a/bsnes/phoenix/layout/vertical-layout.hpp +++ b/bsnes/phoenix/layout/vertical-layout.hpp @@ -2,14 +2,17 @@ struct HorizontalLayout; struct VerticalLayout : public Layout { void setParent(Window &parent); + void setGeometry(Geometry &geometry); void append(HorizontalLayout &layout, unsigned width, unsigned height, unsigned spacing = 0); void append(Widget &widget, unsigned width, unsigned height, unsigned spacing = 0); - void update(Geometry &geometry); void setMargin(unsigned margin); + unsigned minimumHeight(); VerticalLayout(); //private: unsigned margin; + unsigned width; + unsigned height; struct Children { HorizontalLayout *layout; Widget *widget; diff --git a/bsnes/phoenix/qt/action/action.cpp b/bsnes/phoenix/qt/action/action.cpp new file mode 100755 index 00000000..e69de29b diff --git a/bsnes/phoenix/qt/action/menu-check-item.cpp b/bsnes/phoenix/qt/action/menu-check-item.cpp new file mode 100755 index 00000000..be0d0fcf --- /dev/null +++ b/bsnes/phoenix/qt/action/menu-check-item.cpp @@ -0,0 +1,33 @@ +void MenuCheckItem::setText(const string &text) { + menuCheckItem->setText(QString::fromUtf8(text)); +} + +bool MenuCheckItem::visible() { + return menuCheckItem->isVisible(); +} + +void MenuCheckItem::setVisible(bool visible) { + menuCheckItem->setVisible(visible); +} + +bool MenuCheckItem::enabled() { + return menuCheckItem->isEnabled(); +} + +void MenuCheckItem::setEnabled(bool enabled) { + menuCheckItem->setEnabled(enabled); +} + +bool MenuCheckItem::checked() { + return menuCheckItem->isChecked(); +} + +void MenuCheckItem::setChecked(bool checked) { + menuCheckItem->setChecked(checked); +} + +MenuCheckItem::MenuCheckItem() { + menuCheckItem = new MenuCheckItem::Data(*this); + menuCheckItem->setCheckable(true); + menuCheckItem->connect(menuCheckItem, SIGNAL(triggered()), SLOT(onTick())); +} diff --git a/bsnes/phoenix/qt/action/menu-item.cpp b/bsnes/phoenix/qt/action/menu-item.cpp new file mode 100755 index 00000000..7cc6c744 --- /dev/null +++ b/bsnes/phoenix/qt/action/menu-item.cpp @@ -0,0 +1,24 @@ +void MenuItem::setText(const string &text) { + menuItem->setText(QString::fromUtf8(text)); +} + +bool MenuItem::visible() { + return menuItem->isVisible(); +} + +void MenuItem::setVisible(bool visible) { + menuItem->setVisible(visible); +} + +bool MenuItem::enabled() { + return menuItem->isEnabled(); +} + +void MenuItem::setEnabled(bool enabled) { + menuItem->setEnabled(enabled); +} + +MenuItem::MenuItem() { + menuItem = new MenuItem::Data(*this); + menuItem->connect(menuItem, SIGNAL(triggered()), SLOT(onTick())); +} diff --git a/bsnes/phoenix/qt/action/menu-radio-item.cpp b/bsnes/phoenix/qt/action/menu-radio-item.cpp new file mode 100755 index 00000000..2e58c248 --- /dev/null +++ b/bsnes/phoenix/qt/action/menu-radio-item.cpp @@ -0,0 +1,41 @@ +void MenuRadioItem::setParent(MenuRadioItem &parent) { + delete menuRadioItem->actionGroup(); + menuRadioItem->setActionGroup(parent.menuRadioItem->actionGroup()); +} + +void MenuRadioItem::setText(const string &text) { + menuRadioItem->setText(QString::fromUtf8(text)); +} + +bool MenuRadioItem::visible() { + return menuRadioItem->isVisible(); +} + +void MenuRadioItem::setVisible(bool visible) { + menuRadioItem->setVisible(visible); +} + +bool MenuRadioItem::enabled() { + return menuRadioItem->isEnabled(); +} + +void MenuRadioItem::setEnabled(bool enabled) { + menuRadioItem->setEnabled(enabled); +} + +bool MenuRadioItem::checked() { + return menuRadioItem->isChecked(); +} + +void MenuRadioItem::setChecked() { + object->locked = true; + menuRadioItem->setChecked(true); + object->locked = false; +} + +MenuRadioItem::MenuRadioItem() { + menuRadioItem = new MenuRadioItem::Data(*this); + menuRadioItem->setCheckable(true); + menuRadioItem->setActionGroup(new QActionGroup(0)); + menuRadioItem->connect(menuRadioItem, SIGNAL(changed()), SLOT(onTick())); +} diff --git a/bsnes/phoenix/qt/action/menu-separator.cpp b/bsnes/phoenix/qt/action/menu-separator.cpp new file mode 100755 index 00000000..c3cfc778 --- /dev/null +++ b/bsnes/phoenix/qt/action/menu-separator.cpp @@ -0,0 +1,19 @@ +bool MenuSeparator::visible() { + return menuSeparator->action->isVisible(); +} + +void MenuSeparator::setVisible(bool visible) { + menuSeparator->action->setVisible(visible); +} + +bool MenuSeparator::enabled() { + return menuSeparator->action->isEnabled(); +} + +void MenuSeparator::setEnabled(bool enabled) { + menuSeparator->action->setEnabled(enabled); +} + +MenuSeparator::MenuSeparator() { + menuSeparator = new MenuSeparator::Data(*this); +} diff --git a/bsnes/phoenix/qt/action/menu.cpp b/bsnes/phoenix/qt/action/menu.cpp new file mode 100755 index 00000000..54ec1ff9 --- /dev/null +++ b/bsnes/phoenix/qt/action/menu.cpp @@ -0,0 +1,39 @@ +void Menu::setText(const string &text) { + menu->setTitle(QString::fromUtf8(text)); +} + +void Menu::append(Action &item) { + if(dynamic_cast(&item)) { + menu->addMenu(((Menu*)&item)->menu); + } else if(dynamic_cast(&item)) { + menu->addSeparator(); + } else if(dynamic_cast(&item)) { + menu->addAction(((MenuItem*)&item)->menuItem); + } else if(dynamic_cast(&item)) { + menu->addAction(((MenuCheckItem*)&item)->menuCheckItem); + } else if(dynamic_cast(&item)) { + MenuRadioItem &radioItem = (MenuRadioItem&)item; + menu->addAction(radioItem.menuRadioItem); + if(radioItem.menuRadioItem->actionGroup()->checkedAction() == 0) radioItem.setChecked(); + } +} + +bool Menu::visible() { + return menu->isVisible(); +} + +void Menu::setVisible(bool visible) { + menu->setVisible(visible); +} + +bool Menu::enabled() { + return menu->isEnabled(); +} + +void Menu::setEnabled(bool enabled) { + menu->setEnabled(enabled); +} + +Menu::Menu() { + menu = new Menu::Data(*this); +} diff --git a/bsnes/phoenix/qt/menu.cpp b/bsnes/phoenix/qt/menu.cpp deleted file mode 100755 index 8e6fa819..00000000 --- a/bsnes/phoenix/qt/menu.cpp +++ /dev/null @@ -1,169 +0,0 @@ -void Menu::create(Window &parent, const string &text) { - menu->parent = &parent; - if(menu->parent->window->defaultFont) menu->setFont(*menu->parent->window->defaultFont); - menu->setTitle(QString::fromUtf8(text)); - parent.window->menuBar->addMenu(menu); -} - -void Menu::create(Menu &parent, const string &text) { - menu->parent = parent.menu->parent; - if(menu->parent->window->defaultFont) menu->setFont(*menu->parent->window->defaultFont); - menu->setTitle(QString::fromUtf8(text)); - parent.menu->addMenu(menu); -} - -bool Menu::visible() { - return menu->isVisible(); -} - -void Menu::setVisible(bool visible) { - menu->setVisible(visible); -} - -bool Menu::enabled() { - return menu->isEnabled(); -} - -void Menu::setEnabled(bool enabled) { - menu->setEnabled(enabled); -} - -Menu::Menu() { - menu = new Menu::Data(*this); -} - -void MenuSeparator::create(Menu &parent) { - menuSeparator->action = parent.menu->addSeparator(); -} - -bool MenuSeparator::visible() { - return menuSeparator->action->isVisible(); -} - -void MenuSeparator::setVisible(bool visible) { - menuSeparator->action->setVisible(visible); -} - -bool MenuSeparator::enabled() { - return menuSeparator->action->isEnabled(); -} - -void MenuSeparator::setEnabled(bool enabled) { - menuSeparator->action->setEnabled(enabled); -} - -MenuSeparator::MenuSeparator() { - menuSeparator = new MenuSeparator::Data(*this); -} - -void MenuItem::create(Menu &parent, const string &text) { - menuItem->setText(QString::fromUtf8(text)); - menuItem->connect(menuItem, SIGNAL(triggered()), SLOT(onTick())); - parent.menu->addAction(menuItem); -} - -bool MenuItem::visible() { - return menuItem->isVisible(); -} - -void MenuItem::setVisible(bool visible) { - menuItem->setVisible(visible); -} - -bool MenuItem::enabled() { - return menuItem->isEnabled(); -} - -void MenuItem::setEnabled(bool enabled) { - menuItem->setEnabled(enabled); -} - -MenuItem::MenuItem() { - menuItem = new MenuItem::Data(*this); -} - -void MenuCheckItem::create(Menu &parent, const string &text) { - menuCheckItem->setText(QString::fromUtf8(text)); - menuCheckItem->setCheckable(true); - menuCheckItem->connect(menuCheckItem, SIGNAL(triggered()), SLOT(onTick())); - parent.menu->addAction(menuCheckItem); -} - -bool MenuCheckItem::visible() { - return menuCheckItem->isVisible(); -} - -void MenuCheckItem::setVisible(bool visible) { - menuCheckItem->setVisible(visible); -} - -bool MenuCheckItem::enabled() { - return menuCheckItem->isEnabled(); -} - -void MenuCheckItem::setEnabled(bool enabled) { - menuCheckItem->setEnabled(enabled); -} - -bool MenuCheckItem::checked() { - return menuCheckItem->isChecked(); -} - -void MenuCheckItem::setChecked(bool checked) { - menuCheckItem->setChecked(checked); -} - -MenuCheckItem::MenuCheckItem() { - menuCheckItem = new MenuCheckItem::Data(*this); -} - -void MenuRadioItem::create(Menu &parent, const string &text) { - menuRadioItem->parent = &parent; - menuRadioItem->actionGroup = new QActionGroup(0); - menuRadioItem->actionGroup->addAction(menuRadioItem); - menuRadioItem->setText(QString::fromUtf8(text)); - menuRadioItem->setCheckable(true); - menuRadioItem->setChecked(true); - menuRadioItem->connect(menuRadioItem, SIGNAL(changed()), SLOT(onTick())); - menuRadioItem->parent->menu->addAction(menuRadioItem); -} - -void MenuRadioItem::create(MenuRadioItem &parent, const string &text) { - menuRadioItem->parent = parent.menuRadioItem->parent; - menuRadioItem->actionGroup = parent.menuRadioItem->actionGroup; - menuRadioItem->actionGroup->addAction(menuRadioItem); - menuRadioItem->setText(QString::fromUtf8(text)); - menuRadioItem->setCheckable(true); - menuRadioItem->connect(menuRadioItem, SIGNAL(changed()), SLOT(onTick())); - menuRadioItem->parent->menu->addAction(menuRadioItem); -} - -bool MenuRadioItem::visible() { - return menuRadioItem->isVisible(); -} - -void MenuRadioItem::setVisible(bool visible) { - menuRadioItem->setVisible(visible); -} - -bool MenuRadioItem::enabled() { - return menuRadioItem->isEnabled(); -} - -void MenuRadioItem::setEnabled(bool enabled) { - menuRadioItem->setEnabled(enabled); -} - -bool MenuRadioItem::checked() { - return menuRadioItem->isChecked(); -} - -void MenuRadioItem::setChecked() { - object->locked = true; - menuRadioItem->setChecked(true); - object->locked = false; -} - -MenuRadioItem::MenuRadioItem() { - menuRadioItem = new MenuRadioItem::Data(*this); -} diff --git a/bsnes/phoenix/qt/messagewindow.cpp b/bsnes/phoenix/qt/message-window.cpp similarity index 100% rename from bsnes/phoenix/qt/messagewindow.cpp rename to bsnes/phoenix/qt/message-window.cpp diff --git a/bsnes/phoenix/qt/qt.cpp b/bsnes/phoenix/qt/qt.cpp index 83495f8e..f1529e54 100755 --- a/bsnes/phoenix/qt/qt.cpp +++ b/bsnes/phoenix/qt/qt.cpp @@ -1,5 +1,8 @@ #include #include + +#include +#include using namespace nall; namespace phoenix { @@ -7,27 +10,35 @@ namespace phoenix { #include "qt.moc.hpp" #include "qt.moc" +#include "settings.cpp" #include "object.cpp" #include "font.cpp" -#include "menu.cpp" #include "window.cpp" -#include "widget.cpp" #include "layout.cpp" -#include "button.cpp" -#include "canvas.cpp" -#include "checkbox.cpp" -#include "combobox.cpp" -#include "editbox.cpp" -#include "hexeditor.cpp" -#include "horizontalslider.cpp" -#include "label.cpp" -#include "listbox.cpp" -#include "progressbar.cpp" -#include "radiobox.cpp" -#include "textbox.cpp" -#include "verticalslider.cpp" -#include "viewport.cpp" -#include "messagewindow.cpp" +#include "message-window.cpp" + +#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 "widget/widget.cpp" +#include "widget/button.cpp" +#include "widget/canvas.cpp" +#include "widget/check-box.cpp" +#include "widget/combo-box.cpp" +#include "widget/edit-box.cpp" +#include "widget/hex-editor.cpp" +#include "widget/horizontal-slider.cpp" +#include "widget/label.cpp" +#include "widget/list-box.cpp" +#include "widget/progress-bar.cpp" +#include "widget/radio-box.cpp" +#include "widget/text-box.cpp" +#include "widget/vertical-slider.cpp" +#include "widget/viewport.cpp" OS::Data *OS::os = 0; Window Window::None; @@ -37,6 +48,8 @@ void OS::initialize() { if(initialized == true) return; initialized = true; + settings.load(); + os = new OS::Data; static int argc = 1; static char *argv[2]; @@ -60,6 +73,7 @@ void OS::main() { } void OS::quit() { + settings.save(); QApplication::quit(); } diff --git a/bsnes/phoenix/qt/qt.hpp b/bsnes/phoenix/qt/qt.hpp index cbc81930..1a7444e4 100755 --- a/bsnes/phoenix/qt/qt.hpp +++ b/bsnes/phoenix/qt/qt.hpp @@ -13,10 +13,10 @@ struct Object { }; struct Geometry { - unsigned x, y; + signed x, y; unsigned width, height; inline Geometry() : x(0), y(0), width(0), height(0) {} - inline Geometry(unsigned x, unsigned y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {} + inline Geometry(signed x, signed y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {} }; struct Font : Object { @@ -36,95 +36,22 @@ struct Font : Object { inline Font::Style operator|(Font::Style a, Font::Style b) { return (Font::Style)((unsigned)a | (unsigned)b); } inline Font::Style operator&(Font::Style a, Font::Style b) { return (Font::Style)((unsigned)a & (unsigned)b); } -struct Action : Object { - virtual bool visible() = 0; - virtual void setVisible(bool visible = true) = 0; - virtual bool enabled() = 0; - virtual void setEnabled(bool enabled = true) = 0; -}; - -struct Menu : Action { - void create(Window &parent, const nall::string &text); - void create(Menu &parent, const nall::string &text); - bool visible(); - void setVisible(bool visible = true); - bool enabled(); - void setEnabled(bool enabled = true); - Menu(); -//private: - struct Data; - Data *menu; -}; - -struct MenuSeparator : Action { - void create(Menu &parent); - bool visible(); - void setVisible(bool visible = true); - bool enabled(); - void setEnabled(bool enabled = true); - MenuSeparator(); -//private: - struct Data; - Data *menuSeparator; -}; - -struct MenuItem : Action { - nall::function onTick; - void create(Menu &parent, const nall::string &text); - bool visible(); - void setVisible(bool visible = true); - bool enabled(); - void setEnabled(bool enabled = true); - MenuItem(); -//private: - struct Data; - Data *menuItem; -}; - -struct MenuCheckItem : Action { - nall::function onTick; - void create(Menu &parent, const nall::string &text); - bool visible(); - void setVisible(bool visible = true); - bool enabled(); - void setEnabled(bool enabled = true); - bool checked(); - void setChecked(bool checked = true); - MenuCheckItem(); -//private: - struct Data; - Data *menuCheckItem; -}; - -struct MenuRadioItem : Action { - nall::function onTick; - void create(Menu &parent, const nall::string &text); - void create(MenuRadioItem &parent, const nall::string &text); - bool visible(); - void setVisible(bool visible = true); - bool enabled(); - void setEnabled(bool enabled = true); - bool checked(); - void setChecked(); - MenuRadioItem(); -//private: - struct Data; - Data *menuRadioItem; -}; - +struct Menu; struct Layout; struct Widget; struct Window : Object { + static Window None; nall::function onClose; nall::function onMove; - nall::function onResize; - void create(unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); + nall::function onSize; + void append(Menu &menu); void setLayout(Layout &layout); void setResizable(bool resizable = true); Geometry frameGeometry(); Geometry geometry(); - void setGeometry(unsigned x, unsigned y, unsigned width, unsigned height); + void setFrameGeometry(signed x, signed y, unsigned width, unsigned height); + void setGeometry(signed x, signed y, unsigned width, unsigned height); void setDefaultFont(Font &font); void setFont(Font &font); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); @@ -140,13 +67,89 @@ struct Window : Object { //private: struct Data; Data *window; - static Window None; +private: + void updateFrameGeometry(); +}; + +struct Action : Object { + virtual bool visible() = 0; + virtual void setVisible(bool visible = true) = 0; + virtual bool enabled() = 0; + virtual void setEnabled(bool enabled = true) = 0; +}; + +struct Menu : Action { + void append(Action &action); + void setText(const nall::string &text); + bool visible(); + void setVisible(bool visible = true); + bool enabled(); + void setEnabled(bool enabled = true); + Menu(); +//private: + struct Data; + Data *menu; +}; + +struct MenuSeparator : Action { + bool visible(); + void setVisible(bool visible = true); + bool enabled(); + void setEnabled(bool enabled = true); + MenuSeparator(); +//private: + struct Data; + Data *menuSeparator; +}; + +struct MenuItem : Action { + nall::function onTick; + void setText(const nall::string &text); + bool visible(); + void setVisible(bool visible = true); + bool enabled(); + void setEnabled(bool enabled = true); + MenuItem(); +//private: + struct Data; + Data *menuItem; +}; + +struct MenuCheckItem : Action { + nall::function onTick; + void setText(const nall::string &text); + bool visible(); + void setVisible(bool visible = true); + bool enabled(); + void setEnabled(bool enabled = true); + bool checked(); + void setChecked(bool checked = true); + MenuCheckItem(); +//private: + struct Data; + Data *menuCheckItem; +}; + +struct MenuRadioItem : Action { + nall::function onTick; + void setParent(MenuRadioItem &parent); + void setText(const nall::string &text); + bool visible(); + void setVisible(bool visible = true); + bool enabled(); + void setEnabled(bool enabled = true); + bool checked(); + void setChecked(); + MenuRadioItem(); +//private: + struct Data; + Data *menuRadioItem; }; struct Layout : Object { virtual void setParent(Window &parent); + virtual void setGeometry(Geometry &geometry) = 0; virtual void append(Widget &widget); - virtual void update(Geometry &geometry) = 0; Layout(); //private: struct Data; diff --git a/bsnes/phoenix/qt/qt.moc b/bsnes/phoenix/qt/qt.moc index cead6899..3925cb64 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: Mon Feb 7 01:23:56 2011 +** Created: Tue Feb 8 19:56:49 2011 ** by: The Qt Meta Object Compiler version 62 (Qt 4.6.2) ** ** WARNING! All changes made in this file will be lost! diff --git a/bsnes/phoenix/qt/qt.moc.hpp b/bsnes/phoenix/qt/qt.moc.hpp index cb92ef73..cc8b85c7 100755 --- a/bsnes/phoenix/qt/qt.moc.hpp +++ b/bsnes/phoenix/qt/qt.moc.hpp @@ -1,3 +1,13 @@ +struct Settings : public configuration { + unsigned frameGeometryX; + unsigned frameGeometryY; + unsigned frameGeometryWidth; + unsigned frameGeometryHeight; + + void load(); + void save(); +}; + struct Object::Data { public: Object &self; @@ -69,8 +79,6 @@ struct MenuRadioItem::Data : public QAction { public: MenuRadioItem &self; - Menu *parent; - QActionGroup *actionGroup; Data(MenuRadioItem &self) : self(self), QAction(0) { } @@ -129,11 +137,11 @@ public: if(layout) { Geometry geom = self.geometry(); geom.x = geom.y = 0; - layout->update(geom); + layout->setGeometry(geom); } - if(self.object->locked == false && self.onResize) { - self.onResize(); + if(self.object->locked == false && self.onSize) { + self.onSize(); } } diff --git a/bsnes/phoenix/qt/settings.cpp b/bsnes/phoenix/qt/settings.cpp new file mode 100755 index 00000000..d6c42386 --- /dev/null +++ b/bsnes/phoenix/qt/settings.cpp @@ -0,0 +1,20 @@ +static Settings settings; + +void Settings::load() { + attach(frameGeometryX = 0, "frameGeometryX"); + attach(frameGeometryY = 0, "frameGeometryY"); + attach(frameGeometryWidth = 0, "frameGeometryWidth"); + attach(frameGeometryHeight = 0, "frameGeometryHeight"); + + string path = { userpath(), ".config/phoenix/qt.cfg" }; + configuration::load(path); +} + +void Settings::save() { + string path = { userpath(), ".config/" }; + mkdir(path, 0755); + path.append("phoenix/"); + mkdir(path, 0755); + path.append("qt.cfg"); + configuration::save(path); +} diff --git a/bsnes/phoenix/qt/button.cpp b/bsnes/phoenix/qt/widget/button.cpp similarity index 100% rename from bsnes/phoenix/qt/button.cpp rename to bsnes/phoenix/qt/widget/button.cpp diff --git a/bsnes/phoenix/qt/canvas.cpp b/bsnes/phoenix/qt/widget/canvas.cpp similarity index 100% rename from bsnes/phoenix/qt/canvas.cpp rename to bsnes/phoenix/qt/widget/canvas.cpp diff --git a/bsnes/phoenix/qt/checkbox.cpp b/bsnes/phoenix/qt/widget/check-box.cpp similarity index 100% rename from bsnes/phoenix/qt/checkbox.cpp rename to bsnes/phoenix/qt/widget/check-box.cpp diff --git a/bsnes/phoenix/qt/combobox.cpp b/bsnes/phoenix/qt/widget/combo-box.cpp similarity index 100% rename from bsnes/phoenix/qt/combobox.cpp rename to bsnes/phoenix/qt/widget/combo-box.cpp diff --git a/bsnes/phoenix/qt/editbox.cpp b/bsnes/phoenix/qt/widget/edit-box.cpp similarity index 100% rename from bsnes/phoenix/qt/editbox.cpp rename to bsnes/phoenix/qt/widget/edit-box.cpp diff --git a/bsnes/phoenix/qt/hexeditor.cpp b/bsnes/phoenix/qt/widget/hex-editor.cpp similarity index 100% rename from bsnes/phoenix/qt/hexeditor.cpp rename to bsnes/phoenix/qt/widget/hex-editor.cpp diff --git a/bsnes/phoenix/qt/horizontalslider.cpp b/bsnes/phoenix/qt/widget/horizontal-slider.cpp similarity index 100% rename from bsnes/phoenix/qt/horizontalslider.cpp rename to bsnes/phoenix/qt/widget/horizontal-slider.cpp diff --git a/bsnes/phoenix/qt/label.cpp b/bsnes/phoenix/qt/widget/label.cpp similarity index 100% rename from bsnes/phoenix/qt/label.cpp rename to bsnes/phoenix/qt/widget/label.cpp diff --git a/bsnes/phoenix/qt/listbox.cpp b/bsnes/phoenix/qt/widget/list-box.cpp similarity index 100% rename from bsnes/phoenix/qt/listbox.cpp rename to bsnes/phoenix/qt/widget/list-box.cpp diff --git a/bsnes/phoenix/qt/progressbar.cpp b/bsnes/phoenix/qt/widget/progress-bar.cpp similarity index 100% rename from bsnes/phoenix/qt/progressbar.cpp rename to bsnes/phoenix/qt/widget/progress-bar.cpp diff --git a/bsnes/phoenix/qt/radiobox.cpp b/bsnes/phoenix/qt/widget/radio-box.cpp similarity index 100% rename from bsnes/phoenix/qt/radiobox.cpp rename to bsnes/phoenix/qt/widget/radio-box.cpp diff --git a/bsnes/phoenix/qt/textbox.cpp b/bsnes/phoenix/qt/widget/text-box.cpp similarity index 100% rename from bsnes/phoenix/qt/textbox.cpp rename to bsnes/phoenix/qt/widget/text-box.cpp diff --git a/bsnes/phoenix/qt/verticalslider.cpp b/bsnes/phoenix/qt/widget/vertical-slider.cpp similarity index 100% rename from bsnes/phoenix/qt/verticalslider.cpp rename to bsnes/phoenix/qt/widget/vertical-slider.cpp diff --git a/bsnes/phoenix/qt/viewport.cpp b/bsnes/phoenix/qt/widget/viewport.cpp similarity index 100% rename from bsnes/phoenix/qt/viewport.cpp rename to bsnes/phoenix/qt/widget/viewport.cpp diff --git a/bsnes/phoenix/qt/widget.cpp b/bsnes/phoenix/qt/widget/widget.cpp similarity index 100% rename from bsnes/phoenix/qt/widget.cpp rename to bsnes/phoenix/qt/widget/widget.cpp diff --git a/bsnes/phoenix/qt/window.cpp b/bsnes/phoenix/qt/window.cpp index 7ba64c33..fdeababf 100755 --- a/bsnes/phoenix/qt/window.cpp +++ b/bsnes/phoenix/qt/window.cpp @@ -1,26 +1,7 @@ -void Window::create(unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - window->setWindowTitle(QString::fromUtf8(text)); - - window->vlayout = new QVBoxLayout(window); - window->vlayout->setMargin(0); - window->vlayout->setSpacing(0); - window->setLayout(window->vlayout); - - window->menuBar = new QMenuBar(window); - window->menuBar->setVisible(false); - window->vlayout->addWidget(window->menuBar); - - window->container = new QWidget(window); - window->container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - window->container->setVisible(true); - window->vlayout->addWidget(window->container); - - window->statusBar = new QStatusBar(window); - window->statusBar->setSizeGripEnabled(false); - window->statusBar->setVisible(false); - window->vlayout->addWidget(window->statusBar); - - setGeometry(x, y, width, height); +void Window::append(Menu &menu) { + menu.menu->parent = this; + if(window->defaultFont) menu.menu->setFont(*window->defaultFont); + window->menuBar->addMenu(menu.menu); } void Window::setLayout(Layout &layout) { @@ -29,7 +10,7 @@ void Window::setLayout(Layout &layout) { Geometry geom = geometry(); geom.x = geom.y = 0; layout.setParent(*this); - layout.update(geom); + layout.setGeometry(geom); } void Window::setResizable(bool resizable) { @@ -45,43 +26,26 @@ void Window::setResizable(bool resizable) { Geometry Window::frameGeometry() { if(window->fullscreen) return { 0, 0, OS::desktopWidth(), OS::desktopHeight() }; - - QRect rect = window->frameGeometry(); - unsigned x = rect.x(); - unsigned y = rect.y(); - unsigned width = rect.width(); - unsigned height = rect.height(); - if(x > 65535) x = 0; - if(y > 65535) y = 0; - - return { x, y, width, height }; + return { + window->x - settings.frameGeometryX, window->y - settings.frameGeometryY, + window->width + settings.frameGeometryWidth, window->height + settings.frameGeometryHeight + }; } Geometry Window::geometry() { if(window->fullscreen) return { 0, 0, OS::desktopWidth(), OS::desktopHeight() }; return { window->x, window->y, window->width, window->height }; - - unsigned x = window->x; - unsigned y = window->y; - - if(window->fullscreen == false) { - QRect border = window->frameGeometry(); - QRect client = window->geometry(); - x += client.x() - border.x(); - y += client.y() - border.y(); - if(window->menuVisible) y += window->menuBar->height(); - if(x > 65535) x = 0; - if(y > 65535) y = 0; - } - - return { x, y, window->width, window->height }; } -void Window::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height) { - object->locked = true; +void Window::setFrameGeometry(signed x, signed y, unsigned width, unsigned height) { + setGeometry( + x + settings.frameGeometryX, y + settings.frameGeometryY, + width - settings.frameGeometryWidth, height - settings.frameGeometryHeight + ); +} - QRect border = window->frameGeometry(); - QRect client = window->geometry(); +void Window::setGeometry(signed x, signed y, unsigned width, unsigned height) { + object->locked = true; window->x = x; window->y = y; @@ -89,7 +53,7 @@ void Window::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height window->height = height; setResizable(window->resizable); - window->move(x - (client.x() - border.x()), y - (client.y() - border.y())); + window->move(x - settings.frameGeometryX, y - settings.frameGeometryY); window->adjustSize(); object->locked = false; @@ -124,13 +88,7 @@ void Window::setVisible(bool visible) { if(visible) { window->show(); - //an unfortunate hack: before window is visible, geometry() == frameGeometry(); - //we must wait for frameGeometry() to correctly populate and then move window - if(window->fullscreen == false) for(unsigned n = 0; n < 100; n++) { - if(window->geometry().x() > window->frameGeometry().x()) break; - usleep(100); - QApplication::processEvents(); - } + updateFrameGeometry(); setGeometry(window->x, window->y, window->width, window->height); } else { window->hide(); @@ -176,4 +134,58 @@ void Window::setFullscreen(bool fullscreen) { Window::Window() { window = new Window::Data(*this); window->defaultFont = 0; + + window->vlayout = new QVBoxLayout(window); + window->vlayout->setMargin(0); + window->vlayout->setSpacing(0); + window->setLayout(window->vlayout); + + window->menuBar = new QMenuBar(window); + window->menuBar->setVisible(false); + window->vlayout->addWidget(window->menuBar); + + window->container = new QWidget(window); + window->container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + window->container->setVisible(true); + window->vlayout->addWidget(window->container); + + window->statusBar = new QStatusBar(window); + window->statusBar->setSizeGripEnabled(false); + window->statusBar->setVisible(false); + window->vlayout->addWidget(window->statusBar); + + setGeometry(128, 128, 256, 256); +} + +// + +void Window::updateFrameGeometry() { + //Qt does not even attempt to cache frameGeometry, so if this is called before + //a window is visible onscreen, it is equivalent to geometry(). Without proper + //frameGeometry, phoenix's set(Frame)Geometry functions will not work + //properly. Attempting to detect frame geometry after the window is visible + //would require moving a visible window, causing a slight jitter effect. + + //This routine is called every time a new window is shown, and attempts to + //cache frame geometry for the next set(Frame)Geometry call. The information + //is stored to disk, so that hopefully a phoenix window will never jitter more + //than once. + + //The information is constantly updated after each window show to detect theme + //changes that may adjust frame geometry. + + if(window->fullscreen == false) { + for(unsigned n = 0; n < 100; n++) { + if(window->geometry().x() > window->frameGeometry().x()) break; + usleep(100); + QApplication::processEvents(); + } + } + QRect border = window->frameGeometry(); + QRect client = window->geometry(); + + settings.frameGeometryX = client.x() - border.x(); + settings.frameGeometryY = client.y() - border.y(); + settings.frameGeometryWidth = border.width() - client.width(); + settings.frameGeometryHeight = border.height() - client.height(); } diff --git a/bsnes/phoenix/windows/action/action.cpp b/bsnes/phoenix/windows/action/action.cpp new file mode 100755 index 00000000..6231389b --- /dev/null +++ b/bsnes/phoenix/windows/action/action.cpp @@ -0,0 +1,4 @@ +Action::Action() { + OS::os->objects.append(this); + action = new Action::Data; +} diff --git a/bsnes/phoenix/windows/action/menu-check-item.cpp b/bsnes/phoenix/windows/action/menu-check-item.cpp new file mode 100755 index 00000000..9a6108d8 --- /dev/null +++ b/bsnes/phoenix/windows/action/menu-check-item.cpp @@ -0,0 +1,30 @@ +void MenuCheckItem::setText(const string &text) { + action->text = text; +} + +bool MenuCheckItem::enabled() { + MENUITEMINFO info; + memset(&info, 0, sizeof(MENUITEMINFO)); + info.cbSize = sizeof(MENUITEMINFO); + info.fMask = MIIM_STATE; + GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); + return (info.fState & MFS_GRAYED) == 0; +} + +void MenuCheckItem::setEnabled(bool enabled) { + EnableMenuItem(action->parent->action->menu, object->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); +} + +bool MenuCheckItem::checked() { + MENUITEMINFO info; + memset(&info, 0, sizeof(MENUITEMINFO)); + info.cbSize = sizeof(MENUITEMINFO); + info.fMask = MIIM_STATE; + GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); + return info.fState & MFS_CHECKED; +} + +void MenuCheckItem::setChecked(bool checked) { + action->checked = checked; + if(action->parent) CheckMenuItem(action->parent->action->menu, object->id, checked ? MF_CHECKED : MF_UNCHECKED); +} diff --git a/bsnes/phoenix/windows/action/menu-item.cpp b/bsnes/phoenix/windows/action/menu-item.cpp new file mode 100755 index 00000000..a6416345 --- /dev/null +++ b/bsnes/phoenix/windows/action/menu-item.cpp @@ -0,0 +1,16 @@ +void MenuItem::setText(const string &text) { + action->text = text; +} + +bool MenuItem::enabled() { + MENUITEMINFO info; + memset(&info, 0, sizeof(MENUITEMINFO)); + info.cbSize = sizeof(MENUITEMINFO); + info.fMask = MIIM_STATE; + GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); + return (info.fState & MFS_GRAYED) == 0; +} + +void MenuItem::setEnabled(bool enabled) { + EnableMenuItem(action->parent->action->menu, object->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); +} diff --git a/bsnes/phoenix/windows/action/menu-radio-item.cpp b/bsnes/phoenix/windows/action/menu-radio-item.cpp new file mode 100755 index 00000000..82fbb98e --- /dev/null +++ b/bsnes/phoenix/windows/action/menu-radio-item.cpp @@ -0,0 +1,49 @@ +void MenuRadioItem::setText(const string &text) { + action->text = text; +} + +void MenuRadioItem::setParent(MenuRadioItem &parent) { + action->checked = false; + action->radioParent = parent.action->radioParent; + action->radioParent->action->items.append(this); +} + +bool MenuRadioItem::enabled() { + MENUITEMINFO info; + memset(&info, 0, sizeof(MENUITEMINFO)); + info.cbSize = sizeof(MENUITEMINFO); + info.fMask = MIIM_STATE; + GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); + return (info.fState & MFS_GRAYED) == 0; +} + +void MenuRadioItem::setEnabled(bool enabled) { + EnableMenuItem(action->parent->action->menu, object->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); +} + +bool MenuRadioItem::checked() { + MENUITEMINFO info; + memset(&info, 0, sizeof(MENUITEMINFO)); + info.cbSize = sizeof(MENUITEMINFO); + info.fMask = MIIM_STATE; + GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); + return info.fState & MFS_CHECKED; +} + +void MenuRadioItem::setChecked() { + action->checked = true; + MenuRadioItem *parent = action->radioParent; + foreach(item, parent->action->items) { + if(action->parent) CheckMenuRadioItem( + action->parent->action->menu, + item->object->id, item->object->id, item->object->id + (item != this), + MF_BYCOMMAND + ); + } +} + +MenuRadioItem::MenuRadioItem() { + action->radioParent = this; + action->items.append(this); + action->checked = true; +} diff --git a/bsnes/phoenix/windows/action/menu-separator.cpp b/bsnes/phoenix/windows/action/menu-separator.cpp new file mode 100755 index 00000000..8280cfc3 --- /dev/null +++ b/bsnes/phoenix/windows/action/menu-separator.cpp @@ -0,0 +1,12 @@ +bool MenuSeparator::enabled() { + MENUITEMINFO info; + memset(&info, 0, sizeof(MENUITEMINFO)); + info.cbSize = sizeof(MENUITEMINFO); + info.fMask = MIIM_STATE; + GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); + return (info.fState & MFS_GRAYED) == 0; +} + +void MenuSeparator::setEnabled(bool enabled) { + EnableMenuItem(action->parent->action->menu, object->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); +} diff --git a/bsnes/phoenix/windows/action/menu.cpp b/bsnes/phoenix/windows/action/menu.cpp new file mode 100755 index 00000000..bbc636a7 --- /dev/null +++ b/bsnes/phoenix/windows/action/menu.cpp @@ -0,0 +1,51 @@ +void Menu::setText(const string &text) { + action->text = text; +} + +void Menu::append(Action &item) { + menu->children.append(&item); +} + +bool Menu::enabled() { + MENUITEMINFO info; + memset(&info, 0, sizeof(MENUITEMINFO)); + info.cbSize = sizeof(MENUITEMINFO); + info.fMask = MIIM_STATE; + GetMenuItemInfo(action->parentMenu, (UINT_PTR)action->menu, false, &info); + return (info.fState & MFS_GRAYED) == 0; +} + +void Menu::setEnabled(bool enabled) { + EnableMenuItem(action->parentMenu, (UINT_PTR)action->menu, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); +} + +Menu::Menu() { + menu = new Menu::Data; +} + +//internal + +void Menu::create() { + action->menu = CreatePopupMenu(); + foreach(child, menu->children) { + child->action->parent = this; + if(dynamic_cast(child)) { + Menu &item = *(Menu*)child; + item.action->parentMenu = action->menu; + item.create(); + AppendMenu(action->menu, MF_STRING | MF_POPUP, (UINT_PTR)item.action->menu, utf16_t(item.action->text)); + } else if(dynamic_cast(child)) { + AppendMenu(action->menu, MF_SEPARATOR, child->object->id, L""); + } else if(dynamic_cast(child)) { + AppendMenu(action->menu, MF_STRING, child->object->id, utf16_t(child->action->text)); + } else if(dynamic_cast(child)) { + AppendMenu(action->menu, MF_STRING, child->object->id, utf16_t(child->action->text)); + MenuCheckItem &item = *(MenuCheckItem*)child; + if(item.action->checked) item.setChecked(); + } else if(dynamic_cast(child)) { + AppendMenu(action->menu, MF_STRING, child->object->id, utf16_t(child->action->text)); + MenuRadioItem &item = *(MenuRadioItem*)child; + if(item.action->checked) item.setChecked(); + } + } +} diff --git a/bsnes/phoenix/windows/layout.cpp b/bsnes/phoenix/windows/layout.cpp index b68a2119..47a12adc 100755 --- a/bsnes/phoenix/windows/layout.cpp +++ b/bsnes/phoenix/windows/layout.cpp @@ -3,7 +3,7 @@ void Layout::setParent(Window &parent) { } void Layout::append(Widget &child) { - SetParent(child.widget->window, layout->parent->widget->window); + SetParent(child.widget->window, layout->parent->window->window); SendMessage( child.widget->window, WM_SETFONT, (WPARAM)(layout->parent->window->defaultFont ? layout->parent->window->defaultFont : OS::os->proportionalFont), 0 diff --git a/bsnes/phoenix/windows/menu.cpp b/bsnes/phoenix/windows/menu.cpp deleted file mode 100755 index 789ed382..00000000 --- a/bsnes/phoenix/windows/menu.cpp +++ /dev/null @@ -1,144 +0,0 @@ -Action::Action() { - OS::os->objects.append(this); - action = new Action::Data; -} - -void Menu::create(Window &parent, const string &text) { - action->parentMenu = parent.window->menu; - action->menu = CreatePopupMenu(); - AppendMenu(parent.window->menu, MF_STRING | MF_POPUP, (UINT_PTR)action->menu, utf16_t(text)); -} - -void Menu::create(Menu &parent, const string &text) { - action->parentMenu = parent.action->menu; - action->menu = CreatePopupMenu(); - AppendMenu(parent.action->menu, MF_STRING | MF_POPUP, (UINT_PTR)action->menu, utf16_t(text)); -} - -bool Menu::enabled() { - MENUITEMINFO info; - memset(&info, 0, sizeof(MENUITEMINFO)); - info.cbSize = sizeof(MENUITEMINFO); - info.fMask = MIIM_STATE; - GetMenuItemInfo(action->parentMenu, (UINT_PTR)action->menu, false, &info); - return (info.fState & MFS_GRAYED) == 0; -} - -void Menu::setEnabled(bool enabled) { - EnableMenuItem(action->parentMenu, (UINT_PTR)action->menu, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); -} - -void MenuSeparator::create(Menu &parent) { - action->parent = &parent; - AppendMenu(parent.action->menu, MF_SEPARATOR, object->id, L""); -} - -bool MenuSeparator::enabled() { - MENUITEMINFO info; - memset(&info, 0, sizeof(MENUITEMINFO)); - info.cbSize = sizeof(MENUITEMINFO); - info.fMask = MIIM_STATE; - GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); - return (info.fState & MFS_GRAYED) == 0; -} - -void MenuSeparator::setEnabled(bool enabled) { - EnableMenuItem(action->parent->action->menu, object->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); -} - -void MenuItem::create(Menu &parent, const string &text) { - action->parent = &parent; - AppendMenu(parent.action->menu, MF_STRING, object->id, utf16_t(text)); -} - -bool MenuItem::enabled() { - MENUITEMINFO info; - memset(&info, 0, sizeof(MENUITEMINFO)); - info.cbSize = sizeof(MENUITEMINFO); - info.fMask = MIIM_STATE; - GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); - return (info.fState & MFS_GRAYED) == 0; -} - -void MenuItem::setEnabled(bool enabled) { - EnableMenuItem(action->parent->action->menu, object->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); -} - -void MenuCheckItem::create(Menu &parent, const string &text) { - action->parent = &parent; - AppendMenu(parent.action->menu, MF_STRING, object->id, utf16_t(text)); -} - -bool MenuCheckItem::enabled() { - MENUITEMINFO info; - memset(&info, 0, sizeof(MENUITEMINFO)); - info.cbSize = sizeof(MENUITEMINFO); - info.fMask = MIIM_STATE; - GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); - return (info.fState & MFS_GRAYED) == 0; -} - -void MenuCheckItem::setEnabled(bool enabled) { - EnableMenuItem(action->parent->action->menu, object->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); -} - -bool MenuCheckItem::checked() { - MENUITEMINFO info; - memset(&info, 0, sizeof(MENUITEMINFO)); - info.cbSize = sizeof(MENUITEMINFO); - info.fMask = MIIM_STATE; - GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); - return info.fState & MFS_CHECKED; -} - -void MenuCheckItem::setChecked(bool checked) { - CheckMenuItem(action->parent->action->menu, object->id, checked ? MF_CHECKED : MF_UNCHECKED); -} - -void MenuRadioItem::create(Menu &parent, const string &text) { - action->parent = &parent; - action->radioParent = this; - action->items.append(this); - AppendMenu(parent.action->menu, MF_STRING, object->id, utf16_t(text)); - setChecked(); -} - -void MenuRadioItem::create(MenuRadioItem &parent, const string &text) { - action->parent = parent.action->parent; - action->radioParent = parent.action->radioParent; - action->radioParent->action->items.append(this); - AppendMenu(action->parent->action->menu, MF_STRING, object->id, utf16_t(text)); -} - -bool MenuRadioItem::enabled() { - MENUITEMINFO info; - memset(&info, 0, sizeof(MENUITEMINFO)); - info.cbSize = sizeof(MENUITEMINFO); - info.fMask = MIIM_STATE; - GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); - return (info.fState & MFS_GRAYED) == 0; -} - -void MenuRadioItem::setEnabled(bool enabled) { - EnableMenuItem(action->parent->action->menu, object->id, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); -} - -bool MenuRadioItem::checked() { - MENUITEMINFO info; - memset(&info, 0, sizeof(MENUITEMINFO)); - info.cbSize = sizeof(MENUITEMINFO); - info.fMask = MIIM_STATE; - GetMenuItemInfo(action->parent->action->menu, object->id, false, &info); - return info.fState & MFS_CHECKED; -} - -void MenuRadioItem::setChecked() { - MenuRadioItem *parent = action->radioParent; - foreach(item, parent->action->items) { - CheckMenuRadioItem( - action->parent->action->menu, - item->object->id, item->object->id, item->object->id + (item != this), - MF_BYCOMMAND - ); - } -} diff --git a/bsnes/phoenix/windows/messagewindow.cpp b/bsnes/phoenix/windows/message-window.cpp similarity index 88% rename from bsnes/phoenix/windows/messagewindow.cpp rename to bsnes/phoenix/windows/message-window.cpp index b2439dc3..209a1c8d 100755 --- a/bsnes/phoenix/windows/messagewindow.cpp +++ b/bsnes/phoenix/windows/message-window.cpp @@ -13,7 +13,7 @@ MessageWindow::Response MessageWindow::information(Window &parent, const string if(buttons == Buttons::Ok) flags |= MB_OK; if(buttons == Buttons::OkCancel) flags |= MB_OKCANCEL; if(buttons == Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::None ? parent.widget->window : 0, utf16_t(text), L"", flags)); + return MessageWindow_response(buttons, MessageBox(&parent != &Window::None ? parent.window->window : 0, utf16_t(text), L"", flags)); } MessageWindow::Response MessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { @@ -21,7 +21,7 @@ MessageWindow::Response MessageWindow::question(Window &parent, const string &te if(buttons == Buttons::Ok) flags |= MB_OK; if(buttons == Buttons::OkCancel) flags |= MB_OKCANCEL; if(buttons == Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::None ? parent.widget->window : 0, utf16_t(text), L"", flags)); + return MessageWindow_response(buttons, MessageBox(&parent != &Window::None ? parent.window->window : 0, utf16_t(text), L"", flags)); } MessageWindow::Response MessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { @@ -29,7 +29,7 @@ MessageWindow::Response MessageWindow::warning(Window &parent, const string &tex if(buttons == Buttons::Ok) flags |= MB_OK; if(buttons == Buttons::OkCancel) flags |= MB_OKCANCEL; if(buttons == Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::None ? parent.widget->window : 0, utf16_t(text), L"", flags)); + return MessageWindow_response(buttons, MessageBox(&parent != &Window::None ? parent.window->window : 0, utf16_t(text), L"", flags)); } MessageWindow::Response MessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { @@ -37,5 +37,5 @@ MessageWindow::Response MessageWindow::critical(Window &parent, const string &te if(buttons == Buttons::Ok) flags |= MB_OK; if(buttons == Buttons::OkCancel) flags |= MB_OKCANCEL; if(buttons == Buttons::YesNo) flags |= MB_YESNO; - return MessageWindow_response(buttons, MessageBox(&parent != &Window::None ? parent.widget->window : 0, utf16_t(text), L"", flags)); + return MessageWindow_response(buttons, MessageBox(&parent != &Window::None ? parent.window->window : 0, utf16_t(text), L"", flags)); } diff --git a/bsnes/phoenix/windows/object.cpp b/bsnes/phoenix/windows/object.cpp index fac81e70..802f7f56 100755 --- a/bsnes/phoenix/windows/object.cpp +++ b/bsnes/phoenix/windows/object.cpp @@ -13,9 +13,24 @@ struct Action::Data { HMENU menu; MenuRadioItem *radioParent; array items; + string text; + bool checked; + + Data() { + parent = 0; + parentMenu = 0; + menu = 0; + radioParent = 0; + checked = false; + } +}; + +struct Menu::Data { + array children; }; struct Window::Data { + HWND window; Layout *layout; HFONT defaultFont; HBRUSH brush; @@ -30,6 +45,7 @@ struct Window::Data { unsigned height; Data() { + window = 0; layout = 0; defaultFont = 0; brush = 0; diff --git a/bsnes/phoenix/windows/button.cpp b/bsnes/phoenix/windows/widget/button.cpp similarity index 100% rename from bsnes/phoenix/windows/button.cpp rename to bsnes/phoenix/windows/widget/button.cpp diff --git a/bsnes/phoenix/windows/canvas.cpp b/bsnes/phoenix/windows/widget/canvas.cpp similarity index 96% rename from bsnes/phoenix/windows/canvas.cpp rename to bsnes/phoenix/windows/widget/canvas.cpp index 783d7042..6f9e8a3d 100755 --- a/bsnes/phoenix/windows/canvas.cpp +++ b/bsnes/phoenix/windows/widget/canvas.cpp @@ -16,7 +16,7 @@ void Canvas::create(Window &parent, unsigned x, unsigned y, unsigned width, unsi L"phoenix_canvas", L"", WS_CHILD | WS_VISIBLE, x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 + parent.window->window, (HMENU)object->id, GetModuleHandle(0), 0 ); SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); } diff --git a/bsnes/phoenix/windows/checkbox.cpp b/bsnes/phoenix/windows/widget/check-box.cpp similarity index 100% rename from bsnes/phoenix/windows/checkbox.cpp rename to bsnes/phoenix/windows/widget/check-box.cpp diff --git a/bsnes/phoenix/windows/combobox.cpp b/bsnes/phoenix/windows/widget/combo-box.cpp similarity index 100% rename from bsnes/phoenix/windows/combobox.cpp rename to bsnes/phoenix/windows/widget/combo-box.cpp diff --git a/bsnes/phoenix/windows/editbox.cpp b/bsnes/phoenix/windows/widget/edit-box.cpp similarity index 100% rename from bsnes/phoenix/windows/editbox.cpp rename to bsnes/phoenix/windows/widget/edit-box.cpp diff --git a/bsnes/phoenix/windows/hexeditor.cpp b/bsnes/phoenix/windows/widget/hex-editor.cpp similarity index 100% rename from bsnes/phoenix/windows/hexeditor.cpp rename to bsnes/phoenix/windows/widget/hex-editor.cpp diff --git a/bsnes/phoenix/windows/horizontalslider.cpp b/bsnes/phoenix/windows/widget/horizontal-slider.cpp similarity index 100% rename from bsnes/phoenix/windows/horizontalslider.cpp rename to bsnes/phoenix/windows/widget/horizontal-slider.cpp diff --git a/bsnes/phoenix/windows/label.cpp b/bsnes/phoenix/windows/widget/label.cpp similarity index 100% rename from bsnes/phoenix/windows/label.cpp rename to bsnes/phoenix/windows/widget/label.cpp diff --git a/bsnes/phoenix/windows/listbox.cpp b/bsnes/phoenix/windows/widget/list-box.cpp similarity index 100% rename from bsnes/phoenix/windows/listbox.cpp rename to bsnes/phoenix/windows/widget/list-box.cpp diff --git a/bsnes/phoenix/windows/progressbar.cpp b/bsnes/phoenix/windows/widget/progress-bar.cpp similarity index 100% rename from bsnes/phoenix/windows/progressbar.cpp rename to bsnes/phoenix/windows/widget/progress-bar.cpp diff --git a/bsnes/phoenix/windows/radiobox.cpp b/bsnes/phoenix/windows/widget/radio-box.cpp similarity index 100% rename from bsnes/phoenix/windows/radiobox.cpp rename to bsnes/phoenix/windows/widget/radio-box.cpp diff --git a/bsnes/phoenix/windows/textbox.cpp b/bsnes/phoenix/windows/widget/text-box.cpp similarity index 100% rename from bsnes/phoenix/windows/textbox.cpp rename to bsnes/phoenix/windows/widget/text-box.cpp diff --git a/bsnes/phoenix/windows/verticalslider.cpp b/bsnes/phoenix/windows/widget/vertical-slider.cpp similarity index 100% rename from bsnes/phoenix/windows/verticalslider.cpp rename to bsnes/phoenix/windows/widget/vertical-slider.cpp diff --git a/bsnes/phoenix/windows/viewport.cpp b/bsnes/phoenix/windows/widget/viewport.cpp similarity index 100% rename from bsnes/phoenix/windows/viewport.cpp rename to bsnes/phoenix/windows/widget/viewport.cpp diff --git a/bsnes/phoenix/windows/widget.cpp b/bsnes/phoenix/windows/widget/widget.cpp similarity index 93% rename from bsnes/phoenix/windows/widget.cpp rename to bsnes/phoenix/windows/widget/widget.cpp index 70ac5301..fe377f39 100755 --- a/bsnes/phoenix/windows/widget.cpp +++ b/bsnes/phoenix/windows/widget/widget.cpp @@ -4,7 +4,7 @@ void Widget::setFont(Font &font) { } bool Widget::visible() { - return GetWindowLong(widget->window, GWL_STYLE) & WS_VISIBLE; + return GetWindowLongPtr(widget->window, GWL_STYLE) & WS_VISIBLE; } void Widget::setVisible(bool visible) { diff --git a/bsnes/phoenix/windows/window.cpp b/bsnes/phoenix/windows/window.cpp index df7c7ec3..46316076 100755 --- a/bsnes/phoenix/windows/window.cpp +++ b/bsnes/phoenix/windows/window.cpp @@ -1,20 +1,10 @@ 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; -void Window::create(unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - widget->window = CreateWindowEx( - 0, L"phoenix_window", utf16_t(text), ResizableStyle, - 0, 0, 64, 64, 0, 0, GetModuleHandle(0), 0 - ); - window->menu = CreateMenu(); - window->status = CreateWindowEx( - 0, STATUSCLASSNAME, L"", WS_CHILD, - 0, 0, 0, 0, widget->window, 0, GetModuleHandle(0), 0 - ); - //StatusBar will be capable of receiving tab focus if it is not disabled - SetWindowLongPtr(window->status, GWL_STYLE, GetWindowLong(window->status, GWL_STYLE) | WS_DISABLED); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - setGeometry(x, y, width, height); +void Window::append(Menu &menu) { + menu.action->parentMenu = window->menu; + menu.create(); + AppendMenu(window->menu, MF_STRING | MF_POPUP, (UINT_PTR)menu.action->menu, utf16_t(menu.action->text)); } void Window::setLayout(Layout &layout) { @@ -22,12 +12,12 @@ void Window::setLayout(Layout &layout) { Geometry geom = geometry(); geom.x = geom.y = 0; layout.setParent(*this); - layout.update(geom); + layout.setGeometry(geom); } void Window::setResizable(bool resizable) { window->resizable = resizable; - SetWindowLongPtr(widget->window, GWL_STYLE, window->resizable ? ResizableStyle : FixedStyle); + SetWindowLongPtr(window->window, GWL_STYLE, window->resizable ? ResizableStyle : FixedStyle); setGeometry(window->x, window->y, window->width, window->height); } @@ -41,14 +31,12 @@ void Window::setFont(Font &font) { Geometry Window::frameGeometry() { RECT rc; - GetWindowRect(widget->window, &rc); + GetWindowRect(window->window, &rc); - unsigned x = rc.left; - unsigned y = rc.top; + signed x = rc.left; + signed y = rc.top; unsigned width = (rc.right - rc.left); unsigned height = (rc.bottom - rc.top); - if((signed)x < 0) x = 0; - if((signed)y < 0) y = 0; return { x, y, width, height }; } @@ -56,19 +44,22 @@ Geometry Window::frameGeometry() { Geometry Window::geometry() { Geometry fm = frameMargin(); RECT rc; - GetWindowRect(widget->window, &rc); + GetWindowRect(window->window, &rc); - unsigned x = rc.left + fm.x; - unsigned y = rc.top + fm.y; + signed x = rc.left + fm.x; + signed y = rc.top + fm.y; unsigned width = (rc.right - rc.left) - fm.width; unsigned height = (rc.bottom - rc.top) - fm.height; - if((signed)x < 0) x = 0; - if((signed)y < 0) y = 0; return { x, y, width, height }; } -void Window::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height) { +void Window::setFrameGeometry(signed x, signed y, unsigned width, unsigned height) { + Geometry fm = frameMargin(); + setGeometry(x + fm.x, y + fm.y, width - fm.width, height - fm.height); +} + +void Window::setGeometry(signed x, signed y, unsigned width, unsigned height) { object->locked = true; if(window->fullscreen == false) { window->x = x; @@ -77,8 +68,11 @@ void Window::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height window->height = height; } Geometry fm = frameMargin(); - SetWindowPos(widget->window, NULL, x - fm.x, y - fm.y, width + fm.width, height + fm.height, SWP_NOZORDER | SWP_FRAMECHANGED); + SetWindowPos(window->window, NULL, x - fm.x, y - fm.y, width + fm.width, height + fm.height, SWP_NOZORDER | SWP_FRAMECHANGED); SetWindowPos(window->status, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED); + Geometry geom = geometry(); + geom.x = geom.y = 0; + if(window->layout) window->layout->setGeometry(geom); object->locked = false; } @@ -89,7 +83,7 @@ void Window::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { } void Window::setTitle(const string &text) { - SetWindowText(widget->window, utf16_t(text)); + SetWindowText(window->window, utf16_t(text)); } void Window::setStatusText(const string &text) { @@ -98,7 +92,7 @@ void Window::setStatusText(const string &text) { void Window::setMenuVisible(bool visible) { object->locked = true; - SetMenu(widget->window, visible ? window->menu : 0); + SetMenu(window->window, visible ? window->menu : 0); setGeometry(window->x, window->y, window->width, window->height); object->locked = false; } @@ -118,17 +112,48 @@ void Window::setFullscreen(bool fullscreen) { object->locked = true; window->fullscreen = fullscreen; if(window->fullscreen == false) { - SetWindowLong(widget->window, GWL_STYLE, WS_VISIBLE | (window->resizable ? ResizableStyle : FixedStyle)); + SetWindowLong(window->window, GWL_STYLE, WS_VISIBLE | (window->resizable ? ResizableStyle : FixedStyle)); setGeometry(window->x, window->y, window->width, window->height); } else { - SetWindowLong(widget->window, GWL_STYLE, WS_VISIBLE | WS_POPUP); + SetWindowLong(window->window, GWL_STYLE, WS_VISIBLE | WS_POPUP); setGeometry(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); } object->locked = false; } +bool Window::visible() { + return GetWindowLongPtr(window->window, GWL_STYLE) & WS_VISIBLE; +} + +void Window::setVisible(bool visible) { + ShowWindow(window->window, visible ? SW_SHOWNORMAL : SW_HIDE); +} + +bool Window::focused() { + return (GetForegroundWindow() == window->window); +} + +void Window::setFocused() { + if(visible() == false) setVisible(true); + SetFocus(window->window); +} + Window::Window() { window = new Window::Data; + + window->window = CreateWindowEx( + 0, L"phoenix_window", L"", ResizableStyle, + 0, 0, 64, 64, 0, 0, GetModuleHandle(0), 0 + ); + window->menu = CreateMenu(); + window->status = CreateWindowEx( + 0, STATUSCLASSNAME, L"", WS_CHILD, + 0, 0, 0, 0, window->window, 0, GetModuleHandle(0), 0 + ); + //StatusBar will be capable of receiving tab focus if it is not disabled + SetWindowLongPtr(window->status, GWL_STYLE, GetWindowLong(window->status, GWL_STYLE) | WS_DISABLED); + SetWindowLongPtr(window->window, GWLP_USERDATA, (LONG_PTR)this); + setGeometry(128, 128, 256, 256); } //internal @@ -139,7 +164,7 @@ Geometry Window::frameMargin() { //width,height: total pixels of window geometry that are not part of client area //width-x,height-y: pixels from the bottom-right of window to the client area RECT rc = { 0, 0, 640, 480 }; - AdjustWindowRect(&rc, window->resizable ? ResizableStyle : FixedStyle, (bool)GetMenu(widget->window)); + AdjustWindowRect(&rc, window->resizable ? ResizableStyle : FixedStyle, (bool)GetMenu(window->window)); unsigned statusHeight = 0; if(GetWindowLongPtr(window->status, GWL_STYLE) & WS_VISIBLE) { RECT src; diff --git a/bsnes/phoenix/windows/windows.cpp b/bsnes/phoenix/windows/windows.cpp index 90006af5..f29e1445 100755 --- a/bsnes/phoenix/windows/windows.cpp +++ b/bsnes/phoenix/windows/windows.cpp @@ -12,25 +12,32 @@ namespace phoenix { #include "object.cpp" #include "font.cpp" -#include "menu.cpp" -#include "widget.cpp" #include "window.cpp" #include "layout.cpp" -#include "button.cpp" -#include "canvas.cpp" -#include "checkbox.cpp" -#include "combobox.cpp" -#include "editbox.cpp" -#include "hexeditor.cpp" -#include "horizontalslider.cpp" -#include "label.cpp" -#include "listbox.cpp" -#include "progressbar.cpp" -#include "radiobox.cpp" -#include "textbox.cpp" -#include "verticalslider.cpp" -#include "viewport.cpp" -#include "messagewindow.cpp" +#include "message-window.cpp" + +#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 "widget/widget.cpp" +#include "widget/button.cpp" +#include "widget/canvas.cpp" +#include "widget/check-box.cpp" +#include "widget/combo-box.cpp" +#include "widget/edit-box.cpp" +#include "widget/hex-editor.cpp" +#include "widget/horizontal-slider.cpp" +#include "widget/label.cpp" +#include "widget/list-box.cpp" +#include "widget/progress-bar.cpp" +#include "widget/radio-box.cpp" +#include "widget/text-box.cpp" +#include "widget/vertical-slider.cpp" +#include "widget/viewport.cpp" OS::Data *OS::os = 0; Window Window::None; @@ -151,7 +158,7 @@ unsigned OS::desktopHeight() { string OS::folderSelect(Window &parent, const string &path) { wchar_t wfilename[PATH_MAX + 1] = L""; BROWSEINFO bi; - bi.hwndOwner = &parent != &Window::None ? parent.widget->window : 0; + bi.hwndOwner = &parent != &Window::None ? parent.window->window : 0; bi.pidlRoot = NULL; bi.pszDisplayName = wfilename; bi.lpszTitle = L""; @@ -211,7 +218,7 @@ string OS::fileOpen(Window &parent, const string &filter, const string &path) { OPENFILENAME ofn; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = &parent != &Window::None ? parent.widget->window : 0; + ofn.hwndOwner = &parent != &Window::None ? parent.window->window : 0; ofn.lpstrFilter = wfilter; ofn.lpstrInitialDir = wdir; ofn.lpstrFile = wfilename; @@ -259,7 +266,7 @@ string OS::fileSave(Window &parent, const string &filter, const string &path) { OPENFILENAME ofn; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = &parent != &Window::None ? parent.widget->window : 0; + ofn.hwndOwner = &parent != &Window::None ? parent.window->window : 0; ofn.lpstrFilter = wfilter; ofn.lpstrInitialDir = wdir; ofn.lpstrFile = wfilename; @@ -335,10 +342,10 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM if(window.window->layout) { geometry.x = geometry.y = 0; - window.window->layout->update(geometry); + window.window->layout->setGeometry(geometry); } - if(window.onResize) window.onResize(); + if(window.onSize) window.onSize(); break; } @@ -352,11 +359,11 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM case WM_ERASEBKGND: { if(window.window->brush == 0) break; RECT rc; - GetClientRect(window.widget->window, &rc); + GetClientRect(window.window->window, &rc); PAINTSTRUCT ps; - BeginPaint(window.widget->window, &ps); + BeginPaint(window.window->window, &ps); FillRect(ps.hdc, &rc, window.window->brush); - EndPaint(window.widget->window, &ps); + EndPaint(window.window->window, &ps); return TRUE; } @@ -372,7 +379,7 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM case WM_COMMAND: { unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.widget->window, id); + HWND control = GetDlgItem(window.window->window, id); if(control == 0) { Object *object_ptr = (Object*)OS::findObject(id); if(object_ptr) { @@ -432,7 +439,7 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM case WM_NOTIFY: { unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.widget->window, id); + HWND control = GetDlgItem(window.window->window, id); if(control) { Object *object_ptr = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); if(object_ptr) { @@ -465,7 +472,7 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM case WM_HSCROLL: { unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.widget->window, id); + HWND control = GetDlgItem(window.window->window, id); if(control) { Object *object_ptr = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); if(object_ptr) { @@ -482,7 +489,7 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM case WM_VSCROLL: { unsigned id = LOWORD(wparam); - HWND control = GetDlgItem(window.widget->window, id); + HWND control = GetDlgItem(window.window->window, id); if(control) { Object *object_ptr = (Object*)GetWindowLongPtr(control, GWLP_USERDATA); if(object_ptr) { diff --git a/bsnes/phoenix/windows/windows.hpp b/bsnes/phoenix/windows/windows.hpp index 8ea6764d..cb64e3c5 100755 --- a/bsnes/phoenix/windows/windows.hpp +++ b/bsnes/phoenix/windows/windows.hpp @@ -14,10 +14,10 @@ private: }; struct Geometry { - unsigned x, y; + signed x, y; unsigned width, height; inline Geometry() : x(0), y(0), width(0), height(0) {} - inline Geometry(unsigned x, unsigned y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {} + inline Geometry(signed x, signed y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {} }; struct Font : Object { @@ -37,6 +37,42 @@ struct Font : Object { inline Font::Style operator|(Font::Style a, Font::Style b) { return (Font::Style)((unsigned)a | (unsigned)b); } inline Font::Style operator&(Font::Style a, Font::Style b) { return (Font::Style)((unsigned)a & (unsigned)b); } +struct Menu; +struct Layout; +struct Widget; + +struct Window : Object { + nall::function onClose; + nall::function onMove; + nall::function onSize; + void append(Menu &menu); + void setLayout(Layout &layout); + void setResizable(bool resizable); + void setDefaultFont(Font &font); + void setFont(Font &font); + Geometry frameGeometry(); + Geometry geometry(); + void setFrameGeometry(signed x, signed y, unsigned width, unsigned height); + void setGeometry(signed x, signed y, unsigned width, unsigned height); + void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); + void setTitle(const nall::string &text); + void setStatusText(const nall::string &text); + void setMenuVisible(bool visible = true); + void setStatusVisible(bool visible = true); + bool fullscreen(); + void setFullscreen(bool fullscreen = true); + bool visible(); + void setVisible(bool visible = true); + bool focused(); + void setFocused(); + Window(); +//private: + struct Data; + Data *window; + static Window None; + Geometry frameMargin(); +}; + struct Action : Object { virtual bool enabled() = 0; virtual void setEnabled(bool enabled = true) = 0; @@ -47,28 +83,32 @@ struct Action : Object { }; struct Menu : Action { - void create(Window &parent, const nall::string &text); - void create(Menu &parent, const nall::string &text); + void append(Action &action); + void setText(const nall::string &text); bool enabled(); void setEnabled(bool enabled = true); + Menu(); +//private: + struct Data; + Data *menu; + void create(); }; struct MenuSeparator : Action { - void create(Menu &parent); bool enabled(); void setEnabled(bool enabled = true); }; struct MenuItem : Action { nall::function onTick; - void create(Menu &parent, const nall::string &text); + void setText(const nall::string &text); bool enabled(); void setEnabled(bool enabled = true); }; struct MenuCheckItem : Action { nall::function onTick; - void create(Menu &parent, const nall::string &text); + void setText(const nall::string &text); bool enabled(); void setEnabled(bool enabled = true); bool checked(); @@ -77,17 +117,15 @@ struct MenuCheckItem : Action { struct MenuRadioItem : Action { nall::function onTick; - void create(Menu &parent, const nall::string &text); - void create(MenuRadioItem &parent, const nall::string &text); + void setParent(MenuRadioItem &parent); + void setText(const nall::string &text); bool enabled(); void setEnabled(bool enabled = true); bool checked(); void setChecked(); + MenuRadioItem(); }; -struct Window; -struct Layout; - struct Widget : Object { virtual void setParent(Layout &parent) {} @@ -105,39 +143,10 @@ struct Widget : Object { Data *widget; }; -struct Window : Widget { - nall::function onClose; - nall::function onMove; - nall::function onResize; - void create(unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); - void setLayout(Layout &layout); - void setResizable(bool resizable); - void setDefaultFont(Font &font); - void setFont(Font &font); - Geometry frameGeometry(); - Geometry geometry(); - void setGeometry(unsigned x, unsigned y, unsigned width, unsigned height); - void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); - void setTitle(const nall::string &text); - void setStatusText(const nall::string &text); - void setMenuVisible(bool visible = true); - void setStatusVisible(bool visible = true); - bool fullscreen(); - void setFullscreen(bool fullscreen = true); - Window(); -//private: - struct Data; - Data *window; - static Window None; -//private: - Geometry frameMargin(); - void resize(unsigned width, unsigned height); -}; - struct Layout : Widget { virtual void setParent(Window &parent); + virtual void setGeometry(Geometry &geometry) = 0; virtual void append(Widget &widget); - virtual void update(Geometry &geometry) = 0; Layout(); //private: struct Data; diff --git a/bsnes/snes/snes.hpp b/bsnes/snes/snes.hpp index 2cea1fad..d335a27c 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.10"; + static const char Version[] = "075.11"; static const unsigned SerializerVersion = 18; } } diff --git a/bsnes/ui/debugger/console.cpp b/bsnes/ui/debugger/console.cpp index 1df20688..a1eb6885 100755 --- a/bsnes/ui/debugger/console.cpp +++ b/bsnes/ui/debugger/console.cpp @@ -1,7 +1,7 @@ Console console; void Console::create() { - Window::create(0, 0, 715, 350, "Console"); + setTitle("Console"); application.addWindow(this, "Debugger.Console", "192,192"); output.setFont(application.monospaceFont); @@ -23,17 +23,9 @@ void Console::create() { controlLayout.append(spacer, 120, 0, Style::CheckBoxHeight); controlLayout.append(clearConsole, 120, Style::ButtonHeight); layout.append(controlLayout, 120, 0); - setLayout(layout); -/*unsigned x = 5, y = 5; - layout.append(output, x, y, 580, 338); x += 580 + 5; - layout.append(traceToConsole, x, y, 120, Style::CheckBoxHeight); y += Style::CheckBoxHeight; - layout.append(traceToFile, x, y, 120, Style::CheckBoxHeight); y += Style::CheckBoxHeight; - layout.append(traceCPU, x, y, 120, Style::CheckBoxHeight); y += Style::CheckBoxHeight; - layout.append(traceSMP, x, y, 120, Style::CheckBoxHeight); y += Style::CheckBoxHeight; - layout.append(clearConsole, x, 348 - Style::ButtonHeight - 5, 120, Style::ButtonHeight); - setGeometry(0, 0, 715, 348); - setLayout(layout);*/ + setGeometry(0, 0, layout.minimumWidth() + 565, 350); + setLayout(layout); onClose = []() { debugger.showConsole.setChecked(false); diff --git a/bsnes/ui/debugger/cpu/debugger.cpp b/bsnes/ui/debugger/cpu/debugger.cpp index 100c910d..c33d473c 100755 --- a/bsnes/ui/debugger/cpu/debugger.cpp +++ b/bsnes/ui/debugger/cpu/debugger.cpp @@ -1,7 +1,7 @@ CPUDebugger cpuDebugger; void CPUDebugger::create() { - Window::create(0, 0, 495, 220, "CPU Debugger"); + setTitle("CPU Debugger"); application.addWindow(this, "Debugger.CPUdebugger", "192,192"); output.setFont(application.monospaceFont); @@ -17,6 +17,8 @@ void CPUDebugger::create() { controlLayout.append(stepOver, 80, Style::ButtonHeight); controlLayout.append(proceed, 80, Style::ButtonHeight); layout.append(controlLayout, 80, 0); + + setGeometry(0, 0, layout.minimumWidth() + 300, 220); setLayout(layout); onClose = []() { diff --git a/bsnes/ui/debugger/debugger.cpp b/bsnes/ui/debugger/debugger.cpp index 769e6261..ca7691ae 100755 --- a/bsnes/ui/debugger/debugger.cpp +++ b/bsnes/ui/debugger/debugger.cpp @@ -18,7 +18,7 @@ void Debugger::create() { breakpointEditor.create(); memoryEditor.create(); - Window::create(0, 0, 256, 80, "Debugger"); + setTitle("Debugger"); application.addWindow(this, "Debugger", "160,160"); enableDebugger.setText("Enable debugger"); @@ -35,6 +35,8 @@ void Debugger::create() { layout.append(showSMPDebugger, 0, Style::CheckBoxHeight); layout.append(showBreakpointEditor, 0, Style::CheckBoxHeight); layout.append(showMemoryEditor, 0, Style::CheckBoxHeight); + + setGeometry(0, 0, 256, layout.minimumHeight()); setLayout(layout); /*unsigned x = 5, y = 5; diff --git a/bsnes/ui/debugger/smp/debugger.cpp b/bsnes/ui/debugger/smp/debugger.cpp index 0b4444f1..79ec3211 100755 --- a/bsnes/ui/debugger/smp/debugger.cpp +++ b/bsnes/ui/debugger/smp/debugger.cpp @@ -1,7 +1,7 @@ SMPDebugger smpDebugger; void SMPDebugger::create() { - Window::create(0, 0, 495, 220, "SMP Debugger"); + setTitle("SMP Debugger"); application.addWindow(this, "Debugger.SMPDebugger", "192,192"); output.setFont(application.monospaceFont); @@ -17,6 +17,8 @@ void SMPDebugger::create() { controlLayout.append(stepOver, 80, Style::ButtonHeight); controlLayout.append(proceed, 80, Style::ButtonHeight); layout.append(controlLayout, 80, 0); + + setGeometry(0, 0, layout.minimumWidth() + 300, 220); setLayout(layout); onClose = []() { diff --git a/bsnes/ui/debugger/tools/breakpoint-editor.cpp b/bsnes/ui/debugger/tools/breakpoint-editor.cpp index e09548bc..8877a19d 100755 --- a/bsnes/ui/debugger/tools/breakpoint-editor.cpp +++ b/bsnes/ui/debugger/tools/breakpoint-editor.cpp @@ -1,7 +1,7 @@ BreakpointEditor breakpointEditor; void BreakpointEditor::create() { - Window::create(0, 0, 310, 240, "Breakpoint Editor"); + setTitle("Breakpoint Editor"); application.addWindow(this, "Debugger.BreakpointEditor", "192,192"); runToBreakpoint.setText("Run to breakpoint"); @@ -28,19 +28,9 @@ void BreakpointEditor::create() { breakpointLayout[n].append(sourceBox[n], 80, Style::EditBoxHeight); layout.append(breakpointLayout[n], 0, Style::EditBoxHeight, 5); } - setLayout(layout); -/*unsigned x = 5, y = 5; - layout.append(runToBreakpoint, x, y, 295, Style::CheckBoxHeight); y += Style::CheckBoxHeight + 5; - for(unsigned n = 0; n < Breakpoints; n++) { - layout.append(enableBox[n], x, y, 35, Style::EditBoxHeight); - layout.append(addressBox[n], x + 35, y, 60, Style::EditBoxHeight); - layout.append(valueBox[n], x + 100, y, 30, Style::EditBoxHeight); - layout.append(typeBox[n], x + 135, y, 80, Style::EditBoxHeight); - layout.append(sourceBox[n], x + 220, y, 80, Style::EditBoxHeight); y += Style::EditBoxHeight + 5; - } - setGeometry(0, 0, 310, y); - setLayout(layout);*/ + setGeometry(0, 0, 310, layout.minimumHeight()); + setLayout(layout); runToBreakpoint.onTick = []() { if(breakpointEditor.runToBreakpoint.checked()) { diff --git a/bsnes/ui/debugger/tools/memory-editor.cpp b/bsnes/ui/debugger/tools/memory-editor.cpp index 76b06f48..52cb46e2 100755 --- a/bsnes/ui/debugger/tools/memory-editor.cpp +++ b/bsnes/ui/debugger/tools/memory-editor.cpp @@ -1,7 +1,7 @@ MemoryEditor memoryEditor; void MemoryEditor::create() { - Window::create(0, 0, 570, 230, "Memory Editor"); + setTitle("Memory Editor"); application.addWindow(this, "Debugger.MemoryEditor", "192,192"); editor.setFont(application.monospaceFont); @@ -20,6 +20,8 @@ void MemoryEditor::create() { controlLayout.append(gotoBox, 80, Style::ComboBoxHeight); controlLayout.append(refreshButton, 80, Style::ComboBoxHeight); layout.append(controlLayout, 80, 0); + + setGeometry(0, 0, layout.minimumWidth() + 475, 230); setLayout(layout); onClose = []() { diff --git a/bsnes/ui/general/file-browser.cpp b/bsnes/ui/general/file-browser.cpp index 9c5a82f1..c600c950 100755 --- a/bsnes/ui/general/file-browser.cpp +++ b/bsnes/ui/general/file-browser.cpp @@ -1,18 +1,19 @@ FileBrowser fileBrowser; void FileBrowser::create() { - Window::create(0, 0, 640, 400); application.addWindow(this, "FileBrowser", "160,160"); browseButton.setText("..."); upButton.setText(".."); layout.setMargin(5); - pathLayout.append(pathBox, 0, Style::TextBoxHeight, 5); - pathLayout.append(browseButton, Style::TextBoxHeight, Style::TextBoxHeight, 5); - pathLayout.append(upButton, Style::TextBoxHeight, Style::TextBoxHeight); + pathLayout.append(pathBox, 0, 0, 5); + pathLayout.append(browseButton, Style::TextBoxHeight, 0, 5); + pathLayout.append(upButton, Style::TextBoxHeight, 0); layout.append(pathLayout, 0, Style::TextBoxHeight, 5); layout.append(contentsBox, 0, 0); + + setGeometry(0, 0, 640, layout.minimumHeight() + 400); setLayout(layout); pathBox.onActivate = []() { diff --git a/bsnes/ui/general/main-window.cpp b/bsnes/ui/general/main-window.cpp index 14fad801..9f7a1a68 100755 --- a/bsnes/ui/general/main-window.cpp +++ b/bsnes/ui/general/main-window.cpp @@ -1,39 +1,226 @@ MainWindow mainWindow; void MainWindow::create() { - Window::create(0, 0, 595, 448, { SNES::Info::Name, " v", SNES::Info::Version }); + setTitle({ SNES::Info::Name, " v", SNES::Info::Version }); + setResizable(false); + setGeometry(0, 0, 595, 448); application.addWindow(this, "MainWindow", "128,128"); setFont(application.proportionalFontBold); setBackgroundColor(0, 0, 0); - system.create(*this, "System"); - systemLoadCartridge.create(system, "Load Cartridge ..."); - systemLoadCartridgeSpecial.create(system, "Load Special"); - systemLoadCartridgeBsxSlotted.create(systemLoadCartridgeSpecial, "Load BS-X Slotted Cartridge ..."); - systemLoadCartridgeBsx.create(systemLoadCartridgeSpecial, "Load BS-X Cartridge ..."); - systemLoadCartridgeSufamiTurbo.create(systemLoadCartridgeSpecial, "Load Sufami Turbo Cartridge ..."); - systemLoadCartridgeSuperGameBoy.create(systemLoadCartridgeSpecial, "Load Super Game Boy Cartridge ..."); - systemSeparator1.create(system); - systemPower.create(system, "Power Cycle"); - systemReset.create(system, "Reset"); - systemSeparator2.create(system); - systemPort1.create(system, "Controller Port 1"); - systemPort1None.create(systemPort1, "None"); - systemPort1Gamepad.create(systemPort1None, "Gamepad"); - systemPort1Multitap.create(systemPort1None, "Multitap"); - systemPort1Mouse.create(systemPort1None, "Mouse"); + system.setText("System"); + + systemLoadCartridge.setText("Load Cartridge ..."); + system.append(systemLoadCartridge); + + systemLoadCartridgeSpecial.setText("Load Special"); + system.append(systemLoadCartridgeSpecial); + + systemLoadCartridgeBsxSlotted.setText("Load BS-X Slotted Cartridge ..."); + systemLoadCartridgeSpecial.append(systemLoadCartridgeBsxSlotted); + + systemLoadCartridgeBsx.setText("Load BS-X Cartridge ..."); + systemLoadCartridgeSpecial.append(systemLoadCartridgeBsx); + + systemLoadCartridgeSufamiTurbo.setText("Load Sufami Turbo Cartridge ..."); + systemLoadCartridgeSpecial.append(systemLoadCartridgeSufamiTurbo); + + systemLoadCartridgeSuperGameBoy.setText("Load Super Game Boy Cartridge ..."); + systemLoadCartridgeSpecial.append(systemLoadCartridgeSuperGameBoy); + + system.append(systemSeparator1); + + systemPower.setText("Power Cycle"); + system.append(systemPower); + + systemReset.setText("Reset"); + system.append(systemReset); + + system.append(systemSeparator2); + + systemPort1.setText("Controller Port 1"); + system.append(systemPort1); + + systemPort1None.setText("None"); + systemPort1.append(systemPort1None); + + systemPort1Gamepad.setText("Gamepad"); + systemPort1Gamepad.setParent(systemPort1None); + systemPort1.append(systemPort1Gamepad); + + systemPort1Multitap.setText("Multitap"); + systemPort1Multitap.setParent(systemPort1None); + systemPort1.append(systemPort1Multitap); + + systemPort1Mouse.setText("Mouse"); + systemPort1Mouse.setParent(systemPort1None); + systemPort1.append(systemPort1Mouse); + + systemPort2.setText("Controller Port 2"); + system.append(systemPort2); + + systemPort2None.setText("None"); + systemPort2.append(systemPort2None); + + systemPort2Gamepad.setText("Gamepad"); + systemPort2Gamepad.setParent(systemPort2None); + systemPort2.append(systemPort2Gamepad); + + systemPort2Multitap.setText("Multitap"); + systemPort2Multitap.setParent(systemPort2None); + systemPort2.append(systemPort2Multitap); + + systemPort2Mouse.setText("Mouse"); + systemPort2Mouse.setParent(systemPort2None); + systemPort2.append(systemPort2Mouse); + + systemPort2SuperScope.setText("Super Scope"); + systemPort2SuperScope.setParent(systemPort2None); + systemPort2.append(systemPort2SuperScope); + + systemPort2Justifier.setText("Justifier"); + systemPort2Justifier.setParent(systemPort2None); + systemPort2.append(systemPort2Justifier); + + systemPort2Justifiers.setText("Justifiers"); + systemPort2Justifiers.setParent(systemPort2None); + systemPort2.append(systemPort2Justifiers); + + append(system); + + settings.setText("Settings"); + + settingsVideoMode.setText("Video Mode"); + settings.append(settingsVideoMode); + + settingsVideoMode1x.setText("Scale 1x"); + settingsVideoMode.append(settingsVideoMode1x); + + settingsVideoMode2x.setText("Scale 2x"); + settingsVideoMode2x.setParent(settingsVideoMode1x); + settingsVideoMode.append(settingsVideoMode2x); + + settingsVideoMode3x.setText("Scale 3x"); + settingsVideoMode3x.setParent(settingsVideoMode1x); + settingsVideoMode.append(settingsVideoMode3x); + + settingsVideoMode4x.setText("Scale 4x"); + settingsVideoMode4x.setParent(settingsVideoMode1x); + settingsVideoMode.append(settingsVideoMode4x); + + settingsVideoMode5x.setText("Scale 5x"); + settingsVideoMode5x.setParent(settingsVideoMode1x); + settingsVideoMode.append(settingsVideoMode5x); + + settingsVideoMode.append(settingsVideoModeSeparator1); + + settingsVideoModeAspectRatioCorrection.setText("Correct Aspect Ratio"); + settingsVideoMode.append(settingsVideoModeAspectRatioCorrection); + + settingsVideoMode.append(settingsVideoModeSeparator2); + + settingsVideoModeNTSC.setText("NTSC"); + settingsVideoMode.append(settingsVideoModeNTSC); + + settingsVideoModePAL.setText("PAL"); + settingsVideoMode.append(settingsVideoModePAL); + + settingsSmoothVideo.setText("Smooth Video"); + settings.append(settingsSmoothVideo); + + settings.append(settingsSeparator1); + + settingsSynchronizeVideo.setText("Synchronize Video"); + settings.append(settingsSynchronizeVideo); + + settingsSynchronizeAudio.setText("Synchronize Audio"); + settings.append(settingsSynchronizeAudio); + + settingsMuteAudio.setText("Mute Audio"); + settings.append(settingsMuteAudio); + + settings.append(settingsSeparator2); + + settingsVideo.setText("Video Settings ..."); + settings.append(settingsVideo); + + settingsAudio.setText("Audio Settings ..."); + settings.append(settingsAudio); + + settingsInput.setText("Input Settings ..."); + settings.append(settingsInput); + + settingsAdvanced.setText("Advanced Settings ..."); + settings.append(settingsAdvanced); + + append(settings); + + tools.setText("Tools"); + + toolsStateSave.setText("Save State"); + tools.append(toolsStateSave); + + toolsStateSave1.setText("Slot 1"); + toolsStateSave.append(toolsStateSave1); + + toolsStateSave2.setText("Slot 2"); + toolsStateSave.append(toolsStateSave2); + + toolsStateSave3.setText("Slot 3"); + toolsStateSave.append(toolsStateSave3); + + toolsStateSave4.setText("Slot 4"); + toolsStateSave.append(toolsStateSave4); + + toolsStateSave5.setText("Slot 5"); + toolsStateSave.append(toolsStateSave5); + + toolsStateLoad.setText("Load State"); + tools.append(toolsStateLoad); + + toolsStateLoad1.setText("Slot 1"); + toolsStateLoad.append(toolsStateLoad1); + + toolsStateLoad2.setText("Slot 2"); + toolsStateLoad.append(toolsStateLoad2); + + toolsStateLoad3.setText("Slot 3"); + toolsStateLoad.append(toolsStateLoad3); + + toolsStateLoad4.setText("Slot 4"); + toolsStateLoad.append(toolsStateLoad4); + + toolsStateLoad5.setText("Slot 5"); + toolsStateLoad.append(toolsStateLoad5); + + tools.append(toolsSeparator1); + + toolsCheatEditor.setText("Cheat Editor ..."); + tools.append(toolsCheatEditor); + + toolsStateManager.setText("State Manager ..."); + tools.append(toolsStateManager); + + #if defined(DEBUGGER) + tools.append(toolsSeparator2); + + toolsDebugger.setText("Debugger ..."); + tools.append(toolsDebugger); + #endif + + append(tools); + + help.setText("Help"); + + helpAbout.setText("About ..."); + help.append(helpAbout); + + append(help); + if(config.controller.port1 == 0) systemPort1None.setChecked(); if(config.controller.port1 == 1) systemPort1Gamepad.setChecked(); if(config.controller.port1 == 2) systemPort1Multitap.setChecked(); if(config.controller.port1 == 3) systemPort1Mouse.setChecked(); - systemPort2.create(system, "Controller Port 2"); - systemPort2None.create(systemPort2, "None"); - systemPort2Gamepad.create(systemPort2None, "Gamepad"); - systemPort2Multitap.create(systemPort2None, "Multitap"); - systemPort2Mouse.create(systemPort2None, "Mouse"); - systemPort2SuperScope.create(systemPort2None, "Super Scope"); - systemPort2Justifier.create(systemPort2None, "Justifier"); - systemPort2Justifiers.create(systemPort2None, "Justifiers"); if(config.controller.port2 == 0) systemPort2None.setChecked(); if(config.controller.port2 == 1) systemPort2Gamepad.setChecked(); if(config.controller.port2 == 2) systemPort2Multitap.setChecked(); @@ -42,64 +229,18 @@ void MainWindow::create() { if(config.controller.port2 == 5) systemPort2Justifier.setChecked(); if(config.controller.port2 == 6) systemPort2Justifiers.setChecked(); - settings.create(*this, "Settings"); - settingsVideoMode.create(settings, "Video Mode"); - settingsVideoMode1x.create(settingsVideoMode, "Scale 1x"); - settingsVideoMode2x.create(settingsVideoMode1x, "Scale 2x"); - settingsVideoMode3x.create(settingsVideoMode1x, "Scale 3x"); - settingsVideoMode4x.create(settingsVideoMode1x, "Scale 4x"); - settingsVideoMode5x.create(settingsVideoMode1x, "Scale 5x"); if(config.video.scale == 1) settingsVideoMode1x.setChecked(); if(config.video.scale == 2) settingsVideoMode2x.setChecked(); if(config.video.scale == 3) settingsVideoMode3x.setChecked(); if(config.video.scale == 4) settingsVideoMode4x.setChecked(); if(config.video.scale == 5) settingsVideoMode5x.setChecked(); - settingsVideoModeSeparator1.create(settingsVideoMode); - settingsVideoModeAspectRatioCorrection.create(settingsVideoMode, "Correct Aspect Ratio"); settingsVideoModeAspectRatioCorrection.setChecked(config.video.aspectRatioCorrection); - settingsVideoModeSeparator2.create(settingsVideoMode); - settingsVideoModeNTSC.create(settingsVideoMode, "NTSC"); - settingsVideoModePAL.create(settingsVideoModeNTSC, "PAL"); if(config.video.region == 0) settingsVideoModeNTSC.setChecked(); if(config.video.region == 1) settingsVideoModePAL.setChecked(); - settingsSmoothVideo.create(settings, "Smooth Video"); settingsSmoothVideo.setChecked(config.video.smooth); - settingsSeparator1.create(settings); - settingsSynchronizeVideo.create(settings, "Synchronize Video"); settingsSynchronizeVideo.setChecked(config.video.synchronize); - settingsSynchronizeAudio.create(settings, "Synchronize Audio"); settingsSynchronizeAudio.setChecked(config.audio.synchronize); - settingsMuteAudio.create(settings, "Mute Audio"); settingsMuteAudio.setChecked(config.audio.mute); - settingsSeparator2.create(settings); - settingsVideo.create(settings, "Video Settings ..."); - settingsAudio.create(settings, "Audio Settings ..."); - settingsInput.create(settings, "Input Settings ..."); - settingsAdvanced.create(settings, "Advanced Settings ..."); - - tools.create(*this, "Tools"); - toolsStateSave.create(tools, "Save State"); - toolsStateSave1.create(toolsStateSave, "Slot 1"); - toolsStateSave2.create(toolsStateSave, "Slot 2"); - toolsStateSave3.create(toolsStateSave, "Slot 3"); - toolsStateSave4.create(toolsStateSave, "Slot 4"); - toolsStateSave5.create(toolsStateSave, "Slot 5"); - toolsStateLoad.create(tools, "Load State"); - toolsStateLoad1.create(toolsStateLoad, "Slot 1"); - toolsStateLoad2.create(toolsStateLoad, "Slot 2"); - toolsStateLoad3.create(toolsStateLoad, "Slot 3"); - toolsStateLoad4.create(toolsStateLoad, "Slot 4"); - toolsStateLoad5.create(toolsStateLoad, "Slot 5"); - toolsSeparator1.create(tools); - toolsCheatEditor.create(tools, "Cheat Editor ..."); - toolsStateManager.create(tools, "State Manager ..."); - #if defined(DEBUGGER) - toolsSeparator2.create(tools); - toolsDebugger.create(tools, "Debugger ..."); - #endif - - help.create(*this, "Help"); - helpAbout.create(help, "About ..."); layout.append(viewport, 0, 0, 595, 448); setLayout(layout); @@ -212,10 +353,6 @@ void MainWindow::create() { return false; }; - onResize = []() { - utility.centerViewport(); - }; - synchronize(); } diff --git a/bsnes/ui/general/slot-loader.cpp b/bsnes/ui/general/slot-loader.cpp index fd7a4e4f..ae2a8ae6 100755 --- a/bsnes/ui/general/slot-loader.cpp +++ b/bsnes/ui/general/slot-loader.cpp @@ -2,7 +2,6 @@ SingleSlotLoader singleSlotLoader; DoubleSlotLoader doubleSlotLoader; void SingleSlotLoader::create() { - Window::create(0, 0, 480, 80); application.addWindow(this, "SingleSlotLoader", "160,160"); baseLabel.setText("Base:"); @@ -12,17 +11,19 @@ void SingleSlotLoader::create() { okButton.setText("Ok"); layout.setMargin(5); - baseLayout.append(baseLabel, 40, Style::TextBoxHeight, 5); - baseLayout.append(basePath, 0, Style::TextBoxHeight, 5); - baseLayout.append(baseBrowse, Style::TextBoxHeight, Style::TextBoxHeight); + baseLayout.append(baseLabel, 40, 0, 5); + baseLayout.append(basePath, 0, 0, 5); + baseLayout.append(baseBrowse, Style::TextBoxHeight, 0); layout.append(baseLayout, 0, Style::TextBoxHeight, 5); - slotLayout.append(slotLabel, 40, Style::TextBoxHeight, 5); - slotLayout.append(slotPath, 0, Style::TextBoxHeight, 5); - slotLayout.append(slotBrowse, Style::TextBoxHeight, Style::TextBoxHeight); + slotLayout.append(slotLabel, 40, 0, 5); + slotLayout.append(slotPath, 0, 0, 5); + slotLayout.append(slotBrowse, Style::TextBoxHeight, 0); layout.append(slotLayout, 0, Style::TextBoxHeight, 5); - controlLayout.append(spacer, 0, Style::ButtonHeight); - controlLayout.append(okButton, 80, Style::ButtonHeight); + controlLayout.append(spacer, 0, 0); + controlLayout.append(okButton, 80, 0); layout.append(controlLayout, 0, Style::ButtonHeight); + + setGeometry(0, 0, 480, layout.minimumHeight()); setLayout(layout); baseBrowse.onTick = []() { @@ -93,7 +94,6 @@ void SingleSlotLoader::load() { // void DoubleSlotLoader::create() { - Window::create(0, 0, 480, 115); application.addWindow(this, "DoubleSlotLoader", "160,160"); baseLabel.setText("Base:"); @@ -105,21 +105,23 @@ void DoubleSlotLoader::create() { okButton.setText("Ok"); layout.setMargin(5); - baseLayout.append(baseLabel, 40, Style::TextBoxHeight, 5); - baseLayout.append(basePath, 0, Style::TextBoxHeight, 5); - baseLayout.append(baseBrowse, Style::TextBoxHeight, Style::TextBoxHeight); + baseLayout.append(baseLabel, 40, 0, 5); + baseLayout.append(basePath, 0, 0, 5); + baseLayout.append(baseBrowse, Style::TextBoxHeight, 0); layout.append(baseLayout, 0, Style::TextBoxHeight, 5); - slotALayout.append(slotALabel, 40, Style::TextBoxHeight, 5); - slotALayout.append(slotAPath, 0, Style::TextBoxHeight, 5); - slotALayout.append(slotABrowse, Style::TextBoxHeight, Style::TextBoxHeight); + slotALayout.append(slotALabel, 40, 0, 5); + slotALayout.append(slotAPath, 0, 0, 5); + slotALayout.append(slotABrowse, Style::TextBoxHeight, 0); layout.append(slotALayout, 0, Style::TextBoxHeight, 5); - slotBLayout.append(slotBLabel, 40, Style::TextBoxHeight, 5); - slotBLayout.append(slotBPath, 0, Style::TextBoxHeight, 5); - slotBLayout.append(slotBBrowse, Style::TextBoxHeight, Style::TextBoxHeight); + slotBLayout.append(slotBLabel, 40, 0, 5); + slotBLayout.append(slotBPath, 0, 0, 5); + slotBLayout.append(slotBBrowse, Style::TextBoxHeight, 0); layout.append(slotBLayout, 0, Style::TextBoxHeight, 5); - controlLayout.append(spacer, 0, Style::ButtonHeight); - controlLayout.append(okButton, 80, Style::ButtonHeight); + controlLayout.append(spacer, 0, 0); + controlLayout.append(okButton, 80, 0); layout.append(controlLayout, 0, Style::ButtonHeight); + + setGeometry(0, 0, 480, layout.minimumHeight()); setLayout(layout); baseBrowse.onTick = []() { diff --git a/bsnes/ui/main.cpp b/bsnes/ui/main.cpp index 0a85bf6e..8303fd88 100755 --- a/bsnes/ui/main.cpp +++ b/bsnes/ui/main.cpp @@ -151,7 +151,7 @@ void Application::loadGeometry() { lstring position; position.split(",", window->position); Geometry geom = window->geometry(); - window->setGeometry(decimal(position[0]), decimal(position[1]), geom.width, geom.height); + window->setGeometry(integer(position[0]), integer(position[1]), geom.width, geom.height); } } diff --git a/bsnes/ui/settings/advanced.cpp b/bsnes/ui/settings/advanced.cpp index 1a37fb2d..023cd5e5 100755 --- a/bsnes/ui/settings/advanced.cpp +++ b/bsnes/ui/settings/advanced.cpp @@ -1,7 +1,7 @@ AdvancedSettings advancedSettings; void AdvancedSettings::create() { - Window::create(0, 0, 640, 80, "Advanced Settings"); + setTitle("Advanced Settings"); application.addWindow(this, "AdvancedSettings", "160,160"); driverSelectionLabel.setText("Driver Selection :."); @@ -22,34 +22,21 @@ void AdvancedSettings::create() { layout.setMargin(5); layout.append(driverSelectionLabel, 0, Style::LabelHeight); - driverLayout.append(videoDriverLabel, 40, Style::ComboBoxHeight, 5); - driverLayout.append(videoDriverBox, 0, Style::ComboBoxHeight, 5); - driverLayout.append(audioDriverLabel, 40, Style::ComboBoxHeight, 5); - driverLayout.append(audioDriverBox, 0, Style::ComboBoxHeight, 5); - driverLayout.append(inputDriverLabel, 40, Style::ComboBoxHeight, 5); - driverLayout.append(inputDriverBox, 0, Style::ComboBoxHeight); + driverLayout.append(videoDriverLabel, 40, 0, 5); + driverLayout.append(videoDriverBox, 0, 0, 5); + driverLayout.append(audioDriverLabel, 40, 0, 5); + driverLayout.append(audioDriverBox, 0, 0, 5); + driverLayout.append(inputDriverLabel, 40, 0, 5); + driverLayout.append(inputDriverBox, 0, 0); layout.append(driverLayout, 0, Style::ComboBoxHeight, 5); layout.append(focusPolicyLabel, 0, Style::LabelHeight); - focusPolicyLayout.append(focusPolicyPause, 0, Style::CheckBoxHeight, 5); - focusPolicyLayout.append(focusPolicyIgnore, 0, Style::CheckBoxHeight, 5); - focusPolicyLayout.append(focusPolicyAllow, 0, Style::CheckBoxHeight); + focusPolicyLayout.append(focusPolicyPause, 0, 0, 5); + focusPolicyLayout.append(focusPolicyIgnore, 0, 0, 5); + focusPolicyLayout.append(focusPolicyAllow, 0, 0); layout.append(focusPolicyLayout, 0, Style::CheckBoxHeight); - setLayout(layout); -/*unsigned x = 5, y = 5; - layout.append(driverSelectionLabel, x, y, 595, Style::LabelHeight); y += Style::LabelHeight + 5; - layout.append(videoDriverLabel, x, y, 45, Style::ComboBoxHeight); - layout.append(videoDriverBox, x + 45, y, 150, Style::ComboBoxHeight); - layout.append(audioDriverLabel, x + 200, y, 45, Style::ComboBoxHeight); - layout.append(audioDriverBox, x + 245, y, 150, Style::ComboBoxHeight); - layout.append(inputDriverLabel, x + 400, y, 45, Style::ComboBoxHeight); - layout.append(inputDriverBox, x + 445, y, 150, Style::ComboBoxHeight); y += Style::ComboBoxHeight + 5; - layout.append(focusPolicyLabel, x, y, 595, Style::LabelHeight); y += Style::LabelHeight + 5; - layout.append(focusPolicyPause, x, y, 195, Style::CheckBoxHeight); - layout.append(focusPolicyIgnore, x + 200, y, 195, Style::CheckBoxHeight); - layout.append(focusPolicyAllow, x + 400, y, 195, Style::CheckBoxHeight); y += Style::CheckBoxHeight + 5; - setGeometry(0, 0, 605, y); - setLayout(layout);*/ + setGeometry(0, 0, 640, layout.minimumHeight()); + setLayout(layout); lstring list; diff --git a/bsnes/ui/settings/audio.cpp b/bsnes/ui/settings/audio.cpp index d97d7873..febe7d32 100755 --- a/bsnes/ui/settings/audio.cpp +++ b/bsnes/ui/settings/audio.cpp @@ -1,7 +1,7 @@ AudioSettings audioSettings; void AudioSettings::create() { - Window::create(0, 0, 480, 50, "Audio Settings"); + setTitle("Audio Settings"); application.addWindow(this, "AudioSettings", "160,160"); volumeLabel.setText("Volume:"); @@ -10,25 +10,17 @@ void AudioSettings::create() { frequencySlider.setLength(2001); layout.setMargin(5); - volumeLayout.append(volumeLabel, 70, Style::SliderHeight); - volumeLayout.append(volumeValue, 60, Style::SliderHeight); - volumeLayout.append(volumeSlider, 0, Style::SliderHeight); + volumeLayout.append(volumeLabel, 70, 0); + volumeLayout.append(volumeValue, 60, 0); + volumeLayout.append(volumeSlider, 0, 0); layout.append(volumeLayout, 0, Style::SliderHeight); - frequencyLayout.append(frequencyLabel, 70, Style::SliderHeight); - frequencyLayout.append(frequencyValue, 60, Style::SliderHeight); - frequencyLayout.append(frequencySlider, 0, Style::SliderHeight); + frequencyLayout.append(frequencyLabel, 70, 0); + frequencyLayout.append(frequencyValue, 60, 0); + frequencyLayout.append(frequencySlider, 0, 0); layout.append(frequencyLayout, 0, Style::SliderHeight); - setLayout(layout); -/*unsigned x = 5, y = 5; - layout.append(volumeLabel, x, y, 70, Style::SliderHeight); - layout.append(volumeValue, x + 70, y, 60, Style::SliderHeight); - layout.append(volumeSlider, x + 130, y, 300, Style::SliderHeight); y += Style::SliderHeight + 5; - layout.append(frequencyLabel, x, y, 70, Style::SliderHeight); - layout.append(frequencyValue, x + 70, y, 60, Style::SliderHeight); - layout.append(frequencySlider, x + 130, y, 300, Style::SliderHeight); y += Style::SliderHeight + 5; - setGeometry(0, 0, 440, y); - setLayout(layout);*/ + setGeometry(0, 0, 480, layout.minimumHeight()); + setLayout(layout); volumeSlider.onChange = []() { config.audio.volume = audioSettings.volumeSlider.position(); diff --git a/bsnes/ui/settings/input.cpp b/bsnes/ui/settings/input.cpp index 3bbb8565..4ebfbf21 100755 --- a/bsnes/ui/settings/input.cpp +++ b/bsnes/ui/settings/input.cpp @@ -2,7 +2,7 @@ InputSettings inputSettings; static InputMapper::AbstractInput *activeInput = 0; void InputSettings::create() { - Window::create(0, 0, 640, 300, "Input Settings"); + setTitle("Input Settings"); application.addWindow(this, "InputSettings", "160,160"); setFont(application.proportionalFontBold); setStatusVisible(); @@ -24,20 +24,22 @@ void InputSettings::create() { clearButton.setText("Clear"); layout.setMargin(5); - selectionLayout.append(portLabel, 50, Style::ComboBoxHeight, 5); - selectionLayout.append(portBox, 0, Style::ComboBoxHeight, 5); - selectionLayout.append(deviceLabel, 50, Style::ComboBoxHeight, 5); - selectionLayout.append(deviceBox, 0, Style::ComboBoxHeight); + selectionLayout.append(portLabel, 50, 0, 5); + selectionLayout.append(portBox, 0, 0, 5); + selectionLayout.append(deviceLabel, 50, 0, 5); + selectionLayout.append(deviceBox, 0, 0); layout.append(selectionLayout, 0, Style::ComboBoxHeight, 5); layout.append(mappingList, 0, 0, 5); - mapLayout.append(mouseXaxis, 100, Style::ButtonHeight, 5); - mapLayout.append(mouseYaxis, 100, Style::ButtonHeight, 5); - mapLayout.append(mouseLeft, 100, Style::ButtonHeight, 5); - mapLayout.append(mouseMiddle, 100, Style::ButtonHeight, 5); - mapLayout.append(mouseRight, 100, Style::ButtonHeight, 5); - mapLayout.append(spacer, 0, Style::ButtonHeight); - mapLayout.append(clearButton, 80, Style::ButtonHeight); + 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); layout.append(mapLayout, 0, Style::ButtonHeight); + + setGeometry(0, 0, 640, layout.minimumHeight() + 250); setLayout(layout); mouseXaxis.setVisible(false); diff --git a/bsnes/ui/settings/video.cpp b/bsnes/ui/settings/video.cpp index 913fb5f3..fd2325d0 100755 --- a/bsnes/ui/settings/video.cpp +++ b/bsnes/ui/settings/video.cpp @@ -1,7 +1,7 @@ VideoSettings videoSettings; void VideoSettings::create() { - Window::create(0, 0, 480, 225, "Video Settings"); + setTitle("Video Settings"); application.addWindow(this, "VideoSettings", "160,160"); colorAdjustmentLabel.setText("Color Adjustment :."); @@ -33,34 +33,36 @@ void VideoSettings::create() { layout.setMargin(5); layout.append(colorAdjustmentLabel, 0, Style::LabelHeight); - brightnessLayout.append(brightnessLabel, 80, Style::SliderHeight); - brightnessLayout.append(brightnessValue, 50, Style::SliderHeight); - brightnessLayout.append(brightnessSlider, 0, Style::SliderHeight); + brightnessLayout.append(brightnessLabel, 80, 0); + brightnessLayout.append(brightnessValue, 50, 0); + brightnessLayout.append(brightnessSlider, 0, 0); layout.append(brightnessLayout, 0, Style::SliderHeight); - contrastLayout.append(contrastLabel, 80, Style::SliderHeight); - contrastLayout.append(contrastValue, 50, Style::SliderHeight); - contrastLayout.append(contrastSlider, 0, Style::SliderHeight); + contrastLayout.append(contrastLabel, 80, 0); + contrastLayout.append(contrastValue, 50, 0); + contrastLayout.append(contrastSlider, 0, 0); layout.append(contrastLayout, 0, Style::SliderHeight); - gammaLayout.append(gammaLabel, 80, Style::SliderHeight); - gammaLayout.append(gammaValue, 50, Style::SliderHeight); - gammaLayout.append(gammaSlider, 0, Style::SliderHeight); + gammaLayout.append(gammaLabel, 80, 0); + gammaLayout.append(gammaValue, 50, 0); + gammaLayout.append(gammaSlider, 0, 0); layout.append(gammaLayout, 0, Style::SliderHeight); layout.append(gammaRampCheck, 0, Style::CheckBoxHeight, 5); layout.append(fullscreenLabel, 0, Style::LabelHeight); - fullscreenLayout.append(fullscreenCenter, 0, Style::CheckBoxHeight); - fullscreenLayout.append(fullscreenScale, 0, Style::CheckBoxHeight); - fullscreenLayout.append(fullscreenStretch, 0, Style::CheckBoxHeight); + fullscreenLayout.append(fullscreenCenter, 0, 0); + fullscreenLayout.append(fullscreenScale, 0, 0); + fullscreenLayout.append(fullscreenStretch, 0, 0); layout.append(fullscreenLayout, 0, Style::CheckBoxHeight, 5); layout.append(filterLabel, 0, Style::LabelHeight); - filterLayout.append(filterPath, 0, Style::TextBoxHeight, 5); - filterLayout.append(filterClear, Style::TextBoxHeight, Style::TextBoxHeight, 5); - filterLayout.append(filterSelect, Style::TextBoxHeight, Style::TextBoxHeight); + filterLayout.append(filterPath, 0, 0, 5); + filterLayout.append(filterClear, Style::TextBoxHeight, 0, 5); + filterLayout.append(filterSelect, Style::TextBoxHeight, 0); layout.append(filterLayout, 0, Style::TextBoxHeight, 5); layout.append(shaderLabel, 0, Style::LabelHeight); - shaderLayout.append(shaderPath, 0, Style::TextBoxHeight, 5); - shaderLayout.append(shaderClear, Style::TextBoxHeight, Style::TextBoxHeight, 5); - shaderLayout.append(shaderSelect, Style::TextBoxHeight, Style::TextBoxHeight); + shaderLayout.append(shaderPath, 0, 0, 5); + shaderLayout.append(shaderClear, Style::TextBoxHeight, 0, 5); + shaderLayout.append(shaderSelect, Style::TextBoxHeight, 0); layout.append(shaderLayout, 0, Style::TextBoxHeight); + + setGeometry(0, 0, 480, layout.minimumHeight()); setLayout(layout); brightnessSlider.setPosition(config.video.brightness); diff --git a/bsnes/ui/tools/cheat-editor.cpp b/bsnes/ui/tools/cheat-editor.cpp index 869beac0..e4e461a2 100755 --- a/bsnes/ui/tools/cheat-editor.cpp +++ b/bsnes/ui/tools/cheat-editor.cpp @@ -79,7 +79,7 @@ void CheatEditor::save(string filename) { } void CheatEditor::create() { - Window::create(0, 0, 480, 325, "Cheat Editor"); + setTitle("Cheat Editor"); application.addWindow(this, "CheatEditor", "160,160"); cheatList.setHeaderText("Slot\tCode\tDescription"); @@ -93,17 +93,19 @@ void CheatEditor::create() { layout.setMargin(5); layout.append(cheatList, 0, 0, 5); - codeLayout.append(codeLabel, 80, Style::TextBoxHeight, 5); - codeLayout.append(codeEdit, 0, Style::TextBoxHeight); + codeLayout.append(codeLabel, 80, 0, 5); + codeLayout.append(codeEdit, 0, 0); layout.append(codeLayout, 0, Style::TextBoxHeight, 5); - descLayout.append(descLabel, 80, Style::TextBoxHeight, 5); - descLayout.append(descEdit, 0, Style::TextBoxHeight); + descLayout.append(descLabel, 80, 0, 5); + descLayout.append(descEdit, 0, 0); layout.append(descLayout, 0, Style::TextBoxHeight, 5); - controlLayout.append(findButton, 100, Style::ButtonHeight); - controlLayout.append(spacer, 0, Style::ButtonHeight); - controlLayout.append(clearAllButton, 80, Style::ButtonHeight, 5); - controlLayout.append(clearButton, 80, Style::ButtonHeight); + controlLayout.append(findButton, 100, 0); + controlLayout.append(spacer, 0, 0); + controlLayout.append(clearAllButton, 80, 0, 5); + controlLayout.append(clearButton, 80, 0); layout.append(controlLayout, 0, Style::ButtonHeight); + + setGeometry(0, 0, 480, layout.minimumHeight() + 250); setLayout(layout); synchronize(); @@ -121,7 +123,6 @@ void CheatEditor::create() { }; //databaseWindow - databaseWindow.create(0, 0, 600, 360); application.addWindow(&databaseWindow, "CheatDatabase", "192,192"); databaseList.setCheckable(true); @@ -131,11 +132,13 @@ void CheatEditor::create() { databaseLayout.setMargin(5); databaseLayout.append(databaseList, 0, 0, 5); - databaseControlLayout.append(databaseSelectAll, 100, Style::ButtonHeight, 5); - databaseControlLayout.append(databaseUnselectAll, 100, Style::ButtonHeight); - databaseControlLayout.append(databaseSpacer, 0, Style::ButtonHeight); - databaseControlLayout.append(databaseOk, 80, Style::ButtonHeight); + databaseControlLayout.append(databaseSelectAll, 100, 0, 5); + databaseControlLayout.append(databaseUnselectAll, 100, 0); + databaseControlLayout.append(databaseSpacer, 0, 0); + databaseControlLayout.append(databaseOk, 80, 0); databaseLayout.append(databaseControlLayout, 0, Style::ButtonHeight); + + databaseWindow.setGeometry(0, 0, 600, layout.minimumHeight() + 250); databaseWindow.setLayout(databaseLayout); databaseSelectAll.onTick = []() { diff --git a/bsnes/ui/tools/state-manager.cpp b/bsnes/ui/tools/state-manager.cpp index b00d9658..f972acf1 100755 --- a/bsnes/ui/tools/state-manager.cpp +++ b/bsnes/ui/tools/state-manager.cpp @@ -1,7 +1,7 @@ StateManager stateManager; void StateManager::create() { - Window::create(0, 0, 480, 300, "State Manager"); + setTitle("State Manager"); application.addWindow(this, "StateManager", "160,160"); stateList.setHeaderText("Slot\tDescription"); @@ -13,25 +13,17 @@ void StateManager::create() { layout.setMargin(5); layout.append(stateList, 0, 0, 5); - descLayout.append(descLabel, 80, Style::TextBoxHeight, 5); - descLayout.append(descEdit, 0, Style::TextBoxHeight); + descLayout.append(descLabel, 80, 0, 5); + descLayout.append(descEdit, 0, 0); layout.append(descLayout, 0, Style::TextBoxHeight, 5); - controlLayout.append(spacer, 0, Style::ButtonHeight); - controlLayout.append(loadButton, 80, Style::ButtonHeight, 5); - controlLayout.append(saveButton, 80, Style::ButtonHeight, 5); - controlLayout.append(eraseButton, 80, Style::ButtonHeight); + controlLayout.append(spacer, 0, 0); + controlLayout.append(loadButton, 80, 0, 5); + controlLayout.append(saveButton, 80, 0, 5); + controlLayout.append(eraseButton, 80, 0); layout.append(controlLayout, 0, Style::ButtonHeight); - setLayout(layout); -/*unsigned x = 5, y = 5; - layout.append(stateList, x, y, 500, 250); y += 255; - layout.append(descLabel, x, y, 80, Style::TextBoxHeight); - layout.append(descEdit, x + 80, y, 420, Style::TextBoxHeight); y += Style::TextBoxHeight + 5; - layout.append(loadButton, x + 505 - 85 - 85 - 85, y, 80, Style::ButtonHeight); - layout.append(saveButton, x + 505 - 85 - 85, y, 80, Style::ButtonHeight); - layout.append(eraseButton, x + 505 - 85, y, 80, Style::ButtonHeight); y += Style::ButtonHeight + 5; - setGeometry(0, 0, 510, y); - setLayout(layout);*/ + setGeometry(0, 0, 480, layout.minimumHeight() + 250); + setLayout(layout); synchronize(); diff --git a/bsnes/ui/utility/utility.cpp b/bsnes/ui/utility/utility.cpp index 04b25eb5..f48b9c60 100755 --- a/bsnes/ui/utility/utility.cpp +++ b/bsnes/ui/utility/utility.cpp @@ -57,16 +57,6 @@ void Utility::setControllers() { } } -void Utility::centerViewport() { - Geometry geometry = mainWindow.geometry(); - viewportX = viewportY = 0; - if(geometry.width >= viewportWidth) viewportX = (geometry.width - viewportWidth) / 2; - if(geometry.height >= viewportHeight) viewportY = (geometry.height - viewportHeight) / 2; - mainWindow.viewport.setGeometry( - viewportX, viewportY, min(geometry.width, viewportWidth), min(geometry.height, viewportHeight) - ); -} - void Utility::setScale(unsigned scale) { if(scale == 0) scale = config.video.scale; config.video.scale = scale; diff --git a/bsnes/ui/utility/utility.hpp b/bsnes/ui/utility/utility.hpp index 4977db51..a61c1c41 100755 --- a/bsnes/ui/utility/utility.hpp +++ b/bsnes/ui/utility/utility.hpp @@ -6,7 +6,6 @@ struct Utility : property { void setControllers(); - void centerViewport(); void setScale(unsigned scale = 0); void setFullscreen(bool fullscreen = true);