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