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