XamlBrushes.h

00001 //
00002 //  Copyright (c) 1996-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 #if !defined XAML_BRUSHES
00019 #define XAML_BRUSHES
00020 
00021 
00022 #include "whiptk/whip_toolkit.h"
00023 #include "whiptk/typedefs_defines.h"
00024 #include "dwfcore/DWFXMLSerializer.h"
00025 #include "dwfcore/Owner.h"
00026 #include "XAML/XamlResource.h"
00027 
00028 class WT_XAML_File;
00029 
00030 namespace XamlBrush
00031 {
00032     typedef enum eType
00033     {
00034         kSolidColor,
00035         kImage,
00036         kRadialGradient,
00037         kLinearGradient,
00038         kVisual
00039     };
00040 
00041     class Brush : public DWFOwnable
00042     {
00043     public:
00044         // serialize as an XML element
00045         virtual ~Brush() throw() {}
00046         virtual WT_Result serializeElement( WT_XAML_File &, DWFCore::DWFXMLSerializer * ) const = 0;
00047         virtual const eType type() const = 0;
00048         virtual bool operator==( const Brush& ) const = 0;
00049 
00050         static size_t PrintColor( wchar_t* buf, size_t bufSize, const WT_RGBA32& rColor );
00051         static WT_Result ReadColor( WT_RGBA32& rColor, const char* zBuf );
00052     };
00053 
00054     //SolidColorBrush
00055     class SolidColor : public Brush
00056     {
00057     public:
00058         SolidColor();
00059         SolidColor( const WT_RGBA32 &r );
00060         ~SolidColor() throw();
00061         virtual bool operator==( const Brush& ) const;
00062         const eType type() const { return kSolidColor; }
00063     public:
00064         virtual WT_Result set( const WT_RGBA32 &r );
00065         virtual WT_Result materializeAttribute( WT_XAML_File &, const char * );
00066         virtual WT_Result serializeElement( WT_XAML_File &, DWFCore::DWFXMLSerializer * ) const;
00067         virtual const WT_RGBA32& color() const;
00068         virtual const DWFString& colorString() const;
00069     private:
00070         WT_RGBA32 _oColor;
00071         DWFString _szColorString;
00072     };    
00073 
00074     //ImageBrush
00075     class Image: public Brush, public XamlResource
00076     {
00077     public:
00078         Image();
00079         ~Image() throw();
00080         bool operator==( const Brush& ) const;
00081         const eType type() const { return kImage; }
00082     public:
00083         WT_Result serializeElement( WT_XAML_File &, DWFCore::DWFXMLSerializer * ) const;
00084     };    
00085 
00086     //RadialGradientBrush
00087     class RadialGradient: public Brush
00088     {
00089     public:
00090         RadialGradient();
00091         ~RadialGradient() throw();
00092         virtual bool operator==( const Brush& ) const;
00093         const eType type() const { return kRadialGradient; }
00094     public:
00095         virtual WT_Result serializeElement( WT_XAML_File &, DWFCore::DWFXMLSerializer * ) const;
00096     };    
00097 
00098     //LinearGradientBrush - this implementation only assumes two colors, needs work if more gradient stops are needed
00099     class LinearGradient: public Brush
00100     {
00101     public:
00102         LinearGradient();
00103         ~LinearGradient() throw();
00104         virtual bool operator==( const Brush& ) const;
00105         const eType type() const { return kLinearGradient; }
00106 
00107     public:
00108         virtual const WT_Point2D& startPoint() const { return _oStartPt; }
00109         virtual WT_Point2D& startPoint() { return _oStartPt; }
00110         virtual const WT_Point2D& endPoint() const { return _oEndPt; }
00111         virtual WT_Point2D& endPoint() { return _oEndPt; }
00112 
00113         virtual const WT_RGBA32& startColor() const { return _oStartColor; }
00114         virtual WT_RGBA32& startColor() { return _oStartColor; }
00115         virtual const WT_RGBA32& endColor() const { return _oEndColor; }
00116         virtual WT_RGBA32& endColor() { return _oEndColor; }
00117 
00118     private:
00119         WT_Point2D _oStartPt, _oEndPt;
00120         WT_RGBA32 _oStartColor, _oEndColor;
00121 
00122     public:
00123         virtual WT_Result serializeElement( WT_XAML_File &, DWFCore::DWFXMLSerializer * ) const;
00124     };    
00125 
00126     //
00127     // VisualBrush
00128     //
00129     // note : since <VisualBrush> almost always need a lot of drawable content,
00130     // it needs to be referenced as a resource
00131     //
00132     class Visual: public Brush, public XamlResource
00133     {
00134     public:
00135 
00136         Visual();
00137         ~Visual() throw();
00138         virtual bool operator==( const Brush& ) const;
00139         const eType type() const { return kVisual; }
00140 
00141     public:
00142 
00143         virtual WT_Result serializeElement( WT_XAML_File &, DWFCore::DWFXMLSerializer * ) const;
00144     };    
00145 
00146     //
00147     // image brush translator, derived from Image
00148     //
00149     class XamlImageBrush : public Image
00150     {
00151     public :
00152 
00153         //Need this empty constructor to create ImageBrush shell
00154         //while materialization
00155         XamlImageBrush()
00156             : _zName()
00157             , _oXfo()
00158             , _nDpi(-1)
00159             , _nWidth(0)
00160             , _nHeight(0)
00161         {}
00162 
00163         XamlImageBrush(
00164             const DWFString &,                              // name
00165             const WT_Matrix2D &,                            // image xfo
00166             WT_Unsigned_Integer16,                          // width > 0
00167             WT_Unsigned_Integer16);                         // height > 0
00168 
00169         XamlImageBrush(
00170             const DWFString &,                              // name
00171             const WT_Matrix2D &,                            // image xfo
00172             WT_Integer32,                                   // Scanned Resolution dpi
00173             WT_Unsigned_Integer16,                          // width > 0
00174             WT_Unsigned_Integer16);                         // height > 0
00175 
00176         ~XamlImageBrush() throw();
00177 
00178         //
00179         // from XamlBrush::Visual
00180         //
00181         WT_Result serializeElement(
00182             WT_XAML_File &,                                 // current file
00183             DWFCore::DWFXMLSerializer *) const;             // XML utility, !=0
00184 
00185         //
00186         // from XamlResource
00187         //
00188         bool operator==(
00189             const XamlResource&) const;                     // comparee
00190 
00191         //
00192         // from XamlResource
00193         //
00194         XamlResource *copy() const;
00195         
00196         //
00197         // from XamlResource
00198         //
00199         eResourceType resourceType() const;
00200         
00201         //
00202         // from XamlResource
00203         //
00204         WT_Result serializeResource(
00205             const wchar_t*,                                 // key, != 0
00206             WT_XAML_File &,                                 // current file
00207             DWFXMLSerializer &) const;                      // xml serializer
00208 
00209     private :
00210 
00211         DWFString _zName;
00212         WT_Matrix2D _oXfo;
00213         WT_Integer32 _nDpi;
00214         WT_Unsigned_Integer16 _nWidth;
00215         WT_Unsigned_Integer16 _nHeight;
00216     };
00217 
00218     //
00219     // user hatch XAML translator, built as a visual brush
00220     //
00221     // the hatch definition comes from a WT_User_Hatch_Pattern::Hatch_Pattern
00222     // multi-patterns hatches will have to use multiple XamlHatchBrush
00223     // instances.
00224     //
00225     class XamlHatchBrush : public Visual
00226     {
00227     public :
00228 
00229         //
00230         // ctor, holding the w2d pattern definition data
00231         // the HatchPattern's smart pointer is incremented
00232         //
00233         XamlHatchBrush(
00234            WT_User_Hatch_Pattern::Hatch_Pattern *);   // ptr from w2d
00235 
00236         //
00237         // dtor
00238         // the HatchPattern's smart pointer is decremented
00239         //
00240         ~XamlHatchBrush() throw();
00241 
00242         //
00243         // from XamlBrush::Visual
00244         //
00245         WT_Result serializeElement(
00246             WT_XAML_File &,                                 // current file
00247             DWFCore::DWFXMLSerializer *) const;             // XML utility, !=0
00248 
00249         //
00250         // from XamlResource
00251         //
00252         bool operator==(
00253             const XamlResource&) const;                     // comparee
00254 
00255         //
00256         // from XamlResource
00257         //
00258         XamlResource *copy() const;
00259         
00260         //
00261         // from XamlResource
00262         //
00263         eResourceType resourceType() const;
00264         
00265         //
00266         // from XamlResource
00267         //
00268         WT_Result serializeResource(
00269             const wchar_t*,                                 // key, != 0
00270             WT_XAML_File &,                                 // current file
00271             DWFXMLSerializer &) const;                      // xml serializer
00272 
00273     private :
00274 
00275         WT_User_Hatch_Pattern::Hatch_Pattern *_pPat;  // ptr from w2d
00276     };
00277 
00278     //
00279     // fill pattern XAML translator, built as a visual brush
00280     //
00281     //
00282     class XamlFixedPatternBrush : public Visual
00283     {
00284     public :
00285 
00286         //
00287         // ctor, holding the w2d pattern definition data
00288         // the HatchPattern's smart pointer is incremented
00289         //
00290         // note : Solid is _not_ supported (use the SolidColor brush
00291         // instead) and UserDefined won't draw anything
00292         //
00293         XamlFixedPatternBrush(
00294             WT_Fill_Pattern::WT_Pattern_ID,                 // what pattern ?
00295             double);                                        // pattern scale
00296 
00297         //
00298         // dtor
00299         // the HatchPattern's smart pointer is decremented
00300         //
00301         ~XamlFixedPatternBrush() throw();
00302 
00303         //
00304         // from XamlBrush::Visual
00305         //
00306         WT_Result serializeElement(
00307             WT_XAML_File &,                                 // current file
00308             DWFCore::DWFXMLSerializer *) const;             // XML utility, !=0
00309 
00310         //
00311         // from XamlResource
00312         //
00313         bool operator==(
00314             const XamlResource&) const;                     // comparee
00315 
00316         //
00317         // from XamlResource
00318         //
00319         XamlResource *copy() const;
00320         
00321         //
00322         // from XamlResource
00323         //
00324         eResourceType resourceType() const;
00325         
00326         //
00327         // from XamlResource
00328         //
00329         WT_Result serializeResource(
00330             const wchar_t*,                                 // key, != 0
00331             WT_XAML_File &,                                 // current file
00332             DWFXMLSerializer &) const;                      // xml serializer
00333 
00334     private :
00335 
00336         WT_Fill_Pattern::WT_Pattern_ID  _eId;               // what pattern ?
00337         double                       _fScale;               // pattern scale
00338     };
00339 
00340     //
00341     // user-defined pattern XAML translator, built as a visual brush
00342     //
00343     //
00344     class XamlUserPatternBrush : public Visual
00345     {
00346     public :
00347 
00348         //
00349         // ctor, holding the w2d pattern definition data
00350         // the FillPattern's smart pointer is incremented
00351         //
00352         XamlUserPatternBrush(
00353             WT_User_Fill_Pattern::Fill_Pattern *,     // what pattern ?
00354             double);                                        // pattern scale
00355 
00356         //
00357         // dtor
00358         // the FillPattern's smart pointer is decremented
00359         //
00360         ~XamlUserPatternBrush() throw();
00361 
00362         //
00363         // from XamlBrush::Visual
00364         //
00365         WT_Result serializeElement(
00366             WT_XAML_File &,                                 // current file
00367             DWFCore::DWFXMLSerializer *) const;             // XML utility, !=0
00368 
00369         //
00370         // from XamlResource
00371         //
00372         bool operator==(
00373             const XamlResource&) const;                     // comparee
00374 
00375         //
00376         // from XamlResource
00377         //
00378         XamlResource *copy() const;
00379         
00380         //
00381         // from XamlResource
00382         //
00383         eResourceType resourceType() const;
00384         
00385         //
00386         // from XamlResource
00387         //
00388         WT_Result serializeResource(
00389             const wchar_t*,                                 // key, != 0
00390             WT_XAML_File &,                                 // current file
00391             DWFXMLSerializer &) const;                      // xml serializer
00392 
00393     private :
00394 
00395         WT_User_Fill_Pattern::Fill_Pattern *_pPat;          // pattern spec, != 0
00396         double _fScale;                                     // pattern scale
00397     };
00398 
00399 }
00400 
00401 #endif //XAML_BRUSHES
00402 

Generated on Tue Jan 6 22:40:05 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5