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 #ifndef _LAYER_H_ 11 #define _LAYER_H_ 12 13 #include <GraphicsDefs.h> 14 #include <List.h> 15 #include <Locker.h> 16 #include <OS.h> 17 #include <String.h> 18 #include <Rect.h> 19 #include <Region.h> 20 21 #include "RGBColor.h" 22 #include "ServerWindow.h" 23 24 enum { 25 B_LAYER_NONE = 1, 26 B_LAYER_MOVE = 2, 27 B_LAYER_SIMPLE_MOVE = 3, 28 B_LAYER_RESIZE = 4, 29 B_LAYER_MASK_RESIZE = 5, 30 }; 31 32 enum { 33 B_LAYER_ACTION_NONE = 0, 34 B_LAYER_ACTION_MOVE, 35 B_LAYER_ACTION_RESIZE 36 }; 37 38 enum { 39 B_LAYER_CHILDREN_DEPENDANT = 0x1000U, 40 }; 41 42 class ServerApp; 43 class RootLayer; 44 class DrawingEngine; 45 class DrawState; 46 class ServerBitmap; 47 48 class PointerEvent { 49 public: 50 int32 code; // B_MOUSE_UP, B_MOUSE_DOWN, B_MOUSE_MOVED, 51 // B_MOUSE_WHEEL_CHANGED 52 bigtime_t when; 53 BPoint where; 54 float wheel_delta_x; 55 float wheel_delta_y; 56 int32 modifiers; 57 int32 buttons; // B_PRIMARY_MOUSE_BUTTON, B_SECONDARY_MOUSE_BUTTON 58 // B_TERTIARY_MOUSE_BUTTON 59 int32 clicks; 60 }; 61 62 class Layer { 63 public: 64 Layer(BRect frame, const char* name, 65 int32 token, uint32 resize, 66 uint32 flags, DrawingEngine* driver); 67 virtual ~Layer(); 68 69 // name 70 virtual void SetName(const char* name); 71 inline const char* Name() const 72 { return fName.String(); } 73 74 int32 ViewToken() const { return fViewToken; } 75 76 // children handling 77 void AddChild(Layer* child, ServerWindow* serverWin); 78 void RemoveChild(Layer* child); 79 void RemoveSelf(); 80 bool HasChild(Layer* layer); 81 Layer* Parent() const 82 { return fParent; } 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 void SetAsTopLayer(bool option) 94 { fIsTopLayer = option; } 95 inline bool IsTopLayer() const 96 { return fIsTopLayer; } 97 98 // visible state 99 void Show(bool invalidate = true); 100 void Hide(bool invalidate = true); 101 bool IsHidden() const; 102 bool IsVisuallyHidden() const; 103 104 // graphic state and attributes 105 void PushState(); 106 void PopState(); 107 DrawState* CurrentState() const { return fDrawState; } 108 109 void SetViewColor(const RGBColor& color); 110 inline const RGBColor& ViewColor() const 111 { return fViewColor; } 112 void SetBackgroundBitmap(const ServerBitmap* bitmap); 113 inline const ServerBitmap* BackgroundBitmap() const 114 { return fBackgroundBitmap; } 115 void SetOverlayBitmap(const ServerBitmap* bitmap); 116 inline const ServerBitmap* OverlayBitmap() const 117 { return fOverlayBitmap; } 118 119 // coordinate system 120 BRect Bounds() const; 121 BRect Frame() const; 122 BPoint ScrollingOffset() const; 123 124 void SetDrawingOrigin(BPoint origin); 125 BPoint DrawingOrigin() const; 126 127 void SetScale(float scale); 128 float Scale() const; 129 130 void ConvertToParent(BPoint* pt) const; 131 void ConvertToParent(BRect* rect) const; 132 void ConvertToParent(BRegion* reg) const; 133 void ConvertFromParent(BPoint* pt) const; 134 void ConvertFromParent(BRect* rect) const; 135 void ConvertFromParent(BRegion* reg) const; 136 137 void ConvertToScreen(BPoint* pt) const; 138 void ConvertToScreen(BRect* rect) const; 139 void ConvertToScreen(BRegion* reg) const; 140 void ConvertFromScreen(BPoint* pt) const; 141 void ConvertFromScreen(BRect* rect) const; 142 void ConvertFromScreen(BRegion* reg) const; 143 144 void ConvertToScreenForDrawing(BPoint* pt) const; 145 void ConvertToScreenForDrawing(BRect* rect) const; 146 void ConvertToScreenForDrawing(BRegion* reg) const; 147 148 void ConvertFromScreenForDrawing(BPoint* pt) const; 149 150 virtual void MoveBy(float x, float y); 151 virtual void ResizeBy(float x, float y); 152 virtual void ScrollBy(float x, float y); 153 void CopyBits(BRect& src, BRect& dst, 154 int32 xOffset, int32 yOffset); 155 156 // input handling 157 virtual void MouseDown(const BMessage *msg); 158 virtual void MouseUp(const BMessage *msg); 159 virtual void MouseMoved(const BMessage *msg); 160 virtual void MouseWheelChanged(const BMessage *msg); 161 162 virtual void WorkspaceActivated(int32 index, bool active); 163 virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); 164 virtual void Activated(bool active); 165 166 // action hooks 167 virtual void MovedByHook(float dx, float dy); 168 virtual void ResizedByHook(float dx, float dy, bool automatic); 169 virtual void ScrolledByHook(float dx, float dy); 170 171 // app_server objects getters 172 ServerWindow* Window() const 173 { return fServerWin; } 174 ServerApp* App() const 175 { return fServerWin? fServerWin->App(): NULL; } 176 inline WinBorder* Owner() const 177 { return fOwner; } 178 RootLayer* GetRootLayer() const 179 { return fRootLayer; } 180 void SetRootLayer(RootLayer* rl) 181 { fRootLayer = rl; } 182 DrawingEngine* GetDrawingEngine() const 183 { return fDriver; } 184 185 void SetEventMask(uint32 eventMask, uint32 options); 186 uint32 EventMask() const 187 { return fEventMask; } 188 uint32 EventOptions() const 189 { return fEventOptions; } 190 191 inline uint32 ResizeMode() const 192 { return fResizeMode; } 193 inline uint32 Flags() const 194 { return fFlags; } 195 void SetFlags(uint32 flags); 196 197 // clipping stuff and redraw 198 void SetUserClipping(const BRegion& region); 199 // region is expected in layer coordinates 200 201 inline const BRegion& VisibleRegion() const { return fVisible; } 202 inline const BRegion& FullVisible() const { return fFullVisible; } 203 inline const BRegion& DrawingRegion() const { return fDrawingRegion; } 204 205 virtual void GetOnScreenRegion(BRegion& region); 206 207 void MarkForRebuild(const BRegion &dirty); 208 void TriggerRebuild(); 209 void _GetAllRebuildDirty(BRegion *totalReg); 210 211 virtual void Draw(const BRect& r); 212 void _AllRedraw(const BRegion &invalid); 213 214 private: 215 friend class RootLayer; 216 friend class WinBorder; 217 friend class ServerWindow; 218 219 // private clipping stuff 220 virtual void _ReserveRegions(BRegion ®); 221 void _RebuildVisibleRegions( const BRegion &invalid, 222 const BRegion &parentLocalVisible, 223 const Layer *startFrom); 224 void _RebuildDrawingRegion(); 225 void _ClearVisibleRegions(); 226 void _ResizeLayerFrameBy(float x, float y); 227 void _RezizeLayerRedrawMore(BRegion ®, float dx, float dy); 228 void _ResizeLayerFullUpdateOnResize(BRegion ®, float dx, float dy); 229 230 // for updating client-side coordinates 231 void _AddToViewsWithInvalidCoords() const; 232 void _SendViewCoordUpdateMsg() const; 233 234 235 BString fName; 236 BRect fFrame; 237 BPoint fScrollingOffset; 238 239 BRegion fVisible; 240 BRegion fFullVisible; 241 BRegion fDirtyForRebuild; 242 BRegion fDrawingRegion; 243 244 DrawingEngine* fDriver; 245 RootLayer* fRootLayer; 246 ServerWindow* fServerWin; 247 WinBorder* fOwner; 248 249 DrawState* fDrawState; 250 251 Layer* fParent; 252 Layer* fPreviousSibling; 253 Layer* fNextSibling; 254 Layer* fFirstChild; 255 Layer* fLastChild; 256 257 mutable Layer* fCurrent; 258 259 int32 fViewToken; 260 uint32 fFlags; 261 uint16 fAdFlags; 262 uint32 fResizeMode; 263 uint32 fEventMask; 264 uint32 fEventOptions; 265 266 bool fHidden; 267 bool fIsTopLayer; 268 RGBColor fViewColor; 269 270 const ServerBitmap* fBackgroundBitmap; 271 const ServerBitmap* fOverlayBitmap; 272 273 }; 274 275 #endif // _LAYER_H_ 276