00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Bitmap.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 "Logging.h"
00032 #include "freemheg.h"
00033
00034 #include "inttypes.h"
00035
00036
00037
00038
00039
00040 MHBitmap::MHBitmap()
00041 {
00042 m_fTiling = false;
00043 m_nOrigTransparency = 0;
00044 m_nXDecodeOffset = 0;
00045 m_nYDecodeOffset = 0;
00046 m_pContent = NULL;
00047 }
00048
00049 MHBitmap::MHBitmap(const MHBitmap &ref): MHVisible(ref)
00050 {
00051 m_fTiling = ref.m_fTiling;
00052 m_nOrigTransparency = ref.m_nOrigTransparency;
00053 m_nXDecodeOffset = 0;
00054 m_nYDecodeOffset = 0;
00055 m_pContent = NULL;
00056 }
00057
00058 MHBitmap::~MHBitmap()
00059 {
00060 delete(m_pContent);
00061 }
00062
00063 void MHBitmap::Initialise(MHParseNode *p, MHEngine *engine)
00064 {
00065 MHVisible::Initialise(p, engine);
00066
00067 MHParseNode *pTiling = p->GetNamedArg(C_TILING);
00068 if (pTiling) m_fTiling = pTiling->GetArgN(0)->GetBoolValue();
00069
00070 MHParseNode *pTransparency = p->GetNamedArg(C_ORIGINAL_TRANSPARENCY);
00071 if (pTransparency) m_nOrigTransparency = pTransparency->GetArgN(0)->GetIntValue();
00072 m_pContent = engine->GetContext()->CreateBitmap(m_fTiling);
00073 }
00074
00075 void MHBitmap::PrintMe(FILE *fd, int nTabs) const
00076 {
00077 PrintTabs(fd, nTabs); fprintf(fd, "{:Bitmap ");
00078 MHVisible::PrintMe(fd, nTabs+1);
00079 if (m_fTiling) { PrintTabs(fd, nTabs+1); fprintf(fd, ":Tiling true\n"); }
00080 if (m_nOrigTransparency != 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigTransparency %d\n", m_nOrigTransparency); }
00081 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00082 }
00083
00084 void MHBitmap::Preparation(MHEngine *engine)
00085 {
00086 if (m_fAvailable) return;
00087 m_nTransparency = m_nOrigTransparency;
00088 MHVisible::Preparation(engine);
00089 }
00090
00091
00092 void MHBitmap::ContentPreparation(MHEngine *engine)
00093 {
00094 MHVisible::ContentPreparation(engine);
00095 if (m_ContentType == IN_NoContent)
00096 MHERROR("Bitmap must contain a content");
00097 if (m_ContentType == IN_IncludedContent)
00098 MHERROR("Included content in bitmap is not implemented");
00099 }
00100
00101
00102 void MHBitmap::ContentArrived(const unsigned char *data, int length, MHEngine *engine)
00103 {
00104 QRegion updateArea = GetVisibleArea();
00105 if (! m_pContent) return;
00106
00107 int nCHook = m_nContentHook;
00108 if (nCHook == 0) nCHook = engine->GetDefaultBitmapCHook();
00109
00110
00111 if (nCHook == 4) {
00112 m_pContent->CreateFromPNG(data, length);
00113 }
00114
00115
00116
00117 else if (nCHook == 2 ) {
00118 m_pContent->CreateFromMPEG(data, length);
00119 }
00120
00121 else MHERROR(QString("Unknown bitmap content hook %1").arg(nCHook));
00122
00123 updateArea += GetVisibleArea();
00124 engine->Redraw(updateArea);
00125
00126
00127 engine->EventTriggered(this, EventContentAvailable);
00128 }
00129
00130
00131
00132
00133 void MHBitmap::SetTransparency(int nTransPerCent, MHEngine *)
00134 {
00135
00136
00137 if (nTransPerCent < 0) nTransPerCent = 0;
00138 if (nTransPerCent > 100) nTransPerCent = 100;
00139 m_nTransparency = ((nTransPerCent * 255) + 50) / 100;
00140 }
00141
00142
00143 void MHBitmap::ScaleBitmap(int xScale, int yScale, MHEngine *engine)
00144 {
00145 QRegion updateArea = GetVisibleArea();
00146 m_pContent->ScaleImage(xScale, yScale);
00147 updateArea += GetVisibleArea();
00148 engine->Redraw(updateArea);
00149 }
00150
00151
00152 void MHBitmap::SetBitmapDecodeOffset(int newXOffset, int newYOffset, MHEngine *engine)
00153 {
00154 QRegion updateArea = GetVisibleArea();
00155 m_nXDecodeOffset = newXOffset;
00156 m_nYDecodeOffset = newYOffset;
00157 updateArea += GetVisibleArea();
00158 engine->Redraw(updateArea);
00159 }
00160
00161
00162 void MHBitmap::GetBitmapDecodeOffset(MHRoot *pXOffset, MHRoot *pYOffset)
00163 {
00164 pXOffset->SetVariableValue(m_nXDecodeOffset);
00165 pYOffset->SetVariableValue(m_nYDecodeOffset);
00166 }
00167
00168 void MHBitmap::Display(MHEngine *)
00169 {
00170 if (! m_fRunning || ! m_pContent || m_nBoxWidth == 0 || m_nBoxHeight == 0) return;
00171
00172 m_pContent->Draw(m_nPosX+m_nXDecodeOffset, m_nPosY+m_nYDecodeOffset,
00173 QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight), m_fTiling);
00174 }
00175
00176
00177 QRegion MHBitmap::GetVisibleArea()
00178 {
00179 if (! m_fRunning || m_pContent == NULL) return QRegion();
00180
00181
00182 QSize imageSize = m_pContent->GetSize();
00183 QRegion boxRegion = QRegion(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight);
00184 QRegion bitmapRegion = QRegion(m_nPosX+m_nXDecodeOffset, m_nPosY+m_nYDecodeOffset,
00185 imageSize.width(), imageSize.height());
00186 return boxRegion & bitmapRegion;
00187 }
00188
00189
00190 QRegion MHBitmap::GetOpaqueArea()
00191 {
00192
00193 if (! m_fRunning || m_pContent == NULL || ! m_pContent->IsOpaque()) return QRegion();
00194 else return GetVisibleArea();
00195 }
00196