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
46void 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{
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{
83}
84
85// As well as the general action this also clears the drawing.
86void 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
96void MHDynamicLineArt::SetFillColour(const MHColour &colour, MHEngine * /*engine*/)
97{
98 m_fillColour.Copy(colour);
100}
101
102void MHDynamicLineArt::SetLineColour(const MHColour &colour, MHEngine * /*engine*/)
103{
104 m_lineColour.Copy(colour);
106}
107
108void MHDynamicLineArt::SetLineWidth(int nWidth, MHEngine * /*engine*/)
109{
110 m_nLineWidth = nWidth;
112}
113
114// We don't actually use this at the moment.
115void 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
146void 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
152void 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
158void 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
164void 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
171void 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{
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
209void 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}
std::vector< int > MHPointVec
Definition: BaseClasses.h:31
void PrintTabs(FILE *fd, int n)
Definition: ParseNode.cpp:34
MHOctetString m_colStr
Definition: BaseClasses.h:147
void Copy(const MHColour &col)
int m_nColIndex
Definition: BaseClasses.h:148
virtual MHDLADisplay * CreateDynamicLineArt(bool isBoxed, MHRgba lineColour, MHRgba fillColour)=0
virtual void SetLineColour(MHRgba colour)=0
virtual void SetSize(int width, int height)=0
virtual void DrawArcSector(int x, int y, int width, int height, int start, int arc, bool isSector)=0
virtual void DrawLine(int x1, int y1, int x2, int y2)=0
virtual void DrawOval(int x, int y, int width, int height)=0
virtual void DrawPoly(bool isFilled, const MHPointVec &xArray, const MHPointVec &yArray)=0
virtual void SetLineSize(int width)=0
virtual void Draw(int x, int y)=0
virtual void Clear()=0
virtual void DrawBorderedRectangle(int x, int y, int width, int height)=0
virtual void SetFillColour(MHRgba colour)=0
MHOwnPtrSequence< MHPointArg > m_points
void Perform(MHEngine *engine) override
void PrintArgs(FILE *fd, int nTabs) const override
void Initialise(MHParseNode *p, MHEngine *engine) override
void PrintMe(FILE *fd, int nTabs) const override
MHDLADisplay * m_picture
void SetLineWidth(int nWidth, MHEngine *engine) override
void DrawLine(int x1, int y1, int x2, int y2, MHEngine *engine) override
void Preparation(MHEngine *engine) override
void DrawPoly(bool fIsPolygon, const MHPointVec &xArray, const MHPointVec &yArray, MHEngine *engine) override
void SetBoxSize(int nWidth, int nHeight, MHEngine *engine) override
~MHDynamicLineArt() override
void Display(MHEngine *d) override
void GetFillColour(MHRoot *pResult) override
void SetLineColour(const MHColour &colour, MHEngine *engine) override
void GetLineColour(MHRoot *pResult) override
void Clear() override
void DrawArcSector(bool fIsSector, int x, int y, int width, int height, int start, int arc, MHEngine *engine) override
void DrawOval(int x1, int y1, int width, int height, MHEngine *engine) override
void SetFillColour(const MHColour &colour, MHEngine *engine) override
void DrawRectangle(int x1, int y1, int x2, int y2, MHEngine *engine) override
void Initialise(MHParseNode *p, MHEngine *engine) override
void SetLineStyle(int nStyle, MHEngine *engine) override
QRegion GetOpaqueArea() override
MHRoot * Target(MHEngine *engine)
Definition: BaseActions.cpp:46
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseActions.cpp:31
void Redraw(const QRegion &region)
Definition: Engine.cpp:926
MHContext * GetContext()
Definition: Engine.h:154
int GetValue(MHEngine *engine) const
MHColour m_fillColour
Definition: Visible.h:118
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Visible.cpp:285
MHColour m_origLineColour
Definition: Visible.h:114
void Preparation(MHEngine *engine) override
Definition: Visible.cpp:368
void PrintMe(FILE *fd, int nTabs) const override
Definition: Visible.cpp:329
int m_lineStyle
Definition: Visible.h:117
bool m_fBorderedBBox
Definition: Visible.h:110
MHColour m_origFillColour
Definition: Visible.h:114
int m_nLineWidth
Definition: Visible.h:116
MHColour m_lineColour
Definition: Visible.h:118
MHGenericInteger m_x
Definition: BaseClasses.h:328
MHGenericInteger m_y
Definition: BaseClasses.h:328
Definition: Root.h:45
virtual void DrawPoly(bool, const MHPointVec &, const MHPointVec &, MHEngine *)
Definition: Root.h:206
virtual void SetVariableValue(const MHUnion &)
Definition: Root.h:109
int Size() const
Definition: BaseClasses.h:47
void Append(BASE b)
Definition: BaseClasses.h:64
virtual QRegion GetVisibleArea()
Definition: Visible.cpp:203
int m_nBoxWidth
Definition: Visible.h:79
int m_nBoxHeight
Definition: Visible.h:80
static MHRgba GetColour(const MHColour &colour)
Definition: Visible.cpp:162
int m_nPosY
Definition: Visible.h:82
void SetBoxSize(int nWidth, int nHeight, MHEngine *engine) override
Definition: Visible.cpp:231
int m_nPosX
Definition: Visible.h:81
static int x1
Definition: mythsocket.cpp:50
static int x2
Definition: mythsocket.cpp:51
int FILE
Definition: mythburn.py:138