diff --git a/src/gui/control/gallery_list.cpp b/src/gui/control/gallery_list.cpp index 35ac2b36..e9dc780c 100644 --- a/src/gui/control/gallery_list.cpp +++ b/src/gui/control/gallery_list.cpp @@ -11,6 +11,8 @@ #include #include +DECLARE_TYPEOF_COLLECTION(GalleryList::Column_for_typeof); + // ----------------------------------------------------------------------------- : Events DEFINE_EVENT_TYPE(EVENT_GALLERY_SELECT); @@ -20,34 +22,53 @@ DEFINE_EVENT_TYPE(EVENT_GALLERY_ACTIVATE); GalleryList::GalleryList(Window* parent, int id, int direction, bool always_focused) : wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER | wxWANTS_CHARS | (direction == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL) ) - , selection(NO_SELECTION) + , active_column(0) , direction(direction) , always_focused(always_focused) , visible_start(0) -{} +{ + Column col; + col.can_select = true; + col.selection = NO_SELECTION; + columns.push_back(col); +} -void GalleryList::select(size_t item, bool event) { +void GalleryList::selectColumn(size_t column) { + if (column >= columns.size()) return; + if (!columns[column].can_select) return; + if (active_column == column) return; + RefreshItem(columns[active_column].selection); + RefreshItem(columns[column ].selection); + active_column = column; +} + +void GalleryList::select(size_t item, size_t column, bool event) { if (item >= itemCount()) return; // select - size_t old_sel = selection; - selection = item; + bool changes = false; + selectColumn(column); + onSelect(item, active_column, changes); + Column& col = columns[active_column]; + size_t old_sel = col.selection; + col.selection = item; + changes |= col.selection != old_sel; // ensure visible - if (itemStart(selection) < visible_start) { - scrollTo(itemStart(selection)); - } else if (itemEnd(selection) > visibleEnd()) { - scrollTo(itemEnd(selection) + visible_start - visibleEnd()); - } else { + if (itemStart(col.selection) < visible_start) { + scrollTo(itemStart(col.selection)); + } else if (itemEnd(col.selection) > visibleEnd()) { + scrollTo(itemEnd(col.selection) + visible_start - visibleEnd()); + } else if (col.selection != old_sel) { RefreshItem(old_sel); - RefreshItem(selection); + RefreshItem(col.selection); } // send event - if (event && selection != old_sel) { + if (event && changes) { sendEvent(EVENT_GALLERY_SELECT); } } void GalleryList::update() { - select(selection); + select(columns[active_column].selection); updateScrollbar(); Refresh(false); } @@ -97,6 +118,9 @@ void GalleryList::RefreshItem(size_t item) { if (item >= itemCount()) return; RefreshRect(wxRect(itemPos(item),item_size).Inflate(BORDER,BORDER), false); } +void GalleryList::RefreshSelection() { + FOR_EACH(col,columns) RefreshItem(col.selection); +} void GalleryList::onScroll(wxScrollWinEvent& ev) { wxEventType type = ev.GetEventType(); @@ -130,8 +154,21 @@ void GalleryList::onMouseWheel(wxMouseEvent& ev) { void GalleryList::onLeftDown(wxMouseEvent& ev) { size_t item = findItem(ev); - if (item != selection && item < itemCount()) { - select(item); + if (item < itemCount()) { + // find column + wxPoint pos = itemPos(item); + int x = ev.GetX() - pos.x; + int y = ev.GetY() - pos.y; + size_t column = active_column; + for (size_t j = 0 ; columns.size() ; ++j) { + Column& col = columns[j]; + if (x >= col.offset.x && y >= col.offset.y && x < col.size.x + col.offset.x && y < col.size.y + col.offset.y) { + // clicked on this column + column = j; + break; + } + } + select(item, column); } ev.Skip(); // focus } @@ -141,19 +178,36 @@ void GalleryList::onLeftDClick(wxMouseEvent& ev) { } void GalleryList::onChar(wxKeyEvent& ev) { + Column& col = columns[active_column]; switch (ev.GetKeyCode()) { - case WXK_LEFT: if (direction == wxHORIZONTAL) { - select(selection - 1); - } break; - case WXK_RIGHT: if (direction == wxHORIZONTAL) { - select(selection + 1); - } break; - case WXK_UP: if (direction == wxVERTICAL) { - select(selection - 1); - } break; - case WXK_DOWN: if (direction == wxVERTICAL) { - select(selection + 1); - } break; + case WXK_LEFT: + if (direction == wxHORIZONTAL) { + select(col.selection - 1); + } else { + selectColumn(active_column - 1); + } + break; + case WXK_RIGHT: + if (direction == wxHORIZONTAL) { + select(col.selection + 1); + } else { + selectColumn(active_column + 1); + } + break; + case WXK_UP: + if (direction == wxVERTICAL) { + select(col.selection - 1); + } else { + selectColumn(active_column - 1); + } + break; + case WXK_DOWN: + if (direction == wxVERTICAL) { + select(col.selection + 1); + } else { + selectColumn(active_column + 1); + } + break; case WXK_TAB: { // send a navigation event to our parent, to select another control // we need this because tabs of wxWANTS_CHARS @@ -202,21 +256,26 @@ void GalleryList::OnDraw(DC& dc) { Color unselected = lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW), wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 0.1); Color background = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); + bool has_focus = always_focused || FindFocus() == this; for (size_t i = start ; i < end ; ++i) { - // draw selection rectangle - bool selected = i == selection; - Color c = selected ? ( always_focused || FindFocus() == this - ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT) - : lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW), - wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 0.7) - ) - : unselected; - dc.SetPen(c); - dc.SetBrush(saturate(lerp(background, c, 0.3), selected ? 0.5 : 0)); wxPoint pos = itemPos(i); - dc.DrawRectangle(pos.x - BORDER, pos.y - BORDER, item_size.x + 2*BORDER, item_size.y + 2*BORDER); + // draw selection rectangle + for (size_t j = 0 ; j < columns.size() ; ++j) { + const Column& col = columns[j]; + bool selected = i == col.selection; + Color c = selected ? ( has_focus && j == active_column + ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT) + : lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW), + wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), columnActivity(j)) + ) + : unselected; + dc.SetPen(c); + dc.SetBrush(saturate(lerp(background, c, 0.3), selected ? 0.5 : 0)); + dc.DrawRectangle(pos.x + col.offset.x - BORDER, pos.y + col.offset.y - BORDER, + col.size.x + 2*BORDER, col.size.y + 2*BORDER); + } // draw item - drawItem(dc, pos.x, pos.y, i, selected); + drawItem(dc, pos.x, pos.y, i); } } diff --git a/src/gui/control/gallery_list.hpp b/src/gui/control/gallery_list.hpp index 16316784..87e679c4 100644 --- a/src/gui/control/gallery_list.hpp +++ b/src/gui/control/gallery_list.hpp @@ -31,15 +31,24 @@ class GalleryList : public wxPanel { public: GalleryList(Window* parent, int id, int direction = wxHORIZONTAL, bool always_focused = true); - /// Select the given item - void select(size_t item, bool event = true); + /// Select the given column + void selectColumn(size_t column); + /// Select the given item in the given column (or in the active column) + void select(size_t item, size_t column = NO_SELECTION, bool event = true); /// Is there an item selected? - inline bool hasSelection() const { return selection < itemCount(); } + inline bool hasSelection(size_t column = 0) const { return columns[column].selection < itemCount(); } + /// Is the given item selected? + inline bool isSelected(size_t item, size_t column = 0) const { + return column < columns.size() && columns[column].selection == item; + } + + /// Redraw only the selected items + void RefreshSelection(); protected: static const size_t NO_SELECTION = (size_t)-1; - size_t selection; ///< The selected item, or NO_SELECTION if there is no selection - wxSize item_size; ///< The size of a single item + size_t active_column; ///< The active column + wxSize item_size; ///< The total size of a single item (over all columns) int direction; ///< Direction of the list, can be wxHORIZONTAL or wxVERTICAL bool always_focused; ///< Always draw as if focused @@ -49,11 +58,25 @@ class GalleryList : public wxPanel { /// Return how many items there are in the list virtual size_t itemCount() const = 0; /// Draw an item - virtual void drawItem(DC& dc, int x, int y, size_t item, bool selected) = 0; + virtual void drawItem(DC& dc, int x, int y, size_t item) = 0; + /// How 'salient' should the selection in the given column be? + virtual double columnActivity(size_t col) const { return 0.7; } + + /// Filter calls to select, or apply some extra operaions + virtual void onSelect(size_t item, size_t col, bool& changes) {} /// Return the desired size of control virtual wxSize DoGetBestSize() const; + /// Information on the columns + struct Column { + wxPoint offset; + wxSize size; + bool can_select; + size_t selection; + }; + vector columns; + private: DECLARE_EVENT_TABLE(); @@ -97,6 +120,8 @@ class GalleryList : public wxPanel { return direction == wxHORIZONTAL ? s.x : s.y; } + public: + typedef Column Column_for_typeof; protected: /// Send an event void sendEvent(WXTYPE type); diff --git a/src/gui/control/package_list.cpp b/src/gui/control/package_list.cpp index 2c73dd17..34182916 100644 --- a/src/gui/control/package_list.cpp +++ b/src/gui/control/package_list.cpp @@ -18,7 +18,7 @@ DECLARE_TYPEOF_COLLECTION(PackagedP); PackageList::PackageList(Window* parent, int id, int direction, bool always_focused) : GalleryList(parent, id, direction, always_focused) { - item_size = wxSize(108, 150); + item_size = columns[0].size = wxSize(108, 150); SetThemeEnabled(true); } @@ -26,7 +26,7 @@ size_t PackageList::itemCount() const { return packages.size(); } -void PackageList::drawItem(DC& dc, int x, int y, size_t item, bool selected) { +void PackageList::drawItem(DC& dc, int x, int y, size_t item) { PackageData& d = packages.at(item); RealRect rect(RealPoint(x,y),item_size); RealPoint pos; @@ -88,7 +88,7 @@ void PackageList::clear() { void PackageList::select(const String& name, bool send_event) { for (vector::const_iterator it = packages.begin() ; it != packages.end() ; ++it) { if (it->package->name() == name) { - selection = it - packages.begin(); + columns[0].selection = it - packages.begin(); update(); if (send_event) { sendEvent(EVENT_GALLERY_SELECT); @@ -96,7 +96,7 @@ void PackageList::select(const String& name, bool send_event) { return; } } - selection = NO_SELECTION; + columns[0].selection = NO_SELECTION; update(); return; } diff --git a/src/gui/control/package_list.hpp b/src/gui/control/package_list.hpp index f4a412f5..e89af790 100644 --- a/src/gui/control/package_list.hpp +++ b/src/gui/control/package_list.hpp @@ -39,7 +39,7 @@ class PackageList : public GalleryList { * Throws if the selection is not of type T */ template intrusive_ptr getSelection(bool load_fully = true) const { - intrusive_ptr ret = dynamic_pointer_cast(packages.at(selection).package); + intrusive_ptr ret = dynamic_pointer_cast(packages.at(columns[0].selection).package); if (!ret) throw InternalError(_("PackageList: Selected package has the wrong type")); if (load_fully) ret->loadFully(); return ret; @@ -52,7 +52,7 @@ class PackageList : public GalleryList { /// Return how many items there are in the list virtual size_t itemCount() const; /// Draw an item - virtual void drawItem(DC& dc, int x, int y, size_t item, bool selected); + virtual void drawItem(DC& dc, int x, int y, size_t item); private: // The default icon to use diff --git a/src/gui/set/stats_panel.cpp b/src/gui/set/stats_panel.cpp index 8b18085a..c1d3156c 100644 --- a/src/gui/set/stats_panel.cpp +++ b/src/gui/set/stats_panel.cpp @@ -27,10 +27,8 @@ DECLARE_TYPEOF_COLLECTION(CardP); typedef pair pair_StatsDimensionP_String; DECLARE_TYPEOF_COLLECTION(pair_StatsDimensionP_String); -// Pick the style here: -#define USE_DIMENSION_LISTS 1 - // ----------------------------------------------------------------------------- : StatCategoryList +#if !USE_DIMENSION_LISTS /// A list of fields of which the statistics can be shown class StatCategoryList : public GalleryList { @@ -38,19 +36,19 @@ class StatCategoryList : public GalleryList { StatCategoryList(Window* parent, int id) : GalleryList(parent, id, wxVERTICAL) { - item_size = wxSize(150, 23); + item_size = columns[0].size = wxSize(150, 23); } void show(const GameP&); /// The selected category inline StatsCategory& getSelection() { - return *categories.at(selection); + return *categories.at(columns[0].selection); } protected: virtual size_t itemCount() const; - virtual void drawItem(DC& dc, int x, int y, size_t item, bool selected); + virtual void drawItem(DC& dc, int x, int y, size_t item); private: GameP game; @@ -69,14 +67,14 @@ void StatCategoryList::show(const GameP& game) { stable_sort(categories.begin(), categories.end(), ComparePositionHint()); update(); // select first item - selection = itemCount() > 0 ? 0 : NO_SELECTION; + columns[0].selection = itemCount() > 0 ? 0 : NO_SELECTION; } size_t StatCategoryList::itemCount() const { return categories.size(); } -void StatCategoryList::drawItem(DC& dc, int x, int y, size_t item, bool selected) { +void StatCategoryList::drawItem(DC& dc, int x, int y, size_t item) { StatsCategory& cat = *categories.at(item); // draw icon if (!cat.icon_filename.empty() && !cat.icon.Ok()) { @@ -101,28 +99,74 @@ void StatCategoryList::drawItem(DC& dc, int x, int y, size_t item, bool selected } // ----------------------------------------------------------------------------- : StatDimensionList +#else /// A list of fields of which the statistics can be shown class StatDimensionList : public GalleryList { public: - StatDimensionList(Window* parent, int id, bool show_empty) - : GalleryList(parent, id, wxVERTICAL) + StatDimensionList(Window* parent, int id, bool show_empty, int dimension_count = 3) + : GalleryList(parent, id, wxVERTICAL, false) , show_empty(show_empty) + , dimension_count(dimension_count) + , prefered_dimension_count(dimension_count) { - item_size = wxSize(150, 23); + //item_size = wxSize(150, 23); + columns[0].size = wxSize(140,23); + if (dimension_count > 0) { + columns[0].selection = NO_SELECTION; + columns[0].can_select = false; + active_column = 1; + } + // additional columns + Column col; + col.selection = show_empty ? NO_SELECTION : 0; + col.can_select = true; + col.offset.x = columns[0].size.x + SPACING; + col.size = wxSize(18,23); + for (int i = 0 ; i < dimension_count ; ++i) { + columns.push_back(col); + col.offset.x += col.size.x + SPACING; + } + // total + item_size = wxSize(col.offset.x - SPACING, 23); } void show(const GameP&); /// The selected category - inline StatsDimensionP getSelection() { - if (show_empty && selection == 0) return StatsDimensionP(); - return dimensions.at(selection - show_empty); + StatsDimensionP getSelection(size_t column=(size_t)-1) { + size_t sel = columns[column+1].selection - show_empty; + if (sel >= itemCount()) return StatsDimensionP(); + else return dimensions.at(sel); } + /// The number of dimensions shown + const int dimension_count; + size_t prefered_dimension_count; + protected: virtual size_t itemCount() const; - virtual void drawItem(DC& dc, int x, int y, size_t item, bool selected); + virtual void drawItem(DC& dc, int x, int y, size_t item); + + virtual double columnActivity(size_t col) const { + return col-1 >= prefered_dimension_count ? 0.2 : 0.7; + } + + virtual void onSelect(size_t item, size_t col, bool& changes) { + // swap selection with another column? + for (size_t j = 1 ; j < columns.size() ; ++j) { + if (j != col && columns[j].selection == item) { + columns[j].selection = columns[col].selection; + changes = true; + break; + } + } + // update prefered dimension count? + if (col > prefered_dimension_count) { + prefered_dimension_count = col; + changes = true; + } + } private: GameP game; @@ -142,14 +186,21 @@ void StatDimensionList::show(const GameP& game) { stable_sort(dimensions.begin(), dimensions.end(), ComparePositionHint2()); update(); // select first item - selection = itemCount() > 0 ? 0 : NO_SELECTION; + if (dimension_count > 0) { + for (int j = 0 ; j < dimension_count ; ++j) { + columns[j+1].selection = itemCount() > 0 ? 0 : NO_SELECTION; + } + prefered_dimension_count = 1; + } else { + columns[0].selection = itemCount() > 0 ? 0 : NO_SELECTION; + } } size_t StatDimensionList::itemCount() const { return dimensions.size() + show_empty; } -void StatDimensionList::drawItem(DC& dc, int x, int y, size_t item, bool selected) { +void StatDimensionList::drawItem(DC& dc, int x, int y, size_t item) { if (show_empty && item == 0) { RealRect rect(RealPoint(x + 24, y), RealSize(item_size.x - 30, item_size.y)); String str = _("None"); @@ -182,8 +233,22 @@ void StatDimensionList::drawItem(DC& dc, int x, int y, size_t item, bool selecte RealSize size = RealSize(w,h); RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, size, rect); dc.DrawText(str, (int)pos.x, (int)pos.y); + // draw selection icon + for (size_t j = 1 ; j <= prefered_dimension_count ; ++j) { + if (isSelected(item,j)) { + // TODO: different icons for different dimensions + /* + int cx = x + columns[j].offset.x + columns[j].size.x/2; + int cy = y + columns[j].offset.y + columns[j].size.y/2; + dc.SetPen(*wxTRANSPARENT_PEN); + dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); + dc.DrawCircle(cx,cy,6); + */ + } + } } +#endif // ----------------------------------------------------------------------------- : StatsPanel StatsPanel::StatsPanel(Window* parent, int id) @@ -192,10 +257,12 @@ StatsPanel::StatsPanel(Window* parent, int id) { // init controls wxSplitterWindow* splitter; - #if USE_DIMENSION_LISTS + #if USE_SEPARATE_DIMENSION_LISTS for (int i = 0 ; i < 3 ; ++i) { dimensions[i] = new StatDimensionList(this, ID_FIELD_LIST, i > 0); } + #elif USE_DIMENSION_LISTS + dimensions = new StatDimensionList(this, ID_FIELD_LIST, false, 3); #else categories = new StatCategoryList(this, ID_FIELD_LIST); #endif @@ -208,12 +275,14 @@ StatsPanel::StatsPanel(Window* parent, int id) splitter->SplitHorizontally(graph, card_list, -170); // init sizer wxSizer* s = new wxBoxSizer(wxHORIZONTAL); - #if USE_DIMENSION_LISTS + #if USE_SEPARATE_DIMENSION_LISTS wxSizer* s2 = new wxBoxSizer(wxVERTICAL); s2->Add(dimensions[0], 1, wxBOTTOM, 2); s2->Add(dimensions[1], 1, wxBOTTOM, 2); s2->Add(dimensions[2], 1); s->Add(s2, 0, wxEXPAND | wxRIGHT, 2); + #elif USE_DIMENSION_LISTS + s->Add(dimensions, 0, wxEXPAND | wxRIGHT, 2); #else s->Add(categories, 0, wxEXPAND | wxRIGHT, 2); #endif @@ -236,8 +305,10 @@ StatsPanel::~StatsPanel() { void StatsPanel::onChangeSet() { card_list->setSet(set); - #if USE_DIMENSION_LISTS + #if USE_SEPARATE_DIMENSION_LISTS for (int i = 0 ; i < 3 ; ++i) dimensions[i]->show(set->game); + #elif USE_DIMENSION_LISTS + dimensions->show(set->game); #else categories->show(set->game); #endif @@ -252,7 +323,7 @@ void StatsPanel::initUI (wxToolBar* tb, wxMenuBar* mb) { active = true; if (!up_to_date) showCategory(); // Toolbar - #if USE_DIMENSION_LISTS + #if USE_DIMENSION_LISTS || USE_SEPARATE_DIMENSION_LISTS tb->AddTool(ID_GRAPH_PIE, _(""), load_resource_tool_image(_("graph_pie")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("pie"), _HELP_("pie")); tb->AddTool(ID_GRAPH_BAR, _(""), load_resource_tool_image(_("graph_bar")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("bar"), _HELP_("bar")); tb->AddTool(ID_GRAPH_STACK, _(""), load_resource_tool_image(_("graph_stack")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("stack"), _HELP_("stack")); @@ -265,7 +336,7 @@ void StatsPanel::initUI (wxToolBar* tb, wxMenuBar* mb) { } void StatsPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) { active = false; - #if USE_DIMENSION_LISTS + #if USE_DIMENSION_LISTS || USE_SEPARATE_DIMENSION_LISTS // Toolbar tb->DeleteTool(ID_GRAPH_PIE); tb->DeleteTool(ID_GRAPH_BAR); @@ -282,7 +353,9 @@ void StatsPanel::onUpdateUI(wxUpdateUIEvent& ev) { case ID_GRAPH_PIE: case ID_GRAPH_BAR: case ID_GRAPH_STACK: case ID_GRAPH_SCATTER: case ID_GRAPH_SCATTER_PIE: { GraphType type = (GraphType)(ev.GetId() - ID_GRAPH_PIE); ev.Check(graph->getLayout() == type); - ev.Enable(graph->getDimensionality() == dimensionality(type)); + #if USE_SEPARATE_DIMENSION_LISTS + ev.Enable(graph->getDimensionality() == dimensionality(type)); + #endif break; } } @@ -296,8 +369,7 @@ void StatsPanel::onCommand(int id) { } case ID_GRAPH_PIE: case ID_GRAPH_BAR: case ID_GRAPH_STACK: case ID_GRAPH_SCATTER: case ID_GRAPH_SCATTER_PIE: { GraphType type = (GraphType)(id - ID_GRAPH_PIE); - graph->setLayout(type); - graph->Refresh(false); + showLayout(type); break; } } @@ -338,51 +410,25 @@ void StatsPanel::onChange() { } } -void StatsPanel::showCategory() { +void StatsPanel::showCategory(const GraphType* prefer_layout) { up_to_date = true; - // change graph data - #if USE_DIMENSION_LISTS - GraphDataPre d; - // create axes + // find dimensions and layout + #if USE_DIMENSION_LISTS || USE_SEPARATE_DIMENSION_LISTS + // dimensions vector dims; - for (int i = 0 ; i < 3 ; ++i) { - StatsDimensionP dim = dimensions[i]->getSelection(); - if (!dim) continue; - dims.push_back(dim); - d.axes.push_back(new_intrusive5( - dim->name, - dim->colors.empty() ? AUTO_COLOR_EVEN : AUTO_COLOR_NO, - dim->numeric, - &dim->colors, - dim->groups.empty() ? nullptr : &dim->groups - ) - ); - } - // find values - FOR_EACH(card, set->cards) { - Context& ctx = set->getContext(card); - GraphElementP e(new GraphElement); - bool show = true; - FOR_EACH(dim, dims) { - String value = untag(dim->script.invoke(ctx)->toString()); - e->values.push_back(value); - if (value.empty() && !dim->show_empty) { - // don't show this element - show = false; - break; - } + #if USE_SEPARATE_DIMENSION_LISTS + for (int i = 0 ; i < 3 ; ++i) { + StatsDimensionP dim = dimensions[i]->getSelection(); + if (dim) dims.push_back(dim); } - if (show) { - d.elements.push_back(e); + #else // USE_DIMENSION_LISTS + for (size_t i = 0 ; i < dimensions->prefered_dimension_count ; ++i) { + StatsDimensionP dim = dimensions->getSelection(i); + if (dim) dims.push_back(dim); } - } - // split lists - size_t dim_id = 0; - FOR_EACH(dim, dims) { - if (dim->split_list) d.splitList(dim_id); - ++dim_id; - } - GraphType layout = graph->getLayout(); + #endif + // layout + GraphType layout = prefer_layout ? *prefer_layout : graph->getLayout(); if (dimensionality(layout) != dims.size()) { // we must switch to another layout layout = dims.size() == 1 ? GRAPH_TYPE_BAR @@ -390,87 +436,98 @@ void StatsPanel::showCategory() { ? GRAPH_TYPE_SCATTER : GRAPH_TYPE_STACK) : GRAPH_TYPE_SCATTER_PIE; } - graph->setLayout(layout, true); - graph->setData(d); - filterCards(); #else - if (categories->hasSelection()) { - StatsCategory& cat = categories->getSelection(); - GraphDataPre d; - cat.find_dimensions(set->game->statistics_dimensions); - // create axes - FOR_EACH(dim, cat.dimensions) { - d.axes.push_back(new_intrusive5( - dim->name, - dim->colors.empty() ? AUTO_COLOR_EVEN : AUTO_COLOR_NO, - dim->numeric, - &dim->colors, - dim->groups.empty() ? nullptr : &dim->groups - ) - ); + if (!categories->hasSelection()) return + StatsCategory& cat = categories->getSelection(); + // dimensions + cat.find_dimensions(set->game->statistics_dimensions); + vector& dims = cat.dimensions; + // layout + GraphType layout = cat.type; + #endif + // create axes + GraphDataPre d; + FOR_EACH(dim, dims) { + d.axes.push_back(new_intrusive5( + dim->name, + dim->colors.empty() ? AUTO_COLOR_EVEN : AUTO_COLOR_NO, + dim->numeric, + &dim->colors, + dim->groups.empty() ? nullptr : &dim->groups + ) + ); + } + // find values + FOR_EACH(card, set->cards) { + Context& ctx = set->getContext(card); + GraphElementP e(new GraphElement); + bool show = true; + FOR_EACH(dim, dims) { + String value = untag(dim->script.invoke(ctx)->toString()); + e->values.push_back(value); + if (value.empty() && !dim->show_empty) { + // don't show this element + show = false; + break; } - // find values - FOR_EACH(card, set->cards) { - Context& ctx = set->getContext(card); - GraphElementP e(new GraphElement); - bool show = true; - FOR_EACH(dim, cat.dimensions) { - String value = untag(dim->script.invoke(ctx)->toString()); - e->values.push_back(value); - if (value.empty() && !dim->show_empty) { - // don't show this element - show = false; - break; - } - } - if (show) { - d.elements.push_back(e); - } - } - // split lists - size_t dim_id = 0; - FOR_EACH(dim, cat.dimensions) { - if (dim->split_list) d.splitList(dim_id); - ++dim_id; - } - graph->setLayout(cat.type); - graph->setData(d); - filterCards(); + } + if (show) { + d.elements.push_back(e); + } + } + // split lists + size_t dim_id = 0; + FOR_EACH(dim, dims) { + if (dim->split_list) d.splitList(dim_id); + ++dim_id; + } + // update graph and card list + graph->setLayout(layout, true); + graph->setData(d); + filterCards(); +} +void StatsPanel::showLayout(GraphType layout) { + #if USE_DIMENSION_LISTS && !USE_SEPARATE_DIMENSION_LISTS + // make sure we have the right number of data dimensions + if (dimensions->prefered_dimension_count != dimensionality(layout)) { + dimensions->prefered_dimension_count = dimensionality(layout); + showCategory(&layout); // full update + dimensions->RefreshSelection(); + return; } #endif + graph->setLayout(layout); + graph->Refresh(false); } void StatsPanel::onGraphSelect(wxCommandEvent&) { filterCards(); } void StatsPanel::filterCards() { - #if USE_DIMENSION_LISTS - intrusive_ptr filter(new StatsFilter(*set)); - int dims = 0; + #if USE_SEPARATE_DIMENSION_LISTS + vector dims; for (int i = 0 ; i < 3 ; ++i) { StatsDimensionP dim = dimensions[i]->getSelection(); - if (!dim) continue; - ++dims; - if (graph->hasSelection(i)) { - filter->values.push_back(make_pair(dim, graph->getSelection(i))); - } + if (dim) dims.push_back(dim); + } + #elif USE_DIMENSION_LISTS + vector dims; + for (size_t i = 0 ; i < dimensions->prefered_dimension_count ; ++i) { + StatsDimensionP dim = dimensions->getSelection(i); + if (dim) dims.push_back(dim); } - if (dims == 0) return; - card_list->setFilter(filter); #else if (!categories->hasSelection()) return; - intrusive_ptr filter(new StatsFilter(*set)); - StatsCategory& cat = categories->getSelection(); - vector > values; - int i = 0; - FOR_EACH(dim, cat.dimensions) { - if (graph->hasSelection(i)) { - filter->values.push_back(make_pair(dim, graph->getSelection(i))); - } - i++; - } - card_list->setFilter(filter); + const StatsCategory& cat = categories->getSelection(); + const vector& dims = cat.dimensions; #endif + intrusive_ptr filter(new StatsFilter(*set)); + for (size_t i = 0 ; i < dims.size() ; ++i) { + if (graph->hasSelection(i)) { + filter->values.push_back(make_pair(dims[i], graph->getSelection(i))); + } + } + card_list->setFilter(filter); } BEGIN_EVENT_TABLE(StatsPanel, wxPanel) diff --git a/src/gui/set/stats_panel.hpp b/src/gui/set/stats_panel.hpp index 2ac31510..f6a66914 100644 --- a/src/gui/set/stats_panel.hpp +++ b/src/gui/set/stats_panel.hpp @@ -11,6 +11,7 @@ #include #include +#include class StatCategoryList; class StatDimensionList; @@ -18,6 +19,10 @@ class GraphControl; class FilteredCardList; class IconMenu; +// Pick the style here: +#define USE_DIMENSION_LISTS 1 +#define USE_SEPARATE_DIMENSION_LISTS 0 + // ----------------------------------------------------------------------------- : StatsPanel /// A panel for showing statistics on cards @@ -44,8 +49,13 @@ class StatsPanel : public SetWindowPanel { private: DECLARE_EVENT_TABLE(); - StatCategoryList* categories; - StatDimensionList* dimensions[3]; + #if USE_SEPARATE_DIMENSION_LISTS + StatDimensionList* dimensions[3]; + #elif USE_DIMENSION_LISTS + StatDimensionList* dimensions; + #else + StatCategoryList* categories; + #endif GraphControl* graph; FilteredCardList* card_list; IconMenu* menuGraph; @@ -55,7 +65,8 @@ class StatsPanel : public SetWindowPanel { void onChange(); void onGraphSelect(wxCommandEvent&); - void showCategory(); + void showCategory(const GraphType* prefer_layout = nullptr); + void showLayout(GraphType); void filterCards(); };