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

View File

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

View File

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

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();
}
bool pMenuCheckItem::checked() {
bool pCheckItem::checked() {
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
}
void pMenuCheckItem::setChecked(bool checked) {
void pCheckItem::setChecked(bool checked) {
locked = true;
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), checked);
locked = false;
}
void pMenuCheckItem::setText(const string &text) {
void pCheckItem::setText(const string &text) {
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text);
}
void pMenuCheckItem::constructor() {
void pCheckItem::constructor() {
widget = gtk_check_menu_item_new_with_label("");
g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(MenuCheckItem_tick), (gpointer)&menuCheckItem);
g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(CheckItem_tick), (gpointer)&checkItem);
}

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

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;
item.p.update(parentWindow, hmenu);
AppendMenu(hmenu, MF_STRING | MF_POPUP | enabled, (UINT_PTR)item.p.hmenu, utf16_t(item.state.text));
} else if(dynamic_cast<MenuSeparator*>(&action)) {
MenuSeparator &item = (MenuSeparator&)action;
} else if(dynamic_cast<Separator*>(&action)) {
Separator &item = (Separator&)action;
if(action.state.visible) AppendMenu(hmenu, MF_SEPARATOR | enabled, item.p.id, L"");
} else if(dynamic_cast<MenuItem*>(&action)) {
MenuItem &item = (MenuItem&)action;
} else if(dynamic_cast<Item*>(&action)) {
Item &item = (Item&)action;
if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text));
} else if(dynamic_cast<MenuCheckItem*>(&action)) {
MenuCheckItem &item = (MenuCheckItem&)action;
} else if(dynamic_cast<CheckItem*>(&action)) {
CheckItem &item = (CheckItem&)action;
if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text));
if(item.state.checked) item.setChecked();
} else if(dynamic_cast<MenuRadioItem*>(&action)) {
MenuRadioItem &item = (MenuRadioItem&)action;
} else if(dynamic_cast<RadioItem*>(&action)) {
RadioItem &item = (RadioItem&)action;
if(action.state.visible) AppendMenu(hmenu, MF_STRING | enabled, item.p.id, utf16_t(item.state.text));
if(item.state.checked) item.setChecked();
}

View File

@ -1,9 +1,9 @@
bool pMenuRadioItem::checked() {
return menuRadioItem.state.checked;
bool pRadioItem::checked() {
return radioItem.state.checked;
}
void pMenuRadioItem::setChecked() {
foreach(item, menuRadioItem.state.group) {
void pRadioItem::setChecked() {
foreach(item, radioItem.state.group) {
//CheckMenuRadioItem takes: lo, hi, id; checking only id when lo <= id <= hi
//phoenix does not force IDs to be linear, so to uncheck id, we use: lo == hi == id + 1 (out of range)
//to check id, we use: lo == hi == id (only ID, but in range)
@ -11,12 +11,12 @@ void pMenuRadioItem::setChecked() {
}
}
void pMenuRadioItem::setGroup(const reference_array<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();
}
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) {
SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 200, SWP_NOZORDER);
RECT rc;
GetWindowRect(hwnd, &rc);
unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0));
SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight);
SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 1, SWP_NOZORDER);
//RECT rc;
//GetWindowRect(hwnd, &rc);
//unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0));
//SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight);
}
void pComboBox::setParent(Window &parent) {

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);
if(!window || !label) return DefWindowProc(hwnd, msg, wparam, lparam);
if(msg == WM_ERASEBKGND) {
//background is erased during WM_PAINT to prevent flickering
return TRUE;
}
if(msg == WM_PAINT) {
PAINTSTRUCT ps;
RECT rc;

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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