1 /* 2 * Copyright (c) 2001-2015, 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 * Axel Dörfler, axeld@pinc-software.de 9 * Stephan Aßmus <superstippi@gmx.de> 10 * Marcus Overhagen <marcus@overhagen.de> 11 * Adrien Destugues <pulkomandy@pulkomandy.tk> 12 * Julian Harnath <julian.harnath@rwth-aachen.de> 13 */ 14 #ifndef CANVAS_H 15 #define CANVAS_H 16 17 18 #include <Point.h> 19 20 #include "SimpleTransform.h" 21 22 23 class AlphaMask; 24 class BGradient; 25 class BRegion; 26 class DrawingEngine; 27 class DrawState; 28 class IntPoint; 29 class IntRect; 30 class Layer; 31 class ServerPicture; 32 class shape_data; 33 34 35 class Canvas { 36 public: 37 Canvas(); 38 Canvas(const DrawState& state); 39 virtual ~Canvas(); 40 41 status_t InitCheck() const; 42 43 virtual void PushState(); 44 virtual void PopState(); 45 DrawState* CurrentState() const { return fDrawState; } 46 void SetDrawState(DrawState* newState); 47 48 void SetDrawingOrigin(BPoint origin); 49 BPoint DrawingOrigin() const; 50 51 void SetScale(float scale); 52 float Scale() const; 53 54 void SetUserClipping(const BRegion* region); 55 // region is expected in view coordinates 56 57 bool ClipToRect(BRect rect, bool inverse); 58 void ClipToShape(shape_data* shape, bool inverse); 59 60 void SetAlphaMask(AlphaMask* mask); 61 AlphaMask* GetAlphaMask() const; 62 63 virtual IntRect Bounds() const = 0; 64 65 SimpleTransform LocalToScreenTransform() const; 66 SimpleTransform ScreenToLocalTransform() const; 67 SimpleTransform PenToScreenTransform() const; 68 SimpleTransform PenToLocalTransform() const; 69 SimpleTransform ScreenToPenTransform() const; 70 71 void BlendLayer(Layer* layer); 72 73 virtual DrawingEngine* GetDrawingEngine() const = 0; 74 virtual ServerPicture* GetPicture(int32 token) const = 0; 75 virtual void RebuildClipping(bool deep) = 0; 76 virtual void ResyncDrawState() {}; 77 virtual void UpdateCurrentDrawingRegion() {}; 78 79 protected: 80 virtual void _LocalToScreenTransform( 81 SimpleTransform& transform) const = 0; 82 virtual void _ScreenToLocalTransform( 83 SimpleTransform& transform) const = 0; 84 85 protected: 86 DrawState* fDrawState; 87 }; 88 89 90 class OffscreenCanvas : public Canvas { 91 public: 92 OffscreenCanvas(DrawingEngine* engine, 93 const DrawState& state, const IntRect& bounds); 94 virtual ~OffscreenCanvas(); 95 96 virtual DrawingEngine* GetDrawingEngine() const { return fDrawingEngine; } 97 98 virtual void RebuildClipping(bool deep) { /* TODO */ } 99 virtual void ResyncDrawState(); 100 virtual void UpdateCurrentDrawingRegion(); 101 virtual ServerPicture* GetPicture(int32 token) const 102 { /* TODO */ return NULL; } 103 virtual IntRect Bounds() const; 104 105 protected: 106 virtual void _LocalToScreenTransform(SimpleTransform&) const {} 107 virtual void _ScreenToLocalTransform(SimpleTransform&) const {} 108 109 private: 110 DrawingEngine* fDrawingEngine; 111 BRegion fCurrentDrawingRegion; 112 IntRect fBounds; 113 }; 114 115 116 #endif // CANVAS_H 117