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)
70 void Box::blt(Region& r)
72 // Log::getInstance()->log("Box", Log::DEBUG, "Show region %p %u %u %u %u", surface, r.x, r.y, r.w, r.h);
73 // surface->updateToScreen(area.x, area.y, area.w, area.h);
75 /* surface update to screen needs:
76 source x distance into this surface
77 source y distance into this surface
80 destination x on screen
81 destination y on screen
84 surface->updateToScreen(r.x - area.x, r.y - area.y, r.w, r.h, r.x, r.y);
107 // Level 1 drawing functions
109 void Box::fillColour(Colour& colour)
111 rectangle(0, 0, area.w, area.h, colour);
114 void Box::drawPara(char* text, int x, int y, Colour& colour)
117 int lineHeight = surface->getFontHeight() + gap;
137 if (text[textPos] == '\0') break;
139 if (text[textPos] == '\n')
141 textPos++; // ignore the \n
146 thisCharWidth = surface->getCharWidth(text[textPos]);
147 if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
149 // this character would break the right margin
150 if (text[textPos] == ' ')
152 // this char is a space, ignore and break
158 // Need to go back to the last space in the line
159 while ((text[textPos] != ' ') && (linePos >= 0))
164 // Now take the space we just found
169 line[linePos++] = text[textPos];
170 lineWidth += thisCharWidth;
174 // line[linePos++] = '\0';
175 if (linePos>=0) line[linePos++] = '\0'; //Here is the change
177 if (printLine || (linePos > 1)) // if some text was put in line
179 drawText(line, x, ypos, colour);
181 if (ypos > (int)(area.h - lineHeight)) break;
190 // Level 0 drawing functions
192 void Box::rectangle(int x1, int y1, int w, int h, Colour colour)
194 surface->fillblt(offsetX + x1, offsetY + y1, w, h, colour.rgba());
197 void Box::rectangle(Region& region, Colour& colour)
199 surface->fillblt(offsetX + region.x, offsetY + region.y, region.w, region.h, colour.rgba());
202 void Box::drawText(char* text, int x, int y, Colour& colour)
204 surface->drawText(text, offsetX + x, offsetY + y, colour.rgba());
207 void Box::drawTextRJ(char* text, int x, int y, Colour& colour)
209 surface->drawTextRJ(text, offsetX + x, offsetY + y, colour.rgba());
212 void Box::drawTextCentre(char* text, int x, int y, Colour& colour)
214 surface->drawTextCentre(text, offsetX + x, offsetY + y, colour.rgba());
217 void Box::drawPixel(UINT x, UINT y, Colour& colour)
219 int c = ( (0xFF000000 )
221 | (colour.green << 8)
225 surface->drawPixel(offsetX + x, offsetY + y, c);