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