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