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