1 /* 2 * Copyright 2001-2015, 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 * Julian Harnath <julian.harnath@rwth-aachen.de> 11 */ 12 #ifndef _DRAW_STATE_H_ 13 #define _DRAW_STATE_H_ 14 15 16 #include <AffineTransform.h> 17 #include <GraphicsDefs.h> 18 #include <InterfaceDefs.h> 19 #include <Point.h> 20 #include <Referenceable.h> 21 #include <View.h> 22 23 #include "ServerFont.h" 24 #include "PatternHandler.h" 25 #include "SimpleTransform.h" 26 27 class AlphaMask; 28 class BRegion; 29 class shape_data; 30 31 namespace BPrivate { 32 class LinkReceiver; 33 class LinkSender; 34 }; 35 36 37 class DrawState { 38 public: 39 DrawState(); 40 DrawState(const DrawState& other); 41 public: 42 virtual ~DrawState(); 43 44 DrawState* PushState(); 45 DrawState* PopState(); 46 DrawState* PreviousState() const { return fPreviousState; } 47 48 void ReadFontFromLink(BPrivate::LinkReceiver& link); 49 // NOTE: ReadFromLink() does not read Font state!! 50 // It was separate in ServerWindow, and I didn't 51 // want to change it without knowing implications. 52 void ReadFromLink(BPrivate::LinkReceiver& link); 53 void WriteToLink(BPrivate::LinkSender& link) const; 54 55 // coordinate transformation 56 void SetOrigin(BPoint origin); 57 BPoint Origin() const 58 { return fOrigin; } 59 BPoint CombinedOrigin() const 60 { return fCombinedOrigin; } 61 62 void SetScale(float scale); 63 float Scale() const 64 { return fScale; } 65 float CombinedScale() const 66 { return fCombinedScale; } 67 68 void SetTransform(BAffineTransform transform); 69 BAffineTransform Transform() const 70 { return fTransform; } 71 BAffineTransform CombinedTransform() const 72 { return fCombinedTransform; } 73 void SetTransformEnabled(bool enabled); 74 75 DrawState* Squash() const; 76 77 // additional clipping as requested by client 78 void SetClippingRegion(const BRegion* region); 79 80 bool HasClipping() const; 81 bool HasAdditionalClipping() const; 82 bool GetCombinedClippingRegion(BRegion* region) const; 83 84 bool ClipToRect(BRect rect, bool inverse); 85 void ClipToShape(shape_data* shape, bool inverse); 86 87 void SetAlphaMask(AlphaMask* mask); 88 AlphaMask* GetAlphaMask() const; 89 90 // coordinate transformations 91 void Transform(SimpleTransform& transform) const; 92 void InverseTransform(SimpleTransform& transform) const; 93 94 // color 95 void SetHighColor(rgb_color color); 96 rgb_color HighColor() const 97 { return fHighColor; } 98 99 void SetLowColor(rgb_color color); 100 rgb_color LowColor() const 101 { return fLowColor; } 102 103 void SetPattern(const Pattern& pattern); 104 const Pattern& GetPattern() const 105 { return fPattern; } 106 107 // drawing/blending mode 108 bool SetDrawingMode(drawing_mode mode); 109 drawing_mode GetDrawingMode() const 110 { return fDrawingMode; } 111 112 bool SetBlendingMode(source_alpha srcMode, 113 alpha_function fncMode); 114 source_alpha AlphaSrcMode() const 115 { return fAlphaSrcMode; } 116 alpha_function AlphaFncMode() const 117 { return fAlphaFncMode; } 118 119 void SetDrawingModeLocked(bool locked); 120 121 // pen 122 void SetPenLocation(BPoint location); 123 BPoint PenLocation() const; 124 125 void SetPenSize(float size); 126 float PenSize() const; 127 float UnscaledPenSize() const; 128 129 // font 130 void SetFont(const ServerFont& font, 131 uint32 flags = B_FONT_ALL); 132 const ServerFont& Font() const 133 { return fFont; } 134 135 // overrides aliasing flag contained in SeverFont::Flags()) 136 void SetForceFontAliasing(bool aliasing); 137 bool ForceFontAliasing() const 138 { return fFontAliasing; } 139 140 // postscript style settings 141 void SetLineCapMode(cap_mode mode); 142 cap_mode LineCapMode() const 143 { return fLineCapMode; } 144 145 void SetLineJoinMode(join_mode mode); 146 join_mode LineJoinMode() const 147 { return fLineJoinMode; } 148 149 void SetMiterLimit(float limit); 150 float MiterLimit() const 151 { return fMiterLimit; } 152 153 void SetFillRule(int32 fillRule); 154 int32 FillRule() const 155 { return fFillRule; } 156 157 // convenience functions 158 void PrintToStream() const; 159 160 void SetSubPixelPrecise(bool precise); 161 bool SubPixelPrecise() const 162 { return fSubPixelPrecise; } 163 164 protected: 165 BPoint fOrigin; 166 BPoint fCombinedOrigin; 167 float fScale; 168 float fCombinedScale; 169 BAffineTransform fTransform; 170 BAffineTransform fCombinedTransform; 171 172 BRegion* fClippingRegion; 173 174 BReference<AlphaMask> fAlphaMask; 175 176 rgb_color fHighColor; 177 rgb_color fLowColor; 178 Pattern fPattern; 179 180 drawing_mode fDrawingMode; 181 source_alpha fAlphaSrcMode; 182 alpha_function fAlphaFncMode; 183 bool fDrawingModeLocked; 184 185 BPoint fPenLocation; 186 float fPenSize; 187 188 ServerFont fFont; 189 // overrides font aliasing flag 190 bool fFontAliasing; 191 192 // This is not part of the normal state stack. 193 // The view will update it in PushState/PopState. 194 // A BView can have a flag "B_SUBPIXEL_PRECISE", 195 // I never knew what it does on R5, but I can use 196 // it in Painter to actually draw stuff with 197 // sub-pixel coordinates. It means 198 // StrokeLine(BPoint(10, 5), BPoint(20, 9)); 199 // will look different from 200 // StrokeLine(BPoint(10.3, 5.8), BPoint(20.6, 9.5)); 201 bool fSubPixelPrecise; 202 203 cap_mode fLineCapMode; 204 join_mode fLineJoinMode; 205 float fMiterLimit; 206 int32 fFillRule; 207 // "internal", used to calculate the size 208 // of the font (again) when the scale changes 209 float fUnscaledFontSize; 210 211 DrawState* fPreviousState; 212 }; 213 214 #endif // _DRAW_STATE_H_ 215