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"
26 SurfaceVector::SurfaceVector(OsdVector* vosd)
32 SurfaceVector::~SurfaceVector()
34 osd->removeSurface(this);
35 list<SVGCommand>::iterator itty=commands.begin();
36 while (itty!=commands.end())
38 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
39 ImageIndex ii=(*itty).getImageIndex();
41 osd->removeImageRef(ii);
43 LoadIndex li=(*itty).getLoadIndex();
44 if (li) osd->removeLoadIndexRef(li);
50 int SurfaceVector::getFontHeight()
52 return osd->getFontHeight();
55 float SurfaceVector::getCharWidth(wchar_t c)
57 return osd->getCharWidth(c);
60 wchar_t SurfaceVector::getWChar(const char* str, unsigned int *length)
69 } else if (str[1]=='\0'){
71 } else if (str[2]=='\0'){
75 memset((void*)&state,0,sizeof(state));
76 num_bytes=mbrtowc(tempo, str, max_length, &state);
77 if (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2))
87 int SurfaceVector::drawText(const char* text, int x, int y, const DrawStyle& c){
88 return drawText(text, x, y, 0, c);
91 int SurfaceVector::drawText(const char* text, int x, int y, int width, const DrawStyle& c)
98 size_t length=strlen(text);
99 memset((void*)&state,0,sizeof(state));
100 command_mutex.Lock();
101 num_bytes=mbrtowc(tempo, run, length, &state);
102 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
104 unsigned int ref=osd->getStyleRef(c);
105 commands.push_back(SVGCommand::PaintGlyph(x+shift,y,*tempo,ref));
106 shift+=osd->getCharWidth(*tempo);
109 if (shift>width && width >0) {
110 command_mutex.Unlock();
113 num_bytes=mbrtowc(tempo, run, length, &state);
115 command_mutex.Unlock();
119 int SurfaceVector::drawTextRJ(const char* text, int x, int y, const DrawStyle& c)
122 const char *run=text;
126 size_t length=strlen(text);
127 memset((void*)&state,0,sizeof(state));
129 num_bytes=mbrtowc(tempo, run, length, &state);
130 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
132 shift+=osd->getCharWidth(*tempo);
135 num_bytes=mbrtowc(tempo, run, length, &state);
137 return drawText(text, x-shift, y, c);
140 int SurfaceVector::drawTextCentre(const char* text, int x, int y, const DrawStyle& c)
143 const char *run=text;
147 size_t length=strlen(text);
148 memset((void*)&state,0,sizeof(state));
150 num_bytes=mbrtowc(tempo, run, length, &state);
151 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
153 shift+=osd->getCharWidth(*tempo);
156 num_bytes=mbrtowc(tempo, run, length, &state);
158 return drawText(text, x-shift/2., y, c);
161 void SurfaceVector::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
163 command_mutex.Lock();
164 ImageIndex image=osd->getJpegRef(fileName,width,height);
165 commands.push_back(SVGCommand::PaintImage(x,y,*width,*height,image,0));
166 command_mutex.Unlock();
169 void SurfaceVector::drawTVMedia(TVMediaInfo & tvmedia,float x, float y, float width, float height, Corner corner)
171 command_mutex.Lock();
173 LoadIndex load_index=osd->getTVMediaRef(tvmedia,image);
175 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image %d %d", load_index,image);
176 commands.push_back(SVGCommand::PaintImage(x,y,width,height,image,0,corner));
179 commands.push_back(SVGCommand::PaintImageLoading(load_index,x,y,width,height,0,corner));
180 //Log::getInstance()->log("SurfaceVector", Log::DEBUG, "TVMedia Add instru image loading %d %d", load_index,image);
182 command_mutex.Unlock();
185 void SurfaceVector::drawClippingRectangle(float x, float y, float w, float h)
187 command_mutex.Lock();
188 commands.push_back(SVGCommand::PaintClipping((float)x,(float)y,(float)w,(float)h));
189 command_mutex.Unlock();
192 int SurfaceVector::create(UINT width, UINT height)
198 void SurfaceVector::display()
200 //nothing this is really mvp specific
203 int SurfaceVector::fillblt(int x, int y, int width, int height, const DrawStyle& c)
205 command_mutex.Lock();
206 removeCommands(x,y,width,height); // remove commands below the box
207 unsigned int ref=osd->getStyleRef(c);
208 commands.push_back(SVGCommand::PaintPath(x,y,width,height,Rectangle,ref));
209 command_mutex.Unlock();
213 void SurfaceVector::drawHorzLine(int x1, int x2, int y, const DrawStyle& c)
215 command_mutex.Lock();
216 unsigned int ref=osd->getStyleRef(c);
217 commands.push_back(SVGCommand::PaintPath(x1,y,x2-x1,1,HorzLine,ref));
218 command_mutex.Unlock();
221 void SurfaceVector::drawVertLine(int x, int y1, int y2, const DrawStyle& c){
222 command_mutex.Lock();
223 unsigned int ref=osd->getStyleRef(c);
224 commands.push_back(SVGCommand::PaintPath(x,y1,1,y2-y1,VertLine,ref));
225 command_mutex.Unlock();
228 void SurfaceVector::drawBitmap(int x, int y, const Bitmap& bm,const DisplayRegion & region)
230 //this is complicated
231 command_mutex.Lock();
233 unsigned int * data=(unsigned int*)malloc(sizeof(unsigned int)*bm.getWidth()*bm.getHeight());
234 for (UINT j = 0; j < bm.getHeight(); ++j){
235 for (UINT i = 0; i < bm.getWidth(); ++i)
237 data[i+j*bm.getHeight()]=bm.getColour(i,j);
240 ImageIndex image=osd->getImagePalette(bm.getWidth(),bm.getHeight(),&(bm.rawData()[0]),
241 (const unsigned int*)&bm.palette.getColourVector()[0]); // data is freed by the OSD
243 float tx=x+region.windowx;
244 float ty=y+region.windowy;
245 float th=bm.getHeight();
246 float tw=bm.getWidth();
248 float scalex=720.f/((float) (region.framewidth+1));
249 float scaley=576.f/((float) (region.frameheight+1));
254 SVGCommand temp=SVGCommand::PaintImage(tx,ty,tw,th,image,0);
255 commands.push_back(temp);
256 command_mutex.Unlock();
259 void SurfaceVector::drawPoint(int x, int y, DrawStyle& c, bool fastdraw){
260 if (!fastdraw) command_mutex.Lock();
261 unsigned int ref=osd->getStyleRef(c);
262 commands.push_back(SVGCommand::PaintPath(x,y,1,1,Point,ref));
263 if (!fastdraw) command_mutex.Unlock();
265 void SurfaceVector::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height,unsigned int width, DrawStyle& nextColour)
267 command_mutex.Lock();
268 ImageIndex image=osd->getMonoBitmapRef(base,width,height);
269 unsigned int ref=osd->getStyleRef(nextColour);
270 commands.push_back(SVGCommand::PaintImage(dx,dy,height,width,image,ref));
271 command_mutex.Unlock();
275 int SurfaceVector::removeCommands(float x,float y,float width,float height)
277 // we iterate through all old commands in order to remove commands hidden by this rectangle
278 list<SVGCommand>::iterator itty=commands.begin();
279 while (itty!=commands.end())
281 if ((*itty).Test(x,y,width,height) && (*itty).instr != DrawClipping) {
282 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
283 ImageIndex ii=(*itty).getImageIndex();
284 if (ii) osd->removeImageRef(ii);
285 LoadIndex li=(*itty).getLoadIndex();
286 if (li) osd->removeLoadIndexRef(li);
287 itty=commands.erase(itty);
296 int SurfaceVector::updateToScreen(int sx, int sy, int w, int h, int dx, int dy)
298 // ok this method really works in a pixel oriented way
299 command_mutex.Lock();
300 osd->updateOrAddSurface(this,dx-sx,dy-sy,swidth,sheight,commands);
301 command_mutex.Unlock();
306 /* This is for systems which need a locking of the drawing surface to speed up drawing */
307 void SurfaceVector::startFastDraw() {
308 command_mutex.Lock();
310 void SurfaceVector::endFastDraw() {
311 command_mutex.Unlock();
315 void SurfaceVector::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c)
317 command_mutex.Lock();
318 list<SVGCommand>::iterator itty=commands.begin();
319 while (itty!=commands.end())
321 if ((*itty).TTTest(ox,oy,x,y) ) {
322 itty=commands.erase(itty);
328 commands.push_back(SVGCommand::PaintTTchar(ox,oy,x,y,c.getInternal()));
329 command_mutex.Unlock();