Added GraphControl; FilteredCardList; ValueEditor

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@74 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-11-19 18:59:33 +00:00
parent ce6a83e34b
commit ed336dea06
31 changed files with 705 additions and 82 deletions
+14 -25
View File
@@ -14,12 +14,15 @@ DECLARE_TYPEOF_COLLECTION(TextElementP);
// ----------------------------------------------------------------------------- : TextElements
void TextElements::draw(RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const {
void TextElements::draw(RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const {
FOR_EACH_CONST(e, elements) {
size_t start_ = max(start, e->start);
size_t end_ = min(end, e->end);
if (start_ < end_) {
e->draw(dc, scale, rect, what, start_, end_);
e->draw(dc, scale,
RealRect(rect.position.x + xs[start_-start], rect.position.y,
xs[end_-start] - xs[start_-start], rect.size.height),
xs + start_ - start, what, start_, end_);
}
if (end <= e->end) return; // nothing can be after this
}
@@ -28,38 +31,24 @@ void TextElements::draw(RotatedDC& dc, double scale, const RealRect& rect, DrawW
void TextElements::getCharInfo(RotatedDC& dc, double scale, size_t start, size_t end, vector<CharInfo>& out) const {
FOR_EACH_CONST(e, elements) {
// characters before this element, after the previous
for (size_t i = start ; i < e->start ; ++i) {
while (start + out.size() < e->start) {
out.push_back(CharInfo(RealSize(0,0), BREAK_NO));
}
e->getCharInfo(dc, scale, out);
start = min(end, e->end);
}
for (size_t i = start ; i < end ; ++i) {
while (start + out.size() < end) {
out.push_back(CharInfo(RealSize(0,0), BREAK_NO));
}
}
/*//@@
RealSize TextElements::charSize(const Rotation& rot, double scale, size_t index) const {
vector<TextElementP>::const_iterator e = findByIndex(index);
if (e != elements.end()) {
return (*e)->charSize(rot, scale, index);
} else {
return RealSize(0,0);
double TextElements::minScale() const {
double m = 0.0001;
FOR_EACH_CONST(e, elements) {
m = max(m, e->minScale());
}
return m;
}
bool ends_before_index(const TextElementP& e, size_t index) {
return index < e->end;
}
vector<TextElementP>::const_iterator TextElements::findByIndex(size_t index) const {
// Note: slightly abusing lower_bound, since typeof(index) != elements.element_type
vector<TextElementP>::const_iterator it = lower_bound(elements.begin(), elements.end(), index, ends_before_index);
if ((*it)->start <= index && (*it)->end > index) return it;
else return elements.end();
}*/
// Helper class for TextElements::fromString, to allow persistent formating state accross recusive calls
struct TextElementsFromString {
// What formatting is enabled?
@@ -114,8 +103,8 @@ struct TextElementsFromString {
e->end = pos + 1; // just move the end, no need to make a new element
} else {
// add a new element for this text
if (symbol > 0) {
te.elements.push_back(new_shared3<SymbolTextElement>(text, pos, pos + 1));
if (symbol > 0 && style.symbol_font.valid()) {
te.elements.push_back(new_shared4<SymbolTextElement>(text, pos, pos + 1, style.symbol_font));
} else {
te.elements.push_back(new_shared4<FontTextElement> (text, pos, pos + 1, style.font.make(bold > 0, italic > 0)));
}
+23 -14
View File
@@ -17,6 +17,7 @@ DECLARE_POINTER_TYPE(TextElement);
DECLARE_POINTER_TYPE(Font);
class TextStyle;
class Context;
class SymbolFontRef;
// ----------------------------------------------------------------------------- : TextElement
@@ -56,14 +57,13 @@ class TextElement {
virtual ~TextElement() {}
/// Draw a subsection section of the text in the given rectangle
/** this->start <= start < end <= this->end <= text.size() */
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const = 0;
// /// The size of a single character at position index
// /** index is in the range [start..end) */
// virtual RealSize charSize(const Rotation& rot, double scale, size_t index) const = 0;
/** xs give the x coordinates for each character
* this->start <= start < end <= this->end <= text.size() */
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const = 0;
/// Get information on all characters in the range [start...end) and store them in out
virtual void getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const = 0;
/// Return the minimum scale factor allowed (starts at 1)
virtual double minScale() const = 0;
/*
// draw the section <start...end)
// drawSeparators indicates what we should draw, separators or normal text
@@ -96,10 +96,11 @@ class TextElement {
class TextElements : public vector<TextElementP> {
public:
/// Draw all the elements (as need to show the range start..end)
void draw (RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const;
// RealSize charSize(const Rotation& rot, double scale, size_t index) const;
void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const;
// Get information on all characters in the range [start...end) and store them in out
void getCharInfo(RotatedDC& dc, double scale, size_t start, size_t end, vector<CharInfo>& out) const;
/// Return the minimum scale factor allowed by all elements
double minScale() const;
/// The actual elements
/** They must be in order of positions and not overlap, i.e.
@@ -130,8 +131,9 @@ class FontTextElement : public SimpleTextElement {
, font(font)
{}
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const;
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const;
virtual void getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const;
virtual double minScale() const;
private:
FontP font;
DrawWhat draw_as;
@@ -140,10 +142,16 @@ class FontTextElement : public SimpleTextElement {
/// A text element that uses a symbol font
class SymbolTextElement : public SimpleTextElement {
public:
SymbolTextElement(const String& text, size_t start ,size_t end) : SimpleTextElement(text, start, end) {}
SymbolTextElement(const String& text, size_t start ,size_t end, const SymbolFontRef& font)
: SimpleTextElement(text, start, end)
, font(font)
{}
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const;
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const;
virtual void getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const;
virtual double minScale() const;
private:
const SymbolFontRef& font; // owned by TextStyle
};
// ----------------------------------------------------------------------------- : CompoundTextElement
@@ -163,8 +171,9 @@ class HorizontalLineTextElement : public TextElement {
public:
HorizontalLineTextElement(const String& text, size_t start ,size_t end) : TextElement(text, start, end) {}
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const;
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const;
virtual void getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const;
virtual double minScale() const;
};
/*
@@ -175,8 +184,8 @@ class CompoundTextElement : public TextElement {
public:
CompoundTextElement(const String& text, size_t start ,size_t end) : TextElement(text, start, end) {}
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const;
virtual RealSize charSize(RotatedDC& dc, double scale, size_t index) const;
virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const;
virtual RealSize charSize(RotatedDC& dc, double scale, size_t index) const;
private:
TextElements elements;
+6 -2
View File
@@ -11,7 +11,7 @@
// ----------------------------------------------------------------------------- : FontTextElement
void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const {
void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const {
dc.SetFont(font->font, font->size * scale);
if (end != start && text.substr(end-1, 1) == _("\n")) end -= 1; // don't draw the newline character at the end
@@ -42,7 +42,7 @@ void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>&
double prev_width = 0;
for (size_t i = start ; i < end ; ++i) {
Char c = text.GetChar(i);
RealSize s = dc.GetTextExtent(text.substr(start, i - start));
RealSize s = dc.GetTextExtent(text.substr(start, i - start + 1));
out.push_back(CharInfo(RealSize(s.width - prev_width, s.height),
c == _('\n') ? BREAK_HARD :
c == _(' ') ? BREAK_SOFT : BREAK_NO
@@ -50,3 +50,7 @@ void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>&
prev_width = s.width;
}
}
double FontTextElement::minScale() const {
return 1; // TODO
}
+8 -3
View File
@@ -10,10 +10,15 @@
// ----------------------------------------------------------------------------- : HorizontalLineTextElement
void HorizontalLineTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const {
// TODO
void HorizontalLineTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const {
// handled by TextViewer
}
void HorizontalLineTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const {
// TODO
out.push_back(CharInfo(RealSize(0,0), BREAK_LINE));
}
double HorizontalLineTextElement::minScale() const {
return 0; // we don't care about scaling
}
+5 -1
View File
@@ -10,10 +10,14 @@
// ----------------------------------------------------------------------------- : SymbolTextElement
void SymbolTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, DrawWhat what, size_t start, size_t end) const {
void SymbolTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const {
// TODO
}
void SymbolTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const {
// TODO
}
double SymbolTextElement::minScale() const {
return 1; // TODO
}
+1 -1
View File
@@ -75,7 +75,7 @@ void TextViewer::draw(RotatedDC& dc, const String& text, const TextStyle& style,
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, what, l.start, l.end());
elements.draw(dc, scale, rect, &*l.positions.begin(), what, l.start, l.end());
}
}
}