mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
New rotation system (see forum thread).
Major changes: - when rotating, the top left corner of the rectangle stays in place. - ValueViewers get a dc that is pre-rotated/translated for them, i.e. (0,0) is the top-left of the viewer (with ValueViewer::getRotation). - moved 'angle' from individual Styles to the Style base class. - any rotation angle is now possible. angle is still an int for now. This warrants a version bump git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@782 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -44,6 +44,7 @@ void DataViewer::draw(RotatedDC& dc, const Color& background) {
|
||||
bool changed_content_properties = false;
|
||||
FOR_EACH(v, viewers) { // draw low z index fields first
|
||||
if (v->getStyle()->visible) {
|
||||
Rotater r(dc, v->getRotation());
|
||||
try {
|
||||
if (v->prepare(dc)) {
|
||||
changed_content_properties = true;
|
||||
@@ -59,6 +60,7 @@ void DataViewer::draw(RotatedDC& dc, const Color& background) {
|
||||
// draw viewers
|
||||
FOR_EACH(v, viewers) { // draw low z index fields first
|
||||
if (v->getStyle()->visible) {// visible
|
||||
Rotater r(dc, v->getRotation());
|
||||
try {
|
||||
drawViewer(dc, *v);
|
||||
} catch (const Error& e) {
|
||||
@@ -104,7 +106,7 @@ Context& DataViewer::getContext() const { return set->getContext(card); }
|
||||
Rotation DataViewer::getRotation() const {
|
||||
if (!stylesheet) stylesheet = set->stylesheet;
|
||||
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
|
||||
return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), 1.0, true);
|
||||
return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Setting data
|
||||
@@ -154,8 +156,8 @@ void DataViewer::addStyles(IndexMap<FieldP,StyleP>& styles) {
|
||||
FOR_EACH(s, styles) {
|
||||
if ((s->visible || s->visible.isScripted()) &&
|
||||
(nativeLook() || (
|
||||
(s->width || s->width .isScripted() || s->right || s->right .isScripted()) &&
|
||||
(s->height || s->height .isScripted() || s->bottom || s->bottom.isScripted())))) {
|
||||
(s->width != -1 || s->width .isScripted() || s->right != -1 || s->right .isScripted()) &&
|
||||
(s->height != -1 || s->height .isScripted() || s->bottom != -1 || s->bottom.isScripted())))) {
|
||||
// no need to make a viewer for things that are always invisible
|
||||
ValueViewerP viewer = makeViewer(s);
|
||||
if (viewer) viewers.push_back(viewer);
|
||||
|
||||
@@ -365,7 +365,7 @@ void SymbolViewer::highlightPart(DC& dc, const SymbolGroup& group, HighlightStyl
|
||||
if (style == HIGHLIGHT_BORDER) {
|
||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
dc.SetPen (wxPen(Color(255,0,0), 2));
|
||||
dc.DrawRectangle(rotation.tr(RealRect(group.min_pos, RealSize(group.max_pos - group.min_pos))));
|
||||
dc.DrawRectangle(rotation.trRectToBB(RealRect(group.min_pos, RealSize(group.max_pos - group.min_pos))));
|
||||
}
|
||||
FOR_EACH_CONST(part, group.parts) {
|
||||
highlightPart(dc, *part, (HighlightStyle)(style | HIGHLIGHT_LESS));
|
||||
|
||||
@@ -39,7 +39,7 @@ struct TextViewer::Line {
|
||||
|
||||
/// Is this line visible using the given rectangle?
|
||||
bool visible(const Rotation& rot) const {
|
||||
return top + line_height > 0 && top < rot.getInternalSize().height;
|
||||
return top + line_height > 0 && top < rot.getHeight();
|
||||
}
|
||||
|
||||
/// Get a rectangle of the selection on this line
|
||||
@@ -68,7 +68,6 @@ TextViewer::~TextViewer() {}
|
||||
|
||||
void TextViewer::draw(RotatedDC& dc, const TextStyle& style, DrawWhat what) {
|
||||
assert(!lines.empty());
|
||||
Rotater r(dc, style.getRotation());
|
||||
// separator lines?
|
||||
// do this first, so pen is still set from drawing the field border
|
||||
if (what & DRAW_BORDERS) {
|
||||
@@ -99,7 +98,6 @@ RealRect intersect(const RealRect& a, const RealRect& b) {
|
||||
}
|
||||
|
||||
void TextViewer::drawSelection(RotatedDC& dc, const TextStyle& style, size_t sel_start, size_t sel_end) {
|
||||
Rotater r(dc, style.getRotation());
|
||||
if (sel_start == sel_end) return;
|
||||
if (sel_end < sel_start) swap(sel_start, sel_end);
|
||||
dc.SetBrush(*wxBLACK_BRUSH);
|
||||
@@ -148,9 +146,8 @@ void TextViewer::drawSeparators(RotatedDC& dc) {
|
||||
}
|
||||
|
||||
bool TextViewer::prepare(RotatedDC& dc, const String& text, TextStyle& style, Context& ctx) {
|
||||
if (lines.empty()) {
|
||||
if (!prepared()) {
|
||||
// not prepared yet
|
||||
Rotater r(dc, style.getRotationNoStretch());
|
||||
prepareElements(text, style, ctx);
|
||||
prepareLines(dc, text, style, ctx);
|
||||
return true;
|
||||
|
||||
+14
-26
@@ -27,21 +27,12 @@ bool ChoiceValueViewer::prepare(RotatedDC& dc) {
|
||||
ImageCombine combine = style().combine;
|
||||
style().loadMask(*viewer.stylesheet);
|
||||
Bitmap bitmap; Image image;
|
||||
img.generateCached(img_options, &style().mask, &combine, &bitmap, &image);
|
||||
int w, h;
|
||||
if (bitmap.Ok()) {
|
||||
w = bitmap.GetWidth();
|
||||
h = bitmap.GetHeight();
|
||||
} else {
|
||||
assert(image.Ok());
|
||||
w = image.GetWidth();
|
||||
h = image.GetHeight();
|
||||
}
|
||||
if (sideways(img_options.angle)) swap(w,h);
|
||||
RealSize size;
|
||||
img.generateCached(img_options, &style().mask, &combine, &bitmap, &image, &size);
|
||||
// store content properties
|
||||
if (style().content_width != w || style().content_height != h) {
|
||||
style().content_width = w;
|
||||
style().content_height = h;
|
||||
if (style().content_width != size.width || style().content_height != size.height) {
|
||||
style().content_width = size.width;
|
||||
style().content_height = size.height;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -64,21 +55,18 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
ImageCombine combine = style().combine;
|
||||
style().loadMask(*viewer.stylesheet);
|
||||
Bitmap bitmap; Image image;
|
||||
img.generateCached(img_options, &style().mask, &combine, &bitmap, &image);
|
||||
RealSize size;
|
||||
img.generateCached(img_options, &style().mask, &combine, &bitmap, &image, &size);
|
||||
size = dc.trInvS(size);
|
||||
RealRect rect(align_in_rect(style().alignment, size, dc.getInternalRect()), size);
|
||||
if (bitmap.Ok()) {
|
||||
// just draw it
|
||||
dc.DrawPreRotatedBitmap(bitmap,
|
||||
align_in_rect(style().alignment, dc.trInvNoNeg(RealSize(bitmap)), style().getRect())
|
||||
);
|
||||
margin = dc.trInv(RealSize(bitmap)).width + 1;
|
||||
dc.DrawPreRotatedBitmap(bitmap,rect);
|
||||
} else {
|
||||
// use combine mode
|
||||
dc.DrawPreRotatedImage(image,
|
||||
align_in_rect(style().alignment, dc.trInvNoNeg(RealSize(image)), style().getRect()),
|
||||
combine
|
||||
);
|
||||
margin = dc.trInv(RealSize(image)).width + 1;
|
||||
dc.DrawPreRotatedImage(image,rect,combine);
|
||||
}
|
||||
margin = size.width + 1;
|
||||
} else if (nativeLook()) {
|
||||
// always have the margin
|
||||
margin = 17;
|
||||
@@ -88,7 +76,7 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
// draw text
|
||||
dc.SetFont(style().font, 1.0);
|
||||
String text = tr(*viewer.stylesheet, value().value(), capitalize(value().value()));
|
||||
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), style().getRect()) + RealSize(margin, 0);
|
||||
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0);
|
||||
if (style().font.hasShadow()) {
|
||||
dc.SetTextForeground(style().font.shadow_color);
|
||||
dc.DrawText(text, pos + style().font.shadow_displacement);
|
||||
@@ -106,7 +94,7 @@ void ChoiceValueViewer::onStyleChange(int changes) {
|
||||
void ChoiceValueViewer::getOptions(Rotation& rot, GeneratedImage::Options& opts) {
|
||||
opts.package = viewer.stylesheet.get();
|
||||
opts.local_package = &getSet();
|
||||
opts.angle = rot.trAngle(style().angle);
|
||||
opts.angle = rot.trAngle(0);
|
||||
if (nativeLook()) {
|
||||
opts.width = opts.height = 16;
|
||||
opts.preserve_aspect = ASPECT_BORDER;
|
||||
|
||||
@@ -34,11 +34,11 @@ void ColorValueViewer::draw(RotatedDC& dc) {
|
||||
}
|
||||
// draw name and color
|
||||
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
|
||||
dc.DrawRectangle(RealRect(style().left, style().top, 40, style().height));
|
||||
dc.DrawRectangle(RealRect(0, 0, 40, dc.getHeight()));
|
||||
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.DrawRectangle(style().getRect().move(40, 0, -40, 0));
|
||||
dc.DrawText(color_name, style().getPos() + RealSize(43, 3));
|
||||
dc.DrawRectangle(RealRect(40, 0, dc.getWidth()-40, dc.getHeight()));
|
||||
dc.DrawText(color_name, RealPoint(43, 3));
|
||||
} else {
|
||||
// is there a mask?
|
||||
loadMask(dc);
|
||||
@@ -53,8 +53,8 @@ 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.tr(style().getRect()).toRect();
|
||||
r.Subtract(dc.tr(RealRect(
|
||||
wxRegion r = dc.trRectToRegion(style().getInternalRect());
|
||||
r.Subtract(dc.trRectToRegion(RealRect(
|
||||
style().left + style().left_width,
|
||||
style().top + style().top_width,
|
||||
style().width - style().left_width - style().right_width,
|
||||
@@ -62,7 +62,7 @@ void ColorValueViewer::draw(RotatedDC& dc) {
|
||||
)));
|
||||
dc.getDC().SetClippingRegion(r);
|
||||
}
|
||||
dc.DrawRoundedRectangle(style().getRect(), style().radius);
|
||||
dc.DrawRoundedRectangle(style().getInternalRect(), style().radius);
|
||||
if (clip) dc.getDC().DestroyClippingRegion();
|
||||
}
|
||||
}
|
||||
@@ -70,8 +70,8 @@ void ColorValueViewer::draw(RotatedDC& dc) {
|
||||
|
||||
bool ColorValueViewer::containsPoint(const RealPoint& p) const {
|
||||
// distance to each side
|
||||
double left = p.x - style().left, right = style().right - p.x - 1;
|
||||
double top = p.y - style().top, bottom = style().bottom - p.y - 1;
|
||||
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 || // outside bounding box
|
||||
(left >= style().left_width && right >= style().right_width && // outside horizontal border
|
||||
top >= style().top_width && bottom >= style().bottom_width)) { // outside vertical border
|
||||
@@ -93,7 +93,7 @@ void ColorValueViewer::onStyleChange(int changes) {
|
||||
|
||||
void ColorValueViewer::loadMask(const Rotation& rot) const {
|
||||
if (style().mask_filename().empty()) return; // no mask
|
||||
int w = (int) rot.trX(style().width), h = (int) rot.trY(style().height);
|
||||
int w = (int) rot.trX(rot.getWidth()), h = (int) rot.trY(rot.getHeight());
|
||||
if (alpha_mask && alpha_mask->size == wxSize(w,h)) return; // mask loaded and right size
|
||||
// (re) load the mask
|
||||
Image image;
|
||||
|
||||
+23
-35
@@ -12,14 +12,15 @@
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <gui/util.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(wxPoint);
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageValueViewer
|
||||
|
||||
void ImageValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
// reset?
|
||||
int w = (int)dc.trX(style().width), h = (int)dc.trY(style().height);
|
||||
int a = dc.trAngle(style().angle);
|
||||
if (bitmap.Ok() && (a != angle || bitmap.GetWidth() != w || bitmap.GetHeight() != h)) {
|
||||
int a = dc.trAngle(0); //% TODO : Add getAngle()?
|
||||
if (bitmap.Ok() && (a != angle || size.width != w || size.height != h)) {
|
||||
bitmap = Bitmap();
|
||||
}
|
||||
// try to load image
|
||||
@@ -65,53 +66,40 @@ void ImageValueViewer::draw(RotatedDC& dc) {
|
||||
if (image.Ok()) {
|
||||
// apply mask and rotate
|
||||
if (alpha_mask) alpha_mask->setAlpha(image);
|
||||
size = RealSize(image);
|
||||
image = rotate_image(image, angle);
|
||||
bitmap = Bitmap(image);
|
||||
}
|
||||
}
|
||||
// border
|
||||
drawFieldBorder(dc);
|
||||
// draw image, if any
|
||||
if (bitmap.Ok()) {
|
||||
dc.DrawPreRotatedBitmap(bitmap, style().getPos());
|
||||
dc.DrawPreRotatedBitmap(bitmap, dc.getInternalRect());
|
||||
}
|
||||
/*
|
||||
// if there is no image, generate a placeholder
|
||||
if (!bitmap.Ok()) {
|
||||
UInt w = (UInt)dc.trX(style().width), h = (UInt)dc.trY(style().height);
|
||||
loadMask(dc);
|
||||
if (style().default_image.isReady()) {
|
||||
// we have a script to use for the default image
|
||||
Image img = style().default_image.generate(GeneratedImage::Options(w, h, viewer.stylesheet.get(), &getSet()));
|
||||
if (viewer.drawEditing()) {
|
||||
bitmap = imagePlaceholder(dc, w, h, img, viewer.drawEditing());
|
||||
if (alpha_mask) alpha_mask->setAlpha(bitmap);
|
||||
} else {
|
||||
if (alpha_mask) alpha_mask->setAlpha(img);
|
||||
bitmap = Bitmap(img);
|
||||
}
|
||||
} else if (style().width > 40) {
|
||||
// still not okay, use a checkered image, but only if there is enough room for it
|
||||
bitmap = imagePlaceholder(dc, w, h, wxNullImage, viewer.drawEditing());
|
||||
if (alpha_mask) alpha_mask->setAlpha(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageValueViewer::drawFieldBorder(RotatedDC& dc) {
|
||||
if (!alpha_mask) {
|
||||
ValueViewer::drawFieldBorder(dc);
|
||||
} else if (viewer.drawBorders() && field().editable) {
|
||||
dc.SetPen(viewer.borderPen(isCurrent()));
|
||||
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]);
|
||||
}
|
||||
// draw image, if any
|
||||
if (bitmap.Ok()) {
|
||||
dc.DrawBitmap(bitmap, style().getPos());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool ImageValueViewer::containsPoint(const RealPoint& p) const {
|
||||
double x = p.x - style().left;
|
||||
double y = p.y - style().top;
|
||||
if (x < 0 || y < 0 || x >= style().width || y >= style().height) {
|
||||
return false; // outside rectangle
|
||||
}
|
||||
if (!ValueViewer::containsPoint(p)) return false;
|
||||
// check against mask
|
||||
if (!style().mask_filename().empty()) {
|
||||
loadMask(viewer.getRotation());
|
||||
Rotation rot = viewer.getRotation();
|
||||
return !alpha_mask || !alpha_mask->isTransparent((int)rot.trX(x), (int)rot.trY(y));
|
||||
return !alpha_mask || !alpha_mask->isTransparent((int)rot.trX(p.x), (int)rot.trY(p.y));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ class ImageValueViewer : public ValueViewer {
|
||||
|
||||
private:
|
||||
Bitmap bitmap; ///< Cached bitmap
|
||||
RealSize size; ///< Size of cached bitmap
|
||||
int angle; ///< Angle of cached bitmap
|
||||
int is_default; ///< Is the default placeholder image used?
|
||||
mutable AlphaMaskP alpha_mask;
|
||||
@@ -39,6 +40,9 @@ 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);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -23,7 +23,7 @@ void InfoValueViewer::draw(RotatedDC& dc) {
|
||||
dc.SetFont(style().font, 1.0);
|
||||
}
|
||||
// draw background
|
||||
RealRect rect = style().getRect();
|
||||
RealRect rect = style().getInternalRect();
|
||||
dc.DrawRectangle(rect.grow(2));
|
||||
// draw text
|
||||
rect = rect.move(
|
||||
|
||||
@@ -18,7 +18,7 @@ DECLARE_TYPEOF_COLLECTION(String);
|
||||
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().getRect());
|
||||
RealPoint pos = align_in_rect(style().alignment, RealSize(0,0), style().getInternalRect());
|
||||
// selected choices
|
||||
vector<String> selected;
|
||||
value().get(selected);
|
||||
@@ -55,27 +55,24 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
ImageCombine combine = style().combine;
|
||||
style().loadMask(*viewer.stylesheet);
|
||||
Bitmap bitmap; Image image;
|
||||
img.generateCached(img_options, &style().mask, &combine, &bitmap, &image);
|
||||
RealSize size;
|
||||
img.generateCached(img_options, &style().mask, &combine, &bitmap, &image, &size);
|
||||
size = dc.trInvS(size);
|
||||
RealRect rect(align_in_rect(style().alignment, size, dc.getInternalRect()), size);
|
||||
if (bitmap.Ok()) {
|
||||
// just draw it
|
||||
dc.DrawPreRotatedBitmap(bitmap,
|
||||
align_in_rect(style().alignment, dc.trInvNoNeg(RealSize(bitmap)), style().getRect())
|
||||
);
|
||||
margin = dc.trInv(RealSize(bitmap)).width + 1;
|
||||
dc.DrawPreRotatedBitmap(bitmap,rect);
|
||||
} else {
|
||||
// use combine mode
|
||||
dc.DrawPreRotatedImage(image,
|
||||
align_in_rect(style().alignment, dc.trInvNoNeg(RealSize(image)), style().getRect()),
|
||||
combine
|
||||
);
|
||||
margin = dc.trInv(RealSize(image)).width + 1;
|
||||
dc.DrawPreRotatedImage(image,rect,combine);
|
||||
}
|
||||
margin = size.width + 1;
|
||||
}
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
// draw text
|
||||
dc.DrawText(tr(*viewer.stylesheet, value().value(), capitalize(value().value())),
|
||||
align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), style().getRect()) + RealSize(margin, 0)
|
||||
align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0)
|
||||
);
|
||||
}
|
||||
// COPY ENDS HERE
|
||||
@@ -85,7 +82,7 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active) {
|
||||
RealSize size; size.height = item_height;
|
||||
if (nativeLook() && (style().render_style & RENDER_CHECKLIST)) {
|
||||
wxRect rect = dc.tr(RealRect(pos + RealSize(1,1), RealSize(12,12)));
|
||||
wxRect rect = dc.trRectStraight(RealRect(pos + RealSize(1,1), RealSize(12,12)));
|
||||
draw_checkbox(nullptr, dc.getDC(), rect, active); // TODO
|
||||
size = add_horizontal(size, RealSize(14,16));
|
||||
}
|
||||
@@ -99,8 +96,8 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
|
||||
Image image = it->second.generate(options);
|
||||
ImageCombine combine = it->second.combine();
|
||||
// TODO : alignment?
|
||||
dc.DrawPreRotatedImage(image, pos + RealSize(size.width, 0), combine == COMBINE_DEFAULT ? style().combine : combine);
|
||||
size = add_horizontal(size, dc.trInvNoNeg(RealSize(image.GetWidth() + 1, image.GetHeight())));
|
||||
dc.DrawPreRotatedImage(image, RealRect(pos.x + size.width, pos.y, options.width, options.height), combine == COMBINE_DEFAULT ? style().combine : combine);
|
||||
size.width += options.width;
|
||||
}
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
@@ -119,7 +116,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
|
||||
void MultipleChoiceValueViewer::getOptions(Rotation& rot, GeneratedImage::Options& opts) {
|
||||
opts.package = viewer.stylesheet.get();
|
||||
opts.local_package = &getSet();
|
||||
opts.angle = rot.trAngle(style().angle);
|
||||
opts.angle = rot.trAngle(0); //%%
|
||||
if (nativeLook()) {
|
||||
opts.width = opts.height = 16;
|
||||
opts.preserve_aspect = ASPECT_BORDER;
|
||||
|
||||
@@ -20,8 +20,8 @@ DECLARE_TYPEOF_COLLECTION(SymbolVariationP);
|
||||
void SymbolValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
// draw checker background
|
||||
draw_checker(dc, style().getRect());
|
||||
double wh = min(style().width, style().height);
|
||||
draw_checker(dc, style().getInternalRect());
|
||||
double wh = min(dc.getWidth(), dc.getHeight());
|
||||
// try to load symbol
|
||||
if (symbols.empty() && !value().filename.empty()) {
|
||||
try {
|
||||
@@ -45,7 +45,7 @@ void SymbolValueViewer::draw(RotatedDC& dc) {
|
||||
int x = 0;
|
||||
for (size_t i = 0 ; i < symbols.size() ; ++i) {
|
||||
// todo : labels?
|
||||
dc.DrawBitmap(symbols[i], style().getPos() + RealSize(x, 0));
|
||||
dc.DrawBitmap(symbols[i], RealPoint(x, 0));
|
||||
x += symbols[i].GetWidth() + 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ void TextValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
if (!v.prepared()) {
|
||||
v.prepare(dc, value().value(), style(), viewer.getContext());
|
||||
dc.setStretch(getStretch());
|
||||
}
|
||||
if (viewer.drawFocus() && isCurrent()) {
|
||||
v.draw(dc, style(), DRAW_ACTIVE);
|
||||
@@ -50,3 +51,7 @@ void TextValueViewer::onStyleChange(int changes) {
|
||||
void TextValueViewer::onAction(const Action&, bool undone) {
|
||||
v.reset(true);
|
||||
}
|
||||
|
||||
double TextValueViewer::getStretch() const {
|
||||
return v.prepared() ? style().getStretch() : 1.0;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ class TextValueViewer : public ValueViewer {
|
||||
virtual void onValueChange();
|
||||
virtual void onStyleChange(int);
|
||||
virtual void onAction(const Action&, bool undone);
|
||||
virtual double getStretch() const;
|
||||
|
||||
protected:
|
||||
TextViewer v;
|
||||
|
||||
@@ -32,20 +32,24 @@ void ValueViewer::setValue(const ValueP& value) {
|
||||
}
|
||||
|
||||
bool ValueViewer::containsPoint(const RealPoint& p) const {
|
||||
return p.x >= styleP->left
|
||||
&& p.y >= styleP->top
|
||||
&& p.x < styleP->left + (int)(styleP->width)
|
||||
&& p.y < styleP->top + (int)(styleP->height);
|
||||
return p.x >= 0
|
||||
&& p.y >= 0
|
||||
&& p.x < styleP->width
|
||||
&& p.y < styleP->height;
|
||||
}
|
||||
RealRect ValueViewer::boundingBox() const {
|
||||
return styleP->getRect().grow(1);
|
||||
return styleP->getExternalRect().grow(1);
|
||||
}
|
||||
|
||||
Rotation ValueViewer::getRotation() const {
|
||||
return Rotation(getStyle()->angle, getStyle()->getExternalRect(), 1.0, getStretch());
|
||||
}
|
||||
|
||||
void ValueViewer::drawFieldBorder(RotatedDC& dc) {
|
||||
if (viewer.drawBorders() && getField()->editable) {
|
||||
dc.SetPen(viewer.borderPen(isCurrent()));
|
||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
dc.DrawRectangle(styleP->getRect().grow(dc.trInvS(1)));
|
||||
dc.DrawRectangle(dc.getInternalRect().grow(dc.trInvS(1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,11 @@ class ValueViewer : public StyleListener {
|
||||
/// Get a bounding rectangle for this field (including any border it may have)
|
||||
virtual RealRect boundingBox() const;
|
||||
|
||||
/// Rotation to use for drawing this field
|
||||
virtual Rotation getRotation() const;
|
||||
/// Stretch factor
|
||||
virtual double getStretch() const { return 1.0; }
|
||||
|
||||
/// Called when the associated value is changed
|
||||
/** Both when we are associated with another value,
|
||||
* and by default when the value itself changes (called from onAction)
|
||||
|
||||
Reference in New Issue
Block a user