mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Allow ValueViewers to have a bounding box different from the Style's. This closes #64.
This commit is contained in:
@@ -50,7 +50,7 @@ void ColorValueViewer::draw(RotatedDC& dc) {
|
||||
style().top_width < style().height && style().bottom_width < style().height;
|
||||
if (clip) {
|
||||
// clip away the inside of the rectangle
|
||||
wxRegion r = dc.trRectToRegion(style().getInternalRect());
|
||||
wxRegion r = dc.trRectToRegion(dc.getInternalRect());
|
||||
r.Subtract(dc.trRectToRegion(RealRect(
|
||||
style().left_width,
|
||||
style().top_width,
|
||||
@@ -59,7 +59,7 @@ void ColorValueViewer::draw(RotatedDC& dc) {
|
||||
)));
|
||||
dc.getDC().SetClippingRegion(r);
|
||||
}
|
||||
dc.DrawRoundedRectangle(style().getInternalRect(), style().radius);
|
||||
dc.DrawRoundedRectangle(dc.getInternalRect(), style().radius);
|
||||
if (clip) dc.getDC().DestroyClippingRegion();
|
||||
}
|
||||
drawFieldBorder(dc);
|
||||
@@ -69,15 +69,15 @@ void ColorValueViewer::draw(RotatedDC& dc) {
|
||||
bool ColorValueViewer::containsPoint(const RealPoint& p) const {
|
||||
// check against mask
|
||||
const AlphaMask& alpha_mask = getMask();
|
||||
if (alpha_mask.isLoaded()) {
|
||||
if (alpha_mask.isLoaded() || nativeLook()) {
|
||||
// check against mask
|
||||
return alpha_mask.isOpaque(p, style().getSize());
|
||||
return alpha_mask.isOpaque(p, bounding_box.size());
|
||||
} else {
|
||||
double left = p.x, right = style().width - p.x - 1;
|
||||
double top = p.y, bottom = style().height - p.y - 1;
|
||||
if (left < 0 || right < 0 || top < 0 || bottom < 0) return false; // outside bounding box
|
||||
// check against border
|
||||
return left < style().left_width || right < style().right_width // inside horizontal border
|
||||
|| top < style().top_width || bottom < style().bottom_width; // inside vertical border
|
||||
|| top < style().top_width || bottom < style().bottom_width; // inside vertical border
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ void InfoValueViewer::draw(RotatedDC& dc) {
|
||||
dc.SetFont(style().font, 1.0);
|
||||
}
|
||||
// draw background
|
||||
RealRect rect = style().getInternalRect();
|
||||
RealRect rect = dc.getInternalRect();
|
||||
dc.DrawRectangle(rect.grow(2));
|
||||
// draw text
|
||||
rect = rect.move(
|
||||
|
||||
@@ -24,7 +24,7 @@ bool MultipleChoiceValueViewer::prepare(RotatedDC& dc) {
|
||||
void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
if (style().render_style & RENDER_HIDDEN) return;
|
||||
RealPoint pos = align_in_rect(style().alignment, RealSize(0,0), style().getInternalRect());
|
||||
RealPoint pos = align_in_rect(style().alignment, RealSize(0,0), dc.getInternalRect());
|
||||
// selected choices
|
||||
vector<String> selected;
|
||||
value().get(selected);
|
||||
|
||||
@@ -21,7 +21,7 @@ IMPLEMENT_VALUE_VIEWER(Symbol);
|
||||
void SymbolValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
// draw checker background
|
||||
draw_checker(dc, style().getInternalRect());
|
||||
draw_checker(dc, dc.getInternalRect());
|
||||
double wh = min(dc.getWidth(), dc.getHeight());
|
||||
// try to load symbol
|
||||
if (symbols.empty() && !value().filename.empty()) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
ValueViewer::ValueViewer(DataViewer& parent, const StyleP& style)
|
||||
: StyleListener(style), parent(parent)
|
||||
, bounding_box(style->getExternalRect())
|
||||
{}
|
||||
|
||||
Package& ValueViewer::getStylePackage() const { return parent.getStylePackage(); }
|
||||
@@ -27,14 +28,21 @@ void ValueViewer::setValue(const ValueP& value) {
|
||||
}
|
||||
|
||||
bool ValueViewer::containsPoint(const RealPoint& p) const {
|
||||
return getMask().isOpaque(p, styleP->getSize());
|
||||
return getMask().isOpaque(p, bounding_box.size());
|
||||
}
|
||||
RealRect ValueViewer::boundingBox() const {
|
||||
return styleP->getExternalRect().grow(1);
|
||||
RealRect ValueViewer::boundingBoxBorder() const {
|
||||
return bounding_box.grow(1);
|
||||
}
|
||||
bool ValueViewer::isVisible() const {
|
||||
return getStyle()->visible
|
||||
&& bounding_box.width > 0
|
||||
&& bounding_box.height > 0
|
||||
&& fabs(bounding_box.x) < 100000
|
||||
&& fabs(bounding_box.y) < 100000;
|
||||
}
|
||||
|
||||
Rotation ValueViewer::getRotation() const {
|
||||
return Rotation(deg_to_rad(getStyle()->angle), getStyle()->getExternalRect(), 1.0, getStretch());
|
||||
return Rotation(deg_to_rad(getStyle()->angle), bounding_box, 1.0, getStretch());
|
||||
}
|
||||
|
||||
#if defined(__WXMSW__)
|
||||
@@ -113,4 +121,6 @@ void ValueViewer::onStyleChange(int changes) {
|
||||
if (!(changes & CHANGE_ALREADY_PREPARED)) {
|
||||
parent.redraw(*this);
|
||||
}
|
||||
// update bounding box
|
||||
if (!nativeLook()) bounding_box = getStyle()->getExternalRect();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,9 @@ public:
|
||||
/// Does this field contian the given point?
|
||||
virtual bool containsPoint(const RealPoint& p) const;
|
||||
/// Get a bounding rectangle for this field (including any border it may have)
|
||||
virtual RealRect boundingBox() const;
|
||||
virtual RealRect boundingBoxBorder() const;
|
||||
/// Is this field visible?
|
||||
bool isVisible() const;
|
||||
|
||||
/// Rotation to use for drawing this field
|
||||
virtual Rotation getRotation() const;
|
||||
@@ -73,6 +75,7 @@ public:
|
||||
|
||||
public:
|
||||
DataViewer& parent; ///< Our parent object
|
||||
RealRect bounding_box; ///< The bounding box of this viewer. Corresponds to styleP->getExternalRect(), except for native look editor
|
||||
protected:
|
||||
ValueP valueP; ///< The value we are currently viewing
|
||||
|
||||
|
||||
Reference in New Issue
Block a user