mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37:00 -04:00
Use enum class
This commit is contained in:
@@ -387,7 +387,7 @@ void SymbolFont::getCharInfo(RotatedDC& dc, double font_size, const SplitSymbols
|
|||||||
RealSize size = dc.trInvS(symbolSize(dc.trS(font_size), sym));
|
RealSize size = dc.trInvS(symbolSize(dc.trS(font_size), sym));
|
||||||
size.width /= count; // divide into count parts
|
size.width /= count; // divide into count parts
|
||||||
for (size_t i = 0 ; i < count ; ++i) {
|
for (size_t i = 0 ; i < count ; ++i) {
|
||||||
out.push_back(CharInfo(size, i == count - 1 ? BREAK_MAYBE : BREAK_NO));
|
out.push_back(CharInfo(size, i == count - 1 ? LineBreak::MAYBE : LineBreak::NO));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,8 +205,8 @@ struct TextElementsFromString {
|
|||||||
} else {
|
} else {
|
||||||
// text, possibly mixed with symbols
|
// text, possibly mixed with symbols
|
||||||
DrawWhat what = soft > 0 ? DRAW_ACTIVE : DRAW_NORMAL;
|
DrawWhat what = soft > 0 ? DRAW_ACTIVE : DRAW_NORMAL;
|
||||||
LineBreak line_break = line > 0 ? BREAK_LINE :
|
LineBreak line_break = line > 0 ? LineBreak::LINE :
|
||||||
soft_line > 0 ? BREAK_SOFT : BREAK_HARD;
|
soft_line > 0 ? LineBreak::SOFT : LineBreak::HARD;
|
||||||
if (kwpph > 0 || param > 0) {
|
if (kwpph > 0 || param > 0) {
|
||||||
// bracket the text
|
// bracket the text
|
||||||
content = String(LEFT_ANGLE_BRACKET) + content + RIGHT_ANGLE_BRACKET;
|
content = String(LEFT_ANGLE_BRACKET) + content + RIGHT_ANGLE_BRACKET;
|
||||||
|
|||||||
@@ -23,23 +23,23 @@ class SymbolFontRef;
|
|||||||
// ----------------------------------------------------------------------------- : TextElement
|
// ----------------------------------------------------------------------------- : TextElement
|
||||||
|
|
||||||
/// Information on a linebreak
|
/// Information on a linebreak
|
||||||
enum LineBreak
|
enum class LineBreak {
|
||||||
{ BREAK_NO // no line break ever
|
NO, // no line break ever
|
||||||
, BREAK_MAYBE // break here when in "direction:vertical" mode
|
MAYBE, // break here when in "direction:vertical" mode
|
||||||
, BREAK_SPACE // optional line break (' ')
|
SPACE, // optional line break (' ')
|
||||||
, BREAK_SOFT // always a line break, spacing as a soft break
|
SOFT, // always a line break, spacing as a soft break
|
||||||
, BREAK_HARD // always a line break ('\n')
|
HARD, // always a line break ('\n')
|
||||||
, BREAK_LINE // line break with a separator line (<line>)
|
LINE, // line break with a separator line (<line>)
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Information on a character in a TextElement
|
/// Information on a character in a TextElement
|
||||||
struct CharInfo {
|
struct CharInfo {
|
||||||
RealSize size; ///< Size of this character
|
RealSize size; ///< Size of this character
|
||||||
LineBreak break_after : 31; ///< How/when to break after it?
|
LineBreak break_after : 16; ///< How/when to break after it?
|
||||||
bool soft : 1; ///< Is this a 'soft' character? soft characters are ignored for alignment
|
bool soft : 1; ///< Is this a 'soft' character? soft characters are ignored for alignment
|
||||||
|
|
||||||
explicit CharInfo()
|
explicit CharInfo()
|
||||||
: break_after(BREAK_NO), soft(true)
|
: break_after(LineBreak::NO), soft(true)
|
||||||
{}
|
{}
|
||||||
inline CharInfo(RealSize size, LineBreak break_after, bool soft = false)
|
inline CharInfo(RealSize size, LineBreak break_after, bool soft = false)
|
||||||
: size(size), break_after(break_after), soft(soft)
|
: size(size), break_after(break_after), soft(soft)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>&
|
|||||||
RealSize s = dc.GetTextExtent(content.substr(line_start - this->start, i - line_start + 1));
|
RealSize s = dc.GetTextExtent(content.substr(line_start - this->start, i - line_start + 1));
|
||||||
out.push_back(CharInfo(
|
out.push_back(CharInfo(
|
||||||
RealSize(s.width - prev_width, s.height),
|
RealSize(s.width - prev_width, s.height),
|
||||||
c == _(' ') ? BREAK_SPACE : BREAK_MAYBE,
|
c == _(' ') ? LineBreak::SPACE : LineBreak::MAYBE,
|
||||||
draw_as == DRAW_ACTIVE // from <soft> tag
|
draw_as == DRAW_ACTIVE // from <soft> tag
|
||||||
));
|
));
|
||||||
prev_width = s.width;
|
prev_width = s.width;
|
||||||
|
|||||||
+33
-33
@@ -13,18 +13,18 @@
|
|||||||
// ----------------------------------------------------------------------------- : Line
|
// ----------------------------------------------------------------------------- : Line
|
||||||
|
|
||||||
struct TextViewer::Line {
|
struct TextViewer::Line {
|
||||||
size_t start; ///< Index of the first character in this line
|
size_t start; ///< Index of the first character in this line
|
||||||
size_t end_or_soft; ///< Index just beyond the last non-soft character
|
size_t end_or_soft; ///< Index just beyond the last non-soft character
|
||||||
vector<double> positions; ///< x position of each character in this line, gives the number of characters + 1, never empty
|
vector<double> positions; ///< x position of each character in this line, gives the number of characters + 1, never empty
|
||||||
double top; ///< y position of (the top of) this line
|
double top; ///< y position of (the top of) this line
|
||||||
double line_height; ///< The height of this line in pixels
|
double line_height; ///< The height of this line in pixels
|
||||||
LineBreak break_after; ///< Is there a saparator after this line?
|
LineBreak break_after; ///< Is there a saparator after this line?
|
||||||
Alignment alignment; ///< Alignment of this line
|
Alignment alignment; ///< Alignment of this line
|
||||||
bool justifying; ///< Is the text justified? Only true when *really* justifying.
|
bool justifying; ///< Is the text justified? Only true when *really* justifying.
|
||||||
|
|
||||||
Line()
|
Line()
|
||||||
: start(0), end_or_soft(0), top(0), line_height(0)
|
: start(0), end_or_soft(0), top(0), line_height(0)
|
||||||
, break_after(BREAK_NO), justifying(false)
|
, break_after(LineBreak::NO), justifying(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/// The position (just beyond) the bottom of this line
|
/// The position (just beyond) the bottom of this line
|
||||||
@@ -142,7 +142,7 @@ void TextViewer::drawSeparators(RotatedDC& dc) {
|
|||||||
y = (y + l.top) / 2;
|
y = (y + l.top) / 2;
|
||||||
dc.DrawLine(RealPoint(0, y), RealPoint(dc.getInternalRect().width, y));
|
dc.DrawLine(RealPoint(0, y), RealPoint(dc.getInternalRect().width, y));
|
||||||
}
|
}
|
||||||
separator = l.break_after == BREAK_LINE;
|
separator = l.break_after == LineBreak::LINE;
|
||||||
y = y2;
|
y = y2;
|
||||||
}
|
}
|
||||||
// separator at the end?
|
// separator at the end?
|
||||||
@@ -375,9 +375,9 @@ TextLayoutP TextViewer::extractLayoutInfo() const {
|
|||||||
update_size(*block, l);
|
update_size(*block, l);
|
||||||
update_size(*layout, l);
|
update_size(*layout, l);
|
||||||
}
|
}
|
||||||
if (l.break_after == BREAK_LINE) {
|
if (l.break_after == LineBreak::LINE) {
|
||||||
paragraph = block = nullptr;
|
paragraph = block = nullptr;
|
||||||
} else if (l.break_after == BREAK_HARD) {
|
} else if (l.break_after == LineBreak::HARD) {
|
||||||
paragraph = nullptr;
|
paragraph = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -569,21 +569,21 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
|
|||||||
bool break_now = false;
|
bool break_now = false;
|
||||||
bool accept_word = false; // the current word should be added to the line
|
bool accept_word = false; // the current word should be added to the line
|
||||||
bool hide_breaker = true; // hide the \n or _(' ') that caused a line break
|
bool hide_breaker = true; // hide the \n or _(' ') that caused a line break
|
||||||
if (c.break_after == BREAK_SOFT || c.break_after == BREAK_HARD || c.break_after == BREAK_LINE) {
|
if (c.break_after == LineBreak::SOFT || c.break_after == LineBreak::HARD || c.break_after == LineBreak::LINE) {
|
||||||
break_now = true;
|
break_now = true;
|
||||||
accept_word = true;
|
accept_word = true;
|
||||||
line.break_after = c.break_after;
|
line.break_after = c.break_after;
|
||||||
} else if (c.break_after == BREAK_SPACE && style.field().multi_line) {
|
} else if (c.break_after == LineBreak::SPACE && style.field().multi_line) {
|
||||||
// Soft break == end of word
|
// Soft break == end of word
|
||||||
accept_word = true;
|
accept_word = true;
|
||||||
} else if (c.break_after == BREAK_MAYBE && style.direction == TOP_TO_BOTTOM) {
|
} else if (c.break_after == LineBreak::MAYBE && style.direction == TOP_TO_BOTTOM) {
|
||||||
break_now = true;
|
break_now = true;
|
||||||
accept_word = true;
|
accept_word = true;
|
||||||
hide_breaker = false;
|
hide_breaker = false;
|
||||||
line.break_after = BREAK_SOFT;
|
line.break_after = LineBreak::SOFT;
|
||||||
}
|
}
|
||||||
// Add size of the character
|
// Add size of the character
|
||||||
if (c.break_after != BREAK_LINE) {
|
if (c.break_after != LineBreak::LINE) {
|
||||||
// ^^ HACK: don't count the line height of <line> tags, if they are the only thing on a line
|
// ^^ HACK: don't count the line height of <line> tags, if they are the only thing on a line
|
||||||
// then the linebreak is 'ignored'.
|
// then the linebreak is 'ignored'.
|
||||||
word_size = add_horizontal(word_size, c.size);
|
word_size = add_horizontal(word_size, c.size);
|
||||||
@@ -607,12 +607,12 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
|
|||||||
accept_word = true;
|
accept_word = true;
|
||||||
hide_breaker = false;
|
hide_breaker = false;
|
||||||
word_too_long = true;
|
word_too_long = true;
|
||||||
line.break_after = BREAK_SOFT;
|
line.break_after = LineBreak::SOFT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// line would become too long, break before the current word
|
// line would become too long, break before the current word
|
||||||
break_now = true;
|
break_now = true;
|
||||||
line.break_after = BREAK_SOFT;
|
line.break_after = LineBreak::SOFT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -654,14 +654,14 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
|
|||||||
// push
|
// push
|
||||||
lines.push_back(line);
|
lines.push_back(line);
|
||||||
// reset line object for next line
|
// reset line object for next line
|
||||||
double line_height_multiplier = line.break_after == BREAK_HARD ? style.line_height_hard
|
double line_height_multiplier = line.break_after == LineBreak::HARD ? style.line_height_hard
|
||||||
: line.break_after == BREAK_LINE ? style.line_height_line
|
: line.break_after == LineBreak::LINE ? style.line_height_line
|
||||||
: style.line_height_soft;
|
: style.line_height_soft;
|
||||||
line.top += line.line_height * line_height_multiplier;
|
line.top += line.line_height * line_height_multiplier;
|
||||||
line.start = word_start;
|
line.start = word_start;
|
||||||
line.positions.clear();
|
line.positions.clear();
|
||||||
if (line.break_after == BREAK_LINE) line.line_height = 0;
|
if (line.break_after == LineBreak::LINE) line.line_height = 0;
|
||||||
line.break_after = BREAK_NO;
|
line.break_after = LineBreak::NO;
|
||||||
// reset line_size
|
// reset line_size
|
||||||
line_size = RealSize(lineLeft(dc, style, line.top), 0);
|
line_size = RealSize(lineLeft(dc, style, line.top), 0);
|
||||||
while (line.top < style.height && line_size.width + 1 >= style.width - style.padding_right) {
|
while (line.top < style.height && line_size.width + 1 >= style.width - style.padding_right) {
|
||||||
@@ -693,7 +693,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
|
|||||||
// per paragraph alignment
|
// per paragraph alignment
|
||||||
size_t start = 0;
|
size_t start = 0;
|
||||||
for (size_t last = 0 ; last < lines.size() ; ++last) {
|
for (size_t last = 0 ; last < lines.size() ; ++last) {
|
||||||
if (lines[last].break_after != BREAK_SOFT || last == lines.size()) {
|
if (lines[last].break_after != LineBreak::SOFT || last == lines.size()) {
|
||||||
max_height = max(max_height, lines[last].bottom() - lines[start].top);
|
max_height = max(max_height, lines[last].bottom() - lines[start].top);
|
||||||
start = last + 1;
|
start = last + 1;
|
||||||
}
|
}
|
||||||
@@ -728,7 +728,7 @@ void TextViewer::alignLines(RotatedDC& dc, const vector<CharInfo>& chars, const
|
|||||||
size_t start = 0;
|
size_t start = 0;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (size_t last = 0 ; last < lines.size() ; ++last) {
|
for (size_t last = 0 ; last < lines.size() ; ++last) {
|
||||||
if (lines[last].break_after != BREAK_SOFT || last == lines.size()) {
|
if (lines[last].break_after != LineBreak::SOFT || last == lines.size()) {
|
||||||
alignParagraph(start, last + 1, chars, style, RealRect(0, style.padding_top+n*style.paragraph_height, s.width, style.paragraph_height));
|
alignParagraph(start, last + 1, chars, style, RealRect(0, style.padding_top+n*style.paragraph_height, s.width, style.paragraph_height));
|
||||||
start = last + 1;
|
start = last + 1;
|
||||||
++n;
|
++n;
|
||||||
@@ -767,9 +767,9 @@ void TextViewer::alignParagraph(size_t start_line, size_t end_line, const vector
|
|||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (size_t li = start_line ; li < end_line ; ++li) {
|
for (size_t li = start_line ; li < end_line ; ++li) {
|
||||||
const Line& l = lines[li];
|
const Line& l = lines[li];
|
||||||
if ((soft && l.break_after == BREAK_SOFT)
|
if ((soft && l.break_after == LineBreak::SOFT)
|
||||||
|| (hard && l.break_after == BREAK_HARD)
|
|| (hard && l.break_after == LineBreak::HARD)
|
||||||
|| (line && l.break_after == BREAK_LINE)) sum += l.line_height;
|
|| (line && l.break_after == LineBreak::LINE)) sum += l.line_height;
|
||||||
}
|
}
|
||||||
if (sum == 0) break;
|
if (sum == 0) break;
|
||||||
// how much do we need to add?
|
// how much do we need to add?
|
||||||
@@ -780,9 +780,9 @@ void TextViewer::alignParagraph(size_t start_line, size_t end_line, const vector
|
|||||||
Line& l = lines[li];
|
Line& l = lines[li];
|
||||||
l.top += add;
|
l.top += add;
|
||||||
// adjust next line by..
|
// adjust next line by..
|
||||||
if ((soft && l.break_after == BREAK_SOFT)
|
if ((soft && l.break_after == LineBreak::SOFT)
|
||||||
|| (hard && l.break_after == BREAK_HARD)
|
|| (hard && l.break_after == LineBreak::HARD)
|
||||||
|| (line && l.break_after == BREAK_LINE)) add += to_add * l.line_height;
|
|| (line && l.break_after == LineBreak::LINE)) add += to_add * l.line_height;
|
||||||
}
|
}
|
||||||
height += add;
|
height += add;
|
||||||
}
|
}
|
||||||
@@ -806,7 +806,7 @@ void TextViewer::alignParagraph(size_t start_line, size_t end_line, const vector
|
|||||||
void TextViewer::Line::alignHorizontal(const vector<CharInfo>& chars, const TextStyle& style, const RealRect& s) {
|
void TextViewer::Line::alignHorizontal(const vector<CharInfo>& chars, const TextStyle& style, const RealRect& s) {
|
||||||
double width = this->width();
|
double width = this->width();
|
||||||
bool should_fill = (alignment & ALIGN_IF_OVERFLOW ? width > s.width : true)
|
bool should_fill = (alignment & ALIGN_IF_OVERFLOW ? width > s.width : true)
|
||||||
&& (alignment & ALIGN_IF_SOFTBREAK ? break_after == BREAK_SOFT || !style.field().multi_line : true);
|
&& (alignment & ALIGN_IF_SOFTBREAK ? break_after == LineBreak::SOFT || !style.field().multi_line : true);
|
||||||
if ((alignment & ALIGN_JUSTIFY_ALL) && should_fill) {
|
if ((alignment & ALIGN_JUSTIFY_ALL) && should_fill) {
|
||||||
// justify text, by characters
|
// justify text, by characters
|
||||||
justifying = true;
|
justifying = true;
|
||||||
@@ -823,13 +823,13 @@ void TextViewer::Line::alignHorizontal(const vector<CharInfo>& chars, const Text
|
|||||||
double hdelta = s.width - width; // amount of space to distribute
|
double hdelta = s.width - width; // amount of space to distribute
|
||||||
int count = 0; // distribute it among this many word breaks
|
int count = 0; // distribute it among this many word breaks
|
||||||
for (size_t k = start + 1 ; k < end_or_soft - 1 ; ++k) {
|
for (size_t k = start + 1 ; k < end_or_soft - 1 ; ++k) {
|
||||||
if (chars[k].break_after == BREAK_SPACE) ++count;
|
if (chars[k].break_after == LineBreak::SPACE) ++count;
|
||||||
}
|
}
|
||||||
if (count == 0) count = 1; // prevent div by 0
|
if (count == 0) count = 1; // prevent div by 0
|
||||||
int i = 0; size_t j = start;
|
int i = 0; size_t j = start;
|
||||||
FOR_EACH(c, positions) {
|
FOR_EACH(c, positions) {
|
||||||
c += s.x + hdelta * i / count;
|
c += s.x + hdelta * i / count;
|
||||||
if (j < end_or_soft && chars[j++].break_after == BREAK_SPACE) i++;
|
if (j < end_or_soft && chars[j++].break_after == LineBreak::SPACE) i++;
|
||||||
}
|
}
|
||||||
} else if ((alignment & ALIGN_STRETCH) && should_fill) {
|
} else if ((alignment & ALIGN_STRETCH) && should_fill) {
|
||||||
// stretching, don't center or align right
|
// stretching, don't center or align right
|
||||||
|
|||||||
Reference in New Issue
Block a user