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