mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Conversion to new ScriptableImage complete, this affected quite a bit, including the evil thumbnail thread;
Added StyleListener, so style changes are only propagated to interested viewers. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@329 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -34,15 +34,19 @@ void DataViewer::draw(DC& dc) {
|
||||
}
|
||||
void DataViewer::draw(RotatedDC& dc, const Color& background) {
|
||||
if (!set) return; // no set specified, don't draw anything
|
||||
drawing = true;
|
||||
// fill with background color
|
||||
clearDC(dc.getDC(), background);
|
||||
// update style scripts
|
||||
//%% if (card) set->updateFor(card);
|
||||
Context& ctx = getContext();
|
||||
FOR_EACH(v, viewers) {
|
||||
if (v->getStyle()->update(ctx)) {
|
||||
v->onStyleChange();
|
||||
try {
|
||||
Context& ctx = getContext();
|
||||
FOR_EACH(v, viewers) {
|
||||
if (v->getStyle()->update(ctx)) {
|
||||
v->getStyle()->tellListeners();
|
||||
}
|
||||
}
|
||||
} catch (const Error& e) {
|
||||
handle_error(e, false, false);
|
||||
}
|
||||
// draw values
|
||||
FOR_EACH(v, viewers) { // draw low z index fields first
|
||||
@@ -54,6 +58,7 @@ void DataViewer::draw(RotatedDC& dc, const Color& background) {
|
||||
}
|
||||
}
|
||||
}
|
||||
drawing = false;
|
||||
}
|
||||
void DataViewer::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
v.draw(dc);
|
||||
@@ -159,16 +164,16 @@ void DataViewer::onAction(const Action& action, bool undone) {
|
||||
}
|
||||
}
|
||||
}
|
||||
TYPE_CASE(action, ScriptStyleEvent) {
|
||||
/*//% TYPE_CASE(action, ScriptStyleEvent) {
|
||||
if (action.stylesheet == stylesheet.get()) {
|
||||
FOR_EACH(v, viewers) {
|
||||
if (v->getStyle().get() == action.style) {
|
||||
// refresh the viewer
|
||||
v->onStyleChange();
|
||||
onChange();
|
||||
if (!drawing) onChange();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ class Context;
|
||||
/// A viewer can generate an image of some values, usually a card.
|
||||
class DataViewer : public SetView {
|
||||
public:
|
||||
DataViewer() : drawing(false) {}
|
||||
|
||||
// --------------------------------------------------- : Drawing
|
||||
|
||||
/// Draw the current (card/data) to the given dc
|
||||
@@ -56,6 +58,8 @@ class DataViewer : public SetView {
|
||||
virtual Rotation getRotation() const;
|
||||
/// The card we are viewing
|
||||
inline CardP getCard() const { return card; }
|
||||
/// Invalidate and redraw (the area of) a single value viewer
|
||||
virtual void redraw(const ValueViewer&) {}
|
||||
|
||||
// --------------------------------------------------- : Setting data
|
||||
|
||||
@@ -86,6 +90,7 @@ 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
|
||||
};
|
||||
|
||||
@@ -366,7 +366,7 @@ void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle
|
||||
// no text, find a dummy height for the single line we have
|
||||
if (lines.size() == 1 && lines[0].width() < 0.0001) {
|
||||
if (style.always_symbol && style.symbol_font.valid()) {
|
||||
lines[0].line_height = style.symbol_font.font->defaultSymbolSize(ctx, style.symbol_font.size).height;
|
||||
lines[0].line_height = style.symbol_font.font->defaultSymbolSize(style.symbol_font.size).height;
|
||||
} else {
|
||||
dc.SetFont(style.font, scale);
|
||||
lines[0].line_height = dc.GetCharHeight();
|
||||
|
||||
+25
-22
@@ -20,34 +20,33 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
if (style().render_style & RENDER_IMAGE) {
|
||||
// draw image
|
||||
map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(value().value()));
|
||||
if (it != style().choice_images.end()) {
|
||||
if (it != style().choice_images.end() && it->second.isReady()) {
|
||||
ScriptableImage& img = it->second;
|
||||
ScriptImageP i;
|
||||
GeneratedImage::Options img_options(0,0, viewer.stylesheet.get(), &getSet());
|
||||
if (nativeLook()) {
|
||||
i = img.update(viewer.getContext(), *viewer.stylesheet, 16, 16, ASPECT_BORDER, false);
|
||||
img_options.width = img_options.height = 16;
|
||||
img_options.preserve_aspect = ASPECT_BORDER;
|
||||
} else if(style().render_style & RENDER_TEXT) {
|
||||
// also drawing text
|
||||
i = img.update(viewer.getContext(), *viewer.stylesheet, 0, 0);
|
||||
// also drawing text, use original size
|
||||
} else {
|
||||
i = img.update(viewer.getContext(), *viewer.stylesheet,
|
||||
(int) dc.trS(style().width), (int) dc.trS(style().height),
|
||||
style().alignment == ALIGN_STRETCH ? ASPECT_STRETCH : ASPECT_FIT
|
||||
);
|
||||
img_options.width = (int) dc.trS(style().width);
|
||||
img_options.height = (int) dc.trS(style().height);
|
||||
img_options.preserve_aspect = style().alignment == ALIGN_STRETCH ? ASPECT_STRETCH : ASPECT_FIT;
|
||||
}
|
||||
if (i) {
|
||||
// apply mask?
|
||||
style().loadMask(*viewer.stylesheet);
|
||||
if (style().mask.Ok()) {
|
||||
set_alpha(i->image, style().mask);
|
||||
}
|
||||
// draw
|
||||
dc.DrawImage(i->image,
|
||||
align_in_rect(style().alignment, RealSize(i->image.GetWidth(), i->image.GetHeight()), style().getRect()),
|
||||
i->combine == COMBINE_NORMAL ? style().combine : i->combine,
|
||||
style().angle
|
||||
);
|
||||
margin = dc.trInvS(i->image.GetWidth()) + 1;
|
||||
Image image = img.generate(img_options, true);
|
||||
ImageCombine combine = img.combine();
|
||||
// apply mask?
|
||||
style().loadMask(*viewer.stylesheet);
|
||||
if (style().mask.Ok()) {
|
||||
set_alpha(image, style().mask);
|
||||
}
|
||||
// draw
|
||||
dc.DrawImage(image,
|
||||
align_in_rect(style().alignment, RealSize(image.GetWidth(), image.GetHeight()), style().getRect()),
|
||||
combine == COMBINE_NORMAL ? style().combine : combine,
|
||||
style().angle
|
||||
);
|
||||
margin = dc.trInvS(image.GetWidth()) + 1;
|
||||
}
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
@@ -57,3 +56,7 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void ChoiceValueViewer::onStyleChange() {
|
||||
viewer.redraw(*this);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class ChoiceValueViewer : public ValueViewer {
|
||||
DECLARE_VALUE_VIEWER(Choice) : ValueViewer(parent,style) {}
|
||||
|
||||
virtual void draw(RotatedDC& dc);
|
||||
virtual void onStyleChange();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -88,6 +88,7 @@ bool ColorValueViewer::containsPoint(const RealPoint& p) const {
|
||||
|
||||
void ColorValueViewer::onStyleChange() {
|
||||
alpha_mask = AlphaMaskP();
|
||||
viewer.redraw(*this);
|
||||
}
|
||||
|
||||
void ColorValueViewer::loadMask(const Rotation& rot) const {
|
||||
|
||||
@@ -80,6 +80,7 @@ void ImageValueViewer::onValueChange() {
|
||||
void ImageValueViewer::onStyleChange() {
|
||||
bitmap = Bitmap();
|
||||
alpha_mask = AlphaMaskP(); // TODO: only reload whatever has changed
|
||||
viewer.redraw(*this);
|
||||
}
|
||||
|
||||
void ImageValueViewer::loadMask(const Rotation& rot) const {
|
||||
|
||||
@@ -49,13 +49,12 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
|
||||
}
|
||||
if (style().render_style & RENDER_IMAGE) {
|
||||
map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(choice));
|
||||
if (it != style().choice_images.end()) {
|
||||
ScriptImageP i = it->second.update(viewer.getContext(), *viewer.stylesheet, 0, 0);
|
||||
if (i) {
|
||||
// TODO : alignment?
|
||||
dc.DrawImage(i->image, pos + RealSize(size.width, 0), i->combine == COMBINE_NORMAL ? style().combine : i->combine);
|
||||
size = add_horizontal(size, dc.trInv(RealSize(i->image.GetWidth() + 1, i->image.GetHeight())));
|
||||
}
|
||||
if (it != style().choice_images.end() && it->second.isReady()) {
|
||||
Image image = it->second.generate(GeneratedImage::Options(0,0, viewer.stylesheet.get(),&getSet()), true);
|
||||
ImageCombine combine = it->second.combine();
|
||||
// TODO : alignment?
|
||||
dc.DrawImage(image, pos + RealSize(size.width, 0), combine == COMBINE_NORMAL ? style().combine : combine);
|
||||
size = add_horizontal(size, dc.trInv(RealSize(image.GetWidth() + 1, image.GetHeight())));
|
||||
}
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
|
||||
@@ -36,4 +36,5 @@ void TextValueViewer::onValueChange() {
|
||||
|
||||
void TextValueViewer::onStyleChange() {
|
||||
v.reset();
|
||||
viewer.redraw(*this);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
// ----------------------------------------------------------------------------- : ValueViewer
|
||||
|
||||
ValueViewer::ValueViewer(DataViewer& parent, const StyleP& style)
|
||||
: viewer(parent), styleP(style)
|
||||
: StyleListener(style), viewer(parent)
|
||||
{}
|
||||
|
||||
Set& ValueViewer::getSet() const { return *viewer.getSet(); }
|
||||
|
||||
@@ -24,7 +24,7 @@ DECLARE_POINTER_TYPE(Value);
|
||||
|
||||
/// The virtual viewer control for a single field on a card (or in the set data)
|
||||
/** A viewer can only display a value, not edit it, ValueEditor is used for that */
|
||||
class ValueViewer {
|
||||
class ValueViewer : public StyleListener{
|
||||
public:
|
||||
/// Construct a ValueViewer, set the value at a later time
|
||||
ValueViewer(DataViewer& parent, const StyleP& style);
|
||||
@@ -62,7 +62,6 @@ class ValueViewer {
|
||||
|
||||
DataViewer& viewer; ///< Our parent object
|
||||
protected:
|
||||
StyleP styleP; ///< The style of this viewer
|
||||
ValueP valueP; ///< The value we are currently viewing
|
||||
|
||||
/// Should this viewer render using a platform native look?
|
||||
|
||||
Reference in New Issue
Block a user