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.
26 char Boxx::numBoxxes = 0;
30 // I want a parent box or a surface.
39 paraVSpace = 6; // default gap for drawPara
41 backgroundColourSet = false;
45 Log::getInstance()->log("Boxx", Log::DEBUG, "Construct, now %u", numBoxxes);
50 if (surface) delete surface;
52 Log::getInstance()->log("Boxx", Log::DEBUG, "Destruct, now %u", numBoxxes);
57 //Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p", this, surface);
58 if (backgroundColourSet) fillColour(backgroundColour);
61 vector<Boxx*>::iterator j;
62 for (j = children.begin(); j != children.end(); j++)
65 if (currentBoxx->getVisible()) currentBoxx->draw();
69 void Boxx::setSize(UINT w, UINT h)
75 void Boxx::setPosition(UINT x, UINT y)
81 void Boxx::createBuffer()
83 surface = new Surface_TYPE();
84 surface->create(area.w, area.h);
87 void Boxx::add(Boxx* newChild)
89 newChild->setParent(this);
90 children.push_back(newChild);
93 void Boxx::remove(Boxx* oldChild)
95 for(vector<Boxx*>::iterator i = children.begin(); i != children.end(); i++)
103 Log::getInstance()->log("Boxx", Log::ERR, "Remove child box called, child %p not found", oldChild);
106 void Boxx::setParent(Boxx* newParent)
111 void Boxx::setBackgroundColour(const Colour& Tcolour)
113 backgroundColour = Tcolour;
114 backgroundColourSet = true;
117 void Boxx::setVisible(bool isVisible)
122 bool Boxx::getVisible()
127 void Boxx::setGap(UINT gap)
132 void Boxx::blt(Region& r)
134 /* surface update to screen needs:
135 source x distance into this surface
136 source y distance into this surface
139 destination x on screen
140 destination y on screen
143 if (parent) abort(); // if (parent) then this is a child boxx. It can not blt.
145 // this shouldn't be here
149 surface->updateToScreen(r.x, r.y, r.w, r.h, area.x + r.x, area.y + r.y);
153 int Boxx::getScreenX()
155 if (parent) return area.x + parent->getScreenX();
159 int Boxx::getScreenY()
161 if (parent) return area.y + parent->getScreenY();
165 int Boxx::getRootBoxOffsetX() // convert this to be getX and silently do the parent/not thing? same for Y below?
167 if (parent) return area.x + parent->getRootBoxOffsetX();
171 int Boxx::getRootBoxOffsetY()
173 if (parent) return area.y + parent->getRootBoxOffsetY();
189 return area.x + area.w;
194 return area.y + area.h;
197 UINT Boxx::getWidth()
202 UINT Boxx::getHeight()
207 // FIXME Clean up the code to use just one of the following
209 Region* Boxx::getRegion()
214 Region Boxx::getRegionR()
219 void Boxx::getRootBoxRegion(Region* r)
221 // Returns a region that describes the position of this box on the box with the surface
222 // To be used for boxstack->update calls
224 r->x = getRootBoxOffsetX();
225 r->y = getRootBoxOffsetY();
230 // Level 1 drawing functions
232 void Boxx::fillColour(const Colour& colour)
234 rectangle(0, 0, area.w, area.h, colour);
237 void Boxx::drawPara(const char* text, int x, int y, const Colour& colour)
240 int lineHeight = surface->getFontHeight() + paraVSpace;
260 if (text[textPos] == '\0') break;
262 if (text[textPos] == '\n')
264 textPos++; // ignore the \n
269 thisCharWidth = surface->getCharWidth(text[textPos]);
270 if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
272 // this character would break the right margin
273 if (text[textPos] == ' ')
275 // this char is a space, ignore and break
281 // Need to go back to the last space in the line
282 while ((text[textPos] != ' ') && (linePos >= 0))
287 // Now take the space we just found
292 line[linePos++] = text[textPos];
293 lineWidth += thisCharWidth;
297 // line[linePos++] = '\0';
298 if (linePos>=0) line[linePos++] = '\0'; //Here is the change
300 if (printLine || (linePos > 1)) // if some text was put in line
302 drawText(line, x, ypos, colour);
304 if (ypos > (int)(area.h - lineHeight)) break;
313 void Boxx::rectangle(Region& region, const Colour& colour)
315 rectangle(region.x, region.y, region.w, region.h, colour);
318 // Level 0 drawing functions
320 void Boxx::rectangle(UINT x, UINT y, UINT w, UINT h, const Colour& colour)
322 if (parent) parent->rectangle(area.x + x, area.y + y, w, h, colour);
323 else surface->fillblt(x, y, w, h, colour.rgba());
326 void Boxx::drawText(const char* text, int x, int y, const Colour& colour)
328 if (parent) parent->drawText(text, area.x + x, area.y + y, colour);
329 else surface->drawText(text, x, y, colour.rgba());
332 void Boxx::drawText(const char* text, int x, int y, int width, const Colour& colour)
334 if (parent) parent->drawText(text, area.x + x, area.y + y, width, colour);
335 else surface->drawText(text, x, y, width, colour.rgba());
338 void Boxx::drawTextRJ(const char* text, int x, int y, const Colour& colour)
340 if (parent) parent->drawTextRJ(text, area.x + x, area.y + y, colour);
341 else surface->drawTextRJ(text, x, y, colour.rgba());
344 void Boxx::drawTextCentre(const char* text, int x, int y, const Colour& colour)
346 if (parent) parent->drawTextCentre(text, area.x + x, area.y + y, colour);
347 else surface->drawTextCentre(text, x, y, colour.rgba());
350 void Boxx::drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw)
352 if (parent) parent->drawPixelAlpha(area.x + x, area.y + y, colour,fastdraw);
355 int c = ( (colour.alpha << 24 )
357 | (colour.green << 8)
360 surface->drawPixel(x, y, c,fastdraw);
364 void Boxx::drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw)
366 if (parent) parent->drawPixel(area.x + x, area.y + y, colour,fastdraw);
369 int c = ( (0xFF000000 )
371 | (colour.green << 8)
374 surface->drawPixel(x, y, c,fastdraw);
377 void Boxx::drawBitmap(UINT x, UINT y, const Bitmap& bm)
379 if (parent) parent->drawBitmap(area.x + x, area.y + y, bm);
380 else surface->drawBitmap(x, y, bm);
383 void Boxx::startFastDraw()
385 if (parent) parent->startFastDraw();
388 surface->startFastDraw();
392 void Boxx::endFastDraw()
394 if (parent) parent->endFastDraw();
397 surface->endFastDraw();
402 int Boxx::charWidth(char c)
404 if (parent) return parent->charWidth(c);
405 else return surface->getCharWidth(c);
408 Surface * Boxx::getSurface() {
409 if (parent) return parent->getSurface();