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 char Boxx::numBoxxes = 0;
33 // I want a parent box or a surface.
42 paraVSpace = 6; // default gap for drawPara
44 backgroundColourSet = false;
48 Log::getInstance()->log("Boxx", Log::DEBUG, "Construct, now %u", numBoxxes);
53 if (surface) delete surface;
55 Log::getInstance()->log("Boxx", Log::DEBUG, "Destruct, now %u", numBoxxes);
60 //Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p", this, surface);
61 if (backgroundColourSet) fillColour(backgroundColour);
64 vector<Boxx*>::iterator j;
66 for (j = children.begin(); j != children.end(); j++)
69 // Log::getInstance()->log("Boxx", Log::DEBUG, "Draw child %d %d", count,currentBoxx);
70 if (currentBoxx->getVisible()) currentBoxx->draw();
73 // Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p End", this, surface);
76 void Boxx::setSize(UINT w, UINT h)
82 void Boxx::setPosition(UINT x, UINT y)
88 void Boxx::createBuffer()
90 surface = Osd::getInstance()->createNewSurface();
91 surface->create(area.w, area.h);
94 void Boxx::add(Boxx* newChild)
96 newChild->setParent(this);
97 children.push_back(newChild);
100 void Boxx::remove(Boxx* oldChild)
102 for(vector<Boxx*>::iterator i = children.begin(); i != children.end(); i++)
110 Log::getInstance()->log("Boxx", Log::ERR, "Remove child box called, child %p not found", oldChild);
113 void Boxx::setParent(Boxx* newParent)
118 void Boxx::setBackgroundColour(const DrawStyle& Tcolour)
120 backgroundColour = Tcolour;
121 backgroundColourSet = true;
124 void Boxx::setVisible(bool isVisible)
129 bool Boxx::getVisible()
134 void Boxx::setGap(UINT gap)
139 void Boxx::blt(Region& r)
141 /* surface update to screen needs:
142 source x distance into this surface
143 source y distance into this surface
146 destination x on screen
147 destination y on screen
150 if (parent) abort(); // if (parent) then this is a child boxx. It can not blt.
152 // this shouldn't be here
156 surface->updateToScreen(r.x, r.y, r.w, r.h, area.x + r.x, area.y + r.y);
160 int Boxx::getScreenX()
162 if (parent) return area.x + parent->getScreenX();
166 int Boxx::getScreenY()
168 if (parent) return area.y + parent->getScreenY();
172 int Boxx::getRootBoxOffsetX() // convert this to be getX and silently do the parent/not thing? same for Y below?
174 if (parent) return area.x + parent->getRootBoxOffsetX();
178 int Boxx::getRootBoxOffsetY()
180 if (parent) return area.y + parent->getRootBoxOffsetY();
196 return area.x + area.w;
201 return area.y + area.h;
204 UINT Boxx::getWidth()
209 UINT Boxx::getHeight()
214 // FIXME Clean up the code to use just one of the following
216 Region* Boxx::getRegion()
221 Region Boxx::getRegionR()
226 void Boxx::getRootBoxRegion(Region* r)
228 // Returns a region that describes the position of this box on the box with the surface
229 // To be used for boxstack->update calls
231 r->x = getRootBoxOffsetX();
232 r->y = getRootBoxOffsetY();
237 // Level 1 drawing functions
239 void Boxx::fillColour(const DrawStyle& colour)
241 rectangle(0, 0, area.w, area.h, colour);
244 void Boxx::drawPara(const char* text, int x, int y, const DrawStyle& colour)
247 int lineHeight = getFontHeight() + paraVSpace;
267 wchar_t cur_char = getWChar(text + textPos, &cur_length);
269 if (cur_char == '\0') break;
271 if (cur_char == '\n')
273 textPos += cur_length; // ignore the \n
277 thisCharWidth = charWidth(cur_char);
278 if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
280 // this character would break the right margin
283 // this char is a space, ignore and break
284 textPos += cur_length;
289 // Need to go back to the last space in the line
290 while ((cur_char != ' ') && (linePos >= 0))
292 textPos -= cur_length;
293 cur_char = getWChar(text + textPos, &cur_length);
296 // Now take the space we just found
297 textPos += cur_length;
301 for (UINT n = 0; n < cur_length; n++) line[linePos++] = text[textPos + n];
302 lineWidth += thisCharWidth;
303 textPos += cur_length;
306 // line[linePos++] = '\0';
307 if (linePos >= 0) line[linePos++] = '\0'; //Here is the change
309 if (printLine || (linePos > 1)) // if some text was put in line
311 drawText(line, x, ypos, colour);
313 if (ypos > (int)(area.h - lineHeight)) break;
322 void Boxx::rectangle(Region& region, const DrawStyle& colour)
324 rectangle(region.x, region.y, region.w, region.h, colour);
327 // Level 0 drawing functions
329 void Boxx::rectangle(UINT x, UINT y, UINT w, UINT h, const DrawStyle& colour)
331 if (parent) parent->rectangle(area.x + x, area.y + y, w, h, colour);
332 else surface->fillblt(x, y, w, h, colour);
335 void Boxx::drawText(const char* text, int x, int y, const DrawStyle& colour)
337 if (parent) parent->drawText(text, area.x + x, area.y + y, colour);
338 else surface->drawText(text, x, y, colour);
341 void Boxx::drawText(const char* text, int x, int y, int width, const DrawStyle& colour)
343 if (parent) parent->drawText(text, area.x + x, area.y + y, width, colour);
344 else surface->drawText(text, x, y, width, colour);
347 void Boxx::drawTextRJ(const char* text, int x, int y, const DrawStyle& colour)
349 if (parent) parent->drawTextRJ(text, area.x + x, area.y + y, colour);
350 else surface->drawTextRJ(text, x, y, colour);
353 void Boxx::drawTextCentre(const char* text, int x, int y, const DrawStyle& colour)
355 if (parent) parent->drawTextCentre(text, area.x + x, area.y + y, colour);
356 else surface->drawTextCentre(text, x, y, colour);
360 void Boxx::drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw)
362 if (parent) parent->drawPixelAlpha(area.x + x, area.y + y, colour,fastdraw);
365 int c = ( (colour.alpha << 24 )
367 | (colour.green << 8)
370 surface->drawPixel(x, y, c,fastdraw);
374 void Boxx::drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw)
376 if (parent) parent->drawPixel(area.x + x, area.y + y, colour,fastdraw);
379 int c = ( (0xFF000000 )
381 | (colour.green << 8)
384 surface->drawPixel(x, y, c,fastdraw);
389 void Boxx::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c)
391 if (parent) parent->drawTTChar(area.x + ox, area.y + oy, x,y,c);
392 else if (surface) surface->drawTTChar(ox, oy,x,y,c);
396 void Boxx::drawBitmap(UINT x, UINT y, const Bitmap& bm, const DisplayRegion & region)
398 if (parent) parent->drawBitmap(area.x + x, area.y + y, bm, region);
399 else if (surface) surface->drawBitmap(x, y, bm, region);
402 void Boxx::drawJpeg(const char *fileName, int x, int y, int *width, int *height)
404 if (parent) parent->drawJpeg(fileName, area.x + x, area.y + y, width, height);
405 else if (surface) surface->drawJpeg(fileName, x, y, width, height);
408 void Boxx::drawMonoBitmap(UCHAR*base, int dx, int dy, UINT height, UINT width, Colour& nextColour)
410 if (parent) parent->drawMonoBitmap(base, area.x +dx, area.y + dy, height, width, nextColour);
411 else if (surface) surface->drawMonoBitmap(base, dx,dy, height, width, nextColour);
414 int Boxx::getFontHeight()
416 if (parent) return parent->getFontHeight();
417 else if (surface) return surface->getFontHeight();
421 void Boxx::startFastDraw()
425 parent->startFastDraw();
429 if (surface) surface->startFastDraw();
433 void Boxx::endFastDraw()
437 parent->endFastDraw();
441 if (surface) surface->endFastDraw();
445 float Boxx::charWidth(wchar_t c)
447 if (parent) return parent->charWidth(c);
448 else if (surface) return surface->getCharWidth(c);
452 wchar_t Boxx::getWChar(const char* str, UINT *length)
454 if (parent) return parent->getWChar(str, length);
455 else if (surface) return surface->getWChar(str, length);
459 Surface* Boxx::getSurface()
461 if (parent) return parent->getSurface();