Skip to content

Commit

Permalink
Allow fonts to use a gradient fill instead of a solid color. The <gra…
Browse files Browse the repository at this point in the history
…dient> tag takes the same form as the one used for shapes. This only works with the QT painter currently, it's implemented for the GL painter but for an unknown reason we end up with a solid color representing the mid-point of the gradient range. I'm still hoping to figure out the GL painter issue but it would benefit from more eyes.

git-svn-id: http://svn.mythtv.org/svn/trunk@24796 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information
stuartm committed May 22, 2010
1 parent d4478be commit 4376bd8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
16 changes: 11 additions & 5 deletions mythtv/libs/libmythui/mythfontproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define LOC_ERR QString("MythFontProperties, Error: ")

MythFontProperties::MythFontProperties() :
m_color(QColor(Qt::white)), m_hasShadow(false), m_shadowAlpha(255),
m_brush(QColor(Qt::white)), m_hasShadow(false), m_shadowAlpha(255),
m_hasOutline(false), m_outlineAlpha(255), m_bFreeze(false)
{
CalcHash();
Expand All @@ -32,7 +32,7 @@ void MythFontProperties::SetFace(const QFont &face)

void MythFontProperties::SetColor(const QColor &color)
{
m_color = color;
m_brush.setColor(color);
CalcHash();
}

Expand Down Expand Up @@ -81,7 +81,9 @@ void MythFontProperties::CalcHash(void)
return;

m_hash = QString("%1%2%3%4").arg(m_face.toString())
.arg(m_color.name()).arg(m_hasShadow).arg(m_hasOutline);
.arg(m_brush.color().name())
.arg(m_hasShadow)
.arg(m_hasOutline);

if (m_hasShadow)
m_hash += QString("%1%2%3%4").arg(m_shadowOffset.x())
Expand Down Expand Up @@ -238,7 +240,11 @@ MythFontProperties *MythFontProperties::ParseFromXml(
}
else if (info.tagName() == "color")
{
newFont->m_color = QColor(getFirstText(info));
newFont->m_brush = QBrush(QColor(getFirstText(info)));
}
else if (info.tagName() == "gradient")
{
newFont->m_brush = parseGradient(info);
}
else if (info.tagName() == "shadowcolor")
{
Expand Down Expand Up @@ -448,7 +454,7 @@ bool FontMap::AddFont(const QString &text, MythFontProperties *font)
fontProp oldf;

oldf.face = font->m_face;
oldf.color = font->m_color;
oldf.color = font->m_brush.color();
if (font->m_hasShadow)
{
oldf.dropColor = font->m_shadowColor;
Expand Down
6 changes: 4 additions & 2 deletions mythtv/libs/libmythui/mythfontproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <QFont>
#include <QColor>
#include <QBrush>
#include <QPoint>
#include <QMap>

Expand All @@ -19,7 +20,8 @@ class MPUBLIC MythFontProperties: public XMLParseBase
void SetOutline(bool on, const QColor &color, int size, int alpha);

QFont face(void) const { return m_face; }
QColor color(void) const { return m_color; }
QColor color(void) const { return m_brush.color(); }
QBrush GetBrush(void) const { return m_brush; }

bool hasShadow(void) const { return m_hasShadow; }
void GetShadow(QPoint &offset, QColor &color, int &alpha) const;
Expand All @@ -43,7 +45,7 @@ class MPUBLIC MythFontProperties: public XMLParseBase
void CalcHash(void);

QFont m_face;
QColor m_color;
QBrush m_brush;

bool m_hasShadow;
QPoint m_shadowOffset;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythpainter_ogl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ MythImage *MythOpenGLPainter::GetImageFromString(const QString &msg,
}
}

tmp.setPen(font.color());
tmp.setPen(QPen(font.GetBrush(), 0));
tmp.drawText(drawOffset.x(), drawOffset.y(), r.width(), r.height(),
flags, msg);

Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythui/mythpainter_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void MythQtPainter::DrawImage(const QRect &r, MythImage *im,
MythQtImage *qim = reinterpret_cast<MythQtImage *>(im);

if (qim->NeedsRegen())
qim->RegeneratePixmap();
qim->RegeneratePixmap();

painter->setOpacity(static_cast<float>(alpha) / 255.0);
painter->drawPixmap(r.topLeft(), *(qim->GetPixmap()), src);
Expand Down Expand Up @@ -201,7 +201,7 @@ void MythQtPainter::DrawText(const QRect &r, const QString &msg,
}
}

painter->setPen(font.color());
painter->setPen(QPen(font.GetBrush(), 0));
painter->drawText(r, flags, msg);
painter->setOpacity(1.0);
}
Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythui/mythpainter_vdpau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ MythImage *MythVDPAUPainter::GetImageFromString(const QString &msg,
}
}

tmp.setPen(font.color());
QPen pen;
pen.setBrush(font.GetBrush());
tmp.setPen(pen);
tmp.drawText(drawOffset.x(), drawOffset.y(), r.width(), r.height(),
flags, msg);

Expand Down

0 comments on commit 4376bd8

Please sign in to comment.