2 Copyright 2007 Chris Tallon
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.
29 #include "surfacevector.h"
30 char Boxx::numBoxxes = 0;
34 // I want a parent box or a surface.
45 paraVSpace = 6; // default gap for drawPara
47 backgroundColourSet = false;
51 Log::getInstance()->log("Boxx", Log::DEBUG, "Construct, now %u", numBoxxes);
56 if (surface) delete surface;
58 Log::getInstance()->log("Boxx", Log::DEBUG, "Destruct, now %u", numBoxxes);
63 //Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p", this, surface);
64 if (backgroundColourSet) fillColour(backgroundColour);
67 vector<Boxx*>::iterator j;
69 for (j = children.begin(); j != children.end(); j++)
72 // Log::getInstance()->log("Boxx", Log::DEBUG, "Draw child %d %d", count,currentBoxx);
73 if (currentBoxx->getVisible()) currentBoxx->draw();
76 // Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p End", this, surface);
79 void Boxx::setSize(UINT w, UINT h)
85 void Boxx::setPosition(UINT x, UINT y)
91 void Boxx::createBuffer()
93 surface = Osd::getInstance()->createNewSurface();
94 surface->create(area.w, area.h);
97 void Boxx::add(Boxx* newChild)
99 newChild->setParent(this);
100 children.push_back(newChild);
103 void Boxx::remove(Boxx* oldChild)
105 for(vector<Boxx*>::iterator i = children.begin(); i != children.end(); i++)
113 Log::getInstance()->log("Boxx", Log::ERR, "Remove child box called, child %p not found", oldChild);
116 bool Boxx::overlapsVisibleChilds(Region & r)
118 for(vector<Boxx*>::iterator i = children.begin(); i != children.end(); i++)
120 if ((*i)->getVisible() && r.intersects((*i)->getRegionR()))
128 void Boxx::setParent(Boxx* newParent)
133 void Boxx::setBackgroundColour(const DrawStyle& Tcolour)
135 backgroundColour = Tcolour;
136 backgroundColourSet = true;
139 void Boxx::setVideoBackground()
141 vdisplay.mode=Window;
142 vdisplay.fallbackMode=Fullscreen;
143 vdisplay.x=getScreenX();
144 vdisplay.y=getScreenY();
145 vdisplay.width=getWidth();
146 vdisplay.height=getHeight();
149 void Boxx::setVisible(bool isVisible)
154 bool Boxx::getVisible()
159 void Boxx::setGap(UINT gap)
164 void Boxx::blt(Region& r)
166 /* surface update to screen needs:
167 source x distance into this surface
168 source y distance into this surface
171 destination x on screen
172 destination y on screen
175 if (parent) abort(); // if (parent) then this is a child boxx. It can not blt.
177 // this shouldn't be here
181 surface->updateToScreen(r.x, r.y, r.w, r.h, area.x + r.x, area.y + r.y);
185 int Boxx::getScreenX()
187 if (parent) return area.x + parent->getScreenX();
191 int Boxx::getScreenY()
193 if (parent) return area.y + parent->getScreenY();
197 int Boxx::getRootBoxOffsetX() // convert this to be getX and silently do the parent/not thing? same for Y below?
199 if (parent) return area.x + parent->getRootBoxOffsetX();
203 int Boxx::getRootBoxOffsetY()
205 if (parent) return area.y + parent->getRootBoxOffsetY();
221 return area.x + area.w;
226 return area.y + area.h;
229 UINT Boxx::getWidth()
234 UINT Boxx::getHeight()
239 // FIXME Clean up the code to use just one of the following
241 Region* Boxx::getRegion()
246 Region Boxx::getRegionR()
251 void Boxx::getRootBoxRegion(Region* r)
253 // Returns a region that describes the position of this box on the box with the surface
254 // To be used for boxstack->update calls
256 r->x = getRootBoxOffsetX();
257 r->y = getRootBoxOffsetY();
262 bool Boxx::getVideoDisplay(VideoDisplay &vd)
264 for(vector<Boxx*>::iterator i = children.begin(); i != children.end(); i++)
266 if ((*i)->getVideoDisplay(vd)) return true;
269 if (vdisplay.mode==None) return false;
274 // Level 1 drawing functions
276 void Boxx::fillColour(const DrawStyle& colour)
278 rectangle(0, 0, area.w, area.h, colour);
281 int Boxx::drawPara(const char* text, int x, int y, const DrawStyle& colour,unsigned int skiplines)
284 int lineHeight = getFontHeight() + paraVSpace;
294 int drawLinePos=-skiplines;
299 tester.h = lineHeight;
301 bool haschildren = true;
302 if ( children.size() == 0) haschildren = false;
313 wchar_t cur_char = getWChar(text + textPos, &cur_length);
315 if (cur_char == '\0') break;
317 if (cur_char == '\n')
319 textPos += cur_length; // ignore the \n
323 thisCharWidth = charWidth(cur_char);
324 tester.x = lineWidth + x;
325 tester.w = thisCharWidth + 10;
327 if ((lineWidth + thisCharWidth + x) > (int)(area.w - (2 * paraMargin))
328 || (haschildren && overlapsVisibleChilds(tester)))
330 // this character would break the right margin
333 // this char is a space, ignore and break
334 textPos += cur_length;
339 // Need to go back to the last space in the line
340 while ((cur_char != ' ') && (linePos >= 0))
342 textPos -= cur_length;
343 cur_char = getWChar(text + textPos, &cur_length);
346 // Now take the space we just found
347 textPos += cur_length;
351 for (UINT n = 0; n < cur_length; n++) line[linePos++] = text[textPos + n];
352 lineWidth += thisCharWidth;
353 textPos += cur_length;
356 // line[linePos++] = '\0';
357 if (linePos >= 0) line[linePos++] = '\0'; //Here is the change
359 if (printLine || (linePos > 1)) // if some text was put in line
361 if (ypos <= (int)(area.h - lineHeight + paraVSpace)) {
362 if (drawLinePos >= 0) {
363 drawText(line, x, ypos, colour);
379 void Boxx::rectangle(Region& region, const DrawStyle& colour)
381 rectangle(region.x, region.y, region.w, region.h, colour);
384 // Level 0 drawing functions
386 void Boxx::rectangle(UINT x, UINT y, UINT w, UINT h, const DrawStyle& colour)
388 if (parent) parent->rectangle(area.x + x, area.y + y, w, h, colour);
389 else surface->fillblt(x, y, w, h, colour);
392 void Boxx::drawText(const char* text, int x, int y, const DrawStyle& colour)
394 if (parent) parent->drawText(text, area.x + x, area.y + y, colour);
395 else surface->drawText(text, x, y, colour);
398 void Boxx::drawText(const char* text, int x, int y, int width, const DrawStyle& colour)
400 if (parent) parent->drawText(text, area.x + x, area.y + y, width, colour);
401 else surface->drawText(text, x, y, width, colour);
404 void Boxx::drawTextRJ(const char* text, int x, int y, const DrawStyle& colour)
406 if (parent) parent->drawTextRJ(text, area.x + x, area.y + y, colour);
407 else surface->drawTextRJ(text, x, y, colour);
410 void Boxx::drawTextCentre(const char* text, int x, int y, const DrawStyle& colour)
412 if (parent) parent->drawTextCentre(text, area.x + x, area.y + y, colour);
413 else surface->drawTextCentre(text, x, y, colour);
417 void Boxx::drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw)
419 if (parent) parent->drawPixelAlpha(area.x + x, area.y + y, colour,fastdraw);
422 int c = ( (colour.alpha << 24 )
424 | (colour.green << 8)
427 surface->drawPixel(x, y, c,fastdraw);
431 void Boxx::drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw)
433 if (parent) parent->drawPixel(area.x + x, area.y + y, colour,fastdraw);
436 int c = ( (0xFF000000 )
438 | (colour.green << 8)
441 surface->drawPixel(x, y, c,fastdraw);
446 void Boxx::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c)
448 if (parent) parent->drawTTChar(area.x + ox, area.y + oy, x,y,c);
449 else if (surface) surface->drawTTChar(ox, oy,x,y,c);
453 void Boxx::drawBitmap(UINT x, UINT y, const Bitmap& bm, const DisplayRegion & region)
455 if (parent) parent->drawBitmap(area.x + x, area.y + y, bm, region);
456 else if (surface) surface->drawBitmap(x, y, bm, region);
459 void Boxx::drawJpeg(const char *fileName, int x, int y, int *width, int *height)
461 if (parent) parent->drawJpeg(fileName, area.x + x, area.y + y, width, height);
462 else if (surface) surface->drawJpeg(fileName, x, y, width, height);
465 void Boxx::drawMonoBitmap(UCHAR*base, int dx, int dy, unsigned int height,unsigned int width, DrawStyle& nextColour)
467 if (parent) parent->drawMonoBitmap(base, area.x +dx, area.y + dy, height, width, nextColour);
468 else if (surface) surface->drawMonoBitmap(base, dx,dy, height, width, nextColour);
471 void Boxx::drawTVMedia(TVMediaInfo & tvmedia,float x, float y, float width, float height, Corner corner)
473 if (parent) parent->drawTVMedia(tvmedia,area.x + x,area.y + y,width, height, corner);
475 SurfaceVector * surfacevector=dynamic_cast<SurfaceVector*>(surface);
476 if (surfacevector) surfacevector->drawTVMedia(tvmedia,x, y,width, height, corner);
477 else surface->fillblt(x, y, width, height, DrawStyle::RED); // Signal that something went wrong
482 void Boxx::drawClippingRectangle(float x, float y, float w, float h)
484 if (parent) parent->drawClippingRectangle(area.x + x, area.y + y, w, h);
486 SurfaceVector * surfacevector=dynamic_cast<SurfaceVector*>(surface);
487 if (surfacevector) surfacevector->drawClippingRectangle(x, y, w, h);
492 int Boxx::getFontHeight()
494 if (parent) return parent->getFontHeight();
495 else if (surface) return surface->getFontHeight();
499 void Boxx::startFastDraw()
503 parent->startFastDraw();
507 if (surface) surface->startFastDraw();
511 void Boxx::endFastDraw()
515 parent->endFastDraw();
519 if (surface) surface->endFastDraw();
523 float Boxx::charWidth(wchar_t c)
525 if (parent) return parent->charWidth(c);
526 else if (surface) return surface->getCharWidth(c);
530 wchar_t Boxx::getWChar(const char* str, UINT *length)
532 if (parent) return parent->getWChar(str, length);
533 else if (surface) return surface->getWChar(str, length);
537 Surface* Boxx::getSurface()
539 if (parent) return parent->getSurface();