]> git.vomp.tv Git - vompclient.git/blob - boxx.h
Fixed Scaling in Jpeg handling, add Subtitles handling for HD resolutions(untested...
[vompclient.git] / boxx.h
1 /*\r
2     Copyright 2004-2005 Chris Tallon\r
3 \r
4     This file is part of VOMP.\r
5 \r
6     VOMP is free software; you can redistribute it and/or modify\r
7     it under the terms of the GNU General Public License as published by\r
8     the Free Software Foundation; either version 2 of the License, or\r
9     (at your option) any later version.\r
10 \r
11     VOMP is distributed in the hope that it will be useful,\r
12     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14     GNU General Public License for more details.\r
15 \r
16     You should have received a copy of the GNU General Public License\r
17     along with VOMP; if not, write to the Free Software\r
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
19 */\r
20 \r
21 #ifndef BOXX_H\r
22 #define BOXX_H\r
23 \r
24 #include <stdio.h>\r
25 #include <vector>\r
26 \r
27 using namespace std;\r
28 \r
29 #include "colour.h"\r
30 #include "region.h"\r
31 #include "message.h"\r
32 \r
33 \r
34 #include "surface.h"\r
35 \r
36 class Bitmap;\r
37 \r
38 class Boxx\r
39 {\r
40   friend class Wwss;\r
41   public:\r
42     Boxx();\r
43     virtual ~Boxx();\r
44 \r
45     virtual void setSize(UINT w, UINT h);  // virtual? really?\r
46     void setPosition(UINT x, UINT y); // Set position on parent. Even numbers only!!!\r
47     void createBuffer(); // Make this a root view that goes in the BoxStack\r
48     virtual void draw();\r
49     \r
50     \r
51     void setGap(UINT gap);\r
52     void setBackgroundColour(const DrawStyle& colour);\r
53     void setVisible(bool isVisible);\r
54 \r
55 \r
56     // The following are supposed to be abstract functions\r
57     // However, it is useful to be able to make instances of Boxx\r
58     // Therefore the following stubs are provided.\r
59     virtual void preDelete() {}\r
60     virtual int handleCommand(int x) { return 0; }\r
61     virtual void processMessage(Message* m) {}\r
62     virtual bool mouseMove(int x, int y) { return false; }\r
63     virtual bool mouseLBDOWN(int x, int y) { return false; }\r
64     virtual bool mouseAndroidScroll(int x, int y,int sx, int sy) { return false; }\r
65     virtual void deactivateAllControls() {}\r
66 \r
67     /* preDelete \r
68     \r
69      I think it's functionally equivalent to e.g. delete timers in Boxx::preDelete\r
70      because the only place where a Boxx is deleted is in \r
71      BoxStack::remove. There is now a call in BoxStack::remove to Boxx::preDelete\r
72      The reason for this is to stop timercalls calling BoxStack::update at the\r
73      same time BoxStack::remove is locked trying to delete the Boxx\r
74     */\r
75 \r
76     // Get functions\r
77     int getScreenX();        // where is it on screen\r
78     int getScreenY();\r
79     int getRootBoxOffsetX(); // where is it relative to the top-parent in the boxstack\r
80     int getRootBoxOffsetY();\r
81     int getX();              // where is it relative to its parent\r
82     int getX2();             // .. and the right edge\r
83     int getY();\r
84     int getY2();\r
85     UINT getWidth();\r
86     UINT getHeight();\r
87     bool getVisible();\r
88     Region* getRegion();     // Not to be used for changing the region\r
89     Region getRegionR();     // Same but as an object\r
90     void getRootBoxRegion(Region*);\r
91     \r
92     // Drawing functions level 1\r
93     void fillColour(const DrawStyle & colour);\r
94     void drawPara(const char* text, int x, int y, const DrawStyle& colour);\r
95 \r
96     // Drawing functions level 0\r
97     void rectangle(UINT x, UINT y, UINT w, UINT h, const DrawStyle& colour);\r
98     void rectangle(Region& region, const DrawStyle& colour);\r
99 \r
100     void drawText(const char* text, int x, int y, const DrawStyle& colour);\r
101     void drawText(const char* text, int x, int y, int width, const DrawStyle& colour);\r
102     void drawTextRJ(const char* text, int x, int y, const DrawStyle& colour);\r
103     void drawTextCentre(const char* text, int x, int y, const DrawStyle& colour);\r
104     //Now deprecated\r
105     //void drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw=false);\r
106     void drawBitmap(UINT x, UINT y, const Bitmap& bm, const DisplayRegion & region);\r
107    //Now deprecated\r
108     // void drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw=false);\r
109     int getFontHeight();\r
110 \r
111     void drawJpeg(const char *fileName,int x, int y,int *width, int *height);\r
112 \r
113     void drawTTChar(int ox, int oy,int x, int y, cTeletextChar c);\r
114     void drawMonoBitmap(UCHAR*base, int dx, int dy, unsigned int height,unsigned int width, Colour& nextColour);\r
115 \r
116     /* This is for system which need a locking of the drawing surface to speed up drawing */\r
117     void startFastDraw();\r
118     void endFastDraw();\r
119 \r
120     float charWidth(wchar_t c);\r
121     wchar_t getWChar(const char* str, unsigned int *length);\r
122 \r
123     void add(Boxx*); // a boxx has a set of child boxxs\r
124     void remove(Boxx*);\r
125 \r
126     /*\r
127     The following function sets the child's parent pointer without adding the child to the children vector.\r
128     It's a hack (that should be deprecated?) to allow things like WSymbol to be created, do some drawing on\r
129     the surface and then be deleted again, leaving the drawing present.\r
130     A better design would be to create many WSymbols - one per symbol and leave them created - then the\r
131     automatic draw code will be able to redraw the symbols without all that code needing\r
132     to be in the derived boxx's draw method.\r
133     */    \r
134     void TEMPADD(Boxx* child) { child->setParent(this); }\r
135 \r
136   friend class BoxStack;\r
137   protected:\r
138     //get the surface this box is drawing to\r
139     Surface *getSurface();\r
140     Boxx* parent;\r
141     Region area;\r
142     vector<Boxx*> children;\r
143 \r
144     void setParent(Boxx*);    \r
145     void blt(Region& r);\r
146 \r
147     static const int paraMargin = 10;\r
148     UINT paraVSpace;\r
149 \r
150     DrawStyle backgroundColour;\r
151     bool backgroundColourSet;\r
152     bool visible;\r
153 \r
154     static char numBoxxes;\r
155     Surface* surface;\r
156 };\r
157 \r
158 #endif\r
159 \r
160 \r
161 /*\r
162 \r
163 New Boxx design\r
164 \r
165 It's "Boxx" because "Box" was already taken.\r
166 \r
167 BoxStack replaces Viewman and handles displaying a stack of root boxxs (boxxs with surfaces) on the screen.\r
168 \r
169 Boxx relaces Box, Widget and parts of View and represents a box with or without a surface.\r
170 Let's call a Boxx with a surface a root box, and a boxx without a surface a child box.\r
171 \r
172 A boxx with a surface (root) is like an old View and is handled by BoxStack.\r
173 A boxx without a surface (child) is like and old Widget and needs to be a child box of another boxx (root or not).\r
174 \r
175 Don't add a boxx with a surface to another boxx. That isn't the design.\r
176 \r
177 So, when you create a boxx, either that boxx calls createBuffer() on itself,\r
178 or some other box add()s the new box to itself.\r
179 \r
180 Root boxxs can overlap each other - this is managed by boxstack.\r
181 Child boxxs within a parent boxx do not overlap each other.\r
182 However, a grandchild box can overlap a child box (but must be entirely contained within the child box).\r
183 \r
184 TBBoxx replaces View but is now only a convenience class for the window dressing stuff. It isn't required anymore since\r
185 all the real work that view used to do is done in Boxx now.\r
186 \r
187 Obseleted classes: Box, View, Viewman, Widget, others?\r
188 No code outside boxx should talk about surfaces anymore. Hopefully.\r
189 \r
190 */\r
191 \r