xref: /haiku/src/servers/app/Layer.h (revision 2899b880f6c1e9ba92bbd4e78f4dc63c720a5e24)
1 /*
2  * Copyright (c) 2001-2005, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Adi Oanca <adioanca@gmail.com>
8  *		Stephan Aßmus <superstippi@gmx.de>
9  */
10 #ifndef _LAYER_H_
11 #define _LAYER_H_
12 
13 #include <GraphicsDefs.h>
14 #include <List.h>
15 #include <Locker.h>
16 #include <OS.h>
17 #include <String.h>
18 #include <Rect.h>
19 #include <Region.h>
20 
21 #include "RGBColor.h"
22 #include "ServerWindow.h"
23 
24 enum {
25 	B_LAYER_NONE		= 1,
26 	B_LAYER_MOVE		= 2,
27 	B_LAYER_SIMPLE_MOVE	= 3,
28 	B_LAYER_RESIZE		= 4,
29 	B_LAYER_MASK_RESIZE	= 5,
30 };
31 
32 enum {
33 	B_LAYER_ACTION_NONE = 0,
34 	B_LAYER_ACTION_MOVE,
35 	B_LAYER_ACTION_RESIZE
36 };
37 
38 enum {
39 	B_LAYER_CHILDREN_DEPENDANT = 0x1000U,
40 };
41 
42 class ServerApp;
43 class RootLayer;
44 class DrawingEngine;
45 class DrawState;
46 class ServerBitmap;
47 
48 class PointerEvent {
49  public:
50 	int32		code;		// B_MOUSE_UP, B_MOUSE_DOWN, B_MOUSE_MOVED,
51 							// B_MOUSE_WHEEL_CHANGED
52 	bigtime_t	when;
53 	BPoint		where;
54 	float		wheel_delta_x;
55 	float		wheel_delta_y;
56 	int32		modifiers;
57 	int32		buttons;	// B_PRIMARY_MOUSE_BUTTON, B_SECONDARY_MOUSE_BUTTON
58 							// B_TERTIARY_MOUSE_BUTTON
59 	int32		clicks;
60 };
61 
62 class Layer {
63  public:
64 								Layer(BRect frame, const char* name,
65 									  int32 token, uint32 resize,
66 									  uint32 flags, DrawingEngine* driver);
67 	virtual						~Layer();
68 
69 	// name
70 	virtual	void				SetName(const char* name);
71 	inline	const char*			Name() const
72 									{ return fName.String(); }
73 
74 			int32				ViewToken() const { return fViewToken; }
75 
76 	// children handling
77 			void				AddChild(Layer* child, ServerWindow* serverWin);
78 			void				RemoveChild(Layer* child);
79 			void				RemoveSelf();
80 			bool				HasChild(Layer* layer);
81 			Layer*				Parent() const
82 									{ return fParent; }
83 
84 			uint32				CountChildren() const;
85 			Layer*				FindLayer(const int32 token);
86 			Layer*				LayerAt(const BPoint &pt, bool recursive = true);
87 
88 	virtual	Layer*				FirstChild() const;
89 	virtual	Layer*				NextChild() const;
90 	virtual	Layer*				PreviousChild() const;
91 	virtual	Layer*				LastChild() const;
92 
93 			void				SetAsTopLayer(bool option)
94 									{ fIsTopLayer = option; }
95 	inline	bool				IsTopLayer() const
96 									{ return fIsTopLayer; }
97 
98 	// visible state
99 			void				Show(bool invalidate = true);
100 			void				Hide(bool invalidate = true);
101 			bool				IsHidden() const;
102 			bool				IsVisuallyHidden() const;
103 
104 	// graphic state and attributes
105 			void				PushState();
106 			void				PopState();
107 			DrawState*			CurrentState() const { return fDrawState; }
108 
109 			void				SetViewColor(const RGBColor& color);
110 	inline	const RGBColor&		ViewColor() const
111 									{ return fViewColor; }
112 			void				SetBackgroundBitmap(const ServerBitmap* bitmap);
113 	inline	const ServerBitmap*	BackgroundBitmap() const
114 									{ return fBackgroundBitmap; }
115 			void				SetOverlayBitmap(const ServerBitmap* bitmap);
116 	inline	const ServerBitmap*	OverlayBitmap() const
117 									{ return fOverlayBitmap; }
118 
119 	// coordinate system
120 			BRect				Bounds() const;
121 			BRect				Frame() const;
122 			BPoint				BoundsOrigin() const; // BoundsFrameDiff()?
123 			float				Scale() const;
124 
125 			void				ConvertToParent(BPoint* pt) const;
126 			void				ConvertToParent(BRect* rect) const;
127 			void				ConvertToParent(BRegion* reg) const;
128 			void				ConvertFromParent(BPoint* pt) const;
129 			void				ConvertFromParent(BRect* rect) const;
130 			void				ConvertFromParent(BRegion* reg) const;
131 
132 			void				ConvertToScreen(BPoint* pt) const;
133 			void				ConvertToScreen(BRect* rect) const;
134 			void				ConvertToScreen(BRegion* reg) const;
135 			void				ConvertFromScreen(BPoint* pt) const;
136 			void				ConvertFromScreen(BRect* rect) const;
137 			void				ConvertFromScreen(BRegion* reg) const;
138 
139 	virtual	void				MoveBy(float x, float y);
140 	virtual	void				ResizeBy(float x, float y);
141 	virtual	void				ScrollBy(float x, float y);
142 			void				CopyBits(BRect& src, BRect& dst,
143 										 int32 xOffset, int32 yOffset);
144 
145 	// input handling
146 	virtual	void				MouseDown(const BMessage *msg);
147 	virtual	void				MouseUp(const BMessage *msg);
148 	virtual	void				MouseMoved(const BMessage *msg);
149 	virtual	void				MouseWheelChanged(const BMessage *msg);
150 
151 	virtual	void				WorkspaceActivated(int32 index, bool active);
152 	virtual	void				WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces);
153 	virtual	void				Activated(bool active);
154 
155 	// action hooks
156 	virtual	void				MovedByHook(float dx, float dy);
157 	virtual	void				ResizedByHook(float dx, float dy, bool automatic);
158 	virtual	void				ScrolledByHook(float dx, float dy);
159 
160 	// app_server objects getters
161 			ServerWindow*		Window() const
162 									{ return fServerWin; }
163 			ServerApp*			App() const
164 									{ return fServerWin? fServerWin->App(): NULL; }
165 	inline	WinBorder*			Owner() const
166 									{ return fOwner; }
167 			RootLayer*			GetRootLayer() const
168 									{ return fRootLayer; }
169 			void				SetRootLayer(RootLayer* rl)
170 									{ fRootLayer = rl; }
171 			DrawingEngine*		GetDrawingEngine() const
172 									{ return fDriver; }
173 
174 	// flags
175 			uint32				EventMask() const
176 									{ return fEventMask; }
177 			uint32				EventOptions() const
178 									{ return fEventOptions; }
179 	inline	void				QuietlySetEventMask(uint32 em)
180 									{ fEventMask = em; }
181 	inline	void				QuietlySetEventOptions(uint32 eo)
182 									{ fEventOptions = eo; }
183 	inline	uint32				ResizeMode() const
184 									{ return fResizeMode; }
185 	inline	uint32				Flags() const
186 									{ return fFlags; }
187 			void				SetFlags(uint32 flags);
188 
189 	// clipping stuff and redraw
190 			void				SetUserClipping(const BRegion& region);
191 				// region is expected in layer coordinates
192 
193 	inline	const BRegion&		VisibleRegion() const { return fVisible; }
194 	inline	const BRegion&		FullVisible() const { return fFullVisible; }
195 	inline	const BRegion&		DrawingRegion() const { return fDrawingRegion; }
196 
197 	virtual	void				GetOnScreenRegion(BRegion& region);
198 
199 			void				MarkForRebuild(const BRegion &dirty);
200 			void				TriggerRebuild();
201 			void				_GetAllRebuildDirty(BRegion *totalReg);
202 
203 	virtual	void				Draw(const BRect& r);
204 			void				_AllRedraw(const BRegion &invalid);
205 
206  private:
207 	friend class RootLayer;
208 	friend class WinBorder;
209 	friend class ServerWindow;
210 
211 	// private clipping stuff
212 	virtual	void				_ReserveRegions(BRegion &reg);
213 			void				_RebuildVisibleRegions( const BRegion &invalid,
214 														const BRegion &parentLocalVisible,
215 														const Layer *startFrom);
216 			void				_RebuildDrawingRegion();
217 			void				_ClearVisibleRegions();
218 			void				_ResizeLayerFrameBy(float x, float y);
219 			void				_RezizeLayerRedrawMore(BRegion &reg, float dx, float dy);
220 			void				_ResizeLayerFullUpdateOnResize(BRegion &reg, float dx, float dy);
221 
222 	// for updating client-side coordinates
223 			void				_AddToViewsWithInvalidCoords() const;
224 			void				_SendViewCoordUpdateMsg() const;
225 
226 
227 			BString				fName;
228 			BRect				fFrame;
229 // TODO: should be removed or reused in a similar fashion
230 // to hold the accumulated origins from the graphics state stack.
231 // The same needs to be done for "scale". (Keeping an accumulated
232 // value.)
233 //			BPoint				fBoundsLeftTop;
234 
235 			BRegion				fVisible;
236 			BRegion				fFullVisible;
237 			BRegion				fDirtyForRebuild;
238 			BRegion				fDrawingRegion;
239 
240 			DrawingEngine*		fDriver;
241 			RootLayer*			fRootLayer;
242 			ServerWindow*		fServerWin;
243 			WinBorder*			fOwner;
244 
245 			DrawState*			fDrawState;
246 
247 			Layer*				fParent;
248 			Layer*				fPreviousSibling;
249 			Layer*				fNextSibling;
250 			Layer*				fFirstChild;
251 			Layer*				fLastChild;
252 
253 	mutable	Layer*				fCurrent;
254 
255 			int32				fViewToken;
256 			uint32				fFlags;
257 			uint16				fAdFlags;
258 			uint32				fResizeMode;
259 			uint32				fEventMask;
260 			uint32				fEventOptions;
261 
262 			bool				fHidden;
263 			bool				fIsTopLayer;
264 			RGBColor			fViewColor;
265 
266 	const	ServerBitmap*		fBackgroundBitmap;
267 	const	ServerBitmap*		fOverlayBitmap;
268 
269 };
270 
271 #endif // _LAYER_H_
272