mirror of https://github.com/bsnes-emu/bsnes.git
Update to v075r09 release.
byuu says: Ported phoenix/Windows and phoenix/GTK+ over to the new system. There are some problems that need to be addressed: - Windows ComboBox height setting needs widget creation height to properly scale itself (make Widget::setGeometry virtual and override ComboBox::setGeometry) - Windows Canvas is completely broken - GTK+ Canvas is slow as shit compared to Qt Canvas, probably nothing I can do about it, have to do a very costly conversion because GTK+ is stupid and uses BGR like Nintendo - GTK+ listboxes are fucking insanely complicated to set up. Currently I just split the second-half of creation to the setHeaderText call, but when you don't call that, things explode - I'm probably going to have to completely destroy and recreate listboxes when changing the header text / column count - Qt resize code is still impossible to get right, it's not letting me size a window > 2/3rds of the screen size (it's in their docs) - I swear, Qt is the most painful API in the world to move/size windows with - now that Window is separate, it really needs geometry() and frameGeometry() as the two are quite different - I need a way to toggle window resizability for fixed layouts, Qt is once again going to be a nightmare as it lacks a way to do this other than fixed layouts - GTK+ currently explodes on bsnes, millions of console messages, wonderful - plenty more I'm forgetting One bit of really cool/good news though: I made Fixed/Horizontal/Vertical layouts external to phoenix itself. The code is included for all targets so that it's always there and compiled into one object, but the great news is that you can easily write your own layout widgets and they'll work on all toolkits instantly. That resize issue with bsnes was so simple it's annoying: my FixedLayout container was repositioning on geometry updates. Made it only do it once at creation like it should. bsnes now has a fancy resize, grow the window and get black borders, shrink it and the video shrinks with it. I plan to make it fancier with constraint settings (center, scale, stretch). Basically I want to turn the fullscreen setting into a general setting that also applies to windowed scaling. I will probably turn the video scale X sizes into regular items instead of radio boxes, so you can easily reset to a fixed size whenever you want. Update bsnes to remember width,height geometry as well and it should be quite nice.
This commit is contained in:
parent
266495b475
commit
2c61ce2522
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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"
|
||||
|
|
|
@ -83,6 +83,8 @@ struct Widget;
|
|||
|
||||
struct Window : Object {
|
||||
nall::function<bool ()> onClose;
|
||||
nall::function<void ()> onMove;
|
||||
nall::function<void ()> 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<void ()> 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<void ()> 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<uint8_t (unsigned)> onRead;
|
||||
nall::function<void (unsigned, uint8_t)> 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<void ()> 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<void (unsigned)> 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<void ()> onActivate;
|
||||
nall::function<void ()> 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<void ()> 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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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> children;
|
||||
struct ComboBox::Data {
|
||||
unsigned counter;
|
||||
};
|
||||
|
||||
struct Canvas::Data {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
}
|
|
@ -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> children;
|
||||
};
|
|
@ -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<HorizontalLayout::Data::Children> children = horizontalLayout->children;
|
||||
linear_vector<HorizontalLayout::Children> 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;
|
||||
}
|
|
@ -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> children;
|
||||
};
|
|
@ -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<VerticalLayout::Data::Children> children = verticalLayout->children;
|
||||
linear_vector<VerticalLayout::Children> 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;
|
||||
}
|
|
@ -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> children;
|
||||
};
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<void*>(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<void*>(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<void*>(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<void*>(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:
|
||||
|
|
|
@ -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> 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> 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> children;
|
||||
|
||||
Data(VerticalLayout &self) : self(self) {
|
||||
}
|
||||
};
|
||||
|
||||
struct Widget::Data {
|
||||
public:
|
||||
Widget &self;
|
||||
QWidget *widget;
|
||||
Font *font;
|
||||
|
|
|
@ -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
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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> widgets;
|
||||
};
|
||||
|
||||
struct Canvas::Data {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<void ()> onTick;
|
||||
void setParent(Layout &parent);
|
||||
void setText(const nall::string &text);
|
||||
Button();
|
||||
};
|
||||
|
@ -165,14 +157,14 @@ struct Canvas : Widget {
|
|||
|
||||
struct CheckBox : Widget {
|
||||
nall::function<void ()> 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<void ()> 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<void ()> 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<uint8_t (unsigned)> onRead;
|
||||
nall::function<void (unsigned, uint8_t)> 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<void ()> 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<void ()> onActivate;
|
||||
nall::function<void ()> onChange;
|
||||
nall::function<void (unsigned)> 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<void ()> 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<void ()> onActivate;
|
||||
nall::function<void ()> 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<void ()> 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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -212,6 +212,10 @@ void MainWindow::create() {
|
|||
return false;
|
||||
};
|
||||
|
||||
onResize = []() {
|
||||
utility.centerViewport();
|
||||
};
|
||||
|
||||
synchronize();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -5,8 +5,11 @@ struct Utility : property<Utility> {
|
|||
void showMessage(const string &text);
|
||||
|
||||
void setControllers();
|
||||
|
||||
void centerViewport();
|
||||
void setScale(unsigned scale = 0);
|
||||
void setFullscreen(bool fullscreen = true);
|
||||
|
||||
void setFilter();
|
||||
void setShader();
|
||||
|
||||
|
|
Loading…
Reference in New Issue