2 Copyright 2007 Chris Tallon
\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
27 char Boxx::numBoxxes = 0;
\r
31 // I want a parent box or a surface.
\r
40 paraVSpace = 6; // default gap for drawPara
\r
42 backgroundColourSet = false;
\r
46 Log::getInstance()->log("Boxx", Log::DEBUG, "Construct, now %u", numBoxxes);
\r
51 if (surface) delete surface;
\r
53 Log::getInstance()->log("Boxx", Log::DEBUG, "Destruct, now %u", numBoxxes);
\r
58 //Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p", this, surface);
\r
59 if (backgroundColourSet) fillColour(backgroundColour);
\r
62 vector<Boxx*>::iterator j;
\r
64 for (j = children.begin(); j != children.end(); j++)
\r
67 // Log::getInstance()->log("Boxx", Log::DEBUG, "Draw child %d %d", count,currentBoxx);
\r
68 if (currentBoxx->getVisible()) currentBoxx->draw();
\r
71 // Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p End", this, surface);
\r
74 void Boxx::setSize(UINT w, UINT h)
\r
80 void Boxx::setPosition(UINT x, UINT y)
\r
86 void Boxx::createBuffer()
\r
88 surface = Osd::getInstance()->createNewSurface();
\r
89 surface->create(area.w, area.h);
\r
92 void Boxx::add(Boxx* newChild)
\r
94 newChild->setParent(this);
\r
95 children.push_back(newChild);
\r
98 void Boxx::remove(Boxx* oldChild)
\r
100 for(vector<Boxx*>::iterator i = children.begin(); i != children.end(); i++)
\r
102 if (*i == oldChild)
\r
108 Log::getInstance()->log("Boxx", Log::ERR, "Remove child box called, child %p not found", oldChild);
\r
111 void Boxx::setParent(Boxx* newParent)
\r
113 parent = newParent;
\r
116 void Boxx::setBackgroundColour(const DrawStyle& Tcolour)
\r
118 backgroundColour = Tcolour;
\r
119 backgroundColourSet = true;
\r
122 void Boxx::setVisible(bool isVisible)
\r
124 visible = isVisible;
\r
127 bool Boxx::getVisible()
\r
132 void Boxx::setGap(UINT gap)
\r
137 void Boxx::blt(Region& r)
\r
139 /* surface update to screen needs:
\r
140 source x distance into this surface
\r
141 source y distance into this surface
\r
144 destination x on screen
\r
145 destination y on screen
\r
148 if (parent) abort(); // if (parent) then this is a child boxx. It can not blt.
\r
150 // this shouldn't be here
\r
154 surface->updateToScreen(r.x, r.y, r.w, r.h, area.x + r.x, area.y + r.y);
\r
158 int Boxx::getScreenX()
\r
160 if (parent) return area.x + parent->getScreenX();
\r
164 int Boxx::getScreenY()
\r
166 if (parent) return area.y + parent->getScreenY();
\r
170 int Boxx::getRootBoxOffsetX() // convert this to be getX and silently do the parent/not thing? same for Y below?
\r
172 if (parent) return area.x + parent->getRootBoxOffsetX();
\r
176 int Boxx::getRootBoxOffsetY()
\r
178 if (parent) return area.y + parent->getRootBoxOffsetY();
\r
194 return area.x + area.w;
\r
199 return area.y + area.h;
\r
202 UINT Boxx::getWidth()
\r
207 UINT Boxx::getHeight()
\r
212 // FIXME Clean up the code to use just one of the following
\r
214 Region* Boxx::getRegion()
\r
219 Region Boxx::getRegionR()
\r
224 void Boxx::getRootBoxRegion(Region* r)
\r
226 // Returns a region that describes the position of this box on the box with the surface
\r
227 // To be used for boxstack->update calls
\r
229 r->x = getRootBoxOffsetX();
\r
230 r->y = getRootBoxOffsetY();
\r
235 // Level 1 drawing functions
\r
237 void Boxx::fillColour(const DrawStyle& colour)
\r
239 rectangle(0, 0, area.w, area.h, colour);
\r
242 void Boxx::drawPara(const char* text, int x, int y, const DrawStyle& colour)
\r
245 int lineHeight = getFontHeight() + paraVSpace;
\r
248 float thisCharWidth;
\r
264 unsigned int cur_length=1;
\r
265 wchar_t cur_char=getWChar(text+textPos,&cur_length);
\r
267 if (cur_char == '\0') break;
\r
269 if (cur_char == '\n')
\r
271 textPos+=cur_length; // ignore the \n
\r
275 thisCharWidth = charWidth(cur_char);
\r
276 if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
\r
278 // this character would break the right margin
\r
279 if (cur_char == ' ')
\r
281 // this char is a space, ignore and break
\r
282 textPos+=cur_length;
\r
287 // Need to go back to the last space in the line
\r
288 while ((cur_char != ' ') && (linePos >= 0))
\r
290 textPos-=cur_length;
\r
291 cur_char=getWChar(text+textPos,&cur_length);
\r
294 // Now take the space we just found
\r
295 textPos+=cur_length;
\r
299 for (int n=0;n<cur_length;n++) line[linePos++] = text[textPos+n];
\r
300 lineWidth += thisCharWidth;
\r
301 textPos+=cur_length;
\r
304 // line[linePos++] = '\0';
\r
305 if (linePos>=0) line[linePos++] = '\0'; //Here is the change
\r
307 if (printLine || (linePos > 1)) // if some text was put in line
\r
309 drawText(line, x, ypos, colour);
\r
310 ypos += lineHeight;
\r
311 if (ypos > (int)(area.h - lineHeight)) break;
\r
320 void Boxx::rectangle(Region& region, const DrawStyle& colour)
\r
322 rectangle(region.x, region.y, region.w, region.h, colour);
\r
325 // Level 0 drawing functions
\r
327 void Boxx::rectangle(UINT x, UINT y, UINT w, UINT h, const DrawStyle& colour)
\r
329 if (parent) parent->rectangle(area.x + x, area.y + y, w, h, colour);
\r
330 else surface->fillblt(x, y, w, h, colour);
\r
333 void Boxx::drawText(const char* text, int x, int y, const DrawStyle& colour)
\r
335 if (parent) parent->drawText(text, area.x + x, area.y + y, colour);
\r
336 else surface->drawText(text, x, y, colour);
\r
339 void Boxx::drawText(const char* text, int x, int y, int width, const DrawStyle& colour)
\r
341 if (parent) parent->drawText(text, area.x + x, area.y + y, width, colour);
\r
342 else surface->drawText(text, x, y, width, colour);
\r
345 void Boxx::drawTextRJ(const char* text, int x, int y, const DrawStyle& colour)
\r
347 if (parent) parent->drawTextRJ(text, area.x + x, area.y + y, colour);
\r
348 else surface->drawTextRJ(text, x, y, colour);
\r
351 void Boxx::drawTextCentre(const char* text, int x, int y, const DrawStyle& colour)
\r
353 if (parent) parent->drawTextCentre(text, area.x + x, area.y + y, colour);
\r
354 else surface->drawTextCentre(text, x, y, colour);
\r
358 void Boxx::drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw)
\r
360 if (parent) parent->drawPixelAlpha(area.x + x, area.y + y, colour,fastdraw);
\r
363 int c = ( (colour.alpha << 24 )
\r
364 | (colour.red << 16)
\r
365 | (colour.green << 8)
\r
366 | (colour.blue ) );
\r
368 surface->drawPixel(x, y, c,fastdraw);
\r
372 void Boxx::drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw)
\r
374 if (parent) parent->drawPixel(area.x + x, area.y + y, colour,fastdraw);
\r
377 int c = ( (0xFF000000 )
\r
378 | (colour.red << 16)
\r
379 | (colour.green << 8)
\r
380 | (colour.blue ) );
\r
382 surface->drawPixel(x, y, c,fastdraw);
\r
387 void Boxx::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c)
\r
389 if (parent) parent->drawTTChar(area.x + ox, area.y + oy, x,y,c);
\r
390 else if (surface) surface->drawTTChar(ox, oy,x,y,c);
\r
394 void Boxx::drawBitmap(UINT x, UINT y, const Bitmap& bm, const DisplayRegion & region)
\r
396 if (parent) parent->drawBitmap(area.x + x, area.y + y, bm, region);
\r
397 else if (surface) surface->drawBitmap(x, y, bm, region);
\r
400 void Boxx::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
\r
402 if (parent) parent->drawJpeg(fileName,area.x +x,area.y +y,width,height);
\r
403 else if (surface) surface->drawJpeg(fileName,x,y,width,height);
\r
406 void Boxx::drawMonoBitmap(UCHAR*base, int dx, int dy, unsigned int height,unsigned int width, Colour& nextColour)
\r
408 if (parent) parent->drawMonoBitmap(base, area.x +dx,area.y +dy, height,width, nextColour);
\r
409 else if (surface) surface->drawMonoBitmap(base, dx,dy, height,width, nextColour);
\r
412 int Boxx::getFontHeight()
\r
414 if (parent) return parent->getFontHeight();
\r
415 else if (surface) return surface->getFontHeight();
\r
419 void Boxx::startFastDraw()
\r
421 if (parent) parent->startFastDraw();
\r
424 if (surface) surface->startFastDraw();
\r
428 void Boxx::endFastDraw()
\r
430 if (parent) parent->endFastDraw();
\r
433 if (surface) surface->endFastDraw();
\r
438 float Boxx::charWidth(wchar_t c)
\r
440 if (parent) return parent->charWidth(c);
\r
441 else if (surface) return surface->getCharWidth(c);
\r
442 else return 16.; //?
\r
445 wchar_t Boxx::getWChar(const char* str, unsigned int *length)
\r
447 if (parent) return parent->getWChar(str,length);
\r
448 else if (surface) return surface->getWChar(str,length);
\r
449 else return '?'; //?
\r
452 Surface * Boxx::getSurface() {
\r
453 if (parent) return parent->getSurface();
\r