mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 13:17:00 -04:00
Added Statistics dimension/categories
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@84 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <gui/control/gallery_list.hpp>
|
||||
#include <gfx/gfx.hpp>
|
||||
#include <wx/dcbuffer.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
@@ -16,66 +17,62 @@ DEFINE_EVENT_TYPE(EVENT_GALLERY_ACTIVATE);
|
||||
|
||||
// ----------------------------------------------------------------------------- : GalleryList
|
||||
|
||||
const int MARGIN = 2; // margin around items
|
||||
const int MARGIN = 1; // margin between items
|
||||
const int BORDER = 1; // margin between items
|
||||
|
||||
GalleryList::GalleryList(Window* parent, int id, int direction)
|
||||
: wxScrolledWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER)
|
||||
: wxScrolledWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER | (direction == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL) )
|
||||
, direction(direction)
|
||||
{}
|
||||
|
||||
void GalleryList::update() {
|
||||
const int w = item_size.GetWidth() + 2 * MARGIN;
|
||||
const int h = item_size.GetHeight() + 2 * MARGIN;
|
||||
const int w = item_size.width + MARGIN + 2*BORDER;
|
||||
const int h = item_size.height + MARGIN + 2*BORDER;
|
||||
// resize and scroll
|
||||
if (direction == wxHORIZONTAL) {
|
||||
// resize window
|
||||
SetVirtualSize(w, h * (int)itemCount());
|
||||
SetVirtualSize(w * (int)itemCount() + MARGIN, h + MARGIN);
|
||||
SetScrollRate(w, 0);
|
||||
// ensure selected item is visible
|
||||
if (selection < itemCount()) {
|
||||
int x, cw;
|
||||
GetViewStart (&x, 0);
|
||||
GetClientSize(&cw, 0);
|
||||
cw /= w;
|
||||
if ((int)selection < x) {
|
||||
Scroll((int)selection, -1); // scroll up
|
||||
} else if ((int)selection >= x + cw) {
|
||||
Scroll((int)selection - cw - 1, -1); // scroll up
|
||||
}
|
||||
}
|
||||
} else { // wxVERTICAL
|
||||
// resize window
|
||||
SetVirtualSize(w * (int)itemCount(), h);
|
||||
SetVirtualSize(w, h * (int)itemCount() + MARGIN + MARGIN);
|
||||
SetScrollRate(0, h);
|
||||
// ensure selected item is visible
|
||||
if (selection < itemCount()) {
|
||||
int y, ch;
|
||||
GetViewStart (0, &y);
|
||||
GetClientSize(0, &ch);
|
||||
ch /= w;
|
||||
if ((int)selection < y) {
|
||||
Scroll((int)selection, -1); // scroll up
|
||||
} else if ((int)selection >= y + ch) {
|
||||
Scroll((int)selection - ch - 1, -1); // scroll down
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
Scroll(x,y);
|
||||
}
|
||||
// redraw
|
||||
Refresh(false);
|
||||
}
|
||||
|
||||
size_t GalleryList::findItem(const wxMouseEvent& ev) {
|
||||
size_t GalleryList::findItem(const wxMouseEvent& ev) const {
|
||||
if (direction == wxHORIZONTAL) {
|
||||
int x, w = item_size.GetWidth() + 2 * MARGIN;
|
||||
int x, w = item_size.width + MARGIN + 2*BORDER;
|
||||
GetViewStart (&x, 0);
|
||||
return static_cast<size_t>( x + ev.GetX() / w );
|
||||
} else { // wxVERTICAL
|
||||
int y, h = item_size.GetHeight() + 2 * MARGIN;
|
||||
int y, h = item_size.height + MARGIN + 2*BORDER;
|
||||
GetViewStart (0, &y);
|
||||
return static_cast<size_t>( y + ev.GetY() / h );
|
||||
}
|
||||
}
|
||||
|
||||
RealPoint GalleryList::itemPos(size_t item) const {
|
||||
if (direction == wxHORIZONTAL) {
|
||||
return RealPoint(item * (item_size.width + MARGIN + 2*BORDER) + MARGIN + BORDER, MARGIN + BORDER);
|
||||
} else {
|
||||
return RealPoint(MARGIN + BORDER, item * (item_size.height + MARGIN + 2*BORDER) + MARGIN + BORDER);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
void GalleryList::onLeftDown(wxMouseEvent& ev) {
|
||||
@@ -85,40 +82,50 @@ void GalleryList::onLeftDown(wxMouseEvent& ev) {
|
||||
update();
|
||||
sendEvent(EVENT_GALLERY_SELECT);
|
||||
}
|
||||
ev.Skip(); // focus
|
||||
}
|
||||
|
||||
void GalleryList::onLeftDClick(wxMouseEvent& ev) {
|
||||
sendEvent(EVENT_GALLERY_ACTIVATE);
|
||||
}
|
||||
|
||||
void GalleryList::onKeyDown(wxKeyEvent& ev) {
|
||||
void GalleryList::onChar(wxKeyEvent& ev) {
|
||||
switch (ev.GetKeyCode()) {
|
||||
case WXK_LEFT: if (direction == wxHORIZONTAL && selection > 0) {
|
||||
selection -= 1;
|
||||
update();
|
||||
sendEvent(EVENT_GALLERY_SELECT);
|
||||
} break;
|
||||
case WXK_RIGHT: if (direction == wxHORIZONTAL && selection + 1 < itemCount()) {
|
||||
selection += 1;
|
||||
update();
|
||||
sendEvent(EVENT_GALLERY_SELECT);
|
||||
} break;
|
||||
case WXK_UP: if (direction == wxVERTICAL && selection > 0) {
|
||||
selection -= 1;
|
||||
update();
|
||||
sendEvent(EVENT_GALLERY_SELECT);
|
||||
} break;
|
||||
case WXK_DOWN: if (direction == wxVERTICAL && selection + 1 < itemCount()) {
|
||||
selection += 1;
|
||||
update();
|
||||
sendEvent(EVENT_GALLERY_SELECT);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
wxSize GalleryList::DoGetBestSize() const {
|
||||
wxSize ws = GetSize(), cs = GetClientSize();
|
||||
const int w = item_size.GetWidth() + 2 * MARGIN;
|
||||
const int h = item_size.GetHeight() + 2 * MARGIN;
|
||||
const int w = item_size.width + 2*MARGIN + 2*BORDER;
|
||||
const int h = item_size.height + 2*MARGIN + 2*BORDER;
|
||||
return wxSize(w, h) + ws - cs;
|
||||
}
|
||||
|
||||
void GalleryList::onPaint(wxPaintEvent&) {
|
||||
wxBufferedPaintDC dc(this);
|
||||
DoPrepareDC(dc);
|
||||
OnDraw(dc);
|
||||
}
|
||||
void GalleryList::OnDraw(DC& dc) {
|
||||
int x, y;
|
||||
int cw, ch;
|
||||
@@ -128,13 +135,13 @@ void GalleryList::OnDraw(DC& dc) {
|
||||
GetViewStart(&x, &y);
|
||||
GetClientSize(&cw, &ch);
|
||||
if (direction == wxHORIZONTAL) {
|
||||
dx = item_size.GetWidth() + 2 * MARGIN;
|
||||
dx = item_size.width + MARGIN + 2*BORDER;
|
||||
dy = 0;
|
||||
start = (size_t) x;
|
||||
end = (size_t) (start + cw / dx + 1);
|
||||
} else {
|
||||
dx = 0;
|
||||
dy = item_size.GetHeight() + 2 * MARGIN;
|
||||
dy = item_size.height + MARGIN + 2*BORDER;
|
||||
start = (size_t) y;
|
||||
end = (size_t) (start + ch / dy + 1);
|
||||
}
|
||||
@@ -153,9 +160,10 @@ void GalleryList::OnDraw(DC& dc) {
|
||||
Color c = selected ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT) : unselected;
|
||||
dc.SetPen(c);
|
||||
dc.SetBrush(lerp(background, c, 0.3));
|
||||
dc.DrawRectangle((int)i * dx + 1, (int)i * dy + 1, item_size.GetWidth() + 2, item_size.GetHeight() + 2);
|
||||
RealPoint pos = itemPos(i);
|
||||
dc.DrawRectangle(pos.x - BORDER, pos.y - BORDER, item_size.width + 2*BORDER, item_size.height + 2*BORDER);
|
||||
// draw item
|
||||
drawItem(dc, (int)i * dx + MARGIN, (int)i * dy + MARGIN, i, selected);
|
||||
drawItem(dc, pos.x, pos.y, i, selected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,5 +177,6 @@ void GalleryList::sendEvent(WXTYPE type) {
|
||||
BEGIN_EVENT_TABLE(GalleryList, wxScrolledWindow)
|
||||
EVT_LEFT_DOWN (GalleryList::onLeftDown)
|
||||
EVT_LEFT_DCLICK (GalleryList::onLeftDClick)
|
||||
EVT_KEY_DOWN (GalleryList::onKeyDown)
|
||||
EVT_CHAR (GalleryList::onChar)
|
||||
EVT_PAINT (GalleryList::onPaint)
|
||||
END_EVENT_TABLE ()
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <util/real_point.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
@@ -36,7 +37,7 @@ 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
|
||||
wxSize item_size; ///< The size of a single item
|
||||
RealSize item_size; ///< The size of a single item
|
||||
int direction; ///< Direction of the list, can be wxHORIZONTAL or wxVERTICAL
|
||||
|
||||
/// Redraw the list after changing the selection or the number of items
|
||||
@@ -55,11 +56,14 @@ class GalleryList : public wxScrolledWindow {
|
||||
|
||||
void onLeftDown (wxMouseEvent& ev);
|
||||
void onLeftDClick(wxMouseEvent& ev);
|
||||
void onKeyDown(wxKeyEvent& ev);
|
||||
void onChar(wxKeyEvent& ev);
|
||||
void onPaint(wxPaintEvent&);
|
||||
void OnDraw(DC& dc);
|
||||
|
||||
/// Find the item corresponding to the given location
|
||||
size_t findItem(const wxMouseEvent&);
|
||||
size_t findItem(const wxMouseEvent&) const;
|
||||
/// Find the coordinates of an item
|
||||
RealPoint itemPos(size_t item) const;
|
||||
/// Send an event
|
||||
void sendEvent(WXTYPE type);
|
||||
};
|
||||
|
||||
@@ -29,7 +29,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 + align_delta_x(ALIGN_CENTER, item_size.GetWidth(), d.image.GetWidth()), y + 3);
|
||||
dc.DrawBitmap(d.image, x + align_delta_x(ALIGN_CENTER, item_size.width, d.image.GetWidth()), y + 3);
|
||||
}
|
||||
// draw short name
|
||||
dc.SetFont(wxFont(12,wxSWISS,wxNORMAL,wxBOLD,false,_("Arial")));
|
||||
|
||||
+73
-14
@@ -10,31 +10,72 @@
|
||||
#include <gui/control/graph.hpp>
|
||||
#include <gui/control/gallery_list.hpp>
|
||||
#include <gui/control/filtered_card_list.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/statistics.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <util/alignment.hpp>
|
||||
#include <gfx/gfx.hpp>
|
||||
#include <wx/splitter.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : StatFieldList
|
||||
DECLARE_TYPEOF_COLLECTION(StatsDimensionP);
|
||||
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : StatCategoryList
|
||||
|
||||
/// A list of fields of which the statistics can be shown
|
||||
class StatFieldList : public GalleryList {
|
||||
class StatCategoryList : public GalleryList {
|
||||
public:
|
||||
StatFieldList(Window* parent, int id)
|
||||
StatCategoryList(Window* parent, int id)
|
||||
: GalleryList(parent, id, wxVERTICAL)
|
||||
{
|
||||
item_size = wxSize(100, 30);
|
||||
item_size = wxSize(140, 23);
|
||||
}
|
||||
|
||||
void show(const GameP&);
|
||||
|
||||
/// The selected category
|
||||
inline StatsCategory& getSelection() {
|
||||
return *game->statistics_categories.at(selection);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual size_t itemCount() const;
|
||||
virtual void drawItem(DC& dc, int x, int y, size_t item, bool selected);
|
||||
|
||||
private:
|
||||
GameP game;
|
||||
};
|
||||
|
||||
size_t StatFieldList::itemCount() const {
|
||||
return 0; // TODO
|
||||
void StatCategoryList::show(const GameP& game) {
|
||||
this->game = game;
|
||||
update();
|
||||
}
|
||||
|
||||
void StatFieldList::drawItem(DC& dc, int x, int y, size_t item, bool selected) {
|
||||
// TODO
|
||||
size_t StatCategoryList::itemCount() const {
|
||||
return game ? game->statistics_categories.size() : 0;
|
||||
}
|
||||
|
||||
void StatCategoryList::drawItem(DC& dc, int x, int y, size_t item, bool selected) {
|
||||
StatsCategory& cat = *game->statistics_categories.at(item);
|
||||
// draw icon
|
||||
if (!cat.icon_filename.empty() && !cat.icon.Ok()) {
|
||||
InputStreamP file = game->openIn(cat.icon_filename);
|
||||
Image img(*file);
|
||||
Image resampled(21, 21);
|
||||
resample_preserve_aspect(img, resampled);
|
||||
if (img.Ok()) cat.icon = Bitmap(resampled);
|
||||
}
|
||||
if (cat.icon.Ok()) {
|
||||
dc.DrawBitmap(cat.icon, x+1, y+1);
|
||||
}
|
||||
// draw name
|
||||
RealRect rect(RealPoint(x + 23, y), RealSize(item_size.width - 30, item_size.height));
|
||||
String str = capitalize(cat.name);
|
||||
dc.SetFont(wxFont(10,wxSWISS,wxNORMAL,wxBOLD,false,_("Arial")));
|
||||
int w, h;
|
||||
dc.GetTextExtent(str, &w, &h);
|
||||
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(w,h), rect);
|
||||
dc.DrawText(str, pos.x, pos.y);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : StatsPanel
|
||||
@@ -44,30 +85,47 @@ StatsPanel::StatsPanel(Window* parent, int id)
|
||||
{
|
||||
// init controls
|
||||
wxSplitterWindow* splitter;
|
||||
fields = new StatFieldList (this, ID_FIELD_LIST);
|
||||
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
|
||||
graph = new GraphControl (splitter, wxID_ANY);
|
||||
card_list = new FilteredCardList(splitter, wxID_ANY);
|
||||
categories = new StatCategoryList(this, ID_FIELD_LIST);
|
||||
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
|
||||
graph = new GraphControl (splitter, wxID_ANY);
|
||||
card_list = new FilteredCardList(splitter, wxID_ANY);
|
||||
// init splitter
|
||||
splitter->SetMinimumPaneSize(100);
|
||||
splitter->SetSashGravity(1.0);
|
||||
splitter->SplitHorizontally(graph, card_list, -100);
|
||||
// init sizer
|
||||
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
|
||||
s->Add(fields, 0, wxEXPAND | wxRIGHT, 2);
|
||||
s->Add(splitter, 1, wxEXPAND);
|
||||
s->Add(categories, 0, wxEXPAND | wxRIGHT, 2);
|
||||
s->Add(splitter, 1, wxEXPAND);
|
||||
s->SetSizeHints(this);
|
||||
SetSizer(s);
|
||||
}
|
||||
|
||||
void StatsPanel::onChangeSet() {
|
||||
card_list->setSet(set);
|
||||
categories->show(set->game);
|
||||
}
|
||||
|
||||
void StatsPanel::onCommand(int id) {
|
||||
switch (id) {
|
||||
case ID_FIELD_LIST: {
|
||||
// change graph data
|
||||
if (categories->hasSelection()) {
|
||||
StatsCategory& cat = categories->getSelection();
|
||||
GraphDataPre d;
|
||||
FOR_EACH(dim, cat.dimensions) {
|
||||
d.axes.push_back(new_shared1<GraphAxis>(dim->name));
|
||||
}
|
||||
FOR_EACH(card, set->cards) {
|
||||
Context& ctx = set->getContext(card);
|
||||
GraphElementP e(new GraphElement);
|
||||
FOR_EACH(dim, cat.dimensions) {
|
||||
e->values.push_back(*dim->script.invoke(ctx));
|
||||
}
|
||||
d.elements.push_back(e);
|
||||
}
|
||||
graph->setData(d);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -80,4 +138,5 @@ CardP StatsPanel::selectedCard() const {
|
||||
}
|
||||
void StatsPanel::selectCard(const CardP& card) {
|
||||
card_list->setCard(card);
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/set/panel.hpp>
|
||||
|
||||
class StatFieldList;
|
||||
class StatCategoryList;
|
||||
class GraphControl;
|
||||
class FilteredCardList;
|
||||
|
||||
@@ -33,7 +33,7 @@ class StatsPanel : public SetWindowPanel {
|
||||
|
||||
// --------------------------------------------------- : Data
|
||||
private:
|
||||
StatFieldList* fields;
|
||||
StatCategoryList* categories;
|
||||
GraphControl* graph;
|
||||
FilteredCardList* card_list;
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <gui/set/style_panel.hpp>
|
||||
#include <gui/set/stats_panel.hpp>
|
||||
#include <gui/control/card_list.hpp>
|
||||
#include <gui/control/gallery_list.hpp>
|
||||
#include <gui/about_window.hpp>
|
||||
#include <gui/new_window.hpp>
|
||||
#include <gui/icon_menu.hpp>
|
||||
@@ -580,6 +581,7 @@ BEGIN_EVENT_TABLE(SetWindow, wxFrame)
|
||||
EVT_MENU (ID_HELP_INDEX, SetWindow::onHelpIndex)
|
||||
EVT_MENU (ID_HELP_ABOUT, SetWindow::onHelpAbout)
|
||||
EVT_TOOL_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, SetWindow::onChildMenu)
|
||||
EVT_GALLERY_SELECT (ID_FIELD_LIST, SetWindow::onChildMenu) // for StatsPanel, because it is not a EVT_TOOL
|
||||
|
||||
EVT_UPDATE_UI (wxID_ANY, SetWindow::onUpdateUI)
|
||||
// EVT_FIND (wxID_ANY, SetWindow::onFind)
|
||||
|
||||
+5
-5
@@ -11,7 +11,7 @@
|
||||
#include <util/rotation.hpp>
|
||||
#include <wx/mstream.h>
|
||||
|
||||
#if defined(wxMSW) && wxUSE_UXTHEME
|
||||
#if wxUSE_UXTHEME
|
||||
#include <wx/msw/uxtheme.h>
|
||||
#include <tmschema.h>
|
||||
#include <shlobj.h>
|
||||
@@ -101,19 +101,19 @@ void draw3DBorder(DC& dc, int x1, int y1, int x2, int y2) {
|
||||
}
|
||||
|
||||
void draw_control_border(Window* win, DC& dc, const wxRect& rect) {
|
||||
#if defined(wxMSW) && wxUSE_UXTHEME
|
||||
#if wxUSE_UXTHEME
|
||||
RECT r;
|
||||
wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
|
||||
if (themeEngine && themeEngine->IsAppThemed()) {
|
||||
wxUxThemeHandle hTheme(win, L_("EDIT"));
|
||||
wxUxThemeHandle hTheme(win, _("EDIT"));
|
||||
r.left = rect.x -1;
|
||||
r.top = rect.y -1;
|
||||
r.right = rect.x + rect.width + 1;
|
||||
r.bottom = rect.y + rect.height + 1;
|
||||
if (hTheme) {
|
||||
wxUxThemeEngine::Get()->DrawThemeBackground(
|
||||
hTheme,
|
||||
dc.GetHDC(),
|
||||
(HTHEME)hTheme,
|
||||
(HDC)dc.GetHDC(),
|
||||
EP_EDITTEXT,
|
||||
ETS_NORMAL,
|
||||
&r,
|
||||
|
||||
Reference in New Issue
Block a user