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 Colour& 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 Colour& colour)
\r
239 rectangle(0, 0, area.w, area.h, colour);
\r
242 void Boxx::drawPara(const char* text, int x, int y, const Colour& colour)
\r
245 int lineHeight = getFontHeight() + paraVSpace;
\r
265 if (text[textPos] == '\0') break;
\r
267 if (text[textPos] == '\n')
\r
269 textPos++; // ignore the \n
\r
274 thisCharWidth = charWidth(text[textPos]);
\r
275 if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
\r
277 // this character would break the right margin
\r
278 if (text[textPos] == ' ')
\r
280 // this char is a space, ignore and break
\r
286 // Need to go back to the last space in the line
\r
287 while ((text[textPos] != ' ') && (linePos >= 0))
\r
292 // Now take the space we just found
\r
297 line[linePos++] = text[textPos];
\r
298 lineWidth += thisCharWidth;
\r
302 // line[linePos++] = '\0';
\r
303 if (linePos>=0) line[linePos++] = '\0'; //Here is the change
\r
305 if (printLine || (linePos > 1)) // if some text was put in line
\r
307 drawText(line, x, ypos, colour);
\r
308 ypos += lineHeight;
\r
309 if (ypos > (int)(area.h - lineHeight)) break;
\r
318 void Boxx::rectangle(Region& region, const Colour& colour)
\r
320 rectangle(region.x, region.y, region.w, region.h, colour);
\r
323 // Level 0 drawing functions
\r
325 void Boxx::rectangle(UINT x, UINT y, UINT w, UINT h, const Colour& colour)
\r
327 if (parent) parent->rectangle(area.x + x, area.y + y, w, h, colour);
\r
328 else surface->fillblt(x, y, w, h, colour.rgba());
\r
331 void Boxx::drawText(const char* text, int x, int y, const Colour& colour)
\r
333 if (parent) parent->drawText(text, area.x + x, area.y + y, colour);
\r
334 else surface->drawText(text, x, y, colour.rgba());
\r
337 void Boxx::drawText(const char* text, int x, int y, int width, const Colour& colour)
\r
339 if (parent) parent->drawText(text, area.x + x, area.y + y, width, colour);
\r
340 else surface->drawText(text, x, y, width, colour.rgba());
\r
343 void Boxx::drawTextRJ(const char* text, int x, int y, const Colour& colour)
\r
345 if (parent) parent->drawTextRJ(text, area.x + x, area.y + y, colour);
\r
346 else surface->drawTextRJ(text, x, y, colour.rgba());
\r
349 void Boxx::drawTextCentre(const char* text, int x, int y, const Colour& colour)
\r
351 if (parent) parent->drawTextCentre(text, area.x + x, area.y + y, colour);
\r
352 else surface->drawTextCentre(text, x, y, colour.rgba());
\r
355 void Boxx::drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw)
\r
357 if (parent) parent->drawPixelAlpha(area.x + x, area.y + y, colour,fastdraw);
\r
360 int c = ( (colour.alpha << 24 )
\r
361 | (colour.red << 16)
\r
362 | (colour.green << 8)
\r
363 | (colour.blue ) );
\r
365 surface->drawPixel(x, y, c,fastdraw);
\r
369 void Boxx::drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw)
\r
371 if (parent) parent->drawPixel(area.x + x, area.y + y, colour,fastdraw);
\r
374 int c = ( (0xFF000000 )
\r
375 | (colour.red << 16)
\r
376 | (colour.green << 8)
\r
377 | (colour.blue ) );
\r
379 surface->drawPixel(x, y, c,fastdraw);
\r
383 void Boxx::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c)
\r
385 if (parent) parent->drawTTChar(area.x + ox, area.y + oy, x,y,c);
\r
386 else if (surface) surface->drawTTChar(ox, oy,x,y,c);
\r
390 void Boxx::drawBitmap(UINT x, UINT y, const Bitmap& bm)
\r
392 if (parent) parent->drawBitmap(area.x + x, area.y + y, bm);
\r
393 else if (surface) surface->drawBitmap(x, y, bm);
\r
396 void Boxx::drawJpeg(const char *fileName,int x, int y,int *width, int *height)
\r
398 if (parent) parent->drawJpeg(fileName,area.x +x,area.y +y,width,height);
\r
399 else if (surface) surface->drawJpeg(fileName,x,y,width,height);
\r
402 int Boxx::getFontHeight()
\r
404 if (parent) return parent->getFontHeight();
\r
405 else if (surface) return surface->getFontHeight();
\r
409 void Boxx::startFastDraw()
\r
411 if (parent) parent->startFastDraw();
\r
414 if (surface) surface->startFastDraw();
\r
418 void Boxx::endFastDraw()
\r
420 if (parent) parent->endFastDraw();
\r
423 if (surface) surface->endFastDraw();
\r
428 int Boxx::charWidth(char c)
\r
430 if (parent) return parent->charWidth(c);
\r
431 else if (surface) return surface->getCharWidth(c);
\r
432 else return 10; //?
\r
435 Surface * Boxx::getSurface() {
\r
436 if (parent) return parent->getSurface();
\r