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