From d922357fa13df25e4024e6ac6baeac59507bf4d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 5 Sep 2013 13:21:32 +0200 Subject: [PATCH] HaikuDepot: CharacterStyle: Added convenience methods --- .../haiku-depot/textview/CharacterStyle.cpp | 23 ++++++++++++++++++ .../haiku-depot/textview/CharacterStyle.h | 8 +++++++ .../textview/CharacterStyleData.cpp | 24 +++++++++++++++++++ .../haiku-depot/textview/CharacterStyleData.h | 6 ++--- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/apps/haiku-depot/textview/CharacterStyle.cpp b/src/apps/haiku-depot/textview/CharacterStyle.cpp index 07a120e1dd..3e1c7ea32c 100644 --- a/src/apps/haiku-depot/textview/CharacterStyle.cpp +++ b/src/apps/haiku-depot/textview/CharacterStyle.cpp @@ -73,6 +73,15 @@ CharacterStyle::Font() const } +bool +CharacterStyle::SetFontSize(float size) +{ + BFont font(Font()); + font.SetSize(size); + return SetFont(font); +} + + bool CharacterStyle::SetAscent(float ascent) { @@ -149,6 +158,13 @@ CharacterStyle::GlyphSpacing() const } +bool +CharacterStyle::SetForegroundColor(uint8 r, uint8 g, uint8 b, uint8 a) +{ + return SetForegroundColor((rgb_color){ r, g, b, a }); +} + + bool CharacterStyle::SetForegroundColor(rgb_color color) { @@ -168,6 +184,13 @@ CharacterStyle::ForegroundColor() const } +bool +CharacterStyle::SetBackgroundColor(uint8 r, uint8 g, uint8 b, uint8 a) +{ + return SetBackgroundColor((rgb_color){ r, g, b, a }); +} + + bool CharacterStyle::SetBackgroundColor(rgb_color color) { diff --git a/src/apps/haiku-depot/textview/CharacterStyle.h b/src/apps/haiku-depot/textview/CharacterStyle.h index c294eebfe3..7e6615bf02 100644 --- a/src/apps/haiku-depot/textview/CharacterStyle.h +++ b/src/apps/haiku-depot/textview/CharacterStyle.h @@ -20,6 +20,8 @@ public: bool SetFont(const BFont& font); const BFont& Font() const; + bool SetFontSize(float size); + bool SetAscent(float ascent); float Ascent() const; @@ -32,9 +34,15 @@ public: bool SetGlyphSpacing(float spacing); float GlyphSpacing() const; + bool SetForegroundColor( + uint8 r, uint8 g, uint8 b, + uint8 a = 255); bool SetForegroundColor(rgb_color color); rgb_color ForegroundColor() const; + bool SetBackgroundColor( + uint8 r, uint8 g, uint8 b, + uint8 a = 255); bool SetBackgroundColor(rgb_color color); rgb_color BackgroundColor() const; diff --git a/src/apps/haiku-depot/textview/CharacterStyleData.cpp b/src/apps/haiku-depot/textview/CharacterStyleData.cpp index d5f23fa811..50ed806f04 100644 --- a/src/apps/haiku-depot/textview/CharacterStyleData.cpp +++ b/src/apps/haiku-depot/textview/CharacterStyleData.cpp @@ -110,6 +110,18 @@ CharacterStyleData::SetAscent(float ascent) } +float +CharacterStyleData::Ascent() const +{ + if (fAscent >= 0.0f) + return fAscent; + + font_height fontHeight; + fFont.GetHeight(&fontHeight); + return fontHeight.ascent; +} + + CharacterStyleDataRef CharacterStyleData::SetDescent(float descent) { @@ -125,6 +137,18 @@ CharacterStyleData::SetDescent(float descent) } +float +CharacterStyleData::Descent() const +{ + if (fDescent >= 0.0f) + return fDescent; + + font_height fontHeight; + fFont.GetHeight(&fontHeight); + return fontHeight.descent; +} + + CharacterStyleDataRef CharacterStyleData::SetWidth(float width) { diff --git a/src/apps/haiku-depot/textview/CharacterStyleData.h b/src/apps/haiku-depot/textview/CharacterStyleData.h index 35789942fe..20377b47ee 100644 --- a/src/apps/haiku-depot/textview/CharacterStyleData.h +++ b/src/apps/haiku-depot/textview/CharacterStyleData.h @@ -46,12 +46,10 @@ public: { return fFont; } CharacterStyleDataRef SetAscent(float ascent); - inline float Ascent() const - { return fAscent; } + float Ascent() const; CharacterStyleDataRef SetDescent(float descent); - inline float Descent() const - { return fDescent; } + float Descent() const; CharacterStyleDataRef SetWidth(float width); inline float Width() const