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