mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
- 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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : InfoValueViewer
|
||||
|
||||
IMPLEMENT_VALUE_VIEWER(Info);
|
||||
|
||||
void InfoValueViewer::draw(RotatedDC& dc) {
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
if (nativeLook()) {
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -17,6 +17,8 @@ DECLARE_TYPEOF_COLLECTION(SymbolVariationP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : SymbolValueViewer
|
||||
|
||||
IMPLEMENT_VALUE_VIEWER(Symbol);
|
||||
|
||||
void SymbolValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
// draw checker background
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user