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.
43 paraVSpace = 6; // default gap for drawPara
45 backgroundColourSet = false;
49 Log::getInstance()->log("Boxx", Log::DEBUG, "Construct, now %u", numBoxxes);
54 if (surface) delete surface;
56 Log::getInstance()->log("Boxx", Log::DEBUG, "Destruct, now %u", numBoxxes);
61 //Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p", this, surface);
62 if (backgroundColourSet) fillColour(backgroundColour);
65 vector<Boxx*>::iterator j;
67 for (j = children.begin(); j != children.end(); j++)
70 // Log::getInstance()->log("Boxx", Log::DEBUG, "Draw child %d %d", count,currentBoxx);
71 if (currentBoxx->getVisible()) currentBoxx->draw();
74 // Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p End", this, surface);
77 void Boxx::setSize(UINT w, UINT h)
83 void Boxx::setPosition(UINT x, UINT y)
89 void Boxx::createBuffer()
91 surface = Osd::getInstance()->createNewSurface();
92 surface->create(area.w, area.h);
95 void Boxx::add(Boxx* newChild)
97 newChild->setParent(this);
98 children.push_back(newChild);
101 void Boxx::remove(Boxx* oldChild)
103 for(vector<Boxx*>::iterator i = children.begin(); i != children.end(); i++)
111 Log::getInstance()->log("Boxx", Log::ERR, "Remove child box called, child %p not found", oldChild);
114 void Boxx::setParent(Boxx* newParent)
119 void Boxx::setBackgroundColour(const DrawStyle& Tcolour)
121 backgroundColour = Tcolour;
122 backgroundColourSet = true;
125 void Boxx::setVisible(bool isVisible)
130 bool Boxx::getVisible()
135 void Boxx::setGap(UINT gap)
140 void Boxx::blt(Region& r)
142 /* surface update to screen needs:
143 source x distance into this surface
144 source y distance into this surface
147 destination x on screen
148 destination y on screen
151 if (parent) abort(); // if (parent) then this is a child boxx. It can not blt.
153 // this shouldn't be here
157 surface->updateToScreen(r.x, r.y, r.w, r.h, area.x + r.x, area.y + r.y);
161 int Boxx::getScreenX()
163 if (parent) return area.x + parent->getScreenX();
167 int Boxx::getScreenY()
169 if (parent) return area.y + parent->getScreenY();
173 int Boxx::getRootBoxOffsetX() // convert this to be getX and silently do the parent/not thing? same for Y below?
175 if (parent) return area.x + parent->getRootBoxOffsetX();
179 int Boxx::getRootBoxOffsetY()
181 if (parent) return area.y + parent->getRootBoxOffsetY();
197 return area.x + area.w;
202 return area.y + area.h;
205 UINT Boxx::getWidth()
210 UINT Boxx::getHeight()
215 // FIXME Clean up the code to use just one of the following
217 Region* Boxx::getRegion()
222 Region Boxx::getRegionR()
227 void Boxx::getRootBoxRegion(Region* r)
229 // Returns a region that describes the position of this box on the box with the surface
230 // To be used for boxstack->update calls
232 r->x = getRootBoxOffsetX();
233 r->y = getRootBoxOffsetY();
238 // Level 1 drawing functions
240 void Boxx::fillColour(const DrawStyle& colour)
242 rectangle(0, 0, area.w, area.h, colour);
245 int Boxx::drawPara(const char* text, int x, int y, const DrawStyle& colour,unsigned int skiplines)
248 int lineHeight = getFontHeight() + paraVSpace;
258 int drawLinePos=-skiplines;
271 wchar_t cur_char = getWChar(text + textPos, &cur_length);
273 if (cur_char == '\0') break;
275 if (cur_char == '\n')
277 textPos += cur_length; // ignore the \n
281 thisCharWidth = charWidth(cur_char);
282 if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
284 // this character would break the right margin
287 // this char is a space, ignore and break
288 textPos += cur_length;
293 // Need to go back to the last space in the line
294 while ((cur_char != ' ') && (linePos >= 0))
296 textPos -= cur_length;
297 cur_char = getWChar(text + textPos, &cur_length);
300 // Now take the space we just found
301 textPos += cur_length;
305 for (UINT n = 0; n < cur_length; n++) line[linePos++] = text[textPos + n];
306 lineWidth += thisCharWidth;
307 textPos += cur_length;
310 // line[linePos++] = '\0';
311 if (linePos >= 0) line[linePos++] = '\0'; //Here is the change
313 if (printLine || (linePos > 1)) // if some text was put in line
315 if (ypos <= (int)(area.h - lineHeight + paraVSpace)) {
316 if (drawLinePos >= 0) {
317 drawText(line, x, ypos, colour);
333 void Boxx::rectangle(Region& region, const DrawStyle& colour)
335 rectangle(region.x, region.y, region.w, region.h, colour);
338 // Level 0 drawing functions
340 void Boxx::rectangle(UINT x, UINT y, UINT w, UINT h, const DrawStyle& colour)
342 if (parent) parent->rectangle(area.x + x, area.y + y, w, h, colour);
343 else surface->fillblt(x, y, w, h, colour);
346 void Boxx::drawText(const char* text, int x, int y, const DrawStyle& colour)
348 if (parent) parent->drawText(text, area.x + x, area.y + y, colour);
349 else surface->drawText(text, x, y, colour);
352 void Boxx::drawText(const char* text, int x, int y, int width, const DrawStyle& colour)
354 if (parent) parent->drawText(text, area.x + x, area.y + y, width, colour);
355 else surface->drawText(text, x, y, width, colour);
358 void Boxx::drawTextRJ(const char* text, int x, int y, const DrawStyle& colour)
360 if (parent) parent->drawTextRJ(text, area.x + x, area.y + y, colour);
361 else surface->drawTextRJ(text, x, y, colour);
364 void Boxx::drawTextCentre(const char* text, int x, int y, const DrawStyle& colour)
366 if (parent) parent->drawTextCentre(text, area.x + x, area.y + y, colour);
367 else surface->drawTextCentre(text, x, y, colour);
371 void Boxx::drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw)
373 if (parent) parent->drawPixelAlpha(area.x + x, area.y + y, colour,fastdraw);
376 int c = ( (colour.alpha << 24 )
378 | (colour.green << 8)
381 surface->drawPixel(x, y, c,fastdraw);
385 void Boxx::drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw)
387 if (parent) parent->drawPixel(area.x + x, area.y + y, colour,fastdraw);
390 int c = ( (0xFF000000 )
392 | (colour.green << 8)
395 surface->drawPixel(x, y, c,fastdraw);
400 void Boxx::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c)
402 if (parent) parent->drawTTChar(area.x + ox, area.y + oy, x,y,c);
403 else if (surface) surface->drawTTChar(ox, oy,x,y,c);
407 void Boxx::drawBitmap(UINT x, UINT y, const Bitmap& bm, const DisplayRegion & region)
409 if (parent) parent->drawBitmap(area.x + x, area.y + y, bm, region);
410 else if (surface) surface->drawBitmap(x, y, bm, region);
413 void Boxx::drawJpeg(const char *fileName, int x, int y, int *width, int *height)
415 if (parent) parent->drawJpeg(fileName, area.x + x, area.y + y, width, height);
416 else if (surface) surface->drawJpeg(fileName, x, y, width, height);
419 void Boxx::drawMonoBitmap(UCHAR*base, int dx, int dy, unsigned int height,unsigned int width, DrawStyle& nextColour)
421 if (parent) parent->drawMonoBitmap(base, area.x +dx, area.y + dy, height, width, nextColour);
422 else if (surface) surface->drawMonoBitmap(base, dx,dy, height, width, nextColour);
425 void Boxx::drawTVMedia(TVMediaInfo & tvmedia,float x, float y, float width, float height, Corner corner)
427 if (parent) parent->drawTVMedia(tvmedia,area.x + x,area.y + y,width, height, corner);
429 SurfaceVector * surfacevector=dynamic_cast<SurfaceVector*>(surface);
430 if (surfacevector) surfacevector->drawTVMedia(tvmedia,x, y,width, height, corner);
431 else surface->fillblt(x, y, width, height, DrawStyle::RED); // Signal that something went wrong
436 void Boxx::drawClippingRectangle(float x, float y, float w, float h)
438 if (parent) parent->drawClippingRectangle(area.x + x, area.y + y, w, h);
440 SurfaceVector * surfacevector=dynamic_cast<SurfaceVector*>(surface);
441 if (surfacevector) surfacevector->drawClippingRectangle(x, y, w, h);
446 int Boxx::getFontHeight()
448 if (parent) return parent->getFontHeight();
449 else if (surface) return surface->getFontHeight();
453 void Boxx::startFastDraw()
457 parent->startFastDraw();
461 if (surface) surface->startFastDraw();
465 void Boxx::endFastDraw()
469 parent->endFastDraw();
473 if (surface) surface->endFastDraw();
477 float Boxx::charWidth(wchar_t c)
479 if (parent) return parent->charWidth(c);
480 else if (surface) return surface->getCharWidth(c);
484 wchar_t Boxx::getWChar(const char* str, UINT *length)
486 if (parent) return parent->getWChar(str, length);
487 else if (surface) return surface->getWChar(str, length);
491 Surface* Boxx::getSurface()
493 if (parent) return parent->getSurface();