]> git.vomp.tv Git - vompclient.git/blob - boxx.h
Updates to new streaming protocol and live tv
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 #include "surfacemvp.h"
37 #endif
38
39 class Boxx
40 {
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(Colour& 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 int handleCommand(int x) { return 0; }
60     virtual void processMessage(Message* m) {}
61     virtual bool mouseMove(int x, int y) { return false; }
62     virtual bool mouseLBDOWN(int x, int y) { return false; }
63     virtual void deactivateAllControls() {}
64
65
66     // Get functions
67     int getScreenX();        // where is it on screen
68     int getScreenY();
69     int getRootBoxOffsetX(); // where is it relative to the top-parent in the boxstack
70     int getRootBoxOffsetY();
71     int getX();              // where is it relative to its parent
72     int getX2();             // .. and the right edge
73     int getY();
74     int getY2();
75     UINT getWidth();
76     UINT getHeight();
77     bool getVisible();
78     Region* getRegion();     // Not to be used for changing the region
79         
80     
81     // Drawing functions level 1
82     void fillColour(Colour& colour);
83     void drawPara(char* text, int x, int y, Colour& colour);
84
85     // Drawing functions level 0
86     void rectangle(UINT x, UINT y, UINT w, UINT h, Colour& colour);
87     void rectangle(Region& region, Colour& colour);
88
89     void drawText(const char* text, int x, int y, Colour& colour);
90     void drawTextRJ(const char* text, int x, int y, Colour& colour);
91     void drawTextCentre(const char* text, int x, int y, Colour& colour);
92     void drawPixel(UINT x, UINT y, Colour& colour);
93
94     /* This is for system which need a locking of the drawing surface to speed up drawing */
95     void startFastDraw();
96     void endFastDraw();
97
98     int charWidth(char c);
99
100     void add(Boxx*); // a boxx has a set of child boxxs
101     void remove(Boxx*);
102
103     /*
104     The following function sets the child's parent pointer without adding the child to the children vector.
105     It's a hack (that should be deprecated?) to allow things like WSymbol to be created, do some drawing on
106     the surface and then be deleted again, leaving the drawing present.
107     A better design would be to create many WSymbols - one per symbol and leave them created - then the
108     automatic draw code will be able to redraw the symbols without all that code needing
109     to be in the derived boxx's draw method.
110     */    
111     void TEMPADD(Boxx* child) { child->setParent(this); }
112
113   friend class BoxStack;
114   protected:
115     Boxx* parent;
116     Region area;
117     vector<Boxx*> children;
118
119     void setParent(Boxx*);    
120     void blt(Region& r);
121
122     static const int paraMargin = 10;
123     UINT paraVSpace;
124
125     Colour backgroundColour;
126     bool backgroundColourSet;
127     bool visible;
128
129     static char numBoxxes;
130     Surface* surface;
131 };
132
133 #endif
134
135
136 /*
137
138 New Boxx design
139
140 It's "Boxx" because "Box" was already taken.
141
142 BoxStack replaces Viewman and handles displaying a stack of root boxxs (boxxs with surfaces) on the screen.
143
144 Boxx relaces Box, Widget and parts of View and represents a box with or without a surface.
145 Let's call a Boxx with a surface a root box, and a boxx without a surface a child box.
146
147 A boxx with a surface (root) is like an old View and is handled by BoxStack.
148 A boxx without a surface (child) is like and old Widget and needs to be a child box of another boxx (root or not).
149
150 Don't add a boxx with a surface to another boxx. That isn't the design.
151
152 So, when you create a boxx, either that boxx calls createBuffer() on itself,
153 or some other box add()s the new box to itself.
154
155 Root boxxs can overlap each other - this is managed by boxstack.
156 Child boxxs within a parent boxx do not overlap each other.
157 However, a grandchild box can overlap a child box (but must be entirely contained within the child box).
158
159 TBBoxx replaces View but is now only a convenience class for the window dressing stuff. It isn't required anymore since
160 all the real work that view used to do is done in Boxx now.
161
162 Obseleted classes: Box, View, Viewman, Widget, others?
163 No code outside boxx should talk about surfaces anymore. Hopefully.
164
165 */
166