MythTV  master
DynamicLineArt.cpp
Go to the documentation of this file.
1 /* DynamicLineArt.cpp
2 
3  Copyright (C) David C. J. Matthews 2004 dm at prolingua.co.uk
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation; either version 2
8  of the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18  Or, point your browser to http://www.gnu.org/copyleft/gpl.html
19 
20 */
21 
22 #include "DynamicLineArt.h"
23 #include "Visible.h"
24 #include "Presentable.h"
25 #include "Ingredients.h"
26 #include "Root.h"
27 #include "BaseClasses.h"
28 #include "ParseNode.h"
29 #include "ASN1Codes.h"
30 #include "Engine.h"
31 #include "freemheg.h"
32 
34 {
35  delete(m_picture);
36 }
37 
38 
40 {
41  MHLineArt::Initialise(p, engine);
42  m_picture =
44 }
45 
46 void MHDynamicLineArt::PrintMe(FILE *fd, int nTabs) const
47 {
48  PrintTabs(fd, nTabs);
49  fprintf(fd, "{:DynamicLineArt ");
50  MHLineArt::PrintMe(fd, nTabs + 1);
51  PrintTabs(fd, nTabs);
52  fprintf(fd, "}\n");
53 }
54 
56 {
57  MHLineArt::Preparation(engine);
62 }
63 
65 {
67 }
68 
69 // Get the opaque area. This is only opaque if the background is opaque.
71 {
72  if ((GetColour(m_origFillColour)).alpha() == 255)
73  {
74  return GetVisibleArea();
75  }
76  return {};
77 }
78 
79 // Reset the picture.
81 {
82  m_picture->Clear();
83 }
84 
85 // As well as the general action this also clears the drawing.
86 void MHDynamicLineArt::SetBoxSize(int nWidth, int nHeight, MHEngine *engine)
87 {
88  MHLineArt::SetBoxSize(nWidth, nHeight, engine);
89  m_picture->SetSize(nWidth, nHeight);
90  Clear();
91 }
92 
93 // SetPosition, BringToFront, SendToBack, PutBefore and PutBehind were defined in the original
94 // MHEG standard to clear the drawing. This was removed in the MHEG Corrigendum.
95 
96 void MHDynamicLineArt::SetFillColour(const MHColour &colour, MHEngine * /*engine*/)
97 {
98  m_fillColour.Copy(colour);
100 }
101 
102 void MHDynamicLineArt::SetLineColour(const MHColour &colour, MHEngine * /*engine*/)
103 {
104  m_lineColour.Copy(colour);
106 }
107 
108 void MHDynamicLineArt::SetLineWidth(int nWidth, MHEngine * /*engine*/)
109 {
110  m_nLineWidth = nWidth;
112 }
113 
114 // We don't actually use this at the moment.
115 void MHDynamicLineArt::SetLineStyle(int nStyle, MHEngine * /*engine*/)
116 {
117  m_lineStyle = nStyle;
118 }
119 
120 
122 {
123  // Returns the palette index as an integer if it is an index or the colour as a string if not.
124  if (m_lineColour.m_nColIndex >= 0)
125  {
127  }
128  else
129  {
131  }
132 }
133 
135 {
136  if (m_fillColour.m_nColIndex >= 0)
137  {
139  }
140  else
141  {
143  }
144 }
145 
146 void MHDynamicLineArt::DrawLine(int x1, int y1, int x2, int y2, MHEngine *engine)
147 {
148  m_picture->DrawLine(x1, y1, x2, y2);
149  engine->Redraw(GetVisibleArea());
150 }
151 
152 void MHDynamicLineArt::DrawRectangle(int x1, int y1, int x2, int y2, MHEngine *engine)
153 {
154  m_picture->DrawBorderedRectangle(x1, y1, x2 - x1, y2 - y1);
155  engine->Redraw(GetVisibleArea());
156 }
157 
158 void MHDynamicLineArt::DrawOval(int x, int y, int width, int height, MHEngine *engine)
159 {
160  m_picture->DrawOval(x, y, width, height);
161  engine->Redraw(GetVisibleArea());
162 }
163 
164 void MHDynamicLineArt::DrawArcSector(bool fIsSector, int x, int y, int width, int height,
165  int start, int arc, MHEngine *engine)
166 {
167  m_picture->DrawArcSector(x, y, width, height, start, arc, fIsSector);
168  engine->Redraw(GetVisibleArea());
169 }
170 
171 void MHDynamicLineArt::DrawPoly(bool fIsPolygon, const MHPointVec& xArray, const MHPointVec& yArray, MHEngine *engine)
172 {
173  m_picture->DrawPoly(fIsPolygon, xArray, yArray);
174  engine->Redraw(GetVisibleArea());
175 }
176 
177 // Actions.
178 
179 // Polygons and Polylines have the same arguments: a list of points.
181 {
182  MHElemAction::Initialise(p, engine);
183  MHParseNode *args = p->GetArgN(1);
184 
185  for (int i = 0; i < args->GetSeqCount(); i++)
186  {
187  auto *pPoint = new MHPointArg;
188  m_points.Append(pPoint);
189  pPoint->Initialise(args->GetSeqN(i), engine);
190  }
191 }
192 
194 {
195  int nPoints = m_points.Size();
196  MHPointVec xArray; xArray.reserve(nPoints);
197  MHPointVec yArray; yArray.reserve(nPoints);
198 
199  for (int i = 0; i < nPoints; i++)
200  {
201  MHPointArg *pPoint = m_points[i];
202  xArray[i] = pPoint->m_x.GetValue(engine);
203  yArray[i] = pPoint->m_y.GetValue(engine);
204  }
205 
206  Target(engine)->DrawPoly(m_fIsPolygon, xArray, yArray, engine);
207 }
208 
209 void MHDrawPoly::PrintArgs(FILE *fd, int /*nTabs*/) const
210 {
211  fprintf(fd, " ( ");
212 
213  for (int i = 0; i < m_points.Size(); i++)
214  {
215  m_points[i]->PrintMe(fd, 0);
216  }
217 
218  fprintf(fd, " )\n");
219 }
MHPointArg::m_x
MHGenericInteger m_x
Definition: BaseClasses.h:328
MHLineArt::m_fillColour
MHColour m_fillColour
Definition: Visible.h:118
build_compdb.args
args
Definition: build_compdb.py:11
MHDrawPoly::PrintArgs
void PrintArgs(FILE *fd, int nTabs) const override
Definition: DynamicLineArt.cpp:209
Presentable.h
MHDynamicLineArt::DrawRectangle
void DrawRectangle(int x1, int y1, int x2, int y2, MHEngine *engine) override
Definition: DynamicLineArt.cpp:152
MHDynamicLineArt::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: DynamicLineArt.cpp:39
MHColour::m_nColIndex
int m_nColIndex
Definition: BaseClasses.h:148
MHEngine::GetContext
MHContext * GetContext()
Definition: Engine.h:154
ASN1Codes.h
MHEngine
Definition: Engine.h:72
MHDynamicLineArt::DrawPoly
void DrawPoly(bool fIsPolygon, const MHPointVec &xArray, const MHPointVec &yArray, MHEngine *engine) override
Definition: DynamicLineArt.cpp:171
x2
static int x2
Definition: mythsocket.cpp:51
MHVisible::GetColour
static MHRgba GetColour(const MHColour &colour)
Definition: Visible.cpp:162
MHLineArt::m_lineColour
MHColour m_lineColour
Definition: Visible.h:118
MHDLADisplay::DrawArcSector
virtual void DrawArcSector(int x, int y, int width, int height, int start, int arc, bool isSector)=0
MHDynamicLineArt::Display
void Display(MHEngine *d) override
Definition: DynamicLineArt.cpp:64
Visible.h
MHRoot::SetVariableValue
virtual void SetVariableValue(const MHUnion &)
Definition: Root.h:109
MHElemAction::Initialise
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseActions.cpp:31
MHDynamicLineArt::Preparation
void Preparation(MHEngine *engine) override
Definition: DynamicLineArt.cpp:55
MHDynamicLineArt::SetLineWidth
void SetLineWidth(int nWidth, MHEngine *engine) override
Definition: DynamicLineArt.cpp:108
MHLineArt::m_lineStyle
int m_lineStyle
Definition: Visible.h:117
MHDLADisplay::DrawOval
virtual void DrawOval(int x, int y, int width, int height)=0
MHDynamicLineArt::DrawLine
void DrawLine(int x1, int y1, int x2, int y2, MHEngine *engine) override
Definition: DynamicLineArt.cpp:146
MHDynamicLineArt::GetOpaqueArea
QRegion GetOpaqueArea() override
Definition: DynamicLineArt.cpp:70
mythburn.FILE
int FILE
Definition: mythburn.py:139
MHVisible::m_nPosY
int m_nPosY
Definition: Visible.h:82
MHDynamicLineArt::Clear
void Clear() override
Definition: DynamicLineArt.cpp:80
MHDLADisplay::Clear
virtual void Clear()=0
MHDLADisplay::SetFillColour
virtual void SetFillColour(MHRgba colour)=0
MHEngine::Redraw
void Redraw(const QRegion &region)
Definition: Engine.cpp:898
MHDrawPoly::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: DynamicLineArt.cpp:180
MHLineArt::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Visible.cpp:329
MHLineArt::m_nLineWidth
int m_nLineWidth
Definition: Visible.h:116
MHDLADisplay::SetLineColour
virtual void SetLineColour(MHRgba colour)=0
MHColour::m_colStr
MHOctetString m_colStr
Definition: BaseClasses.h:147
hardwareprofile.config.p
p
Definition: config.py:33
MHDynamicLineArt::SetLineStyle
void SetLineStyle(int nStyle, MHEngine *engine) override
Definition: DynamicLineArt.cpp:115
ParseNode.h
MHDynamicLineArt::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: DynamicLineArt.cpp:46
x1
static int x1
Definition: mythsocket.cpp:50
PrintTabs
void PrintTabs(FILE *fd, int n)
Definition: ParseNode.cpp:34
MHVisible::m_nBoxHeight
int m_nBoxHeight
Definition: Visible.h:80
MHColour
Definition: BaseClasses.h:139
MHVisible::GetVisibleArea
virtual QRegion GetVisibleArea()
Definition: Visible.cpp:203
MHDLADisplay::DrawPoly
virtual void DrawPoly(bool isFilled, const MHPointVec &xArray, const MHPointVec &yArray)=0
MHVisible::m_nPosX
int m_nPosX
Definition: Visible.h:81
MHDynamicLineArt::~MHDynamicLineArt
~MHDynamicLineArt() override
Definition: DynamicLineArt.cpp:33
Engine.h
MHLineArt::Preparation
void Preparation(MHEngine *engine) override
Definition: Visible.cpp:368
MHContext::CreateDynamicLineArt
virtual MHDLADisplay * CreateDynamicLineArt(bool isBoxed, MHRgba lineColour, MHRgba fillColour)=0
MHDynamicLineArt::GetLineColour
void GetLineColour(MHRoot *pResult) override
Definition: DynamicLineArt.cpp:121
Ingredients.h
MHElemAction::Target
MHRoot * Target(MHEngine *engine)
Definition: BaseActions.cpp:46
MHDrawPoly::m_fIsPolygon
bool m_fIsPolygon
Definition: DynamicLineArt.h:154
MHDynamicLineArt::DrawArcSector
void DrawArcSector(bool fIsSector, int x, int y, int width, int height, int start, int arc, MHEngine *engine) override
Definition: DynamicLineArt.cpp:164
Root.h
MHRoot::DrawPoly
virtual void DrawPoly(bool, const MHPointVec &, const MHPointVec &, MHEngine *)
Definition: Root.h:206
MHDynamicLineArt::GetFillColour
void GetFillColour(MHRoot *pResult) override
Definition: DynamicLineArt.cpp:134
MHVisible::SetBoxSize
void SetBoxSize(int nWidth, int nHeight, MHEngine *engine) override
Definition: Visible.cpp:231
MHDrawPoly::m_points
MHOwnPtrSequence< MHPointArg > m_points
Definition: DynamicLineArt.h:155
MHDynamicLineArt::SetBoxSize
void SetBoxSize(int nWidth, int nHeight, MHEngine *engine) override
Definition: DynamicLineArt.cpp:86
MHDLADisplay::DrawBorderedRectangle
virtual void DrawBorderedRectangle(int x, int y, int width, int height)=0
MHDynamicLineArt::m_picture
MHDLADisplay * m_picture
Definition: DynamicLineArt.h:72
MHColour::Copy
void Copy(const MHColour &col)
Definition: BaseClasses.cpp:251
MHDynamicLineArt::SetFillColour
void SetFillColour(const MHColour &colour, MHEngine *engine) override
Definition: DynamicLineArt.cpp:96
BaseClasses.h
MHPointArg
Definition: BaseClasses.h:323
MHDrawPoly::Perform
void Perform(MHEngine *engine) override
Definition: DynamicLineArt.cpp:193
MHSequence::Size
int Size() const
Definition: BaseClasses.h:47
MHDynamicLineArt::DrawOval
void DrawOval(int x1, int y1, int width, int height, MHEngine *engine) override
Definition: DynamicLineArt.cpp:158
MHParseNode
Definition: ParseNode.h:38
MHGenericInteger::GetValue
int GetValue(MHEngine *engine) const
Definition: BaseClasses.cpp:411
DynamicLineArt.h
MHDLADisplay::DrawLine
virtual void DrawLine(int x1, int y1, int x2, int y2)=0
MHDLADisplay::SetLineSize
virtual void SetLineSize(int width)=0
MHLineArt::m_origLineColour
MHColour m_origLineColour
Definition: Visible.h:114
MHDynamicLineArt::SetLineColour
void SetLineColour(const MHColour &colour, MHEngine *engine) override
Definition: DynamicLineArt.cpp:102
MHSequence::Append
void Append(BASE b)
Definition: BaseClasses.h:64
MHDLADisplay::Draw
virtual void Draw(int x, int y)=0
MHLineArt::m_fBorderedBBox
bool m_fBorderedBBox
Definition: Visible.h:110
freemheg.h
MHVisible::m_nBoxWidth
int m_nBoxWidth
Definition: Visible.h:79
MHPointArg::m_y
MHGenericInteger m_y
Definition: BaseClasses.h:328
MHDLADisplay::SetSize
virtual void SetSize(int width, int height)=0
MHLineArt::m_origFillColour
MHColour m_origFillColour
Definition: Visible.h:114
MHPointVec
std::vector< int > MHPointVec
Definition: BaseClasses.h:31
MHRoot
Definition: Root.h:44
MHLineArt::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Visible.cpp:285