Update to v075r16 release.

byuu says:

This has my latest API enhancements, but there are some known issues:
- resize on Windows seems to not repaint the buttons properly in rare
  cases. I may just need to revert to flickering resize.
- GTK+ reports the wrong menu height, off by two pixels, prior to the
  window being realized (made visible)
  - this results in the main window moving up two pixels after each run
    of bsnes

The menu height bug was actually there previously, it was just that Qt
and GTK+ were computing the frame margins incorrectly (ignoring the menu
bar) before.

On the bright side, ui/settings/input.cpp has been improved by way of
the new multi-layout support. The window is no longer forced to an
awkward 640 pixels wide, as the mouse axes/buttons can overlap now. The
code is also simpler since I am using the Layout::setVisible command to
toggle groups on and off instead of doing it for each and every control.
This commit is contained in:
Tim Allen 2011-02-27 20:05:10 +11:00
parent c31543ea58
commit 017f9926fc
64 changed files with 817 additions and 799 deletions

View File

@ -15,14 +15,14 @@
Object::Object() { OS::initialize(); } Object::Object() { OS::initialize(); }
unsigned OS::desktopWidth() { return pOS::desktopWidth(); } Geometry OS::availableGeometry() { return pOS::availableGeometry(); }
unsigned OS::desktopHeight() { return pOS::desktopHeight(); } Geometry OS::desktopGeometry() { return pOS::desktopGeometry(); }
string OS::fileLoad_(Window &parent, const string &path, const lstring &filter_) { auto filter = filter_; if(filter.size() == 0) filter.append("All files (*)"); return pOS::fileLoad(parent, path, filter); } string OS::fileLoad_(Window &parent, const string &path, const lstring &filter_) { auto filter = filter_; if(filter.size() == 0) filter.append("All files (*)"); return pOS::fileLoad(parent, path, filter); }
string OS::fileSave_(Window &parent, const string &path, const lstring &filter_) { auto filter = filter_; if(filter.size() == 0) filter.append("All files (*)"); return pOS::fileSave(parent, path, filter); } string OS::fileSave_(Window &parent, const string &path, const lstring &filter_) { auto filter = filter_; if(filter.size() == 0) filter.append("All files (*)"); return pOS::fileSave(parent, path, filter); }
string OS::folderSelect(Window &parent, const string &path) { return pOS::folderSelect(parent, path); } string OS::folderSelect(Window &parent, const string &path) { return pOS::folderSelect(parent, path); }
void OS::main() { return pOS::main(); } void OS::main() { return pOS::main(); }
bool OS::pending() { return pOS::pending(); } bool OS::pendingEvents() { return pOS::pendingEvents(); }
void OS::process() { return pOS::process(); } void OS::processEvents() { return pOS::processEvents(); }
void OS::quit() { return pOS::quit(); } void OS::quit() { return pOS::quit(); }
void OS::initialize() { static bool initialized = false; if(initialized == false) { initialized = true; return pOS::initialize(); } } void OS::initialize() { static bool initialized = false; if(initialized == false) { initialized = true; return pOS::initialize(); } }
@ -42,11 +42,12 @@ Window Window::None;
void Window::append(Layout &layout) { state.layout.append(layout); return p.append(layout); } void Window::append(Layout &layout) { state.layout.append(layout); return p.append(layout); }
void Window::append(Menu &menu) { state.menu.append(menu); ((Action&)menu).state.parent = this; return p.append(menu); } void Window::append(Menu &menu) { state.menu.append(menu); ((Action&)menu).state.parent = this; return p.append(menu); }
void Window::append(Widget &widget) { state.widget.append(widget); return p.append(widget); } void Window::append(Widget &widget) { state.widget.append(widget); return p.append(widget); }
Geometry Window::frameGeometry() { return p.frameGeometry(); } Geometry Window::frameGeometry() { Geometry geometry = p.geometry(), margin = p.frameMargin(); return { geometry.x - margin.x, geometry.y - margin.y, geometry.width + margin.width, geometry.height + margin.height }; }
Geometry Window::frameMargin() { return p.frameMargin(); }
bool Window::focused() { return p.focused(); } bool Window::focused() { return p.focused(); }
Geometry Window::geometry() { return p.geometry(); } Geometry Window::geometry() { return p.geometry(); }
void Window::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { state.backgroundColor = true; state.backgroundColorRed = red; state.backgroundColorGreen = green; state.backgroundColorBlue = blue; return p.setBackgroundColor(red, green, blue); } void Window::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { state.backgroundColor = true; state.backgroundColorRed = red; state.backgroundColorGreen = green; state.backgroundColorBlue = blue; return p.setBackgroundColor(red, green, blue); }
void Window::setFrameGeometry(const Geometry &geometry) { return p.setFrameGeometry(geometry); } void Window::setFrameGeometry(const Geometry &geometry) { Geometry margin = p.frameMargin(); return setGeometry({ geometry.x + margin.x, geometry.y + margin.y, geometry.width - margin.width, geometry.height - margin.height }); }
void Window::setFocused() { return p.setFocused(); } void Window::setFocused() { return p.setFocused(); }
void Window::setFullScreen(bool fullScreen) { state.fullScreen = fullScreen; return p.setFullScreen(fullScreen); } void Window::setFullScreen(bool fullScreen) { state.fullScreen = fullScreen; return p.setFullScreen(fullScreen); }
void Window::setGeometry(const Geometry &geometry) { state.geometry = geometry; return p.setGeometry(geometry); } void Window::setGeometry(const Geometry &geometry) { state.geometry = geometry; return p.setGeometry(geometry); }
@ -69,28 +70,29 @@ void Menu::append(Action &action) { state.action.append(action); return p.append
void Menu::setText(const string &text) { state.text = text; return p.setText(text); } void Menu::setText(const string &text) { state.text = text; return p.setText(text); }
Menu::Menu() : state(*new State), base_from_member<pMenu&>(*new pMenu(*this)), Action(base_from_member<pMenu&>::value), p(base_from_member<pMenu&>::value) { p.constructor(); } Menu::Menu() : state(*new State), base_from_member<pMenu&>(*new pMenu(*this)), Action(base_from_member<pMenu&>::value), p(base_from_member<pMenu&>::value) { p.constructor(); }
MenuSeparator::MenuSeparator() : base_from_member<pMenuSeparator&>(*new pMenuSeparator(*this)), Action(base_from_member<pMenuSeparator&>::value), p(base_from_member<pMenuSeparator&>::value) { p.constructor(); } Separator::Separator() : base_from_member<pSeparator&>(*new pSeparator(*this)), Action(base_from_member<pSeparator&>::value), p(base_from_member<pSeparator&>::value) { p.constructor(); }
void MenuItem::setText(const string &text) { state.text = text; return p.setText(text); } void Item::setText(const string &text) { state.text = text; return p.setText(text); }
MenuItem::MenuItem() : state(*new State), base_from_member<pMenuItem&>(*new pMenuItem(*this)), Action(base_from_member<pMenuItem&>::value), p(base_from_member<pMenuItem&>::value) { p.constructor(); } Item::Item() : state(*new State), base_from_member<pItem&>(*new pItem(*this)), Action(base_from_member<pItem&>::value), p(base_from_member<pItem&>::value) { p.constructor(); }
bool MenuCheckItem::checked() { return p.checked(); } bool CheckItem::checked() { return p.checked(); }
void MenuCheckItem::setChecked(bool checked) { state.checked = checked; return p.setChecked(checked); } void CheckItem::setChecked(bool checked) { state.checked = checked; return p.setChecked(checked); }
void MenuCheckItem::setText(const string &text) { state.text = text; return p.setText(text); } void CheckItem::setText(const string &text) { state.text = text; return p.setText(text); }
MenuCheckItem::MenuCheckItem() : state(*new State), base_from_member<pMenuCheckItem&>(*new pMenuCheckItem(*this)), Action(base_from_member<pMenuCheckItem&>::value), p(base_from_member<pMenuCheckItem&>::value) { p.constructor(); } CheckItem::CheckItem() : state(*new State), base_from_member<pCheckItem&>(*new pCheckItem(*this)), Action(base_from_member<pCheckItem&>::value), p(base_from_member<pCheckItem&>::value) { p.constructor(); }
void MenuRadioItem::group_(const reference_array<MenuRadioItem&> &list) { foreach(item, list) item.p.setGroup(item.state.group = list); if(list.size()) list[0].setChecked(); } void RadioItem::group_(const reference_array<RadioItem&> &list) { foreach(item, list) item.p.setGroup(item.state.group = list); if(list.size()) list[0].setChecked(); }
bool MenuRadioItem::checked() { return p.checked(); } bool RadioItem::checked() { return p.checked(); }
void MenuRadioItem::setChecked() { foreach(item, state.group) item.state.checked = false; state.checked = true; return p.setChecked(); } void RadioItem::setChecked() { foreach(item, state.group) item.state.checked = false; state.checked = true; return p.setChecked(); }
void MenuRadioItem::setText(const string &text) { state.text = text; return p.setText(text); } void RadioItem::setText(const string &text) { state.text = text; return p.setText(text); }
MenuRadioItem::MenuRadioItem() : state(*new State), base_from_member<pMenuRadioItem&>(*new pMenuRadioItem(*this)), Action(base_from_member<pMenuRadioItem&>::value), p(base_from_member<pMenuRadioItem&>::value) { p.constructor(); } RadioItem::RadioItem() : state(*new State), base_from_member<pRadioItem&>(*new pRadioItem(*this)), Action(base_from_member<pRadioItem&>::value), p(base_from_member<pRadioItem&>::value) { p.constructor(); }
bool Widget::enabled() { return p.enabled(); } bool Widget::enabled() { return state.enabled; }
void Widget::setEnabled(bool enabled) { state.enabled = enabled; return p.setEnabled(enabled); } void Widget::setEnabled(bool enabled) { state.enabled = enabled; return p.setEnabled(enabled); }
void Widget::setFocused() { return p.setFocused(); } void Widget::setFocused() { return p.setFocused(); }
void Widget::setFont(Font &font) { state.font = &font; return p.setFont(font); } void Widget::setFont(Font &font) { state.font = &font; return p.setFont(font); }
void Widget::setGeometry(const Geometry &geometry) { state.geometry = geometry; return p.setGeometry(geometry); } void Widget::setGeometry(const Geometry &geometry) { state.geometry = geometry; return p.setGeometry(geometry); }
void Widget::setVisible(bool visible) { state.visible = visible; return p.setVisible(visible); } void Widget::setVisible(bool visible) { state.visible = visible; return p.setVisible(visible); }
bool Widget::visible() { return state.visible; }
Widget::Widget() : state(*new State), p(*new pWidget(*this)) { state.abstract = true; p.constructor(); } Widget::Widget() : state(*new State), p(*new pWidget(*this)) { state.abstract = true; p.constructor(); }
Widget::Widget(pWidget &p) : state(*new State), p(p) { p.constructor(); } Widget::Widget(pWidget &p) : state(*new State), p(p) { p.constructor(); }
@ -129,17 +131,18 @@ string LineEdit::text() { return p.text(); }
LineEdit::LineEdit() : state(*new State), base_from_member<pLineEdit&>(*new pLineEdit(*this)), Widget(base_from_member<pLineEdit&>::value), p(base_from_member<pLineEdit&>::value) { p.constructor(); } LineEdit::LineEdit() : state(*new State), base_from_member<pLineEdit&>(*new pLineEdit(*this)), Widget(base_from_member<pLineEdit&>::value), p(base_from_member<pLineEdit&>::value) { p.constructor(); }
void ListView::append_(const lstring &text) { state.checked.append(false); state.text.append(text); return p.append(text); } void ListView::append_(const lstring &text) { state.checked.append(false); state.text.append(text); return p.append(text); }
void ListView::autosizeColumns() { return p.autosizeColumns(); } void ListView::autoSizeColumns() { return p.autoSizeColumns(); }
bool ListView::checked(unsigned row) { return p.checked(row); } bool ListView::checked(unsigned row) { return p.checked(row); }
void ListView::modify_(unsigned row, const lstring &text) { state.text[row] = text; return p.modify(row, text); } void ListView::modify_(unsigned row, const lstring &text) { state.text[row] = text; return p.modify(row, text); }
void ListView::modify(unsigned row, unsigned column, const string &text) { state.text[row][column] = text; return p.modify(row, column, text); }
void ListView::reset() { state.checked.reset(); state.text.reset(); return p.reset(); } void ListView::reset() { state.checked.reset(); state.text.reset(); return p.reset(); }
optional<unsigned> ListView::selection() { return p.selection(); } bool ListView::selected() { return p.selected(); }
unsigned ListView::selection() { return p.selection(); }
void ListView::setCheckable(bool checkable) { state.checkable = checkable; return p.setCheckable(checkable); } void ListView::setCheckable(bool checkable) { state.checkable = checkable; return p.setCheckable(checkable); }
void ListView::setChecked(unsigned row, bool checked) { state.checked[row] = checked; return p.setChecked(row, checked); } void ListView::setChecked(unsigned row, bool checked) { state.checked[row] = checked; return p.setChecked(row, checked); }
void ListView::setHeaderText_(const lstring &text) { state.headerText = text; return p.setHeaderText(text); } void ListView::setHeaderText_(const lstring &text) { state.headerText = text; return p.setHeaderText(text); }
void ListView::setHeaderVisible(bool visible) { state.headerVisible = visible; return p.setHeaderVisible(visible); } void ListView::setHeaderVisible(bool visible) { state.headerVisible = visible; return p.setHeaderVisible(visible); }
void ListView::setSelection(unsigned row) { state.selection = { true, row }; return p.setSelection(row); } void ListView::setSelected(bool selected) { state.selected = selected; return p.setSelected(selected); }
void ListView::setSelection(unsigned row) { state.selected = true; state.selection = row; return p.setSelection(row); }
ListView::ListView() : state(*new State), base_from_member<pListView&>(*new pListView(*this)), Widget(base_from_member<pListView&>::value), p(base_from_member<pListView&>::value) { p.constructor(); } ListView::ListView() : state(*new State), base_from_member<pListView&>(*new pListView(*this)), Widget(base_from_member<pListView&>::value), p(base_from_member<pListView&>::value) { p.constructor(); }
void ProgressBar::setPosition(unsigned position) { state.position = position; return p.setPosition(position); } void ProgressBar::setPosition(unsigned position) { state.position = position; return p.setPosition(position); }

View File

@ -9,10 +9,10 @@ struct pFont;
struct pWindow; struct pWindow;
struct pAction; struct pAction;
struct pMenu; struct pMenu;
struct pMenuSeparator; struct pSeparator;
struct pMenuItem; struct pItem;
struct pMenuCheckItem; struct pCheckItem;
struct pMenuRadioItem; struct pRadioItem;
struct pLayout; struct pLayout;
struct pWidget; struct pWidget;
struct pButton; struct pButton;
@ -44,14 +44,14 @@ struct Object {
}; };
struct OS : Object { struct OS : Object {
static unsigned desktopWidth(); static Geometry availableGeometry();
static unsigned desktopHeight(); static Geometry desktopGeometry();
template<typename... Args> static nall::string fileLoad(Window &parent, const nall::string &path, const Args&... args) { return fileLoad_(parent, path, { args... }); } template<typename... Args> static nall::string fileLoad(Window &parent, const nall::string &path, const Args&... args) { return fileLoad_(parent, path, { args... }); }
template<typename... Args> static nall::string fileSave(Window &parent, const nall::string &path, const Args&... args) { return fileSave_(parent, path, { args... }); } template<typename... Args> static nall::string fileSave(Window &parent, const nall::string &path, const Args&... args) { return fileSave_(parent, path, { args... }); }
static nall::string folderSelect(Window &parent, const nall::string &path); static nall::string folderSelect(Window &parent, const nall::string &path);
static void main(); static void main();
static bool pending(); static bool pendingEvents();
static void process(); static void processEvents();
static void quit(); static void quit();
OS(); OS();
@ -105,6 +105,7 @@ struct Window : Object {
void append(Menu &menu); void append(Menu &menu);
void append(Widget &widget); void append(Widget &widget);
Geometry frameGeometry(); Geometry frameGeometry();
Geometry frameMargin();
bool focused(); bool focused();
Geometry geometry(); Geometry geometry();
void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue);
@ -148,36 +149,36 @@ struct Menu : private nall::base_from_member<pMenu&>, Action {
pMenu &p; pMenu &p;
}; };
struct MenuSeparator : private nall::base_from_member<pMenuSeparator&>, Action { struct Separator : private nall::base_from_member<pSeparator&>, Action {
MenuSeparator(); Separator();
pMenuSeparator &p; pSeparator &p;
}; };
struct MenuItem : private nall::base_from_member<pMenuItem&>, Action { struct Item : private nall::base_from_member<pItem&>, Action {
nall::function<void ()> onTick; nall::function<void ()> onTick;
void setText(const nall::string &text); void setText(const nall::string &text);
MenuItem(); Item();
struct State; struct State;
State &state; State &state;
pMenuItem &p; pItem &p;
}; };
struct MenuCheckItem : private nall::base_from_member<pMenuCheckItem&>, Action { struct CheckItem : private nall::base_from_member<pCheckItem&>, Action {
nall::function<void ()> onTick; nall::function<void ()> onTick;
bool checked(); bool checked();
void setChecked(bool checked = true); void setChecked(bool checked = true);
void setText(const nall::string &text); void setText(const nall::string &text);
MenuCheckItem(); CheckItem();
struct State; struct State;
State &state; State &state;
pMenuCheckItem &p; pCheckItem &p;
}; };
struct MenuRadioItem : private nall::base_from_member<pMenuRadioItem&>, Action { struct RadioItem : private nall::base_from_member<pRadioItem&>, Action {
template<typename... Args> static void group(Args&... args) { group_({ args... }); } template<typename... Args> static void group(Args&... args) { group_({ args... }); }
nall::function<void ()> onTick; nall::function<void ()> onTick;
@ -186,13 +187,13 @@ struct MenuRadioItem : private nall::base_from_member<pMenuRadioItem&>, Action {
void setChecked(); void setChecked();
void setText(const nall::string &text); void setText(const nall::string &text);
MenuRadioItem(); RadioItem();
struct State; struct State;
State &state; State &state;
pMenuRadioItem &p; pRadioItem &p;
private: private:
static void group_(const nall::reference_array<MenuRadioItem&> &list); static void group_(const nall::reference_array<RadioItem&> &list);
}; };
struct Layout : Object { struct Layout : Object {
@ -208,6 +209,7 @@ struct Widget : Object {
void setFont(Font &font); void setFont(Font &font);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
void setVisible(bool visible = true); void setVisible(bool visible = true);
bool visible();
Widget(); Widget();
Widget(pWidget &p); Widget(pWidget &p);
@ -312,16 +314,17 @@ struct ListView : private nall::base_from_member<pListView&>, Widget {
nall::function<void (unsigned)> onTick; nall::function<void (unsigned)> onTick;
template<typename... Args> void append(const Args&... args) { append_({ args... }); } template<typename... Args> void append(const Args&... args) { append_({ args... }); }
void autosizeColumns(); void autoSizeColumns();
bool checked(unsigned row); bool checked(unsigned row);
template<typename... Args> void modify(unsigned row, const Args&... args) { modify_(row, { args... }); } template<typename... Args> void modify(unsigned row, const Args&... args) { modify_(row, { args... }); }
void modify(unsigned row, unsigned column, const nall::string &text);
void reset(); void reset();
nall::optional<unsigned> selection(); bool selected();
unsigned selection();
void setCheckable(bool checkable = true); void setCheckable(bool checkable = true);
void setChecked(unsigned row, bool checked = true); void setChecked(unsigned row, bool checked = true);
template<typename... Args> void setHeaderText(const Args&... args) { setHeaderText_({ args... }); } template<typename... Args> void setHeaderText(const Args&... args) { setHeaderText_({ args... }); }
void setHeaderVisible(bool visible = true); void setHeaderVisible(bool visible = true);
void setSelected(bool selected = true);
void setSelection(unsigned row); void setSelection(unsigned row);
ListView(); ListView();

View File

@ -1,6 +1,6 @@
struct Font::State { struct Font::State {
bool bold; bool bold;
nall::string family; string family;
bool italic; bool italic;
unsigned size; unsigned size;
bool underline; bool underline;
@ -18,17 +18,17 @@ struct Window::State {
unsigned backgroundColorRed, backgroundColorGreen, backgroundColorBlue; unsigned backgroundColorRed, backgroundColorGreen, backgroundColorBlue;
bool fullScreen; bool fullScreen;
Geometry geometry; Geometry geometry;
nall::reference_array<Layout&> layout; reference_array<Layout&> layout;
nall::reference_array<Menu&> menu; reference_array<Menu&> menu;
Font *menuFont; Font *menuFont;
bool menuVisible; bool menuVisible;
bool resizable; bool resizable;
Font *statusFont; Font *statusFont;
nall::string statusText; string statusText;
bool statusVisible; bool statusVisible;
nall::string title; string title;
bool visible; bool visible;
nall::reference_array<Widget&> widget; reference_array<Widget&> widget;
Font *widgetFont; Font *widgetFont;
State() { State() {
@ -60,27 +60,27 @@ struct Action::State {
}; };
struct Menu::State { struct Menu::State {
nall::reference_array<Action&> action; reference_array<Action&> action;
nall::string text; string text;
}; };
struct MenuItem::State { struct Item::State {
nall::string text; string text;
}; };
struct MenuCheckItem::State { struct CheckItem::State {
bool checked; bool checked;
nall::string text; string text;
State() { State() {
checked = false; checked = false;
} }
}; };
struct MenuRadioItem::State { struct RadioItem::State {
bool checked; bool checked;
nall::reference_array<MenuRadioItem&> group; reference_array<RadioItem&> group;
nall::string text; string text;
State() { State() {
checked = true; checked = true;
@ -104,7 +104,7 @@ struct Widget::State {
}; };
struct Button::State { struct Button::State {
nall::string text; string text;
State() { State() {
} }
@ -112,7 +112,7 @@ struct Button::State {
struct CheckBox::State { struct CheckBox::State {
bool checked; bool checked;
nall::string text; string text;
State() { State() {
checked = false; checked = false;
@ -121,7 +121,7 @@ struct CheckBox::State {
struct ComboBox::State { struct ComboBox::State {
unsigned selection; unsigned selection;
nall::linear_vector<nall::string> text; linear_vector<string> text;
State() { State() {
selection = 0; selection = 0;
@ -153,12 +153,12 @@ struct HorizontalSlider::State {
}; };
struct Label::State { struct Label::State {
nall::string text; string text;
}; };
struct LineEdit::State { struct LineEdit::State {
bool editable; bool editable;
nall::string text; string text;
State() { State() {
editable = true; editable = true;
@ -167,15 +167,18 @@ struct LineEdit::State {
struct ListView::State { struct ListView::State {
bool checkable; bool checkable;
nall::array<bool> checked; array<bool> checked;
nall::lstring headerText; lstring headerText;
bool headerVisible; bool headerVisible;
nall::optional<unsigned> selection; bool selected;
nall::linear_vector<nall::lstring> text; unsigned selection;
linear_vector<lstring> text;
State() : selection(false, 0) { State() {
checkable = false; checkable = false;
headerVisible = false; headerVisible = false;
selected = false;
selection = 0;
} }
}; };
@ -189,8 +192,8 @@ struct ProgressBar::State {
struct RadioBox::State { struct RadioBox::State {
bool checked; bool checked;
nall::reference_array<RadioBox&> group; reference_array<RadioBox&> group;
nall::string text; string text;
State() { State() {
checked = true; checked = true;
@ -200,7 +203,7 @@ struct RadioBox::State {
struct TextEdit::State { struct TextEdit::State {
unsigned cursorPosition; unsigned cursorPosition;
bool editable; bool editable;
nall::string text; string text;
bool wordWrap; bool wordWrap;
State() { State() {

View File

@ -1,22 +1,22 @@
static void MenuCheckItem_tick(MenuCheckItem *self) { static void CheckItem_tick(CheckItem *self) {
if(self->p.locked == false && self->onTick) self->onTick(); if(self->p.locked == false && self->onTick) self->onTick();
} }
bool pMenuCheckItem::checked() { bool pCheckItem::checked() {
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
} }
void pMenuCheckItem::setChecked(bool checked) { void pCheckItem::setChecked(bool checked) {
locked = true; locked = true;
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), checked); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), checked);
locked = false; locked = false;
} }
void pMenuCheckItem::setText(const string &text) { void pCheckItem::setText(const string &text) {
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text); gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text);
} }
void pMenuCheckItem::constructor() { void pCheckItem::constructor() {
widget = gtk_check_menu_item_new_with_label(""); widget = gtk_check_menu_item_new_with_label("");
g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(MenuCheckItem_tick), (gpointer)&menuCheckItem); g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(CheckItem_tick), (gpointer)&checkItem);
} }

View File

@ -1,12 +1,12 @@
static void MenuItem_tick(MenuItem *self) { static void Item_tick(Item *self) {
if(self->onTick) self->onTick(); if(self->onTick) self->onTick();
} }
void pMenuItem::setText(const string &text) { void pItem::setText(const string &text) {
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text); gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text);
} }
void pMenuItem::constructor() { void pItem::constructor() {
widget = gtk_menu_item_new_with_label(""); widget = gtk_menu_item_new_with_label("");
g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(MenuItem_tick), (gpointer)&menuItem); g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(Item_tick), (gpointer)&item);
} }

View File

@ -1,19 +1,19 @@
static void MenuRadioItem_tick(MenuRadioItem *self) { static void RadioItem_tick(RadioItem *self) {
if(self->p.locked == false && self->checked() && self->onTick) self->onTick(); if(self->p.locked == false && self->checked() && self->onTick) self->onTick();
} }
bool pMenuRadioItem::checked() { bool pRadioItem::checked() {
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
} }
void pMenuRadioItem::setChecked() { void pRadioItem::setChecked() {
locked = true; locked = true;
foreach(item, menuRadioItem.state.group) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), false); foreach(item, radioItem.state.group) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), false);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), true); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), true);
locked = false; locked = false;
} }
void pMenuRadioItem::setGroup(const reference_array<MenuRadioItem&> &group) { void pRadioItem::setGroup(const reference_array<RadioItem&> &group) {
foreach(item, group, n) { foreach(item, group, n) {
if(n == 0) continue; if(n == 0) continue;
GSList *currentGroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[0].p.widget)); GSList *currentGroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[0].p.widget));
@ -23,11 +23,11 @@ void pMenuRadioItem::setGroup(const reference_array<MenuRadioItem&> &group) {
} }
} }
void pMenuRadioItem::setText(const string &text) { void pRadioItem::setText(const string &text) {
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text); gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text);
} }
void pMenuRadioItem::constructor() { void pRadioItem::constructor() {
widget = gtk_radio_menu_item_new_with_label(0, ""); widget = gtk_radio_menu_item_new_with_label(0, "");
g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(MenuRadioItem_tick), (gpointer)&menuRadioItem); g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(RadioItem_tick), (gpointer)&radioItem);
} }

View File

@ -1,3 +1,3 @@
void pMenuSeparator::constructor() { void pSeparator::constructor() {
widget = gtk_separator_menu_item_new(); widget = gtk_separator_menu_item_new();
} }

View File

@ -7,10 +7,10 @@
#include "action/action.cpp" #include "action/action.cpp"
#include "action/menu.cpp" #include "action/menu.cpp"
#include "action/menu-separator.cpp" #include "action/separator.cpp"
#include "action/menu-item.cpp" #include "action/item.cpp"
#include "action/menu-check-item.cpp" #include "action/check-item.cpp"
#include "action/menu-radio-item.cpp" #include "action/radio-item.cpp"
#include "widget/widget.cpp" #include "widget/widget.cpp"
#include "widget/button.cpp" #include "widget/button.cpp"
@ -27,12 +27,18 @@
#include "widget/vertical-slider.cpp" #include "widget/vertical-slider.cpp"
#include "widget/viewport.cpp" #include "widget/viewport.cpp"
unsigned pOS::desktopWidth() { Geometry pOS::availableGeometry() {
return gdk_screen_get_width(gdk_screen_get_default()); //TODO: is there a GTK+ function for this?
//should return desktopGeometry() sans panels, toolbars, docks, etc.
return desktopGeometry();
} }
unsigned pOS::desktopHeight() { Geometry pOS::desktopGeometry() {
return gdk_screen_get_height(gdk_screen_get_default()); return {
0, 0,
gdk_screen_get_width(gdk_screen_get_default()),
gdk_screen_get_height(gdk_screen_get_default())
};
} }
static string pOS_fileDialog(bool save, Window &parent, const string &path, const lstring &filter) { static string pOS_fileDialog(bool save, Window &parent, const string &path, const lstring &filter) {
@ -109,12 +115,12 @@ void pOS::main() {
gtk_main(); gtk_main();
} }
bool pOS::pending() { bool pOS::pendingEvents() {
return gtk_events_pending(); return gtk_events_pending();
} }
void pOS::process() { void pOS::processEvents() {
while(pending()) gtk_main_iteration_do(false); while(pendingEvents()) gtk_main_iteration_do(false);
} }
void pOS::quit() { void pOS::quit() {

View File

@ -24,14 +24,14 @@ struct pObject {
}; };
struct pOS : public pObject { struct pOS : public pObject {
static unsigned desktopWidth(); static Geometry availableGeometry();
static unsigned desktopHeight(); static Geometry desktopGeometry();
static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileLoad(Window &parent, const string &path, const lstring &filter);
static string fileSave(Window &parent, const string &path, const lstring &filter); static string fileSave(Window &parent, const string &path, const lstring &filter);
static string folderSelect(Window &parent, const string &path); static string folderSelect(Window &parent, const string &path);
static void main(); static void main();
static bool pending(); static bool pendingEvents();
static void process(); static void processEvents();
static void quit(); static void quit();
static void initialize(); static void initialize();
@ -70,11 +70,10 @@ struct pWindow : public pObject {
void append(Layout &layout); void append(Layout &layout);
void append(Menu &menu); void append(Menu &menu);
void append(Widget &widget); void append(Widget &widget);
Geometry frameGeometry();
bool focused(); bool focused();
Geometry frameMargin();
Geometry geometry(); Geometry geometry();
void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue);
void setFrameGeometry(const Geometry &geometry);
void setFocused(); void setFocused();
void setFullScreen(bool fullScreen); void setFullScreen(bool fullScreen);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
@ -117,42 +116,42 @@ struct pMenu : public pAction {
void setFont(Font &font); void setFont(Font &font);
}; };
struct pMenuSeparator : public pAction { struct pSeparator : public pAction {
MenuSeparator &menuSeparator; Separator &separator;
pMenuSeparator(MenuSeparator &menuSeparator) : pAction(menuSeparator), menuSeparator(menuSeparator) {} pSeparator(Separator &separator) : pAction(separator), separator(separator) {}
void constructor(); void constructor();
}; };
struct pMenuItem : public pAction { struct pItem : public pAction {
MenuItem &menuItem; Item &item;
void setText(const string &text); void setText(const string &text);
pMenuItem(MenuItem &menuItem) : pAction(menuItem), menuItem(menuItem) {} pItem(Item &item) : pAction(item), item(item) {}
void constructor(); void constructor();
}; };
struct pMenuCheckItem : public pAction { struct pCheckItem : public pAction {
MenuCheckItem &menuCheckItem; CheckItem &checkItem;
bool checked(); bool checked();
void setChecked(bool checked); void setChecked(bool checked);
void setText(const string &text); void setText(const string &text);
pMenuCheckItem(MenuCheckItem &menuCheckItem) : pAction(menuCheckItem), menuCheckItem(menuCheckItem) {} pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {}
void constructor(); void constructor();
}; };
struct pMenuRadioItem : public pAction { struct pRadioItem : public pAction {
MenuRadioItem &menuRadioItem; RadioItem &radioItem;
bool checked(); bool checked();
void setChecked(); void setChecked();
void setGroup(const reference_array<MenuRadioItem&> &group); void setGroup(const reference_array<RadioItem&> &group);
void setText(const string &text); void setText(const string &text);
pMenuRadioItem(MenuRadioItem &menuRadioItem) : pAction(menuRadioItem), menuRadioItem(menuRadioItem) {} pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
void constructor(); void constructor();
}; };
@ -272,16 +271,17 @@ struct pListView : public pWidget {
linear_vector<GtkColumn> column; linear_vector<GtkColumn> column;
void append(const lstring &text); void append(const lstring &text);
void autosizeColumns(); void autoSizeColumns();
bool checked(unsigned row); bool checked(unsigned row);
void modify(unsigned row, const lstring &text); void modify(unsigned row, const lstring &text);
void modify(unsigned row, unsigned column, const string &text);
void reset(); void reset();
optional<unsigned> selection(); bool selected();
unsigned selection();
void setCheckable(bool checkable); void setCheckable(bool checkable);
void setChecked(unsigned row, bool checked); void setChecked(unsigned row, bool checked);
void setHeaderText(const lstring &text); void setHeaderText(const lstring &text);
void setHeaderVisible(bool visible); void setHeaderVisible(bool visible);
void setSelected(bool selected);
void setSelection(unsigned row); void setSelection(unsigned row);
pListView(ListView &listView) : pWidget(listView), listView(listView) {} pListView(ListView &listView) : pWidget(listView), listView(listView) {}

View File

@ -1,12 +1,13 @@
static void ListView_activate(ListView *self) { static void ListView_activate(ListView *self) {
signed selection = -1;
if(self->onActivate) self->onActivate(); if(self->onActivate) self->onActivate();
} }
static void ListView_change(ListView *self) { static void ListView_change(ListView *self) {
signed selection = -1; if(self->state.selected == false || self->state.selection != self->selection()) {
self->state.selection = self->selection(); self->state.selected = true;
if(self->onChange) self->onChange(); self->state.selection = self->selection();
if(self->onChange) self->onChange();
}
} }
static void ListView_tick(GtkCellRendererToggle *cell, gchar *path_string, ListView *self) { static void ListView_tick(GtkCellRendererToggle *cell, gchar *path_string, ListView *self) {
@ -21,7 +22,7 @@ void pListView::append(const lstring &text) {
foreach(item, text, n) gtk_list_store_set(store, &iter, 1 + n, (const char*)item, -1); foreach(item, text, n) gtk_list_store_set(store, &iter, 1 + n, (const char*)item, -1);
} }
void pListView::autosizeColumns() { void pListView::autoSizeColumns() {
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(subWidget)); gtk_tree_view_columns_autosize(GTK_TREE_VIEW(subWidget));
} }
@ -46,18 +47,9 @@ void pListView::modify(unsigned row, const lstring &text) {
foreach(item, text, n) gtk_list_store_set(store, &iter, 1 + n, (const char*)item, -1); foreach(item, text, n) gtk_list_store_set(store, &iter, 1 + n, (const char*)item, -1);
} }
void pListView::modify(unsigned row, unsigned column, const string &text) {
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
GtkTreeIter iter;
for(unsigned i = 0; i <= row; i++) {
if(i == 0) gtk_tree_model_get_iter_first(model, &iter);
else gtk_tree_model_iter_next(model, &iter);
}
gtk_list_store_set(store, &iter, 1 + column, (const char*)text, -1);
}
void pListView::reset() { void pListView::reset() {
listView.state.selection = { false, 0 }; listView.state.selected = false;
listView.state.selection = 0;
gtk_list_store_clear(GTK_LIST_STORE(store)); gtk_list_store_clear(GTK_LIST_STORE(store));
gtk_tree_view_set_model(GTK_TREE_VIEW(subWidget), GTK_TREE_MODEL(store)); gtk_tree_view_set_model(GTK_TREE_VIEW(subWidget), GTK_TREE_MODEL(store));
//reset gtk_scrolled_window scrollbar position to 0,0 (top-left), as ListView is now empty //reset gtk_scrolled_window scrollbar position to 0,0 (top-left), as ListView is now empty
@ -65,17 +57,32 @@ void pListView::reset() {
gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0); gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0);
} }
optional<unsigned> pListView::selection() { bool pListView::selected() {
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget));
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
GtkTreeIter iter; GtkTreeIter iter;
if(gtk_tree_model_get_iter_first(model, &iter) == false) return { false, 0 }; if(gtk_tree_model_get_iter_first(model, &iter) == false) return false;
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return { true, 0 }; if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return true;
for(unsigned n = 1;; n++) { for(unsigned n = 1;; n++) {
if(gtk_tree_model_iter_next(model, &iter) == false) return { false, 0 }; if(gtk_tree_model_iter_next(model, &iter) == false) return false;
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return { true, n }; if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return true;
} }
return { false, 0 }; return false;
}
unsigned pListView::selection() {
if(selected() == false) return listView.state.selection;
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget));
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
GtkTreeIter iter;
if(gtk_tree_model_get_iter_first(model, &iter) == false) return 0;
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return 0;
for(unsigned n = 1;; n++) {
if(gtk_tree_model_iter_next(model, &iter) == false) return 0;
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return n;
}
return 0;
} }
void pListView::setCheckable(bool checkable) { void pListView::setCheckable(bool checkable) {
@ -99,9 +106,18 @@ void pListView::setHeaderVisible(bool visible) {
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(subWidget), visible); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(subWidget), visible);
} }
void pListView::setSelected(bool selected) {
if(selected == false) {
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget));
gtk_tree_selection_unselect_all(selection);
} else {
setSelection(listView.state.selection);
}
}
void pListView::setSelection(unsigned row) { void pListView::setSelection(unsigned row) {
signed current = -1; signed current = -1;
if(auto position = selection()) current = position(); if(selected()) current = selection();
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget)); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget));
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget)); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
gtk_tree_selection_unselect_all(selection); gtk_tree_selection_unselect_all(selection);
@ -177,8 +193,8 @@ void pListView::create() {
setCheckable(listView.state.checkable); setCheckable(listView.state.checkable);
foreach(text, listView.state.text) append(text); foreach(text, listView.state.text) append(text);
foreach(checked, listView.state.checked, n) setChecked(n, checked); foreach(checked, listView.state.checked, n) setChecked(n, checked);
if(auto selection = listView.state.selection) setSelection(selection()); if(listView.state.selected) setSelection(listView.state.selection);
autosizeColumns(); autoSizeColumns();
gtk_widget_show(subWidget); gtk_widget_show(subWidget);
} }

View File

@ -65,13 +65,15 @@ void pWindow::append(Widget &widget) {
widget.setVisible(); widget.setVisible();
} }
Geometry pWindow::frameGeometry() { Geometry pWindow::frameMargin() {
if(window.state.fullScreen == true) return { 0, 0, OS::desktopWidth(), OS::desktopHeight() }; unsigned menuHeight = window.state.menuVisible ? menu->allocation.height : 0;
unsigned statusHeight = window.state.statusVisible ? status->allocation.height : 0;
if(window.state.fullScreen) return { 0, menuHeight, 0, menuHeight + statusHeight };
return { return {
window.state.geometry.x - settings.frameGeometryX, settings.frameGeometryX,
window.state.geometry.y - settings.frameGeometryY, settings.frameGeometryY + menuHeight,
window.state.geometry.width + settings.frameGeometryWidth, settings.frameGeometryWidth,
window.state.geometry.height + settings.frameGeometryHeight settings.frameGeometryHeight + menuHeight + statusHeight
}; };
} }
@ -81,11 +83,10 @@ bool pWindow::focused() {
Geometry pWindow::geometry() { Geometry pWindow::geometry() {
if(window.state.fullScreen == true) { if(window.state.fullScreen == true) {
unsigned menuHeight = 0, statusHeight = 0; unsigned menuHeight = window.state.menuVisible ? menu->allocation.height : 0;
if(window.state.menuVisible) menuHeight = menu->allocation.height; unsigned statusHeight = window.state.statusVisible ? status->allocation.height : 0;
if(window.state.statusVisible) statusHeight = menu->allocation.height; return { 0, menuHeight, OS::desktopGeometry().width, OS::desktopGeometry().height - menuHeight - statusHeight };
return { 0, menuHeight, OS::desktopWidth(), OS::desktopHeight() - menuHeight - statusHeight }; };
}
return window.state.geometry; return window.state.geometry;
} }
@ -98,13 +99,6 @@ void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) {
gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color); gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color);
} }
void pWindow::setFrameGeometry(const Geometry &geometry) {
window.setGeometry({
geometry.x + settings.frameGeometryX, geometry.y + settings.frameGeometryY,
geometry.width - settings.frameGeometryWidth, geometry.height - settings.frameGeometryHeight
});
}
void pWindow::setFocused() { void pWindow::setFocused() {
gtk_window_present(GTK_WINDOW(widget)); gtk_window_present(GTK_WINDOW(widget));
} }
@ -118,20 +112,21 @@ void pWindow::setFullScreen(bool fullScreen) {
for(unsigned n = 0; n < 4; n++) { for(unsigned n = 0; n < 4; n++) {
setGeometry(window.state.geometry); setGeometry(window.state.geometry);
gtk_widget_set_size_request(widget, -1, -1); gtk_widget_set_size_request(widget, -1, -1);
OS::process(); OS::processEvents();
usleep(2000); usleep(2000);
} }
locked = false; locked = false;
} else { } else {
gtk_window_fullscreen(GTK_WINDOW(widget)); gtk_window_fullscreen(GTK_WINDOW(widget));
gtk_window_set_decorated(GTK_WINDOW(widget), false); gtk_window_set_decorated(GTK_WINDOW(widget), false);
gtk_widget_set_size_request(widget, OS::desktopWidth(), OS::desktopHeight()); gtk_widget_set_size_request(widget, OS::desktopGeometry().width, OS::desktopGeometry().height);
gtk_window_set_resizable(GTK_WINDOW(widget), false); gtk_window_set_resizable(GTK_WINDOW(widget), false);
} }
} }
void pWindow::setGeometry(const Geometry &geometry) { void pWindow::setGeometry(const Geometry &geometry) {
gtk_window_move(GTK_WINDOW(widget), geometry.x - settings.frameGeometryX, geometry.y - settings.frameGeometryY); Geometry margin = frameMargin();
gtk_window_move(GTK_WINDOW(widget), geometry.x - margin.x, geometry.y - margin.y);
gtk_window_resize(GTK_WINDOW(widget), 1, 1); gtk_window_resize(GTK_WINDOW(widget), 1, 1);
gtk_widget_set_size_request(formContainer, geometry.width, geometry.height); gtk_widget_set_size_request(formContainer, geometry.width, geometry.height);
foreach(layout, window.state.layout) { foreach(layout, window.state.layout) {

View File

@ -1,42 +1,42 @@
void pAction::setEnabled(bool enabled) { void pAction::setEnabled(bool enabled) {
if(dynamic_cast<Menu*>(&action)) { if(dynamic_cast<Menu*>(&action)) {
((Menu&)action).p.qtMenu->setEnabled(enabled); ((Menu&)action).p.qtMenu->setEnabled(enabled);
} else if(dynamic_cast<MenuSeparator*>(&action)) { } else if(dynamic_cast<Separator*>(&action)) {
((MenuSeparator&)action).p.qtAction->setEnabled(enabled); ((Separator&)action).p.qtAction->setEnabled(enabled);
} else if(dynamic_cast<MenuItem*>(&action)) { } else if(dynamic_cast<Item*>(&action)) {
((MenuItem&)action).p.qtAction->setEnabled(enabled); ((Item&)action).p.qtAction->setEnabled(enabled);
} else if(dynamic_cast<MenuCheckItem*>(&action)) { } else if(dynamic_cast<CheckItem*>(&action)) {
((MenuCheckItem&)action).p.qtAction->setEnabled(enabled); ((CheckItem&)action).p.qtAction->setEnabled(enabled);
} else if(dynamic_cast<MenuRadioItem*>(&action)) { } else if(dynamic_cast<RadioItem*>(&action)) {
((MenuRadioItem&)action).p.qtAction->setEnabled(enabled); ((RadioItem&)action).p.qtAction->setEnabled(enabled);
} }
} }
void pAction::setFont(Font &font) { void pAction::setFont(Font &font) {
if(dynamic_cast<Menu*>(&action)) { if(dynamic_cast<Menu*>(&action)) {
((Menu&)action).p.setFont(font); ((Menu&)action).p.setFont(font);
} else if(dynamic_cast<MenuSeparator*>(&action)) { } else if(dynamic_cast<Separator*>(&action)) {
((MenuSeparator&)action).p.qtAction->setFont(*font.p.qtFont); ((Separator&)action).p.qtAction->setFont(*font.p.qtFont);
} else if(dynamic_cast<MenuItem*>(&action)) { } else if(dynamic_cast<Item*>(&action)) {
((MenuItem&)action).p.qtAction->setFont(*font.p.qtFont); ((Item&)action).p.qtAction->setFont(*font.p.qtFont);
} else if(dynamic_cast<MenuCheckItem*>(&action)) { } else if(dynamic_cast<CheckItem*>(&action)) {
((MenuCheckItem&)action).p.qtAction->setFont(*font.p.qtFont); ((CheckItem&)action).p.qtAction->setFont(*font.p.qtFont);
} else if(dynamic_cast<MenuRadioItem*>(&action)) { } else if(dynamic_cast<RadioItem*>(&action)) {
((MenuRadioItem&)action).p.qtAction->setFont(*font.p.qtFont); ((RadioItem&)action).p.qtAction->setFont(*font.p.qtFont);
} }
} }
void pAction::setVisible(bool visible) { void pAction::setVisible(bool visible) {
if(dynamic_cast<Menu*>(&action)) { if(dynamic_cast<Menu*>(&action)) {
((Menu&)action).p.qtMenu->setVisible(visible); ((Menu&)action).p.qtMenu->setVisible(visible);
} else if(dynamic_cast<MenuSeparator*>(&action)) { } else if(dynamic_cast<Separator*>(&action)) {
((MenuSeparator&)action).p.qtAction->setVisible(visible); ((Separator&)action).p.qtAction->setVisible(visible);
} else if(dynamic_cast<MenuItem*>(&action)) { } else if(dynamic_cast<Item*>(&action)) {
((MenuItem&)action).p.qtAction->setVisible(visible); ((Item&)action).p.qtAction->setVisible(visible);
} else if(dynamic_cast<MenuCheckItem*>(&action)) { } else if(dynamic_cast<CheckItem*>(&action)) {
((MenuCheckItem&)action).p.qtAction->setVisible(visible); ((CheckItem&)action).p.qtAction->setVisible(visible);
} else if(dynamic_cast<MenuRadioItem*>(&action)) { } else if(dynamic_cast<RadioItem*>(&action)) {
((MenuRadioItem&)action).p.qtAction->setVisible(visible); ((RadioItem&)action).p.qtAction->setVisible(visible);
} }
} }

View File

@ -0,0 +1,22 @@
bool pCheckItem::checked() {
return qtAction->isChecked();
}
void pCheckItem::setChecked(bool checked) {
qtAction->setChecked(checked);
}
void pCheckItem::setText(const string &text) {
qtAction->setText(QString::fromUtf8(text));
}
void pCheckItem::constructor() {
qtAction = new QAction(0);
qtAction->setCheckable(true);
connect(qtAction, SIGNAL(triggered()), SLOT(onTick()));
}
void pCheckItem::onTick() {
checkItem.state.checked = checked();
if(checkItem.onTick) checkItem.onTick();
}

View File

@ -0,0 +1,12 @@
void pItem::setText(const string &text) {
qtAction->setText(QString::fromUtf8(text));
}
void pItem::constructor() {
qtAction = new QAction(0);
connect(qtAction, SIGNAL(triggered()), SLOT(onTick()));
}
void pItem::onTick() {
if(item.onTick) item.onTick();
}

View File

@ -1,22 +0,0 @@
bool pMenuCheckItem::checked() {
return qtAction->isChecked();
}
void pMenuCheckItem::setChecked(bool checked) {
qtAction->setChecked(checked);
}
void pMenuCheckItem::setText(const string &text) {
qtAction->setText(QString::fromUtf8(text));
}
void pMenuCheckItem::constructor() {
qtAction = new QAction(0);
qtAction->setCheckable(true);
connect(qtAction, SIGNAL(triggered()), SLOT(onTick()));
}
void pMenuCheckItem::onTick() {
menuCheckItem.state.checked = checked();
if(menuCheckItem.onTick) menuCheckItem.onTick();
}

View File

@ -1,12 +0,0 @@
void pMenuItem::setText(const string &text) {
qtAction->setText(QString::fromUtf8(text));
}
void pMenuItem::constructor() {
qtAction = new QAction(0);
connect(qtAction, SIGNAL(triggered()), SLOT(onTick()));
}
void pMenuItem::onTick() {
if(menuItem.onTick) menuItem.onTick();
}

View File

@ -1,14 +1,14 @@
void pMenu::append(Action &action) { void pMenu::append(Action &action) {
if(dynamic_cast<Menu*>(&action)) { if(dynamic_cast<Menu*>(&action)) {
qtMenu->addMenu(((Menu&)action).p.qtMenu); qtMenu->addMenu(((Menu&)action).p.qtMenu);
} else if(dynamic_cast<MenuSeparator*>(&action)) { } else if(dynamic_cast<Separator*>(&action)) {
qtMenu->addAction(((MenuSeparator&)action).p.qtAction); qtMenu->addAction(((Separator&)action).p.qtAction);
} else if(dynamic_cast<MenuItem*>(&action)) { } else if(dynamic_cast<Item*>(&action)) {
qtMenu->addAction(((MenuItem&)action).p.qtAction); qtMenu->addAction(((Item&)action).p.qtAction);
} else if(dynamic_cast<MenuCheckItem*>(&action)) { } else if(dynamic_cast<CheckItem*>(&action)) {
qtMenu->addAction(((MenuCheckItem&)action).p.qtAction); qtMenu->addAction(((CheckItem&)action).p.qtAction);
} else if(dynamic_cast<MenuRadioItem*>(&action)) { } else if(dynamic_cast<RadioItem*>(&action)) {
qtMenu->addAction(((MenuRadioItem&)action).p.qtAction); qtMenu->addAction(((RadioItem&)action).p.qtAction);
} }
} }

View File

@ -1,10 +1,10 @@
bool pMenuRadioItem::checked() { bool pRadioItem::checked() {
return qtAction->isChecked(); return qtAction->isChecked();
} }
void pMenuRadioItem::setChecked() { void pRadioItem::setChecked() {
locked = true; locked = true;
foreach(item, menuRadioItem.state.group) { foreach(item, radioItem.state.group) {
bool checkState = item.p.qtAction == qtAction; bool checkState = item.p.qtAction == qtAction;
item.state.checked = checkState; item.state.checked = checkState;
item.p.qtAction->setChecked(checkState); item.p.qtAction->setChecked(checkState);
@ -12,14 +12,14 @@ void pMenuRadioItem::setChecked() {
locked = false; locked = false;
} }
void pMenuRadioItem::setGroup(const reference_array<MenuRadioItem&> &group) { void pRadioItem::setGroup(const reference_array<RadioItem&> &group) {
} }
void pMenuRadioItem::setText(const string &text) { void pRadioItem::setText(const string &text) {
qtAction->setText(QString::fromUtf8(text)); qtAction->setText(QString::fromUtf8(text));
} }
void pMenuRadioItem::constructor() { void pRadioItem::constructor() {
qtAction = new QAction(0); qtAction = new QAction(0);
qtGroup = new QActionGroup(0); qtGroup = new QActionGroup(0);
qtAction->setCheckable(true); qtAction->setCheckable(true);
@ -28,9 +28,9 @@ void pMenuRadioItem::constructor() {
connect(qtAction, SIGNAL(triggered()), SLOT(onTick())); connect(qtAction, SIGNAL(triggered()), SLOT(onTick()));
} }
void pMenuRadioItem::onTick() { void pRadioItem::onTick() {
if(menuRadioItem.state.checked == false) { if(radioItem.state.checked == false) {
setChecked(); setChecked();
if(locked == false && menuRadioItem.onTick) menuRadioItem.onTick(); if(locked == false && radioItem.onTick) radioItem.onTick();
} }
} }

View File

@ -1,4 +1,4 @@
void pMenuSeparator::constructor() { void pSeparator::constructor() {
qtAction = new QAction(0); qtAction = new QAction(0);
qtAction->setSeparator(true); qtAction->setSeparator(true);
} }

View File

@ -8,10 +8,10 @@
#include "action/action.cpp" #include "action/action.cpp"
#include "action/menu.cpp" #include "action/menu.cpp"
#include "action/menu-separator.cpp" #include "action/separator.cpp"
#include "action/menu-item.cpp" #include "action/item.cpp"
#include "action/menu-check-item.cpp" #include "action/check-item.cpp"
#include "action/menu-radio-item.cpp" #include "action/radio-item.cpp"
#include "widget/widget.cpp" #include "widget/widget.cpp"
#include "widget/button.cpp" #include "widget/button.cpp"
@ -30,12 +30,14 @@
QApplication *pOS::application = 0; QApplication *pOS::application = 0;
unsigned pOS::desktopWidth() { Geometry pOS::availableGeometry() {
return QApplication::desktop()->screenGeometry().width(); QRect rect = QApplication::desktop()->availableGeometry();
return { rect.x(), rect.y(), rect.width(), rect.height() };
} }
unsigned pOS::desktopHeight() { Geometry pOS::desktopGeometry() {
return QApplication::desktop()->screenGeometry().height(); QRect rect = QApplication::desktop()->screenGeometry();
return { 0, 0, rect.width(), rect.height() };
} }
string pOS::fileLoad(Window &parent, const string &path, const lstring &filter) { string pOS::fileLoad(Window &parent, const string &path, const lstring &filter) {
@ -100,12 +102,12 @@ void pOS::main() {
QApplication::exec(); QApplication::exec();
} }
bool pOS::pending() { bool pOS::pendingEvents() {
return QApplication::hasPendingEvents(); return QApplication::hasPendingEvents();
} }
void pOS::process() { void pOS::processEvents() {
while(pending()) QApplication::processEvents(); while(pendingEvents()) QApplication::processEvents();
} }
void pOS::quit() { void pOS::quit() {

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
** Meta object code from reading C++ file 'qt.moc.hpp' ** Meta object code from reading C++ file 'qt.moc.hpp'
** **
** Created: Tue Feb 22 04:37:04 2011 ** Created: Thu Feb 24 07:36:07 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.6.2) ** by: The Qt Meta Object Compiler version 62 (Qt 4.6.2)
** **
** WARNING! All changes made in this file will be lost! ** WARNING! All changes made in this file will be lost!
@ -67,7 +67,7 @@ int pWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
return _id; return _id;
return _id; return _id;
} }
static const uint qt_meta_data_pMenuItem[] = { static const uint qt_meta_data_pItem[] = {
// content: // content:
4, // revision 4, // revision
@ -81,40 +81,40 @@ static const uint qt_meta_data_pMenuItem[] = {
0, // signalCount 0, // signalCount
// slots: signature, parameters, type, tag, flags // slots: signature, parameters, type, tag, flags
11, 10, 10, 10, 0x0a, 7, 6, 6, 6, 0x0a,
0 // eod 0 // eod
}; };
static const char qt_meta_stringdata_pMenuItem[] = { static const char qt_meta_stringdata_pItem[] = {
"pMenuItem\0\0onTick()\0" "pItem\0\0onTick()\0"
}; };
const QMetaObject pMenuItem::staticMetaObject = { const QMetaObject pItem::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_pMenuItem, { &QObject::staticMetaObject, qt_meta_stringdata_pItem,
qt_meta_data_pMenuItem, 0 } qt_meta_data_pItem, 0 }
}; };
#ifdef Q_NO_DATA_RELOCATION #ifdef Q_NO_DATA_RELOCATION
const QMetaObject &pMenuItem::getStaticMetaObject() { return staticMetaObject; } const QMetaObject &pItem::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION #endif //Q_NO_DATA_RELOCATION
const QMetaObject *pMenuItem::metaObject() const const QMetaObject *pItem::metaObject() const
{ {
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
} }
void *pMenuItem::qt_metacast(const char *_clname) void *pItem::qt_metacast(const char *_clname)
{ {
if (!_clname) return 0; if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_pMenuItem)) if (!strcmp(_clname, qt_meta_stringdata_pItem))
return static_cast<void*>(const_cast< pMenuItem*>(this)); return static_cast<void*>(const_cast< pItem*>(this));
if (!strcmp(_clname, "pAction")) if (!strcmp(_clname, "pAction"))
return static_cast< pAction*>(const_cast< pMenuItem*>(this)); return static_cast< pAction*>(const_cast< pItem*>(this));
return QObject::qt_metacast(_clname); return QObject::qt_metacast(_clname);
} }
int pMenuItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) int pItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{ {
_id = QObject::qt_metacall(_c, _id, _a); _id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0) if (_id < 0)
@ -128,7 +128,7 @@ int pMenuItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
} }
return _id; return _id;
} }
static const uint qt_meta_data_pMenuCheckItem[] = { static const uint qt_meta_data_pCheckItem[] = {
// content: // content:
4, // revision 4, // revision
@ -142,40 +142,40 @@ static const uint qt_meta_data_pMenuCheckItem[] = {
0, // signalCount 0, // signalCount
// slots: signature, parameters, type, tag, flags // slots: signature, parameters, type, tag, flags
16, 15, 15, 15, 0x0a, 12, 11, 11, 11, 0x0a,
0 // eod 0 // eod
}; };
static const char qt_meta_stringdata_pMenuCheckItem[] = { static const char qt_meta_stringdata_pCheckItem[] = {
"pMenuCheckItem\0\0onTick()\0" "pCheckItem\0\0onTick()\0"
}; };
const QMetaObject pMenuCheckItem::staticMetaObject = { const QMetaObject pCheckItem::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_pMenuCheckItem, { &QObject::staticMetaObject, qt_meta_stringdata_pCheckItem,
qt_meta_data_pMenuCheckItem, 0 } qt_meta_data_pCheckItem, 0 }
}; };
#ifdef Q_NO_DATA_RELOCATION #ifdef Q_NO_DATA_RELOCATION
const QMetaObject &pMenuCheckItem::getStaticMetaObject() { return staticMetaObject; } const QMetaObject &pCheckItem::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION #endif //Q_NO_DATA_RELOCATION
const QMetaObject *pMenuCheckItem::metaObject() const const QMetaObject *pCheckItem::metaObject() const
{ {
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
} }
void *pMenuCheckItem::qt_metacast(const char *_clname) void *pCheckItem::qt_metacast(const char *_clname)
{ {
if (!_clname) return 0; if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_pMenuCheckItem)) if (!strcmp(_clname, qt_meta_stringdata_pCheckItem))
return static_cast<void*>(const_cast< pMenuCheckItem*>(this)); return static_cast<void*>(const_cast< pCheckItem*>(this));
if (!strcmp(_clname, "pAction")) if (!strcmp(_clname, "pAction"))
return static_cast< pAction*>(const_cast< pMenuCheckItem*>(this)); return static_cast< pAction*>(const_cast< pCheckItem*>(this));
return QObject::qt_metacast(_clname); return QObject::qt_metacast(_clname);
} }
int pMenuCheckItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) int pCheckItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{ {
_id = QObject::qt_metacall(_c, _id, _a); _id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0) if (_id < 0)
@ -189,7 +189,7 @@ int pMenuCheckItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
} }
return _id; return _id;
} }
static const uint qt_meta_data_pMenuRadioItem[] = { static const uint qt_meta_data_pRadioItem[] = {
// content: // content:
4, // revision 4, // revision
@ -203,40 +203,40 @@ static const uint qt_meta_data_pMenuRadioItem[] = {
0, // signalCount 0, // signalCount
// slots: signature, parameters, type, tag, flags // slots: signature, parameters, type, tag, flags
16, 15, 15, 15, 0x0a, 12, 11, 11, 11, 0x0a,
0 // eod 0 // eod
}; };
static const char qt_meta_stringdata_pMenuRadioItem[] = { static const char qt_meta_stringdata_pRadioItem[] = {
"pMenuRadioItem\0\0onTick()\0" "pRadioItem\0\0onTick()\0"
}; };
const QMetaObject pMenuRadioItem::staticMetaObject = { const QMetaObject pRadioItem::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_pMenuRadioItem, { &QObject::staticMetaObject, qt_meta_stringdata_pRadioItem,
qt_meta_data_pMenuRadioItem, 0 } qt_meta_data_pRadioItem, 0 }
}; };
#ifdef Q_NO_DATA_RELOCATION #ifdef Q_NO_DATA_RELOCATION
const QMetaObject &pMenuRadioItem::getStaticMetaObject() { return staticMetaObject; } const QMetaObject &pRadioItem::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION #endif //Q_NO_DATA_RELOCATION
const QMetaObject *pMenuRadioItem::metaObject() const const QMetaObject *pRadioItem::metaObject() const
{ {
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
} }
void *pMenuRadioItem::qt_metacast(const char *_clname) void *pRadioItem::qt_metacast(const char *_clname)
{ {
if (!_clname) return 0; if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_pMenuRadioItem)) if (!strcmp(_clname, qt_meta_stringdata_pRadioItem))
return static_cast<void*>(const_cast< pMenuRadioItem*>(this)); return static_cast<void*>(const_cast< pRadioItem*>(this));
if (!strcmp(_clname, "pAction")) if (!strcmp(_clname, "pAction"))
return static_cast< pAction*>(const_cast< pMenuRadioItem*>(this)); return static_cast< pAction*>(const_cast< pRadioItem*>(this));
return QObject::qt_metacast(_clname); return QObject::qt_metacast(_clname);
} }
int pMenuRadioItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) int pRadioItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{ {
_id = QObject::qt_metacall(_c, _id, _a); _id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0) if (_id < 0)

View File

@ -26,14 +26,14 @@ struct pObject {
struct pOS : public pObject { struct pOS : public pObject {
static QApplication *application; static QApplication *application;
static unsigned desktopWidth(); static Geometry availableGeometry();
static unsigned desktopHeight(); static Geometry desktopGeometry();
static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileLoad(Window &parent, const string &path, const lstring &filter);
static string fileSave(Window &parent, const string &path, const lstring &filter); static string fileSave(Window &parent, const string &path, const lstring &filter);
static string folderSelect(Window &parent, const string &path); static string folderSelect(Window &parent, const string &path);
static void main(); static void main();
static bool pending(); static bool pendingEvents();
static void process(); static void processEvents();
static void quit(); static void quit();
static void initialize(); static void initialize();
@ -82,11 +82,10 @@ public:
void append(Layout &layout); void append(Layout &layout);
void append(Menu &menu); void append(Menu &menu);
void append(Widget &widget); void append(Widget &widget);
Geometry frameGeometry(); Geometry frameMargin();
bool focused(); bool focused();
Geometry geometry(); Geometry geometry();
void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue);
void setFrameGeometry(const Geometry &geometry);
void setFocused(); void setFocused();
void setFullScreen(bool fullScreen); void setFullScreen(bool fullScreen);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
@ -128,62 +127,62 @@ struct pMenu : public pAction {
void constructor(); void constructor();
}; };
struct pMenuSeparator : public pAction { struct pSeparator : public pAction {
MenuSeparator &menuSeparator; Separator &separator;
QAction *qtAction; QAction *qtAction;
pMenuSeparator(MenuSeparator &menuSeparator) : pAction(menuSeparator), menuSeparator(menuSeparator) {} pSeparator(Separator &separator) : pAction(separator), separator(separator) {}
void constructor(); void constructor();
}; };
struct pMenuItem : public QObject, public pAction { struct pItem : public QObject, public pAction {
Q_OBJECT Q_OBJECT
public: public:
MenuItem &menuItem; Item &item;
QAction *qtAction; QAction *qtAction;
void setText(const string &text); void setText(const string &text);
pMenuItem(MenuItem &menuItem) : pAction(menuItem), menuItem(menuItem) {} pItem(Item &item) : pAction(item), item(item) {}
void constructor(); void constructor();
public slots: public slots:
void onTick(); void onTick();
}; };
struct pMenuCheckItem : public QObject, public pAction { struct pCheckItem : public QObject, public pAction {
Q_OBJECT Q_OBJECT
public: public:
MenuCheckItem &menuCheckItem; CheckItem &checkItem;
QAction *qtAction; QAction *qtAction;
bool checked(); bool checked();
void setChecked(bool checked); void setChecked(bool checked);
void setText(const string &text); void setText(const string &text);
pMenuCheckItem(MenuCheckItem &menuCheckItem) : pAction(menuCheckItem), menuCheckItem(menuCheckItem) {} pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {}
void constructor(); void constructor();
public slots: public slots:
void onTick(); void onTick();
}; };
struct pMenuRadioItem : public QObject, public pAction { struct pRadioItem : public QObject, public pAction {
Q_OBJECT Q_OBJECT
public: public:
MenuRadioItem &menuRadioItem; RadioItem &radioItem;
QAction *qtAction; QAction *qtAction;
QActionGroup *qtGroup; QActionGroup *qtGroup;
bool checked(); bool checked();
void setChecked(); void setChecked();
void setGroup(const reference_array<MenuRadioItem&> &group); void setGroup(const reference_array<RadioItem&> &group);
void setText(const string &text); void setText(const string &text);
pMenuRadioItem(MenuRadioItem &menuRadioItem) : pAction(menuRadioItem), menuRadioItem(menuRadioItem) {} pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
void constructor(); void constructor();
public slots: public slots:
@ -194,7 +193,6 @@ struct pWidget : public pObject {
Widget &widget; Widget &widget;
QWidget *qtWidget; QWidget *qtWidget;
bool enabled();
void setEnabled(bool enabled); void setEnabled(bool enabled);
void setFocused(); void setFocused();
void setFont(Font &font); void setFont(Font &font);
@ -341,16 +339,17 @@ public:
QTreeWidget *qtListView; QTreeWidget *qtListView;
void append(const lstring &text); void append(const lstring &text);
void autosizeColumns(); void autoSizeColumns();
bool checked(unsigned row); bool checked(unsigned row);
void modify(unsigned row, const lstring &text); void modify(unsigned row, const lstring &text);
void modify(unsigned row, unsigned column, const string &text);
void reset(); void reset();
optional<unsigned> selection(); bool selected();
unsigned selection();
void setCheckable(bool checkable); void setCheckable(bool checkable);
void setChecked(unsigned row, bool checked); void setChecked(unsigned row, bool checked);
void setHeaderText(const lstring &text); void setHeaderText(const lstring &text);
void setHeaderVisible(bool visible); void setHeaderVisible(bool visible);
void setSelected(bool selected);
void setSelection(unsigned row); void setSelection(unsigned row);
pListView(ListView &listView) : pWidget(listView), listView(listView) {} pListView(ListView &listView) : pWidget(listView), listView(listView) {}

View File

@ -10,7 +10,7 @@ void pListView::append(const lstring &text) {
locked = false; locked = false;
} }
void pListView::autosizeColumns() { void pListView::autoSizeColumns() {
for(unsigned n = 0; n < listView.state.headerText.size(); n++) qtListView->resizeColumnToContents(n); for(unsigned n = 0; n < listView.state.headerText.size(); n++) qtListView->resizeColumnToContents(n);
} }
@ -29,23 +29,19 @@ void pListView::modify(unsigned row, const lstring &text) {
locked = false; locked = false;
} }
void pListView::modify(unsigned row, unsigned column, const string &text) {
locked = true;
QTreeWidgetItem *item = qtListView->topLevelItem(row);
if(!item) return;
item->setText(column, QString::fromUtf8(text));
locked = false;
}
void pListView::reset() { void pListView::reset() {
qtListView->clear(); qtListView->clear();
} }
optional<unsigned> pListView::selection() { bool pListView::selected() {
QTreeWidgetItem *item = qtListView->currentItem(); QTreeWidgetItem *item = qtListView->currentItem();
if(item == 0) return { false, 0 }; return (item && item->isSelected() == true);
if(item->isSelected() == false) return { false, 0 }; }
return { true, item->data(0, Qt::UserRole).toUInt() };
unsigned pListView::selection() {
QTreeWidgetItem *item = qtListView->currentItem();
if(item == 0) return 0;
return item->data(0, Qt::UserRole).toUInt();
} }
void pListView::setCheckable(bool checkable) { void pListView::setCheckable(bool checkable) {
@ -69,12 +65,17 @@ void pListView::setHeaderText(const lstring &text) {
qtListView->setColumnCount(text.size()); qtListView->setColumnCount(text.size());
qtListView->setAlternatingRowColors(text.size() >= 2); qtListView->setAlternatingRowColors(text.size() >= 2);
qtListView->setHeaderLabels(labels); qtListView->setHeaderLabels(labels);
autosizeColumns(); autoSizeColumns();
} }
void pListView::setHeaderVisible(bool visible) { void pListView::setHeaderVisible(bool visible) {
qtListView->setHeaderHidden(!visible); qtListView->setHeaderHidden(!visible);
autosizeColumns(); autoSizeColumns();
}
void pListView::setSelected(bool selected) {
QTreeWidgetItem *item = qtListView->currentItem();
if(item) item->setSelected(selected);
} }
void pListView::setSelection(unsigned row) { void pListView::setSelection(unsigned row) {
@ -108,11 +109,8 @@ void pListView::onActivate() {
} }
void pListView::onChange() { void pListView::onChange() {
if(auto position = selection()) { listView.state.selected = selected();
listView.state.selection = { true, position() }; if(listView.state.selected) listView.state.selection = selection();
} else {
listView.state.selection = { false, 0 };
}
if(locked == false && listView.onChange) listView.onChange(); if(locked == false && listView.onChange) listView.onChange();
} }

View File

@ -1,7 +1,3 @@
bool pWidget::enabled() {
return qtWidget->isEnabled();
}
void pWidget::setEnabled(bool enabled) { void pWidget::setEnabled(bool enabled) {
qtWidget->setEnabled(enabled); qtWidget->setEnabled(enabled);
} }

View File

@ -18,13 +18,15 @@ void pWindow::append(Widget &widget) {
widget.setVisible(widget.state.visible); widget.setVisible(widget.state.visible);
} }
Geometry pWindow::frameGeometry() { Geometry pWindow::frameMargin() {
if(window.state.fullScreen) return { 0, 0, OS::desktopWidth(), OS::desktopHeight() }; unsigned menuHeight = window.state.menuVisible ? qtMenu->height() : 0;
unsigned statusHeight = window.state.statusVisible ? qtStatus->height() : 0;
if(window.state.fullScreen) return { 0, menuHeight, 0, menuHeight + statusHeight };
return { return {
window.state.geometry.x - settings.frameGeometryX, settings.frameGeometryX,
window.state.geometry.y - settings.frameGeometryY, settings.frameGeometryY + menuHeight,
window.state.geometry.width + settings.frameGeometryWidth, settings.frameGeometryWidth,
window.state.geometry.height + settings.frameGeometryHeight settings.frameGeometryHeight + menuHeight + statusHeight
}; };
} }
@ -36,8 +38,7 @@ Geometry pWindow::geometry() {
if(window.state.fullScreen) { if(window.state.fullScreen) {
unsigned menuHeight = window.state.menuVisible ? qtMenu->height() : 0; unsigned menuHeight = window.state.menuVisible ? qtMenu->height() : 0;
unsigned statusHeight = window.state.statusVisible ? qtStatus->height() : 0; unsigned statusHeight = window.state.statusVisible ? qtStatus->height() : 0;
unsigned width = OS::desktopWidth(), height = OS::desktopHeight(); return { 0, menuHeight, OS::desktopGeometry().width, OS::desktopGeometry().height - menuHeight - statusHeight };
return { 0, menuHeight, width, height - menuHeight - statusHeight };
} }
return window.state.geometry; return window.state.geometry;
} }
@ -49,18 +50,6 @@ void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) {
qtContainer->setAutoFillBackground(true); qtContainer->setAutoFillBackground(true);
} }
void pWindow::setFrameGeometry(const Geometry &geometry) {
window.state.geometry = {
geometry.x + settings.frameGeometryX,
geometry.y + settings.frameGeometryY,
geometry.width - settings.frameGeometryWidth,
geometry.height - settings.frameGeometryHeight
};
if(window.state.menuVisible) window.state.geometry.height -= qtMenu->height();
if(window.state.statusVisible) window.state.geometry.height -= qtStatus->height();
setGeometry(window.state.geometry);
}
void pWindow::setFocused() { void pWindow::setFocused() {
qtWindow->raise(); qtWindow->raise();
qtWindow->activateWindow(); qtWindow->activateWindow();
@ -72,19 +61,19 @@ void pWindow::setFullScreen(bool fullScreen) {
qtWindow->showNormal(); qtWindow->showNormal();
qtWindow->adjustSize(); qtWindow->adjustSize();
} else { } else {
Geometry geometry = OS::desktopGeometry(), margin = frameMargin();
qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint); qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint);
qtContainer->setFixedSize(OS::desktopWidth(), OS::desktopHeight()); qtContainer->setFixedSize(geometry.width - margin.width, geometry.height - margin.height);
qtWindow->showFullScreen(); qtWindow->showFullScreen();
if(window.state.statusVisible) setStatusVisible(true); //work around for Qt/Xlib bug
} }
} }
void pWindow::setGeometry(const Geometry &geometry_) { void pWindow::setGeometry(const Geometry &geometry_) {
locked = true; locked = true;
Geometry geometry = geometry_; Geometry geometry = geometry_, margin = frameMargin();
setResizable(window.state.resizable); setResizable(window.state.resizable);
qtWindow->move(geometry.x - settings.frameGeometryX, geometry.y - settings.frameGeometryY); qtWindow->move(geometry.x - margin.x, geometry.y - margin.y);
qtWindow->adjustSize(); qtWindow->adjustSize();
foreach(layout, window.state.layout) { foreach(layout, window.state.layout) {

View File

@ -0,0 +1,12 @@
bool pCheckItem::checked() {
return false;
}
void pCheckItem::setChecked(bool checked) {
}
void pCheckItem::setText(const string &text) {
}
void pCheckItem::constructor() {
}

View File

@ -0,0 +1,5 @@
void pItem::setText(const string &text) {
}
void pItem::constructor() {
}

View File

@ -1,12 +0,0 @@
bool pMenuCheckItem::checked() {
return false;
}
void pMenuCheckItem::setChecked(bool checked) {
}
void pMenuCheckItem::setText(const string &text) {
}
void pMenuCheckItem::constructor() {
}

View File

@ -1,5 +0,0 @@
void pMenuItem::setText(const string &text) {
}
void pMenuItem::constructor() {
}

View File

@ -1,15 +0,0 @@
bool pMenuRadioItem::checked() {
return false;
}
void pMenuRadioItem::setChecked() {
}
void pMenuRadioItem::setGroup(const reference_array<MenuRadioItem&> &group) {
}
void pMenuRadioItem::setText(const string &text) {
}
void pMenuRadioItem::constructor() {
}

View File

@ -1,2 +0,0 @@
void pMenuSeparator::constructor() {
}

View File

@ -0,0 +1,15 @@
bool pRadioItem::checked() {
return false;
}
void pRadioItem::setChecked() {
}
void pRadioItem::setGroup(const reference_array<RadioItem&> &group) {
}
void pRadioItem::setText(const string &text) {
}
void pRadioItem::constructor() {
}

View File

@ -0,0 +1,2 @@
void pSeparator::constructor() {
}

View File

@ -6,10 +6,10 @@
#include "action/action.cpp" #include "action/action.cpp"
#include "action/menu.cpp" #include "action/menu.cpp"
#include "action/menu-separator.cpp" #include "action/separator.cpp"
#include "action/menu-item.cpp" #include "action/item.cpp"
#include "action/menu-check-item.cpp" #include "action/check-item.cpp"
#include "action/menu-radio-item.cpp" #include "action/radio-item.cpp"
#include "widget/widget.cpp" #include "widget/widget.cpp"
#include "widget/button.cpp" #include "widget/button.cpp"
@ -26,12 +26,12 @@
#include "widget/vertical-slider.cpp" #include "widget/vertical-slider.cpp"
#include "widget/viewport.cpp" #include "widget/viewport.cpp"
unsigned pOS::desktopWidth() { Geometry pOS::availableGeometry() {
return 0; return { 0, 0, 0, 0 };
} }
unsigned pOS::desktopHeight() { Geometry pOS::desktopGeometry() {
return 0; return { 0, 0, 0, 0 };
} }
string pOS::fileLoad(Window &parent, const string &path, const lstring &filter) { string pOS::fileLoad(Window &parent, const string &path, const lstring &filter) {
@ -49,11 +49,11 @@ string pOS::folderSelect(Window &parent, const string &path) {
void pOS::main() { void pOS::main() {
} }
bool pOS::pending() { bool pOS::pendingEvents() {
return false; return false;
} }
void pOS::process() { void pOS::processEvents() {
} }
void pOS::quit() { void pOS::quit() {

View File

@ -13,14 +13,14 @@ struct pObject {
}; };
struct pOS : public pObject { struct pOS : public pObject {
static unsigned desktopWidth(); static Geometry availableGeometry();
static unsigned desktopHeight(); static Geometry desktopGeometry();
static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileLoad(Window &parent, const string &path, const lstring &filter);
static string fileSave(Window &parent, const string &path, const lstring &filter); static string fileSave(Window &parent, const string &path, const lstring &filter);
static string folderSelect(Window &parent, const string &path); static string folderSelect(Window &parent, const string &path);
static void main(); static void main();
static bool pending(); static bool pendingEvents();
static void process(); static void processEvents();
static void quit(); static void quit();
static void initialize(); static void initialize();
@ -52,11 +52,10 @@ struct pWindow : public pObject {
void append(Layout &layout); void append(Layout &layout);
void append(Menu &menu); void append(Menu &menu);
void append(Widget &widget); void append(Widget &widget);
Geometry frameGeometry();
bool focused(); bool focused();
Geometry frameMargin();
Geometry geometry(); Geometry geometry();
void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue);
void setFrameGeometry(const Geometry &geometry);
void setFocused(); void setFocused();
void setFullScreen(bool fullScreen); void setFullScreen(bool fullScreen);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
@ -94,42 +93,42 @@ struct pMenu : public pAction {
void constructor(); void constructor();
}; };
struct pMenuSeparator : public pAction { struct pSeparator : public pAction {
MenuSeparator &menuSeparator; Separator &separator;
pMenuSeparator(MenuSeparator &menuSeparator) : pAction(menuSeparator), menuSeparator(menuSeparator) {} pSeparator(Separator &separator) : pAction(separator), separator(separator) {}
void constructor(); void constructor();
}; };
struct pMenuItem : public pAction { struct pItem : public pAction {
MenuItem &menuItem; Item &item;
void setText(const string &text); void setText(const string &text);
pMenuItem(MenuItem &menuItem) : pAction(menuItem), menuItem(menuItem) {} pItem(Item &item) : pAction(item), item(item) {}
void constructor(); void constructor();
}; };
struct pMenuCheckItem : public pAction { struct pCheckItem : public pAction {
MenuCheckItem &menuCheckItem; CheckItem &checkItem;
bool checked(); bool checked();
void setChecked(bool checked); void setChecked(bool checked);
void setText(const string &text); void setText(const string &text);
pMenuCheckItem(MenuCheckItem &menuCheckItem) : pAction(menuCheckItem), menuCheckItem(menuCheckItem) {} pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {}
void constructor(); void constructor();
}; };
struct pMenuRadioItem : public pAction { struct pRadioItem : public pAction {
MenuRadioItem &menuRadioItem; RadioItem &radioItem;
bool checked(); bool checked();
void setChecked(); void setChecked();
void setGroup(const reference_array<MenuRadioItem&> &group); void setGroup(const reference_array<RadioItem&> &group);
void setText(const string &text); void setText(const string &text);
pMenuRadioItem(MenuRadioItem &menuRadioItem) : pAction(menuRadioItem), menuRadioItem(menuRadioItem) {} pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
void constructor(); void constructor();
}; };
@ -227,16 +226,17 @@ struct pListView : public pWidget {
ListView &listView; ListView &listView;
void append(const lstring &text); void append(const lstring &text);
void autosizeColumns(); void autoSizeColumns();
bool checked(unsigned row); bool checked(unsigned row);
void modify(unsigned row, const lstring &text); void modify(unsigned row, const lstring &text);
void modify(unsigned row, unsigned column, const string &text);
void reset(); void reset();
optional<unsigned> selection(); bool selected();
unsigned selection();
void setCheckable(bool checkable); void setCheckable(bool checkable);
void setChecked(unsigned row, bool checked); void setChecked(unsigned row, bool checked);
void setHeaderText(const lstring &text); void setHeaderText(const lstring &text);
void setHeaderVisible(bool visible); void setHeaderVisible(bool visible);
void setSelected(bool selected);
void setSelection(unsigned row); void setSelection(unsigned row);
pListView(ListView &listView) : pWidget(listView), listView(listView) {} pListView(ListView &listView) : pWidget(listView), listView(listView) {}

View File

@ -1,7 +1,7 @@
void pListView::append(const lstring &text) { void pListView::append(const lstring &text) {
} }
void pListView::autosizeColumns() { void pListView::autoSizeColumns() {
} }
bool pListView::checked(unsigned row) { bool pListView::checked(unsigned row) {
@ -10,14 +10,15 @@ bool pListView::checked(unsigned row) {
void pListView::modify(unsigned row, const lstring &text) { void pListView::modify(unsigned row, const lstring &text) {
} }
void pListView::modify(unsigned row, unsigned column, const string &text) {
}
void pListView::reset() { void pListView::reset() {
} }
optional<unsigned> pListView::selection() { bool pListView::selected() {
return { false, 0 }; return false;
}
unsigned pListView::selection() {
return 0;
} }
void pListView::setCheckable(bool checkable) { void pListView::setCheckable(bool checkable) {
@ -32,6 +33,9 @@ void pListView::setHeaderText(const lstring &text) {
void pListView::setHeaderVisible(bool visible) { void pListView::setHeaderVisible(bool visible) {
} }
void pListView::setSelected(bool selected) {
}
void pListView::setSelection(unsigned row) { void pListView::setSelection(unsigned row) {
} }

View File

@ -7,14 +7,14 @@ void pWindow::append(Menu &menu) {
void pWindow::append(Widget &widget) { void pWindow::append(Widget &widget) {
} }
Geometry pWindow::frameGeometry() {
return { 0, 0, 0, 0 };
}
bool pWindow::focused() { bool pWindow::focused() {
return false; return false;
} }
Geometry pWindow::frameMargin() {
return { 0, 0, 0, 0 };
}
Geometry pWindow::geometry() { Geometry pWindow::geometry() {
return { 0, 0, 0, 0 }; return { 0, 0, 0, 0 };
} }
@ -22,9 +22,6 @@ Geometry pWindow::geometry() {
void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) {
} }
void pWindow::setFrameGeometry(const Geometry &geometry) {
}
void pWindow::setFocused() { void pWindow::setFocused() {
} }

View File

@ -0,0 +1,14 @@
bool pCheckItem::checked() {
return checkItem.state.checked;
}
void pCheckItem::setChecked(bool checked) {
if(parentMenu) CheckMenuItem(parentMenu, id, checked ? MF_CHECKED : MF_UNCHECKED);
}
void pCheckItem::setText(const string &text) {
if(parentWindow) parentWindow->p.updateMenu();
}
void pCheckItem::constructor() {
}

View File

@ -0,0 +1,6 @@
void pItem::setText(const string &text) {
if(parentWindow) parentWindow->p.updateMenu();
}
void pItem::constructor() {
}

View File

@ -1,14 +0,0 @@
bool pMenuCheckItem::checked() {
return menuCheckItem.state.checked;
}
void pMenuCheckItem::setChecked(bool checked) {
if(parentMenu) CheckMenuItem(parentMenu, id, checked ? MF_CHECKED : MF_UNCHECKED);
}
void pMenuCheckItem::setText(const string &text) {
if(parentWindow) parentWindow->p.updateMenu();
}
void pMenuCheckItem::constructor() {
}

View File

@ -1,6 +0,0 @@
void pMenuItem::setText(const string &text) {
if(parentWindow) parentWindow->p.updateMenu();
}
void pMenuItem::constructor() {
}

View File

@ -1,2 +0,0 @@
void pMenuSeparator::constructor() {
}

View File

@ -27,18 +27,18 @@ void pMenu::update(Window &parentWindow, HMENU parentMenu) {
Menu &item = (Menu&)action; Menu &item = (Menu&)action;
item.p.update(parentWindow, hmenu); item.p.update(parentWindow, hmenu);
AppendMenu(hmenu, MF_STRING | MF_POPUP | enabled, (UINT_PTR)item.p.hmenu, utf16_t(item.state.text)); AppendMenu(hmenu, MF_STRING | MF_POPUP | enabled, (UINT_PTR)item.p.hmenu, utf16_t(item.state.text));
} else if(dynamic_cast<MenuSeparator*>(&action)) { } else if(dynamic_cast<Separator*>(&action)) {
MenuSeparator &item = (MenuSeparator&)action; Separator &item = (Separator&)action;
if(action.state.visible) AppendMenu(hmenu, MF_SEPARATOR | enabled, item.p.id, L""); if(action.state.visible) AppendMenu(hmenu, MF_SEPARATOR | enabled, item.p.id, L"");
} else if(dynamic_cast<MenuItem*>(&action)) { } else if(dynamic_cast<Item*>(&action)) {
MenuItem &item = (MenuItem&)action; Item &item = (Item&)action;
if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text));
} else if(dynamic_cast<MenuCheckItem*>(&action)) { } else if(dynamic_cast<CheckItem*>(&action)) {
MenuCheckItem &item = (MenuCheckItem&)action; CheckItem &item = (CheckItem&)action;
if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text));
if(item.state.checked) item.setChecked(); if(item.state.checked) item.setChecked();
} else if(dynamic_cast<MenuRadioItem*>(&action)) { } else if(dynamic_cast<RadioItem*>(&action)) {
MenuRadioItem &item = (MenuRadioItem&)action; RadioItem &item = (RadioItem&)action;
if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text)); if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text));
if(item.state.checked) item.setChecked(); if(item.state.checked) item.setChecked();
} }

View File

@ -1,9 +1,9 @@
bool pMenuRadioItem::checked() { bool pRadioItem::checked() {
return menuRadioItem.state.checked; return radioItem.state.checked;
} }
void pMenuRadioItem::setChecked() { void pRadioItem::setChecked() {
foreach(item, menuRadioItem.state.group) { foreach(item, radioItem.state.group) {
//CheckMenuRadioItem takes: lo, hi, id; checking only id when lo <= id <= hi //CheckMenuRadioItem takes: lo, hi, id; checking only id when lo <= id <= hi
//phoenix does not force IDs to be linear, so to uncheck id, we use: lo == hi == id + 1 (out of range) //phoenix does not force IDs to be linear, so to uncheck id, we use: lo == hi == id + 1 (out of range)
//to check id, we use: lo == hi == id (only ID, but in range) //to check id, we use: lo == hi == id (only ID, but in range)
@ -11,12 +11,12 @@ void pMenuRadioItem::setChecked() {
} }
} }
void pMenuRadioItem::setGroup(const reference_array<MenuRadioItem&> &group) { void pRadioItem::setGroup(const reference_array<RadioItem&> &group) {
} }
void pMenuRadioItem::setText(const string &text) { void pRadioItem::setText(const string &text) {
if(parentWindow) parentWindow->p.updateMenu(); if(parentWindow) parentWindow->p.updateMenu();
} }
void pMenuRadioItem::constructor() { void pRadioItem::constructor() {
} }

View File

@ -0,0 +1,2 @@
void pSeparator::constructor() {
}

View File

@ -20,11 +20,11 @@ void pComboBox::constructor() {
} }
void pComboBox::setGeometry(const Geometry &geometry) { void pComboBox::setGeometry(const Geometry &geometry) {
SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 200, SWP_NOZORDER); SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 1, SWP_NOZORDER);
RECT rc; //RECT rc;
GetWindowRect(hwnd, &rc); //GetWindowRect(hwnd, &rc);
unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0)); //unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0));
SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight); //SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight);
} }
void pComboBox::setParent(Window &parent) { void pComboBox::setParent(Window &parent) {

View File

@ -20,6 +20,11 @@ static LRESULT CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPA
Label *label = (Label*)GetWindowLongPtr(hwnd, GWLP_USERDATA); Label *label = (Label*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
if(!window || !label) return DefWindowProc(hwnd, msg, wparam, lparam); if(!window || !label) return DefWindowProc(hwnd, msg, wparam, lparam);
if(msg == WM_ERASEBKGND) {
//background is erased during WM_PAINT to prevent flickering
return TRUE;
}
if(msg == WM_PAINT) { if(msg == WM_PAINT) {
PAINTSTRUCT ps; PAINTSTRUCT ps;
RECT rc; RECT rc;

View File

@ -17,7 +17,7 @@ void pListView::append(const lstring &list) {
if(listView.state.headerText.size() <= 1) ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER); if(listView.state.headerText.size() <= 1) ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER);
} }
void pListView::autosizeColumns() { void pListView::autoSizeColumns() {
for(unsigned n = 0; n < listView.state.headerText.size(); n++) { for(unsigned n = 0; n < listView.state.headerText.size(); n++) {
ListView_SetColumnWidth(hwnd, n, LVSCW_AUTOSIZE_USEHEADER); ListView_SetColumnWidth(hwnd, n, LVSCW_AUTOSIZE_USEHEADER);
} }
@ -35,22 +35,24 @@ void pListView::modify(unsigned row, const lstring &list) {
if(listView.state.headerText.size() <= 1) ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER); if(listView.state.headerText.size() <= 1) ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER);
} }
void pListView::modify(unsigned row, unsigned column, const string &text) {
utf16_t wtext(text);
ListView_SetItemText(hwnd, row, column, wtext);
if(listView.state.headerText.size() <= 1) ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER);
}
void pListView::reset() { void pListView::reset() {
ListView_DeleteAllItems(hwnd); ListView_DeleteAllItems(hwnd);
} }
optional<unsigned> pListView::selection() { bool pListView::selected() {
unsigned count = ListView_GetItemCount(hwnd); unsigned count = ListView_GetItemCount(hwnd);
for(unsigned n = 0; n < count; n++) { for(unsigned n = 0; n < count; n++) {
if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return { true, n }; if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return true;
} }
return { false, 0 }; return false;
}
unsigned pListView::selection() {
unsigned count = ListView_GetItemCount(hwnd);
for(unsigned n = 0; n < count; n++) {
if(ListView_GetItemState(hwnd, n, LVIS_SELECTED)) return n;
}
return listView.state.selection;
} }
void pListView::setCheckable(bool checkable) { void pListView::setCheckable(bool checkable) {
@ -78,7 +80,7 @@ void pListView::setHeaderText(const lstring &list) {
column.pszText = headerText; column.pszText = headerText;
ListView_InsertColumn(hwnd, n, &column); ListView_InsertColumn(hwnd, n, &column);
} }
autosizeColumns(); autoSizeColumns();
} }
void pListView::setHeaderVisible(bool visible) { void pListView::setHeaderVisible(bool visible) {
@ -89,12 +91,20 @@ void pListView::setHeaderVisible(bool visible) {
); );
} }
void pListView::setSelection(unsigned row) { void pListView::setSelected(bool selected) {
unsigned count = ListView_GetItemCount(hwnd); locked = true;
for(unsigned n = 0; n < count; n++) { if(selected == false) {
ListView_SetItemState(hwnd, n, LVIS_FOCUSED, (n == row ? LVIS_FOCUSED : 0)); ListView_SetItemState(hwnd, -1, 0, LVIS_FOCUSED | LVIS_SELECTED);
ListView_SetItemState(hwnd, n, LVIS_SELECTED, (n == row ? LVIS_SELECTED : 0)); } else {
setSelection(listView.state.selection);
} }
locked = false;
}
void pListView::setSelection(unsigned row) {
locked = true;
ListView_SetItemState(hwnd, row, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
locked = false;
} }
void pListView::constructor() { void pListView::constructor() {
@ -104,7 +114,7 @@ void pListView::constructor() {
void pListView::setGeometry(const Geometry &geometry) { void pListView::setGeometry(const Geometry &geometry) {
pWidget::setGeometry(geometry); pWidget::setGeometry(geometry);
autosizeColumns(); autoSizeColumns();
} }
void pListView::setParent(Window &parent) { void pListView::setParent(Window &parent) {
@ -121,6 +131,6 @@ void pListView::setParent(Window &parent) {
setCheckable(listView.state.checkable); setCheckable(listView.state.checkable);
foreach(text, listView.state.text) append(text); foreach(text, listView.state.text) append(text);
foreach(checked, listView.state.checked, n) setChecked(n, checked); foreach(checked, listView.state.checked, n) setChecked(n, checked);
if(auto selection = listView.state.selection) setSelection(selection()); if(listView.state.selected) setSelection(listView.state.selection);
autosizeColumns(); autoSizeColumns();
} }

View File

@ -1,5 +1,5 @@
static const unsigned FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER; static const unsigned FixedStyle = WS_CLIPCHILDREN | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER;
static const unsigned ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME; static const unsigned ResizableStyle = WS_CLIPCHILDREN | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME;
void pWindow::append(Layout &layout) { void pWindow::append(Layout &layout) {
layout.setParent(window); layout.setParent(window);
@ -16,16 +16,24 @@ void pWindow::append(Widget &widget) {
widget.p.setParent(window); widget.p.setParent(window);
} }
Geometry pWindow::frameGeometry() {
RECT rc;
GetWindowRect(hwnd, &rc);
return { rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top };
}
bool pWindow::focused() { bool pWindow::focused() {
return (GetForegroundWindow() == hwnd); return (GetForegroundWindow() == hwnd);
} }
Geometry pWindow::frameMargin() {
unsigned style = window.state.resizable ? ResizableStyle : FixedStyle;
if(window.state.fullScreen) style = 0;
RECT rc = { 0, 0, 640, 480 };
AdjustWindowRect(&rc, style, window.state.menuVisible);
unsigned statusHeight = 0;
if(window.state.statusVisible) {
RECT src;
GetClientRect(hstatus, &src);
statusHeight = src.bottom - src.top;
}
return { abs(rc.left), abs(rc.top), (rc.right - rc.left) - 640, (rc.bottom - rc.top) + statusHeight - 480 };
}
Geometry pWindow::geometry() { Geometry pWindow::geometry() {
Geometry margin = frameMargin(); Geometry margin = frameMargin();
RECT rc; RECT rc;
@ -45,14 +53,6 @@ void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) {
brush = CreateSolidBrush(brushColor); brush = CreateSolidBrush(brushColor);
} }
void pWindow::setFrameGeometry(const Geometry &geometry) {
Geometry margin = frameMargin();
window.setGeometry({
geometry.x + margin.x, geometry.y + margin.y,
geometry.width - margin.width, geometry.height - margin.height
});
}
void pWindow::setFocused() { void pWindow::setFocused() {
if(window.state.visible == false) setVisible(true); if(window.state.visible == false) setVisible(true);
SetFocus(hwnd); SetFocus(hwnd);
@ -147,20 +147,6 @@ void pWindow::constructor() {
setGeometry({ 128, 128, 256, 256 }); setGeometry({ 128, 128, 256, 256 });
} }
Geometry pWindow::frameMargin() {
unsigned style = window.state.resizable ? ResizableStyle : FixedStyle;
if(window.state.fullScreen) style = 0;
RECT rc = { 0, 0, 640, 480 };
AdjustWindowRect(&rc, style, window.state.menuVisible);
unsigned statusHeight = 0;
if(window.state.statusVisible) {
RECT src;
GetClientRect(hstatus, &src);
statusHeight = src.bottom - src.top;
}
return { abs(rc.left), abs(rc.top), (rc.right - rc.left) - 640, (rc.bottom - rc.top) + statusHeight - 480 };
}
void pWindow::updateMenu() { void pWindow::updateMenu() {
if(hmenu) DestroyMenu(hmenu); if(hmenu) DestroyMenu(hmenu);
hmenu = CreateMenu(); hmenu = CreateMenu();

View File

@ -7,10 +7,10 @@
#include "action/action.cpp" #include "action/action.cpp"
#include "action/menu.cpp" #include "action/menu.cpp"
#include "action/menu-separator.cpp" #include "action/separator.cpp"
#include "action/menu-item.cpp" #include "action/item.cpp"
#include "action/menu-check-item.cpp" #include "action/check-item.cpp"
#include "action/menu-radio-item.cpp" #include "action/radio-item.cpp"
#include "widget/widget.cpp" #include "widget/widget.cpp"
#include "widget/button.cpp" #include "widget/button.cpp"
@ -32,12 +32,14 @@ static LRESULT CALLBACK OS_windowProc(HWND, UINT, WPARAM, LPARAM);
pOS::State *pOS::state = 0; pOS::State *pOS::state = 0;
unsigned pOS::desktopWidth() { Geometry pOS::availableGeometry() {
return GetSystemMetrics(SM_CXSCREEN); RECT rc;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
return { rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top };
} }
unsigned pOS::desktopHeight() { Geometry pOS::desktopGeometry() {
return GetSystemMetrics(SM_CYSCREEN); return { 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) };
} }
static string pOS_fileDialog(bool save, Window &parent, const string &path, const lstring &filter) { static string pOS_fileDialog(bool save, Window &parent, const string &path, const lstring &filter) {
@ -135,13 +137,13 @@ void pOS::main() {
} }
} }
bool pOS::pending() { bool pOS::pendingEvents() {
MSG msg; MSG msg;
return PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE); return PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE);
} }
void pOS::process() { void pOS::processEvents() {
while(pending()) { while(pendingEvents()) {
MSG msg; MSG msg;
if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
if(msg.message == WM_KEYDOWN || msg.message == WM_KEYUP) { if(msg.message == WM_KEYDOWN || msg.message == WM_KEYUP) {
@ -178,7 +180,7 @@ void pOS::initialize() {
wc.lpfnWndProc = OS_windowProc; wc.lpfnWndProc = OS_windowProc;
wc.lpszClassName = L"phoenix_window"; wc.lpszClassName = L"phoenix_window";
wc.lpszMenuName = 0; wc.lpszMenuName = 0;
wc.style = CS_HREDRAW | CS_VREDRAW; wc.style = 0;
RegisterClass(&wc); RegisterClass(&wc);
wc.cbClsExtra = 0; wc.cbClsExtra = 0;
@ -303,18 +305,18 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
if(control == 0) { if(control == 0) {
pObject *object = (pObject*)pObject::find(id); pObject *object = (pObject*)pObject::find(id);
if(!object) break; if(!object) break;
if(dynamic_cast<pMenuItem*>(object)) { if(dynamic_cast<pItem*>(object)) {
MenuItem &menuItem = ((pMenuItem*)object)->menuItem; Item &item = ((pItem*)object)->item;
if(menuItem.onTick) menuItem.onTick(); if(item.onTick) item.onTick();
} else if(dynamic_cast<pMenuCheckItem*>(object)) { } else if(dynamic_cast<pCheckItem*>(object)) {
MenuCheckItem &menuCheckItem = ((pMenuCheckItem*)object)->menuCheckItem; CheckItem &checkItem = ((pCheckItem*)object)->checkItem;
menuCheckItem.setChecked(!menuCheckItem.state.checked); checkItem.setChecked(!checkItem.state.checked);
if(menuCheckItem.onTick) menuCheckItem.onTick(); if(checkItem.onTick) checkItem.onTick();
} else if(dynamic_cast<pMenuRadioItem*>(object)) { } else if(dynamic_cast<pRadioItem*>(object)) {
MenuRadioItem &menuRadioItem = ((pMenuRadioItem*)object)->menuRadioItem; RadioItem &radioItem = ((pRadioItem*)object)->radioItem;
if(menuRadioItem.state.checked == false) { if(radioItem.state.checked == false) {
menuRadioItem.setChecked(); radioItem.setChecked();
if(menuRadioItem.onTick) menuRadioItem.onTick(); if(radioItem.onTick) radioItem.onTick();
} }
} }
} else { } else {
@ -374,9 +376,13 @@ static LRESULT CALLBACK OS_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
listView.p.lostFocus = true; listView.p.lostFocus = true;
} else { } else {
if(!(nmlistview->uOldState & LVIS_SELECTED) && (nmlistview->uNewState & LVIS_SELECTED)) { if(!(nmlistview->uOldState & LVIS_SELECTED) && (nmlistview->uNewState & LVIS_SELECTED)) {
if(listView.onChange) listView.onChange(); listView.state.selected = true;
} else if(listView.p.lostFocus == false && listView.selection() == false) { listView.state.selection = listView.selection();
if(listView.onChange) listView.onChange(); if(listView.p.locked == false && listView.onChange) listView.onChange();
} else if(listView.p.lostFocus == false && listView.selected() == false) {
listView.state.selected = true;
listView.state.selection = listView.selection();
if(listView.p.locked == false && listView.onChange) listView.onChange();
} }
listView.p.lostFocus = false; listView.p.lostFocus = false;
} }

View File

@ -20,14 +20,14 @@ struct pOS : public pObject {
}; };
static State *state; static State *state;
static unsigned desktopWidth(); static Geometry availableGeometry();
static unsigned desktopHeight(); static Geometry desktopGeometry();
static string fileLoad(Window &parent, const string &path, const lstring &filter); static string fileLoad(Window &parent, const string &path, const lstring &filter);
static string fileSave(Window &parent, const string &path, const lstring &filter); static string fileSave(Window &parent, const string &path, const lstring &filter);
static string folderSelect(Window &parent, const string &path); static string folderSelect(Window &parent, const string &path);
static void main(); static void main();
static bool pending(); static bool pendingEvents();
static void process(); static void processEvents();
static void quit(); static void quit();
static void initialize(); static void initialize();
@ -65,11 +65,10 @@ struct pWindow : public pObject {
void append(Layout &layout); void append(Layout &layout);
void append(Menu &menu); void append(Menu &menu);
void append(Widget &widget); void append(Widget &widget);
Geometry frameGeometry();
bool focused(); bool focused();
Geometry frameMargin();
Geometry geometry(); Geometry geometry();
void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue); void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue);
void setFrameGeometry(const Geometry &geometry);
void setFocused(); void setFocused();
void setFullScreen(bool fullScreen); void setFullScreen(bool fullScreen);
void setGeometry(const Geometry &geometry); void setGeometry(const Geometry &geometry);
@ -85,7 +84,6 @@ struct pWindow : public pObject {
pWindow(Window &window) : window(window) {} pWindow(Window &window) : window(window) {}
void constructor(); void constructor();
Geometry frameMargin();
void updateMenu(); void updateMenu();
}; };
@ -113,42 +111,42 @@ struct pMenu : public pAction {
void update(Window &parentWindow, HMENU parentMenu); void update(Window &parentWindow, HMENU parentMenu);
}; };
struct pMenuSeparator : public pAction { struct pSeparator : public pAction {
MenuSeparator &menuSeparator; Separator &separator;
pMenuSeparator(MenuSeparator &menuSeparator) : pAction(menuSeparator), menuSeparator(menuSeparator) {} pSeparator(Separator &separator) : pAction(separator), separator(separator) {}
void constructor(); void constructor();
}; };
struct pMenuItem : public pAction { struct pItem : public pAction {
MenuItem &menuItem; Item &item;
void setText(const string &text); void setText(const string &text);
pMenuItem(MenuItem &menuItem) : pAction(menuItem), menuItem(menuItem) {} pItem(Item &item) : pAction(item), item(item) {}
void constructor(); void constructor();
}; };
struct pMenuCheckItem : public pAction { struct pCheckItem : public pAction {
MenuCheckItem &menuCheckItem; CheckItem &checkItem;
bool checked(); bool checked();
void setChecked(bool checked); void setChecked(bool checked);
void setText(const string &text); void setText(const string &text);
pMenuCheckItem(MenuCheckItem &menuCheckItem) : pAction(menuCheckItem), menuCheckItem(menuCheckItem) {} pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {}
void constructor(); void constructor();
}; };
struct pMenuRadioItem : public pAction { struct pRadioItem : public pAction {
MenuRadioItem &menuRadioItem; RadioItem &radioItem;
bool checked(); bool checked();
void setChecked(); void setChecked();
void setGroup(const reference_array<MenuRadioItem&> &group); void setGroup(const reference_array<RadioItem&> &group);
void setText(const string &text); void setText(const string &text);
pMenuRadioItem(MenuRadioItem &menuRadioItem) : pAction(menuRadioItem), menuRadioItem(menuRadioItem) {} pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
void constructor(); void constructor();
}; };
@ -260,16 +258,17 @@ struct pListView : public pWidget {
bool lostFocus; bool lostFocus;
void append(const lstring &text); void append(const lstring &text);
void autosizeColumns(); void autoSizeColumns();
bool checked(unsigned row); bool checked(unsigned row);
void modify(unsigned row, const lstring &text); void modify(unsigned row, const lstring &text);
void modify(unsigned row, unsigned column, const string &text);
void reset(); void reset();
optional<unsigned> selection(); bool selected();
unsigned selection();
void setCheckable(bool checkable); void setCheckable(bool checkable);
void setChecked(unsigned row, bool checked); void setChecked(unsigned row, bool checked);
void setHeaderText(const lstring &text); void setHeaderText(const lstring &text);
void setHeaderVisible(bool visible); void setHeaderVisible(bool visible);
void setSelected(bool selected);
void setSelection(unsigned row); void setSelection(unsigned row);
pListView(ListView &listView) : pWidget(listView), listView(listView) {} pListView(ListView &listView) : pWidget(listView), listView(listView) {}

View File

@ -1,7 +1,7 @@
namespace SNES { namespace SNES {
namespace Info { namespace Info {
static const char Name[] = "bsnes"; static const char Name[] = "bsnes";
static const char Version[] = "075.15"; static const char Version[] = "075.16";
static const unsigned SerializerVersion = 18; static const unsigned SerializerVersion = 18;
} }
} }

View File

@ -1,31 +1,31 @@
struct MainWindow : Window { struct MainWindow : Window {
Menu system; Menu system;
MenuItem systemLoadCartridge; Item systemLoadCartridge;
MenuSeparator systemSeparator1; Separator systemSeparator1;
MenuItem systemPower; Item systemPower;
Menu settings; Menu settings;
MenuCheckItem settingsVideoSync; CheckItem settingsVideoSync;
MenuCheckItem settingsAudioSync; CheckItem settingsAudioSync;
Menu tools; Menu tools;
Menu toolsSaveState; Menu toolsSaveState;
MenuItem toolsSaveState1; Item toolsSaveState1;
MenuItem toolsSaveState2; Item toolsSaveState2;
MenuItem toolsSaveState3; Item toolsSaveState3;
MenuItem toolsSaveState4; Item toolsSaveState4;
MenuItem toolsSaveState5; Item toolsSaveState5;
Menu toolsLoadState; Menu toolsLoadState;
MenuItem toolsLoadState1; Item toolsLoadState1;
MenuItem toolsLoadState2; Item toolsLoadState2;
MenuItem toolsLoadState3; Item toolsLoadState3;
MenuItem toolsLoadState4; Item toolsLoadState4;
MenuItem toolsLoadState5; Item toolsLoadState5;
MenuSeparator toolsSeparator1; Separator toolsSeparator1;
MenuCheckItem toolsTraceCPU; CheckItem toolsTraceCPU;
Menu help; Menu help;
MenuItem helpAbout; Item helpAbout;
FixedLayout layout; FixedLayout layout;
Viewport viewport; Viewport viewport;

View File

@ -32,7 +32,7 @@ void Application::main(int argc, char **argv) {
mainWindow.create(); mainWindow.create();
mainWindow.setVisible(); mainWindow.setVisible();
OS::process(); OS::processEvents();
#if defined(PHOENIX_WINDOWS) #if defined(PHOENIX_WINDOWS)
video.driver("Direct3D"); video.driver("Direct3D");
@ -69,7 +69,7 @@ void Application::main(int argc, char **argv) {
GameBoy::system.init(&interface); GameBoy::system.init(&interface);
while(quit == false) { while(quit == false) {
OS::process(); OS::processEvents();
if(GameBoy::cartridge.loaded()) { if(GameBoy::cartridge.loaded()) {
do { do {

View File

@ -45,7 +45,7 @@ void Console::write(const string &text, bool echo) {
buffer.append(text); buffer.append(text);
output.setText(buffer); output.setText(buffer);
output.setCursorPosition(~0); output.setCursorPosition(~0);
OS::process(); OS::processEvents();
} }
if(traceToFile.checked() && logfile.open()) { if(traceToFile.checked() && logfile.open()) {
logfile.print(string(text, "\n")); logfile.print(string(text, "\n"));

View File

@ -113,18 +113,17 @@ void FileBrowser::folderUp() {
} }
void FileBrowser::fileActivate() { void FileBrowser::fileActivate() {
if(auto position = contentsBox.selection()) { if(contentsBox.selected() == false) return;
string filename = contents[position()]; string filename = contents[contentsBox.selection()];
if(strend(filename, "/")) { if(strend(filename, "/")) {
string cartridgeName = cartridgeFolder(filename); string cartridgeName = cartridgeFolder(filename);
if(cartridgeName == "") { if(cartridgeName == "") {
setFolder({ folder, filename }); setFolder({ folder, filename });
} else {
loadFile({ folder, cartridgeName });
}
} else { } else {
loadFile({ folder, filename }); loadFile({ folder, cartridgeName });
} }
} else {
loadFile({ folder, filename });
} }
} }

View File

@ -54,7 +54,7 @@ void MainWindow::create() {
systemPort1Mouse.setText("Mouse"); systemPort1Mouse.setText("Mouse");
systemPort1.append(systemPort1Mouse); systemPort1.append(systemPort1Mouse);
MenuRadioItem::group( RadioItem::group(
systemPort1None, systemPort1Gamepad, systemPort1Multitap, systemPort1Mouse systemPort1None, systemPort1Gamepad, systemPort1Multitap, systemPort1Mouse
); );
@ -82,7 +82,7 @@ void MainWindow::create() {
systemPort2Justifiers.setText("Justifiers"); systemPort2Justifiers.setText("Justifiers");
systemPort2.append(systemPort2Justifiers); systemPort2.append(systemPort2Justifiers);
MenuRadioItem::group( RadioItem::group(
systemPort2None, systemPort2Gamepad, systemPort2Multitap, systemPort2Mouse, systemPort2None, systemPort2Gamepad, systemPort2Multitap, systemPort2Mouse,
systemPort2SuperScope, systemPort2Justifier, systemPort2Justifiers systemPort2SuperScope, systemPort2Justifier, systemPort2Justifiers
); );
@ -109,7 +109,7 @@ void MainWindow::create() {
settingsVideoMode5x.setText("Scale 5x"); settingsVideoMode5x.setText("Scale 5x");
settingsVideoMode.append(settingsVideoMode5x); settingsVideoMode.append(settingsVideoMode5x);
MenuRadioItem::group( RadioItem::group(
settingsVideoMode1x, settingsVideoMode2x, settingsVideoMode3x, settingsVideoMode4x, settingsVideoMode5x settingsVideoMode1x, settingsVideoMode2x, settingsVideoMode3x, settingsVideoMode4x, settingsVideoMode5x
); );
@ -126,7 +126,7 @@ void MainWindow::create() {
settingsVideoModePAL.setText("PAL"); settingsVideoModePAL.setText("PAL");
settingsVideoMode.append(settingsVideoModePAL); settingsVideoMode.append(settingsVideoModePAL);
MenuRadioItem::group( RadioItem::group(
settingsVideoModeNTSC, settingsVideoModePAL settingsVideoModeNTSC, settingsVideoModePAL
); );

View File

@ -1,75 +1,75 @@
struct MainWindow : TopLevelWindow { struct MainWindow : TopLevelWindow {
Menu system; Menu system;
MenuItem systemLoadCartridge; Item systemLoadCartridge;
Menu systemLoadCartridgeSpecial; Menu systemLoadCartridgeSpecial;
MenuItem systemLoadCartridgeBsxSlotted; Item systemLoadCartridgeBsxSlotted;
MenuItem systemLoadCartridgeBsx; Item systemLoadCartridgeBsx;
MenuItem systemLoadCartridgeSufamiTurbo; Item systemLoadCartridgeSufamiTurbo;
MenuItem systemLoadCartridgeSuperGameBoy; Item systemLoadCartridgeSuperGameBoy;
MenuSeparator systemSeparator1; Separator systemSeparator1;
MenuItem systemPower; Item systemPower;
MenuItem systemReset; Item systemReset;
MenuSeparator systemSeparator2; Separator systemSeparator2;
Menu systemPort1; Menu systemPort1;
MenuRadioItem systemPort1None; RadioItem systemPort1None;
MenuRadioItem systemPort1Gamepad; RadioItem systemPort1Gamepad;
MenuRadioItem systemPort1Multitap; RadioItem systemPort1Multitap;
MenuRadioItem systemPort1Mouse; RadioItem systemPort1Mouse;
Menu systemPort2; Menu systemPort2;
MenuRadioItem systemPort2None; RadioItem systemPort2None;
MenuRadioItem systemPort2Gamepad; RadioItem systemPort2Gamepad;
MenuRadioItem systemPort2Multitap; RadioItem systemPort2Multitap;
MenuRadioItem systemPort2Mouse; RadioItem systemPort2Mouse;
MenuRadioItem systemPort2SuperScope; RadioItem systemPort2SuperScope;
MenuRadioItem systemPort2Justifier; RadioItem systemPort2Justifier;
MenuRadioItem systemPort2Justifiers; RadioItem systemPort2Justifiers;
Menu settings; Menu settings;
Menu settingsVideoMode; Menu settingsVideoMode;
MenuRadioItem settingsVideoMode1x; RadioItem settingsVideoMode1x;
MenuRadioItem settingsVideoMode2x; RadioItem settingsVideoMode2x;
MenuRadioItem settingsVideoMode3x; RadioItem settingsVideoMode3x;
MenuRadioItem settingsVideoMode4x; RadioItem settingsVideoMode4x;
MenuRadioItem settingsVideoMode5x; RadioItem settingsVideoMode5x;
MenuSeparator settingsVideoModeSeparator1; Separator settingsVideoModeSeparator1;
MenuCheckItem settingsVideoModeAspectRatioCorrection; CheckItem settingsVideoModeAspectRatioCorrection;
MenuSeparator settingsVideoModeSeparator2; Separator settingsVideoModeSeparator2;
MenuRadioItem settingsVideoModeNTSC; RadioItem settingsVideoModeNTSC;
MenuRadioItem settingsVideoModePAL; RadioItem settingsVideoModePAL;
MenuCheckItem settingsSmoothVideo; CheckItem settingsSmoothVideo;
MenuSeparator settingsSeparator1; Separator settingsSeparator1;
MenuCheckItem settingsSynchronizeVideo; CheckItem settingsSynchronizeVideo;
MenuCheckItem settingsSynchronizeAudio; CheckItem settingsSynchronizeAudio;
MenuCheckItem settingsMuteAudio; CheckItem settingsMuteAudio;
MenuSeparator settingsSeparator2; Separator settingsSeparator2;
MenuItem settingsVideo; Item settingsVideo;
MenuItem settingsAudio; Item settingsAudio;
MenuItem settingsInput; Item settingsInput;
MenuItem settingsAdvanced; Item settingsAdvanced;
Menu tools; Menu tools;
Menu toolsStateSave; Menu toolsStateSave;
MenuItem toolsStateSave1; Item toolsStateSave1;
MenuItem toolsStateSave2; Item toolsStateSave2;
MenuItem toolsStateSave3; Item toolsStateSave3;
MenuItem toolsStateSave4; Item toolsStateSave4;
MenuItem toolsStateSave5; Item toolsStateSave5;
Menu toolsStateLoad; Menu toolsStateLoad;
MenuItem toolsStateLoad1; Item toolsStateLoad1;
MenuItem toolsStateLoad2; Item toolsStateLoad2;
MenuItem toolsStateLoad3; Item toolsStateLoad3;
MenuItem toolsStateLoad4; Item toolsStateLoad4;
MenuItem toolsStateLoad5; Item toolsStateLoad5;
MenuSeparator toolsSeparator1; Separator toolsSeparator1;
MenuItem toolsCheatEditor; Item toolsCheatEditor;
MenuItem toolsStateManager; Item toolsStateManager;
#if defined(DEBUGGER) #if defined(DEBUGGER)
MenuSeparator toolsSeparator2; Separator toolsSeparator2;
MenuItem toolsDebugger; Item toolsDebugger;
#endif #endif
Menu help; Menu help;
MenuItem helpAbout; Item helpAbout;
FixedLayout layout; FixedLayout layout;
Viewport viewport; Viewport viewport;

View File

@ -67,7 +67,7 @@ void Application::main(int argc, char **argv) {
utility.setScale(config.video.scale); utility.setScale(config.video.scale);
mainWindow.setVisible(); mainWindow.setVisible();
OS::process(); OS::processEvents();
video.driver(config.video.driver); video.driver(config.video.driver);
video.set(Video::Handle, mainWindow.viewport.handle()); video.set(Video::Handle, mainWindow.viewport.handle());
@ -108,7 +108,7 @@ void Application::main(int argc, char **argv) {
if(argc == 2) cartridge.loadNormal(argv[1]); if(argc == 2) cartridge.loadNormal(argv[1]);
while(quit == false) { while(quit == false) {
OS::process(); OS::processEvents();
inputMapper.poll(); inputMapper.poll();
utility.updateStatus(); utility.updateStatus();
@ -130,7 +130,7 @@ void Application::main(int argc, char **argv) {
cartridge.unload(); cartridge.unload();
saveGeometry(); saveGeometry();
foreach(window, windows) window->setVisible(false); foreach(window, windows) window->setVisible(false);
OS::process(); OS::processEvents();
SNES::system.term(); SNES::system.term();
config.save(); config.save();

View File

@ -16,12 +16,12 @@ void InputSettings::create() {
deviceLabel.setText("Device:"); deviceLabel.setText("Device:");
mappingList.setHeaderText("Name", "Mapping"); mappingList.setHeaderText("Name", "Mapping");
mappingList.setHeaderVisible(true); mappingList.setHeaderVisible(true);
clearButton.setText("Clear");
mouseXaxis.setText("Mouse X-axis"); mouseXaxis.setText("Mouse X-axis");
mouseYaxis.setText("Mouse Y-axis"); mouseYaxis.setText("Mouse Y-axis");
mouseLeft.setText("Mouse Left"); mouseLeft.setText("Mouse Left");
mouseMiddle.setText("Mouse Middle"); mouseMiddle.setText("Mouse Middle");
mouseRight.setText("Mouse Right"); mouseRight.setText("Mouse Right");
clearButton.setText("Clear");
layout.setMargin(5); layout.setMargin(5);
selectionLayout.append(portLabel, 50, 0, 5); selectionLayout.append(portLabel, 50, 0, 5);
@ -30,23 +30,30 @@ void InputSettings::create() {
selectionLayout.append(deviceBox, 0, 0); selectionLayout.append(deviceBox, 0, 0);
layout.append(selectionLayout, 0, Style::ComboBoxHeight, 5); layout.append(selectionLayout, 0, Style::ComboBoxHeight, 5);
layout.append(mappingList, 0, 0, 5); layout.append(mappingList, 0, 0, 5);
mapLayout.append(mouseXaxis, 100, 0, 5); mapLayout.append(spacer, 0, 0);
mapLayout.append(mouseYaxis, 100, 0, 5); mapLayout.append(clearButton, 80, 0);
mapLayout.append(mouseLeft, 100, 0, 5);
mapLayout.append(mouseMiddle, 100, 0, 5);
mapLayout.append(mouseRight, 100, 0, 5);
mapLayout.append(spacer, 0, 0);
mapLayout.append(clearButton, 80, 0);
layout.append(mapLayout, 0, Style::ButtonHeight); layout.append(mapLayout, 0, Style::ButtonHeight);
setGeometry({ 0, 0, 640, layout.minimumHeight() + 250 }); axisLayout.setMargin(5);
append(layout); axisLayout.append(axisSpacer, 0, 0);
axisControlLayout.append(mouseXaxis, 100, 0, 5);
axisControlLayout.append(mouseYaxis, 100, 0, 5);
axisLayout.append(axisControlLayout, 0, Style::ButtonHeight);
mouseXaxis.setVisible(false); buttonLayout.setMargin(5);
mouseYaxis.setVisible(false); buttonLayout.append(buttonSpacer, 0, 0);
mouseLeft.setVisible(false); buttonControlLayout.append(mouseLeft, 100, 0, 5);
mouseMiddle.setVisible(false); buttonControlLayout.append(mouseMiddle, 100, 0, 5);
mouseRight.setVisible(false); buttonControlLayout.append(mouseRight, 100, 0, 5);
buttonLayout.append(buttonControlLayout, 0, Style::ButtonHeight);
setGeometry({ 0, 0, 480, layout.minimumHeight() + 250 });
append(layout);
append(axisLayout);
append(buttonLayout);
axisLayout.setVisible(false);
buttonLayout.setVisible(false);
portChanged(); portChanged();
portBox.onChange = { &InputSettings::portChanged, this }; portBox.onChange = { &InputSettings::portChanged, this };
@ -90,7 +97,7 @@ void InputSettings::deviceChanged() {
if(mapping == "") mapping = "None"; if(mapping == "") mapping = "None";
mappingList.append(controller[i]->name, mapping); mappingList.append(controller[i]->name, mapping);
} }
mappingList.autosizeColumns(); mappingList.autoSizeColumns();
} }
void InputSettings::mappingChanged() { void InputSettings::mappingChanged() {
@ -106,53 +113,45 @@ void InputSettings::mappingChanged() {
if(mapping == "") mapping = "None"; if(mapping == "") mapping = "None";
mappingList.modify(i, controller[i]->name, mapping); mappingList.modify(i, controller[i]->name, mapping);
} }
mappingList.autosizeColumns(); mappingList.autoSizeColumns();
} }
void InputSettings::assignInput() { void InputSettings::assignInput() {
if(auto position = mappingList.selection()) { if(mappingList.selected() == false) return;
InputMapper::ControllerPort &port = ( InputMapper::ControllerPort &port = (
portBox.selection() == 0 portBox.selection() == 0
? (InputMapper::ControllerPort&)inputMapper.port1 ? (InputMapper::ControllerPort&)inputMapper.port1
: (InputMapper::ControllerPort&)inputMapper.port2 : (InputMapper::ControllerPort&)inputMapper.port2
); );
InputMapper::Controller &controller = (InputMapper::Controller&)*port[deviceBox.selection()]; InputMapper::Controller &controller = (InputMapper::Controller&)*port[deviceBox.selection()];
portBox.setEnabled(false); portBox.setEnabled(false);
deviceBox.setEnabled(false); deviceBox.setEnabled(false);
mappingList.setEnabled(false); mappingList.setEnabled(false);
inputMapper.poll(); //flush any pending keypresses inputMapper.poll(); //flush any pending keypresses
activeInput = controller[position()]; activeInput = controller[mappingList.selection()];
setStatusText({ "Set assignment for [", activeInput->name, "] ..." }); setStatusText({ "Set assignment for [", activeInput->name, "] ..." });
if(dynamic_cast<InputMapper::AnalogInput*>(activeInput)) { if(dynamic_cast<InputMapper::AnalogInput*>(activeInput)) {
mouseLeft.setVisible(false); axisLayout.setVisible(true);
mouseMiddle.setVisible(false); buttonLayout.setVisible(false);
mouseRight.setVisible(false); } else {
mouseXaxis.setVisible(true); axisLayout.setVisible(false);
mouseYaxis.setVisible(true); buttonLayout.setVisible(true);
} else {
mouseXaxis.setVisible(false);
mouseYaxis.setVisible(false);
mouseLeft.setVisible(true);
mouseMiddle.setVisible(true);
mouseRight.setVisible(true);
}
} }
} }
void InputSettings::clearInput() { void InputSettings::clearInput() {
if(auto position = mappingList.selection()) { if(mappingList.selected() == false) return;
InputMapper::ControllerPort &port = ( InputMapper::ControllerPort &port = (
portBox.selection() == 0 portBox.selection() == 0
? (InputMapper::ControllerPort&)inputMapper.port1 ? (InputMapper::ControllerPort&)inputMapper.port1
: (InputMapper::ControllerPort&)inputMapper.port2 : (InputMapper::ControllerPort&)inputMapper.port2
); );
InputMapper::Controller &controller = (InputMapper::Controller&)*port[deviceBox.selection()]; InputMapper::Controller &controller = (InputMapper::Controller&)*port[deviceBox.selection()];
controller[position()]->mapping = ""; controller[mappingList.selection()]->mapping = "";
inputMapper.bind(); inputMapper.bind();
endAssignment(); endAssignment();
}
} }
void InputSettings::setMapping(const string &mapping) { void InputSettings::setMapping(const string &mapping) {
@ -167,11 +166,8 @@ void InputSettings::endAssignment() {
deviceBox.setEnabled(true); deviceBox.setEnabled(true);
mappingList.setEnabled(true); mappingList.setEnabled(true);
setStatusText(""); setStatusText("");
mouseXaxis.setVisible(false); axisLayout.setVisible(false);
mouseYaxis.setVisible(false); buttonLayout.setVisible(false);
mouseLeft.setVisible(false);
mouseMiddle.setVisible(false);
mouseRight.setVisible(false);
mappingChanged(); mappingChanged();
mappingList.setFocused(); mappingList.setFocused();
} }

View File

@ -7,13 +7,21 @@ struct InputSettings : TopLevelWindow {
ComboBox deviceBox; ComboBox deviceBox;
ListView mappingList; ListView mappingList;
HorizontalLayout mapLayout; HorizontalLayout mapLayout;
Label spacer;
Button clearButton;
VerticalLayout axisLayout;
Widget axisSpacer;
HorizontalLayout axisControlLayout;
Button mouseXaxis; Button mouseXaxis;
Button mouseYaxis; Button mouseYaxis;
VerticalLayout buttonLayout;
Widget buttonSpacer;
HorizontalLayout buttonControlLayout;
Button mouseLeft; Button mouseLeft;
Button mouseMiddle; Button mouseMiddle;
Button mouseRight; Button mouseRight;
Label spacer;
Button clearButton;
void inputEvent(uint16_t scancode, int16_t value); void inputEvent(uint16_t scancode, int16_t value);
void calibrateJoypads(); void calibrateJoypads();

View File

@ -75,7 +75,7 @@ void CheatEditor::save(string filename) {
} }
cheatList.reset(); cheatList.reset();
cheatList.autosizeColumns(); cheatList.autoSizeColumns();
} }
void CheatEditor::create() { void CheatEditor::create() {
@ -158,9 +158,9 @@ void CheatEditor::create() {
void CheatEditor::synchronize() { void CheatEditor::synchronize() {
findButton.setEnabled(SNES::cartridge.loaded()); findButton.setEnabled(SNES::cartridge.loaded());
clearAllButton.setEnabled(SNES::cartridge.loaded()); clearAllButton.setEnabled(SNES::cartridge.loaded());
if(auto position = cheatList.selection()) { if(cheatList.selected()) {
codeEdit.setText(cheatText[position()][1]); codeEdit.setText(cheatText[cheatList.selection()][1]);
descEdit.setText(cheatText[position()][2]); descEdit.setText(cheatText[cheatList.selection()][2]);
codeEdit.setEnabled(true); codeEdit.setEnabled(true);
descEdit.setEnabled(true); descEdit.setEnabled(true);
clearButton.setEnabled(true); clearButton.setEnabled(true);
@ -184,7 +184,7 @@ void CheatEditor::refresh() {
cheatList.setChecked(i, SNES::cheat[i].enabled); cheatList.setChecked(i, SNES::cheat[i].enabled);
cheatList.modify(i, cheatText[i][CheatSlot], cheatCode, cheatText[i][CheatDesc]); cheatList.modify(i, cheatText[i][CheatSlot], cheatCode, cheatText[i][CheatDesc]);
} }
cheatList.autosizeColumns(); cheatList.autoSizeColumns();
} }
void CheatEditor::toggle(unsigned row) { void CheatEditor::toggle(unsigned row) {
@ -193,12 +193,12 @@ void CheatEditor::toggle(unsigned row) {
} }
void CheatEditor::bind() { void CheatEditor::bind() {
if(auto position = cheatList.selection()) { if(cheatList.selected() == false) return;
cheatText[position()][CheatCode] = codeEdit.text(); unsigned selection = cheatList.selection();
cheatText[position()][CheatDesc] = descEdit.text(); cheatText[selection][CheatCode] = codeEdit.text();
SNES::cheat[position()] = cheatText[position()][CheatCode]; cheatText[selection][CheatDesc] = descEdit.text();
refresh(); SNES::cheat[selection] = cheatText[selection][CheatCode];
} refresh();
} }
void CheatEditor::findCodes() { void CheatEditor::findCodes() {
@ -289,15 +289,15 @@ void CheatEditor::clearAll() {
} }
void CheatEditor::clear() { void CheatEditor::clear() {
if(auto position = cheatList.selection()) { if(cheatList.selected() == false) return;
SNES::cheat[position()].enabled = false; unsigned selection = cheatList.selection();
SNES::cheat[position()] = ""; SNES::cheat[selection].enabled = false;
cheatList.setChecked(position(), false); SNES::cheat[selection] = "";
cheatText[position()][CheatCode] = ""; cheatList.setChecked(selection, false);
cheatText[position()][CheatDesc] = ""; cheatText[selection][CheatCode] = "";
SNES::cheat.synchronize(); cheatText[selection][CheatDesc] = "";
refresh(); SNES::cheat.synchronize();
codeEdit.setText(""); refresh();
descEdit.setText(""); codeEdit.setText("");
} descEdit.setText("");
} }

View File

@ -38,11 +38,10 @@ void StateManager::create() {
void StateManager::synchronize() { void StateManager::synchronize() {
descEdit.setText(""); descEdit.setText("");
descEdit.setEnabled(false); descEdit.setEnabled(false);
if(auto position = stateList.selection()) { if(stateList.selected() == false) return;
if(slot[position()].capacity() > 0) { if(slot[stateList.selection()].capacity() > 0) {
descEdit.setText(slotLoadDescription(position())); descEdit.setText(slotLoadDescription(stateList.selection()));
descEdit.setEnabled(true); descEdit.setEnabled(true);
}
} }
} }
@ -50,7 +49,7 @@ void StateManager::refresh() {
for(unsigned i = 0; i < 32; i++) { for(unsigned i = 0; i < 32; i++) {
stateList.modify(i, rdecimal<2>(i + 1), slotLoadDescription(i)); stateList.modify(i, rdecimal<2>(i + 1), slotLoadDescription(i));
} }
stateList.autosizeColumns(); stateList.autoSizeColumns();
} }
void StateManager::load() { void StateManager::load() {
@ -106,16 +105,15 @@ void StateManager::save() {
} }
void StateManager::slotLoad() { void StateManager::slotLoad() {
if(auto position = stateList.selection()) { if(stateList.selected() == false) return;
serializer s(slot[position()].data(), slot[position()].capacity()); serializer s(slot[stateList.selection()].data(), slot[stateList.selection()].capacity());
SNES::system.unserialize(s); SNES::system.unserialize(s);
}
} }
void StateManager::slotSave() { void StateManager::slotSave() {
if(auto position = stateList.selection()) { if(stateList.selected()) {
SNES::system.runtosave(); SNES::system.runtosave();
slot[position()] = SNES::system.serialize(); slot[stateList.selection()] = SNES::system.serialize();
} }
refresh(); refresh();
synchronize(); synchronize();
@ -123,8 +121,8 @@ void StateManager::slotSave() {
} }
void StateManager::slotErase() { void StateManager::slotErase() {
if(auto position = stateList.selection()) { if(stateList.selected()) {
slot[position()] = serializer(); slot[stateList.selection()] = serializer();
} }
refresh(); refresh();
synchronize(); synchronize();
@ -138,11 +136,10 @@ string StateManager::slotLoadDescription(unsigned i) {
} }
void StateManager::slotSaveDescription() { void StateManager::slotSaveDescription() {
if(auto position = stateList.selection()) { if(stateList.selected() == false) return;
string text = descEdit.text(); string text = descEdit.text();
if(slot[position()].capacity() > 0) { if(slot[stateList.selection()].capacity() > 0) {
strlcpy((char*)slot[position()].data() + HeaderLength, (const char*)text, 512); strlcpy((char*)slot[stateList.selection()].data() + HeaderLength, (const char*)text, 512);
}
} }
refresh(); refresh();
} }

View File

@ -92,38 +92,39 @@ void Utility::setFullscreen(bool fullscreen) {
setScale(); setScale();
} else { } else {
input.acquire(); input.acquire();
Geometry desktop = OS::desktopGeometry();
unsigned width, height; unsigned width, height;
switch(config.video.fullscreenScale) { default: switch(config.video.fullscreenScale) { default:
case 0: { //center (even multiple of base height) case 0: { //center (even multiple of base height)
unsigned baseHeight = config.video.region == 0 ? 224 : 239; unsigned baseHeight = config.video.region == 0 ? 224 : 239;
unsigned heightScale = OS::desktopHeight() / baseHeight; unsigned heightScale = desktop.height / baseHeight;
height = baseHeight * heightScale; height = baseHeight * heightScale;
width = 256 * heightScale; width = 256 * heightScale;
if(config.video.region == 0 && config.video.aspectRatioCorrection) width *= 54.0 / 47.0; if(config.video.region == 0 && config.video.aspectRatioCorrection) width *= 54.0 / 47.0;
if(config.video.region == 1 && config.video.aspectRatioCorrection) width *= 32.0 / 23.0; if(config.video.region == 1 && config.video.aspectRatioCorrection) width *= 32.0 / 23.0;
width = min(width, OS::desktopWidth()); width = min(width, desktop.width);
break; break;
} }
case 1: { //scale (100% screen height, aspect-corrected width) case 1: { //scale (100% screen height, aspect-corrected width)
unsigned baseHeight = config.video.region == 0 ? 224 : 239; unsigned baseHeight = config.video.region == 0 ? 224 : 239;
height = OS::desktopHeight(); height = desktop.height;
width = 256.0 / baseHeight * height; width = 256.0 / baseHeight * height;
if(config.video.region == 0 && config.video.aspectRatioCorrection) width *= 54.0 / 47.0; if(config.video.region == 0 && config.video.aspectRatioCorrection) width *= 54.0 / 47.0;
if(config.video.region == 1 && config.video.aspectRatioCorrection) width *= 32.0 / 23.0; if(config.video.region == 1 && config.video.aspectRatioCorrection) width *= 32.0 / 23.0;
width = min(width, OS::desktopWidth()); width = min(width, desktop.width);
break; break;
} }
case 2: { //stretch (100% screen width and 100% screen height) case 2: { //stretch (100% screen width and 100% screen height)
width = OS::desktopWidth(); width = desktop.width;
height = OS::desktopHeight(); height = desktop.height;
break; break;
} }
} }
viewportX = (OS::desktopWidth() - width) / 2; viewportX = (desktop.width - width) / 2;
viewportY = (OS::desktopHeight() - height) / 2; viewportY = (desktop.height - height) / 2;
viewportWidth = width; viewportWidth = width;
viewportHeight = height; viewportHeight = height;