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 * Description: 11 * Class used for tracking drawing context and screen clipping. 12 * One Layer per client BWindow (WindowBorder) and each BView therein. 13 */ 14 15 #ifndef _LAYER_H_ 16 #define _LAYER_H_ 17 18 #include <GraphicsDefs.h> 19 #include <List.h> 20 #include <Locker.h> 21 #include <OS.h> 22 #include <String.h> 23 #include <Rect.h> 24 #include <Region.h> 25 26 #include "RGBColor.h" 27 #include "ServerWindow.h" 28 29 enum { 30 B_LAYER_NONE = 1, 31 B_LAYER_MOVE = 2, 32 B_LAYER_SIMPLE_MOVE = 3, 33 B_LAYER_RESIZE = 4, 34 B_LAYER_MASK_RESIZE = 5, 35 }; 36 37 enum { 38 B_LAYER_ACTION_NONE = 0, 39 B_LAYER_ACTION_MOVE, 40 B_LAYER_ACTION_RESIZE 41 }; 42 43 enum { 44 B_LAYER_CHILDREN_DEPENDANT = 0x1000U, 45 }; 46 47 class ServerApp; 48 class RootLayer; 49 class DrawingEngine; 50 class DrawState; 51 class ServerBitmap; 52 53 class PointerEvent { 54 public: 55 int32 code; // B_MOUSE_UP, B_MOUSE_DOWN, B_MOUSE_MOVED, 56 // B_MOUSE_WHEEL_CHANGED 57 bigtime_t when; 58 BPoint where; 59 float wheel_delta_x; 60 float wheel_delta_y; 61 int32 modifiers; 62 int32 buttons; // B_PRIMARY_MOUSE_BUTTON, B_SECONDARY_MOUSE_BUTTON 63 // B_TERTIARY_MOUSE_BUTTON 64 int32 clicks; 65 }; 66 67 class Layer { 68 public: 69 Layer(BRect frame, const char* name, 70 int32 token, uint32 resize, 71 uint32 flags, DrawingEngine* driver); 72 virtual ~Layer(); 73 74 void AddChild(Layer* child, ServerWindow* serverWin); 75 void RemoveChild(Layer* child); 76 void RemoveSelf(); 77 bool HasChild(Layer* layer); 78 79 void SetRootLayer(RootLayer* rl) 80 { fRootLayer = rl; } 81 RootLayer* GetRootLayer() const 82 { return fRootLayer; } 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 virtual void SetName(const char* name); 94 inline const char* Name() const 95 { return fName.String(); } 96 97 inline uint32 ResizeMode() const 98 { return fResizeMode; } 99 100 virtual void SetFlags(uint32 flags); 101 inline uint32 Flags() const 102 { return fFlags; } 103 104 virtual void Draw(const BRect& r); 105 106 void Show(bool invalidate = true); 107 void Hide(bool invalidate = true); 108 bool IsHidden() const; 109 110 // graphic state 111 void PushState(); 112 void PopState(); 113 DrawState* CurrentState() const { return fDrawState; } 114 115 // coordinate system 116 BRect Bounds() const; 117 BRect Frame() const; 118 119 virtual void MoveBy(float x, float y); 120 virtual void ResizeBy(float x, float y); 121 virtual void ScrollBy(float x, float y); 122 123 virtual void MouseDown(const BMessage *msg); 124 virtual void MouseUp(const BMessage *msg); 125 virtual void MouseMoved(const BMessage *msg); 126 virtual void MouseWheelChanged(const BMessage *msg); 127 128 virtual void KeyDown(const BMessage *msg); 129 virtual void KeyUp(const BMessage *msg); 130 virtual void UnmappedKeyDown(const BMessage *msg); 131 virtual void UnmappedKeyUp(const BMessage *msg); 132 virtual void ModifiersChanged(const BMessage *msg); 133 134 virtual void WorkspaceActivated(int32 index, bool active); 135 virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); 136 virtual void Activated(bool active); 137 138 BPoint BoundsOrigin() const; // BoundsFrameDiff()? 139 float Scale() const; 140 141 BPoint ConvertToParent(BPoint pt); 142 BRect ConvertToParent(BRect rect); 143 BRegion ConvertToParent(BRegion* reg); 144 145 BPoint ConvertFromParent(BPoint pt); 146 BRect ConvertFromParent(BRect rect); 147 BRegion ConvertFromParent(BRegion* reg); 148 149 BPoint ConvertToTop(BPoint pt); 150 BRect ConvertToTop(BRect rect); 151 BRegion ConvertToTop(BRegion* reg); 152 153 BPoint ConvertFromTop(BPoint pt); 154 BRect ConvertFromTop(BRect rect); 155 BRegion ConvertFromTop(BRegion *reg); 156 157 158 DrawingEngine* GetDrawingEngine() const 159 { return fDriver; } 160 161 ServerWindow* Window() const 162 { return fServerWin; } 163 164 ServerApp* App() const 165 { return fServerWin? fServerWin->App(): NULL; } 166 167 inline WinBorder* Owner() const 168 { return fOwner; } 169 170 virtual bool HasClient() 171 { return true; } 172 173 uint32 EventMask() const 174 { return fEventMask; } 175 176 uint32 EventOptions() const 177 { return fEventOptions; } 178 179 inline void QuietlySetEventMask(uint32 em) 180 { fEventMask = em; } 181 182 inline void QuietlySetEventOptions(uint32 eo) 183 { fEventOptions = eo; } 184 185 void PruneTree(); 186 187 // debugging 188 void PrintToStream(); 189 void PrintNode(); 190 void PrintTree(); 191 192 // server "private" - should not be used 193 void SetAsTopLayer(bool option) 194 { fIsTopLayer = option; } 195 196 inline bool IsTopLayer() const 197 { return fIsTopLayer; } 198 199 BRegion* ClippingRegion() const 200 { return fClipReg; } 201 202 // automatic background blanking by app_server 203 void SetViewColor(const RGBColor& color); 204 inline const RGBColor& ViewColor() const 205 { return fViewColor; } 206 207 void SetBackgroundBitmap(const ServerBitmap* bitmap); 208 inline const ServerBitmap* BackgroundBitmap() const 209 { return fBackgroundBitmap; } 210 211 // overlay support 212 // TODO: This can't be all, what about color key? 213 void SetOverlayBitmap(const ServerBitmap* bitmap); 214 inline const ServerBitmap* OverlayBitmap() const 215 { return fOverlayBitmap; } 216 217 void CopyBits(BRect& src, BRect& dst, 218 int32 xOffset, int32 yOffset); 219 220 inline const BRegion& VisibleRegion() const { return fVisible2; } 221 inline const BRegion& FullVisible() const { return fFullVisible2; } 222 223 void MarkForRebuild(const BRegion &dirty); 224 void TriggerRebuild(); 225 void _GetAllRebuildDirty(BRegion *totalReg); 226 void _AllRedraw(const BRegion &invalid); 227 228 229 virtual void GetWantedRegion(BRegion& reg); 230 231 virtual void MovedByHook(float dx, float dy); 232 virtual void ResizedByHook(float dx, float dy, bool automatic); 233 virtual void ScrolledByHook(float dx, float dy); 234 235 void ConvertToParent2(BPoint* pt) const; 236 void ConvertToParent2(BRect* rect) const; 237 void ConvertToParent2(BRegion* reg) const; 238 void ConvertFromParent2(BPoint* pt) const; 239 void ConvertFromParent2(BRect* rect) const; 240 void ConvertFromParent2(BRegion* reg) const; 241 242 void ConvertToScreen2(BPoint* pt) const; 243 void ConvertToScreen2(BRect* rect) const; 244 void ConvertToScreen2(BRegion* reg) const; 245 void ConvertFromScreen2(BPoint* pt) const; 246 void ConvertFromScreen2(BRect* rect) const; 247 void ConvertFromScreen2(BRegion* reg) const; 248 bool IsVisuallyHidden() const; 249 private: 250 void do_Hide(); 251 void do_Show(); 252 void do_MoveBy(float dx, float dy); 253 void do_ResizeBy(float dx, float dy); 254 void do_ScrollBy(float dx, float dy); 255 256 void rebuild_visible_regions(const BRegion &invalid, 257 const BRegion &parentLocalVisible, 258 const Layer *startFrom); 259 260 virtual void _ReserveRegions(BRegion ®); 261 262 void clear_visible_regions(); 263 void resize_layer_frame_by(float x, float y); 264 void rezize_layer_redraw_more(BRegion ®, float dx, float dy); 265 void resize_layer_full_update_on_resize(BRegion ®, float dx, float dy); 266 267 void do_CopyBits(BRect& src, BRect& dst, 268 int32 xOffset, int32 yOffset); 269 270 protected: 271 friend class RootLayer; 272 friend class WinBorder; 273 friend class ServerWindow; 274 275 BRect fFrame; 276 // TODO: should be removed or reused in a similar fashion 277 // to hold the accumulated origins from the graphics state stack. 278 // The same needs to be done for "scale". (Keeping an accumulated 279 // value.) 280 // BPoint fBoundsLeftTop; 281 WinBorder* fOwner; 282 283 Layer* fParent; 284 Layer* fPreviousSibling; 285 Layer* fNextSibling; 286 Layer* fFirstChild; 287 Layer* fLastChild; 288 289 mutable Layer* fCurrent; 290 291 private: 292 BRegion fVisible2; 293 BRegion fFullVisible2; 294 BRegion fDirtyForRebuild; 295 protected: 296 297 BRegion* fClipReg; 298 299 ServerWindow* fServerWin; 300 BString fName; 301 int32 fViewToken; 302 uint32 fFlags; 303 uint32 fResizeMode; 304 uint32 fEventMask; 305 uint32 fEventOptions; 306 bool fHidden; 307 bool fIsTopLayer; 308 uint16 fAdFlags; 309 310 DrawingEngine* fDriver; 311 DrawState* fDrawState; 312 313 RootLayer* fRootLayer; 314 315 private: 316 ServerWindow* SearchForServerWindow(); 317 318 status_t SendUpdateMsg(BRegion& reg); 319 void AddToViewsWithInvalidCoords() const; 320 void SendViewCoordUpdateMsg() const; 321 322 RGBColor fViewColor; 323 324 const ServerBitmap* fBackgroundBitmap; 325 const ServerBitmap* fOverlayBitmap; 326 327 }; 328 329 #endif // _LAYER_H_ 330