Moved mask to Style and mask related drawing to ValueViewer.

Used the same mask also for TextStyles.
To keep the text selectable (since the mask is now also used for containsPoint), the future sight cost masks needed to be updated.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1183 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-08-30 23:49:12 +00:00
parent a183ecc9a6
commit a2af3211a4
28 changed files with 105 additions and 214 deletions
+1 -31
View File
@@ -22,46 +22,16 @@ bool ChoiceValueViewer::prepare(RotatedDC& dc) {
return prepare_choice_viewer(dc, *this, style(), value().value());
}
void ChoiceValueViewer::draw(RotatedDC& dc) {
int w = max(0,(int)dc.trX(style().width)), h = max(0,(int)dc.trY(style().height));
const AlphaMask& alpha_mask = getMask(w,h);
drawFieldBorder(dc, alpha_mask);
drawFieldBorder(dc);
if (style().render_style & RENDER_HIDDEN) return;
draw_choice_viewer(dc, *this, style(), value().value());
}
void ChoiceValueViewer::drawFieldBorder(RotatedDC& dc, const AlphaMask& alpha_mask) {
if (!alpha_mask.isLoaded()) {
ValueViewer::drawFieldBorder(dc);
} else if (setFieldBorderPen(dc)) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
vector<wxPoint> points;
alpha_mask.convexHull(points);
if (points.size() < 3) return;
FOR_EACH(p, points) p = dc.trPixelNoZoom(RealPoint(p.x,p.y));
dc.getDC().DrawPolygon((int)points.size(), &points[0]);
}
}
bool ChoiceValueViewer::containsPoint(const RealPoint& p) const {
// check against mask
return getMask(0,0).isOpaque(p, style().getSize());
}
void ChoiceValueViewer::onStyleChange(int changes) {
if (changes & CHANGE_MASK) style().image.clearCache();
ValueViewer::onStyleChange(changes);
}
const AlphaMask& ChoiceValueViewer::getMask(int w, int h) const {
GeneratedImage::Options opts;
opts.package = &viewer.getStylePackage();
opts.local_package = &viewer.getLocalPackage();
opts.angle = 0;
opts.width = w;
opts.height = h;
return style().mask.get(opts);
}
// ----------------------------------------------------------------------------- : Generic draw/prepare
bool prepare_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value) {
-9
View File
@@ -23,19 +23,10 @@ class ChoiceValueViewer : public ValueViewer {
virtual bool prepare(RotatedDC& dc);
virtual void draw(RotatedDC& dc);
virtual void onStyleChange(int);
virtual bool containsPoint(const RealPoint& p) const;
private:
/// Draws a border around the field
void drawFieldBorder(RotatedDC& dc, const AlphaMask& alpha_mask);
/// Load the AlphaMask for this field
const AlphaMask& getMask(int w, int h) const;
};
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);
const AlphaMask& get_mask(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, int w, int h);
// ----------------------------------------------------------------------------- : EOF
#endif
+3 -27
View File
@@ -44,8 +44,7 @@ void ColorValueViewer::draw(RotatedDC& dc) {
dc.DrawText(color_name, RealPoint(43, 3));
} else {
// is there a mask?
int w = max(0,(int)dc.trX(style().width)), h = max(0,(int)dc.trY(style().height));
const AlphaMask& alpha_mask = getMask(w,h);
const AlphaMask& alpha_mask = getMask(dc);
if (alpha_mask.isLoaded()) {
dc.DrawImage(alpha_mask.colorImage(value().value()), RealPoint(0,0), style().combine);
} else {
@@ -66,26 +65,13 @@ void ColorValueViewer::draw(RotatedDC& dc) {
dc.DrawRoundedRectangle(style().getInternalRect(), style().radius);
if (clip) dc.getDC().DestroyClippingRegion();
}
drawFieldBorder(dc, alpha_mask);
}
}
void ColorValueViewer::drawFieldBorder(RotatedDC& dc, const AlphaMask& alpha_mask) {
if (!alpha_mask.isLoaded()) {
ValueViewer::drawFieldBorder(dc);
} else if (setFieldBorderPen(dc)) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
vector<wxPoint> points;
alpha_mask.convexHull(points);
if (points.size() < 3) return;
FOR_EACH(p, points) p = dc.trPixelNoZoom(RealPoint(p.x,p.y));
dc.getDC().DrawPolygon((int)points.size(), &points[0]);
drawFieldBorder(dc);
}
}
bool ColorValueViewer::containsPoint(const RealPoint& p) const {
// check against mask
const AlphaMask& alpha_mask = getMask(0,0);
const AlphaMask& alpha_mask = getMask();
if (alpha_mask.isLoaded()) {
// check against mask
return alpha_mask.isOpaque(p, style().getSize());
@@ -98,13 +84,3 @@ bool ColorValueViewer::containsPoint(const RealPoint& p) const {
|| top < style().top_width || bottom < style().bottom_width; // inside vertical border
}
}
const AlphaMask& ColorValueViewer::getMask(int w, int h) const {
GeneratedImage::Options opts;
opts.package = &viewer.getStylePackage();
opts.local_package = &viewer.getLocalPackage();
opts.angle = 0;
opts.width = w;
opts.height = h;
return style().mask.get(opts);
}
-6
View File
@@ -24,12 +24,6 @@ class ColorValueViewer : public ValueViewer {
virtual void draw(RotatedDC& dc);
virtual bool containsPoint(const RealPoint& p) const;
private:
/// Draws a border around the field
void drawFieldBorder(RotatedDC& dc, const AlphaMask& alpha_mask);
/// Load the AlphaMask for this field
const AlphaMask& getMask(int w, int h) const;
};
// ----------------------------------------------------------------------------- : EOF
+1 -29
View File
@@ -74,31 +74,13 @@ void ImageValueViewer::draw(RotatedDC& dc) {
}
}
// border
drawFieldBorder(dc, alpha_mask);
drawFieldBorder(dc);
// draw image, if any
if (bitmap.Ok()) {
dc.DrawPreRotatedBitmap(bitmap, dc.getInternalRect());
}
}
void ImageValueViewer::drawFieldBorder(RotatedDC& dc, const AlphaMask& alpha_mask) {
if (!alpha_mask.isLoaded()) {
ValueViewer::drawFieldBorder(dc);
} else if (setFieldBorderPen(dc)) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
vector<wxPoint> points;
alpha_mask.convexHull(points);
if (points.size() < 3) return;
FOR_EACH(p, points) p = dc.trPixelNoZoom(RealPoint(p.x,p.y));
dc.getDC().DrawPolygon((int)points.size(), &points[0]);
}
}
bool ImageValueViewer::containsPoint(const RealPoint& p) const {
// check against mask
return getMask(0,0).isOpaque(p, style().getSize());
}
void ImageValueViewer::onValueChange() {
bitmap = Bitmap();
}
@@ -111,16 +93,6 @@ void ImageValueViewer::onStyleChange(int changes) {
ValueViewer::onStyleChange(changes);
}
const AlphaMask& ImageValueViewer::getMask(int w, int h) const {
GeneratedImage::Options opts;
opts.package = &viewer.getStylePackage();
opts.local_package = &viewer.getLocalPackage();
opts.angle = 0;
opts.width = w;
opts.height = h;
return style().mask.get(opts);
}
// is an image very light?
bool very_light(const Image& image) {
int w = image.GetWidth(), h = image.GetHeight();
-9
View File
@@ -23,9 +23,6 @@ class ImageValueViewer : public ValueViewer {
DECLARE_VALUE_VIEWER(Image) : ValueViewer(parent,style) {}
virtual void draw(RotatedDC& dc);
virtual bool containsPoint(const RealPoint& p) const;
virtual void onValueChange();
virtual void onStyleChange(int);
@@ -37,12 +34,6 @@ class ImageValueViewer : public ValueViewer {
/// Generate a placeholder image
static Bitmap imagePlaceholder(const Rotation& rot, UInt w, UInt h, const Image& background, bool editing);
/// Draws a border around the field
void drawFieldBorder(RotatedDC& dc, const AlphaMask& alpha_mask);
/// Load the AlphaMask for this field
const AlphaMask& getMask(int w, int h) const;
};
// ----------------------------------------------------------------------------- : EOF
+1 -31
View File
@@ -25,9 +25,7 @@ bool MultipleChoiceValueViewer::prepare(RotatedDC& dc) {
}
void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
int w = max(0,(int)dc.trX(style().width)), h = max(0,(int)dc.trY(style().height));
const AlphaMask& alpha_mask = getMask(w,h);
drawFieldBorder(dc, alpha_mask);
drawFieldBorder(dc);
if (style().render_style & RENDER_HIDDEN) return;
RealPoint pos = align_in_rect(style().alignment, RealSize(0,0), style().getInternalRect());
// selected choices
@@ -86,35 +84,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
pos = move_in_direction(style().direction, pos, size, style().spacing);
}
void MultipleChoiceValueViewer::drawFieldBorder(RotatedDC& dc, const AlphaMask& alpha_mask) {
if (!alpha_mask.isLoaded()) {
ValueViewer::drawFieldBorder(dc);
} else if (setFieldBorderPen(dc)) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
vector<wxPoint> points;
alpha_mask.convexHull(points);
if (points.size() < 3) return;
FOR_EACH(p, points) p = dc.trPixelNoZoom(RealPoint(p.x,p.y));
dc.getDC().DrawPolygon((int)points.size(), &points[0]);
}
}
bool MultipleChoiceValueViewer::containsPoint(const RealPoint& p) const {
// check against mask
return getMask(0,0).isOpaque(p, style().getSize());
}
void MultipleChoiceValueViewer::onStyleChange(int changes) {
if (changes & CHANGE_MASK) style().image.clearCache();
ValueViewer::onStyleChange(changes);
}
const AlphaMask& MultipleChoiceValueViewer::getMask(int w, int h) const {
GeneratedImage::Options opts;
opts.package = &viewer.getStylePackage();
opts.local_package = &viewer.getLocalPackage();
opts.angle = 0;
opts.width = w;
opts.height = h;
return style().mask.get(opts);
}
-5
View File
@@ -23,15 +23,10 @@ class MultipleChoiceValueViewer : public ValueViewer {
virtual bool prepare(RotatedDC& dc);
virtual void draw(RotatedDC& dc);
virtual void onStyleChange(int);
virtual bool containsPoint(const RealPoint& p) const;
protected:
double item_height; ///< Height of a single item, or 0 if non uniform
private:
void drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active = true);
/// Draws a border around the field
void drawFieldBorder(RotatedDC& dc, const AlphaMask& alpha_mask);
/// Load the AlphaMask for this field
const AlphaMask& getMask(int w, int h) const;
};
// ----------------------------------------------------------------------------- : EOF
+1 -8
View File
@@ -15,14 +15,7 @@
IMPLEMENT_VALUE_VIEWER(Text);
bool TextValueViewer::prepare(RotatedDC& dc) {
if (!style().mask_filename.empty() && !style().mask.isLoaded()) {
// load contour mask
Image image;
InputStreamP image_file = getStylePackage().openIn(style().mask_filename);
if (image.LoadFile(*image_file)) {
style().mask.load(image);
}
}
getMask(dc); // ensure alpha/contour mask is loaded
return v.prepare(dc, value().value(), style(), viewer.getContext());
}
+24 -5
View File
@@ -10,6 +10,8 @@
#include <render/value/viewer.hpp>
#include <render/card/viewer.hpp>
DECLARE_TYPEOF_COLLECTION(wxPoint);
// ----------------------------------------------------------------------------- : ValueViewer
ValueViewer::ValueViewer(DataViewer& parent, const StyleP& style)
@@ -27,10 +29,7 @@ void ValueViewer::setValue(const ValueP& value) {
}
bool ValueViewer::containsPoint(const RealPoint& p) const {
return p.x >= 0
&& p.y >= 0
&& p.x < styleP->width
&& p.y < styleP->height;
return getMask().isOpaque(p, styleP->getSize());
}
RealRect ValueViewer::boundingBox() const {
return styleP->getExternalRect().grow(1);
@@ -54,10 +53,30 @@ bool ValueViewer::setFieldBorderPen(RotatedDC& dc) {
void ValueViewer::drawFieldBorder(RotatedDC& dc) {
if (setFieldBorderPen(dc)) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(dc.getInternalRect().grow(dc.trInvS(1)));
const AlphaMask& alpha_mask = getMask(dc);
if (alpha_mask.isLoaded()) {
// from mask
vector<wxPoint> points;
alpha_mask.convexHull(points);
if (points.size() < 3) return;
FOR_EACH(p, points) p = dc.trPixelNoZoom(RealPoint(p.x,p.y));
dc.getDC().DrawPolygon((int)points.size(), &points[0]);
} else {
// simple rectangle
dc.DrawRectangle(dc.getInternalRect().grow(dc.trInvS(1)));
}
}
}
const AlphaMask& ValueViewer::getMask(int w, int h) const {
GeneratedImage::Options opts(w, h, &getStylePackage(), &getLocalPackage());
return styleP->mask.get(opts);
}
const AlphaMask& ValueViewer::getMask(const Rotation& rot) const {
return getMask((int)rot.trX(styleP->width), (int)rot.trY(styleP->height));
}
void ValueViewer::redraw() {
viewer.redraw(*this);
}
+4
View File
@@ -83,6 +83,10 @@ class ValueViewer : public StyleListener {
/// Redraw this viewer
void redraw();
/// Load the AlphaMask for this field, scaled but not rotated
const AlphaMask& getMask(int w = 0, int h = 0) const;
const AlphaMask& getMask(const Rotation& rot) const;
public:
/// Should this viewer render using a platform native look?
bool nativeLook() const;