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