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 int Boxx::handleCommand(int x)
70 // A similar comment for this? FIXME make a commandreceiver thingy
74 void Boxx::processMessage(Message* m)
79 void Boxx::setSize(UINT w, UINT h)
85 void Boxx::setPosition(UINT x, UINT y)
91 void Boxx::createBuffer()
93 surface = new Surface_TYPE();
94 surface->create(area.w, area.h);
97 void Boxx::add(Boxx* newChild)
99 newChild->setParent(this);
100 children.push_back(newChild);
103 void Boxx::remove(Boxx* oldChild)
105 for(vector<Boxx*>::iterator i = children.begin(); i != children.end(); i++)
113 Log::getInstance()->log("Boxx", Log::ERR, "Remove child box called, child %p not found", oldChild);
116 void Boxx::setParent(Boxx* newParent)
121 void Boxx::setBackgroundColour(Colour& Tcolour)
123 backgroundColour = Tcolour;
124 backgroundColourSet = true;
127 void Boxx::setVisible(bool isVisible)
132 bool Boxx::getVisible()
137 void Boxx::setGap(UINT gap)
142 void Boxx::blt(Region& r)
144 /* surface update to screen needs:
145 source x distance into this surface
146 source y distance into this surface
149 destination x on screen
150 destination y on screen
155 printf("parent blt???\n");
160 // this shouldn't be here
164 surface->updateToScreen(r.x, r.y, r.w, r.h, area.x + r.x, area.y + r.y);
168 int Boxx::getScreenX()
170 if (parent) return area.x + parent->getScreenX();
174 int Boxx::getScreenY()
176 if (parent) return area.y + parent->getScreenY();
180 int Boxx::getRootBoxOffsetX() // convert this to be getX and silently do the parent/not thing? same for Y below?
182 if (parent) return area.x + parent->getRootBoxOffsetX();
186 int Boxx::getRootBoxOffsetY()
188 if (parent) return area.y + parent->getRootBoxOffsetY();
202 UINT Boxx::getWidth()
207 UINT Boxx::getHeight()
212 // Level 1 drawing functions
214 void Boxx::fillColour(Colour& colour)
216 rectangle(0, 0, area.w, area.h, colour);
219 void Boxx::drawPara(char* text, int x, int y, Colour& colour)
222 int lineHeight = surface->getFontHeight() + paraVSpace;
242 if (text[textPos] == '\0') break;
244 if (text[textPos] == '\n')
246 textPos++; // ignore the \n
251 thisCharWidth = surface->getCharWidth(text[textPos]);
252 if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
254 // this character would break the right margin
255 if (text[textPos] == ' ')
257 // this char is a space, ignore and break
263 // Need to go back to the last space in the line
264 while ((text[textPos] != ' ') && (linePos >= 0))
269 // Now take the space we just found
274 line[linePos++] = text[textPos];
275 lineWidth += thisCharWidth;
279 // line[linePos++] = '\0';
280 if (linePos>=0) line[linePos++] = '\0'; //Here is the change
282 if (printLine || (linePos > 1)) // if some text was put in line
284 drawText(line, x, ypos, colour);
286 if (ypos > (int)(area.h - lineHeight)) break;
295 void Boxx::rectangle(Region& region, Colour& colour)
297 rectangle(region.x, region.y, region.w, region.h, colour);
300 // Level 0 drawing functions
302 void Boxx::rectangle(UINT x, UINT y, UINT w, UINT h, Colour& colour)
304 if (parent) parent->rectangle(area.x + x, area.y + y, w, h, colour);
305 else surface->fillblt(x, y, w, h, colour.rgba());
308 void Boxx::drawText(const char* text, int x, int y, Colour& colour)
310 if (parent) parent->drawText(text, area.x + x, area.y + y, colour);
311 else surface->drawText(text, x, y, colour.rgba());
314 void Boxx::drawTextRJ(const char* text, int x, int y, Colour& colour)
316 if (parent) parent->drawTextRJ(text, area.x + x, area.y + y, colour);
317 else surface->drawTextRJ(text, x, y, colour.rgba());
320 void Boxx::drawTextCentre(const char* text, int x, int y, Colour& colour)
322 if (parent) parent->drawTextCentre(text, area.x + x, area.y + y, colour);
323 else surface->drawTextCentre(text, x, y, colour.rgba());
326 void Boxx::drawPixel(UINT x, UINT y, Colour& colour)
328 if (parent) parent->drawPixel(area.x + x, area.y + y, colour);
331 int c = ( (0xFF000000 )
333 | (colour.green << 8)
336 surface->drawPixel(x, y, c);
340 void Boxx::startFastDraw()
342 if (parent) parent->startFastDraw();
345 surface->startFastDraw();
349 void Boxx::endFastDraw()
351 if (parent) parent->endFastDraw();
354 surface->endFastDraw();
359 int Boxx::charWidth(char c)
361 if (parent) return parent->charWidth(c);
362 else return surface->getCharWidth(c);