Commit e5abf752 authored by twanvl's avatar twanvl

filtered card list is used

parent fcc1478c
...@@ -18,6 +18,10 @@ DECLARE_TYPEOF_COLLECTION(int); ...@@ -18,6 +18,10 @@ DECLARE_TYPEOF_COLLECTION(int);
typedef map<String,UInt> map_String_UInt; typedef map<String,UInt> map_String_UInt;
DECLARE_TYPEOF(map_String_UInt); DECLARE_TYPEOF(map_String_UInt);
// ----------------------------------------------------------------------------- : Events
DEFINE_EVENT_TYPE(EVENT_GRAPH_SELECT);
// ----------------------------------------------------------------------------- : GraphData // ----------------------------------------------------------------------------- : GraphData
GraphElement::GraphElement(const String& v1) { GraphElement::GraphElement(const String& v1) {
...@@ -254,21 +258,21 @@ void GraphControl::onMouseDown(wxMouseEvent& ev) { ...@@ -254,21 +258,21 @@ void GraphControl::onMouseDown(wxMouseEvent& ev) {
if (!graph) return; if (!graph) return;
wxSize cs = GetClientSize(); wxSize cs = GetClientSize();
if (graph->findItem(RealPoint(ev.GetX(), ev.GetY()), RealRect(RealPoint(0,0),cs), current_item)) { 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); Refresh(false);
} }
} }
bool GraphControl::hasSelection(size_t axis) const { 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<String>& out) const { String GraphControl::getSelection(size_t axis) const {
out.clear(); if (!graph || axis >= current_item.size() || axis >= graph->getData().axes.size()) return wxEmptyString;
if (!graph) return; GraphAxis& a = *graph->getData().axes[axis];
FOR_EACH_2_CONST(i, current_item, a, graph->getData().axes) { int i = current_item[axis];
if (i >= 0) { if (i == -1 || (size_t)i >= a.groups.size()) return wxEmptyString;
out.push_back((size_t)i < a->groups.size() ? a->groups[i].name : wxEmptyString); return a.groups[current_item[axis]].name;
}
}
} }
BEGIN_EVENT_TABLE(GraphControl, wxControl) BEGIN_EVENT_TABLE(GraphControl, wxControl)
......
...@@ -17,6 +17,13 @@ DECLARE_POINTER_TYPE(GraphElement); ...@@ -17,6 +17,13 @@ DECLARE_POINTER_TYPE(GraphElement);
DECLARE_POINTER_TYPE(GraphData); DECLARE_POINTER_TYPE(GraphData);
DECLARE_POINTER_TYPE(Graph); DECLARE_POINTER_TYPE(Graph);
// ----------------------------------------------------------------------------- : Events
/// Event that indicates the a subset is selected/deselected in a graph
DECLARE_EVENT_TYPE(EVENT_GRAPH_SELECT, <not used>)
/// Handle EVENT_GRAPH_SELECT events
#define EVT_GRAPH_SELECT(id, handler) EVT_COMMAND(id, EVENT_GRAPH_SELECT, handler)
// ----------------------------------------------------------------------------- : Graph data // ----------------------------------------------------------------------------- : Graph data
/// A group in a table or graph /// A group in a table or graph
...@@ -166,8 +173,8 @@ class GraphControl : public wxControl { ...@@ -166,8 +173,8 @@ class GraphControl : public wxControl {
/// Is there a selection on the given axis? /// Is there a selection on the given axis?
bool hasSelection(size_t axis) const; bool hasSelection(size_t axis) const;
/// Get the current item, returns the selected value on each axis in out /// Get the current item along the given axis
void getSelection(vector<String>& out) const; String getSelection(size_t axis) const;
private: private:
/// Graph object /// Graph object
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
DECLARE_TYPEOF_COLLECTION(StatsDimensionP); DECLARE_TYPEOF_COLLECTION(StatsDimensionP);
DECLARE_TYPEOF_COLLECTION(String); DECLARE_TYPEOF_COLLECTION(String);
DECLARE_TYPEOF_COLLECTION(CardP); DECLARE_TYPEOF_COLLECTION(CardP);
typedef pair<StatsDimensionP,String> pair_StatsDimensionP_String;
DECLARE_TYPEOF_COLLECTION(pair_StatsDimensionP_String);
// ----------------------------------------------------------------------------- : StatCategoryList // ----------------------------------------------------------------------------- : StatCategoryList
...@@ -29,7 +31,7 @@ class StatCategoryList : public GalleryList { ...@@ -29,7 +31,7 @@ class StatCategoryList : public GalleryList {
StatCategoryList(Window* parent, int id) StatCategoryList(Window* parent, int id)
: GalleryList(parent, id, wxVERTICAL) : GalleryList(parent, id, wxVERTICAL)
{ {
item_size = wxSize(140, 23); item_size = wxSize(150, 23);
} }
void show(const GameP&); void show(const GameP&);
...@@ -70,12 +72,15 @@ void StatCategoryList::drawItem(DC& dc, int x, int y, size_t item, bool selected ...@@ -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); dc.DrawBitmap(cat.icon, x+1, y+1);
} }
// draw name // 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); 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; int w, h;
dc.GetTextExtent(str, &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); dc.DrawText(str, pos.x, pos.y);
} }
...@@ -132,24 +137,44 @@ void StatsPanel::onCommand(int id) { ...@@ -132,24 +137,44 @@ void StatsPanel::onCommand(int id) {
} }
} }
// ----------------------------------------------------------------------------- : Filtering card list
class StatsFilter : public CardListFilter { class StatsFilter : public CardListFilter {
public: public:
StatsFilter(Set& set, const vector<StatsDimensionP>& dims, const vector<String>& values) StatsFilter(Set& set)
: set(set), dims(dims), values(values) : set(set)
{} {}
virtual bool keep(const CardP& card) { virtual bool keep(const CardP& card) {
Context& ctx = set.getContext(card); Context& ctx = set.getContext(card);
FOR_EACH_2(d, dims, v, values) { FOR_EACH(v, values) {
if (*d->script.invoke(ctx) != v) return false; if (*v.first->script.invoke(ctx) != v.second) return false;
} }
return true; return true;
} }
private:
Set& set; vector<pair<StatsDimensionP, String> > values; ///< Values selected along each dimension
vector<StatsDimensionP> dims; Set& set;
vector<String> values;
}; };
void StatsPanel::onGraphSelect(wxCommandEvent&) {
if (!categories->hasSelection()) return;
shared_ptr<StatsFilter> filter(new StatsFilter(*set));
StatsCategory& cat = categories->getSelection();
vector<pair<StatsDimensionP, String> > 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 // ----------------------------------------------------------------------------- : Selection
CardP StatsPanel::selectedCard() const { CardP StatsPanel::selectedCard() const {
......
...@@ -34,9 +34,13 @@ class StatsPanel : public SetWindowPanel { ...@@ -34,9 +34,13 @@ class StatsPanel : public SetWindowPanel {
// --------------------------------------------------- : Data // --------------------------------------------------- : Data
private: private:
DECLARE_EVENT_TABLE();
StatCategoryList* categories; StatCategoryList* categories;
GraphControl* graph; GraphControl* graph;
FilteredCardList* card_list; FilteredCardList* card_list;
void onGraphSelect(wxCommandEvent&);
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment