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 QRegion();
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, int nPoints, const int xArray[], const int yArray[], MHEngine *engine)
172 {
173  m_picture->DrawPoly(fIsPolygon, nPoints, 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  int *xArray = new int[nPoints];
197  int *yArray = new int[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, nPoints, xArray, yArray, engine);
207  delete[](xArray);
208  delete[](yArray);
209 }
210 
211 void MHDrawPoly::PrintArgs(FILE *fd, int /*nTabs*/) const
212 {
213  fprintf(fd, " ( ");
214 
215  for (int i = 0; i < m_Points.Size(); i++)
216  {
217  m_Points[i]->PrintMe(fd, 0);
218  }
219 
220  fprintf(fd, " )\n");
221 }
void Display(MHEngine *d) override
MHOwnPtrSequence< MHPointArg > m_Points
void SetLineWidth(int nWidth, MHEngine *engine) override
MHColour m_OrigFillColour
Definition: Visible.h:114
void SetLineStyle(int nStyle, MHEngine *engine) override
void Clear() override
void Initialise(MHParseNode *p, MHEngine *engine) override
virtual void DrawPoly(bool isFilled, int nPoints, const int xArray[], const int yArray[])=0
virtual void SetVariableValue(const MHUnion &)
Definition: Root.h:108
MHRoot * Target(MHEngine *engine)
Definition: BaseActions.cpp:46
void SetFillColour(const MHColour &colour, MHEngine *engine) override
int m_nBoxWidth
Definition: Visible.h:79
virtual QRegion GetVisibleArea()
Definition: Visible.cpp:197
void DrawArcSector(bool fIsSector, int x, int y, int width, int height, int start, int arc, MHEngine *engine) override
virtual void DrawPoly(bool, int, const int *, const int *, MHEngine *)
Definition: Root.h:205
int m_nPosY
Definition: Visible.h:82
static MHRgba GetColour(const MHColour &colour)
Definition: Visible.cpp:156
int GetValue(MHEngine *engine) const
void Copy(const MHColour &col)
void Preparation(MHEngine *engine) override
bool m_fBorderedBBox
Definition: Visible.h:110
MHContext * GetContext()
Definition: Engine.h:154
MHGenericInteger m_y
Definition: BaseClasses.h:327
virtual void Draw(int x, int y)=0
MHGenericInteger m_x
Definition: BaseClasses.h:327
void PrintArgs(FILE *fd, int nTabs) const override
void SetBoxSize(int nWidth, int nHeight, MHEngine *engine) override
Definition: Visible.cpp:225
virtual void DrawArcSector(int x, int y, int width, int height, int start, int arc, bool isSector)=0
void Redraw(const QRegion &region)
Definition: Engine.cpp:899
int m_LineStyle
Definition: Visible.h:117
virtual void SetSize(int width, int height)=0
MHColour m_LineColour
Definition: Visible.h:118
void PrintTabs(FILE *fd, int n)
Definition: ParseNode.cpp:34
static int x2
Definition: mythsocket.cpp:61
int m_nPosX
Definition: Visible.h:81
virtual void DrawOval(int x, int y, int width, int height)=0
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Visible.cpp:278
void Perform(MHEngine *engine) override
MHColour m_FillColour
Definition: Visible.h:118
~MHDynamicLineArt() override
Definition: Root.h:43
virtual void DrawLine(int x1, int y1, int x2, int y2)=0
int FILE
Definition: mythburn.py:139
virtual void SetLineColour(MHRgba colour)=0
void PrintMe(FILE *fd, int nTabs) const override
void PrintMe(FILE *fd, int nTabs) const override
Definition: Visible.cpp:322
void Initialise(MHParseNode *p, MHEngine *engine) override
virtual void SetLineSize(int width)=0
void SetLineColour(const MHColour &colour, MHEngine *engine) override
virtual MHDLADisplay * CreateDynamicLineArt(bool isBoxed, MHRgba lineColour, MHRgba fillColour)=0
MHDLADisplay * m_picture
int m_nColIndex
Definition: BaseClasses.h:147
void DrawLine(int x1, int y1, int x2, int y2, MHEngine *engine) override
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseActions.cpp:31
void SetBoxSize(int nWidth, int nHeight, MHEngine *engine) override
virtual void Clear()=0
void GetLineColour(MHRoot *pResult) override
virtual void SetFillColour(MHRgba colour)=0
MHColour m_OrigLineColour
Definition: Visible.h:114
void Preparation(MHEngine *engine) override
Definition: Visible.cpp:361
void DrawOval(int x1, int y1, int width, int height, MHEngine *engine) override
void Append(BASE b)
Definition: BaseClasses.h:63
virtual void DrawBorderedRectangle(int x, int y, int width, int height)=0
int m_nLineWidth
Definition: Visible.h:116
int m_nBoxHeight
Definition: Visible.h:80
int Size() const
Definition: BaseClasses.h:46
QRegion GetOpaqueArea() override
void DrawPoly(bool fIsPolygon, int nPoints, const int *xArray, const int *yArray, MHEngine *engine) override
void DrawRectangle(int x1, int y1, int x2, int y2, MHEngine *engine) override
MHOctetString m_ColStr
Definition: BaseClasses.h:146
void GetFillColour(MHRoot *pResult) override
static int x1
Definition: mythsocket.cpp:60