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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 char Boxx::numBoxxes = 0;
29 // I want a parent box or a surface.
38 paraVSpace = 6; // default gap for drawPara
40 backgroundColourSet = false;
44 Log::getInstance()->log("Boxx", Log::DEBUG, "Construct, now %u", numBoxxes);
49 if (surface) delete surface;
51 Log::getInstance()->log("Boxx", Log::DEBUG, "Destruct, now %u", numBoxxes);
56 //Log::getInstance()->log("Boxx", Log::DEBUG, "Draw this %p surface %p", this, surface);
57 if (backgroundColourSet) fillColour(backgroundColour);
60 vector<Boxx*>::iterator j;
61 for (j = children.begin(); j != children.end(); j++)
64 if (currentBoxx->getVisible()) currentBoxx->draw();
68 void Boxx::setSize(UINT w, UINT h)
74 void Boxx::setPosition(UINT x, UINT y)
80 void Boxx::createBuffer()
82 surface = new Surface_TYPE();
83 surface->create(area.w, area.h);
86 void Boxx::add(Boxx* newChild)
88 newChild->setParent(this);
89 children.push_back(newChild);
92 void Boxx::remove(Boxx* oldChild)
94 for(vector<Boxx*>::iterator i = children.begin(); i != children.end(); i++)
102 Log::getInstance()->log("Boxx", Log::ERR, "Remove child box called, child %p not found", oldChild);
105 void Boxx::setParent(Boxx* newParent)
110 void Boxx::setBackgroundColour(Colour& Tcolour)
112 backgroundColour = Tcolour;
113 backgroundColourSet = true;
116 void Boxx::setVisible(bool isVisible)
121 bool Boxx::getVisible()
126 void Boxx::setGap(UINT gap)
131 void Boxx::blt(Region& r)
133 /* surface update to screen needs:
134 source x distance into this surface
135 source y distance into this surface
138 destination x on screen
139 destination y on screen
142 if (parent) abort(); // if (parent) then this is a child boxx. It can not blt.
144 // this shouldn't be here
148 surface->updateToScreen(r.x, r.y, r.w, r.h, area.x + r.x, area.y + r.y);
152 int Boxx::getScreenX()
154 if (parent) return area.x + parent->getScreenX();
158 int Boxx::getScreenY()
160 if (parent) return area.y + parent->getScreenY();
164 int Boxx::getRootBoxOffsetX() // convert this to be getX and silently do the parent/not thing? same for Y below?
166 if (parent) return area.x + parent->getRootBoxOffsetX();
170 int Boxx::getRootBoxOffsetY()
172 if (parent) return area.y + parent->getRootBoxOffsetY();
188 return area.x + area.w;
193 return area.y + area.h;
196 UINT Boxx::getWidth()
201 UINT Boxx::getHeight()
206 Region* Boxx::getRegion()
211 // Level 1 drawing functions
213 void Boxx::fillColour(Colour& colour)
215 rectangle(0, 0, area.w, area.h, colour);
218 void Boxx::drawPara(char* text, int x, int y, Colour& colour)
221 int lineHeight = surface->getFontHeight() + paraVSpace;
241 if (text[textPos] == '\0') break;
243 if (text[textPos] == '\n')
245 textPos++; // ignore the \n
250 thisCharWidth = surface->getCharWidth(text[textPos]);
251 if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
253 // this character would break the right margin
254 if (text[textPos] == ' ')
256 // this char is a space, ignore and break
262 // Need to go back to the last space in the line
263 while ((text[textPos] != ' ') && (linePos >= 0))
268 // Now take the space we just found
273 line[linePos++] = text[textPos];
274 lineWidth += thisCharWidth;
278 // line[linePos++] = '\0';
279 if (linePos>=0) line[linePos++] = '\0'; //Here is the change
281 if (printLine || (linePos > 1)) // if some text was put in line
283 drawText(line, x, ypos, colour);
285 if (ypos > (int)(area.h - lineHeight)) break;
294 void Boxx::rectangle(Region& region, Colour& colour)
296 rectangle(region.x, region.y, region.w, region.h, colour);
299 // Level 0 drawing functions
301 void Boxx::rectangle(UINT x, UINT y, UINT w, UINT h, Colour& colour)
303 if (parent) parent->rectangle(area.x + x, area.y + y, w, h, colour);
304 else surface->fillblt(x, y, w, h, colour.rgba());
307 void Boxx::drawText(const char* text, int x, int y, Colour& colour)
309 if (parent) parent->drawText(text, area.x + x, area.y + y, colour);
310 else surface->drawText(text, x, y, colour.rgba());
313 void Boxx::drawTextRJ(const char* text, int x, int y, Colour& colour)
315 if (parent) parent->drawTextRJ(text, area.x + x, area.y + y, colour);
316 else surface->drawTextRJ(text, x, y, colour.rgba());
319 void Boxx::drawTextCentre(const char* text, int x, int y, Colour& colour)
321 if (parent) parent->drawTextCentre(text, area.x + x, area.y + y, colour);
322 else surface->drawTextCentre(text, x, y, colour.rgba());
325 void Boxx::drawPixel(UINT x, UINT y, Colour& colour)
327 if (parent) parent->drawPixel(area.x + x, area.y + y, colour);
330 int c = ( (0xFF000000 )
332 | (colour.green << 8)
335 surface->drawPixel(x, y, c);
339 void Boxx::startFastDraw()
341 if (parent) parent->startFastDraw();
344 surface->startFastDraw();
348 void Boxx::endFastDraw()
350 if (parent) parent->endFastDraw();
353 surface->endFastDraw();
358 int Boxx::charWidth(char c)
360 if (parent) return parent->charWidth(c);
361 else return surface->getCharWidth(c);