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 // name 75 virtual void SetName(const char* name); 76 inline const char* Name() const 77 { return fName.String(); } 78 79 // children handling 80 void AddChild(Layer* child, ServerWindow* serverWin); 81 void RemoveChild(Layer* child); 82 void RemoveSelf(); 83 bool HasChild(Layer* layer); 84 85 uint32 CountChildren() const; 86 Layer* FindLayer(const int32 token); 87 Layer* LayerAt(const BPoint &pt, bool recursive = true); 88 89 virtual Layer* FirstChild() const; 90 virtual Layer* NextChild() const; 91 virtual Layer* PreviousChild() const; 92 virtual Layer* LastChild() const; 93 94 void SetAsTopLayer(bool option) 95 { fIsTopLayer = option; } 96 inline bool IsTopLayer() const 97 { return fIsTopLayer; } 98 99 // visible state 100 void Show(bool invalidate = true); 101 void Hide(bool invalidate = true); 102 bool IsHidden() const; 103 bool IsVisuallyHidden() const; 104 105 // graphic state and attributes 106 void PushState(); 107 void PopState(); 108 DrawState* CurrentState() const { return fDrawState; } 109 110 void SetViewColor(const RGBColor& color); 111 inline const RGBColor& ViewColor() const 112 { return fViewColor; } 113 void SetBackgroundBitmap(const ServerBitmap* bitmap); 114 inline const ServerBitmap* BackgroundBitmap() const 115 { return fBackgroundBitmap; } 116 void SetOverlayBitmap(const ServerBitmap* bitmap); 117 inline const ServerBitmap* OverlayBitmap() const 118 { return fOverlayBitmap; } 119 120 // coordinate system 121 BRect Bounds() const; 122 BRect Frame() const; 123 BPoint BoundsOrigin() const; // BoundsFrameDiff()? 124 float Scale() const; 125 126 void ConvertToParent(BPoint* pt) const; 127 void ConvertToParent(BRect* rect) const; 128 void ConvertToParent(BRegion* reg) const; 129 void ConvertFromParent(BPoint* pt) const; 130 void ConvertFromParent(BRect* rect) const; 131 void ConvertFromParent(BRegion* reg) const; 132 133 void ConvertToScreen(BPoint* pt) const; 134 void ConvertToScreen(BRect* rect) const; 135 void ConvertToScreen(BRegion* reg) const; 136 void ConvertFromScreen(BPoint* pt) const; 137 void ConvertFromScreen(BRect* rect) const; 138 void ConvertFromScreen(BRegion* reg) const; 139 140 virtual void MoveBy(float x, float y); 141 virtual void ResizeBy(float x, float y); 142 virtual void ScrollBy(float x, float y); 143 void CopyBits(BRect& src, BRect& dst, 144 int32 xOffset, int32 yOffset); 145 146 // input handling 147 virtual void MouseDown(const BMessage *msg); 148 virtual void MouseUp(const BMessage *msg); 149 virtual void MouseMoved(const BMessage *msg); 150 virtual void MouseWheelChanged(const BMessage *msg); 151 152 virtual void KeyDown(const BMessage *msg); 153 virtual void KeyUp(const BMessage *msg); 154 virtual void UnmappedKeyDown(const BMessage *msg); 155 virtual void UnmappedKeyUp(const BMessage *msg); 156 virtual void ModifiersChanged(const BMessage *msg); 157 158 virtual void WorkspaceActivated(int32 index, bool active); 159 virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); 160 virtual void Activated(bool active); 161 162 // action hooks 163 virtual void MovedByHook(float dx, float dy); 164 virtual void ResizedByHook(float dx, float dy, bool automatic); 165 virtual void ScrolledByHook(float dx, float dy); 166 167 // app_server objects getters 168 ServerWindow* Window() const 169 { return fServerWin; } 170 ServerApp* App() const 171 { return fServerWin? fServerWin->App(): NULL; } 172 inline WinBorder* Owner() const 173 { return fOwner; } 174 RootLayer* GetRootLayer() const 175 { return fRootLayer; } 176 void SetRootLayer(RootLayer* rl) 177 { fRootLayer = rl; } 178 DrawingEngine* GetDrawingEngine() const 179 { return fDriver; } 180 181 // flags 182 uint32 EventMask() const 183 { return fEventMask; } 184 uint32 EventOptions() const 185 { return fEventOptions; } 186 inline void QuietlySetEventMask(uint32 em) 187 { fEventMask = em; } 188 inline void QuietlySetEventOptions(uint32 eo) 189 { fEventOptions = eo; } 190 inline uint32 ResizeMode() const 191 { return fResizeMode; } 192 inline uint32 Flags() const 193 { return fFlags; } 194 void SetFlags(uint32 flags); 195 196 // clipping stuff and redraw 197 inline const BRegion& VisibleRegion() const { return fVisible2; } 198 inline const BRegion& FullVisible() const { return fFullVisible2; } 199 200 virtual void GetWantedRegion(BRegion& reg); 201 202 void MarkForRebuild(const BRegion &dirty); 203 void TriggerRebuild(); 204 void _GetAllRebuildDirty(BRegion *totalReg); 205 206 virtual void Draw(const BRect& r); 207 void _AllRedraw(const BRegion &invalid); 208 209 // others 210 void PruneTree(); 211 212 private: 213 friend class RootLayer; 214 friend class WinBorder; 215 friend class ServerWindow; 216 217 void do_Hide(); 218 void do_Show(); 219 void do_MoveBy(float dx, float dy); 220 void do_ResizeBy(float dx, float dy); 221 void do_ScrollBy(float dx, float dy); 222 void do_CopyBits(BRect& src, BRect& dst, 223 int32 xOffset, int32 yOffset); 224 225 // private clipping stuff 226 virtual void _ReserveRegions(BRegion ®); 227 void _RebuildVisibleRegions( const BRegion &invalid, 228 const BRegion &parentLocalVisible, 229 const Layer *startFrom); 230 void _ClearVisibleRegions(); 231 void _ResizeLayerFrameBy(float x, float y); 232 void _RezizeLayerRedrawMore(BRegion ®, float dx, float dy); 233 void _ResizeLayerFullUpdateOnResize(BRegion ®, float dx, float dy); 234 235 // for updating client-side coordinates 236 void AddToViewsWithInvalidCoords() const; 237 void SendViewCoordUpdateMsg() const; 238 239 240 BString fName; 241 BRect fFrame; 242 // TODO: should be removed or reused in a similar fashion 243 // to hold the accumulated origins from the graphics state stack. 244 // The same needs to be done for "scale". (Keeping an accumulated 245 // value.) 246 // BPoint fBoundsLeftTop; 247 248 BRegion fVisible2; 249 BRegion fFullVisible2; 250 BRegion fDirtyForRebuild; 251 252 DrawingEngine* fDriver; 253 RootLayer* fRootLayer; 254 ServerWindow* fServerWin; 255 WinBorder* fOwner; 256 257 DrawState* fDrawState; 258 259 Layer* fParent; 260 Layer* fPreviousSibling; 261 Layer* fNextSibling; 262 Layer* fFirstChild; 263 Layer* fLastChild; 264 265 mutable Layer* fCurrent; 266 267 int32 fViewToken; 268 uint32 fFlags; 269 uint16 fAdFlags; 270 uint32 fResizeMode; 271 uint32 fEventMask; 272 uint32 fEventOptions; 273 274 bool fHidden; 275 bool fIsTopLayer; 276 RGBColor fViewColor; 277 278 const ServerBitmap* fBackgroundBitmap; 279 const ServerBitmap* fOverlayBitmap; 280 281 }; 282 283 #endif // _LAYER_H_ 284