- Added 'package list' field type

- Some refactoring of the other field types

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@790 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-12-26 23:37:45 +00:00
parent 7b340db04f
commit d493394519
32 changed files with 573 additions and 94 deletions
+3 -1
View File
@@ -12,6 +12,8 @@
// ----------------------------------------------------------------------------- : ChoiceValueViewer
IMPLEMENT_VALUE_VIEWER(Choice);
void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts);
bool ChoiceValueViewer::prepare(RotatedDC& dc) {
@@ -108,4 +110,4 @@ void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, Ge
void ChoiceValueViewer::onStyleChange(int changes) {
if (changes & CHANGE_MASK) style().image.clearCache();
ValueViewer::onStyleChange(changes);
}
}
+2
View File
@@ -14,6 +14,8 @@ DECLARE_TYPEOF_COLLECTION(ColorField::ChoiceP);
// ----------------------------------------------------------------------------- : ColorValueViewer
IMPLEMENT_VALUE_VIEWER(Color);
void ColorValueViewer::draw(RotatedDC& dc) {
// draw in the value color
dc.SetPen(*wxTRANSPARENT_PEN);
+2
View File
@@ -16,6 +16,8 @@ DECLARE_TYPEOF_COLLECTION(wxPoint);
// ----------------------------------------------------------------------------- : ImageValueViewer
IMPLEMENT_VALUE_VIEWER(Image);
void ImageValueViewer::draw(RotatedDC& dc) {
// reset?
int w = (int)dc.trX(style().width), h = (int)dc.trY(style().height);
+2
View File
@@ -11,6 +11,8 @@
// ----------------------------------------------------------------------------- : InfoValueViewer
IMPLEMENT_VALUE_VIEWER(Info);
void InfoValueViewer::draw(RotatedDC& dc) {
dc.SetPen(*wxTRANSPARENT_PEN);
if (nativeLook()) {
+2
View File
@@ -16,6 +16,8 @@ DECLARE_TYPEOF_COLLECTION(String);
// ----------------------------------------------------------------------------- : MultipleChoiceValueViewer
IMPLEMENT_VALUE_VIEWER(MultipleChoice);
bool MultipleChoiceValueViewer::prepare(RotatedDC& dc) {
if (style().render_style & (RENDER_CHECKLIST | RENDER_LIST)) return false;
return prepare_choice_viewer(dc, viewer, style(), value().value());
+62
View File
@@ -0,0 +1,62 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2007 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <render/value/package_choice.hpp>
#include <util/io/package_manager.hpp>
DECLARE_TYPEOF_COLLECTION(PackagedP);
DECLARE_TYPEOF_COLLECTION(PackageChoiceValueViewer::Item);
// ----------------------------------------------------------------------------- : PackageChoiceValueViewer
IMPLEMENT_VALUE_VIEWER(PackageChoice);
struct PackageChoiceValueViewer::ComparePackagePosHint {
bool operator () (const PackagedP& a, const PackagedP& b) {
// use position_hints to determine order
if (a->position_hint < b->position_hint) return true;
if (a->position_hint > b->position_hint) return false;
// ensure a deterministic order: use the names
return a->name() < b->name();
}
};
void PackageChoiceValueViewer::initItems() {
vector<PackagedP> choices;
packages.findMatching(field().match, choices);
sort(choices.begin(), choices.end(), ComparePackagePosHint());
FOR_EACH(p, choices) {
Item i;
i.package_name = p->relativeFilename();
i.name = capitalize_sentence(p->short_name);
Image image;
InputStreamP stream = p->openIconFile();
if (stream && image.LoadFile(*stream)) {
Image resampled(16,16,false);
resample(image, resampled);
i.image = Bitmap(resampled);
}
items.push_back(i);
}
}
void PackageChoiceValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc);
// find item
FOR_EACH(i, items) {
if (i.package_name != value().package_name) continue;
// draw image
if (i.image.Ok()) {
dc.DrawBitmap(i.image, RealPoint(0,0));
}
// draw text
dc.SetFont(style().font, 1.0);
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(17., 0);
dc.DrawTextWithShadow(i.name, style().font, pos);
}
}
+38
View File
@@ -0,0 +1,38 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2007 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_RENDER_VALUE_PACKAGE_CHOICE
#define HEADER_RENDER_VALUE_PACKAGE_CHOICE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <render/value/viewer.hpp>
#include <data/field/package_choice.hpp>
// ----------------------------------------------------------------------------- : PackageChoiceValueViewer
/// Viewer that displays a package choice value
class PackageChoiceValueViewer : public ValueViewer {
public:
DECLARE_VALUE_VIEWER(PackageChoice) : ValueViewer(parent,style) { initItems(); }
virtual void draw(RotatedDC& dc);
struct Item{
String package_name;
String name;
Bitmap image;
};
protected:
vector<Item> items;
private:
void initItems();
struct ComparePackagePosHint;
};
// ----------------------------------------------------------------------------- : EOF
#endif
+2
View File
@@ -17,6 +17,8 @@ DECLARE_TYPEOF_COLLECTION(SymbolVariationP);
// ----------------------------------------------------------------------------- : SymbolValueViewer
IMPLEMENT_VALUE_VIEWER(Symbol);
void SymbolValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc);
// draw checker background
+2
View File
@@ -12,6 +12,8 @@
// ----------------------------------------------------------------------------- : TextValueViewer
IMPLEMENT_VALUE_VIEWER(Text);
bool TextValueViewer::prepare(RotatedDC& dc) {
if (!style().mask_filename.empty() && !style().mask.ok()) {
// load contour mask
-23
View File
@@ -7,13 +7,6 @@
// ----------------------------------------------------------------------------- : Includes
#include <render/value/viewer.hpp>
#include <render/value/text.hpp>
#include <render/value/choice.hpp>
#include <render/value/multiple_choice.hpp>
#include <render/value/image.hpp>
#include <render/value/symbol.hpp>
#include <render/value/color.hpp>
#include <render/value/information.hpp>
#include <render/card/viewer.hpp>
// ----------------------------------------------------------------------------- : ValueViewer
@@ -65,19 +58,3 @@ void ValueViewer::onStyleChange(int changes) {
viewer.redraw(*this);
}
}
// ----------------------------------------------------------------------------- : Type dispatch
#define IMPLEMENT_MAKE_VIEWER(Type) \
ValueViewerP Type##Style::makeViewer(DataViewer& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueViewer(parent, static_pointer_cast<Type##Style>(thisP))); \
}
IMPLEMENT_MAKE_VIEWER(Text);
IMPLEMENT_MAKE_VIEWER(Choice);
IMPLEMENT_MAKE_VIEWER(MultipleChoice);
IMPLEMENT_MAKE_VIEWER(Color);
IMPLEMENT_MAKE_VIEWER(Image);
IMPLEMENT_MAKE_VIEWER(Symbol);
IMPLEMENT_MAKE_VIEWER(Info);
+6
View File
@@ -99,6 +99,12 @@ class ValueViewer : public StyleListener {
public: \
Type##ValueViewer(DataViewer& parent, const Type ## StyleP& style)
#define IMPLEMENT_VALUE_VIEWER(Type) \
ValueViewerP Type##Style::makeViewer(DataViewer& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueViewer(parent, static_pointer_cast<Type##Style>(thisP))); \
}
// ----------------------------------------------------------------------------- : EOF
#endif