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
}
void DataEditor::selectFieldNoEvents(const wxMouseEvent& ev) {
FOR_EACH_EDITOR_REVERSE { // find high z index fields first
int y;
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_editor = e;
return;
......
......@@ -11,7 +11,7 @@
#include <gfx/gfx.hpp>
#include <wx/dcbuffer.h>
DECLARE_TYPEOF_COLLECTION(GalleryList::Column_for_typeof);
DECLARE_TYPEOF_COLLECTION(GalleryList::SubColumn_for_typeof);
// ----------------------------------------------------------------------------- : Events
......@@ -22,35 +22,35 @@ DEFINE_EVENT_TYPE(EVENT_GALLERY_ACTIVATE);
GalleryList::GalleryList(Window* parent, int id, int direction, bool always_focused)
: wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER | wxWANTS_CHARS | (direction == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL) )
, active_column(0)
, active_subcolumn(0)
, direction(direction)
, always_focused(always_focused)
, visible_start(0)
{
Column col;
SubColumn col;
col.can_select = true;
col.selection = NO_SELECTION;
columns.push_back(col);
subcolumns.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::selectSubColumn(size_t subcol) {
if (subcol >= subcolumns.size()) return;
if (!subcolumns[subcol].can_select) return;
if (active_subcolumn == subcol) return;
RefreshItem(subcolumns[active_subcolumn].selection);
RefreshItem(subcolumns[subcol ].selection);
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;
// select column
size_t old_active_column = active_column;
selectColumn(column);
Column& col = columns[active_column];
size_t old_active_subcolumn = active_subcolumn;
selectSubColumn(subcolumn);
SubColumn& col = subcolumns[active_subcolumn];
// filter?
bool changes = col.selection != item;
onSelect(item, old_active_column, changes);
onSelect(item, old_active_subcolumn, changes);
// select
size_t old_sel = col.selection;
col.selection = item;
......@@ -71,7 +71,7 @@ void GalleryList::select(size_t item, size_t column, bool event) {
}
void GalleryList::update() {
select(columns[active_column].selection);
select(subcolumns[active_subcolumn].selection);
updateScrollbar();
Refresh(false);
}
......@@ -122,7 +122,7 @@ void GalleryList::RefreshItem(size_t item) {
RefreshRect(wxRect(itemPos(item),item_size).Inflate(BORDER,BORDER), false);
}
void GalleryList::RefreshSelection() {
FOR_EACH(col,columns) RefreshItem(col.selection);
FOR_EACH(col,subcolumns) RefreshItem(col.selection);
}
void GalleryList::onScroll(wxScrollWinEvent& ev) {
......@@ -162,16 +162,16 @@ void GalleryList::onLeftDown(wxMouseEvent& ev) {
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];
size_t subcolumn = active_subcolumn;
for (size_t j = 0 ; subcolumns.size() ; ++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) {
// clicked on this column
column = j;
subcolumn = j;
break;
}
}
select(item, column);
select(item, subcolumn);
}
ev.Skip(); // focus
}
......@@ -181,34 +181,34 @@ void GalleryList::onLeftDClick(wxMouseEvent& ev) {
}
void GalleryList::onChar(wxKeyEvent& ev) {
Column& col = columns[active_column];
SubColumn& col = subcolumns[active_subcolumn];
switch (ev.GetKeyCode()) {
case WXK_LEFT:
if (direction == wxHORIZONTAL) {
select(col.selection - 1);
} else {
selectColumn(active_column - 1);
selectSubColumn(active_subcolumn - 1);
}
break;
case WXK_RIGHT:
if (direction == wxHORIZONTAL) {
select(col.selection + 1);
} else {
selectColumn(active_column + 1);
selectSubColumn(active_subcolumn + 1);
}
break;
case WXK_UP:
if (direction == wxVERTICAL) {
select(col.selection - 1);
} else {
selectColumn(active_column - 1);
selectSubColumn(active_subcolumn - 1);
}
break;
case WXK_DOWN:
if (direction == wxVERTICAL) {
select(col.selection + 1);
} else {
selectColumn(active_column + 1);
selectSubColumn(active_subcolumn + 1);
}
break;
case WXK_TAB: {
......@@ -263,13 +263,13 @@ void GalleryList::OnDraw(DC& dc) {
for (size_t i = start ; i < end ; ++i) {
wxPoint pos = itemPos(i);
// draw selection rectangle
for (size_t j = 0 ; j < columns.size() ; ++j) {
const Column& col = columns[j];
for (size_t j = 0 ; j < subcolumns.size() ; ++j) {
const SubColumn& col = subcolumns[j];
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)
: lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), columnActivity(j))
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), subcolumnActivity(j))
)
: unselected;
dc.SetPen(c);
......
......@@ -32,14 +32,14 @@ class GalleryList : public wxPanel {
GalleryList(Window* parent, int id, int direction = wxHORIZONTAL, bool always_focused = true);
/// 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)
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?
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?
inline bool isSelected(size_t item, size_t column = 0) const {
return column < columns.size() && columns[column].selection == item;
inline bool isSelected(size_t item, size_t subcol = 0) const {
return subcol < subcolumns.size() && subcolumns[subcol].selection == item;
}
/// Redraw only the selected items
......@@ -47,7 +47,7 @@ class GalleryList : public wxPanel {
protected:
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)
int direction; ///< Direction of the list, can be wxHORIZONTAL or wxVERTICAL
bool always_focused; ///< Always draw as if focused
......@@ -59,8 +59,8 @@ class GalleryList : public wxPanel {
virtual size_t itemCount() const = 0;
/// Draw an item
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; }
/// How 'salient' should the selection in the given subcolumn be?
virtual double subcolumnActivity(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) {}
......@@ -68,14 +68,14 @@ class GalleryList : public wxPanel {
/// Return the desired size of control
virtual wxSize DoGetBestSize() const;
/// Information on the columns
struct Column {
/// Information on the subcolumns. These are columns inside items
struct SubColumn {
wxPoint offset;
wxSize size;
bool can_select;
size_t selection;
};
vector<Column> columns;
vector<SubColumn> subcolumns;
private:
DECLARE_EVENT_TABLE();
......@@ -121,7 +121,7 @@ class GalleryList : public wxPanel {
}
public:
typedef Column Column_for_typeof;
typedef SubColumn SubColumn_for_typeof;
protected:
/// Send an event
void sendEvent(WXTYPE type);
......
......@@ -18,7 +18,7 @@ DECLARE_TYPEOF_COLLECTION(PackagedP);
PackageList::PackageList(Window* parent, int id, int direction, bool 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);
}
......@@ -88,7 +88,7 @@ void PackageList::clear() {
void PackageList::select(const String& name, bool send_event) {
for (vector<PackageData>::const_iterator it = packages.begin() ; it != packages.end() ; ++it) {
if (it->package->name() == name) {
columns[0].selection = it - packages.begin();
subcolumns[0].selection = it - packages.begin();
update();
if (send_event) {
sendEvent(EVENT_GALLERY_SELECT);
......@@ -96,7 +96,7 @@ void PackageList::select(const String& name, bool send_event) {
return;
}
}
columns[0].selection = NO_SELECTION;
subcolumns[0].selection = NO_SELECTION;
update();
return;
}
......@@ -39,7 +39,7 @@ class PackageList : public GalleryList {
* Throws if the selection is not of type T */
template <typename T>
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 (load_fully) ret->loadFully();
return ret;
......
......@@ -38,14 +38,14 @@ class StatCategoryList : public GalleryList {
StatCategoryList(Window* parent, int id)
: GalleryList(parent, id, wxVERTICAL)
{
item_size = columns[0].size = wxSize(150, 23);
item_size = subcolumns[0].size = wxSize(150, 23);
}
void show(const GameP&);
/// The selected category
inline StatsCategory& getSelection() {
return *categories.at(columns[0].selection);
return *categories.at(subcolumns[0].selection);
}
protected:
......@@ -69,7 +69,7 @@ void StatCategoryList::show(const GameP& game) {
stable_sort(categories.begin(), categories.end(), ComparePositionHint());
update();
// select first item
columns[0].selection = itemCount() > 0 ? 0 : NO_SELECTION;
subcolumns[0].selection = itemCount() > 0 ? 0 : NO_SELECTION;
}
size_t StatCategoryList::itemCount() const {
......@@ -114,20 +114,20 @@ class StatDimensionList : public GalleryList {
, prefered_dimension_count(dimension_count)
{
//item_size = wxSize(150, 23);
columns[0].size = wxSize(140,23);
subcolumns[0].size = wxSize(140,23);
if (dimension_count > 0) {
columns[0].selection = NO_SELECTION;
columns[0].can_select = false;
active_column = 1;
subcolumns[0].selection = NO_SELECTION;
subcolumns[0].can_select = false;
active_subcolumn = 1;
}
// additional columns
Column col;
SubColumn col;
col.selection = show_empty ? NO_SELECTION : 0;
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);
for (int i = 0 ; i < dimension_count ; ++i) {
columns.push_back(col);
subcolumns.push_back(col);
col.offset.x += col.size.x + SPACING;
}
// total
......@@ -137,8 +137,8 @@ class StatDimensionList : public GalleryList {
void show(const GameP&);
/// The selected category
StatsDimensionP getSelection(size_t column=(size_t)-1) {
size_t sel = columns[column+1].selection - show_empty;
StatsDimensionP getSelection(size_t subcol=(size_t)-1) {
size_t sel = subcolumns[subcol+1].selection - show_empty;
if (sel >= itemCount()) return StatsDimensionP();
else return dimensions.at(sel);
}
......@@ -149,7 +149,7 @@ class StatDimensionList : public GalleryList {
void restrictDimensions(size_t dims) {
prefered_dimension_count = dims;
active_column = min(active_column, dims);
active_subcolumn = min(active_subcolumn, dims);
RefreshSelection();
}
......@@ -157,33 +157,34 @@ class StatDimensionList : public GalleryList {
virtual size_t itemCount() const;
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;
}
virtual void onSelect(size_t item, size_t old_col, bool& changes) {
// swap selection with another column?
for (size_t j = 1 ; j < columns.size() ; ++j) {
if (j != active_column && columns[j].selection == item && columns[active_column].selection != item) {
columns[j].selection = columns[active_column].selection;
// swap selection with another subcolumn?
for (size_t j = 1 ; j < subcolumns.size() ; ++j) {
if (j != active_subcolumn && subcolumns[j].selection == item &&
subcolumns[active_subcolumn].selection != item) {
subcolumns[j].selection = subcolumns[active_subcolumn].selection;
changes = true;
break;
}
}
// update prefered dimension count?
if (active_column > prefered_dimension_count) {
prefered_dimension_count = active_column;
if (active_subcolumn > prefered_dimension_count) {
prefered_dimension_count = active_subcolumn;
changes = true;
RefreshSelection();
}
// decrease dimension count? (toggle last dimension)
if (!changes && old_col == active_column) {
if (active_column == prefered_dimension_count && prefered_dimension_count > 1) {
if (!changes && old_col == active_subcolumn) {
if (active_subcolumn == prefered_dimension_count && prefered_dimension_count > 1) {
prefered_dimension_count -= 1;
selectColumn(prefered_dimension_count);
selectSubColumn(prefered_dimension_count);
changes = true;
} else if (active_column != prefered_dimension_count) {
active_column = prefered_dimension_count = active_column;
} else if (active_subcolumn != prefered_dimension_count) {
active_subcolumn = prefered_dimension_count = active_subcolumn;
RefreshSelection();
changes = true;
}
......@@ -210,11 +211,11 @@ void StatDimensionList::show(const GameP& game) {
// select first item
if (dimension_count > 0) {
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;
} 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