1 /* 2 * Copyright 2001-2005, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Adi Oanca <adioanca@mymail.ro> 8 * Stephan Aßmus <superstippi@gmx.de> 9 * Axel Dörfler, axeld@pinc-software.de 10 */ 11 #ifndef _DRAW_STATE_H_ 12 #define _DRAW_STATE_H_ 13 14 15 #include <GraphicsDefs.h> 16 #include <InterfaceDefs.h> 17 #include <Point.h> 18 #include <View.h> // for B_FONT_ALL 19 20 #include "RGBColor.h" 21 #include "FontManager.h" 22 #include "ServerFont.h" 23 #include "PatternHandler.h" 24 25 class BRegion; 26 27 namespace BPrivate { 28 class LinkReceiver; 29 class LinkSender; 30 }; 31 32 33 class DrawState { 34 public: 35 DrawState(); 36 DrawState(const DrawState& from); 37 virtual ~DrawState(); 38 39 DrawState& operator=(const DrawState& from); 40 41 DrawState* PushState(); 42 DrawState* PopState(); 43 DrawState* PreviousState() const { return fPreviousState; } 44 45 void ReadFontFromLink(BPrivate::LinkReceiver& link); 46 // NOTE: ReadFromLink() does not read Font state!! 47 // It was separate in ServerWindow, and I didn't 48 // want to change it without knowing implications. 49 void ReadFromLink(BPrivate::LinkReceiver& link); 50 void WriteToLink(BPrivate::LinkSender& link) const; 51 52 // coordinate transformation 53 void SetOrigin(const BPoint& origin); 54 void OffsetOrigin(const BPoint& offset); 55 const BPoint& Origin() const 56 { return fOrigin; } 57 58 void SetScale(float scale); 59 float Scale() const 60 { return fScale; } 61 62 // coordinate transformations 63 void Transform(float* x, float* y) const; 64 void InverseTransform(float* x, float* y) const; 65 66 void Transform(BPoint* point) const; 67 void Transform(BRect* rect) const; 68 void Transform(BRegion* region) const; 69 70 void InverseTransform(BPoint* point) const; 71 72 // additional clipping as requested by client 73 void SetClippingRegion(const BRegion* region); 74 const BRegion* ClippingRegion() const 75 { return fClippingRegion; } 76 /* inline int32 CountClippingRects() const 77 { return fClippingRegion ? fClippingRegion.CountRects() : 0; } 78 inline BRect ClippingRectAt(int32 index) const;*/ 79 80 // color 81 void SetHighColor(const RGBColor& color); 82 const RGBColor& HighColor() const 83 { return fHighColor; } 84 85 void SetLowColor(const RGBColor& color); 86 const RGBColor& LowColor() const 87 { return fLowColor; } 88 89 void SetPattern(const Pattern& pattern); 90 const Pattern& GetPattern() const 91 { return fPattern; } 92 93 // drawing/blending mode 94 void SetDrawingMode(drawing_mode mode); 95 drawing_mode GetDrawingMode() const 96 { return fDrawingMode; } 97 98 void SetBlendingMode(source_alpha srcMode, 99 alpha_function fncMode); 100 source_alpha AlphaSrcMode() const 101 { return fAlphaSrcMode; } 102 alpha_function AlphaFncMode() const 103 { return fAlphaFncMode; } 104 105 // pen 106 void SetPenLocation(const BPoint& location); 107 const BPoint& PenLocation() const; 108 109 void SetPenSize(float size); 110 float PenSize() const; 111 112 // font 113 void SetFont(const ServerFont& font, 114 uint32 flags = B_FONT_ALL); 115 const ServerFont& Font() const 116 { return fFont; } 117 118 // overrides aliasing flag contained in SeverFont::Flags()) 119 void SetForceFontAliasing(bool aliasing); 120 bool ForceFontAliasing() const 121 { return fFontAliasing; } 122 123 // postscript style settings 124 void SetLineCapMode(cap_mode mode); 125 cap_mode LineCapMode() const 126 { return fLineCapMode; } 127 128 void SetLineJoinMode(join_mode mode); 129 join_mode LineJoinMode() const 130 { return fLineJoinMode; } 131 132 void SetMiterLimit(float limit); 133 float MiterLimit() const 134 { return fMiterLimit; } 135 136 // convenience functions 137 void PrintToStream() const; 138 139 void SetSubPixelPrecise(bool precise); 140 bool SubPixelPrecise() const 141 { return fSubPixelPrecise; } 142 143 protected: 144 BPoint fOrigin; 145 float fScale; 146 147 BRegion* fClippingRegion; 148 149 RGBColor fHighColor; 150 RGBColor fLowColor; 151 Pattern fPattern; 152 153 drawing_mode fDrawingMode; 154 source_alpha fAlphaSrcMode; 155 alpha_function fAlphaFncMode; 156 157 BPoint fPenLocation; 158 float fPenSize; 159 160 ServerFont fFont; 161 // overrides font aliasing flag 162 bool fFontAliasing; 163 164 // This is not part of the normal state stack. 165 // Layer will update it in PushState/PopState. 166 // A BView can have a flag "B_SUBPIXEL_PRECISE", 167 // I never knew what it does on R5, but I can use 168 // it in Painter to actually draw stuff with 169 // sub-pixel coordinates. It means 170 // StrokeLine(BPoint(10, 5), BPoint(20, 9)); 171 // will look different from 172 // StrokeLine(BPoint(10.3, 5.8), BPoint(20.6, 9.5)); 173 bool fSubPixelPrecise; 174 175 cap_mode fLineCapMode; 176 join_mode fLineJoinMode; 177 float fMiterLimit; 178 // "internal", used to calculate the size 179 // of the font (again) when the scale changes 180 float fUnscaledFontSize; 181 182 DrawState* fPreviousState; 183 }; 184 185 186 // inline implementations 187 188 /* 189 // ClippingRectAt 190 BRect 191 DrawState::ClippingRectAt(int32 index) const 192 { 193 BRect r; 194 if (fClippingRegion) { 195 r = fClippingRegion.RectAt(index); 196 } 197 return r; 198 }*/ 199 200 #endif /* _DRAW_STATE_H_ */ 201