]> git.vomp.tv Git - vompclient.git/blob - box.cc
More EPG tweaks, fix a freeze changing to a non-transmitting channel
[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   area.x = 0;
28   area.y = 0;
29   area.w = 0;
30   area.h = 0;
31
32   offsetX = 0;
33   offsetY = 0;
34
35   gap = 6; // default gap for drawPara
36
37   numBoxes++;
38   Log::getInstance()->log("Box", Log::DEBUG, "Construct, now %u", numBoxes);
39
40   surface = NULL;
41 }
42
43 Box::~Box()
44 {
45   numBoxes--;
46   Log::getInstance()->log("Box", Log::DEBUG, "Destruct, now %u", numBoxes);
47 }
48
49 void Box::draw()
50 {
51 }
52
53 void Box::setScreenPos(int x, int y)
54 {
55   area.x = x;
56   area.y = y;
57 }
58
59 void Box::setSurfaceOffset(UINT x, UINT y)
60 {
61   offsetX = x;
62   offsetY = y;
63 }
64
65 void Box::setGap(UINT tgap)
66 {
67   gap = tgap;
68 }
69
70 void Box::show()
71 {
72   blt(area);
73 }
74
75 void Box::blt(Region& r)
76 {
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);
79
80   /* surface update to screen needs:
81   source x distance into this surface
82   source y distance into this surface
83   width of update
84   height of update
85   destination x on screen
86   destination y on screen
87   */
88
89   surface->updateToScreen(r.x - area.x, r.y - area.y, r.w, r.h, r.x, r.y);
90 }
91
92 int Box::getScreenX()
93 {
94   return area.x;
95 }
96
97 int Box::getScreenY()
98 {
99   return area.y;
100 }
101
102 int Box::getWidth()
103 {
104   return area.w;
105 }
106
107 int Box::getHeight()
108 {
109   return area.h;
110 }
111
112 // Level 1 drawing functions
113
114 void Box::fillColour(Colour& colour)
115 {
116   rectangle(0, 0, area.w, area.h, colour);
117 }
118
119 void Box::drawPara(char* text, int x, int y, Colour& colour)
120 {
121   char line[256];
122   int lineHeight = surface->getFontHeight() + gap;
123
124   int lineWidth;
125   int thisCharWidth;
126   int textPos;
127   int linePos;
128   int ypos;
129   int printLine;
130
131   textPos = 0;
132   ypos = y;
133
134   while(1)
135   {
136     linePos = 0;
137     lineWidth = 0;
138     while(1)
139     {
140       printLine = 0;
141
142       if (text[textPos] == '\0') break;
143
144       if (text[textPos] == '\n')
145       {
146         textPos++; // ignore the \n
147         printLine = 1;
148         break;
149       }
150
151       thisCharWidth = surface->getCharWidth(text[textPos]);
152       if ((lineWidth + thisCharWidth) > (int)(area.w - (2 * paraMargin)))
153       {
154         // this character would break the right margin
155         if (text[textPos] == ' ')
156         {
157           // this char is a space, ignore and break
158           textPos++;
159           break;
160         }
161         else
162         {
163           // Need to go back to the last space in the line
164           while ((text[textPos] != ' ') && (linePos >= 0))
165           {
166             textPos--;
167             linePos--;
168           }
169           // Now take the space we just found
170           textPos++;
171           break;
172         }
173       }
174       line[linePos++] = text[textPos];
175       lineWidth += thisCharWidth;
176       textPos++;
177     }
178
179     line[linePos++] = '\0';
180     if (printLine || (linePos > 1)) // if some text was put in line
181     {
182       drawText(line, x, ypos, colour);
183       ypos += lineHeight;
184       if (ypos > (int)(area.h - lineHeight)) break;
185     }
186     else
187     {
188       break;
189     }
190   }
191 }
192
193 // Level 0 drawing functions
194
195 void Box::rectangle(int x1, int y1, int w, int h, Colour& colour)
196 {
197   surface->fillblt(offsetX + x1, offsetY + y1, w, h, surface->rgba(colour.red, colour.green, colour.blue, colour.alpha));
198 }
199
200 void Box::drawText(char* text, int x, int y, Colour& colour)
201 {
202   surface->drawText(text, offsetX + x, offsetY + y, colour.red, colour.green, colour.blue);
203 }
204
205 void Box::drawTextRJ(char* text, int x, int y, Colour& colour)
206 {
207   surface->drawTextRJ(text, offsetX + x, offsetY + y, colour.red, colour.green, colour.blue);
208 }
209
210 void Box::drawTextCentre(char* text, int x, int y, Colour& colour)
211 {
212   surface->drawTextCentre(text, offsetX + x, offsetY + y, colour.red, colour.green, colour.blue);
213 }
214
215 void Box::drawPixel(UINT x, UINT y, Colour& colour)
216 {
217   int c = (  (0xFF000000        )
218              | (colour.red  << 16)
219              | (colour.green  <<  8)
220              | (colour.blue     ) );
221
222
223   surface->drawPixel(offsetX + x, offsetY + y, c);
224 }