]> git.vomp.tv Git - vompclient.git/blob - box.cc
Channel schedules in live banner
[vompclient.git] / box.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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
19 */
20
21 #include "box.h"
22
23 char Box::numBoxes = 0;
24
25 Box::Box()
26 {
27   height = 0;
28   width = 0;
29   screenX = 0;
30   screenY = 0;
31
32   numBoxes++;
33   Log::getInstance()->log("Box", Log::DEBUG, "Construct, now %u", numBoxes);
34
35   surface = Surface::getObject(Surface::BUFFER);
36 }
37
38 Box::~Box()
39 {
40   numBoxes--;
41   Log::getInstance()->log("Box", Log::DEBUG, "Destruct, now %u", numBoxes);
42 }
43
44 void Box::draw()
45 {
46 }
47
48 void Box::setDimensions(int w, int h)
49 {
50   width = w;
51   height = h;
52 }
53
54 void Box::setScreenPos(int x, int y)
55 {
56   screenX = x;
57   screenY = y;
58 }
59
60 void Box::show()
61 {
62   Log::getInstance()->log("Box", Log::DEBUG, "Show data %u %u %u %u", screenX, screenY, width, height);
63   surface->updateToScreen(screenX, screenY, width, height);
64 }
65
66 void Box::showAll()
67 {
68   Surface::bufferToScreen();
69 }
70
71 int Box::getScreenX()
72 {
73   return screenX;
74 }
75
76 int Box::getScreenY()
77 {
78   return screenY;
79 }
80
81 int Box::getWidth()
82 {
83   return width;
84 }
85
86 int Box::getHeight()
87 {
88   return height;
89 }
90
91 // Level 1 drawing functions
92
93 void Box::fillColour(Colour& colour)
94 {
95   rectangle(0, 0, width, height, colour);
96 }
97
98 void Box::drawPara(char* text, int x, int y, Colour& colour)
99 {
100   char line[256];
101   int lineHeight = surface->getFontHeight() + 6;
102
103   int lineWidth;
104   int thisCharWidth;
105   int textPos;
106   int linePos;
107   int ypos;
108   int printLine;
109
110   textPos = 0;
111   ypos = y;
112
113   while(1)
114   {
115     linePos = 0;
116     lineWidth = 0;
117     while(1)
118     {
119       printLine = 0;
120
121       if (text[textPos] == '\0') break;
122
123       if (text[textPos] == '\n')
124       {
125         textPos++; // ignore the \n
126         printLine = 1;
127         break;
128       }
129
130       thisCharWidth = surface->getCharWidth(text[textPos]);
131       if ((lineWidth + thisCharWidth) > (width - (2 * paraMargin)))
132       {
133         // this character would break the right margin
134         if (text[textPos] == ' ')
135         {
136           // this char is a space, ignore and break
137           textPos++;
138           break;
139         }
140         else
141         {
142           // Need to go back to the last space in the line
143           while ((text[textPos] != ' ') && (linePos >= 0))
144           {
145             textPos--;
146             linePos--;
147           }
148           // Now take the space we just found
149           textPos++;
150           break;
151         }
152       }
153       line[linePos++] = text[textPos];
154       lineWidth += thisCharWidth;
155       textPos++;
156     }
157
158     line[linePos++] = '\0';
159     if (printLine || (linePos > 1)) // if some text was put in line
160     {
161       drawText(line, x, ypos, colour);
162       ypos += lineHeight;
163       if (ypos > (height - lineHeight)) break;
164     }
165     else
166     {
167       break;
168     }
169   }
170 }
171
172 // Level 0 drawing functions
173
174 void Box::rectangle(int x1, int y1, int width, int height, Colour& colour)
175 {
176   surface->fillblt(screenX + x1, screenY + y1, width, height, surface->rgba(colour.red, colour.green, colour.blue, colour.alpha));
177 }
178
179 void Box::drawText(char* text, int x, int y, Colour& colour)
180 {
181   surface->drawText(text, screenX + x, screenY + y, colour.red, colour.green, colour.blue);
182 }
183
184 void Box::drawTextRJ(char* text, int x, int y, Colour& colour)
185 {
186   surface->drawTextRJ(text, screenX + x, screenY + y, colour.red, colour.green, colour.blue);
187 }
188
189 void Box::drawPixel(int x, int y, Colour& colour)
190 {
191   int c;
192         c = (  (0xFF000000        )
193              | (colour.red  << 16)
194              | (colour.green  <<  8)
195              | (colour.blue     ) );
196
197
198   surface->drawPixel(screenX + x, screenY + y, c);
199 }