]> git.vomp.tv Git - vompclient.git/blob - boxx.h
Initial import of patches for ARM/Android/Raspeberry pi
[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   public:\r
41     Boxx();\r
42     virtual ~Boxx();\r
43 \r
44     virtual void setSize(UINT w, UINT h);  // virtual? really?\r
45     void setPosition(UINT x, UINT y); // Set position on parent. Even numbers only!!!\r
46     void createBuffer(); // Make this a root view that goes in the BoxStack\r
47     virtual void draw();\r
48     \r
49     \r
50     void setGap(UINT gap);\r
51     void setBackgroundColour(const Colour& colour);\r
52     void setVisible(bool isVisible);\r
53 \r
54 \r
55     // The following are supposed to be abstract functions\r
56     // However, it is useful to be able to make instances of Boxx\r
57     // Therefore the following stubs are provided.\r
58     virtual void preDelete() {}\r
59     virtual int handleCommand(int x) { return 0; }\r
60     virtual void processMessage(Message* m) {}\r
61     virtual bool mouseMove(int x, int y) { return false; }\r
62     virtual bool mouseLBDOWN(int x, int y) { return false; }\r
63     virtual bool mouseAndroidScroll(int x, int y,int sx, int sy) { return false; }\r
64     virtual void deactivateAllControls() {}\r
65 \r
66     /* preDelete \r
67     \r
68      I think it's functionally equivalent to e.g. delete timers in Boxx::preDelete\r
69      because the only place where a Boxx is deleted is in \r
70      BoxStack::remove. There is now a call in BoxStack::remove to Boxx::preDelete\r
71      The reason for this is to stop timercalls calling BoxStack::update at the\r
72      same time BoxStack::remove is locked trying to delete the Boxx\r
73     */\r
74 \r
75     // Get functions\r
76     int getScreenX();        // where is it on screen\r
77     int getScreenY();\r
78     int getRootBoxOffsetX(); // where is it relative to the top-parent in the boxstack\r
79     int getRootBoxOffsetY();\r
80     int getX();              // where is it relative to its parent\r
81     int getX2();             // .. and the right edge\r
82     int getY();\r
83     int getY2();\r
84     UINT getWidth();\r
85     UINT getHeight();\r
86     bool getVisible();\r
87     Region* getRegion();     // Not to be used for changing the region\r
88     Region getRegionR();     // Same but as an object\r
89     void getRootBoxRegion(Region*);\r
90     \r
91     // Drawing functions level 1\r
92     void fillColour(const Colour& colour);\r
93     void drawPara(const char* text, int x, int y, const Colour& colour);\r
94 \r
95     // Drawing functions level 0\r
96     void rectangle(UINT x, UINT y, UINT w, UINT h, const Colour& colour);\r
97     void rectangle(Region& region, const Colour& colour);\r
98 \r
99     void drawText(const char* text, int x, int y, const Colour& colour);\r
100     void drawText(const char* text, int x, int y, int width, const Colour& colour);\r
101     void drawTextRJ(const char* text, int x, int y, const Colour& colour);\r
102     void drawTextCentre(const char* text, int x, int y, const Colour& colour);\r
103     void drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw=false);\r
104     void drawBitmap(UINT x, UINT y, const Bitmap& bm);\r
105     void drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw=false);\r
106     int getFontHeight();\r
107 \r
108     void drawJpeg(const char *fileName,int x, int y,int *width, int *height);\r
109 \r
110     void drawTTChar(int ox, int oy,int x, int y, cTeletextChar c);\r
111 \r
112     /* This is for system which need a locking of the drawing surface to speed up drawing */\r
113     void startFastDraw();\r
114     void endFastDraw();\r
115 \r
116     int charWidth(char c);\r
117 \r
118     void add(Boxx*); // a boxx has a set of child boxxs\r
119     void remove(Boxx*);\r
120 \r
121     /*\r
122     The following function sets the child's parent pointer without adding the child to the children vector.\r
123     It's a hack (that should be deprecated?) to allow things like WSymbol to be created, do some drawing on\r
124     the surface and then be deleted again, leaving the drawing present.\r
125     A better design would be to create many WSymbols - one per symbol and leave them created - then the\r
126     automatic draw code will be able to redraw the symbols without all that code needing\r
127     to be in the derived boxx's draw method.\r
128     */    \r
129     void TEMPADD(Boxx* child) { child->setParent(this); }\r
130 \r
131   friend class BoxStack;\r
132   protected:\r
133     //get the surface this box is drawing to\r
134     Surface *getSurface();\r
135     Boxx* parent;\r
136     Region area;\r
137     vector<Boxx*> children;\r
138 \r
139     void setParent(Boxx*);    \r
140     void blt(Region& r);\r
141 \r
142     static const int paraMargin = 10;\r
143     UINT paraVSpace;\r
144 \r
145     Colour backgroundColour;\r
146     bool backgroundColourSet;\r
147     bool visible;\r
148 \r
149     static char numBoxxes;\r
150     Surface* surface;\r
151 };\r
152 \r
153 #endif\r
154 \r
155 \r
156 /*\r
157 \r
158 New Boxx design\r
159 \r
160 It's "Boxx" because "Box" was already taken.\r
161 \r
162 BoxStack replaces Viewman and handles displaying a stack of root boxxs (boxxs with surfaces) on the screen.\r
163 \r
164 Boxx relaces Box, Widget and parts of View and represents a box with or without a surface.\r
165 Let's call a Boxx with a surface a root box, and a boxx without a surface a child box.\r
166 \r
167 A boxx with a surface (root) is like an old View and is handled by BoxStack.\r
168 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
169 \r
170 Don't add a boxx with a surface to another boxx. That isn't the design.\r
171 \r
172 So, when you create a boxx, either that boxx calls createBuffer() on itself,\r
173 or some other box add()s the new box to itself.\r
174 \r
175 Root boxxs can overlap each other - this is managed by boxstack.\r
176 Child boxxs within a parent boxx do not overlap each other.\r
177 However, a grandchild box can overlap a child box (but must be entirely contained within the child box).\r
178 \r
179 TBBoxx replaces View but is now only a convenience class for the window dressing stuff. It isn't required anymore since\r
180 all the real work that view used to do is done in Boxx now.\r
181 \r
182 Obseleted classes: Box, View, Viewman, Widget, others?\r
183 No code outside boxx should talk about surfaces anymore. Hopefully.\r
184 \r
185 */\r
186 \r