mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
Added GraphControl; FilteredCardList; ValueEditor
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@74 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -7,13 +7,22 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/control/card_editor.hpp>
|
||||
#include <gui/value/editor.hpp>
|
||||
#include <data/field.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : DataEditor
|
||||
|
||||
#define FOR_EACH_EDITOR \
|
||||
FOR_EACH(v, viewers) \
|
||||
if (ValueEditorP = static_pointer_cast<ValueEditor>(v))
|
||||
|
||||
DataEditor::DataEditor(Window* parent, int id, long style)
|
||||
: CardViewer(parent, id, style)
|
||||
{}
|
||||
|
||||
ValueViewerP DataEditor::makeViewer(const StyleP& style) {
|
||||
return style->makeEditor(*this, style);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Event table
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
class DataEditor : public CardViewer {
|
||||
public:
|
||||
DataEditor(Window* parent, int id, long style = 0);
|
||||
|
||||
protected:
|
||||
/// Create an editor for the given style (as opposed to a normal viewer)
|
||||
virtual ValueViewerP makeViewer(const StyleP&);
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
||||
@@ -93,7 +93,7 @@ void CardListBase::onAction(const Action& action, bool undone) {
|
||||
}
|
||||
}
|
||||
|
||||
vector<CardP>& CardListBase::getCards() const {
|
||||
const vector<CardP>& CardListBase::getCards() const {
|
||||
return set->cards;
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ struct CardListBase::CardComparer {
|
||||
|
||||
void CardListBase::sortList() {
|
||||
sorted_card_list.clear();
|
||||
FOR_EACH(card, getCards()) {
|
||||
FOR_EACH_CONST(card, getCards()) {
|
||||
sorted_card_list.push_back(card);
|
||||
}
|
||||
if (sort_criterium) {
|
||||
@@ -198,6 +198,7 @@ void CardListBase::rebuild() {
|
||||
ClearAll();
|
||||
column_fields.clear();
|
||||
selected_card_pos = -1;
|
||||
onRebuild();
|
||||
// determine column order
|
||||
map<int,FieldP> new_column_fields;
|
||||
FOR_EACH(f, set->game->card_fields) {
|
||||
|
||||
@@ -82,7 +82,12 @@ class CardListBase : public wxListView, public SetView {
|
||||
// --------------------------------------------------- : The cards
|
||||
protected:
|
||||
/// What cards should be shown?
|
||||
virtual vector<CardP>& getCards() const;
|
||||
virtual const vector<CardP>& getCards() const;
|
||||
|
||||
/// Rebuild the card list (clear all vectors and fill them again)
|
||||
void rebuild();
|
||||
/// Do some additional updating before rebuilding the list
|
||||
virtual void onRebuild() {}
|
||||
|
||||
// --------------------------------------------------- : Item 'events'
|
||||
|
||||
@@ -109,9 +114,6 @@ class CardListBase : public wxListView, public SetView {
|
||||
|
||||
mutable wxListItemAttr item_attr; // for OnGetItemAttr
|
||||
|
||||
// /// Get a card by position
|
||||
// void getCard(long pos);
|
||||
|
||||
/// Select a card, send an event to the parent
|
||||
/** If focus then the card is also focused and selected in the actual control.
|
||||
* This should abviously not be done when the card is selected because it was selected (leading to a loop).
|
||||
@@ -127,8 +129,6 @@ class CardListBase : public wxListView, public SetView {
|
||||
/// Sorts the list by the current sorting criterium
|
||||
void sortList();
|
||||
struct CardComparer; // for comparing cards
|
||||
/// Rebuild the card list (clear all vectors and fill them again)
|
||||
void rebuild();
|
||||
/// Refresh the card list (resort, refresh and reselect current item)
|
||||
void refreshList();
|
||||
/// Find the field that determines the color, if any.
|
||||
|
||||
@@ -18,11 +18,13 @@ CardViewer::CardViewer(Window* parent, int id, long style)
|
||||
|
||||
wxSize CardViewer::DoGetBestSize() const {
|
||||
wxSize ws = GetSize(), cs = GetClientSize();
|
||||
if (set && set->stylesheet) {
|
||||
return wxSize(set->stylesheet->card_width, set->stylesheet->card_height) + ws - cs;
|
||||
} else {
|
||||
return cs;
|
||||
if (set) {
|
||||
StyleSheetP stylesheet = set->stylesheetFor(card);
|
||||
if (stylesheet) {
|
||||
return wxSize(stylesheet->card_width, stylesheet->card_height) + ws - cs;
|
||||
}
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
void CardViewer::onChange() {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/control/filtered_card_list.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : FilteredCardList
|
||||
|
||||
FilteredCardList::FilteredCardList(Window* parent, int id, int style)
|
||||
: CardListBase(parent, id, style)
|
||||
{}
|
||||
|
||||
const vector<CardP>& FilteredCardList::getCards() const {
|
||||
return cards;
|
||||
}
|
||||
|
||||
void FilteredCardList::setFilter(const CardListFilterP& filter_) {
|
||||
filter = filter_;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void FilteredCardList::onRebuild() {
|
||||
cards.clear();
|
||||
if (filter) {
|
||||
FOR_EACH(c, set->cards) {
|
||||
if (filter->keep(c)) {
|
||||
cards.push_back(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
#ifndef HEADER_GUI_CONTROL_FILTERED_CARD_LIST
|
||||
#define HEADER_GUI_CONTROL_FILTERED_CARD_LIST
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/control/card_list.hpp>
|
||||
|
||||
DECLARE_POINTER_TYPE(CardListFilter);
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListFilter
|
||||
|
||||
/// A filter function to determine which items are shown in a card list
|
||||
class CardListFilter {
|
||||
public:
|
||||
virtual ~CardListFilter() {}
|
||||
/// Should a card be shown in the list?
|
||||
virtual bool keep(const CardP& card) = 0;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : FilteredCardList
|
||||
|
||||
/// A card list that lists a subset of the cards in the set
|
||||
class FilteredCardList : public CardListBase {
|
||||
public:
|
||||
FilteredCardList(Window* parent, int id, int style = 0);
|
||||
|
||||
/// Change the filter to use
|
||||
void setFilter(const CardListFilterP& filter_);
|
||||
|
||||
protected:
|
||||
/// Get only the subset of the cards
|
||||
virtual const vector<CardP>& getCards() const;
|
||||
/// Rebuild the filtered card list
|
||||
virtual void onRebuild();
|
||||
// /// Don't reorder
|
||||
// virtual void onDrag(wxMouseEvent& e);
|
||||
|
||||
private:
|
||||
CardListFilterP filter; ///< Filter with which this.cards is made
|
||||
vector<CardP> cards; ///< The cards that are shown
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
@@ -30,6 +30,9 @@ class GalleryList : public wxScrolledWindow {
|
||||
public:
|
||||
GalleryList(Window* parent, int id, int direction = wxHORIZONTAL);
|
||||
|
||||
/// Is there an item selected?
|
||||
inline bool hasSelection() const { return selection < itemCount(); }
|
||||
|
||||
protected:
|
||||
static const size_t NO_SELECTION = (size_t)-1;
|
||||
size_t selection; ///< The selected item, or NO_SELECTION if there is no selection
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/control/graph.hpp>
|
||||
#include <wx/dcbuffer.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Graph
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : GraphControl
|
||||
|
||||
GraphControl::GraphControl(Window* parent, int id)
|
||||
: wxControl(parent, id)
|
||||
{}
|
||||
|
||||
void GraphControl::onPaint(wxPaintEvent&) {
|
||||
wxBufferedPaintDC dc(this);
|
||||
}
|
||||
|
||||
void GraphControl::onSize(wxSizeEvent&) {
|
||||
Refresh(false);
|
||||
}
|
||||
|
||||
void GraphControl::onMouseDown(wxMouseEvent& ev) {
|
||||
if (!graph) return;
|
||||
wxSize cs = GetClientSize();
|
||||
graph->findItem(RealPoint((double)ev.GetX()/cs.GetWidth(), (double)ev.GetY()/cs.GetHeight()), current_item);
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(GraphControl, wxControl)
|
||||
EVT_PAINT (GraphControl::onPaint)
|
||||
EVT_SIZE (GraphControl::onSize)
|
||||
EVT_LEFT_DOWN (GraphControl::onMouseDown)
|
||||
END_EVENT_TABLE ()
|
||||
@@ -0,0 +1,161 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
#ifndef HEADER_GUI_CONTROL_GRAPH
|
||||
#define HEADER_GUI_CONTROL_GRAPH
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <util/rotation.hpp>
|
||||
|
||||
DECLARE_POINTER_TYPE(GraphAxis);
|
||||
DECLARE_POINTER_TYPE(GraphElement);
|
||||
DECLARE_POINTER_TYPE(GraphData);
|
||||
DECLARE_POINTER_TYPE(Graph);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Graph data
|
||||
|
||||
/// A group in a table or graph
|
||||
/** A group is rendered as a single bar or pie slice */
|
||||
class GraphGroup {
|
||||
public:
|
||||
String name; ///< Name of this position
|
||||
Color color; ///< Associated color
|
||||
int size; ///< Number of elements in this group
|
||||
};
|
||||
|
||||
/// An axis in a graph, consists of a list of groups
|
||||
/** The sum of groups.sum = sum of all elements in the data */
|
||||
class GraphAxis {
|
||||
public:
|
||||
String name; ///< Name/label of this axis
|
||||
bool auto_color; ///< Automatically assign colors to the groups on this axis
|
||||
vector<GraphGroup> groups; ///< Groups along this axis
|
||||
int max; ///< Maximum size of the groups
|
||||
};
|
||||
|
||||
/// A single data point of a graph
|
||||
class GraphElement {
|
||||
public:
|
||||
vector<String> axis_groups; ///< Group name for each axis
|
||||
};
|
||||
|
||||
/// Data to be displayed in a graph, not processed yet
|
||||
class GraphDataPre {
|
||||
public:
|
||||
vector<GraphAxisP> axes;
|
||||
vector<GraphElementP> elements;
|
||||
};
|
||||
|
||||
/// Data to be displayed in a graph
|
||||
class GraphData {
|
||||
public:
|
||||
GraphData(GraphDataPre);
|
||||
|
||||
vector<GraphAxisP> axes; ///< The axes in the data
|
||||
vector<int> values; ///< Multi dimensional (dim = axes.size()) array of values
|
||||
int size; ///< Total number of elements
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : Graph
|
||||
|
||||
/// A type of graph
|
||||
/** It is rendered into a sub-rectangle of the screen */
|
||||
class Graph {
|
||||
public:
|
||||
/// Draw this graph, filling the internalRect() of the dc.
|
||||
virtual void draw(RotatedDC& dc) = 0;
|
||||
/// Find the item at the given position, position is normalized to [0..1)
|
||||
virtual bool findItem(const RealPoint& pos, vector<int>& out) const { return false; }
|
||||
/// Change the data
|
||||
virtual void setData(const GraphDataP& d) { data = d; }
|
||||
|
||||
protected:
|
||||
/// Data of the graph
|
||||
GraphDataP data;
|
||||
};
|
||||
|
||||
/// Base class for 1 dimensional graph components
|
||||
class Graph1D : public Graph {
|
||||
public:
|
||||
inline Graph1D(size_t axis) : axis(axis) {}
|
||||
virtual bool findItem(const RealPoint& pos, vector<int>& out) const { return false; }
|
||||
protected:
|
||||
size_t axis;
|
||||
/// Find an item, return the position along the axis, or -1 if not found
|
||||
virtual int findItem(const RealPoint& pos) const = 0;
|
||||
};
|
||||
|
||||
/// A bar graph
|
||||
class BarGraph : public Graph1D {
|
||||
public:
|
||||
inline BarGraph(size_t axis) : Graph1D(axis) {}
|
||||
virtual void draw(RotatedDC& dc) const;
|
||||
virtual int findItem(const RealPoint& pos) const;
|
||||
};
|
||||
|
||||
// TODO
|
||||
//class BarGraph2D {
|
||||
//};
|
||||
|
||||
/// A pie graph
|
||||
class PieGraph : public Graph1D {
|
||||
public:
|
||||
inline PieGraph(size_t axis) : Graph1D(axis) {}
|
||||
virtual void draw(RotatedDC& dc) const;
|
||||
virtual int findItem(const RealPoint& pos) const;
|
||||
};
|
||||
|
||||
/// The legend, used for pie graphs
|
||||
class GraphLegend : public Graph1D {
|
||||
public:
|
||||
inline GraphLegend(size_t axis) : Graph1D(axis) {}
|
||||
virtual void draw(RotatedDC& dc) const;
|
||||
virtual int findItem(const RealPoint& pos) const;
|
||||
};
|
||||
|
||||
//class GraphTable {
|
||||
//};
|
||||
|
||||
//class GraphAxis : public Graph1D {
|
||||
// virtual void draw(RotatedDC& dc) const;
|
||||
//};
|
||||
|
||||
//class GraphValueAxis {
|
||||
// virtual void draw(RotatedDC& dc) const;
|
||||
//};
|
||||
|
||||
// ----------------------------------------------------------------------------- : Graph control
|
||||
|
||||
/// A control showing statistics in a graphical form
|
||||
class GraphControl : public wxControl {
|
||||
public:
|
||||
/// Create a graph control
|
||||
GraphControl(Window* parent, int id);
|
||||
|
||||
/// Update the data in the graph
|
||||
void setData(const GraphDataPre& data);
|
||||
/// Update the data in the graph
|
||||
void setData(const GraphDataP& data);
|
||||
|
||||
private:
|
||||
/// Graph object
|
||||
GraphP graph;
|
||||
/// The selected item per axis, or an empty vector if there is no selection
|
||||
/** If the value for an axis is -1, then all groups on that axis are selected */
|
||||
vector<int> current_item;
|
||||
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
void onPaint(wxPaintEvent&);
|
||||
void onSize (wxSizeEvent&);
|
||||
void onMouseDown(wxMouseEvent& ev);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
@@ -32,10 +32,7 @@ class PackageList : public GalleryList {
|
||||
|
||||
/// Clears this list
|
||||
void clear();
|
||||
|
||||
/// Is there a package selected?
|
||||
inline bool hasSelection() const { return selection < itemCount(); }
|
||||
|
||||
|
||||
/// Get the selected package, T should be the same type used for showData
|
||||
/** @pre hasSelection()
|
||||
* Throws if the selection is not of type T */
|
||||
|
||||
Reference in New Issue
Block a user