mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Fixed sub menus
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@94 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -58,19 +58,22 @@ DropDownList::DropDownList(Window* parent, bool is_submenu, ValueViewer* viewer)
|
||||
, mouse_down(false)
|
||||
, selected_item(NO_SELECTION)
|
||||
, open_sub_menu(nullptr)
|
||||
, parent_menu(is_submenu ? static_cast<DropDownList*>(GetParent()) : nullptr)
|
||||
, parent_menu(nullptr)
|
||||
, hider(is_submenu ? nullptr : new DropDownHider(*this))
|
||||
, viewer(viewer)
|
||||
, item_size(100,1)
|
||||
, icon_size(0,0)
|
||||
, text_offset(0)
|
||||
, text_offset(1)
|
||||
{
|
||||
if (is_submenu) {
|
||||
parent_menu = &dynamic_cast<DropDownList&>(*GetParent());
|
||||
}
|
||||
// determine item height
|
||||
wxClientDC dc(this);
|
||||
dc.SetFont(*wxNORMAL_FONT);
|
||||
int h;
|
||||
dc.GetTextExtent(_("X"), 0, &h);
|
||||
item_size.height = h;
|
||||
item_size.height = h + 2;
|
||||
}
|
||||
|
||||
DropDownList::~DropDownList() {
|
||||
@@ -127,7 +130,6 @@ void DropDownList::show(bool in_place, wxPoint pos) {
|
||||
parent->PushEventHandler(hider);
|
||||
}
|
||||
// show
|
||||
// oldSelectedItem = selectedItem;
|
||||
if (selected_item == NO_SELECTION && itemCount() > 0) selected_item = 0; // select first item by default
|
||||
mouse_down = false;
|
||||
Window::Show();
|
||||
@@ -152,7 +154,7 @@ void DropDownList::realHide() {
|
||||
// onHide();
|
||||
hideSubMenu();
|
||||
if (parent_menu) {
|
||||
parent_menu->open_sub_menu = 0;
|
||||
parent_menu->open_sub_menu = nullptr;
|
||||
} else {
|
||||
redrawArrowOnParent();
|
||||
// disconnect event handler
|
||||
@@ -254,7 +256,7 @@ void DropDownList::drawItem(DC& dc, int y, size_t item) {
|
||||
}
|
||||
// draw text and icon
|
||||
drawIcon(dc, marginW, y, item, item == selected_item);
|
||||
dc.DrawText(capitalize(itemText(item)), marginW + icon_size.width, y + text_offset);
|
||||
dc.DrawText(capitalize(itemText(item)), marginW + icon_size.width + 1, y + text_offset);
|
||||
// draw popup icon
|
||||
if (submenu(item)) {
|
||||
draw_menu_arrow(this, dc, wxRect(marginW, y, item_size.width, item_size.height), item == selected_item);
|
||||
|
||||
@@ -35,6 +35,8 @@ ChoiceField::ChoiceP DropDownChoiceList::getChoice(size_t item) const {
|
||||
String DropDownChoiceList::itemText(size_t item) const {
|
||||
if (isFieldDefault(item)) {
|
||||
return field().default_name;
|
||||
} else if (isGroupDefault(item)) {
|
||||
return group->default_name;
|
||||
} else {
|
||||
ChoiceField::ChoiceP choice = getChoice(item);
|
||||
return choice->name;
|
||||
@@ -43,15 +45,15 @@ String DropDownChoiceList::itemText(size_t item) const {
|
||||
bool DropDownChoiceList::lineBelow(size_t item) const {
|
||||
return isDefault(item);
|
||||
}
|
||||
DropDownList* DropDownChoiceList::submenu(size_t item) {
|
||||
DropDownList* DropDownChoiceList::submenu(size_t item) const {
|
||||
if (isDefault(item)) return nullptr;
|
||||
item -= hasDefault();
|
||||
if (item < submenus.size()) submenus.resize(item + 1);
|
||||
if (item >= submenus.size()) submenus.resize(item + 1);
|
||||
if (submenus[item]) return submenus[item].get();
|
||||
ChoiceField::ChoiceP choice = getChoice(item);
|
||||
ChoiceField::ChoiceP choice = group->choices[item];
|
||||
if (choice->isGroup()) {
|
||||
// create submenu
|
||||
submenus[item].reset(new DropDownChoiceList(GetParent(), true, cve, choice));
|
||||
submenus[item].reset(new DropDownChoiceList(const_cast<DropDownChoiceList*>(this), true, cve, choice));
|
||||
}
|
||||
return submenus[item].get();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class DropDownChoiceList : public DropDownList {
|
||||
virtual bool lineBelow(size_t item) const;
|
||||
virtual String itemText(size_t item) const;
|
||||
virtual void drawIcon(DC& dc, int x, int y, size_t item, bool selected) const;
|
||||
virtual DropDownList* submenu(size_t item);
|
||||
virtual DropDownList* submenu(size_t item) const;
|
||||
|
||||
virtual void select(size_t item);
|
||||
virtual size_t selection() const;
|
||||
@@ -58,7 +58,7 @@ class DropDownChoiceList : public DropDownList {
|
||||
private:
|
||||
ChoiceValueEditor& cve;
|
||||
ChoiceField::ChoiceP group; ///< Group this menu shows
|
||||
vector<DropDownListP> submenus;
|
||||
mutable vector<DropDownListP> submenus;
|
||||
|
||||
inline const ChoiceField& field() const { return cve.field(); }
|
||||
|
||||
|
||||
+5
-5
@@ -98,12 +98,12 @@ bool is_substr(const String& s, String::iterator it, const Char* cmp) {
|
||||
|
||||
String capitalize(const String& s) {
|
||||
String result = s;
|
||||
bool afterSpace = true;
|
||||
bool after_space = true;
|
||||
FOR_EACH_IT(it, result) {
|
||||
if (*it == ' ') {
|
||||
afterSpace = true;
|
||||
} else if (afterSpace) {
|
||||
afterSpace = false;
|
||||
if (*it == _(' ') || *it == _('/')) {
|
||||
after_space = true;
|
||||
} else if (after_space) {
|
||||
after_space = false;
|
||||
if (it != s.begin() &&
|
||||
(is_substr(result,it,_("is ")) || is_substr(result,it,_("the ")) ||
|
||||
is_substr(result,it,_("in ")) || is_substr(result,it,_("of ")) ||
|
||||
|
||||
Reference in New Issue
Block a user