Commit 7d6fc3eb authored by twanvl's avatar twanvl

renamed GalleryList member column -> subcolumn, so we can have proper columns later on as well.

parent 51ca47e4
...@@ -325,8 +325,10 @@ void DataEditor::selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const ...@@ -325,8 +325,10 @@ void DataEditor::selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const
} }
void DataEditor::selectFieldNoEvents(const wxMouseEvent& ev) { void DataEditor::selectFieldNoEvents(const wxMouseEvent& ev) {
FOR_EACH_EDITOR_REVERSE { // find high z index fields first FOR_EACH_EDITOR_REVERSE { // find high z index fields first
int y;
if (v->getField()->editable && (v->containsPoint(mousePoint(ev,*v)) || if (v->getField()->editable && (v->containsPoint(mousePoint(ev,*v)) ||
(nativeLook() && ev.GetY() >= v->getStyle()->top && ev.GetY() < v->getStyle()->bottom) )) { (nativeLook() && (y = ev.GetY() + GetScrollPos(wxVERTICAL)) >= v->getStyle()->top
&& y < v->getStyle()->bottom) )) {
current_viewer = v.get(); current_viewer = v.get();
current_editor = e; current_editor = e;
return; return;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <gfx/gfx.hpp> #include <gfx/gfx.hpp>
#include <wx/dcbuffer.h> #include <wx/dcbuffer.h>
DECLARE_TYPEOF_COLLECTION(GalleryList::Column_for_typeof); DECLARE_TYPEOF_COLLECTION(GalleryList::SubColumn_for_typeof);
// ----------------------------------------------------------------------------- : Events // ----------------------------------------------------------------------------- : Events
...@@ -22,35 +22,35 @@ DEFINE_EVENT_TYPE(EVENT_GALLERY_ACTIVATE); ...@@ -22,35 +22,35 @@ 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) )
, active_column(0) , active_subcolumn(0)
, direction(direction) , direction(direction)
, always_focused(always_focused) , always_focused(always_focused)
, visible_start(0) , visible_start(0)
{ {
Column col; SubColumn col;
col.can_select = true; col.can_select = true;
col.selection = NO_SELECTION; col.selection = NO_SELECTION;
columns.push_back(col); subcolumns.push_back(col);
} }
void GalleryList::selectColumn(size_t column) { void GalleryList::selectSubColumn(size_t subcol) {
if (column >= columns.size()) return; if (subcol >= subcolumns.size()) return;
if (!columns[column].can_select) return; if (!subcolumns[subcol].can_select) return;
if (active_column == column) return; if (active_subcolumn == subcol) return;
RefreshItem(columns[active_column].selection); RefreshItem(subcolumns[active_subcolumn].selection);
RefreshItem(columns[column ].selection); RefreshItem(subcolumns[subcol ].selection);
active_column = column; active_subcolumn = subcol;
} }
void GalleryList::select(size_t item, size_t column, bool event) { void GalleryList::select(size_t item, size_t subcolumn, bool event) {
if (item >= itemCount()) return; if (item >= itemCount()) return;
// select column // select column
size_t old_active_column = active_column; size_t old_active_subcolumn = active_subcolumn;
selectColumn(column); selectSubColumn(subcolumn);
Column& col = columns[active_column]; SubColumn& col = subcolumns[active_subcolumn];
// filter? // filter?
bool changes = col.selection != item; bool changes = col.selection != item;
onSelect(item, old_active_column, changes); onSelect(item, old_active_subcolumn, changes);
// select // select
size_t old_sel = col.selection; size_t old_sel = col.selection;
col.selection = item; col.selection = item;
...@@ -71,7 +71,7 @@ void GalleryList::select(size_t item, size_t column, bool event) { ...@@ -71,7 +71,7 @@ void GalleryList::select(size_t item, size_t column, bool event) {
} }
void GalleryList::update() { void GalleryList::update() {
select(columns[active_column].selection); select(subcolumns[active_subcolumn].selection);
updateScrollbar(); updateScrollbar();
Refresh(false); Refresh(false);
} }
...@@ -122,7 +122,7 @@ void GalleryList::RefreshItem(size_t item) { ...@@ -122,7 +122,7 @@ void GalleryList::RefreshItem(size_t item) {
RefreshRect(wxRect(itemPos(item),item_size).Inflate(BORDER,BORDER), false); RefreshRect(wxRect(itemPos(item),item_size).Inflate(BORDER,BORDER), false);
} }
void GalleryList::RefreshSelection() { void GalleryList::RefreshSelection() {
FOR_EACH(col,columns) RefreshItem(col.selection); FOR_EACH(col,subcolumns) RefreshItem(col.selection);
} }
void GalleryList::onScroll(wxScrollWinEvent& ev) { void GalleryList::onScroll(wxScrollWinEvent& ev) {
...@@ -162,16 +162,16 @@ void GalleryList::onLeftDown(wxMouseEvent& ev) { ...@@ -162,16 +162,16 @@ void GalleryList::onLeftDown(wxMouseEvent& ev) {
wxPoint pos = itemPos(item); wxPoint pos = itemPos(item);
int x = ev.GetX() - pos.x; int x = ev.GetX() - pos.x;
int y = ev.GetY() - pos.y; int y = ev.GetY() - pos.y;
size_t column = active_column; size_t subcolumn = active_subcolumn;
for (size_t j = 0 ; columns.size() ; ++j) { for (size_t j = 0 ; subcolumns.size() ; ++j) {
Column& col = columns[j]; SubColumn& col = subcolumns[j];
if (x >= col.offset.x && y >= col.offset.y && x < col.size.x + col.offset.x && y < col.size.y + col.offset.y) { 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 // clicked on this column
column = j; subcolumn = j;
break; break;
} }
} }
select(item, column); select(item, subcolumn);
} }
ev.Skip(); // focus ev.Skip(); // focus
} }
...@@ -181,34 +181,34 @@ void GalleryList::onLeftDClick(wxMouseEvent& ev) { ...@@ -181,34 +181,34 @@ void GalleryList::onLeftDClick(wxMouseEvent& ev) {
} }
void GalleryList::onChar(wxKeyEvent& ev) { void GalleryList::onChar(wxKeyEvent& ev) {
Column& col = columns[active_column]; SubColumn& col = subcolumns[active_subcolumn];
switch (ev.GetKeyCode()) { switch (ev.GetKeyCode()) {
case WXK_LEFT: case WXK_LEFT:
if (direction == wxHORIZONTAL) { if (direction == wxHORIZONTAL) {
select(col.selection - 1); select(col.selection - 1);
} else { } else {
selectColumn(active_column - 1); selectSubColumn(active_subcolumn - 1);
} }
break; break;
case WXK_RIGHT: case WXK_RIGHT:
if (direction == wxHORIZONTAL) { if (direction == wxHORIZONTAL) {
select(col.selection + 1); select(col.selection + 1);
} else { } else {
selectColumn(active_column + 1); selectSubColumn(active_subcolumn + 1);
} }
break; break;
case WXK_UP: case WXK_UP:
if (direction == wxVERTICAL) { if (direction == wxVERTICAL) {
select(col.selection - 1); select(col.selection - 1);
} else { } else {
selectColumn(active_column - 1); selectSubColumn(active_subcolumn - 1);
} }
break; break;
case WXK_DOWN: case WXK_DOWN:
if (direction == wxVERTICAL) { if (direction == wxVERTICAL) {
select(col.selection + 1); select(col.selection + 1);
} else { } else {
selectColumn(active_column + 1); selectSubColumn(active_subcolumn + 1);
} }
break; break;
case WXK_TAB: { case WXK_TAB: {
...@@ -263,13 +263,13 @@ void GalleryList::OnDraw(DC& dc) { ...@@ -263,13 +263,13 @@ void GalleryList::OnDraw(DC& dc) {
for (size_t i = start ; i < end ; ++i) { for (size_t i = start ; i < end ; ++i) {
wxPoint pos = itemPos(i); wxPoint pos = itemPos(i);
// draw selection rectangle // draw selection rectangle
for (size_t j = 0 ; j < columns.size() ; ++j) { for (size_t j = 0 ; j < subcolumns.size() ; ++j) {
const Column& col = columns[j]; const SubColumn& col = subcolumns[j];
bool selected = i == col.selection; bool selected = i == col.selection;
Color c = selected ? ( has_focus && j == active_column Color c = selected ? ( has_focus && j == active_subcolumn
? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT) ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)
: lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW), : lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), columnActivity(j)) wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), subcolumnActivity(j))
) )
: unselected; : unselected;
dc.SetPen(c); dc.SetPen(c);
......
...@@ -32,14 +32,14 @@ class GalleryList : public wxPanel { ...@@ -32,14 +32,14 @@ class GalleryList : public wxPanel {
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 column /// Select the given column
void selectColumn(size_t column); void selectSubColumn(size_t subcol);
/// Select the given item in the given column (or in the active 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); void select(size_t item, size_t subcol = NO_SELECTION, bool event = true);
/// Is there an item selected? /// Is there an item selected?
inline bool hasSelection(size_t column = 0) const { return columns[column].selection < itemCount(); } inline bool hasSelection(size_t subcol = 0) const { return subcolumns[subcol].selection < itemCount(); }
/// Is the given item selected? /// Is the given item selected?
inline bool isSelected(size_t item, size_t column = 0) const { inline bool isSelected(size_t item, size_t subcol = 0) const {
return column < columns.size() && columns[column].selection == item; return subcol < subcolumns.size() && subcolumns[subcol].selection == item;
} }
/// Redraw only the selected items /// Redraw only the selected items
...@@ -47,10 +47,10 @@ class GalleryList : public wxPanel { ...@@ -47,10 +47,10 @@ class GalleryList : public wxPanel {
protected: protected:
static const size_t NO_SELECTION = (size_t)-1; static const size_t NO_SELECTION = (size_t)-1;
size_t active_column; ///< The active column size_t active_subcolumn; ///< The active subcolumn
wxSize item_size; ///< The total size of a single item (over all columns) 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
/// Redraw the list after changing the selection or the number of items /// Redraw the list after changing the selection or the number of items
void update(); void update();
...@@ -59,8 +59,8 @@ class GalleryList : public wxPanel { ...@@ -59,8 +59,8 @@ class GalleryList : public wxPanel {
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) = 0; virtual void drawItem(DC& dc, int x, int y, size_t item) = 0;
/// How 'salient' should the selection in the given column be? /// How 'salient' should the selection in the given subcolumn be?
virtual double columnActivity(size_t col) const { return 0.7; } virtual double subcolumnActivity(size_t col) const { return 0.7; }
/// Filter calls to select, or apply some extra operaions /// Filter calls to select, or apply some extra operaions
virtual void onSelect(size_t item, size_t col, bool& changes) {} virtual void onSelect(size_t item, size_t col, bool& changes) {}
...@@ -68,14 +68,14 @@ class GalleryList : public wxPanel { ...@@ -68,14 +68,14 @@ class GalleryList : public wxPanel {
/// Return the desired size of control /// Return the desired size of control
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;
/// Information on the columns /// Information on the subcolumns. These are columns inside items
struct Column { struct SubColumn {
wxPoint offset; wxPoint offset;
wxSize size; wxSize size;
bool can_select; bool can_select;
size_t selection; size_t selection;
}; };
vector<Column> columns; vector<SubColumn> subcolumns;
private: private:
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
...@@ -121,7 +121,7 @@ class GalleryList : public wxPanel { ...@@ -121,7 +121,7 @@ class GalleryList : public wxPanel {
} }
public: public:
typedef Column Column_for_typeof; typedef SubColumn SubColumn_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 = columns[0].size = wxSize(108, 150); item_size = subcolumns[0].size = wxSize(108, 150);
SetThemeEnabled(true); SetThemeEnabled(true);
} }
...@@ -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) {
columns[0].selection = it - packages.begin(); subcolumns[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;
} }
} }
columns[0].selection = NO_SELECTION; subcolumns[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(columns[0].selection).package); intrusive_ptr<T> ret = dynamic_pointer_cast<T>(packages.at(subcolumns[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;
......
...@@ -38,14 +38,14 @@ class StatCategoryList : public GalleryList { ...@@ -38,14 +38,14 @@ class StatCategoryList : public GalleryList {
StatCategoryList(Window* parent, int id) StatCategoryList(Window* parent, int id)
: GalleryList(parent, id, wxVERTICAL) : GalleryList(parent, id, wxVERTICAL)
{ {
item_size = columns[0].size = wxSize(150, 23); item_size = subcolumns[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(columns[0].selection); return *categories.at(subcolumns[0].selection);
} }
protected: protected:
...@@ -69,7 +69,7 @@ void StatCategoryList::show(const GameP& game) { ...@@ -69,7 +69,7 @@ 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
columns[0].selection = itemCount() > 0 ? 0 : NO_SELECTION; subcolumns[0].selection = itemCount() > 0 ? 0 : NO_SELECTION;
} }
size_t StatCategoryList::itemCount() const { size_t StatCategoryList::itemCount() const {
...@@ -114,20 +114,20 @@ class StatDimensionList : public GalleryList { ...@@ -114,20 +114,20 @@ class StatDimensionList : public GalleryList {
, prefered_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); subcolumns[0].size = wxSize(140,23);
if (dimension_count > 0) { if (dimension_count > 0) {
columns[0].selection = NO_SELECTION; subcolumns[0].selection = NO_SELECTION;
columns[0].can_select = false; subcolumns[0].can_select = false;
active_column = 1; active_subcolumn = 1;
} }
// additional columns // additional columns
Column col; SubColumn col;
col.selection = show_empty ? NO_SELECTION : 0; col.selection = show_empty ? NO_SELECTION : 0;
col.can_select = true; col.can_select = true;
col.offset.x = columns[0].size.x + SPACING; col.offset.x = subcolumns[0].size.x + SPACING;
col.size = wxSize(18,23); col.size = wxSize(18,23);
for (int i = 0 ; i < dimension_count ; ++i) { for (int i = 0 ; i < dimension_count ; ++i) {
columns.push_back(col); subcolumns.push_back(col);
col.offset.x += col.size.x + SPACING; col.offset.x += col.size.x + SPACING;
} }
// total // total
...@@ -137,8 +137,8 @@ class StatDimensionList : public GalleryList { ...@@ -137,8 +137,8 @@ class StatDimensionList : public GalleryList {
void show(const GameP&); void show(const GameP&);
/// The selected category /// The selected category
StatsDimensionP getSelection(size_t column=(size_t)-1) { StatsDimensionP getSelection(size_t subcol=(size_t)-1) {
size_t sel = columns[column+1].selection - show_empty; size_t sel = subcolumns[subcol+1].selection - show_empty;
if (sel >= itemCount()) return StatsDimensionP(); if (sel >= itemCount()) return StatsDimensionP();
else return dimensions.at(sel); else return dimensions.at(sel);
} }
...@@ -149,7 +149,7 @@ class StatDimensionList : public GalleryList { ...@@ -149,7 +149,7 @@ class StatDimensionList : public GalleryList {
void restrictDimensions(size_t dims) { void restrictDimensions(size_t dims) {
prefered_dimension_count = dims; prefered_dimension_count = dims;
active_column = min(active_column, dims); active_subcolumn = min(active_subcolumn, dims);
RefreshSelection(); RefreshSelection();
} }
...@@ -157,33 +157,34 @@ class StatDimensionList : public GalleryList { ...@@ -157,33 +157,34 @@ class StatDimensionList : public GalleryList {
virtual size_t itemCount() const; virtual size_t itemCount() const;
virtual void drawItem(DC& dc, int x, int y, size_t item); virtual void drawItem(DC& dc, int x, int y, size_t item);
virtual double columnActivity(size_t col) const { virtual double subcolumnActivity(size_t col) const {
return col-1 >= prefered_dimension_count ? 0.2 : 0.7; return col-1 >= prefered_dimension_count ? 0.2 : 0.7;
} }
virtual void onSelect(size_t item, size_t old_col, bool& changes) { virtual void onSelect(size_t item, size_t old_col, bool& changes) {
// swap selection with another column? // swap selection with another subcolumn?
for (size_t j = 1 ; j < columns.size() ; ++j) { for (size_t j = 1 ; j < subcolumns.size() ; ++j) {
if (j != active_column && columns[j].selection == item && columns[active_column].selection != item) { if (j != active_subcolumn && subcolumns[j].selection == item &&
columns[j].selection = columns[active_column].selection; subcolumns[active_subcolumn].selection != item) {
subcolumns[j].selection = subcolumns[active_subcolumn].selection;
changes = true; changes = true;
break; break;
} }
} }
// update prefered dimension count? // update prefered dimension count?
if (active_column > prefered_dimension_count) { if (active_subcolumn > prefered_dimension_count) {
prefered_dimension_count = active_column; prefered_dimension_count = active_subcolumn;
changes = true; changes = true;
RefreshSelection(); RefreshSelection();
} }
// decrease dimension count? (toggle last dimension) // decrease dimension count? (toggle last dimension)
if (!changes && old_col == active_column) { if (!changes && old_col == active_subcolumn) {
if (active_column == prefered_dimension_count && prefered_dimension_count > 1) { if (active_subcolumn == prefered_dimension_count && prefered_dimension_count > 1) {
prefered_dimension_count -= 1; prefered_dimension_count -= 1;
selectColumn(prefered_dimension_count); selectSubColumn(prefered_dimension_count);
changes = true; changes = true;
} else if (active_column != prefered_dimension_count) { } else if (active_subcolumn != prefered_dimension_count) {
active_column = prefered_dimension_count = active_column; active_subcolumn = prefered_dimension_count = active_subcolumn;
RefreshSelection(); RefreshSelection();
changes = true; changes = true;
} }
...@@ -210,11 +211,11 @@ void StatDimensionList::show(const GameP& game) { ...@@ -210,11 +211,11 @@ void StatDimensionList::show(const GameP& game) {
// select first item // select first item
if (dimension_count > 0) { if (dimension_count > 0) {
for (int j = 0 ; j < dimension_count ; ++j) { for (int j = 0 ; j < dimension_count ; ++j) {
columns[j+1].selection = itemCount() > 0 ? 0 : NO_SELECTION; subcolumns[j+1].selection = itemCount() > 0 ? 0 : NO_SELECTION;
} }
prefered_dimension_count = 1; prefered_dimension_count = 1;
} else { } else {
columns[0].selection = itemCount() > 0 ? 0 : NO_SELECTION; subcolumns[0].selection = itemCount() > 0 ? 0 : NO_SELECTION;
} }
} }
......
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