xref: /haiku/src/servers/app/Layer.h (revision ea6253d0ba561f923f74af1febaf250d2419b1ae)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, Haiku, Inc.
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		Layer.h
23 //	Author:			DarkWyrm <bpmagic@columbus.rr.com>
24 //					Adi Oanca <adioanca@cotty.iren.com>
25 //					Stephan Aßmus <superstippi@gmx.de>
26 //	Description:	Class used for rendering to the frame buffer. One layer per
27 //					view on screen and also for window decorators
28 //
29 //------------------------------------------------------------------------------
30 #ifndef _LAYER_H_
31 #define _LAYER_H_
32 
33 #include <GraphicsDefs.h>
34 #include <List.h>
35 #include <Locker.h>
36 #include <OS.h>
37 #include <String.h>
38 #include <Rect.h>
39 #include <Region.h>
40 
41 #include "RGBColor.h"
42 #include "ServerWindow.h"
43 
44 //#define NEW_CLIPPING 1
45 
46 enum {
47 	B_LAYER_NONE		= 1,
48 	B_LAYER_MOVE		= 2,
49 	B_LAYER_SIMPLE_MOVE	= 3,
50 	B_LAYER_RESIZE		= 4,
51 	B_LAYER_MASK_RESIZE	= 5,
52 };
53 
54 enum {
55 	B_LAYER_CHILDREN_DEPENDANT = 0x1000U,
56 };
57 
58 // easy way to determine class type
59 enum {
60 	AS_LAYER_CLASS		= 1,
61 	AS_WINBORDER_CLASS	= 2,
62 	AS_ROOTLAYER_CLASS	= 3,
63 };
64 
65 class ServerApp;
66 class RootLayer;
67 class DisplayDriver;
68 class LayerData;
69 class ServerBitmap;
70 
71 class Layer {
72  public:
73 								Layer(BRect frame, const char* name,
74 									  int32 token, uint32 resize,
75 									  uint32 flags, DisplayDriver* driver);
76 	virtual						~Layer();
77 
78 			void				AddChild(Layer* child, ServerWindow* serverWin);
79 			void				RemoveChild(Layer* child);
80 			void				RemoveSelf();
81 			bool				HasChild(Layer* layer);
82 
83 			RootLayer*			GetRootLayer() const
84 									{ return fRootLayer; }
85 
86 			uint32				CountChildren() const;
87 			Layer*				FindLayer(const int32 token);
88 			Layer*				LayerAt(const BPoint &pt);
89 
90 	virtual	Layer*				TopChild() const;
91 	virtual	Layer*				LowerSibling() const;
92 	virtual	Layer*				UpperSibling() const;
93 	virtual	Layer*				BottomChild() const;
94 
95 			const char*			Name() const
96 									{ return fName.String(); }
97 	inline	uint32				Flags() const
98 									{ return fFlags; }
99 	inline	uint32				ResizeMode() const
100 									{ return fResizeMode; }
101 
102 #ifndef NEW_CLIPPING
103 	virtual	void				RebuildFullRegion();
104 			void				StartRebuildRegions(const BRegion& reg,
105 													Layer* target,
106 													uint32 action,
107 													BPoint& pt);
108 
109 			void				RebuildRegions(const BRegion& reg,
110 											   uint32 action,
111 											   BPoint pt,
112 											   BPoint ptOffset);
113 
114 			uint32				ResizeOthers(float x, float y,
115 											 BPoint coords[],
116 											 BPoint* ptOffset);
117 
118 			void				EmptyGlobals();
119 
120 #endif
121 			void				Redraw(const BRegion& reg,
122 									   Layer* startFrom = NULL);
123 
124 	virtual	void				Draw(const BRect& r);
125 
126 			void				Show(bool invalidate = true);
127 			void				Hide(bool invalidate = true);
128 			bool				IsHidden() const;
129 
130 	// graphic state
131 			void				PushState();
132 			void				PopState();
133 
134 	// coordinate system
135 			BRect				Bounds() const;
136 			BRect				Frame() const;
137 
138 	virtual	void				MoveBy(float x, float y);
139 	virtual	void				ResizeBy(float x, float y);
140 	virtual	void				ScrollBy(float x, float y);
141 
142 			BPoint				BoundsOrigin() const; // BoundsFrameDiff()?
143 			float				Scale() const;
144 
145 			BPoint				ConvertToParent(BPoint pt);
146 			BRect				ConvertToParent(BRect rect);
147 			BRegion				ConvertToParent(BRegion* reg);
148 
149 			BPoint				ConvertFromParent(BPoint pt);
150 			BRect				ConvertFromParent(BRect rect);
151 			BRegion				ConvertFromParent(BRegion* reg);
152 
153 			BPoint				ConvertToTop(BPoint pt);
154 			BRect				ConvertToTop(BRect rect);
155 			BRegion				ConvertToTop(BRegion* reg);
156 
157 			BPoint				ConvertFromTop(BPoint pt);
158 			BRect				ConvertFromTop(BRect rect);
159 			BRegion				ConvertFromTop(BRegion *reg);
160 
161 
162 			DisplayDriver*		GetDisplayDriver() const
163 									{ return fDriver; }
164 
165 			ServerWindow*		Window() const
166 									{ return fServerWin; }
167 
168 			ServerApp*			App() const
169 									{ return fServerWin? fServerWin->App(): NULL; }
170 
171 	virtual	bool				HasClient()
172 									{ return true; }
173 //			bool				IsServerLayer() const;
174 
175 			uint32				EventMask() const
176 									{ return fEventMask; }
177 
178 			uint32				EventOptions() const
179 									{ return fEventOptions; }
180 
181 			void				PruneTree();
182 
183 	// debugging
184 			void				PrintToStream();
185 			void				PrintNode();
186 			void				PrintTree();
187 
188 	// server "private" - should not be used
189 			void				SetRootLayer(RootLayer* rl)
190 									{ fRootLayer = rl; }
191 
192 			void				SetAsTopLayer(bool option)
193 									{ fIsTopLayer = option; }
194 
195 	inline	bool				IsTopLayer() const
196 									{ return fIsTopLayer; }
197 
198 			BRegion*			ClippingRegion() const
199 									{ return fClipReg; }
200 
201 								// automatic background blanking by app_server
202 			void				SetViewColor(const RGBColor& color);
203 	inline	const RGBColor&		ViewColor() const
204 									{ return fViewColor; }
205 
206 			void				SetBackgroundBitmap(const ServerBitmap* bitmap);
207 	inline	const ServerBitmap*	BackgroundBitmap() const
208 									{ return fBackgroundBitmap; }
209 
210 								// overlay support
211 								// TODO: This can't be all, what about color key?
212 			void				SetOverlayBitmap(const ServerBitmap* bitmap);
213 	inline	const ServerBitmap*	OverlayBitmap() const
214 									{ return fOverlayBitmap; }
215 
216 			void				CopyBits(BRect& src, BRect& dst,
217 										 int32 xOffset, int32 yOffset);
218 
219 #ifdef NEW_CLIPPING
220 	inline	const BRegion&		VisibleRegion() const { return fVisible2; }
221 	inline	const BRegion&		FullVisible() const { return fFullVisible2; }
222 
223 	virtual	void				GetWantedRegion(BRegion& reg) const;
224 
225 	virtual	void				MovedByHook(float dx, float dy);
226 	virtual	void				ResizedByHook(float dx, float dy, bool automatic);
227 	virtual	void				ScrolledByHook(float dx, float dy);
228 
229 			void				ConvertToParent2(BPoint* pt) const;
230 			void				ConvertToParent2(BRect* rect) const;
231 			void				ConvertToParent2(BRegion* reg) const;
232 			void				ConvertFromParent2(BPoint* pt) const;
233 			void				ConvertFromParent2(BRect* rect) const;
234 			void				ConvertFromParent2(BRegion* reg) const;
235 
236 			void				ConvertToScreen2(BPoint* pt) const;
237 			void				ConvertToScreen2(BRect* rect) const;
238 			void				ConvertToScreen2(BRegion* reg) const;
239 			void				ConvertFromScreen2(BPoint* pt) const;
240 			void				ConvertFromScreen2(BRect* rect) const;
241 			void				ConvertFromScreen2(BRegion* reg) const;
242 			bool				IsVisuallyHidden() const;
243  private:
244  			void				do_Hide();
245  			void				do_Show();
246 			void				do_RebuildVisibleRegions(const BRegion &invalid,
247 														const Layer *startFrom);
248 			void				do_MoveBy(float dx, float dy);
249 			void				do_ResizeBy(float dx, float dy);
250 			void				do_ScrollBy(float dx, float dy);
251 
252 			void				do_Invalidate(	const BRegion &invalid,
253 												const Layer *startFrom = NULL);
254 
255 			void				do_Redraw(	const BRegion &invalid,
256 											const Layer *startFrom = NULL);
257 
258 			void				rebuild_visible_regions(const BRegion &invalid,
259 													const BRegion &parentLocalVisible,
260 													const Layer *startFrom);
261 
262 	virtual	bool				alter_visible_for_children(BRegion &region);
263 	virtual	void				get_user_regions(BRegion &reg);
264 
265 			void				clear_visible_regions();
266 			void				resize_layer_frame_by(float x, float y);
267 			void				rezize_layer_redraw_more(BRegion &reg, float dx, float dy);
268 			void				resize_layer_full_update_on_resize(BRegion &reg, float dx, float dy);
269 
270 #endif
271  private:
272 			void				do_CopyBits(BRect& src, BRect& dst,
273 											int32 xOffset, int32 yOffset);
274 
275  protected:
276 	friend class RootLayer;
277 	friend class WinBorder;
278 	friend class ServerWindow;
279 
280 #ifndef NEW_CLIPPING
281 			void				move_layer(float x, float y);
282 			void				resize_layer(float x, float y);
283 
284 			void				FullInvalidate(const BRect& rect);
285 			void				FullInvalidate(const BRegion& region);
286 			void				Invalidate(const BRegion& region);
287 #endif
288 
289 			BRect				fFrame;
290 // TODO: should be removed or reused in a similar fashion
291 // to hold the accumulated origins from the graphics state stack.
292 // The same needs to be done for "scale". (Keeping an accumulated
293 // value.)
294 //			BPoint				fBoundsLeftTop;
295 			WinBorder*			fOwner;
296 			Layer*				fParent;
297 			Layer*				fUpperSibling;
298 			Layer*				fLowerSibling;
299 			Layer*				fTopChild;
300 			Layer*				fBottomChild;
301 
302 	mutable	Layer*				fCurrent;
303 
304 #ifndef NEW_CLIPPING
305 			BRegion				fVisible;
306 			BRegion				fFullVisible;
307 			BRegion				fFull;
308 			int8				fFrameAction;
309 #else
310  private:
311 			BRegion				fVisible2;
312 			BRegion				fFullVisible2;
313  protected:
314 #endif
315 			BRegion*			fClipReg;
316 
317 			ServerWindow*		fServerWin;
318 			BString				fName;
319 			int32				fViewToken;
320 			uint32				fFlags;
321 			uint32				fResizeMode;
322 			uint32				fEventMask;
323 			uint32				fEventOptions;
324 			bool				fHidden;
325 			bool				fIsTopLayer;
326 			uint16				fAdFlags;
327 			int8				fClassID;
328 
329 			DisplayDriver*		fDriver;
330 			LayerData*			fLayerData;
331 
332 			RootLayer*			fRootLayer;
333 
334  private:
335 			void				RequestDraw(const BRegion& reg,
336 											Layer* startFrom);
337 			ServerWindow*		SearchForServerWindow();
338 
339 			void				SendUpdateMsg(BRegion& reg);
340 			void				AddToViewsWithInvalidCoords() const;
341 			void				SendViewCoordUpdateMsg() const;
342 
343 			RGBColor			fViewColor;
344 
345 	const	ServerBitmap*		fBackgroundBitmap;
346 	const	ServerBitmap*		fOverlayBitmap;
347 
348 };
349 
350 #endif // _LAYER_H_
351