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