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