mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37:00 -04:00
Multicolumn support (major level) for gallery list
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1137 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -24,6 +24,7 @@ GalleryList::GalleryList(Window* parent, int id, int direction, bool always_focu
|
|||||||
: 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_subcolumn(0)
|
, active_subcolumn(0)
|
||||||
, direction(direction)
|
, direction(direction)
|
||||||
|
, column_count(1)
|
||||||
, always_focused(always_focused)
|
, always_focused(always_focused)
|
||||||
, visible_start(0)
|
, visible_start(0)
|
||||||
{
|
{
|
||||||
@@ -77,16 +78,30 @@ void GalleryList::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t GalleryList::findItem(const wxMouseEvent& ev) const {
|
size_t GalleryList::findItem(const wxMouseEvent& ev) const {
|
||||||
int x = visible_start + (direction == wxHORIZONTAL ? ev.GetX() : ev.GetY());
|
int x = ev.GetX();
|
||||||
int w = mainSize(item_size) + SPACING;
|
int y = ev.GetY();
|
||||||
return static_cast<size_t>( max(0, x - MARGIN) / w );
|
int w = item_size.x + SPACING;
|
||||||
|
int h = item_size.y + SPACING;
|
||||||
|
if (direction == wxHORIZONTAL) {
|
||||||
|
x += visible_start;
|
||||||
|
return (size_t)(max(0, x - MARGIN) / w) * column_count
|
||||||
|
+ (size_t)min(max(0, y - MARGIN) / h, (int)column_count-1);
|
||||||
|
} else {
|
||||||
|
y += visible_start;
|
||||||
|
return (size_t)(max(0, y - MARGIN) / h) * column_count
|
||||||
|
+ (size_t)min(max(0, x - MARGIN) / w, (int)column_count-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxPoint GalleryList::itemPos(size_t item) const {
|
wxPoint GalleryList::itemPos(size_t item) const {
|
||||||
if (direction == wxHORIZONTAL) {
|
if (direction == wxHORIZONTAL) {
|
||||||
return wxPoint((int)item * (item_size.x + SPACING) + MARGIN + BORDER - visible_start, MARGIN + BORDER);
|
int x = (int)(item / column_count) * (item_size.x + SPACING);
|
||||||
|
int y = (int)(item % column_count) * (item_size.y + SPACING);
|
||||||
|
return wxPoint(x + MARGIN + BORDER - visible_start, y + MARGIN + BORDER);
|
||||||
} else {
|
} else {
|
||||||
return wxPoint(MARGIN + BORDER, (int)item * (item_size.y + SPACING) + MARGIN + BORDER - visible_start);
|
int x = (int)(item % column_count) * (item_size.x + SPACING);
|
||||||
|
int y = (int)(item / column_count) * (item_size.y + SPACING);
|
||||||
|
return wxPoint(x + MARGIN + BORDER, y + MARGIN + BORDER - visible_start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,6 +200,8 @@ void GalleryList::onChar(wxKeyEvent& ev) {
|
|||||||
switch (ev.GetKeyCode()) {
|
switch (ev.GetKeyCode()) {
|
||||||
case WXK_LEFT:
|
case WXK_LEFT:
|
||||||
if (direction == wxHORIZONTAL) {
|
if (direction == wxHORIZONTAL) {
|
||||||
|
select(col.selection - column_count);
|
||||||
|
} else if (column_count > 1) {
|
||||||
select(col.selection - 1);
|
select(col.selection - 1);
|
||||||
} else {
|
} else {
|
||||||
selectSubColumn(active_subcolumn - 1);
|
selectSubColumn(active_subcolumn - 1);
|
||||||
@@ -192,6 +209,8 @@ void GalleryList::onChar(wxKeyEvent& ev) {
|
|||||||
break;
|
break;
|
||||||
case WXK_RIGHT:
|
case WXK_RIGHT:
|
||||||
if (direction == wxHORIZONTAL) {
|
if (direction == wxHORIZONTAL) {
|
||||||
|
select(col.selection + column_count);
|
||||||
|
} else if (column_count > 1) {
|
||||||
select(col.selection + 1);
|
select(col.selection + 1);
|
||||||
} else {
|
} else {
|
||||||
selectSubColumn(active_subcolumn + 1);
|
selectSubColumn(active_subcolumn + 1);
|
||||||
@@ -199,6 +218,8 @@ void GalleryList::onChar(wxKeyEvent& ev) {
|
|||||||
break;
|
break;
|
||||||
case WXK_UP:
|
case WXK_UP:
|
||||||
if (direction == wxVERTICAL) {
|
if (direction == wxVERTICAL) {
|
||||||
|
select(col.selection - column_count);
|
||||||
|
} else if (column_count > 1) {
|
||||||
select(col.selection - 1);
|
select(col.selection - 1);
|
||||||
} else {
|
} else {
|
||||||
selectSubColumn(active_subcolumn - 1);
|
selectSubColumn(active_subcolumn - 1);
|
||||||
@@ -206,6 +227,8 @@ void GalleryList::onChar(wxKeyEvent& ev) {
|
|||||||
break;
|
break;
|
||||||
case WXK_DOWN:
|
case WXK_DOWN:
|
||||||
if (direction == wxVERTICAL) {
|
if (direction == wxVERTICAL) {
|
||||||
|
select(col.selection + column_count);
|
||||||
|
} else if (column_count > 1) {
|
||||||
select(col.selection + 1);
|
select(col.selection + 1);
|
||||||
} else {
|
} else {
|
||||||
selectSubColumn(active_subcolumn + 1);
|
selectSubColumn(active_subcolumn + 1);
|
||||||
@@ -220,7 +243,8 @@ void GalleryList::onChar(wxKeyEvent& ev) {
|
|||||||
} break;
|
} break;
|
||||||
case WXK_RETURN: {
|
case WXK_RETURN: {
|
||||||
// same thing: press dialog box default button
|
// same thing: press dialog box default button
|
||||||
wxButton* btn = wxDynamicCast(wxDynamicCast(GetParent(), wxTopLevelWindow)->GetDefaultItem(), wxButton);
|
wxTopLevelWindow* tlw = wxDynamicCast(GetParent(), wxTopLevelWindow);
|
||||||
|
wxButton* btn = tlw ? wxDynamicCast(tlw->GetDefaultItem(), wxButton) : nullptr;
|
||||||
if ( btn && btn->IsEnabled() ) {
|
if ( btn && btn->IsEnabled() ) {
|
||||||
// if we do have a default button, do press it
|
// if we do have a default button, do press it
|
||||||
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, btn->GetId());
|
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, btn->GetId());
|
||||||
@@ -235,7 +259,11 @@ wxSize GalleryList::DoGetBestSize() const {
|
|||||||
wxSize ws = GetSize(), cs = GetClientSize();
|
wxSize ws = GetSize(), cs = GetClientSize();
|
||||||
const int w = item_size.x + 2*MARGIN + 2*BORDER;
|
const int w = item_size.x + 2*MARGIN + 2*BORDER;
|
||||||
const int h = item_size.y + 2*MARGIN + 2*BORDER;
|
const int h = item_size.y + 2*MARGIN + 2*BORDER;
|
||||||
return wxSize(w, h) + ws - cs;
|
if (direction == wxHORIZONTAL) {
|
||||||
|
return wxSize(w, h * (int)column_count) + ws - cs;
|
||||||
|
} else {
|
||||||
|
return wxSize(w * (int)column_count, h) + ws - cs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GalleryList::onPaint(wxPaintEvent&) {
|
void GalleryList::onPaint(wxPaintEvent&) {
|
||||||
@@ -248,8 +276,8 @@ void GalleryList::OnDraw(DC& dc) {
|
|||||||
wxSize cs = GetClientSize();
|
wxSize cs = GetClientSize();
|
||||||
size_t start, end; // items to draw
|
size_t start, end; // items to draw
|
||||||
// number of visble items
|
// number of visble items
|
||||||
start = (size_t) max(0, visible_start / (mainSize(item_size) + SPACING));
|
start = (size_t) max(0, visible_start / (mainSize(item_size) + SPACING)) * column_count;
|
||||||
end = (size_t) max(0, visibleEnd() / (mainSize(item_size) + SPACING) + 1);
|
end = (size_t) max(0, visibleEnd() / (mainSize(item_size) + SPACING) + 1) * column_count;
|
||||||
end = min(end, itemCount());
|
end = min(end, itemCount());
|
||||||
// clear background
|
// clear background
|
||||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class GalleryList : public wxPanel {
|
|||||||
size_t active_subcolumn; ///< The active subcolumn
|
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
|
||||||
|
size_t column_count; ///< Number of major level columns (if vertical) or rows (if horizontal)
|
||||||
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
|
||||||
@@ -110,10 +111,10 @@ class GalleryList : public wxPanel {
|
|||||||
}
|
}
|
||||||
/// Pixel position of an item
|
/// Pixel position of an item
|
||||||
inline int itemStart(size_t item) const {
|
inline int itemStart(size_t item) const {
|
||||||
return (int)item * (mainSize(item_size) + SPACING);
|
return (int)(item / column_count) * (mainSize(item_size) + SPACING);
|
||||||
}
|
}
|
||||||
inline int itemEnd(size_t item) const {
|
inline int itemEnd(size_t item) const {
|
||||||
return (int)(item + 1) * (mainSize(item_size) + SPACING) + MARGIN;
|
return (int)(item / column_count + 1) * (mainSize(item_size) + SPACING) + MARGIN;
|
||||||
}
|
}
|
||||||
/// Main component of a size (i.e. in the direction of this list)
|
/// Main component of a size (i.e. in the direction of this list)
|
||||||
inline int mainSize(wxSize s) const {
|
inline int mainSize(wxSize s) const {
|
||||||
|
|||||||
Reference in New Issue
Block a user