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_ACTION_NONE = 0, 56 B_LAYER_ACTION_MOVE, 57 B_LAYER_ACTION_RESIZE 58 }; 59 60 enum { 61 B_LAYER_CHILDREN_DEPENDANT = 0x1000U, 62 }; 63 64 // easy way to determine class type 65 enum { 66 AS_LAYER_CLASS = 1, 67 AS_WINBORDER_CLASS = 2, 68 AS_ROOTLAYER_CLASS = 3, 69 }; 70 71 class ServerApp; 72 class RootLayer; 73 class DisplayDriver; 74 class LayerData; 75 class ServerBitmap; 76 77 class PointerEvent { 78 public: 79 int32 code; // B_MOUSE_UP, B_MOUSE_DOWN, B_MOUSE_MOVED, 80 // B_MOUSE_WHEEL_CHANGED 81 bigtime_t when; 82 BPoint where; 83 float wheel_delta_x; 84 float wheel_delta_y; 85 int32 modifiers; 86 int32 buttons; // B_PRIMARY_MOUSE_BUTTON, B_SECONDARY_MOUSE_BUTTON 87 // B_TERTIARY_MOUSE_BUTTON 88 int32 clicks; 89 }; 90 91 class Layer { 92 public: 93 Layer(BRect frame, const char* name, 94 int32 token, uint32 resize, 95 uint32 flags, DisplayDriver* driver); 96 virtual ~Layer(); 97 98 void AddChild(Layer* child, ServerWindow* serverWin); 99 void RemoveChild(Layer* child); 100 void RemoveSelf(); 101 bool HasChild(Layer* layer); 102 103 void SetRootLayer(RootLayer* rl) 104 { fRootLayer = rl; } 105 RootLayer* GetRootLayer() const 106 { return fRootLayer; } 107 108 uint32 CountChildren() const; 109 Layer* FindLayer(const int32 token); 110 Layer* LayerAt(const BPoint &pt, bool recursive = true); 111 112 virtual Layer* FirstChild() const; 113 virtual Layer* NextChild() const; 114 virtual Layer* PreviousChild() const; 115 virtual Layer* LastChild() const; 116 117 virtual void SetName(const char* name); 118 inline const char* Name() const 119 { return fName.String(); } 120 121 inline uint32 ResizeMode() const 122 { return fResizeMode; } 123 124 virtual void SetFlags(uint32 flags); 125 inline uint32 Flags() const 126 { return fFlags; } 127 128 #ifndef NEW_CLIPPING 129 virtual void RebuildFullRegion(); 130 void StartRebuildRegions(const BRegion& reg, 131 Layer* target, 132 uint32 action, 133 BPoint& pt); 134 135 void RebuildRegions(const BRegion& reg, 136 uint32 action, 137 BPoint pt, 138 BPoint ptOffset); 139 140 uint32 ResizeOthers(float x, float y, 141 BPoint coords[], 142 BPoint* ptOffset); 143 144 void EmptyGlobals(); 145 146 #endif 147 void Redraw(const BRegion& reg, 148 Layer* startFrom = NULL); 149 150 virtual void Draw(const BRect& r); 151 152 void Show(bool invalidate = true); 153 void Hide(bool invalidate = true); 154 bool IsHidden() const; 155 156 // graphic state 157 void PushState(); 158 void PopState(); 159 160 // coordinate system 161 BRect Bounds() const; 162 BRect Frame() const; 163 164 virtual void MoveBy(float x, float y); 165 virtual void ResizeBy(float x, float y); 166 virtual void ScrollBy(float x, float y); 167 168 virtual void MouseDown(const PointerEvent& evt); 169 virtual void MouseUp(const PointerEvent& evt); 170 virtual void MouseMoved(const PointerEvent& evt, uint32 transit); 171 virtual void WorkspaceActivated(int32 index, bool active); 172 virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); 173 174 BPoint BoundsOrigin() const; // BoundsFrameDiff()? 175 float Scale() const; 176 177 BPoint ConvertToParent(BPoint pt); 178 BRect ConvertToParent(BRect rect); 179 BRegion ConvertToParent(BRegion* reg); 180 181 BPoint ConvertFromParent(BPoint pt); 182 BRect ConvertFromParent(BRect rect); 183 BRegion ConvertFromParent(BRegion* reg); 184 185 BPoint ConvertToTop(BPoint pt); 186 BRect ConvertToTop(BRect rect); 187 BRegion ConvertToTop(BRegion* reg); 188 189 BPoint ConvertFromTop(BPoint pt); 190 BRect ConvertFromTop(BRect rect); 191 BRegion ConvertFromTop(BRegion *reg); 192 193 194 DisplayDriver* GetDisplayDriver() const 195 { return fDriver; } 196 197 ServerWindow* Window() const 198 { return fServerWin; } 199 200 ServerApp* App() const 201 { return fServerWin? fServerWin->App(): NULL; } 202 203 inline WinBorder* Owner() const 204 { return fOwner; } 205 206 virtual bool HasClient() 207 { return true; } 208 209 uint32 EventMask() const 210 { return fEventMask; } 211 212 uint32 EventOptions() const 213 { return fEventOptions; } 214 215 inline void QuietlySetEventMask(uint32 em) 216 { fEventMask = em; } 217 218 inline void QuietlySetEventOptions(uint32 eo) 219 { fEventOptions = eo; } 220 221 void PruneTree(); 222 223 // debugging 224 void PrintToStream(); 225 void PrintNode(); 226 void PrintTree(); 227 228 // server "private" - should not be used 229 void SetAsTopLayer(bool option) 230 { fIsTopLayer = option; } 231 232 inline bool IsTopLayer() const 233 { return fIsTopLayer; } 234 235 BRegion* ClippingRegion() const 236 { return fClipReg; } 237 238 // automatic background blanking by app_server 239 void SetViewColor(const RGBColor& color); 240 inline const RGBColor& ViewColor() const 241 { return fViewColor; } 242 243 void SetBackgroundBitmap(const ServerBitmap* bitmap); 244 inline const ServerBitmap* BackgroundBitmap() const 245 { return fBackgroundBitmap; } 246 247 // overlay support 248 // TODO: This can't be all, what about color key? 249 void SetOverlayBitmap(const ServerBitmap* bitmap); 250 inline const ServerBitmap* OverlayBitmap() const 251 { return fOverlayBitmap; } 252 253 void CopyBits(BRect& src, BRect& dst, 254 int32 xOffset, int32 yOffset); 255 #ifndef NEW_CLIPPING 256 inline const BRegion& VisibleRegion() const { return fVisible; } 257 inline const BRegion& FullVisible() const { return fFullVisible; } 258 259 #else 260 inline const BRegion& VisibleRegion() const { return fVisible2; } 261 inline const BRegion& FullVisible() const { return fFullVisible2; } 262 263 virtual void GetWantedRegion(BRegion& reg) const; 264 265 virtual void MovedByHook(float dx, float dy); 266 virtual void ResizedByHook(float dx, float dy, bool automatic); 267 virtual void ScrolledByHook(float dx, float dy); 268 269 void ConvertToParent2(BPoint* pt) const; 270 void ConvertToParent2(BRect* rect) const; 271 void ConvertToParent2(BRegion* reg) const; 272 void ConvertFromParent2(BPoint* pt) const; 273 void ConvertFromParent2(BRect* rect) const; 274 void ConvertFromParent2(BRegion* reg) const; 275 276 void ConvertToScreen2(BPoint* pt) const; 277 void ConvertToScreen2(BRect* rect) const; 278 void ConvertToScreen2(BRegion* reg) const; 279 void ConvertFromScreen2(BPoint* pt) const; 280 void ConvertFromScreen2(BRect* rect) const; 281 void ConvertFromScreen2(BRegion* reg) const; 282 bool IsVisuallyHidden() const; 283 private: 284 void do_Hide(); 285 void do_Show(); 286 void do_RebuildVisibleRegions(const BRegion &invalid, 287 const Layer *startFrom); 288 void do_MoveBy(float dx, float dy); 289 void do_ResizeBy(float dx, float dy); 290 void do_ScrollBy(float dx, float dy); 291 292 void do_Invalidate( const BRegion &invalid, 293 const Layer *startFrom = NULL); 294 295 void do_Redraw( const BRegion &invalid, 296 const Layer *startFrom = NULL); 297 298 void rebuild_visible_regions(const BRegion &invalid, 299 const BRegion &parentLocalVisible, 300 const Layer *startFrom); 301 302 virtual void _ReserveRegions(BRegion ®); 303 virtual void _GetWantedRegion(BRegion ®); 304 305 void clear_visible_regions(); 306 void resize_layer_frame_by(float x, float y); 307 void rezize_layer_redraw_more(BRegion ®, float dx, float dy); 308 void resize_layer_full_update_on_resize(BRegion ®, float dx, float dy); 309 310 #endif 311 private: 312 void do_CopyBits(BRect& src, BRect& dst, 313 int32 xOffset, int32 yOffset); 314 315 protected: 316 friend class RootLayer; 317 friend class WinBorder; 318 friend class ServerWindow; 319 // TODO: remove, is here for debugging purposes only 320 friend class OffscreenWinBorder; 321 322 #ifndef NEW_CLIPPING 323 void move_layer(float x, float y); 324 void resize_layer(float x, float y); 325 326 void FullInvalidate(const BRect& rect); 327 void FullInvalidate(const BRegion& region); 328 void Invalidate(const BRegion& region); 329 #endif 330 331 BRect fFrame; 332 // TODO: should be removed or reused in a similar fashion 333 // to hold the accumulated origins from the graphics state stack. 334 // The same needs to be done for "scale". (Keeping an accumulated 335 // value.) 336 // BPoint fBoundsLeftTop; 337 WinBorder* fOwner; 338 339 Layer* fParent; 340 Layer* fPreviousSibling; 341 Layer* fNextSibling; 342 Layer* fFirstChild; 343 Layer* fLastChild; 344 345 mutable Layer* fCurrent; 346 347 #ifndef NEW_CLIPPING 348 BRegion fVisible; 349 BRegion fFullVisible; 350 BRegion fFull; 351 int8 fFrameAction; 352 #else 353 private: 354 BRegion fVisible2; 355 BRegion fFullVisible2; 356 protected: 357 #endif 358 BRegion* fClipReg; 359 360 ServerWindow* fServerWin; 361 BString fName; 362 int32 fViewToken; 363 uint32 fFlags; 364 uint32 fResizeMode; 365 uint32 fEventMask; 366 uint32 fEventOptions; 367 bool fHidden; 368 bool fIsTopLayer; 369 uint16 fAdFlags; 370 int8 fClassID; 371 372 DisplayDriver* fDriver; 373 LayerData* fLayerData; 374 375 RootLayer* fRootLayer; 376 377 private: 378 void RequestDraw(const BRegion& reg, 379 Layer* startFrom); 380 ServerWindow* SearchForServerWindow(); 381 382 void SendUpdateMsg(BRegion& reg); 383 void AddToViewsWithInvalidCoords() const; 384 void SendViewCoordUpdateMsg() const; 385 386 RGBColor fViewColor; 387 388 const ServerBitmap* fBackgroundBitmap; 389 const ServerBitmap* fOverlayBitmap; 390 391 }; 392 393 #endif // _LAYER_H_ 394