xref: /haiku/src/servers/app/Layer.h (revision b223f7804125d5a1cc0f397085125930a7a93a22)
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				ScrollingOffset() const;
123 
124 			void				SetDrawingOrigin(BPoint origin);
125 			BPoint				DrawingOrigin() const;
126 
127 			void				SetScale(float scale);
128 			float				Scale() const;
129 
130 			void				ConvertToParent(BPoint* pt) const;
131 			void				ConvertToParent(BRect* rect) const;
132 			void				ConvertToParent(BRegion* reg) const;
133 			void				ConvertFromParent(BPoint* pt) const;
134 			void				ConvertFromParent(BRect* rect) const;
135 			void				ConvertFromParent(BRegion* reg) const;
136 
137 			void				ConvertToScreen(BPoint* pt) const;
138 			void				ConvertToScreen(BRect* rect) const;
139 			void				ConvertToScreen(BRegion* reg) const;
140 			void				ConvertFromScreen(BPoint* pt) const;
141 			void				ConvertFromScreen(BRect* rect) const;
142 			void				ConvertFromScreen(BRegion* reg) const;
143 
144 			void				ConvertToScreenForDrawing(BPoint* pt) const;
145 			void				ConvertToScreenForDrawing(BRect* rect) const;
146 			void				ConvertToScreenForDrawing(BRegion* reg) const;
147 
148 			void				ConvertFromScreenForDrawing(BPoint* pt) const;
149 
150 	virtual	void				MoveBy(float x, float y);
151 	virtual	void				ResizeBy(float x, float y);
152 	virtual	void				ScrollBy(float x, float y);
153 			void				CopyBits(BRect& src, BRect& dst,
154 										 int32 xOffset, int32 yOffset);
155 
156 	// input handling
157 	virtual	void				MouseDown(const BMessage *msg);
158 	virtual	void				MouseUp(const BMessage *msg);
159 	virtual	void				MouseMoved(const BMessage *msg);
160 	virtual	void				MouseWheelChanged(const BMessage *msg);
161 
162 	virtual	void				WorkspaceActivated(int32 index, bool active);
163 	virtual	void				WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces);
164 	virtual	void				Activated(bool active);
165 
166 	// action hooks
167 	virtual	void				MovedByHook(float dx, float dy);
168 	virtual	void				ResizedByHook(float dx, float dy, bool automatic);
169 	virtual	void				ScrolledByHook(float dx, float dy);
170 
171 	// app_server objects getters
172 			ServerWindow*		Window() const
173 									{ return fServerWin; }
174 			ServerApp*			App() const
175 									{ return fServerWin? fServerWin->App(): NULL; }
176 	inline	WinBorder*			Owner() const
177 									{ return fOwner; }
178 			RootLayer*			GetRootLayer() const
179 									{ return fRootLayer; }
180 			void				SetRootLayer(RootLayer* rl)
181 									{ fRootLayer = rl; }
182 			DrawingEngine*		GetDrawingEngine() const
183 									{ return fDriver; }
184 
185 	// flags
186 			uint32				EventMask() const
187 									{ return fEventMask; }
188 			uint32				EventOptions() const
189 									{ return fEventOptions; }
190 	inline	void				QuietlySetEventMask(uint32 em)
191 									{ fEventMask = em; }
192 	inline	void				QuietlySetEventOptions(uint32 eo)
193 									{ fEventOptions = eo; }
194 	inline	uint32				ResizeMode() const
195 									{ return fResizeMode; }
196 	inline	uint32				Flags() const
197 									{ return fFlags; }
198 			void				SetFlags(uint32 flags);
199 
200 	// clipping stuff and redraw
201 			void				SetUserClipping(const BRegion& region);
202 				// region is expected in layer coordinates
203 
204 	inline	const BRegion&		VisibleRegion() const { return fVisible; }
205 	inline	const BRegion&		FullVisible() const { return fFullVisible; }
206 	inline	const BRegion&		DrawingRegion() const { return fDrawingRegion; }
207 
208 	virtual	void				GetOnScreenRegion(BRegion& region);
209 
210 			void				MarkForRebuild(const BRegion &dirty);
211 			void				TriggerRebuild();
212 			void				_GetAllRebuildDirty(BRegion *totalReg);
213 
214 	virtual	void				Draw(const BRect& r);
215 			void				_AllRedraw(const BRegion &invalid);
216 
217  private:
218 	friend class RootLayer;
219 	friend class WinBorder;
220 	friend class ServerWindow;
221 
222 	// private clipping stuff
223 	virtual	void				_ReserveRegions(BRegion &reg);
224 			void				_RebuildVisibleRegions( const BRegion &invalid,
225 														const BRegion &parentLocalVisible,
226 														const Layer *startFrom);
227 			void				_RebuildDrawingRegion();
228 			void				_ClearVisibleRegions();
229 			void				_ResizeLayerFrameBy(float x, float y);
230 			void				_RezizeLayerRedrawMore(BRegion &reg, float dx, float dy);
231 			void				_ResizeLayerFullUpdateOnResize(BRegion &reg, float dx, float dy);
232 
233 	// for updating client-side coordinates
234 			void				_AddToViewsWithInvalidCoords() const;
235 			void				_SendViewCoordUpdateMsg() const;
236 
237 
238 			BString				fName;
239 			BRect				fFrame;
240 			BPoint				fScrollingOffset;
241 
242 			BRegion				fVisible;
243 			BRegion				fFullVisible;
244 			BRegion				fDirtyForRebuild;
245 			BRegion				fDrawingRegion;
246 
247 			DrawingEngine*		fDriver;
248 			RootLayer*			fRootLayer;
249 			ServerWindow*		fServerWin;
250 			WinBorder*			fOwner;
251 
252 			DrawState*			fDrawState;
253 
254 			Layer*				fParent;
255 			Layer*				fPreviousSibling;
256 			Layer*				fNextSibling;
257 			Layer*				fFirstChild;
258 			Layer*				fLastChild;
259 
260 	mutable	Layer*				fCurrent;
261 
262 			int32				fViewToken;
263 			uint32				fFlags;
264 			uint16				fAdFlags;
265 			uint32				fResizeMode;
266 			uint32				fEventMask;
267 			uint32				fEventOptions;
268 
269 			bool				fHidden;
270 			bool				fIsTopLayer;
271 			RGBColor			fViewColor;
272 
273 	const	ServerBitmap*		fBackgroundBitmap;
274 	const	ServerBitmap*		fOverlayBitmap;
275 
276 };
277 
278 #endif // _LAYER_H_
279