Commit 6d6721b6 authored by twanvl's avatar twanvl

All three dimensions on stats panel in a single multicolumn list

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