2 Copyright 2004-2005 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
23 char Box::numBoxes = 0;
35 gap = 6; // default gap for drawPara
38 Log::getInstance()->log("Box", Log::DEBUG, "Construct, now %u", numBoxes);
46 Log::getInstance()->log("Box", Log::DEBUG, "Destruct, now %u", numBoxes);
53 void Box::setScreenPos(int x, int y)
59 void Box::setSurfaceOffset(UINT x, UINT y)
65 void Box::setGap(UINT tgap)
75 void Box::blt(Region& r)
77 Log::getInstance()->log("Box", Log::DEBUG, "Show region %p %u %u %u %u", surface, r.x, r.y, r.w, r.h);
78 // surface->updateToScreen(area.x, area.y, area.w, area.h);
80 /* surface update to screen needs:
81 source x distance into this surface
82 source y distance into this surface
85 destination x on screen
86 destination y on screen
89 surface->updateToScreen(r.x - area.x, r.y - area.y, r.w, r.h, r.x, r.y);
112 // Level 1 drawing functions
114 void Box::fillColour(Colour& colour)
116 rectangle(0, 0, area.w, area.h, colour);
119 void Box::drawPara(char* text, int x, int y, Colour& colour)
122 int lineHeight = surface->getFontHeight() + gap;
142 if (text[textPos] == '\0') break;
144 if (text[textPos] == '\n')
146 textPos++; // ignore the \n
151 thisCharWidth = surface->getCharWidth(text[textPos]);
152 if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
154 // this character would break the right margin
155 if (text[textPos] == ' ')
157 // this char is a space, ignore and break
163 // Need to go back to the last space in the line
164 while ((text[textPos] != ' ') && (linePos >= 0))
169 // Now take the space we just found
174 line[linePos++] = text[textPos];
175 lineWidth += thisCharWidth;
179 line[linePos++] = '\0';
180 if (printLine || (linePos > 1)) // if some text was put in line
182 drawText(line, x, ypos, colour);
184 if (ypos > (int)(area.h - lineHeight)) break;
193 // Level 0 drawing functions
195 void Box::rectangle(int x1, int y1, int w, int h, Colour& colour)
197 surface->fillblt(offsetX + x1, offsetY + y1, w, h, surface->rgba(colour.red, colour.green, colour.blue, colour.alpha));
200 void Box::drawText(char* text, int x, int y, Colour& colour)
202 surface->drawText(text, offsetX + x, offsetY + y, colour.red, colour.green, colour.blue);
205 void Box::drawTextRJ(char* text, int x, int y, Colour& colour)
207 surface->drawTextRJ(text, offsetX + x, offsetY + y, colour.red, colour.green, colour.blue);
210 void Box::drawTextCentre(char* text, int x, int y, Colour& colour)
212 surface->drawTextCentre(text, offsetX + x, offsetY + y, colour.red, colour.green, colour.blue);
215 void Box::drawPixel(UINT x, UINT y, Colour& colour)
217 int c = ( (0xFF000000 )
219 | (colour.green << 8)
223 surface->drawPixel(offsetX + x, offsetY + y, c);