diff --git a/bsnes/gameboy/apu/noise/noise.cpp b/bsnes/gameboy/apu/noise/noise.cpp index 31855373..36d38bf5 100755 --- a/bsnes/gameboy/apu/noise/noise.cpp +++ b/bsnes/gameboy/apu/noise/noise.cpp @@ -10,7 +10,7 @@ void APU::Noise::run() { } } - uint4 sample = (lfsr & 1) ? -volume : volume; + uint4 sample = (lfsr & 1) ? 0 : volume; if(counter && length == 0) sample = 0; output = (sample * 4369) - 32768; diff --git a/bsnes/gameboy/gameboy.hpp b/bsnes/gameboy/gameboy.hpp index eac830c2..bb31c897 100755 --- a/bsnes/gameboy/gameboy.hpp +++ b/bsnes/gameboy/gameboy.hpp @@ -5,7 +5,7 @@ namespace GameBoy { namespace Info { static const char Name[] = "bgameboy"; - static const char Version[] = "000.17"; + static const char Version[] = "000.18"; static unsigned SerializerVersion = 1; } } diff --git a/bsnes/phoenix/gtk/canvas.cpp b/bsnes/phoenix/gtk/canvas.cpp index 43913871..ed86c5f4 100755 --- a/bsnes/phoenix/gtk/canvas.cpp +++ b/bsnes/phoenix/gtk/canvas.cpp @@ -16,22 +16,15 @@ static void Canvas_expose(Canvas *self) { ); } -void Canvas::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) { +void Canvas::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height) { + if(canvas->bufferRGB) delete[] canvas->bufferRGB; + if(canvas->bufferBGR) delete[] canvas->bufferBGR; + canvas->bufferRGB = new uint32_t[width * height](); canvas->bufferBGR = new uint32_t[width * height](); canvas->pitch = width * sizeof(uint32_t); - object->widget = gtk_drawing_area_new(); - widget->parent = &parent; - GdkColor color; - color.pixel = color.red = color.green = color.blue = 0; - gtk_widget_modify_bg(object->widget, GTK_STATE_NORMAL, &color); - gtk_widget_set_double_buffered(object->widget, false); - gtk_widget_add_events(object->widget, GDK_EXPOSURE_MASK); - gtk_widget_set_size_request(object->widget, width, height); - g_signal_connect_swapped(G_OBJECT(object->widget), "expose_event", G_CALLBACK(Canvas_expose), (gpointer)this); - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); - gtk_widget_show(object->widget); + Widget::setGeometry(x, y, width, height); } uint32_t* Canvas::buffer() { @@ -51,6 +44,15 @@ Canvas::Canvas() { canvas = new Canvas::Data; canvas->bufferRGB = 0; canvas->bufferBGR = 0; + canvas->pitch = 0; + + object->widget = gtk_drawing_area_new(); + GdkColor color; + color.pixel = color.red = color.green = color.blue = 0; + gtk_widget_modify_bg(object->widget, GTK_STATE_NORMAL, &color); + gtk_widget_set_double_buffered(object->widget, false); + gtk_widget_add_events(object->widget, GDK_EXPOSURE_MASK); + g_signal_connect_swapped(G_OBJECT(object->widget), "expose_event", G_CALLBACK(Canvas_expose), (gpointer)this); } Canvas::~Canvas() { diff --git a/bsnes/phoenix/gtk/combobox.cpp b/bsnes/phoenix/gtk/combobox.cpp index dbabf247..32f01533 100755 --- a/bsnes/phoenix/gtk/combobox.cpp +++ b/bsnes/phoenix/gtk/combobox.cpp @@ -2,35 +2,18 @@ void ComboBox_change(ComboBox *self) { if(self->object->locked == false && self->onChange) self->onChange(); } -void ComboBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - object->widget = gtk_combo_box_new_text(); - widget->parent = &parent; - gtk_widget_set_size_request(object->widget, width, height); - g_signal_connect_swapped(G_OBJECT(object->widget), "changed", G_CALLBACK(ComboBox_change), (gpointer)this); - - if(*text) { - lstring list; - list.split("\n", text); - foreach(item, list) addItem(item); - } - - if(parent.window->defaultFont) setFont(*parent.window->defaultFont); - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); - gtk_widget_show(object->widget); -} - void ComboBox::reset() { object->locked = true; - for(signed i = counter - 1; i >= 0; i--) { + for(signed i = comboBox->counter - 1; i >= 0; i--) { gtk_combo_box_remove_text(GTK_COMBO_BOX(object->widget), i); } object->locked = false; - counter = 0; + comboBox->counter = 0; } void ComboBox::addItem(const string &text) { gtk_combo_box_append_text(GTK_COMBO_BOX(object->widget), text); - if(counter++ == 0) setSelection(0); + if(comboBox->counter++ == 0) setSelection(0); } unsigned ComboBox::selection() { @@ -44,5 +27,8 @@ void ComboBox::setSelection(unsigned item) { } ComboBox::ComboBox() { - counter = 0; + comboBox = new ComboBox::Data; + comboBox->counter = 0; + object->widget = gtk_combo_box_new_text(); + g_signal_connect_swapped(G_OBJECT(object->widget), "changed", G_CALLBACK(ComboBox_change), (gpointer)this); } diff --git a/bsnes/phoenix/gtk/editbox.cpp b/bsnes/phoenix/gtk/editbox.cpp index 90cddfe9..fbd8afca 100755 --- a/bsnes/phoenix/gtk/editbox.cpp +++ b/bsnes/phoenix/gtk/editbox.cpp @@ -2,24 +2,6 @@ static void EditBox_change(EditBox *self) { if(self->object->locked == false && self->onChange) self->onChange(); } -void EditBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - object->widget = gtk_scrolled_window_new(0, 0); - widget->parent = &parent; - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(object->widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(object->widget), GTK_SHADOW_ETCHED_IN); - gtk_widget_set_size_request(object->widget, width, height); - object->subWidget = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(object->subWidget), GTK_WRAP_WORD_CHAR); - gtk_container_add(GTK_CONTAINER(object->widget), object->subWidget); - object->textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(object->subWidget)); - gtk_text_buffer_set_text(object->textBuffer, text, -1); - g_signal_connect_swapped(G_OBJECT(object->textBuffer), "changed", G_CALLBACK(EditBox_change), (gpointer)this); - if(parent.window->defaultFont) setFont(*parent.window->defaultFont); - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); - gtk_widget_show(object->subWidget); - gtk_widget_show(object->widget); -} - void EditBox::setFocused() { gtk_widget_grab_focus(object->subWidget); } @@ -56,3 +38,15 @@ void EditBox::setCursorPosition(unsigned position) { gtk_text_buffer_place_cursor(object->textBuffer, &iter); gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(object->subWidget), mark); } + +EditBox::EditBox() { + object->widget = gtk_scrolled_window_new(0, 0); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(object->widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(object->widget), GTK_SHADOW_ETCHED_IN); + object->subWidget = gtk_text_view_new(); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(object->subWidget), GTK_WRAP_WORD_CHAR); + gtk_container_add(GTK_CONTAINER(object->widget), object->subWidget); + object->textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(object->subWidget)); + g_signal_connect_swapped(G_OBJECT(object->textBuffer), "changed", G_CALLBACK(EditBox_change), (gpointer)this); + gtk_widget_show(object->subWidget); +} diff --git a/bsnes/phoenix/gtk/fixed-layout.cpp b/bsnes/phoenix/gtk/fixed-layout.cpp deleted file mode 100755 index bb6c7357..00000000 --- a/bsnes/phoenix/gtk/fixed-layout.cpp +++ /dev/null @@ -1,24 +0,0 @@ -void FixedLayout::setParent(Window &parent) { - Layout::setParent(parent); - foreach(child, fixedLayout->children) { - gtk_fixed_put(GTK_FIXED(layout->parent->object->formContainer), child.widget->object->widget, 0, 0); - } -} - -void FixedLayout::append(Widget &widget, unsigned x, unsigned y, unsigned width, unsigned height) { - fixedLayout->children.append({ &widget, x, y, width, height }); -} - -void FixedLayout::update(Geometry &geometry) { - Layout::update(geometry); - - foreach(child, fixedLayout->children) { - gtk_fixed_move(GTK_FIXED(layout->parent->object->formContainer), child.widget->object->widget, child.x, child.y); - gtk_widget_set_size_request(child.widget->object->widget, child.width, child.height); - gtk_widget_show(child.widget->object->widget); - } -} - -FixedLayout::FixedLayout() { - fixedLayout = new FixedLayout::Data; -} diff --git a/bsnes/phoenix/gtk/gtk.cpp b/bsnes/phoenix/gtk/gtk.cpp index cda00194..9ec6007b 100755 --- a/bsnes/phoenix/gtk/gtk.cpp +++ b/bsnes/phoenix/gtk/gtk.cpp @@ -23,7 +23,6 @@ namespace phoenix { #include "widget.cpp" #include "window.cpp" #include "layout.cpp" -#include "fixed-layout.cpp" #include "button.cpp" #include "canvas.cpp" #include "checkbox.cpp" diff --git a/bsnes/phoenix/gtk/gtk.hpp b/bsnes/phoenix/gtk/gtk.hpp index 1575a0aa..3adf2d7a 100755 --- a/bsnes/phoenix/gtk/gtk.hpp +++ b/bsnes/phoenix/gtk/gtk.hpp @@ -83,6 +83,8 @@ struct Widget; struct Window : Object { 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); bool focused(); @@ -108,25 +110,16 @@ struct Window : Object { struct Layout : Object { virtual void setParent(Window &parent); - virtual void update(Geometry &geometry); - void setMargin(unsigned margin); + virtual void setParent(Window &parent, Widget &child); + virtual void update(Geometry &geometry) = 0; Layout(); //private: struct Data; Data *layout; }; -struct FixedLayout : Layout { - void setParent(Window &parent); - void append(Widget &widget, unsigned x, unsigned y, unsigned width, unsigned height); - void update(Geometry &geometry); - FixedLayout(); -//private: - struct Data; - Data *fixedLayout; -}; - struct Widget : Object { + virtual Geometry geometry(); virtual void setGeometry(unsigned x, unsigned y, unsigned width, unsigned height); virtual void setFont(Font &font); bool visible(); @@ -148,7 +141,7 @@ struct Button : Widget { }; struct Canvas : Widget { - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height); + void setGeometry(unsigned x, unsigned y, unsigned width, unsigned height); uint32_t* buffer(); void redraw(); Canvas(); @@ -168,31 +161,30 @@ struct CheckBox : Widget { struct ComboBox : Widget { nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); void reset(); void addItem(const nall::string &text); unsigned selection(); void setSelection(unsigned item); ComboBox(); -private: - unsigned counter; +//private: + struct Data; + Data *comboBox; }; struct EditBox : Widget { nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); void setFocused(); void setEditable(bool editable = true); void setWordWrap(bool wordWrap = true); nall::string text(); void setText(const nall::string &text); void setCursorPosition(unsigned position); + EditBox(); }; struct HexEditor : Widget { nall::function onRead; nall::function onWrite; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height); void setSize(unsigned size); void setOffset(unsigned offset); void setColumns(unsigned columns); @@ -212,9 +204,10 @@ struct HexEditor : Widget { struct HorizontalSlider : Widget { nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length); unsigned position(); + void setLength(unsigned length); void setPosition(unsigned position); + HorizontalSlider(); }; struct Label : Widget { @@ -228,6 +221,7 @@ struct ListBox : Widget { nall::function onTick; void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); void setFocused(); + void setHeaderText(const nall::string &text); void setHeaderVisible(bool headerVisible = true); void setCheckable(bool checkable = true); void setFont(Font &font); @@ -246,8 +240,8 @@ struct ListBox : Widget { }; struct ProgressBar : Widget { - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height); void setPosition(unsigned position); + ProgressBar(); }; struct RadioBox : Widget { @@ -264,22 +258,23 @@ private: struct TextBox : Widget { nall::function onActivate; nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); void setEditable(bool editable = true); nall::string text(); void setText(const nall::string &text); + TextBox(); }; struct VerticalSlider : Widget { nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length); unsigned position(); + void setLength(unsigned length); void setPosition(unsigned position); + VerticalSlider(); }; struct Viewport : Widget { - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height); uintptr_t handle(); + Viewport(); }; struct MessageWindow : Object { diff --git a/bsnes/phoenix/gtk/hexeditor.cpp b/bsnes/phoenix/gtk/hexeditor.cpp index 2705a672..2ca4458f 100755 --- a/bsnes/phoenix/gtk/hexeditor.cpp +++ b/bsnes/phoenix/gtk/hexeditor.cpp @@ -7,47 +7,6 @@ static bool HexEditor_scroll(GtkRange *range, GtkScrollType scroll, gdouble valu return false; } -void HexEditor::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) { - widget->parent = &parent; - - hexEditor->size = 0; - hexEditor->offset = 0; - hexEditor->columns = 16; - hexEditor->rows = 16; - - object->widget = gtk_hbox_new(false, 0); - gtk_widget_set_size_request(object->widget, width, height); - - hexEditor->container = gtk_scrolled_window_new(0, 0); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(hexEditor->container), GTK_POLICY_NEVER, GTK_POLICY_NEVER); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(hexEditor->container), GTK_SHADOW_ETCHED_IN); - - hexEditor->widget = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(hexEditor->widget), GTK_WRAP_NONE); - gtk_container_add(GTK_CONTAINER(hexEditor->container), hexEditor->widget); - g_signal_connect(G_OBJECT(hexEditor->widget), "key-press-event", G_CALLBACK(HexEditor_keyPress), (gpointer)this); - - hexEditor->scroll = gtk_vscrollbar_new((GtkAdjustment*)0); - gtk_range_set_range(GTK_RANGE(hexEditor->scroll), 0, 256); - gtk_range_set_increments(GTK_RANGE(hexEditor->scroll), 1, 16); - gtk_widget_set_sensitive(hexEditor->scroll, false); - g_signal_connect(G_OBJECT(hexEditor->scroll), "change-value", G_CALLBACK(HexEditor_scroll), (gpointer)this); - - gtk_box_pack_start(GTK_BOX(object->widget), hexEditor->container, true, true, 0); - gtk_box_pack_start(GTK_BOX(object->widget), hexEditor->scroll, false, false, 1); - - object->textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(hexEditor->widget)); - hexEditor->cursor = gtk_text_buffer_get_mark(object->textBuffer, "insert"); - - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); - if(parent.window->defaultFont) setFont(*parent.window->defaultFont); - - gtk_widget_show(hexEditor->scroll); - gtk_widget_show(hexEditor->widget); - gtk_widget_show(hexEditor->container); - gtk_widget_show(object->widget); -} - void HexEditor::setSize(unsigned size) { hexEditor->size = size; setScroll(); @@ -111,6 +70,37 @@ void HexEditor::update() { HexEditor::HexEditor() { hexEditor = new HexEditor::Data; + hexEditor->size = 0; + hexEditor->offset = 0; + hexEditor->columns = 16; + hexEditor->rows = 16; + + object->widget = gtk_hbox_new(false, 0); + + hexEditor->container = gtk_scrolled_window_new(0, 0); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(hexEditor->container), GTK_POLICY_NEVER, GTK_POLICY_NEVER); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(hexEditor->container), GTK_SHADOW_ETCHED_IN); + + hexEditor->widget = gtk_text_view_new(); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(hexEditor->widget), GTK_WRAP_NONE); + gtk_container_add(GTK_CONTAINER(hexEditor->container), hexEditor->widget); + g_signal_connect(G_OBJECT(hexEditor->widget), "key-press-event", G_CALLBACK(HexEditor_keyPress), (gpointer)this); + + hexEditor->scroll = gtk_vscrollbar_new((GtkAdjustment*)0); + gtk_range_set_range(GTK_RANGE(hexEditor->scroll), 0, 256); + gtk_range_set_increments(GTK_RANGE(hexEditor->scroll), 1, 16); + gtk_widget_set_sensitive(hexEditor->scroll, false); + g_signal_connect(G_OBJECT(hexEditor->scroll), "change-value", G_CALLBACK(HexEditor_scroll), (gpointer)this); + + gtk_box_pack_start(GTK_BOX(object->widget), hexEditor->container, true, true, 0); + gtk_box_pack_start(GTK_BOX(object->widget), hexEditor->scroll, false, false, 1); + + object->textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(hexEditor->widget)); + hexEditor->cursor = gtk_text_buffer_get_mark(object->textBuffer, "insert"); + + gtk_widget_show(hexEditor->scroll); + gtk_widget_show(hexEditor->widget); + gtk_widget_show(hexEditor->container); } //internal diff --git a/bsnes/phoenix/gtk/horizontalslider.cpp b/bsnes/phoenix/gtk/horizontalslider.cpp index 9e6e76c7..6a38118d 100755 --- a/bsnes/phoenix/gtk/horizontalslider.cpp +++ b/bsnes/phoenix/gtk/horizontalslider.cpp @@ -4,22 +4,22 @@ static void HorizontalSlider_change(HorizontalSlider *self) { if(self->onChange) self->onChange(); } -void HorizontalSlider::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length) { - object->position = 0; - length += (length == 0); - object->widget = gtk_hscale_new_with_range(0, length - 1, 1); - widget->parent = &parent; - gtk_scale_set_draw_value(GTK_SCALE(object->widget), false); - gtk_widget_set_size_request(object->widget, width, height); - g_signal_connect_swapped(G_OBJECT(object->widget), "value-changed", G_CALLBACK(HorizontalSlider_change), (gpointer)this); - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); - gtk_widget_show(object->widget); -} - unsigned HorizontalSlider::position() { return (unsigned)gtk_range_get_value(GTK_RANGE(object->widget)); } +void HorizontalSlider::setLength(unsigned length) { + length += (length == 0); + gtk_range_set_range(GTK_RANGE(object->widget), 0, length - 1); +} + void HorizontalSlider::setPosition(unsigned position) { gtk_range_set_value(GTK_RANGE(object->widget), position); } + +HorizontalSlider::HorizontalSlider() { + object->position = 0; + object->widget = gtk_hscale_new_with_range(0, 0, 1); + gtk_scale_set_draw_value(GTK_SCALE(object->widget), false); + g_signal_connect_swapped(G_OBJECT(object->widget), "value-changed", G_CALLBACK(HorizontalSlider_change), (gpointer)this); +} diff --git a/bsnes/phoenix/gtk/layout.cpp b/bsnes/phoenix/gtk/layout.cpp index e862a3c7..19b92220 100755 --- a/bsnes/phoenix/gtk/layout.cpp +++ b/bsnes/phoenix/gtk/layout.cpp @@ -2,19 +2,13 @@ void Layout::setParent(Window &parent) { layout->parent = &parent; } -void Layout::update(Geometry &geometry) { - geometry.x += layout->margin; - geometry.y += layout->margin; - geometry.width -= layout->margin * 2; - geometry.height -= layout->margin * 2; -} - -void Layout::setMargin(unsigned margin) { - layout->margin = margin; +void Layout::setParent(Window &parent, Widget &child) { + child.widget->parent = &parent; + gtk_fixed_put(GTK_FIXED(layout->parent->object->formContainer), child.object->widget, 0, 0); + gtk_widget_show(child.object->widget); } Layout::Layout() { layout = new Layout::Data; layout->parent = 0; - layout->margin = 0; } diff --git a/bsnes/phoenix/gtk/listbox.cpp b/bsnes/phoenix/gtk/listbox.cpp index 3d390338..ebae27ea 100755 --- a/bsnes/phoenix/gtk/listbox.cpp +++ b/bsnes/phoenix/gtk/listbox.cpp @@ -19,14 +19,11 @@ static void ListBox_tick(GtkCellRendererToggle *cell, gchar *path_string, ListBo if(self->onTick) self->onTick(index); } -void ListBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - listBox->selection = -1; - object->widget = gtk_scrolled_window_new(0, 0); - widget->parent = &parent; - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(object->widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(object->widget), GTK_SHADOW_ETCHED_IN); - gtk_widget_set_size_request(object->widget, width, height); +void ListBox::setFocused() { + gtk_widget_grab_focus(object->subWidget); +} +void ListBox::setHeaderText(const string &text) { lstring list; list.split("\t", string("\t", text)); @@ -67,14 +64,7 @@ void ListBox::create(Window &parent, unsigned x, unsigned y, unsigned width, uns g_signal_connect_swapped(G_OBJECT(object->subWidget), "cursor-changed", G_CALLBACK(ListBox_change), (gpointer)this); g_signal_connect_swapped(G_OBJECT(object->subWidget), "row-activated", G_CALLBACK(ListBox_activate), (gpointer)this); - if(parent.window->defaultFont) setFont(*parent.window->defaultFont); - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); gtk_widget_show(object->subWidget); - gtk_widget_show(object->widget); -} - -void ListBox::setFocused() { - gtk_widget_grab_focus(object->subWidget); } void ListBox::setHeaderVisible(bool visible) { @@ -192,4 +182,9 @@ void ListBox::setSelection(unsigned row) { ListBox::ListBox() { listBox = new ListBox::Data; listBox->checkable = false; + listBox->selection = -1; + + object->widget = gtk_scrolled_window_new(0, 0); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(object->widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(object->widget), GTK_SHADOW_ETCHED_IN); } diff --git a/bsnes/phoenix/gtk/object.cpp b/bsnes/phoenix/gtk/object.cpp index e812ad58..bebf58a9 100755 --- a/bsnes/phoenix/gtk/object.cpp +++ b/bsnes/phoenix/gtk/object.cpp @@ -22,31 +22,25 @@ struct Action::Data { }; struct Window::Data { + Layout *layout; Font *defaultFont; bool isFullscreen; - unsigned x; - unsigned y; - unsigned width; - unsigned height; + unsigned x, y; + unsigned width, height; }; struct Widget::Data { Window *parent; + unsigned x, y; + unsigned width, height; }; struct Layout::Data { Window *parent; - unsigned margin; }; -struct FixedLayout::Data { - Window *parent; - struct Children { - Widget *widget; - unsigned x, y; - unsigned width, height; - }; - linear_vector children; +struct ComboBox::Data { + unsigned counter; }; struct Canvas::Data { diff --git a/bsnes/phoenix/gtk/progressbar.cpp b/bsnes/phoenix/gtk/progressbar.cpp index 193e924d..2e804880 100755 --- a/bsnes/phoenix/gtk/progressbar.cpp +++ b/bsnes/phoenix/gtk/progressbar.cpp @@ -1,12 +1,8 @@ -void ProgressBar::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) { - object->widget = gtk_progress_bar_new(); - widget->parent = &parent; - gtk_widget_set_size_request(object->widget, width, height); - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); - gtk_widget_show(object->widget); -} - void ProgressBar::setPosition(unsigned position) { position = position <= 100 ? position : 0; gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(object->widget), (double)position / 100.0); } + +ProgressBar::ProgressBar() { + object->widget = gtk_progress_bar_new(); +} diff --git a/bsnes/phoenix/gtk/textbox.cpp b/bsnes/phoenix/gtk/textbox.cpp index 66455f03..fc1cb8fe 100755 --- a/bsnes/phoenix/gtk/textbox.cpp +++ b/bsnes/phoenix/gtk/textbox.cpp @@ -6,18 +6,6 @@ static void TextBox_change(TextBox *self) { if(self->object->locked == false && self->onChange) self->onChange(); } -void TextBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - object->widget = gtk_entry_new(); - widget->parent = &parent; - gtk_entry_set_text(GTK_ENTRY(object->widget), text); - gtk_widget_set_size_request(object->widget, width, height); - g_signal_connect_swapped(G_OBJECT(object->widget), "activate", G_CALLBACK(TextBox_activate), (gpointer)this); - g_signal_connect_swapped(G_OBJECT(object->widget), "changed", G_CALLBACK(TextBox_change), (gpointer)this); - if(parent.window->defaultFont) setFont(*parent.window->defaultFont); - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); - gtk_widget_show(object->widget); -} - void TextBox::setEditable(bool editable) { gtk_entry_set_editable(GTK_ENTRY(object->widget), editable); } @@ -31,3 +19,9 @@ void TextBox::setText(const string &text) { gtk_entry_set_text(GTK_ENTRY(object->widget), text); object->locked = false; } + +TextBox::TextBox() { + object->widget = gtk_entry_new(); + g_signal_connect_swapped(G_OBJECT(object->widget), "activate", G_CALLBACK(TextBox_activate), (gpointer)this); + g_signal_connect_swapped(G_OBJECT(object->widget), "changed", G_CALLBACK(TextBox_change), (gpointer)this); +} diff --git a/bsnes/phoenix/gtk/verticalslider.cpp b/bsnes/phoenix/gtk/verticalslider.cpp index 1cca9e4c..0fdd7e8e 100755 --- a/bsnes/phoenix/gtk/verticalslider.cpp +++ b/bsnes/phoenix/gtk/verticalslider.cpp @@ -4,22 +4,22 @@ static void VerticalSlider_change(VerticalSlider *self) { if(self->onChange) self->onChange(); } -void VerticalSlider::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length) { - object->position = 0; - length += (length == 0); - object->widget = gtk_vscale_new_with_range(0, length - 1, 1); - widget->parent = &parent; - gtk_scale_set_draw_value(GTK_SCALE(object->widget), false); - gtk_widget_set_size_request(object->widget, width, height); - g_signal_connect_swapped(G_OBJECT(object->widget), "value-changed", G_CALLBACK(VerticalSlider_change), (gpointer)this); - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); - gtk_widget_show(object->widget); -} - unsigned VerticalSlider::position() { return (unsigned)gtk_range_get_value(GTK_RANGE(object->widget)); } +void VerticalSlider::setLength(unsigned length) { + length += (length == 0); + gtk_range_set_range(GTK_RANGE(object->widget), 0, length - 1); +} + void VerticalSlider::setPosition(unsigned position) { gtk_range_set_value(GTK_RANGE(object->widget), position); } + +VerticalSlider::VerticalSlider() { + object->position = 0; + object->widget = gtk_vscale_new_with_range(0, 0, 1); + gtk_scale_set_draw_value(GTK_SCALE(object->widget), false); + g_signal_connect_swapped(G_OBJECT(object->widget), "value-changed", G_CALLBACK(VerticalSlider_change), (gpointer)this); +} diff --git a/bsnes/phoenix/gtk/viewport.cpp b/bsnes/phoenix/gtk/viewport.cpp index 3b407727..e84c91df 100755 --- a/bsnes/phoenix/gtk/viewport.cpp +++ b/bsnes/phoenix/gtk/viewport.cpp @@ -1,8 +1,10 @@ -void Viewport::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) { +uintptr_t Viewport::handle() { + return GDK_WINDOW_XID(object->widget->window); +} + +Viewport::Viewport() { object->widget = gtk_drawing_area_new(); - widget->parent = &parent; //gtk_widget_set_double_buffered(object->widget, false); - gtk_widget_set_size_request(object->widget, width, height); GdkColor color; color.pixel = 0; @@ -10,11 +12,4 @@ void Viewport::create(Window &parent, unsigned x, unsigned y, unsigned width, un color.green = 0; color.blue = 0; gtk_widget_modify_bg(object->widget, GTK_STATE_NORMAL, &color); - - gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y); - gtk_widget_show(object->widget); -} - -uintptr_t Viewport::handle() { - return GDK_WINDOW_XID(object->widget->window); } diff --git a/bsnes/phoenix/gtk/widget.cpp b/bsnes/phoenix/gtk/widget.cpp index 4f0bf079..2650395e 100755 --- a/bsnes/phoenix/gtk/widget.cpp +++ b/bsnes/phoenix/gtk/widget.cpp @@ -35,8 +35,18 @@ void Widget::setFocused() { gtk_widget_grab_focus(object->widget); } +Geometry Widget::geometry() { + return { widget->x, widget->y, widget->width, widget->height }; +} + void Widget::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height) { if(widget->parent == 0) return; + + widget->x = x; + widget->y = y; + widget->width = width; + widget->height = height; + gtk_fixed_move(GTK_FIXED(widget->parent->object->formContainer), object->widget, x, y); gtk_widget_set_size_request(object->widget, width, height); } @@ -44,4 +54,8 @@ void Widget::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height Widget::Widget() { widget = new Widget::Data; widget->parent = 0; + widget->x = 0; + widget->y = 0; + widget->width = 0; + widget->height = 0; } diff --git a/bsnes/phoenix/gtk/window.cpp b/bsnes/phoenix/gtk/window.cpp index 4a1cd069..a450af79 100755 --- a/bsnes/phoenix/gtk/window.cpp +++ b/bsnes/phoenix/gtk/window.cpp @@ -7,6 +7,26 @@ static gint Window_close(Window *window) { return true; } +static void Window_configure(GtkWindow *widget, GdkEvent *event, Window *window) { + 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(); + } +} + +static gboolean Window_expose(GtkWidget *widget, GdkEventExpose *event, Window *window) { +} + void Window::create(unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { window->x = x; window->y = y; @@ -17,10 +37,12 @@ void Window::create(unsigned x, unsigned y, unsigned width, unsigned height, con 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), false); + 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); + g_signal_connect(G_OBJECT(object->widget), "expose_event", G_CALLBACK(Window_expose), (gpointer)this); object->menuContainer = gtk_vbox_new(false, 0); gtk_container_add(GTK_CONTAINER(object->widget), object->menuContainer); @@ -45,8 +67,10 @@ void Window::create(unsigned x, unsigned y, unsigned width, unsigned height, con } void Window::setLayout(Layout &layout) { + window->layout = &layout; layout.setParent(*this); Geometry geom = geometry(); + geom.x = geom.y = 0; layout.update(geom); } @@ -59,10 +83,7 @@ void Window::setFocused() { } Geometry Window::geometry() { - gint x, y, width, height; - gtk_window_get_position(GTK_WINDOW(object->widget), &x, &y); - gtk_widget_get_size_request(object->formContainer, &width, &height); - return Geometry(x, y, width, height); + return { window->x, window->y, window->width, window->height }; } void Window::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height) { @@ -138,6 +159,7 @@ void Window::setFullscreen(bool fullscreen) { Window::Window() { window = new Window::Data; + window->layout = 0; window->defaultFont = 0; window->isFullscreen = false; window->x = 0; diff --git a/bsnes/phoenix/layout/fixed-layout.cpp b/bsnes/phoenix/layout/fixed-layout.cpp new file mode 100755 index 00000000..ecae72ba --- /dev/null +++ b/bsnes/phoenix/layout/fixed-layout.cpp @@ -0,0 +1,17 @@ +void FixedLayout::setParent(Window &parent) { + Layout::setParent(parent); + foreach(child, children) { + Layout::setParent(parent, *child.widget); + child.widget->setGeometry(child.x, child.y, child.width, child.height); + } +} + +void FixedLayout::append(Widget &widget, unsigned x, unsigned y, unsigned width, unsigned height) { + children.append({ &widget, x, y, width, height }); +} + +void FixedLayout::update(Geometry &geometry) { +} + +FixedLayout::FixedLayout() { +} diff --git a/bsnes/phoenix/layout/fixed-layout.hpp b/bsnes/phoenix/layout/fixed-layout.hpp new file mode 100755 index 00000000..c686d6e8 --- /dev/null +++ b/bsnes/phoenix/layout/fixed-layout.hpp @@ -0,0 +1,15 @@ +struct FixedLayout : public Layout { + void setParent(Window &parent); + void append(Widget &widget, unsigned x, unsigned y, unsigned width, unsigned height); + void update(Geometry &geometry); + FixedLayout(); + +//private: + Window *parent; + struct Children { + Widget *widget; + unsigned x, y; + unsigned width, height; + }; + nall::linear_vector children; +}; diff --git a/bsnes/phoenix/qt/horizontal-layout.cpp b/bsnes/phoenix/layout/horizontal-layout.cpp similarity index 65% rename from bsnes/phoenix/qt/horizontal-layout.cpp rename to bsnes/phoenix/layout/horizontal-layout.cpp index b2b0e076..e61b4ff7 100755 --- a/bsnes/phoenix/qt/horizontal-layout.cpp +++ b/bsnes/phoenix/layout/horizontal-layout.cpp @@ -1,32 +1,27 @@ void HorizontalLayout::setParent(Window &parent) { Layout::setParent(parent); - foreach(child, horizontalLayout->children) { - if(child.layout) { - child.layout->setParent(parent); - } - - if(child.widget) { - child.widget->widget->widget->setParent(layout->parent->window->container); - if(!child.widget->widget->font && layout->parent->window->defaultFont) { - QWidget *control = child.widget->widget->widget; - control->setFont(*layout->parent->window->defaultFont); - } - } + foreach(child, children) { + if(child.layout) child.layout->setParent(parent); + if(child.widget) Layout::setParent(parent, *child.widget); } } void HorizontalLayout::append(VerticalLayout &layout, unsigned width, unsigned height, unsigned spacing) { - horizontalLayout->children.append({ &layout, 0, width, height, spacing }); + children.append({ &layout, 0, width, height, spacing }); } void HorizontalLayout::append(Widget &widget, unsigned width, unsigned height, unsigned spacing) { - horizontalLayout->children.append({ 0, &widget, width, height, spacing }); + children.append({ 0, &widget, width, height, spacing }); } void HorizontalLayout::update(Geometry &geometry) { - Layout::update(geometry); + geometry.x += margin; + geometry.y += margin; + geometry.width -= margin * 2; + geometry.height -= margin * 2; + Geometry baseGeometry = geometry; - linear_vector children = horizontalLayout->children; + linear_vector children = this->children; unsigned minimumWidth = 0; foreach(child, children) minimumWidth += child.width + child.spacing; @@ -65,6 +60,10 @@ void HorizontalLayout::update(Geometry &geometry) { geometry.height -= maxHeight; } -HorizontalLayout::HorizontalLayout() { - horizontalLayout = new HorizontalLayout::Data(*this); +void HorizontalLayout::setMargin(unsigned margin_) { + margin = margin_; +} + +HorizontalLayout::HorizontalLayout() { + margin = 0; } diff --git a/bsnes/phoenix/layout/horizontal-layout.hpp b/bsnes/phoenix/layout/horizontal-layout.hpp new file mode 100755 index 00000000..7c61bdeb --- /dev/null +++ b/bsnes/phoenix/layout/horizontal-layout.hpp @@ -0,0 +1,19 @@ +struct VerticalLayout; + +struct HorizontalLayout : public Layout { + void setParent(Window &parent); + 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); + HorizontalLayout(); + +//private: + unsigned margin; + struct Children { + VerticalLayout *layout; + Widget *widget; + unsigned width, height, spacing; + }; + nall::linear_vector children; +}; diff --git a/bsnes/phoenix/qt/vertical-layout.cpp b/bsnes/phoenix/layout/vertical-layout.cpp similarity index 66% rename from bsnes/phoenix/qt/vertical-layout.cpp rename to bsnes/phoenix/layout/vertical-layout.cpp index e3085d21..277851d4 100755 --- a/bsnes/phoenix/qt/vertical-layout.cpp +++ b/bsnes/phoenix/layout/vertical-layout.cpp @@ -1,32 +1,27 @@ void VerticalLayout::setParent(Window &parent) { Layout::setParent(parent); - foreach(child, verticalLayout->children) { - if(child.layout) { - child.layout->setParent(parent); - } - - if(child.widget) { - child.widget->widget->widget->setParent(layout->parent->window->container); - if(!child.widget->widget->font && layout->parent->window->defaultFont) { - QWidget *control = child.widget->widget->widget; - control->setFont(*layout->parent->window->defaultFont); - } - } + foreach(child, children) { + if(child.layout) child.layout->setParent(parent); + if(child.widget) Layout::setParent(parent, *child.widget); } } void VerticalLayout::append(HorizontalLayout &layout, unsigned width, unsigned height, unsigned spacing) { - verticalLayout->children.append({ &layout, 0, width, height, spacing }); + children.append({ &layout, 0, width, height, spacing }); } void VerticalLayout::append(Widget &widget, unsigned width, unsigned height, unsigned spacing) { - verticalLayout->children.append({ 0, &widget, width, height, spacing }); + children.append({ 0, &widget, width, height, spacing }); } void VerticalLayout::update(Geometry &geometry) { - Layout::update(geometry); + geometry.x += margin; + geometry.y += margin; + geometry.width -= margin * 2; + geometry.height -= margin * 2; + Geometry baseGeometry = geometry; - linear_vector children = verticalLayout->children; + linear_vector children = this->children; unsigned minimumHeight = 0; foreach(child, children) minimumHeight += child.height + child.spacing; @@ -65,6 +60,10 @@ void VerticalLayout::update(Geometry &geometry) { geometry.width -= maxWidth; } -VerticalLayout::VerticalLayout() { - verticalLayout = new VerticalLayout::Data(*this); +void VerticalLayout::setMargin(unsigned margin_) { + margin = margin_; +} + +VerticalLayout::VerticalLayout() { + margin = 0; } diff --git a/bsnes/phoenix/layout/vertical-layout.hpp b/bsnes/phoenix/layout/vertical-layout.hpp new file mode 100755 index 00000000..e1b6b058 --- /dev/null +++ b/bsnes/phoenix/layout/vertical-layout.hpp @@ -0,0 +1,19 @@ +struct HorizontalLayout; + +struct VerticalLayout : public Layout { + void setParent(Window &parent); + 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); + VerticalLayout(); + +//private: + unsigned margin; + struct Children { + HorizontalLayout *layout; + Widget *widget; + unsigned width, height, spacing; + }; + nall::linear_vector children; +}; diff --git a/bsnes/phoenix/phoenix.cpp b/bsnes/phoenix/phoenix.cpp index bf51451b..e926c7dd 100755 --- a/bsnes/phoenix/phoenix.cpp +++ b/bsnes/phoenix/phoenix.cpp @@ -15,3 +15,9 @@ #elif defined(PHOENIX_QT) #include "qt/qt.cpp" #endif + +namespace phoenix { + #include "layout/fixed-layout.cpp" + #include "layout/horizontal-layout.cpp" + #include "layout/vertical-layout.cpp" +} diff --git a/bsnes/phoenix/phoenix.hpp b/bsnes/phoenix/phoenix.hpp index 99c82d15..9c6b9d58 100755 --- a/bsnes/phoenix/phoenix.hpp +++ b/bsnes/phoenix/phoenix.hpp @@ -13,3 +13,9 @@ #elif defined(PHOENIX_QT) #include "qt/qt.hpp" #endif + +namespace phoenix { + #include "layout/fixed-layout.hpp" + #include "layout/horizontal-layout.hpp" + #include "layout/vertical-layout.hpp" +} diff --git a/bsnes/phoenix/qt/fixed-layout.cpp b/bsnes/phoenix/qt/fixed-layout.cpp deleted file mode 100755 index 4a7f08d2..00000000 --- a/bsnes/phoenix/qt/fixed-layout.cpp +++ /dev/null @@ -1,31 +0,0 @@ -void FixedLayout::setParent(Window &parent) { - Layout::setParent(parent); - foreach(child, fixedLayout->children) { - child.widget->widget->widget->setParent(layout->parent->window->container); - if(!child.widget->widget->font && layout->parent->window->defaultFont) { - QWidget *control = child.widget->widget->widget; - control->setFont(*layout->parent->window->defaultFont); - } - } -} - -void FixedLayout::append(Widget &widget, unsigned x, unsigned y, unsigned width, unsigned height) { - fixedLayout->children.append({ &widget, x, y, width, height }); -} - -void FixedLayout::update(Geometry &geometry) { - Layout::update(geometry); - - foreach(child, fixedLayout->children) { - child.widget->widget->widget->setParent(layout->parent->window->container); - child.widget->setGeometry(child.x, child.y, child.width, child.height); - if(layout->parent->window->defaultFont) { - QWidget *control = child.widget->widget->widget; - control->setFont(*layout->parent->window->defaultFont); - } - } -} - -FixedLayout::FixedLayout() { - fixedLayout = new FixedLayout::Data(*this); -} diff --git a/bsnes/phoenix/qt/layout.cpp b/bsnes/phoenix/qt/layout.cpp index 82456905..63157325 100755 --- a/bsnes/phoenix/qt/layout.cpp +++ b/bsnes/phoenix/qt/layout.cpp @@ -2,15 +2,12 @@ void Layout::setParent(Window &parent) { layout->parent = &parent; } -void Layout::update(Geometry &geometry) { - geometry.x += layout->margin; - geometry.y += layout->margin; - geometry.width -= layout->margin * 2; - geometry.height -= layout->margin * 2; -} - -void Layout::setMargin(unsigned margin) { - layout->margin = margin; +void Layout::setParent(Window &parent, Widget &child) { + child.widget->widget->setParent(layout->parent->window->container); + if(!child.widget->font && layout->parent->window->defaultFont) { + QWidget *control = child.widget->widget; + control->setFont(*layout->parent->window->defaultFont); + } } Layout::Layout() { diff --git a/bsnes/phoenix/qt/qt.cpp b/bsnes/phoenix/qt/qt.cpp index e5421472..83495f8e 100755 --- a/bsnes/phoenix/qt/qt.cpp +++ b/bsnes/phoenix/qt/qt.cpp @@ -13,9 +13,6 @@ namespace phoenix { #include "window.cpp" #include "widget.cpp" #include "layout.cpp" -#include "fixed-layout.cpp" -#include "horizontal-layout.cpp" -#include "vertical-layout.cpp" #include "button.cpp" #include "canvas.cpp" #include "checkbox.cpp" diff --git a/bsnes/phoenix/qt/qt.hpp b/bsnes/phoenix/qt/qt.hpp index d7f697cc..285a91c5 100755 --- a/bsnes/phoenix/qt/qt.hpp +++ b/bsnes/phoenix/qt/qt.hpp @@ -143,49 +143,14 @@ struct Window : Object { struct Layout : Object { virtual void setParent(Window &parent); - virtual void update(Geometry &geometry); - void setMargin(unsigned margin); + virtual void setParent(Window &parent, Widget &child); + virtual void update(Geometry &geometry) = 0; Layout(); //private: struct Data; Data *layout; }; -struct FixedLayout : Layout { - void setParent(Window &parent); - void append(Widget &widget, unsigned x, unsigned y, unsigned width, unsigned height); - void update(Geometry &geometry); - FixedLayout(); -//private: - struct Data; - Data *fixedLayout; -}; - -struct HorizontalLayout; -struct VerticalLayout; - -struct HorizontalLayout : Layout { - void setParent(Window &parent); - 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); - HorizontalLayout(); -//private: - struct Data; - Data *horizontalLayout; -}; - -struct VerticalLayout : Layout { - void setParent(Window &parent); - 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); - VerticalLayout(); -//private: - struct Data; - Data *verticalLayout; -}; - struct Widget : Object { virtual Geometry geometry(); virtual void setGeometry(unsigned x, unsigned y, unsigned width, unsigned height); diff --git a/bsnes/phoenix/qt/qt.moc b/bsnes/phoenix/qt/qt.moc index 4039970e..4be6f8a0 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: Fri Feb 4 22:10:00 2011 +** Created: Sat Feb 5 21:33:04 2011 ** by: The Qt Meta Object Compiler version 62 (Qt 4.6.2) ** ** WARNING! All changes made in this file will be lost! @@ -242,202 +242,6 @@ int Window::Data::qt_metacall(QMetaObject::Call _c, int _id, void **_a) return _id; return _id; } -static const uint qt_meta_data_Layout__Data[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_Layout__Data[] = { - "Layout::Data\0" -}; - -const QMetaObject Layout::Data::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_Layout__Data, - qt_meta_data_Layout__Data, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &Layout::Data::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *Layout::Data::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *Layout::Data::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_Layout__Data)) - return static_cast(const_cast< Data*>(this)); - return QObject::qt_metacast(_clname); -} - -int Layout::Data::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -static const uint qt_meta_data_FixedLayout__Data[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_FixedLayout__Data[] = { - "FixedLayout::Data\0" -}; - -const QMetaObject FixedLayout::Data::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_FixedLayout__Data, - qt_meta_data_FixedLayout__Data, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &FixedLayout::Data::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *FixedLayout::Data::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *FixedLayout::Data::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_FixedLayout__Data)) - return static_cast(const_cast< Data*>(this)); - return QObject::qt_metacast(_clname); -} - -int FixedLayout::Data::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -static const uint qt_meta_data_HorizontalLayout__Data[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_HorizontalLayout__Data[] = { - "HorizontalLayout::Data\0" -}; - -const QMetaObject HorizontalLayout::Data::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_HorizontalLayout__Data, - qt_meta_data_HorizontalLayout__Data, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &HorizontalLayout::Data::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *HorizontalLayout::Data::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *HorizontalLayout::Data::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_HorizontalLayout__Data)) - return static_cast(const_cast< Data*>(this)); - return QObject::qt_metacast(_clname); -} - -int HorizontalLayout::Data::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} -static const uint qt_meta_data_VerticalLayout__Data[] = { - - // content: - 4, // revision - 0, // classname - 0, 0, // classinfo - 0, 0, // methods - 0, 0, // properties - 0, 0, // enums/sets - 0, 0, // constructors - 0, // flags - 0, // signalCount - - 0 // eod -}; - -static const char qt_meta_stringdata_VerticalLayout__Data[] = { - "VerticalLayout::Data\0" -}; - -const QMetaObject VerticalLayout::Data::staticMetaObject = { - { &QObject::staticMetaObject, qt_meta_stringdata_VerticalLayout__Data, - qt_meta_data_VerticalLayout__Data, 0 } -}; - -#ifdef Q_NO_DATA_RELOCATION -const QMetaObject &VerticalLayout::Data::getStaticMetaObject() { return staticMetaObject; } -#endif //Q_NO_DATA_RELOCATION - -const QMetaObject *VerticalLayout::Data::metaObject() const -{ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; -} - -void *VerticalLayout::Data::qt_metacast(const char *_clname) -{ - if (!_clname) return 0; - if (!strcmp(_clname, qt_meta_stringdata_VerticalLayout__Data)) - return static_cast(const_cast< Data*>(this)); - return QObject::qt_metacast(_clname); -} - -int VerticalLayout::Data::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -{ - _id = QObject::qt_metacall(_c, _id, _a); - if (_id < 0) - return _id; - return _id; -} static const uint qt_meta_data_Button__Data[] = { // content: diff --git a/bsnes/phoenix/qt/qt.moc.hpp b/bsnes/phoenix/qt/qt.moc.hpp index 3b60a37c..35cce53d 100755 --- a/bsnes/phoenix/qt/qt.moc.hpp +++ b/bsnes/phoenix/qt/qt.moc.hpp @@ -144,71 +144,16 @@ public: } }; -struct Layout::Data : public QObject { - Q_OBJECT - -public: +struct Layout::Data { Layout &self; Window *parent; - unsigned margin; Data(Layout &self) : self(self) { parent = 0; - margin = 0; - } -}; - -struct FixedLayout::Data : public QObject { - Q_OBJECT - -public: - FixedLayout &self; - Window *parent; - struct Children { - Widget *widget; - unsigned x, y; - unsigned width, height; - }; - linear_vector children; - - Data(FixedLayout &self) : self(self) { - } -}; - -struct HorizontalLayout::Data : public QObject { - Q_OBJECT - -public: - HorizontalLayout &self; - struct Children { - VerticalLayout *layout; - Widget *widget; - unsigned width, height, spacing; - }; - linear_vector children; - - Data(HorizontalLayout &self) : self(self) { - } -}; - -struct VerticalLayout::Data : public QObject { - Q_OBJECT - -public: - VerticalLayout &self; - struct Children { - HorizontalLayout *layout; - Widget *widget; - unsigned width, height, spacing; - }; - linear_vector children; - - Data(VerticalLayout &self) : self(self) { } }; struct Widget::Data { -public: Widget &self; QWidget *widget; Font *font; diff --git a/bsnes/phoenix/windows/button.cpp b/bsnes/phoenix/windows/button.cpp index 84ed6a04..29c8e1e4 100755 --- a/bsnes/phoenix/windows/button.cpp +++ b/bsnes/phoenix/windows/button.cpp @@ -1,7 +1,3 @@ -void Button::setParent(Layout &layout) { - SetParent(widget->window, layout.widget->window); -} - void Button::setText(const string &text) { SetWindowText(widget->window, utf16_t(text)); } @@ -13,17 +9,5 @@ Button::Button() { 0, 0, 64, 64, OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 ); -} - -#if 0 -void Button::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - widget->window = CreateWindow( - L"BUTTON", utf16_t(text), - WS_CHILD | WS_TABSTOP | WS_VISIBLE, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->proportionalFont), 0); } -#endif \ No newline at end of file diff --git a/bsnes/phoenix/windows/checkbox.cpp b/bsnes/phoenix/windows/checkbox.cpp index 035deb56..2c6ee5ec 100755 --- a/bsnes/phoenix/windows/checkbox.cpp +++ b/bsnes/phoenix/windows/checkbox.cpp @@ -1,14 +1,3 @@ -void CheckBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - widget->window = CreateWindow( - L"BUTTON", utf16_t(text), - WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_CHECKBOX, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->proportionalFont), 0); -} - bool CheckBox::checked() { return SendMessage(widget->window, BM_GETCHECK, 0, 0); } @@ -16,3 +5,17 @@ bool CheckBox::checked() { void CheckBox::setChecked(bool checked) { SendMessage(widget->window, BM_SETCHECK, (WPARAM)checked, 0); } + +void CheckBox::setText(const string &text) { + SetWindowText(widget->window, utf16_t(text)); +} + +CheckBox::CheckBox() { + widget->window = CreateWindow( + L"BUTTON", L"", + WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_CHECKBOX, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); +} diff --git a/bsnes/phoenix/windows/combobox.cpp b/bsnes/phoenix/windows/combobox.cpp index 4965a529..7f789e43 100755 --- a/bsnes/phoenix/windows/combobox.cpp +++ b/bsnes/phoenix/windows/combobox.cpp @@ -1,28 +1,3 @@ -void ComboBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - widget->window = CreateWindowEx( - 0, L"COMBOBOX", L"", - WS_CHILD | WS_TABSTOP | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS, - x, y, width, 200, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->proportionalFont), 0); - - //CreateWindow height parameter is the height of the expanded list box; - //need additional code to override default ComboBox control height - RECT rc; - GetWindowRect(widget->window, &rc); - unsigned adjustedHeight = height - ((rc.bottom - rc.top) - SendMessage(widget->window, CB_GETITEMHEIGHT, (WPARAM)-1, 0)); - SendMessage(widget->window, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight); - - if(*text) { - lstring list; - list.split("\n", text); - foreach(item, list) addItem(item); - } -} - void ComboBox::reset() { SendMessage(widget->window, CB_RESETCONTENT, 0, 0); } @@ -43,4 +18,28 @@ void ComboBox::setSelection(unsigned row) { ComboBox::ComboBox() { comboBox = new ComboBox::Data; comboBox->selection = 0; + + widget->window = CreateWindowEx( + 0, L"COMBOBOX", L"", + WS_CHILD | WS_TABSTOP | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS, + 0, 0, 64, 200, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); + + //CreateWindow height parameter is the height of the expanded list box; + //need additional code to override default ComboBox control height + #if 0 + RECT rc; + GetWindowRect(widget->window, &rc); + unsigned adjustedHeight = height - ((rc.bottom - rc.top) - SendMessage(widget->window, CB_GETITEMHEIGHT, (WPARAM)-1, 0)); + SendMessage(widget->window, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight); + + if(*text) { + lstring list; + list.split("\n", text); + foreach(item, list) addItem(item); + } + #endif } diff --git a/bsnes/phoenix/windows/editbox.cpp b/bsnes/phoenix/windows/editbox.cpp index 06cb3368..5af8a19f 100755 --- a/bsnes/phoenix/windows/editbox.cpp +++ b/bsnes/phoenix/windows/editbox.cpp @@ -1,16 +1,3 @@ -void EditBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - widget->window = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", L"", - WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN | - (editBox->wordWrap == false ? ES_AUTOHSCROLL : 0), - editBox->x = x, editBox->y = y, editBox->width = width, editBox->height = height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - setText(text); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->proportionalFont), 0); -} - string EditBox::getText() { unsigned length = GetWindowTextLength(widget->window); wchar_t buffer[length + 1]; @@ -44,14 +31,25 @@ void EditBox::setWordWrap(bool wordWrap) { //ES_AUTOSCROLL options cannot be changed after control has been created; //so destroy the control and recreate it with desired options + #if 0 HWND hparent = GetParent(widget->window); Window *parent = (Window*)GetWindowLongPtr(hparent, GWLP_USERDATA); string text = getText(); DestroyWindow(widget->window); create(*parent, editBox->x, editBox->y, editBox->width, editBox->height, text); + #endif } EditBox::EditBox() { editBox = new EditBox::Data; editBox->wordWrap = true; + + widget->window = CreateWindowEx( + WS_EX_CLIENTEDGE, L"EDIT", L"", + WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN | + (editBox->wordWrap == false ? ES_AUTOHSCROLL : 0), + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); } diff --git a/bsnes/phoenix/windows/fixed-layout.cpp b/bsnes/phoenix/windows/fixed-layout.cpp deleted file mode 100755 index d6016aef..00000000 --- a/bsnes/phoenix/windows/fixed-layout.cpp +++ /dev/null @@ -1,23 +0,0 @@ -void FixedLayout::append(Widget &widget, unsigned x, unsigned y, unsigned width, unsigned height) { - fixedLayout->widgets.append({ &widget, x, y, width, height }); -} - -void FixedLayout::create(Window &parent_) { - SetParent(widget->window, parent_.widget->window); - setGeometry(0, 0, 640, 480); - - foreach(control, fixedLayout->widgets) { - SetParent(control.widget->widget->window, widget->window); - control.widget->setGeometry(control.x, control.y, control.width, control.height); - } -} - -FixedLayout::FixedLayout() { - fixedLayout = new FixedLayout::Data; - widget->window = CreateWindow( - L"phoenix_window", L"", - WS_CHILD | WS_TABSTOP | WS_VISIBLE, - 0, 0, 64, 64, - OS::os->nullWindow, 0, GetModuleHandle(0), 0 - ); -} diff --git a/bsnes/phoenix/windows/hexeditor.cpp b/bsnes/phoenix/windows/hexeditor.cpp index 96dca950..494d43e6 100755 --- a/bsnes/phoenix/windows/hexeditor.cpp +++ b/bsnes/phoenix/windows/hexeditor.cpp @@ -10,21 +10,6 @@ static LRESULT CALLBACK HexEditor_WindowProc(HWND hwnd, UINT msg, WPARAM wparam, return self.hexEditor->windowProc(hwnd, msg, wparam, lparam); } -void HexEditor::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) { - widget->window = CreateWindowEx( - WS_EX_CLIENTEDGE, - L"EDIT", L"", - WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_READONLY | ES_MULTILINE | ES_WANTRETURN, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->monospaceFont), 0); - - hexEditor->windowProc = (LRESULT CALLBACK (*)(HWND, UINT, LPARAM, WPARAM))GetWindowLongPtr(widget->window, GWLP_WNDPROC); - SetWindowLongPtr(widget->window, GWLP_WNDPROC, (LONG_PTR)HexEditor_WindowProc); -} - void HexEditor::setSize(unsigned size) { hexEditor->size = size; update(); @@ -142,6 +127,18 @@ HexEditor::HexEditor() { hexEditor->offset = 0; hexEditor->columns = 16; hexEditor->rows = 16; + + widget->window = CreateWindowEx( + WS_EX_CLIENTEDGE, + L"EDIT", L"", + WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_READONLY | ES_MULTILINE | ES_WANTRETURN, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); + + hexEditor->windowProc = (LRESULT CALLBACK (*)(HWND, UINT, LPARAM, WPARAM))GetWindowLongPtr(widget->window, GWLP_WNDPROC); + SetWindowLongPtr(widget->window, GWLP_WNDPROC, (LONG_PTR)HexEditor_WindowProc); } HexEditor::~HexEditor() { diff --git a/bsnes/phoenix/windows/horizontalslider.cpp b/bsnes/phoenix/windows/horizontalslider.cpp index 9f5939bd..543a3c70 100755 --- a/bsnes/phoenix/windows/horizontalslider.cpp +++ b/bsnes/phoenix/windows/horizontalslider.cpp @@ -1,25 +1,26 @@ -void HorizontalSlider::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length) { +unsigned HorizontalSlider::position() { + return SendMessage(widget->window, TBM_GETPOS, 0, 0); +} + +void HorizontalSlider::setLength(unsigned length) { length += (length == 0); - widget->window = CreateWindow( - TRACKBAR_CLASS, L"", - WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_HORZ, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); SendMessage(widget->window, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); SendMessage(widget->window, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); setPosition(0); } -unsigned HorizontalSlider::position() { - return SendMessage(widget->window, TBM_GETPOS, 0, 0); -} - void HorizontalSlider::setPosition(unsigned position) { SendMessage(widget->window, TBM_SETPOS, (WPARAM)true, (LPARAM)(horizontalSlider->position = position)); } HorizontalSlider::HorizontalSlider() { horizontalSlider = new HorizontalSlider::Data; + + widget->window = CreateWindow( + TRACKBAR_CLASS, L"", + WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_HORZ, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); } diff --git a/bsnes/phoenix/windows/label.cpp b/bsnes/phoenix/windows/label.cpp index e20c7cf0..74ad0fe8 100755 --- a/bsnes/phoenix/windows/label.cpp +++ b/bsnes/phoenix/windows/label.cpp @@ -1,20 +1,18 @@ -void Label::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - widget->window = CreateWindow( - L"phoenix_label", L"", - WS_CHILD | WS_VISIBLE, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->proportionalFont), 0); - setText(text); -} - void Label::setText(const string &text) { SetWindowText(widget->window, utf16_t(text)); InvalidateRect(widget->window, 0, false); } +Label::Label() { + widget->window = CreateWindow( + L"phoenix_label", L"", + WS_CHILD | WS_VISIBLE, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); +} + //all of this for want of a STATIC SS_VCENTER flag ... LRESULT CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { Window *window_ptr = (Window*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); diff --git a/bsnes/phoenix/windows/layout.cpp b/bsnes/phoenix/windows/layout.cpp index e257ad42..8c47924e 100755 --- a/bsnes/phoenix/windows/layout.cpp +++ b/bsnes/phoenix/windows/layout.cpp @@ -1,3 +1,14 @@ +void Layout::setParent(Window &parent) { + layout->parent = &parent; +} + +void Layout::setParent(Window &parent, Widget &child) { + SetParent(child.widget->window, parent.widget->window); + + SendMessage(child.widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->proportionalFont), 0); +} + Layout::Layout() { layout = new Layout::Data; + layout->parent = 0; } diff --git a/bsnes/phoenix/windows/listbox.cpp b/bsnes/phoenix/windows/listbox.cpp index 86d82255..b8df535d 100755 --- a/bsnes/phoenix/windows/listbox.cpp +++ b/bsnes/phoenix/windows/listbox.cpp @@ -1,15 +1,4 @@ -void ListBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - widget->window = CreateWindowEx( - WS_EX_CLIENTEDGE, WC_LISTVIEW, L"", - WS_CHILD | WS_TABSTOP | WS_VISIBLE | - LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | LVS_NOCOLUMNHEADER, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->proportionalFont), 0); - ListView_SetExtendedListViewStyle(widget->window, LVS_EX_FULLROWSELECT); - +void ListBox::setHeaderText(const string &text) { lstring list; list.split("\t", text); listBox->columns = list.size(); @@ -111,4 +100,14 @@ void ListBox::setChecked(unsigned row, bool checked) { ListBox::ListBox() { listBox = new ListBox::Data; listBox->lostFocus = false; + + widget->window = CreateWindowEx( + WS_EX_CLIENTEDGE, WC_LISTVIEW, L"", + WS_CHILD | WS_TABSTOP | WS_VISIBLE | + LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | LVS_NOCOLUMNHEADER, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); + ListView_SetExtendedListViewStyle(widget->window, LVS_EX_FULLROWSELECT); } diff --git a/bsnes/phoenix/windows/object.cpp b/bsnes/phoenix/windows/object.cpp index 854e616e..e5706fb3 100755 --- a/bsnes/phoenix/windows/object.cpp +++ b/bsnes/phoenix/windows/object.cpp @@ -34,17 +34,7 @@ struct Widget::Data { }; struct Layout::Data { -}; - -struct FixedLayout::Data { Window *parent; - - struct Widgets { - Widget *widget; - unsigned x, y; - unsigned width, height; - }; - linear_vector widgets; }; struct Canvas::Data { diff --git a/bsnes/phoenix/windows/progressbar.cpp b/bsnes/phoenix/windows/progressbar.cpp index 230f12b4..7d403ba1 100755 --- a/bsnes/phoenix/windows/progressbar.cpp +++ b/bsnes/phoenix/windows/progressbar.cpp @@ -1,14 +1,3 @@ -void ProgressBar::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) { - widget->window = CreateWindow( - PROGRESS_CLASS, L"", - WS_CHILD | WS_VISIBLE | PBS_SMOOTH, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SendMessage(widget->window, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); - SendMessage(widget->window, PBM_SETSTEP, MAKEWPARAM(1, 0), 0); -} - unsigned ProgressBar::position() { return SendMessage(widget->window, PBM_GETPOS, 0, 0); } @@ -16,3 +5,14 @@ unsigned ProgressBar::position() { void ProgressBar::setPosition(unsigned position) { SendMessage(widget->window, PBM_SETPOS, (WPARAM)position, 0); } + +ProgressBar::ProgressBar() { + widget->window = CreateWindow( + PROGRESS_CLASS, L"", + WS_CHILD | WS_VISIBLE | PBS_SMOOTH, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SendMessage(widget->window, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); + SendMessage(widget->window, PBM_SETSTEP, MAKEWPARAM(1, 0), 0); +} diff --git a/bsnes/phoenix/windows/radiobox.cpp b/bsnes/phoenix/windows/radiobox.cpp index 9c49297b..295a66a6 100755 --- a/bsnes/phoenix/windows/radiobox.cpp +++ b/bsnes/phoenix/windows/radiobox.cpp @@ -1,30 +1,11 @@ -void RadioBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - radioBox->parentWindow = &parent; - radioBox->parent = this; - radioBox->parent->radioBox->items.append(this); - widget->window = CreateWindow( - L"BUTTON", utf16_t(text), - WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_RADIOBUTTON, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->proportionalFont), 0); - setChecked(); -} - -void RadioBox::create(RadioBox &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - radioBox->parentWindow = parent.radioBox->parentWindow; +void RadioBox::setParent(RadioBox &parent) { radioBox->parent = parent.radioBox->parent; radioBox->parent->radioBox->items.append(this); - widget->window = CreateWindow( - L"BUTTON", utf16_t(text), - WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_RADIOBUTTON, - x, y, width, height, - GetParent(radioBox->parent->widget->window), (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(radioBox->parentWindow->window->defaultFont ? radioBox->parentWindow->window->defaultFont : OS::os->proportionalFont), 0); + parent.setChecked(); +} + +void RadioBox::setText(const string &text) { + SetWindowText(widget->window, utf16_t(text)); } bool RadioBox::checked() { @@ -39,4 +20,15 @@ void RadioBox::setChecked() { RadioBox::RadioBox() { radioBox = new RadioBox::Data; + + radioBox->parent = this; + radioBox->parent->radioBox->items.append(this); + widget->window = CreateWindow( + L"BUTTON", L"", + WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_RADIOBUTTON, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); + setChecked(); } diff --git a/bsnes/phoenix/windows/textbox.cpp b/bsnes/phoenix/windows/textbox.cpp index e63f2dac..bd114355 100755 --- a/bsnes/phoenix/windows/textbox.cpp +++ b/bsnes/phoenix/windows/textbox.cpp @@ -1,14 +1,3 @@ -void TextBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) { - widget->window = CreateWindowEx( - WS_EX_CLIENTEDGE, L"EDIT", utf16_t(text), - WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(widget->window, WM_SETFONT, (WPARAM)(parent.window->defaultFont ? parent.window->defaultFont : OS::os->proportionalFont), 0); -} - string TextBox::text() { unsigned length = GetWindowTextLength(widget->window); wchar_t text[length + 1]; @@ -26,3 +15,13 @@ void TextBox::setText(const string &text) { void TextBox::setEditable(bool editable) { SendMessage(widget->window, EM_SETREADONLY, editable == false, 0); } + +TextBox::TextBox() { + widget->window = CreateWindowEx( + WS_EX_CLIENTEDGE, L"EDIT", L"", + WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); +} diff --git a/bsnes/phoenix/windows/verticalslider.cpp b/bsnes/phoenix/windows/verticalslider.cpp index 43024432..881ef2aa 100755 --- a/bsnes/phoenix/windows/verticalslider.cpp +++ b/bsnes/phoenix/windows/verticalslider.cpp @@ -1,25 +1,26 @@ -void VerticalSlider::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length) { +unsigned VerticalSlider::position() { + return SendMessage(widget->window, TBM_GETPOS, 0, 0); +} + +void VerticalSlider::setLength(unsigned length) { length += (length == 0); - widget->window = CreateWindow( - TRACKBAR_CLASS, L"", - WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_VERT, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); SendMessage(widget->window, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); SendMessage(widget->window, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); setPosition(0); } -unsigned VerticalSlider::position() { - return SendMessage(widget->window, TBM_GETPOS, 0, 0); -} - void VerticalSlider::setPosition(unsigned position) { SendMessage(widget->window, TBM_SETPOS, (WPARAM)true, (LPARAM)(verticalSlider->position = position)); } VerticalSlider::VerticalSlider() { verticalSlider = new VerticalSlider::Data; + + widget->window = CreateWindow( + TRACKBAR_CLASS, L"", + WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_VERT, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); } diff --git a/bsnes/phoenix/windows/viewport.cpp b/bsnes/phoenix/windows/viewport.cpp index 21e38d79..e830eaa8 100755 --- a/bsnes/phoenix/windows/viewport.cpp +++ b/bsnes/phoenix/windows/viewport.cpp @@ -1,17 +1,17 @@ -void Viewport::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) { - widget->window = CreateWindow( - L"phoenix_viewport", L"", - WS_CHILD | WS_VISIBLE | WS_DISABLED, - x, y, width, height, - parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 - ); - SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); +static LRESULT CALLBACK Viewport_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { + return DefWindowProc(hwnd, msg, wparam, lparam); } uintptr_t Viewport::handle() { return (uintptr_t)widget->window; } -static LRESULT CALLBACK Viewport_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - return DefWindowProc(hwnd, msg, wparam, lparam); +Viewport::Viewport() { + widget->window = CreateWindow( + L"phoenix_viewport", L"", + WS_CHILD | WS_VISIBLE | WS_DISABLED, + 0, 0, 64, 64, + OS::os->nullWindow, (HMENU)object->id, GetModuleHandle(0), 0 + ); + SetWindowLongPtr(widget->window, GWLP_USERDATA, (LONG_PTR)this); } diff --git a/bsnes/phoenix/windows/window.cpp b/bsnes/phoenix/windows/window.cpp index d68eb45a..bbe9a3b4 100755 --- a/bsnes/phoenix/windows/window.cpp +++ b/bsnes/phoenix/windows/window.cpp @@ -19,7 +19,10 @@ void Window::create(unsigned x, unsigned y, unsigned width, unsigned height, con } void Window::setLayout(Layout &layout) { - layout.create(*this); + Geometry geom = geometry(); + geom.x = geom.y = 0; + layout.setParent(*this); + layout.update(geom); } void Window::setDefaultFont(Font &font) { diff --git a/bsnes/phoenix/windows/windows.cpp b/bsnes/phoenix/windows/windows.cpp index 13e5ef1a..f679b9f0 100755 --- a/bsnes/phoenix/windows/windows.cpp +++ b/bsnes/phoenix/windows/windows.cpp @@ -16,7 +16,6 @@ namespace phoenix { #include "widget.cpp" #include "window.cpp" #include "layout.cpp" -#include "fixed-layout.cpp" #include "button.cpp" #include "canvas.cpp" #include "checkbox.cpp" diff --git a/bsnes/phoenix/windows/windows.hpp b/bsnes/phoenix/windows/windows.hpp index 827a3e34..9b3b046f 100755 --- a/bsnes/phoenix/windows/windows.hpp +++ b/bsnes/phoenix/windows/windows.hpp @@ -129,25 +129,17 @@ struct Window : Widget { }; struct Layout : Widget { - virtual void create(Window &parent) = 0; + virtual void setParent(Window &parent); + virtual void setParent(Window &parent, Widget &child); + virtual void update(Geometry &geometry) = 0; Layout(); //private: struct Data; Data *layout; }; -struct FixedLayout : Layout { - void append(Widget &widget, unsigned x, unsigned y, unsigned width, unsigned height); - void create(Window &parent); - FixedLayout(); -//private: - struct Data; - Data *fixedLayout; -}; - struct Button : Widget { nall::function onTick; - void setParent(Layout &parent); void setText(const nall::string &text); Button(); }; @@ -165,14 +157,14 @@ struct Canvas : Widget { struct CheckBox : Widget { nall::function onTick; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); bool checked(); void setChecked(bool checked = true); + void setText(const nall::string &text); + CheckBox(); }; struct ComboBox : Widget { nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); void reset(); void addItem(const nall::string &text); unsigned selection(); @@ -185,7 +177,6 @@ struct ComboBox : Widget { struct EditBox : Widget { nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); nall::string getText(); void setText(const nall::string &text); void setCursorPosition(unsigned position); @@ -200,7 +191,6 @@ struct EditBox : Widget { struct HexEditor : Widget { nall::function onRead; nall::function onWrite; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height); void setSize(unsigned size); void setOffset(unsigned offset); void setColumns(unsigned columns); @@ -216,8 +206,8 @@ struct HexEditor : Widget { struct HorizontalSlider : Widget { nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length); unsigned position(); + void setLength(unsigned length); void setPosition(unsigned position); HorizontalSlider(); //private: @@ -226,15 +216,15 @@ struct HorizontalSlider : Widget { }; struct Label : Widget { - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); void setText(const nall::string &text); + Label(); }; struct ListBox : Widget { nall::function onActivate; nall::function onChange; nall::function onTick; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); + void setHeaderText(const nall::string &text); void setHeaderVisible(bool headerVisible = true); void setCheckable(bool checkable = true); void reset(); @@ -252,15 +242,15 @@ struct ListBox : Widget { }; struct ProgressBar : Widget { - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height); unsigned position(); void setPosition(unsigned position); + ProgressBar(); }; struct RadioBox : Widget { nall::function onTick; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); - void create(RadioBox &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); + void setParent(RadioBox &parent); + void setText(const nall::string &text); bool checked(); void setChecked(); RadioBox(); @@ -272,16 +262,16 @@ struct RadioBox : Widget { struct TextBox : Widget { nall::function onActivate; nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = ""); nall::string text(); void setText(const nall::string &text); void setEditable(bool editable = true); + TextBox(); }; struct VerticalSlider : Widget { nall::function onChange; - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length); unsigned position(); + void setLength(unsigned length); void setPosition(unsigned position); VerticalSlider(); //private: @@ -290,8 +280,8 @@ struct VerticalSlider : Widget { }; struct Viewport : Widget { - void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height); uintptr_t handle(); + Viewport(); }; struct MessageWindow : Object { diff --git a/bsnes/snes/snes.hpp b/bsnes/snes/snes.hpp index 7501b7c9..46b54125 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.08"; + static const char Version[] = "075.09"; static const unsigned SerializerVersion = 18; } } diff --git a/bsnes/ui-gameboy/main.cpp b/bsnes/ui-gameboy/main.cpp index 5dfca13c..ead80bcc 100755 --- a/bsnes/ui-gameboy/main.cpp +++ b/bsnes/ui-gameboy/main.cpp @@ -38,12 +38,12 @@ void Application::main(int argc, char **argv) { audio.driver("ALSA"); #endif audio.set(Audio::Handle, (uintptr_t)mainWindow.viewport.handle()); - audio.set(Audio::Synchronize, false); + audio.set(Audio::Synchronize, true); audio.set(Audio::Volume, 100U); audio.set(Audio::Latency, 80U); audio.set(Audio::Frequency, 44100U); audio.set(Audio::Resample, true); - audio.set(Audio::ResampleRatio, (4.0 * 1024.0 * 1024.0) / 44100.0); + audio.set(Audio::ResampleRatio, 4194304.0 / 44100.0); audio.init(); #if defined(PHOENIX_WINDOWS) diff --git a/bsnes/ui/general/main-window.cpp b/bsnes/ui/general/main-window.cpp index 794e9a95..14fad801 100755 --- a/bsnes/ui/general/main-window.cpp +++ b/bsnes/ui/general/main-window.cpp @@ -212,6 +212,10 @@ void MainWindow::create() { return false; }; + onResize = []() { + utility.centerViewport(); + }; + synchronize(); } diff --git a/bsnes/ui/interface.cpp b/bsnes/ui/interface.cpp index 07c6ba2d..5ee935cf 100755 --- a/bsnes/ui/interface.cpp +++ b/bsnes/ui/interface.cpp @@ -79,11 +79,6 @@ void Filter::render(uint32_t *output, unsigned outpitch, const uint16_t *input, } void Interface::video_refresh(const uint16_t *data, unsigned width, unsigned height) { - //TODO: this should not be necessary ... somehow window is not updated otherwise - mainWindow.viewport.setGeometry( - utility.viewportX, utility.viewportY, utility.viewportWidth, utility.viewportHeight - ); - bool interlace = (height >= 240); bool overscan = (height == 239 || height == 478); unsigned inpitch = interlace ? 1024 : 2048; diff --git a/bsnes/ui/utility/utility.cpp b/bsnes/ui/utility/utility.cpp index f48b9c60..04b25eb5 100755 --- a/bsnes/ui/utility/utility.cpp +++ b/bsnes/ui/utility/utility.cpp @@ -57,6 +57,16 @@ 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 b04fa7e6..4977db51 100755 --- a/bsnes/ui/utility/utility.hpp +++ b/bsnes/ui/utility/utility.hpp @@ -5,8 +5,11 @@ struct Utility : property { void showMessage(const string &text); void setControllers(); + + void centerViewport(); void setScale(unsigned scale = 0); void setFullscreen(bool fullscreen = true); + void setFilter(); void setShader();