MythTV master
mythuiprocedural.cpp
Go to the documentation of this file.
1// Qt
2#include <QDomDocument>
3#include <QCryptographicHash>
4#include <QTextStream>
5
6// MythTV
8#include "mythpainter.h"
9#include "mythuiprocedural.h"
10#include "mythuihelper.h"
11
39 : MythUIType(Parent, Name)
40{
41}
42
43void MythUIProcedural::DrawSelf(MythPainter* Painter, int XOffset, int YOffset,
44 int AlphaMod, QRect ClipRect)
45{
46 QRect area = GetArea();
47 area.translate(XOffset, YOffset);
48 Painter->SetClipRect(ClipRect);
49 Painter->DrawProcedural(area, AlphaMod, m_vertexSource, m_fragmentSource, m_hash);
50}
51
52bool MythUIProcedural::ParseElement(const QString& FileName, QDomElement& Element, bool ShowWarnings)
53{
54 if (Element.tagName() == "vertexsource")
55 {
57 }
58 else if (Element.tagName() == "fragmentsource")
59 {
61 }
62 else
63 {
64 return MythUIType::ParseElement(FileName, Element, ShowWarnings);
65 }
66
67 return true;
68}
69
71{
72 auto * proc = dynamic_cast<MythUIProcedural*>(Base);
73 if (proc)
74 {
75 m_vertexSource = proc->m_vertexSource;
76 m_fragmentSource = proc->m_fragmentSource;
77 m_hash = proc->m_hash;
78 }
80}
81
83{
84 auto * proc = new MythUIProcedural(Parent, objectName());
85 proc->CopyFrom(this);
86}
87
89{
91 SetRedraw();
92}
93
95{
96 if (!m_vertexSource)
97 LOG(VB_GENERAL, LOG_WARNING, "Failed to retrieve vertex source code for procedural texture");
98
100 LOG(VB_GENERAL, LOG_WARNING, "Failed to retrieve fragment source code for procedural texture");
101
103 m_hash = QCryptographicHash::hash(*m_vertexSource + *m_fragmentSource,
104 QCryptographicHash::Md5);
105}
106
108{
109 QFile f(GetMythUI()->GetThemeDir() + '/' + filename);
110
111 if (!f.open(QFile::ReadOnly | QFile::Text))
112 {
113 LOG(VB_GENERAL, LOG_WARNING, "Failed to load source code for procedural texture from " + filename);
114 return nullptr;
115 }
116
117 QTextStream in(&f);
118 QString program = in.readAll();
119 return std::make_shared<QByteArray>(program.toLatin1().constData());
120}
virtual void DrawProcedural(QRect, int, const ProcSource &, const ProcSource &, const QString &)
Definition: mythpainter.h:65
virtual void SetClipRect(QRect clipRect)
Definition: mythpainter.cpp:45
void Pulse() override
Pulse is called 70 times a second to trigger a single frame of an animation.
MythUIProcedural(MythUIType *Parent, const QString &Name)
A procedural texture class.
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
void CopyFrom(MythUIType *Base) override
Copy this widgets state from another.
void CreateCopy(MythUIType *Parent) override
Copy the state of this widget to the one given, it must be of the same type.
static ShaderSource LoadShaderSource(const QString &filename)
ShaderSource m_fragmentSource
ShaderSource m_vertexSource
void DrawSelf(MythPainter *Painter, int XOffset, int YOffset, int AlphaMod, QRect ClipRect) override
bool ParseElement(const QString &FileName, QDomElement &Element, bool ShowWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
The base class on which all widgets and screens are based.
Definition: mythuitype.h:86
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
void SetRedraw(void)
Definition: mythuitype.cpp:313
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:456
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
Definition: mythuitype.cpp:885
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
static QString parseText(QDomElement &element)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythUIHelper * GetMythUI()
std::shared_ptr< QByteArray > ShaderSource