diff --git a/src/gui/control/graph.cpp b/src/gui/control/graph.cpp index 9a539772..732bf0b9 100644 --- a/src/gui/control/graph.cpp +++ b/src/gui/control/graph.cpp @@ -18,6 +18,10 @@ DECLARE_TYPEOF_COLLECTION(int); typedef map map_String_UInt; DECLARE_TYPEOF(map_String_UInt); +// ----------------------------------------------------------------------------- : Events + +DEFINE_EVENT_TYPE(EVENT_GRAPH_SELECT); + // ----------------------------------------------------------------------------- : GraphData GraphElement::GraphElement(const String& v1) { @@ -254,21 +258,21 @@ void GraphControl::onMouseDown(wxMouseEvent& ev) { if (!graph) return; wxSize cs = GetClientSize(); if (graph->findItem(RealPoint(ev.GetX(), ev.GetY()), RealRect(RealPoint(0,0),cs), current_item)) { + wxCommandEvent ev(EVENT_GRAPH_SELECT, GetId()); + ProcessEvent(ev); Refresh(false); } } bool GraphControl::hasSelection(size_t axis) const { - return current_item.size() >= axis && current_item[axis] >= 0; + return axis < current_item.size() && current_item[axis] >= 0; } -void GraphControl::getSelection(vector& out) const { - out.clear(); - if (!graph) return; - FOR_EACH_2_CONST(i, current_item, a, graph->getData().axes) { - if (i >= 0) { - out.push_back((size_t)i < a->groups.size() ? a->groups[i].name : wxEmptyString); - } - } +String GraphControl::getSelection(size_t axis) const { + if (!graph || axis >= current_item.size() || axis >= graph->getData().axes.size()) return wxEmptyString; + GraphAxis& a = *graph->getData().axes[axis]; + int i = current_item[axis]; + if (i == -1 || (size_t)i >= a.groups.size()) return wxEmptyString; + return a.groups[current_item[axis]].name; } BEGIN_EVENT_TABLE(GraphControl, wxControl) diff --git a/src/gui/control/graph.hpp b/src/gui/control/graph.hpp index df148b71..bf58dc8c 100644 --- a/src/gui/control/graph.hpp +++ b/src/gui/control/graph.hpp @@ -17,6 +17,13 @@ DECLARE_POINTER_TYPE(GraphElement); DECLARE_POINTER_TYPE(GraphData); DECLARE_POINTER_TYPE(Graph); +// ----------------------------------------------------------------------------- : Events + +/// Event that indicates the a subset is selected/deselected in a graph +DECLARE_EVENT_TYPE(EVENT_GRAPH_SELECT, ) +/// Handle EVENT_GRAPH_SELECT events +#define EVT_GRAPH_SELECT(id, handler) EVT_COMMAND(id, EVENT_GRAPH_SELECT, handler) + // ----------------------------------------------------------------------------- : Graph data /// A group in a table or graph @@ -166,8 +173,8 @@ class GraphControl : public wxControl { /// Is there a selection on the given axis? bool hasSelection(size_t axis) const; - /// Get the current item, returns the selected value on each axis in out - void getSelection(vector& out) const; + /// Get the current item along the given axis + String getSelection(size_t axis) const; private: /// Graph object diff --git a/src/gui/set/stats_panel.cpp b/src/gui/set/stats_panel.cpp index b8d6b715..a8809895 100644 --- a/src/gui/set/stats_panel.cpp +++ b/src/gui/set/stats_panel.cpp @@ -20,6 +20,8 @@ DECLARE_TYPEOF_COLLECTION(StatsDimensionP); DECLARE_TYPEOF_COLLECTION(String); DECLARE_TYPEOF_COLLECTION(CardP); +typedef pair pair_StatsDimensionP_String; +DECLARE_TYPEOF_COLLECTION(pair_StatsDimensionP_String); // ----------------------------------------------------------------------------- : StatCategoryList @@ -29,7 +31,7 @@ class StatCategoryList : public GalleryList { StatCategoryList(Window* parent, int id) : GalleryList(parent, id, wxVERTICAL) { - item_size = wxSize(140, 23); + item_size = wxSize(150, 23); } void show(const GameP&); @@ -70,12 +72,15 @@ void StatCategoryList::drawItem(DC& dc, int x, int y, size_t item, bool selected dc.DrawBitmap(cat.icon, x+1, y+1); } // draw name - RealRect rect(RealPoint(x + 23, y), RealSize(item_size.width - 30, item_size.height)); + RealRect rect(RealPoint(x + 24, y), RealSize(item_size.width - 30, item_size.height)); String str = capitalize(cat.name); - dc.SetFont(wxFont(10,wxSWISS,wxNORMAL,wxBOLD,false,_("Arial"))); +// dc.SetFont(wxFont(9.5 * text_scaling, wxSWISS, wxNORMAL, wxNORMAL, false,_("Arial"))); + dc.SetFont(*wxNORMAL_FONT); int w, h; dc.GetTextExtent(str, &w, &h); - RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(w,h), rect); + RealSize size = RealSize(w,h); + RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, size, rect); +// draw_resampled_text(dc, RealRect(pos, size), 0, 0, 0, str); dc.DrawText(str, pos.x, pos.y); } @@ -132,24 +137,44 @@ void StatsPanel::onCommand(int id) { } } +// ----------------------------------------------------------------------------- : Filtering card list + class StatsFilter : public CardListFilter { public: - StatsFilter(Set& set, const vector& dims, const vector& values) - : set(set), dims(dims), values(values) + StatsFilter(Set& set) + : set(set) {} virtual bool keep(const CardP& card) { Context& ctx = set.getContext(card); - FOR_EACH_2(d, dims, v, values) { - if (*d->script.invoke(ctx) != v) return false; + FOR_EACH(v, values) { + if (*v.first->script.invoke(ctx) != v.second) return false; } return true; } - private: - Set& set; - vector dims; - vector values; + + vector > values; ///< Values selected along each dimension + Set& set; }; +void StatsPanel::onGraphSelect(wxCommandEvent&) { + if (!categories->hasSelection()) return; + shared_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); +} + +BEGIN_EVENT_TABLE(StatsPanel, wxPanel) + EVT_GRAPH_SELECT(wxID_ANY, StatsPanel::onGraphSelect) +END_EVENT_TABLE() + // ----------------------------------------------------------------------------- : Selection CardP StatsPanel::selectedCard() const { diff --git a/src/gui/set/stats_panel.hpp b/src/gui/set/stats_panel.hpp index cfed3c96..28a4c369 100644 --- a/src/gui/set/stats_panel.hpp +++ b/src/gui/set/stats_panel.hpp @@ -34,9 +34,13 @@ class StatsPanel : public SetWindowPanel { // --------------------------------------------------- : Data private: + DECLARE_EVENT_TABLE(); + StatCategoryList* categories; GraphControl* graph; FilteredCardList* card_list; + + void onGraphSelect(wxCommandEvent&); }; // ----------------------------------------------------------------------------- : EOF