mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
implemented justification;
fixed initialization bug in item_list; commented out statistics fields for debugging and added 'match' for all keywords in magic.mse-game git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@279 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
|
||||
ItemList::ItemList(Window* parent, int id, long additional_style)
|
||||
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | wxLC_SINGLE_SEL)
|
||||
, selected_item_pos(-1)
|
||||
, sort_by_column(-1), sort_ascending(true)
|
||||
{
|
||||
// create image list
|
||||
wxImageList* il = new wxImageList(18,14);
|
||||
|
||||
@@ -75,8 +75,16 @@ void TextViewer::draw(RotatedDC& dc, const TextStyle& style, DrawWhat what) {
|
||||
// Draw the text, line by line
|
||||
FOR_EACH(l, lines) {
|
||||
if (l.visible(dc)) {
|
||||
RealRect rect(l.positions.front(), l.top, l.width(), l.line_height);
|
||||
elements.draw(dc, scale, rect, &*l.positions.begin(), what, l.start, l.end());
|
||||
if (justifying) {
|
||||
// Draw characters separatly
|
||||
for (size_t i = 0 ; i < l.positions.size() - 1 ; ++i) {
|
||||
RealRect rect(l.positions[i], l.top, l.positions[i+1] - l.positions[i] , l.line_height);
|
||||
elements.draw(dc, scale, rect, &l.positions[i], what, l.start + i, l.start + i + 1);
|
||||
}
|
||||
} else {
|
||||
RealRect rect(l.positions.front(), l.top, l.width(), l.line_height);
|
||||
elements.draw(dc, scale, rect, &*l.positions.begin(), what, l.start, l.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -524,7 +532,7 @@ void TextViewer::alignLines(RotatedDC& dc, const vector<CharInfo>& chars, const
|
||||
if ((style.alignment & ALIGN_JUSTIFY) ||
|
||||
(style.alignment & ALIGN_JUSTIFY_OVERFLOW && width > s.width)) {
|
||||
// justify text
|
||||
// justifying = true;
|
||||
justifying = true;
|
||||
double hdelta = s.width - width; // amount of space to distribute
|
||||
int count = (int)l.positions.size() - 1; // distribute it among this many characters
|
||||
if (count == 0) count = 1; // prevent div by 0
|
||||
@@ -532,9 +540,9 @@ void TextViewer::alignLines(RotatedDC& dc, const vector<CharInfo>& chars, const
|
||||
FOR_EACH(c, l.positions) {
|
||||
c += hdelta * i++ / count;
|
||||
}
|
||||
} else if (style.alignment & ALIGN_JUSTIFY) {
|
||||
} else if (style.alignment & ALIGN_JUSTIFY_WORDS) {
|
||||
// justify text, by words
|
||||
// justifying = true;
|
||||
justifying = true;
|
||||
double hdelta = s.width - width; // amount of space to distribute
|
||||
int count = 0; // distribute it among this many words
|
||||
for (size_t k = l.start + 1 ; k < l.end() - 1 ; ++k) {
|
||||
@@ -548,7 +556,7 @@ void TextViewer::alignLines(RotatedDC& dc, const vector<CharInfo>& chars, const
|
||||
}
|
||||
} else {
|
||||
// simple alignment
|
||||
// justifying = false;
|
||||
justifying = false;
|
||||
double hdelta = align_delta_x(style.alignment, s.width, width);
|
||||
FOR_EACH(c, l.positions) {
|
||||
c += hdelta;
|
||||
|
||||
@@ -117,7 +117,8 @@ class TextViewer {
|
||||
|
||||
private:
|
||||
// --------------------------------------------------- : More drawing
|
||||
double scale; /// < Scale when drawing
|
||||
double scale; ///< Scale when drawing
|
||||
bool justifying; ///< Is text justified?
|
||||
|
||||
// --------------------------------------------------- : Elements
|
||||
TextElements elements; ///< The elements of the prepared text
|
||||
|
||||
@@ -36,15 +36,15 @@ RealPoint align_in_rect(Alignment align, const RealSize& to_align, const RealRec
|
||||
/// Convert a String to an Alignment
|
||||
Alignment from_string(const String& s) {
|
||||
int al = ALIGN_TOP_LEFT;
|
||||
if (s.find(_("left")) !=String::npos) al = ALIGN_LEFT | (al & ALIGN_VERTICAL);
|
||||
if (s.find(_("center")) !=String::npos) al = ALIGN_CENTER | (al & ALIGN_VERTICAL);
|
||||
if (s.find(_("right")) !=String::npos) al = ALIGN_RIGHT | (al & ALIGN_VERTICAL);
|
||||
if (s.find(_("justify")) !=String::npos) al = ALIGN_JUSTIFY | (al & ALIGN_VERTICAL);
|
||||
if (s.find(_("justify-words")) !=String::npos) al = ALIGN_JUSTIFY_WORDS | (al & ALIGN_VERTICAL);
|
||||
if (s.find(_("left")) !=String::npos) al = ALIGN_LEFT | (al & ~ALIGN_HORIZONTAL);
|
||||
if (s.find(_("center")) !=String::npos) al = ALIGN_CENTER | (al & ~ALIGN_HORIZONTAL);
|
||||
if (s.find(_("right")) !=String::npos) al = ALIGN_RIGHT | (al & ~ALIGN_HORIZONTAL);
|
||||
if (s.find(_("justify")) !=String::npos) al = ALIGN_JUSTIFY | (al & ~ALIGN_HORIZONTAL);
|
||||
if (s.find(_("justify-words")) !=String::npos) al = ALIGN_JUSTIFY_WORDS | (al & ~ALIGN_HORIZONTAL);
|
||||
if (s.find(_("shrink-overflow"))!=String::npos) al = ALIGN_JUSTIFY_OVERFLOW | (al & ~ALIGN_JUSTIFY_OVERFLOW);
|
||||
if (s.find(_("top")) !=String::npos) al = ALIGN_TOP | (al & ALIGN_HORIZONTAL);
|
||||
if (s.find(_("middle")) !=String::npos) al = ALIGN_MIDDLE | (al & ALIGN_HORIZONTAL);
|
||||
if (s.find(_("bottom")) !=String::npos) al = ALIGN_BOTTOM | (al & ALIGN_HORIZONTAL);
|
||||
if (s.find(_("top")) !=String::npos) al = ALIGN_TOP | (al & ~ALIGN_VERTICAL);
|
||||
if (s.find(_("middle")) !=String::npos) al = ALIGN_MIDDLE | (al & ~ALIGN_VERTICAL);
|
||||
if (s.find(_("bottom")) !=String::npos) al = ALIGN_BOTTOM | (al & ~ALIGN_VERTICAL);
|
||||
if (s.find(_("stretch")) !=String::npos) al = ALIGN_STRETCH;
|
||||
return static_cast<Alignment>(al);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user