2 Copyright 2012 Marten Richter
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 #include "surfacevector.h"
\r
26 SurfaceVector::SurfaceVector(OsdVector* vosd)
\r
32 SurfaceVector::~SurfaceVector()
\r
34 osd->removeSurface(this);
\r
35 list<SVGCommand>::iterator itty=commands.begin();
\r
36 while (itty!=commands.end())
\r
38 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
\r
39 ImageIndex ii=(*itty).getImageIndex();
\r
40 if (ii) osd->removeImageRef(ii);
\r
46 int SurfaceVector::getFontHeight()
\r
48 return osd->getFontHeight();
\r
51 float SurfaceVector::getCharWidth(wchar_t c)
\r
53 return osd->getCharWidth(c);
\r
56 wchar_t SurfaceVector::getWChar(const char* str, unsigned int *length)
\r
65 } else if (str[1]=='\0'){
\r
67 } else if (str[2]=='\0'){
\r
71 memset((void*)&state,0,sizeof(state));
\r
72 num_bytes=mbrtowc(tempo, str, max_length, &state);
\r
73 if (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2))
\r
83 int SurfaceVector::drawText(const char* text, int x, int y, const DrawStyle& c){
\r
84 return drawText(text, x, y, 0, c);
\r
87 int SurfaceVector::drawText(const char* text, int x, int y, int width, const DrawStyle& c)
\r
90 const char *run=text;
\r
94 size_t length=strlen(text);
\r
95 memset((void*)&state,0,sizeof(state));
\r
96 command_mutex.Lock();
\r
97 num_bytes=mbrtowc(tempo, run, length, &state);
\r
98 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
\r
100 unsigned int ref=osd->getStyleRef(c);
\r
101 commands.push_back(SVGCommand(x+shift,y,*tempo,ref));
\r
102 shift+=osd->getCharWidth(*tempo);
\r
103 length -= num_bytes;
\r
105 if (shift>width && width >0) {
\r
106 command_mutex.Unlock();
\r
109 num_bytes=mbrtowc(tempo, run, length, &state);
\r
111 command_mutex.Unlock();
\r
115 int SurfaceVector::drawTextRJ(const char* text, int x, int y, const DrawStyle& c)
\r
118 const char *run=text;
\r
121 size_t num_bytes=1;
\r
122 size_t length=strlen(text);
\r
123 memset((void*)&state,0,sizeof(state));
\r
125 num_bytes=mbrtowc(tempo, run, length, &state);
\r
126 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
\r
128 shift+=osd->getCharWidth(*tempo);
\r
129 length -= num_bytes;
\r
131 num_bytes=mbrtowc(tempo, run, length, &state);
\r
133 return drawText(text, x-shift, y, c);
\r
136 int SurfaceVector::drawTextCentre(const char* text, int x, int y, const DrawStyle& c)
\r
139 const char *run=text;
\r
142 size_t num_bytes=1;
\r
143 size_t length=strlen(text);
\r
144 memset((void*)&state,0,sizeof(state));
\r
146 num_bytes=mbrtowc(tempo, run, length, &state);
\r
147 while (num_bytes!=((size_t) -1) && num_bytes!=((size_t) -2) && length>0)
\r
149 shift+=osd->getCharWidth(*tempo);
\r
150 length -= num_bytes;
\r
152 num_bytes=mbrtowc(tempo, run, length, &state);
\r
154 return drawText(text, x-shift/2., y, c);
\r
157 void SurfaceVector::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
\r
159 command_mutex.Lock();
\r
160 ImageIndex image=osd->getJpegRef(fileName,width,height);
\r
161 commands.push_back(SVGCommand(x,y,*height,*width,image,0));
\r
162 command_mutex.Unlock();
\r
165 int SurfaceVector::create(UINT width, UINT height)
\r
171 void SurfaceVector::display()
\r
173 //nothing this is really mvp specific
\r
176 int SurfaceVector::fillblt(int x, int y, int width, int height, const DrawStyle& c)
\r
178 command_mutex.Lock();
\r
179 removeCommands(x,y,width,height); // remove commands below the box
\r
180 unsigned int ref=osd->getStyleRef(c);
\r
181 commands.push_back(SVGCommand(x,y,width,height,Rectangle,ref));
\r
182 command_mutex.Unlock();
\r
186 void SurfaceVector::drawHorzLine(int x1, int x2, int y, const DrawStyle& c)
\r
188 command_mutex.Lock();
\r
189 unsigned int ref=osd->getStyleRef(c);
\r
190 commands.push_back(SVGCommand(x1,y,x2-x1,1,HorzLine,ref));
\r
191 command_mutex.Unlock();
\r
194 void SurfaceVector::drawVertLine(int x, int y1, int y2, const DrawStyle& c){
\r
195 command_mutex.Lock();
\r
196 unsigned int ref=osd->getStyleRef(c);
\r
197 commands.push_back(SVGCommand(x,y1,1,y2-y1,VertLine,ref));
\r
198 command_mutex.Unlock();
\r
201 void SurfaceVector::drawBitmap(int x, int y, const Bitmap& bm)
\r
203 //this is complicated
\r
204 command_mutex.Lock();
\r
205 ImageIndex image=osd->getImageRGBA(bm.getWidth(),bm.getHeight());
\r
206 unsigned int * data=(unsigned int*)malloc(sizeof(unsigned int)*bm.getWidth());
\r
207 for (UINT j = 0; j < bm.getHeight(); ++j){
\r
208 for (UINT i = 0; i < bm.getWidth(); ++i)
\r
210 data[i]=bm.getColour(i,j);
\r
212 osd->imageUploadLine(image,j,bm.getWidth(),data);
\r
215 commands.push_back(SVGCommand(x,y,bm.getHeight(),bm.getWidth(),image,0));
\r
216 command_mutex.Unlock();
\r
219 void SurfaceVector::drawPoint(int x, int y, DrawStyle& c, bool fastdraw){
\r
220 if (!fastdraw) command_mutex.Lock();
\r
221 unsigned int ref=osd->getStyleRef(c);
\r
222 commands.push_back(SVGCommand(x,y,1,1,Point,ref));
\r
223 if (!fastdraw) command_mutex.Unlock();
\r
225 void SurfaceVector::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height,unsigned int width, Colour& nextColour)
\r
227 command_mutex.Lock();
\r
228 ImageIndex image=osd->getMonoBitmapRef(base,width,height);
\r
229 unsigned int ref=osd->getColorRef(nextColour);
\r
230 commands.push_back(SVGCommand(dx,dy,height,width,image,ref));
\r
231 command_mutex.Unlock();
\r
235 int SurfaceVector::removeCommands(float x,float y,float width,float height)
\r
237 // we iterate through all old commands in order to remove commands hidden by this rectangle
\r
238 list<SVGCommand>::iterator itty=commands.begin();
\r
239 while (itty!=commands.end())
\r
241 if ((*itty).Test(x,y,width,height) ) {
\r
242 osd->removeStyleRef((*itty).getRef()); // We remove the Style reference, so that osd can free stuff
\r
243 ImageIndex ii=(*itty).getImageIndex();
\r
244 if (ii) osd->removeImageRef(ii);
\r
245 itty=commands.erase(itty);
\r
254 int SurfaceVector::updateToScreen(int sx, int sy, int w, int h, int dx, int dy)
\r
256 // ok this method really works in a pixel oriented way
\r
257 command_mutex.Lock();
\r
258 osd->updateOrAddSurface(this,dx-sx,dy-sy,swidth,sheight,commands);
\r
259 command_mutex.Unlock();
\r
264 /* This is for systems which need a locking of the drawing surface to speed up drawing */
\r
265 void SurfaceVector::startFastDraw() {
\r
266 command_mutex.Lock();
\r
268 void SurfaceVector::endFastDraw() {
\r
269 command_mutex.Unlock();
\r
273 void SurfaceVector::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c)
\r
275 command_mutex.Lock();
\r
276 list<SVGCommand>::iterator itty=commands.begin();
\r
277 while (itty!=commands.end())
\r
279 if ((*itty).TTTest(ox,oy,x,y) ) {
\r
280 itty=commands.erase(itty);
\r
286 commands.push_back(SVGCommand(ox,oy,x,y,c.getInternal()));
\r
287 command_mutex.Unlock();
\r