brshattr.h

Go to the documentation of this file.
00001 // $Id: brshattr.h 1688 2006-08-10 12:05:20Z gerry $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // Brush Attribute header
00100 
00101 #ifndef INC_BRSHATTR
00102 #define INC_BRSHATTR
00103 
00104 //#include "attrval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 //#include "cxfrech.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "nodeattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "brshdata.h"
00108 #include "brpress.h"
00109 #include "samplist.h"
00110 
00111 class BrushPointInfo;
00112 class FreeHandTool;
00113 class CDistanceSampler;
00114 
00115 
00116 
00117 
00118 #define BRUSHPOINTSCACHE
00119 #define PRESSURE_INVALID 65536
00120 
00121 
00122 /********************************************************************************************
00123 
00124 >   class BrushAttrValue : public AttributeValue
00125 
00126     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00127     Created:    7/1/97
00128 
00129     Purpose:    Brush attribute value
00130                 
00131     Notes:      This AttrValue just contains a pointer to a path processor which will
00132                 apply brush path objects and attributes to the attributee, so to speak.
00133 
00134 ********************************************************************************************/
00135 
00136 class BrushAttrValue : public AttributeValue
00137 {
00138     CC_DECLARE_DYNAMIC(BrushAttrValue)
00139 
00140 #ifdef NEWFASTBRUSHES
00141 private:
00142     NodeBitmap* pCachedBitmap;
00143     Node* pBoundsParent;
00144 public:
00145     NodeBitmap* GetCachedBitmap () { return (pCachedBitmap); }
00146     void SetBoundsParent (Node* parent) { pBoundsParent = parent; }
00147     Node* GetBoundsParent () { return (pBoundsParent); }
00148     void SetCachedBitmap (NodeBitmap* pBitmap) { pCachedBitmap = pBitmap; }
00149 #endif
00150 
00151 public:         // Construction/Initialisation
00152     BrushAttrValue();
00153     BrushAttrValue(PathProcessorBrush *pPathProcessor);
00154     ~BrushAttrValue();
00155 
00156     static BOOL Init(void);
00157     
00158 
00159 public:         // Overridden access methods
00160     virtual void Render(RenderRegion *pRegion, BOOL Temp = FALSE);
00161     virtual void Restore(RenderRegion *pRegion, BOOL Temp);
00162     virtual void GoingOutOfScope(RenderRegion *pRegion);
00163 
00164     virtual void SimpleCopy(AttributeValue *pValue);
00165     virtual NodeAttribute *MakeNode();
00166 
00167     virtual BOOL IsDifferent(AttributeValue *pAttr);
00168 
00169     virtual BrushAttrValue &operator=(BrushAttrValue &Attrib);
00170     virtual INT32 operator==(const BrushAttrValue &Attrib);
00171 
00172     virtual BOOL Blend(BlendAttrParam* pBlendParam);
00173 
00174     BOOL DoBecomeA(BecomeA* pBecomeA, Node* pParent);
00175 
00176     //Bounding box functions
00177     BOOL EffectsParentBounds();
00178     DocRect GetAttrBoundingRect(NodeRenderableInk* pParent = NULL, CCAttrMap* pAttribMap = NULL);
00179     static BOOL RotateBounds(double Angle, DocRect* pBounds, DocCoord* pCentre = NULL );
00180 
00181     void SetCachedRect(DocRect Rect);
00182     void TransformCachedRect(TransformBase& Trans);
00183 
00184 public:     // interface to the path processor
00185     void                SetPathProcessor(PathProcessorBrush *pNewProcessor);
00186     PathProcessorBrush *GetPathProcessor(void)  const   { return(m_pProcessor); };
00187             // Get the path processor for this Brush type (may be NULL)
00188     
00189 // access to the various caches that we use
00190     
00191 public: // access to the points cache
00192     void FlushCache();  // flushes the points cache
00193     void TransformCache(TransformBase& Trans);      // transform the points in the cache
00194     void SetCache(PointsMap* pMap);
00195     PointsMap* GetCache() {return m_pCachedPoints;}
00196     
00197 public: // access to the timestamp cache
00198     TimeStampList* GetTimeStampList() { return m_pTimeStampList;}
00199     void SetTimeStampList(TimeStampList* pList);
00200     BOOL IsTimeStamping();
00201     
00202     // access to our repositioning flag
00203     void  SetTimeStampUpdateType(ListUpdateType Update);
00204     ListUpdateType GetTimeStampUpdateType();
00205 
00206     // functions to make sure the timestamp list is all in order
00207     void CalculateProportionalDistances(MILLIPOINT PathLength);
00208     void TransformTimeStampList(TransformBase& Trans);
00209     BOOL DeleteTimeStampPoints(MILLIPOINT StartDistance, MILLIPOINT EndDistance, 
00210                                 TimeStampList* pRemovedPoints = NULL);
00211     BOOL DeleteTimeStampPoints(MILLIPOINT StartDistance, UINT32 NumPoints, 
00212                                 TimeStampList* pRemovedPoints = NULL);
00213     BOOL AddTimeStampPoints(TimeStampList* pNewPoints, MILLIPOINT StartDistance);
00214     BOOL RecalculateTimeStampList(Path* pPath);
00215     BOOL RepositionPointsByProportion(Path* pPath);
00216     BOOL RepositionPointsByPosition(Path* pPath);
00217     
00218     TimeStampList* CopyTimeStampList();
00219 
00220     BOOL WriteTimeStampList(BaseCamelotFilter *pFilter);
00221 
00222 public: // access to the old pressure cache
00223     void    SetPresssureCache(CDistanceSampler* pPress);
00224     CDistanceSampler* GetPressureCache();
00225     UINT32  GetPressureValue(UINT32 Index);
00226     BOOL    SetPressureValue(UINT32 Index, PressureItem Value);
00227     
00228     void    CalculatePressureArrayProportions(MILLIPOINT PathLength);
00229 
00230 public: // access to the new pressure cache
00231 
00232     void    PressureSpacingChange(MILLIPOINT OldSpacing, MILLIPOINT NewSpacing);
00233     void    FlushPressureCache();
00234 
00235     INT32   GetPressureListIndexAtDistance(MILLIPOINT Distance);
00236     // functions to add to or remove points from our list
00237     BOOL DeletePressurePoints(MILLIPOINT StartDistance, MILLIPOINT EndDistance, 
00238                                 SampleArray* pRemovedPoints = NULL);
00239     BOOL DeletePressurePoints(UINT32 StartIndex, size_t NumPoints, 
00240                                 SampleArray* pRemovedPoints = NULL);
00241     BOOL AddPressurePoints(CSampleData* pNewPoints, MILLIPOINT StartDistance);
00242     BOOL AddPressurePoints(CSampleData* pNewPoints, UINT32 StartIndex);
00243     
00244 
00245     // access to our repositioning flag
00246     void  SetPressureUpdateType(ListUpdateType Update);
00247     ListUpdateType GetPressureUpdateType();
00248 
00249     CDistanceSampler* CopyPressureCache(); // makes a duplicate pressure cache
00250 
00251     BOOL    WritePressureData(BaseCamelotFilter *pFilter); // writes the list to a filter
00252 
00253 protected: // pressure helper fns.
00254         BOOL RepositionPressureDataByPosition(Path* pPath);
00255 
00256 public:
00257     // line width functions
00258     void                ScaleToLineWidth(MILLIPOINT Width); 
00259     MILLIPOINT          GetDefaultLineWidth(BOOL IgnorePressure = FALSE);
00260 
00261     // access to our brush definition
00262     BrushDefinition*    GetBrushDefinition(void);
00263     BrushHandle         GetBrushHandle(void);
00264     
00265 protected:  // helper functions
00266     void InitialisePointsCache();
00267     void FlushTimeStampCache();  // time stamp data is too valuable to be public
00268 
00269     static void ShuffleArrayUp(PressureArray* pPressure, UINT32 StartIndex);
00270     static void ShuffleArrayDown(PressureArray* pPressure, UINT32 StartIndex);
00271 
00272     static UINT32 BlendUINT32(UINT32 First, UINT32 Second, double BlendRatio);
00273     static INT32 BlendINT32(INT32 First, INT32 Second, double BlendRatio);
00274     static double BlendDouble(double First, double Second, double BlendRatio);
00275 
00276     // timestamping helpers
00277     BOOL RecalculateDistances(Path* pPath); 
00278     BOOL RecalculateTangents(Path* pPath);
00279     BOOL SortTimeStampingList();
00280     BOOL GetRidOfCrapFromList(Path* pPath);
00281 
00282 
00283 private:
00284     PathProcessorBrush *m_pProcessor;           // Pointer to the PPS we use (if any)
00285 
00286 
00287 #ifdef BRUSHPOINTSCACHE 
00288     PointsMap* m_pCachedPoints;                // caches the points along the path (unless we're timestamping)
00289 #endif   
00290 
00291     TimeStampList* m_pTimeStampList;            // if we are using timestamped points keep 'em here
00292 
00293     PressureArray* m_pPressureVals;
00294 
00295     CDistanceSampler* m_pPressureSampler;     // the latest incarnation of the pressure data cache
00296     DocRect        m_CachedBRect;
00297 
00298     ListUpdateType m_TimeStampUpdateType;  // indicates what kind of update we have to perform on 
00299                                                 // the timestamping list following an edit
00300     ListUpdateType  m_PressureUpdateType; 
00301 
00302 };
00303 
00304 
00305 
00306 
00307 /***********************************************************************************************
00308 
00309 >   class AttrBrushType : public NodeAttribute
00310 
00311     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00312     Created:    7/1/97
00313 
00314     Purpose:    BrushType attribute
00315                 BrushType attributes are very simple, and merely contain a BrushTypeAttrValue,
00316                 which is the entity which holds all the info and does all the work.
00317 
00318 ***********************************************************************************************/
00319 
00320 class AttrBrushType : public NodeAttribute
00321 {
00322     CC_DECLARE_DYNCREATE(AttrBrushType)
00323 
00324 public:     // Constructors
00325     AttrBrushType();
00326     AttrBrushType(Node *ContextNode,
00327                      AttachNodeDirection Direction,
00328                      BOOL Locked    = FALSE,
00329                      BOOL Mangled   = FALSE,
00330                      BOOL Marked    = FALSE,
00331                      BOOL Selected  = FALSE);
00332     ~AttrBrushType();
00333 
00334 public: // regular attribute virtual fns.
00335     virtual void Render(RenderRegion *pRender);
00336     virtual void CopyNodeContents(AttrBrushType *NodeCopy);
00337     virtual INT32 operator==(const NodeAttribute& NodeAttrib);
00338     virtual Node *SimpleCopy();
00339     virtual UINT32 GetAttrNameID(void);
00340     virtual void GetDebugDetails(StringBase *Str);
00341     virtual UINT32 GetNodeSize() const;
00342     virtual void Transform( TransformBase& );
00343     virtual BOOL WritePreChildrenWeb(BaseCamelotFilter *pFilter);
00344     virtual BOOL WritePreChildrenNative(BaseCamelotFilter *pFilter);
00345 
00346     virtual AttributeValue* GetAttributeValue()     { return(&m_Value); };
00347 
00348     virtual BOOL NeedsTransparency() const;
00349 
00350     virtual BOOL Blend(BlendAttrParam* pBlendParam);
00351 
00352     virtual SubtreeRenderState RenderSubtree(RenderRegion *pRender, Node** ppNextNode = NULL, BOOL bClip = TRUE);
00353 
00354     BOOL DoBecomeA(BecomeA* pBecomeA, Node* pParent);
00355     virtual void PolyCopyNodeContents(NodeRenderable* pNodeCopy);
00356 
00357     //Bounding box functions
00358     virtual BOOL EffectsParentBounds();
00359     virtual DocRect GetAttrBoundingRect(NodeRenderableInk* pParent = NULL, CCAttrMap* pAttribMap = NULL);
00360 
00361     virtual BOOL IsABrush() const;
00362     virtual BOOL ShouldBeOptimized() { return TRUE;}
00363 
00364     void NodePathUpdated(Path* pPath);
00365 
00366     BOOL OnReplaceAttribute(AttrBrushType* pOther);
00367         // call when this attribute is being used to replace pOther
00368 
00369 public:  // access functions - these are actually an interface to the path processor 
00370          // of m_Value
00371         String_32 GetBrushName();
00372         BOOL SetSpacing(MILLIPOINT NewSpacing);
00373         BOOL SetScaling(double NewScale);
00374         BOOL SetPathOffsetType(PathOffset NewOffsetType);
00375         BOOL SetPathOffsetValue(MILLIPOINT NewOffsetValue);
00376         BOOL SetTiled(BOOL Tiled);
00377         BOOL SetRotated(BOOL Rotated);
00378         BOOL SetRotateAngle(double NewAngle);
00379         PathProcessorBrush* GetPathProcessor();
00380         BrushDefinition* GetBrushDefinition();
00381         BrushHandle      GetBrushHandle(void);
00382         MILLIPOINT GetSpacing();
00383         MILLIPOINT GetDefaultLineWidth(BOOL IgnorePressure = FALSE);
00384         
00385         void SetUseLocalTransp(BOOL UseTransp);
00386 public:
00387         // Cache access functions
00388         void FlushCache();
00389         void SetCache(PointsMap* pMap);
00390         PointsMap* GetCache();
00391         
00392         // timestamping access fns.
00393         TimeStampList* GetTimeStampList();
00394         BOOL IsTimeStamping();
00395 
00396         // pressure access fns.
00397         void SetPressureCache(CDistanceSampler* pSamp);
00398         CDistanceSampler* GetPressureCache();
00399         BOOL ContainsPressureCache();
00400     
00401         BOOL ReversePressureCache();  // reverse list belonging to this attribute
00402 
00403         
00404         BOOL CanUsePointsCache();
00405 
00406         // assorted other access fns.
00407         MILLIPOINT GetAppliedLineWidth();
00408         void       SetValueToScaleTo(MILLIPOINT LineWidth);
00409         DocColour  GetLocalStrokeColour();
00410         void       SetBlendedStrokeColour(DocColour* pCol);
00411         
00412         UINT32     GetLocalTranspValue();
00413         UINT32     GetLocalTranspType();
00414 
00415         static BOOL RotateBounds(double Angle, DocRect* pBounds) ;
00416         void ClearCachedRect();
00417 
00418         void SetFreeHandTool(FreeHandTool* pTool); 
00419 public:     // BrushData functions  
00420         void InitialiseBrushData();
00421         BrushData GetBrushData();
00422         void SetBrushData(BrushData NewData);
00423 
00424 public: // other
00425         void GetMaxScalingFromDefinition();
00426         BOOL IsParentSelected();
00427 
00428 protected:
00429         void FindNearestStrokeColour();  // looks for the nearest applied stroke colour and caches it
00430         void FindNearestStrokeTransp();
00431         
00432 protected:
00433         BrushAttrValue m_Value;
00434 
00435         DocColour*      m_pLocalStrokeColour; // the nearest stroke colour
00436         DocColour*      m_pBlendedStrokeColour;  // the current stroke colour if we are in a blend
00437         BrushData       m_BrushData;
00438 
00439         FreeHandTool*  m_pFreeTool;
00440             
00441         UINT32          m_LocalTranspValue; // stores the applied stroke transparency
00442         UINT32          m_LocalTranspType;
00443 };
00444 
00445 
00446 /***********************************************************************************************
00447 
00448 >   class BrushAttrRecordHandler : public CamelotRecordHandler
00449 
00450     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00451     Created:    7/1/97
00452     Purpose:    Handles the reading of all brush attribute records
00453                 
00454 ***********************************************************************************************/
00455 
00456 class CXaraFileRecord;
00457 
00458 class BrushAttrRecordHandler : public CamelotRecordHandler
00459 {
00460     CC_DECLARE_DYNAMIC(BrushAttrRecordHandler);
00461 
00462 public:
00463     BrushAttrRecordHandler() : CamelotRecordHandler() { m_pLastAttribute = NULL;}
00464     ~BrushAttrRecordHandler() {}
00465 
00466     // functions that must be implemented.
00467     virtual UINT32 *GetTagList();
00468     virtual BOOL HandleRecord(CXaraFileRecord *pCXaraFileRecord);
00469 
00470     // handling of atomic TAG_STROKEDEFINITION tags
00471     virtual BOOL BeginSubtree(UINT32 Tag);
00472     virtual BOOL EndSubtree(UINT32 Tag);
00473 
00474 
00475 
00476 protected: //helper functions
00477     BOOL HandleBrushAttributeRecord(CXaraFileRecord* pRecord);
00478     BOOL HandleBrushDataRecord(CXaraFileRecord* pRecord);
00479     BOOL HandleMoreBrushDataRecord(CXaraFileRecord* pRecord);
00480     BOOL HandleMoreBrushAttrRecord(CXaraFileRecord* pRecord);
00481     BOOL HandleEvenMoreBrushData(CXaraFileRecord* pRecord);
00482     BOOL HandleEvenMoreBrushAttr(CXaraFileRecord* pRecord);
00483     BOOL HandleTimeStampData(CXaraFileRecord* pRecord);
00484     BOOL HandlePressureInfo(CXaraFileRecord* pRecord);
00485     BOOL HandleAttrPressureInfo(CXaraFileRecord* pRecord);
00486     BOOL HandlePressureData(CXaraFileRecord* pRecord);
00487     BOOL HandlePressureSampleData(CXaraFileRecord* pRecord);
00488     BOOL HandleAttrFillFlags(CXaraFileRecord* pRecord);
00489     BOOL HandleTranspInfo(CXaraFileRecord* pRecord);
00490     BOOL HandleAttrTranspInfo(CXaraFileRecord* pRecord);
00491 
00492 
00493 #ifdef XAR_TREE_DIALOG
00494     virtual void GetRecordDescriptionText(CXaraFileRecord* pRecord, StringBase* pStr);
00495 #endif
00496 
00497 protected:
00498     // keeps track of the last brush attribute we imported
00499     static AttrBrushType* m_pLastAttribute;
00500 
00501 };
00502 
00503 #endif

Generated on Sat Nov 10 03:44:31 2007 for Camelot by  doxygen 1.4.4