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
......
This diff is collapsed.
...@@ -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