mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Cleaned up Set::Styling/Card::Styling by spliting that functionality into a 'DelayedIndexMaps' class;
Added 'right' and 'bottom' properties to style as an alternative way of specifying width/height; Added content_width, content_height and content_lines properties that give feedback on text rendering; Always show warnings when showing errors and vice-versa, this prevents script errors from appearing before the reader/parse error that caused them; Finally some preliminairy work on export templates git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@428 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -54,7 +54,17 @@ void DataViewer::draw(RotatedDC& dc, const Color& background) {
|
||||
} catch (const Error& e) {
|
||||
handle_error(e, false, false);
|
||||
}
|
||||
// draw values
|
||||
// prepare viewers
|
||||
FOR_EACH(v, viewers) { // draw low z index fields first
|
||||
if (v->getStyle()->visible) {
|
||||
try {
|
||||
v->prepare(dc);
|
||||
} catch (const Error& e) {
|
||||
handle_error(e, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// draw viewers
|
||||
FOR_EACH(v, viewers) { // draw low z index fields first
|
||||
if (v->getStyle()->visible) {// visible
|
||||
try {
|
||||
@@ -133,8 +143,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->height || s->height .isScripted()))) {
|
||||
(s->width || s->width .isScripted() || s->right || s->right .isScripted()) &&
|
||||
(s->height || s->height .isScripted() || s->bottom || 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);
|
||||
|
||||
@@ -131,7 +131,7 @@ void TextViewer::drawSeparators(RotatedDC& dc) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextViewer::prepare(RotatedDC& dc, const String& text, const TextStyle& style, Context& ctx) {
|
||||
void TextViewer::prepare(RotatedDC& dc, const String& text, TextStyle& style, Context& ctx) {
|
||||
if (lines.empty()) {
|
||||
// not prepared yet
|
||||
Rotater r(dc, style.getRotation());
|
||||
@@ -312,7 +312,7 @@ void TextViewer::prepareElements(const String& text, const TextStyle& style, Con
|
||||
|
||||
// ----------------------------------------------------------------------------- : Layout
|
||||
|
||||
void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle& style, Context& ctx) {
|
||||
void TextViewer::prepareLines(RotatedDC& dc, const String& text, TextStyle& style, Context& ctx) {
|
||||
// try to layout, at different scales
|
||||
vector<CharInfo> chars;
|
||||
scale = 1;
|
||||
@@ -363,6 +363,19 @@ void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle
|
||||
// returns negative values if it fits, positive if it doesn't
|
||||
*/
|
||||
|
||||
// store information about the content/layout, allow this to change alignment
|
||||
style.content_width = 0;
|
||||
FOR_EACH(l, lines) {
|
||||
style.content_width = max(style.content_width, l.width());
|
||||
}
|
||||
style.content_height = 0;
|
||||
FOR_EACH_REVERSE(l, lines) {
|
||||
style.content_height = l.top + l.line_height;
|
||||
if (l.line_height) break; // not an empty line
|
||||
}
|
||||
style.content_lines = (int)lines.size();
|
||||
style.alignment.update(ctx); // allow this to affect the alignment
|
||||
|
||||
// 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()) {
|
||||
|
||||
@@ -54,7 +54,7 @@ class TextViewer {
|
||||
void drawSeparators(RotatedDC& dc);
|
||||
|
||||
/// Prepare the text for drawing, if it is not already prepared
|
||||
void prepare(RotatedDC& dc, const String& text, const TextStyle& style, Context&);
|
||||
void prepare(RotatedDC& dc, const String& text, TextStyle& style, Context&);
|
||||
/// Reset the cached data, at a new call to draw it will be recalculated
|
||||
void reset();
|
||||
|
||||
@@ -130,7 +130,7 @@ class TextViewer {
|
||||
vector<Line> lines; ///< The lines in the text box
|
||||
|
||||
/// Prepare the lines, layout the text
|
||||
void prepareLines(RotatedDC& dc, const String& text, const TextStyle& style, Context& ctx);
|
||||
void prepareLines(RotatedDC& dc, const String& text, TextStyle& style, Context& ctx);
|
||||
/// Prepare the lines, layout the text; at a specific scale
|
||||
bool prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars, const TextStyle& style, bool stop_if_too_long);
|
||||
/// Align the lines within the textbox
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : TextValueViewer
|
||||
|
||||
void TextValueViewer::draw(RotatedDC& dc) {
|
||||
void TextValueViewer::prepare(RotatedDC& dc) {
|
||||
if (!style().mask_filename.empty() && !style().mask.ok()) {
|
||||
// load contour mask
|
||||
Image image;
|
||||
@@ -21,8 +21,11 @@ void TextValueViewer::draw(RotatedDC& dc) {
|
||||
style().mask.load(image);
|
||||
}
|
||||
}
|
||||
drawFieldBorder(dc);
|
||||
v.prepare(dc, value().value(), style(), viewer.getContext());
|
||||
}
|
||||
|
||||
void TextValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
v.draw(dc, style(), (DrawWhat)(
|
||||
DRAW_NORMAL
|
||||
| (viewer.drawBorders() ? DRAW_BORDERS : 0)
|
||||
|
||||
@@ -21,6 +21,7 @@ class TextValueViewer : public ValueViewer {
|
||||
public:
|
||||
DECLARE_VALUE_VIEWER(Text) : ValueViewer(parent,style) {}
|
||||
|
||||
virtual void prepare(RotatedDC& dc);
|
||||
virtual void draw(RotatedDC& dc);
|
||||
virtual void onValueChange();
|
||||
virtual void onStyleChange();
|
||||
|
||||
@@ -39,7 +39,10 @@ class ValueViewer : public StyleListener {
|
||||
/// Return the associated value
|
||||
inline const ValueP& getValue() const { return valueP; }
|
||||
|
||||
// Draw this value
|
||||
/// Prepare before drawing.
|
||||
/** Scripts are updated after preparing, allowing */
|
||||
virtual void prepare(RotatedDC& dc) {};
|
||||
/// Draw this value
|
||||
virtual void draw(RotatedDC& dc) = 0;
|
||||
|
||||
/// Does this field contian the given point?
|
||||
|
||||
Reference in New Issue
Block a user