Draw: AttrText now has Bold/Italic/Underline/Strikeout methods

git-svn-id: svn://ultimatepp.org/upp/trunk@4014 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-10-14 08:52:14 +00:00
parent 0d46d0fd11
commit 3987e33d22
4 changed files with 84 additions and 49 deletions

View file

@ -23,32 +23,28 @@ void AttrText::Init()
ink = Null;
normalink = Null;
paper = Null;
font = Null;
font = StdFont();
align = Null;
imgspc = 0;
}
AttrText::AttrText(const char *_text)
AttrText::AttrText(const char *text) : text(text)
{
text = _text;
Init();
}
AttrText::AttrText(const wchar *_text)
AttrText::AttrText(const wchar *text) : text(text)
{
text = _text;
Init();
}
AttrText::AttrText(const WString& _text)
AttrText::AttrText(const WString& text) : text(text)
{
text = _text;
Init();
}
AttrText::AttrText(const String& _text)
AttrText::AttrText(const String& text) : text(text.ToWString())
{
text = _text.ToWString();
Init();
}
@ -102,14 +98,13 @@ void StdDisplayClass::Paint0(Draw& w, const Rect& r, const Value& q,
if(IsType<AttrText>(q)) {
const AttrText& t = ValueTo<AttrText>(q);
txt = t.text;
font = t.font;
if(!IsNull(t.paper))
paper = t.paper;
if(!IsNull(t.ink))
ink = t.ink;
if(!IsNull(t.normalink) && !(s & (CURSOR|SELECT|READONLY)))
ink = t.normalink;
if(!IsNull(t.font))
font = t.font;
if(!IsNull(t.align))
a = t.align;
if(!IsNull(t.img)) {
@ -154,8 +149,7 @@ Size StdDisplayClass::GetStdSize(const Value& q) const
if(IsType<AttrText>(q)) {
const AttrText& t = ValueTo<AttrText>(q);
txt = t.text;
if(!IsNull(t.font))
font = t.font;
font = t.font;
if(!IsNull(t.img)) {
isz = t.img.GetSize();
isz.cx += t.imgspc;

View file

@ -40,6 +40,12 @@ struct AttrText {
AttrText& NormalInk(Color c) { normalink = c; return *this; }
AttrText& Paper(Color c) { paper = c; return *this; }
AttrText& SetFont(Font f) { font = f; return *this; }
AttrText& Bold(bool b = true) { font.Bold(b); return *this; }
AttrText& Italic(bool b = true) { font.Italic(b); return *this; }
AttrText& Underline(bool b = true) { font.Underline(b); return *this; }
AttrText& Strikeout(bool b = true) { font.Strikeout(b); return *this; }
AttrText& Align(int a) { align = a; return *this; }
AttrText& Left() { return Align(ALIGN_LEFT); }
AttrText& Center() { return Align(ALIGN_CENTER); }

View file

@ -54,6 +54,15 @@ class Font : AssignValueTypeNo<Font, FONT_V, Moveable<Font> >{
} v;
};
enum {
FONT_BOLD = 0x8000,
FONT_ITALIC = 0x4000,
FONT_UNDERLINE = 0x2000,
FONT_STRIKEOUT = 0x1000,
FONT_NON_ANTI_ALIASED = 0x800,
FONT_TRUE_TYPE_ONLY = 0x400
};
static Font AStdFont;
static Size StdFontSize;
@ -101,16 +110,16 @@ public:
SCREEN_SANS = SANSSERIF,
SCREEN_FIXED = MONOSPACE,
};
int GetFace() const { return v.face; }
int GetHeight() const;
int GetWidth() const { return v.width; }
bool IsBold() const { return v.flags & 0x8000; }
bool IsItalic() const { return v.flags & 0x4000; }
bool IsUnderline() const { return v.flags & 0x2000; }
bool IsStrikeout() const { return v.flags & 0x1000; }
bool IsNonAntiAliased() const { return v.flags & 0x800; }
bool IsTrueTypeOnly() const { return v.flags & 0x400; }
bool IsBold() const { return v.flags & FONT_BOLD; }
bool IsItalic() const { return v.flags & FONT_ITALIC; }
bool IsUnderline() const { return v.flags & FONT_UNDERLINE; }
bool IsStrikeout() const { return v.flags & FONT_STRIKEOUT; }
bool IsNonAntiAliased() const { return v.flags & FONT_NON_ANTI_ALIASED; }
bool IsTrueTypeOnly() const { return v.flags & FONT_TRUE_TYPE_ONLY; }
String GetFaceName() const;
dword GetFaceInfo() const;
int64 AsInt64() const { return data; }
@ -118,24 +127,25 @@ public:
Font& Face(int n) { v.face = n; return *this; }
Font& Height(int n) { v.height = n; return *this; }
Font& Width(int n) { v.width = n; return *this; }
Font& Bold() { v.flags |= 0x8000; return *this; }
Font& NoBold() { v.flags &= ~0x8000; return *this; }
Font& Bold() { v.flags |= FONT_BOLD; return *this; }
Font& NoBold() { v.flags &= ~FONT_BOLD; return *this; }
Font& Bold(bool b) { return b ? Bold() : NoBold(); }
Font& Italic() { v.flags |= 0x4000; return *this; }
Font& NoItalic() { v.flags &= ~0x4000; return *this; }
Font& Italic() { v.flags |= FONT_ITALIC; return *this; }
Font& NoItalic() { v.flags &= ~FONT_ITALIC; return *this; }
Font& Italic(bool b) { return b ? Italic() : NoItalic(); }
Font& Underline() { v.flags |= 0x2000; return *this; }
Font& NoUnderline() { v.flags &= ~0x2000; return *this; }
Font& Underline() { v.flags |= FONT_UNDERLINE; return *this; }
Font& NoUnderline() { v.flags &= ~FONT_UNDERLINE; return *this; }
Font& Underline(bool b) { return b ? Underline() : NoUnderline(); }
Font& Strikeout() { v.flags |= 0x1000; return *this; }
Font& NoStrikeout() { v.flags &= ~0x1000; return *this; }
Font& Strikeout() { v.flags |= FONT_STRIKEOUT; return *this; }
Font& NoStrikeout() { v.flags &= ~FONT_STRIKEOUT; return *this; }
Font& Strikeout(bool b) { return b ? Strikeout() : NoStrikeout(); }
Font& NonAntiAliased() { v.flags |= 0x800; return *this; }
Font& NoNonAntiAliased() { v.flags &= ~0x800; return *this; }
Font& NonAntiAliased() { v.flags |= FONT_NON_ANTI_ALIASED; return *this; }
Font& NoNonAntiAliased() { v.flags &= ~FONT_NON_ANTI_ALIASED; return *this; }
Font& NonAntiAliased(bool b) { return b ? NonAntiAliased() : NoNonAntiAliased(); }
Font& TrueTypeOnly() { v.flags |= 0x400; return *this; }
Font& NoTrueTypeOnly() { v.flags &= ~0x400; return *this; }
Font& TrueTypeOnly() { v.flags |= FONT_TRUE_TYPE_ONLY; return *this; }
Font& NoTrueTypeOnly() { v.flags &= ~FONT_TRUE_TYPE_ONLY; return *this; }
Font& TrueTypeOnly(bool b) { return b ? TrueTypeOnly() : NoTrueTypeOnly(); }
Font& FaceName(const String& name);
Font operator()() const { return *this; }

View file

@ -112,13 +112,18 @@ for the text painted.&]
[s3;%- &]
[s4;%- &]
[s5;:AttrText`:`:font:%- [_^Font^ Font]_font&]
[s2; Font of text.&]
[s2; Font of text. It is default initialized by constructor to StdFont.&]
[s3;%- &]
[s4;%- &]
[s5;:AttrText`:`:ink:%- [_^Color^ Color]_ink&]
[s2; Text color.&]
[s3;%- &]
[s4;%- &]
[s5;:AttrText`:`:normalink:%- [_^Color^ Color]_[* normalink]&]
[s2; Text color to be used if the item is not in selected nor focused
nor read`-only state.&]
[s3;%- &]
[s4;%- &]
[s5;:AttrText`:`:paper:%- [_^Color^ Color]_paper&]
[s2; Background color&]
[s3;%- &]
@ -151,6 +156,11 @@ perator`=([@(0.0.255) const]_[_^WString^ WString][@(0.0.255) `&]_[@3 s])&]
[s2; Sets the text to [%-*@3 s].&]
[s3; &]
[s4;%- &]
[s5;:AttrText`:`:operator`=`(const String`&`):%- [_^AttrText^ AttrText][@(0.0.255) `&]_[* o
perator`=]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 s])&]
[s2; Sets the text to [%-*@3 s].&]
[s3; &]
[s4;%- &]
[s5;:AttrText`:`:Ink`(Color`):%- [_^AttrText^ AttrText][@(0.0.255) `&]_Ink([_^Color^ Color]_
[@3 c])&]
[s2; Sets the text color.&]
@ -178,6 +188,26 @@ ont]_[@3 f])&]
[s7; [*/ Return value]-|`*this.&]
[s3;%- &]
[s4;%- &]
[s5;:AttrText`:`:Bold`(bool`):%- [_^AttrText^ AttrText][@(0.0.255) `&]_[* Bold]([@(0.0.255) b
ool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2; Calls font.Bold([%-*@3 b]). Returns `*this.&]
[s3; &]
[s4;%- &]
[s5;:AttrText`:`:Italic`(bool`):%- [_^AttrText^ AttrText][@(0.0.255) `&]_[* Italic]([@(0.0.255) b
ool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2; Calls font.Italic([%-*@3 b]). Returns `*this.&]
[s3; &]
[s4;%- &]
[s5;:AttrText`:`:Underline`(bool`):%- [_^AttrText^ AttrText][@(0.0.255) `&]_[* Underline]([@(0.0.255) b
ool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2; Calls font.Underline([%-*@3 b]). Returns `*this.&]
[s3; &]
[s4;%- &]
[s5;:AttrText`:`:Strikeout`(bool`):%- [_^AttrText^ AttrText][@(0.0.255) `&]_[* Strikeout]([@(0.0.255) b
ool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2; Calls font.Strikeout([%-*@3 b]). Returns `*this.&]
[s3; &]
[s4;%- &]
[s5;:AttrText`:`:Align`(int`):%- [_^AttrText^ AttrText][@(0.0.255) `&]_Align([@(0.0.255) in
t]_[@3 a])&]
[s2; Sets the text horizontal alignment. Approved values are ALIGN`_LEFT,
@ -211,26 +241,21 @@ ue][@(0.0.255) `&]_[*@3 v])&]
[s2; Converts Value to AttrText.&]
[s3; &]
[s4;%- &]
[s5;:AttrText`:`:AttrText`(const char`*`):%- AttrText([@(0.0.255) const]_[@(0.0.255) char
]_`*[@3 text])&]
[s2; Constructs AttrText, assigning the text attribute and all other
attributes to zero.&]
[s3;%- &]
[s4;%- &]
[s5;:AttrText`:`:AttrText`(const wchar`*`):%- AttrText([@(0.0.255) const]_[_^wchar^ wchar
]_`*[@3 text])&]
[s2; Constructs AttrText, assigning the text attribute and all other
attributes to zero.&]
[s3;%- &]
[s4;%- &]
[s5;:AttrText`:`:AttrText`(const WString`&`):%- AttrText([@(0.0.255) const]_[_^WString^ W
[s5;:AttrText`:`:AttrText`(const char`*`):%- [* AttrText]([@(0.0.255) const]_[@(0.0.255) ch
ar]_`*[@3 text])&]
[s5;:AttrText`:`:AttrText`(const wchar`*`):%- [* AttrText]([@(0.0.255) const]_[_^wchar^ wch
ar]_`*[@3 text])&]
[s5;:AttrText`:`:AttrText`(const WString`&`):%- [* AttrText]([@(0.0.255) const]_[_^WString^ W
String][@(0.0.255) `&]_[@3 text])&]
[s2; Constructs AttrText, assigning the text attribute and all other
attributes to zero.&]
[s5;:AttrText`:`:AttrText`(const String`&`):%- [* AttrText]([@(0.0.255) const]_[_^String^ S
tring][@(0.0.255) `&]_[*@3 text])&]
[s2; Assigns text attribute. Assigns Null to all other members except
font, which is initialized to StdFont.&]
[s3; &]
[s4;%- &]
[s5;:AttrText`:`:AttrText`(`):%- AttrText()&]
[s2; Default constructor.&]
[s2; Default constructor. Assigns Null to all members except font,
which is initialized to StdFont.&]
[s3; &]
[s0; &]
[s0; &]