00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "DynamicLineArt.h"
00023 #include "Visible.h"
00024 #include "Presentable.h"
00025 #include "Ingredients.h"
00026 #include "Root.h"
00027 #include "BaseClasses.h"
00028 #include "ParseNode.h"
00029 #include "ASN1Codes.h"
00030 #include "Engine.h"
00031 #include "freemheg.h"
00032
00033 MHDynamicLineArt::MHDynamicLineArt()
00034 {
00035 m_picture = NULL;
00036 }
00037
00038 MHDynamicLineArt::~MHDynamicLineArt()
00039 {
00040 delete(m_picture);
00041 }
00042
00043
00044 void MHDynamicLineArt::Initialise(MHParseNode *p, MHEngine *engine)
00045 {
00046 MHLineArt::Initialise(p, engine);
00047 m_picture =
00048 engine->GetContext()->CreateDynamicLineArt(m_fBorderedBBox, GetColour(m_OrigLineColour), GetColour(m_OrigFillColour));
00049 }
00050
00051 void MHDynamicLineArt::PrintMe(FILE *fd, int nTabs) const
00052 {
00053 PrintTabs(fd, nTabs);
00054 fprintf(fd, "{:DynamicLineArt ");
00055 MHLineArt::PrintMe(fd, nTabs + 1);
00056 PrintTabs(fd, nTabs);
00057 fprintf(fd, "}\n");
00058 }
00059
00060 void MHDynamicLineArt::Preparation(MHEngine *engine)
00061 {
00062 MHLineArt::Preparation(engine);
00063 m_picture->SetSize(m_nBoxWidth, m_nBoxHeight);
00064 m_picture->SetLineSize(m_nLineWidth);
00065 m_picture->SetLineColour(GetColour(m_LineColour));
00066 m_picture->SetFillColour(GetColour(m_FillColour));
00067 }
00068
00069 void MHDynamicLineArt::Display(MHEngine *)
00070 {
00071 m_picture->Draw(m_nPosX, m_nPosY);
00072 }
00073
00074
00075 QRegion MHDynamicLineArt::GetOpaqueArea()
00076 {
00077 if ((GetColour(m_OrigFillColour)).alpha() == 255)
00078 {
00079 return GetVisibleArea();
00080 }
00081 else
00082 {
00083 return QRegion();
00084 }
00085 }
00086
00087
00088 void MHDynamicLineArt::Clear()
00089 {
00090 m_picture->Clear();
00091 }
00092
00093
00094 void MHDynamicLineArt::SetBoxSize(int nWidth, int nHeight, MHEngine *engine)
00095 {
00096 MHLineArt::SetBoxSize(nWidth, nHeight, engine);
00097 m_picture->SetSize(nWidth, nHeight);
00098 Clear();
00099 }
00100
00101
00102
00103
00104 void MHDynamicLineArt::SetFillColour(const MHColour &colour, MHEngine *)
00105 {
00106 m_FillColour.Copy(colour);
00107 m_picture->SetFillColour(GetColour(m_FillColour));
00108 }
00109
00110 void MHDynamicLineArt::SetLineColour(const MHColour &colour, MHEngine *)
00111 {
00112 m_LineColour.Copy(colour);
00113 m_picture->SetLineColour(GetColour(m_LineColour));
00114 }
00115
00116 void MHDynamicLineArt::SetLineWidth(int nWidth)
00117 {
00118 m_nLineWidth = nWidth;
00119 m_picture->SetLineSize(m_nLineWidth);
00120 }
00121
00122
00123 void MHDynamicLineArt::SetLineStyle(int nStyle)
00124 {
00125 m_LineStyle = nStyle;
00126 }
00127
00128
00129 void MHDynamicLineArt::GetLineColour(MHRoot *pResult)
00130 {
00131
00132 if (m_LineColour.m_nColIndex >= 0)
00133 {
00134 pResult->SetVariableValue(m_LineColour.m_nColIndex);
00135 }
00136 else
00137 {
00138 pResult->SetVariableValue(m_LineColour.m_ColStr);
00139 }
00140 }
00141
00142 void MHDynamicLineArt::GetFillColour(MHRoot *pResult)
00143 {
00144 if (m_FillColour.m_nColIndex >= 0)
00145 {
00146 pResult->SetVariableValue(m_FillColour.m_nColIndex);
00147 }
00148 else
00149 {
00150 pResult->SetVariableValue(m_FillColour.m_ColStr);
00151 }
00152 }
00153
00154 void MHDynamicLineArt::DrawLine(int x1, int y1, int x2, int y2, MHEngine *engine)
00155 {
00156 m_picture->DrawLine(x1, y1, x2, y2);
00157 engine->Redraw(GetVisibleArea());
00158 }
00159
00160 void MHDynamicLineArt::DrawRectangle(int x1, int y1, int x2, int y2, MHEngine *engine)
00161 {
00162 m_picture->DrawBorderedRectangle(x1, y1, x2 - x1, y2 - y1);
00163 engine->Redraw(GetVisibleArea());
00164 }
00165
00166 void MHDynamicLineArt::DrawOval(int x, int y, int width, int height, MHEngine *engine)
00167 {
00168 m_picture->DrawOval(x, y, width, height);
00169 engine->Redraw(GetVisibleArea());
00170 }
00171
00172 void MHDynamicLineArt::DrawArcSector(bool fIsSector, int x, int y, int width, int height,
00173 int start, int arc, MHEngine *engine)
00174 {
00175 m_picture->DrawArcSector(x, y, width, height, start, arc, fIsSector);
00176 engine->Redraw(GetVisibleArea());
00177 }
00178
00179 void MHDynamicLineArt::DrawPoly(bool fIsPolygon, int nPoints, const int xArray[], const int yArray[], MHEngine *engine)
00180 {
00181 m_picture->DrawPoly(fIsPolygon, nPoints, xArray, yArray);
00182 engine->Redraw(GetVisibleArea());
00183 }
00184
00185
00186
00187
00188 void MHDrawPoly::Initialise(MHParseNode *p, MHEngine *engine)
00189 {
00190 MHElemAction::Initialise(p, engine);
00191 MHParseNode *args = p->GetArgN(1);
00192
00193 for (int i = 0; i < args->GetSeqCount(); i++)
00194 {
00195 MHPointArg *pPoint = new MHPointArg;
00196 m_Points.Append(pPoint);
00197 pPoint->Initialise(args->GetSeqN(i), engine);
00198 }
00199 }
00200
00201 void MHDrawPoly::Perform(MHEngine *engine)
00202 {
00203 int nPoints = m_Points.Size();
00204 int *xArray = new int[nPoints];
00205 int *yArray = new int[nPoints];
00206
00207 for (int i = 0; i < nPoints; i++)
00208 {
00209 MHPointArg *pPoint = m_Points[i];
00210 xArray[i] = pPoint->x.GetValue(engine);
00211 yArray[i] = pPoint->y.GetValue(engine);
00212 }
00213
00214 Target(engine)->DrawPoly(m_fIsPolygon, nPoints, xArray, yArray, engine);
00215 delete[](xArray);
00216 delete[](yArray);
00217 }
00218
00219 void MHDrawPoly::PrintArgs(FILE *fd, int ) const
00220 {
00221 fprintf(fd, " ( ");
00222
00223 for (int i = 0; i < m_Points.Size(); i++)
00224 {
00225 m_Points[i]->PrintMe(fd, 0);
00226 }
00227
00228 fprintf(fd, " )\n");
00229 }