mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
All three dimensions on stats panel in a single multicolumn list
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1040 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include <gfx/gfx.hpp>
|
||||
#include <wx/dcbuffer.h>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(GalleryList::Column_for_typeof);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
DEFINE_EVENT_TYPE(EVENT_GALLERY_SELECT);
|
||||
@@ -20,34 +22,53 @@ 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) )
|
||||
, selection(NO_SELECTION)
|
||||
, active_column(0)
|
||||
, direction(direction)
|
||||
, always_focused(always_focused)
|
||||
, visible_start(0)
|
||||
{}
|
||||
{
|
||||
Column col;
|
||||
col.can_select = true;
|
||||
col.selection = NO_SELECTION;
|
||||
columns.push_back(col);
|
||||
}
|
||||
|
||||
void GalleryList::select(size_t item, bool event) {
|
||||
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, size_t column, bool event) {
|
||||
if (item >= itemCount()) return;
|
||||
// select
|
||||
size_t old_sel = selection;
|
||||
selection = item;
|
||||
bool changes = false;
|
||||
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
|
||||
if (itemStart(selection) < visible_start) {
|
||||
scrollTo(itemStart(selection));
|
||||
} else if (itemEnd(selection) > visibleEnd()) {
|
||||
scrollTo(itemEnd(selection) + visible_start - visibleEnd());
|
||||
} else {
|
||||
if (itemStart(col.selection) < visible_start) {
|
||||
scrollTo(itemStart(col.selection));
|
||||
} else if (itemEnd(col.selection) > visibleEnd()) {
|
||||
scrollTo(itemEnd(col.selection) + visible_start - visibleEnd());
|
||||
} else if (col.selection != old_sel) {
|
||||
RefreshItem(old_sel);
|
||||
RefreshItem(selection);
|
||||
RefreshItem(col.selection);
|
||||
}
|
||||
// send event
|
||||
if (event && selection != old_sel) {
|
||||
if (event && changes) {
|
||||
sendEvent(EVENT_GALLERY_SELECT);
|
||||
}
|
||||
}
|
||||
|
||||
void GalleryList::update() {
|
||||
select(selection);
|
||||
select(columns[active_column].selection);
|
||||
updateScrollbar();
|
||||
Refresh(false);
|
||||
}
|
||||
@@ -97,6 +118,9 @@ void GalleryList::RefreshItem(size_t item) {
|
||||
if (item >= itemCount()) return;
|
||||
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) {
|
||||
wxEventType type = ev.GetEventType();
|
||||
@@ -130,8 +154,21 @@ void GalleryList::onMouseWheel(wxMouseEvent& ev) {
|
||||
|
||||
void GalleryList::onLeftDown(wxMouseEvent& ev) {
|
||||
size_t item = findItem(ev);
|
||||
if (item != selection && item < itemCount()) {
|
||||
select(item);
|
||||
if (item < itemCount()) {
|
||||
// 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
|
||||
}
|
||||
@@ -141,19 +178,36 @@ void GalleryList::onLeftDClick(wxMouseEvent& ev) {
|
||||
}
|
||||
|
||||
void GalleryList::onChar(wxKeyEvent& ev) {
|
||||
Column& col = columns[active_column];
|
||||
switch (ev.GetKeyCode()) {
|
||||
case WXK_LEFT: if (direction == wxHORIZONTAL) {
|
||||
select(selection - 1);
|
||||
} break;
|
||||
case WXK_RIGHT: if (direction == wxHORIZONTAL) {
|
||||
select(selection + 1);
|
||||
} break;
|
||||
case WXK_UP: if (direction == wxVERTICAL) {
|
||||
select(selection - 1);
|
||||
} break;
|
||||
case WXK_DOWN: if (direction == wxVERTICAL) {
|
||||
select(selection + 1);
|
||||
} break;
|
||||
case WXK_LEFT:
|
||||
if (direction == wxHORIZONTAL) {
|
||||
select(col.selection - 1);
|
||||
} else {
|
||||
selectColumn(active_column - 1);
|
||||
}
|
||||
break;
|
||||
case WXK_RIGHT:
|
||||
if (direction == wxHORIZONTAL) {
|
||||
select(col.selection + 1);
|
||||
} else {
|
||||
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: {
|
||||
// send a navigation event to our parent, to select another control
|
||||
// we need this because tabs of wxWANTS_CHARS
|
||||
@@ -202,21 +256,26 @@ void GalleryList::OnDraw(DC& dc) {
|
||||
Color unselected = lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
|
||||
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 0.1);
|
||||
Color background = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
bool has_focus = always_focused || FindFocus() == this;
|
||||
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);
|
||||
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
|
||||
drawItem(dc, pos.x, pos.y, i, selected);
|
||||
drawItem(dc, pos.x, pos.y, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,15 +31,24 @@ class GalleryList : public wxPanel {
|
||||
public:
|
||||
GalleryList(Window* parent, int id, int direction = wxHORIZONTAL, bool always_focused = true);
|
||||
|
||||
/// Select the given item
|
||||
void select(size_t item, bool event = true);
|
||||
/// Select the given column
|
||||
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?
|
||||
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:
|
||||
static const size_t NO_SELECTION = (size_t)-1;
|
||||
size_t selection; ///< The selected item, or NO_SELECTION if there is no selection
|
||||
wxSize item_size; ///< The size of a single item
|
||||
size_t active_column; ///< The active column
|
||||
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
|
||||
|
||||
@@ -49,11 +58,25 @@ class GalleryList : public wxPanel {
|
||||
/// Return how many items there are in the list
|
||||
virtual size_t itemCount() const = 0;
|
||||
/// 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
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
/// Information on the columns
|
||||
struct Column {
|
||||
wxPoint offset;
|
||||
wxSize size;
|
||||
bool can_select;
|
||||
size_t selection;
|
||||
};
|
||||
vector<Column> columns;
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
@@ -97,6 +120,8 @@ class GalleryList : public wxPanel {
|
||||
return direction == wxHORIZONTAL ? s.x : s.y;
|
||||
}
|
||||
|
||||
public:
|
||||
typedef Column Column_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 = wxSize(108, 150);
|
||||
item_size = columns[0].size = wxSize(108, 150);
|
||||
SetThemeEnabled(true);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ size_t PackageList::itemCount() const {
|
||||
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);
|
||||
RealRect rect(RealPoint(x,y),item_size);
|
||||
RealPoint pos;
|
||||
@@ -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) {
|
||||
selection = it - packages.begin();
|
||||
columns[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;
|
||||
}
|
||||
}
|
||||
selection = NO_SELECTION;
|
||||
columns[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(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 (load_fully) ret->loadFully();
|
||||
return ret;
|
||||
@@ -52,7 +52,7 @@ class PackageList : public GalleryList {
|
||||
/// Return how many items there are in the list
|
||||
virtual size_t itemCount() const;
|
||||
/// 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:
|
||||
// The default icon to use
|
||||
|
||||
Reference in New Issue
Block a user