mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Changed scroll size of PackageList;
Added 'collapse' option for card notes; Made variant of DECLARE_TYPEOF for maps (two template arguments). git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@202 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -26,10 +26,8 @@
|
||||
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||
DECLARE_TYPEOF_COLLECTION(FieldP);
|
||||
DECLARE_POINTER_TYPE(ChoiceValue);
|
||||
typedef map<int,FieldP> map_int_FieldP;
|
||||
DECLARE_TYPEOF(map_int_FieldP);
|
||||
typedef IndexMap<FieldP,StyleP> IndexMap_FieldP_StyleP;
|
||||
DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_StyleP);
|
||||
DECLARE_TYPEOF2(map<int,FieldP>);
|
||||
DECLARE_TYPEOF_NO_REV2(IndexMap<FieldP,StyleP>);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
|
||||
@@ -17,37 +17,40 @@ DEFINE_EVENT_TYPE(EVENT_GALLERY_ACTIVATE);
|
||||
|
||||
// ----------------------------------------------------------------------------- : GalleryList
|
||||
|
||||
const int MARGIN = 1; // margin between items
|
||||
const int BORDER = 1; // margin between items
|
||||
const int MARGIN = 1; // margin between items (excluding border)
|
||||
const int BORDER = 1; // border aroung items
|
||||
const int SPACING = MARGIN + 2*BORDER; // distance between items
|
||||
|
||||
GalleryList::GalleryList(Window* parent, int id, int direction)
|
||||
: wxScrolledWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER | (direction == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL) )
|
||||
, selection(NO_SELECTION)
|
||||
, direction(direction)
|
||||
, scroll_increment(10)
|
||||
{}
|
||||
|
||||
void GalleryList::update() {
|
||||
const int w = (int)item_size.width + MARGIN + 2*BORDER;
|
||||
const int h = (int)item_size.height + MARGIN + 2*BORDER;
|
||||
const int w = item_size.x + SPACING;
|
||||
const int h = item_size.y + SPACING;
|
||||
// resize and scroll
|
||||
if (direction == wxHORIZONTAL) {
|
||||
SetVirtualSize(w * (int)itemCount() + MARGIN, h + MARGIN);
|
||||
SetScrollRate(w, 0);
|
||||
SetScrollRate(scroll_increment, 0);
|
||||
} else { // wxVERTICAL
|
||||
SetVirtualSize(w, h * (int)itemCount() + MARGIN + MARGIN);
|
||||
SetScrollRate(0, h);
|
||||
SetVirtualSize(w + MARGIN, h * (int)itemCount() + MARGIN);
|
||||
SetScrollRate(0, scroll_increment);
|
||||
}
|
||||
// ensure selected item + its margin is visible
|
||||
if (selection < itemCount()) {
|
||||
int x, y, cw, ch;
|
||||
GetViewStart (&x, &y);
|
||||
GetClientSize(&cw, &ch);
|
||||
cw = (cw - w + 1) / w; ch = (ch - h + 1) / h;
|
||||
RealPoint pos = itemPos(selection);
|
||||
x = min(x, (int)selection);
|
||||
y = min(y, (int)selection);
|
||||
x = max(x + cw, (int)selection) - cw;
|
||||
y = max(y + ch, (int)selection) - ch;
|
||||
cw = (cw - scroll_increment + 1) / scroll_increment;
|
||||
ch = (ch - scroll_increment + 1) / scroll_increment;
|
||||
wxPoint pos = itemPos(selection);
|
||||
x = min(x, (int)(selection * w) / scroll_increment);
|
||||
y = min(y, (int)(selection * h) / scroll_increment);
|
||||
x = max(x + cw, (int)(selection * w + w - 1) / scroll_increment) - cw;
|
||||
y = max(y + ch, (int)(selection * h + h - 1) / scroll_increment) - ch;
|
||||
Scroll(x,y);
|
||||
}
|
||||
// redraw
|
||||
@@ -56,21 +59,21 @@ void GalleryList::update() {
|
||||
|
||||
size_t GalleryList::findItem(const wxMouseEvent& ev) const {
|
||||
if (direction == wxHORIZONTAL) {
|
||||
int x, w = (int)item_size.width + MARGIN + 2*BORDER;
|
||||
int x, w = item_size.x + SPACING;
|
||||
GetViewStart (&x, 0);
|
||||
return static_cast<size_t>( x + ev.GetX() / w );
|
||||
return static_cast<size_t>( max(0, x * scroll_increment + ev.GetX() - MARGIN) / w );
|
||||
} else { // wxVERTICAL
|
||||
int y, h = (int)item_size.height + MARGIN + 2*BORDER;
|
||||
int y, h = item_size.y + SPACING;
|
||||
GetViewStart (0, &y);
|
||||
return static_cast<size_t>( y + ev.GetY() / h );
|
||||
return static_cast<size_t>( max(0, y * scroll_increment + ev.GetY() - MARGIN) / h );
|
||||
}
|
||||
}
|
||||
|
||||
RealPoint GalleryList::itemPos(size_t item) const {
|
||||
wxPoint GalleryList::itemPos(size_t item) const {
|
||||
if (direction == wxHORIZONTAL) {
|
||||
return RealPoint(item * (item_size.width + MARGIN + 2*BORDER) + MARGIN + BORDER, MARGIN + BORDER);
|
||||
return wxPoint((int)item * (item_size.x + SPACING) + MARGIN + BORDER, MARGIN + BORDER);
|
||||
} else {
|
||||
return RealPoint(MARGIN + BORDER, item * (item_size.height + MARGIN + 2*BORDER) + MARGIN + BORDER);
|
||||
return wxPoint(MARGIN + BORDER, (int)item * (item_size.y + SPACING) + MARGIN + BORDER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +120,8 @@ void GalleryList::onChar(wxKeyEvent& ev) {
|
||||
|
||||
wxSize GalleryList::DoGetBestSize() const {
|
||||
wxSize ws = GetSize(), cs = GetClientSize();
|
||||
const int w = int(item_size.width) + 2*MARGIN + 2*BORDER;
|
||||
const int h = int(item_size.height) + 2*MARGIN + 2*BORDER;
|
||||
const int w = item_size.x + SPACING;
|
||||
const int h = item_size.y + SPACING;
|
||||
return wxSize(w, h) + ws - cs;
|
||||
}
|
||||
|
||||
@@ -136,15 +139,15 @@ void GalleryList::OnDraw(DC& dc) {
|
||||
GetViewStart(&x, &y);
|
||||
GetClientSize(&cw, &ch);
|
||||
if (direction == wxHORIZONTAL) {
|
||||
dx = int(item_size.width) + MARGIN + 2*BORDER;
|
||||
dx = item_size.x + MARGIN + 2*BORDER;
|
||||
dy = 0;
|
||||
start = (size_t) x;
|
||||
end = (size_t) (start + cw / dx + 1);
|
||||
start = (size_t) max(0, x * scroll_increment - MARGIN) / dx;
|
||||
end = (size_t) max(0, x * scroll_increment - MARGIN + cw + dx) / dx;
|
||||
} else {
|
||||
dx = 0;
|
||||
dy = int(item_size.height) + MARGIN + 2*BORDER;
|
||||
start = (size_t) y;
|
||||
end = (size_t) (start + ch / dy + 1);
|
||||
dy = item_size.y + MARGIN + 2*BORDER;
|
||||
start = (size_t) max(0, y * scroll_increment - MARGIN) / dy;
|
||||
end = (size_t) max(0, y * scroll_increment - MARGIN + ch + dy) / dy;
|
||||
}
|
||||
end = min(end, itemCount());
|
||||
// clear background
|
||||
@@ -161,10 +164,10 @@ void GalleryList::OnDraw(DC& dc) {
|
||||
Color c = selected ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT) : unselected;
|
||||
dc.SetPen(c);
|
||||
dc.SetBrush(saturate(lerp(background, c, 0.3), selected ? 0.5 : 0));
|
||||
RealPoint pos = itemPos(i);
|
||||
dc.DrawRectangle(int(pos.x) - BORDER, int(pos.y) - BORDER, int(item_size.width) + 2*BORDER, int(item_size.height) + 2*BORDER);
|
||||
wxPoint pos = itemPos(i);
|
||||
dc.DrawRectangle(pos.x - BORDER, pos.y - BORDER, item_size.x + 2*BORDER, item_size.y + 2*BORDER);
|
||||
// draw item
|
||||
drawItem(dc, int(pos.x), int(pos.y), i, selected);
|
||||
drawItem(dc, pos.x, pos.y, i, selected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,10 @@ class GalleryList : public wxScrolledWindow {
|
||||
|
||||
protected:
|
||||
static const size_t NO_SELECTION = (size_t)-1;
|
||||
size_t selection; ///< The selected item, or NO_SELECTION if there is no selection
|
||||
RealSize item_size; ///< The size of a single item
|
||||
int direction; ///< Direction of the list, can be wxHORIZONTAL or wxVERTICAL
|
||||
size_t selection; ///< The selected item, or NO_SELECTION if there is no selection
|
||||
wxSize item_size; ///< The size of a single item
|
||||
int scroll_increment; ///< How large are the scroll steps?
|
||||
int direction; ///< Direction of the list, can be wxHORIZONTAL or wxVERTICAL
|
||||
|
||||
/// Redraw the list after changing the selection or the number of items
|
||||
void update();
|
||||
@@ -63,7 +64,7 @@ class GalleryList : public wxScrolledWindow {
|
||||
/// Find the item corresponding to the given location
|
||||
size_t findItem(const wxMouseEvent&) const;
|
||||
/// Find the coordinates of an item
|
||||
RealPoint itemPos(size_t item) const;
|
||||
wxPoint itemPos(size_t item) const;
|
||||
protected:
|
||||
/// Send an event
|
||||
void sendEvent(WXTYPE type);
|
||||
|
||||
@@ -15,8 +15,7 @@ DECLARE_TYPEOF_COLLECTION(GraphAxisP);
|
||||
DECLARE_TYPEOF_COLLECTION(GraphElementP);
|
||||
DECLARE_TYPEOF_COLLECTION(GraphGroup);
|
||||
DECLARE_TYPEOF_COLLECTION(int);
|
||||
typedef map<String,UInt> map_String_UInt;
|
||||
DECLARE_TYPEOF(map_String_UInt);
|
||||
DECLARE_TYPEOF2(map<String,UInt>);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@
|
||||
#include <data/stylesheet.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(ValueViewerP);
|
||||
typedef IndexMap<FieldP,StyleP> IndexMap_FieldP_StyleP;
|
||||
DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_StyleP);
|
||||
DECLARE_TYPEOF_NO_REV2(IndexMap<FieldP,StyleP>);
|
||||
|
||||
// ----------------------------------------------------------------------------- : NativeLookEditor
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
PackageList::PackageList(Window* parent, int id, int direction)
|
||||
: GalleryList(parent, id, direction)
|
||||
{
|
||||
item_size = wxSize(110, 150);
|
||||
item_size = wxSize(108, 150);
|
||||
SetThemeEnabled(true);
|
||||
}
|
||||
|
||||
size_t PackageList::itemCount() const {
|
||||
@@ -29,7 +30,7 @@ void PackageList::drawItem(DC& dc, int x, int y, size_t item, bool selected) {
|
||||
int w, h;
|
||||
// draw image
|
||||
if (d.image.Ok()) {
|
||||
dc.DrawBitmap(d.image, x + int(align_delta_x(ALIGN_CENTER, item_size.width, d.image.GetWidth())), y + 3);
|
||||
dc.DrawBitmap(d.image, x + int(align_delta_x(ALIGN_CENTER, item_size.x, d.image.GetWidth())), y + 3, true);
|
||||
}
|
||||
// draw short name
|
||||
dc.SetFont(wxFont(12,wxSWISS,wxNORMAL,wxBOLD,false,_("Arial")));
|
||||
|
||||
Reference in New Issue
Block a user