mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Reduce coupling between ValueEditors/Viewers and Set and StyleSheet.
- Adding of actions is done with an addAction function
- Files are read from
- getStylePackage for styling stuff (this is stylesheet)
- getLocalPackage for symbol and image values (this was the set)
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@970 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -110,6 +110,16 @@ Rotation DataViewer::getRotation() const {
|
||||
return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT);
|
||||
}
|
||||
|
||||
Package& DataViewer::getStylePackage() const {
|
||||
return *stylesheet;
|
||||
}
|
||||
Package& DataViewer::getLocalPackage() const {
|
||||
return *set;
|
||||
}
|
||||
Game& DataViewer::getGame() const {
|
||||
return *set->game;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Setting data
|
||||
|
||||
void DataViewer::setCard(const CardP& card, bool refresh) {
|
||||
|
||||
@@ -62,6 +62,13 @@ class DataViewer : public SetView {
|
||||
/// Invalidate and redraw (the area of) a single value viewer
|
||||
virtual void redraw(const ValueViewer&) {}
|
||||
|
||||
/// The package containing style stuff like images
|
||||
virtual Package& getStylePackage() const;
|
||||
/// The local package for loading/saving files
|
||||
Package& getLocalPackage() const;
|
||||
/// Return the game to use for information
|
||||
Game& getGame() const;
|
||||
|
||||
// --------------------------------------------------- : Setting data
|
||||
|
||||
/// Display a card in this viewer
|
||||
@@ -100,7 +107,6 @@ class DataViewer : public SetView {
|
||||
vector<ValueViewerP> viewers; ///< The viewers for the different values in the data
|
||||
CardP card; ///< The card that is currently displayed, if any
|
||||
bool drawing; ///< Are we currently drawing?
|
||||
public:
|
||||
mutable StyleSheetP stylesheet; ///< Stylesheet being used
|
||||
};
|
||||
|
||||
|
||||
+12
-13
@@ -9,28 +9,27 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <render/value/choice.hpp>
|
||||
#include <render/card/viewer.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : ChoiceValueViewer
|
||||
|
||||
IMPLEMENT_VALUE_VIEWER(Choice);
|
||||
|
||||
void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts);
|
||||
void get_options(Rotation& rot, ValueViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts);
|
||||
|
||||
bool ChoiceValueViewer::prepare(RotatedDC& dc) {
|
||||
return prepare_choice_viewer(dc, viewer, style(), value().value());
|
||||
return prepare_choice_viewer(dc, *this, style(), value().value());
|
||||
}
|
||||
void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
if (style().render_style & RENDER_HIDDEN) return;
|
||||
draw_choice_viewer(dc, viewer, style(), value().value());
|
||||
draw_choice_viewer(dc, *this, style(), value().value());
|
||||
}
|
||||
|
||||
bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value) {
|
||||
bool prepare_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value) {
|
||||
if (style.render_style & RENDER_IMAGE) {
|
||||
style.initImage();
|
||||
CachedScriptableImage& img = style.image;
|
||||
Context& ctx = viewer.getContext();
|
||||
Context& ctx = viewer.viewer.getContext();
|
||||
ctx.setVariable(SCRIPT_VAR_input, to_script(value));
|
||||
// generate to determine the size
|
||||
if (img.update(ctx) && img.isReady()) {
|
||||
@@ -39,7 +38,7 @@ bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style
|
||||
// Generate image/bitmap (whichever is available)
|
||||
// don't worry, we cache the image
|
||||
ImageCombine combine = style.combine;
|
||||
style.loadMask(*viewer.stylesheet);
|
||||
style.loadMask(viewer.getStylePackage());
|
||||
Bitmap bitmap; Image image;
|
||||
RealSize size;
|
||||
img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size);
|
||||
@@ -54,7 +53,7 @@ bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style
|
||||
return false;
|
||||
}
|
||||
|
||||
void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value) {
|
||||
void draw_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value) {
|
||||
if (value.empty()) return;
|
||||
double margin = 0;
|
||||
if (style.render_style & RENDER_IMAGE) {
|
||||
@@ -65,7 +64,7 @@ void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, c
|
||||
get_options(dc, viewer, style, img_options);
|
||||
// Generate image/bitmap
|
||||
ImageCombine combine = style.combine;
|
||||
style.loadMask(*viewer.stylesheet);
|
||||
style.loadMask(viewer.getStylePackage());
|
||||
Bitmap bitmap; Image image;
|
||||
RealSize size;
|
||||
img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size);
|
||||
@@ -85,16 +84,16 @@ void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, c
|
||||
}
|
||||
}
|
||||
if (style.render_style & RENDER_TEXT) {
|
||||
String text = tr(*viewer.stylesheet, value, capitalize_sentence);
|
||||
String text = tr(viewer.getStylePackage(), value, capitalize_sentence);
|
||||
dc.SetFont(style.font, 1.0);
|
||||
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0);
|
||||
dc.DrawTextWithShadow(text, style.font, pos);
|
||||
}
|
||||
}
|
||||
|
||||
void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts) {
|
||||
opts.package = viewer.stylesheet.get();
|
||||
opts.local_package = viewer.getSet().get();
|
||||
void get_options(Rotation& rot, ValueViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts) {
|
||||
opts.package = &viewer.getStylePackage();
|
||||
opts.local_package = &viewer.getLocalPackage();
|
||||
opts.angle = rot.trAngle(0);
|
||||
if (viewer.nativeLook()) {
|
||||
opts.width = opts.height = 16;
|
||||
|
||||
@@ -25,8 +25,8 @@ class ChoiceValueViewer : public ValueViewer {
|
||||
virtual void onStyleChange(int);
|
||||
};
|
||||
|
||||
bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value);
|
||||
void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value);
|
||||
bool prepare_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value);
|
||||
void draw_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value);
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <render/value/color.hpp>
|
||||
#include <render/card/viewer.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(ColorField::ChoiceP);
|
||||
|
||||
@@ -100,7 +99,7 @@ void ColorValueViewer::loadMask(const Rotation& rot) const {
|
||||
if (alpha_mask && alpha_mask->size == wxSize(w,h)) return; // mask loaded and right size
|
||||
// (re) load the mask
|
||||
Image image;
|
||||
InputStreamP image_file = viewer.stylesheet->openIn(style().mask_filename);
|
||||
InputStreamP image_file = getStylePackage().openIn(style().mask_filename);
|
||||
if (image.LoadFile(*image_file)) {
|
||||
Image resampled(w,h);
|
||||
resample(image, resampled);
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <render/value/image.hpp>
|
||||
#include <render/card/viewer.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <gui/util.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(wxPoint);
|
||||
@@ -35,7 +33,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
|
||||
// load from file
|
||||
if (!value().filename.empty()) {
|
||||
try {
|
||||
InputStreamP image_file = getSet().openIn(value().filename);
|
||||
InputStreamP image_file = getLocalPackage().openIn(value().filename);
|
||||
if (image.LoadFile(*image_file)) {
|
||||
image.Rescale(w, h);
|
||||
}
|
||||
@@ -45,7 +43,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
|
||||
}
|
||||
// nice placeholder
|
||||
if (!image.Ok() && style().default_image.isReady()) {
|
||||
image = style().default_image.generate(GeneratedImage::Options(w, h, viewer.stylesheet.get(), &getSet()));
|
||||
image = style().default_image.generate(GeneratedImage::Options(w, h, &getStylePackage(), &getLocalPackage()));
|
||||
is_default = true;
|
||||
if (viewer.drawEditing()) {
|
||||
bitmap = imagePlaceholder(dc, w, h, image, viewer.drawEditing());
|
||||
@@ -127,7 +125,7 @@ void ImageValueViewer::loadMask(const Rotation& rot) const {
|
||||
if (alpha_mask && alpha_mask->size == wxSize(w,h)) return; // mask loaded and right size
|
||||
// (re) load the mask
|
||||
Image image;
|
||||
InputStreamP image_file = viewer.stylesheet->openIn(style().mask_filename);
|
||||
InputStreamP image_file = getStylePackage().openIn(style().mask_filename);
|
||||
if (image.LoadFile(*image_file)) {
|
||||
alpha_mask = new_intrusive1<AlphaMask>(resample(image,w,h));
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <render/value/multiple_choice.hpp>
|
||||
#include <render/value/choice.hpp>
|
||||
#include <render/card/viewer.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <gui/util.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(String);
|
||||
@@ -21,7 +20,7 @@ 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());
|
||||
return prepare_choice_viewer(dc, *this, style(), value().value());
|
||||
}
|
||||
|
||||
void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
@@ -47,7 +46,7 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
drawChoice(dc, pos, choice);
|
||||
}
|
||||
} else {
|
||||
draw_choice_viewer(dc, viewer, style(), value().value());
|
||||
draw_choice_viewer(dc, *this, style(), value().value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +61,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
|
||||
map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(choice));
|
||||
if (it != style().choice_images.end() && it->second.isReady()) {
|
||||
// TODO: caching
|
||||
GeneratedImage::Options options(0,0, viewer.stylesheet.get(),&getSet());
|
||||
GeneratedImage::Options options(0,0, &getStylePackage(), &getLocalPackage());
|
||||
options.zoom = dc.getZoom();
|
||||
options.angle = dc.trAngle(style().angle);
|
||||
Image image = it->second.generate(options);
|
||||
@@ -74,7 +73,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
// draw text
|
||||
String text = tr(*viewer.stylesheet, choice, capitalize_sentence);
|
||||
String text = tr(getStylePackage(), choice, capitalize_sentence);
|
||||
RealSize text_size = dc.GetTextExtent(text);
|
||||
dc.DrawText(text, align_in_rect(ALIGN_MIDDLE_LEFT, text_size,
|
||||
RealRect(pos + RealSize(size.width + 1, 0), RealSize(0,size.height))));
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <util/io/package.hpp>
|
||||
#include <render/value/symbol.hpp>
|
||||
#include <render/symbol/filter.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <data/symbol.hpp>
|
||||
#include <gui/util.hpp> // draw_checker
|
||||
#include <util/error.hpp>
|
||||
@@ -29,7 +29,7 @@ void SymbolValueViewer::draw(RotatedDC& dc) {
|
||||
if (symbols.empty() && !value().filename.empty()) {
|
||||
try {
|
||||
// load symbol
|
||||
SymbolP symbol = getSet().readFile<SymbolP>(value().filename);
|
||||
SymbolP symbol = getLocalPackage().readFile<SymbolP>(value().filename);
|
||||
// aspect ratio
|
||||
double ar = symbol->aspectRatio();
|
||||
ar = min(style().max_aspect_ratio, max(style().min_aspect_ratio, ar));
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <render/value/text.hpp>
|
||||
#include <render/card/viewer.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : TextValueViewer
|
||||
|
||||
@@ -19,7 +18,7 @@ bool TextValueViewer::prepare(RotatedDC& dc) {
|
||||
if (!style().mask_filename.empty() && !style().mask.ok()) {
|
||||
// load contour mask
|
||||
Image image;
|
||||
InputStreamP image_file = viewer.stylesheet->openIn(style().mask_filename);
|
||||
InputStreamP image_file = getStylePackage().openIn(style().mask_filename);
|
||||
if (image.LoadFile(*image_file)) {
|
||||
style().mask.load(image);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ ValueViewer::ValueViewer(DataViewer& parent, const StyleP& style)
|
||||
: StyleListener(style), viewer(parent)
|
||||
{}
|
||||
|
||||
Set& ValueViewer::getSet() const { return *viewer.getSet(); }
|
||||
Package& ValueViewer::getStylePackage() const { return viewer.getStylePackage(); }
|
||||
Package& ValueViewer::getLocalPackage() const { return viewer.getLocalPackage(); }
|
||||
|
||||
void ValueViewer::setValue(const ValueP& value) {
|
||||
assert(value->fieldP == styleP->fieldP); // matching field
|
||||
@@ -47,6 +48,10 @@ void ValueViewer::drawFieldBorder(RotatedDC& dc) {
|
||||
}
|
||||
}
|
||||
|
||||
void ValueViewer::redraw() {
|
||||
viewer.redraw(*this);
|
||||
}
|
||||
|
||||
bool ValueViewer::nativeLook() const {
|
||||
return viewer.nativeLook();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <data/field.hpp>
|
||||
|
||||
class Set;
|
||||
class Package;
|
||||
class DataViewer;
|
||||
class Action;
|
||||
DECLARE_POINTER_TYPE(Style);
|
||||
@@ -74,16 +75,23 @@ class ValueViewer : public StyleListener {
|
||||
protected:
|
||||
ValueP valueP; ///< The value we are currently viewing
|
||||
|
||||
/// Draws a border around the field
|
||||
void drawFieldBorder(RotatedDC& dc);
|
||||
|
||||
/// Redraw this viewer
|
||||
void redraw();
|
||||
|
||||
public:
|
||||
/// Should this viewer render using a platform native look?
|
||||
bool nativeLook() const;
|
||||
/// Is this the currently selected viewer?
|
||||
/** Usually only the editor allows selection of viewers */
|
||||
bool isCurrent() const;
|
||||
|
||||
/// Draws a border around the field
|
||||
void drawFieldBorder(RotatedDC& dc);
|
||||
|
||||
Set& getSet() const;
|
||||
/// The package containing style stuff like images
|
||||
Package& getStylePackage() const;
|
||||
/// The local package for loading/saving files
|
||||
Package& getLocalPackage() const;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : Utility
|
||||
|
||||
Reference in New Issue
Block a user