2 Copyright 2012 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "surfacevector.h"
27 SurfaceVector::SurfaceVector(OsdVector* vosd)
33 SurfaceVector::~SurfaceVector()
35 osd->removeSurface(this);
36 list<SVGCommand>::iterator itty=commands.begin();
37 while (itty!=commands.end())
39 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
40 ImageIndex ii=(*itty).getImageIndex();
42 osd->removeImageRef(ii);
44 LoadIndex li=(*itty).getLoadIndex();
45 if (li) osd->removeLoadIndexRef(li);
51 int SurfaceVector::getFontHeight()
53 return osd->getFontHeight();
56 float SurfaceVector::getCharWidth(wchar_t c)
58 return osd->getCharWidth(c);
61 wchar_t SurfaceVector::getWChar(const char* str, unsigned int *length)
70 } else if (str[1]=='\0'){
72 } else if (str[2]=='\0'){
76 memset((void*)&state,0,sizeof(state));
77 num_bytes=mbrtowc(tempo, str, max_length, &state);
78 if (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2))
88 int SurfaceVector::drawText(const char* text, int x, int y, const DrawStyle& c){
89 return drawText(text, x, y, 0, c);
92 int SurfaceVector::drawText(const char* text, int x, int y, int width, const DrawStyle& c)
99 size_t length=strlen(text);
100 memset((void*)&state,0,sizeof(state));
101 command_mutex.Lock();
102 num_bytes=mbrtowc(tempo, run, length, &state);
103 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
105 unsigned int ref=osd->getStyleRef(c);
106 commands.push_back(SVGCommand::PaintGlyph(x+shift,y,*tempo,ref));
107 shift+=osd->getCharWidth(*tempo);
110 if (shift>width && width >0) {
111 command_mutex.Unlock();
114 num_bytes=mbrtowc(tempo, run, length, &state);
116 command_mutex.Unlock();
120 int SurfaceVector::drawTextRJ(const char* text, int x, int y, const DrawStyle& c)
123 const char *run=text;
127 size_t length=strlen(text);
128 memset((void*)&state,0,sizeof(state));
130 num_bytes=mbrtowc(tempo, run, length, &state);
131 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
133 shift+=osd->getCharWidth(*tempo);
136 num_bytes=mbrtowc(tempo, run, length, &state);
138 return drawText(text, x-shift, y, c);
141 int SurfaceVector::drawTextCentre(const char* text, int x, int y, const DrawStyle& c)
144 const char *run=text;
148 size_t length=strlen(text);
149 memset((void*)&state,0,sizeof(state));
151 num_bytes=mbrtowc(tempo, run, length, &state);
152 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
154 shift+=osd->getCharWidth(*tempo);
157 num_bytes=mbrtowc(tempo, run, length, &state);
159 return drawText(text, x-shift/2., y, c);
162 void SurfaceVector::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
164 int jpeg_index=-1; // This is for compatibility only
165 if (strcmp(fileName,"/vdr.jpg")==0) {
167 *height=100; // this is faked so that the system does use the old coordinate system
168 *width=ceil(190.f*osd->getPixelAspect());
169 } else if (strcmp(fileName,"/wallpaperPAL.jpg")==0) {
171 *width=720; // this is faked so that the system does use the old coordinate system
176 info.setDefaultJpeg(jpeg_index);
177 drawTVMedia(info,x,y,*width,*height,TopLeft);
182 void SurfaceVector::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
184 command_mutex.Lock();
185 ImageIndex image=osd->getJpegRef(fileName,width,height);
186 commands.push_back(SVGCommand::PaintImage(x,y,*width,*height,image,0));
187 command_mutex.Unlock();
191 void SurfaceVector::drawTVMedia(TVMediaInfo & tvmedia,float x, float y, float width, float height, Corner corner)
193 command_mutex.Lock();
195 LoadIndex load_index=osd->getTVMediaRef(tvmedia,image);
197 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image %d %d", load_index,image);
198 commands.push_back(SVGCommand::PaintImage(x,y,width,height,image,0,corner));
201 commands.push_back(SVGCommand::PaintImageLoading(load_index,x,y,width,height,0,corner));
202 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image loading %d %d", load_index,image);
204 command_mutex.Unlock();
207 void SurfaceVector::drawClippingRectangle(float x, float y, float w, float h)
209 command_mutex.Lock();
210 commands.push_back(SVGCommand::PaintClipping((float)x,(float)y,(float)w,(float)h));
211 command_mutex.Unlock();
214 int SurfaceVector::create(UINT width, UINT height)
220 void SurfaceVector::display()
222 //nothing this is really mvp specific
225 int SurfaceVector::fillblt(int x, int y, int width, int height, const DrawStyle& c)
227 command_mutex.Lock();
228 removeCommands(x,y,width,height); // remove commands below the box
229 unsigned int ref=osd->getStyleRef(c);
230 commands.push_back(SVGCommand::PaintPath(x,y,width,height,Rectangle,ref));
231 command_mutex.Unlock();
235 void SurfaceVector::drawHorzLine(int x1, int x2, int y, const DrawStyle& c)
237 command_mutex.Lock();
238 unsigned int ref=osd->getStyleRef(c);
239 commands.push_back(SVGCommand::PaintPath(x1,y,x2-x1,1,HorzLine,ref));
240 command_mutex.Unlock();
243 void SurfaceVector::drawVertLine(int x, int y1, int y2, const DrawStyle& c){
244 command_mutex.Lock();
245 unsigned int ref=osd->getStyleRef(c);
246 commands.push_back(SVGCommand::PaintPath(x,y1,1,y2-y1,VertLine,ref));
247 command_mutex.Unlock();
250 void SurfaceVector::drawBitmap(int x, int y, const Bitmap& bm,const DisplayRegion & region)
252 //this is complicated
253 command_mutex.Lock();
255 unsigned int * data=(unsigned int*)malloc(sizeof(unsigned int)*bm.getWidth()*bm.getHeight());
256 for (UINT j = 0; j < bm.getHeight(); ++j){
257 for (UINT i = 0; i < bm.getWidth(); ++i)
259 data[i+j*bm.getHeight()]=bm.getColour(i,j);
262 ImageIndex image=osd->getImagePalette(bm.getWidth(),bm.getHeight(),&(bm.rawData()[0]),
263 (const unsigned int*)&bm.palette.getColourVector()[0]); // data is freed by the OSD
265 float tx=x+region.windowx;
266 float ty=y+region.windowy;
267 float th=bm.getHeight();
268 float tw=bm.getWidth();
270 float scalex=720.f/((float) (region.framewidth+1));
271 float scaley=576.f/((float) (region.frameheight+1));
276 SVGCommand temp=SVGCommand::PaintImage(tx,ty,tw,th,image,0);
277 commands.push_back(temp);
278 command_mutex.Unlock();
281 void SurfaceVector::drawPoint(int x, int y, DrawStyle& c, bool fastdraw){
282 if (!fastdraw) command_mutex.Lock();
283 unsigned int ref=osd->getStyleRef(c);
284 commands.push_back(SVGCommand::PaintPath(x,y,1,1,Point,ref));
285 if (!fastdraw) command_mutex.Unlock();
287 void SurfaceVector::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height,unsigned int width, DrawStyle& nextColour)
289 command_mutex.Lock();
290 ImageIndex image=osd->getMonoBitmapRef(base,width,height);
291 unsigned int ref=osd->getStyleRef(nextColour);
292 commands.push_back(SVGCommand::PaintImage(dx,dy,height,width,image,ref));
293 command_mutex.Unlock();
297 int SurfaceVector::removeCommands(float x,float y,float width,float height)
299 // we iterate through all old commands in order to remove commands hidden by this rectangle
300 list<SVGCommand>::iterator itty=commands.begin();
301 while (itty!=commands.end())
303 if ((*itty).Test(x,y,width,height) && (*itty).instr != DrawClipping) {
304 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
305 ImageIndex ii=(*itty).getImageIndex();
306 if (ii) osd->removeImageRef(ii);
307 LoadIndex li=(*itty).getLoadIndex();
308 if (li) osd->removeLoadIndexRef(li);
309 itty=commands.erase(itty);
318 int SurfaceVector::updateToScreen(int sx, int sy, int w, int h, int dx, int dy)
320 // ok this method really works in a pixel oriented way
321 command_mutex.Lock();
322 osd->updateOrAddSurface(this,dx-sx,dy-sy,swidth,sheight,commands);
323 command_mutex.Unlock();
328 /* This is for systems which need a locking of the drawing surface to speed up drawing */
329 void SurfaceVector::startFastDraw() {
330 command_mutex.Lock();
332 void SurfaceVector::endFastDraw() {
333 command_mutex.Unlock();
337 void SurfaceVector::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c)
339 command_mutex.Lock();
340 list<SVGCommand>::iterator itty=commands.begin();
341 while (itty!=commands.end())
343 if ((*itty).TTTest(ox,oy,x,y) ) {
344 itty=commands.erase(itty);
350 commands.push_back(SVGCommand::PaintTTchar(ox,oy,x,y,c.getInternal()));
351 command_mutex.Unlock();