cnamecol.cpp

Go to the documentation of this file.
00001 // $Id: cnamecol.cpp 1282 2006-06-09 09:46:49Z alex $
00002 // $Header:
00003 // CNamedColourReplacer class implementation
00004 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00005 ================================XARAHEADERSTART===========================
00006  
00007                Xara LX, a vector drawing and manipulation program.
00008                     Copyright (C) 1993-2006 Xara Group Ltd.
00009        Copyright on certain contributions may be held in joint with their
00010               respective authors. See AUTHORS file for details.
00011 
00012 LICENSE TO USE AND MODIFY SOFTWARE
00013 ----------------------------------
00014 
00015 This file is part of Xara LX.
00016 
00017 Xara LX is free software; you can redistribute it and/or modify it
00018 under the terms of the GNU General Public License version 2 as published
00019 by the Free Software Foundation.
00020 
00021 Xara LX and its component source files are distributed in the hope
00022 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00023 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00024 See the GNU General Public License for more details.
00025 
00026 You should have received a copy of the GNU General Public License along
00027 with Xara LX (see the file GPL in the root directory of the
00028 distribution); if not, write to the Free Software Foundation, Inc., 51
00029 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00030 
00031 
00032 ADDITIONAL RIGHTS
00033 -----------------
00034 
00035 Conditional upon your continuing compliance with the GNU General Public
00036 License described above, Xara Group Ltd grants to you certain additional
00037 rights. 
00038 
00039 The additional rights are to use, modify, and distribute the software
00040 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00041 library and any other such library that any version of Xara LX relased
00042 by Xara Group Ltd requires in order to compile and execute, including
00043 the static linking of that library to XaraLX. In the case of the
00044 "CDraw" library, you may satisfy obligation under the GNU General Public
00045 License to provide source code by providing a binary copy of the library
00046 concerned and a copy of the license accompanying it.
00047 
00048 Nothing in this section restricts any of the rights you have under
00049 the GNU General Public License.
00050 
00051 
00052 SCOPE OF LICENSE
00053 ----------------
00054 
00055 This license applies to this program (XaraLX) and its constituent source
00056 files only, and does not necessarily apply to other Xara products which may
00057 in part share the same code base, and are subject to their own licensing
00058 terms.
00059 
00060 This license does not apply to files in the wxXtra directory, which
00061 are built into a separate library, and are subject to the wxWindows
00062 license contained within that directory in the file "WXXTRA-LICENSE".
00063 
00064 This license does not apply to the binary libraries (if any) within
00065 the "libs" directory, which are subject to a separate license contained
00066 within that directory in the file "LIBS-LICENSE".
00067 
00068 
00069 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00070 ----------------------------------------------
00071 
00072 Subject to the terms of the GNU Public License (see above), you are
00073 free to do whatever you like with your modifications. However, you may
00074 (at your option) wish contribute them to Xara's source tree. You can
00075 find details of how to do this at:
00076   http://www.xaraxtreme.org/developers/
00077 
00078 Prior to contributing your modifications, you will need to complete our
00079 contributor agreement. This can be found at:
00080   http://www.xaraxtreme.org/developers/contribute/
00081 
00082 Please note that Xara will not accept modifications which modify any of
00083 the text between the start and end of this header (marked
00084 XARAHEADERSTART and XARAHEADEREND).
00085 
00086 
00087 MARKS
00088 -----
00089 
00090 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00091 designs are registered or unregistered trademarks, design-marks, and/or
00092 service marks of Xara Group Ltd. All rights in these marks are reserved.
00093 
00094 
00095       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00096                         http://www.xara.com/
00097 
00098 =================================XARAHEADEREND============================
00099  */
00100 
00101 #include "camtypes.h"
00102 #include "cnamecol.h"
00103 //#include "fillval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "doccolor.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 
00106 
00107 CC_IMPLEMENT_DYNCREATE(CNamedColourReplacer, CCObject);
00108 CC_IMPLEMENT_DYNCREATE(CHSVChanger, CNamedColourReplacer);
00109 CC_IMPLEMENT_DYNAMIC(CTransparencyReplacer, CCObject);
00110 
00111 const INT32 MAX_SAT_VALUE = 255;
00112 const INT32 MAX_HUE_VALUE = 360;
00113 const INT32 MIN_VALUE = 0;
00114 const INT32 MAX_TRANSPARENCY = 255;
00115 
00116 /***********************************************************************************************
00117 
00118 >   CNamedColourReplacer::CNamedColourReplacer()
00119 
00120     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00121     Created:    12/4/2000
00122 
00123     Purpose:    Constructor
00124 
00125 ***********************************************************************************************/
00126 
00127 CNamedColourReplacer::CNamedColourReplacer()
00128 {
00129     m_pColourFill    = NULL;
00130     m_pReplaceColour = NULL;
00131 }
00132 
00133 /***********************************************************************************************
00134 
00135 >   CNamedColourReplacer::CNamedColourReplacer(ColourFillAttribute* pFillAttr, DocColour* pColour)
00136 
00137     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00138     Created:    12/4/2000
00139     Inputs:     pFillAttr - the attribute value that we want to replace the colours in
00140                 pColour - the colour we wish to replace them with
00141     Purpose:    Constructor with initialisation
00142 
00143 ***********************************************************************************************/
00144 
00145 CNamedColourReplacer::CNamedColourReplacer(ColourFillAttribute* pFillAttr, DocColour* pColour)
00146 {
00147     // call the default constructor that NULLs all the member pointers
00148     CNamedColourReplacer::CNamedColourReplacer();
00149     Initialise(pFillAttr, pColour);
00150 }
00151 
00152 
00153 /***********************************************************************************************
00154 
00155 >   CNamedColourReplacer::~CNamedColourReplacer()
00156 
00157     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00158     Created:    12/4/2000
00159 
00160     Purpose:    Destructor
00161 
00162 ***********************************************************************************************/
00163 
00164 CNamedColourReplacer::~CNamedColourReplacer()
00165 {
00166 
00167 }
00168 
00169 /***********************************************************************************************
00170 
00171 >   CNamedColourReplacer::Initialise(ColourFillAttribute* pFillAttr, DocColour* pColour)
00172 
00173     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00174     Created:    12/4/2000
00175     Inputs:     pFillAttr - the attribute value that we want to replace the colours in
00176                 pColour - the colour we wish to replace them with
00177     Purpose:    initialisation function.
00178 
00179 ***********************************************************************************************/
00180 
00181 BOOL CNamedColourReplacer::Initialise(ColourFillAttribute* pFillAttr, DocColour* pColour)
00182 {
00183     if (pFillAttr == NULL || pColour == NULL)
00184         return FALSE;
00185 
00186     m_pColourFill = pFillAttr;
00187     m_pReplaceColour = pColour;
00188 
00189     return TRUE;
00190 }
00191 
00192 
00193 /***********************************************************************************************
00194 
00195 >   BOOL CNamedColourReplacer::IsInitialised()
00196 
00197     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00198     Created:    12/4/2000
00199     Inputs:     -
00200     Retuns:     TRUE if our important members have been initialised, FALSE otherwise
00201     Purpose:    as above
00202 
00203 ***********************************************************************************************/
00204 
00205 BOOL CNamedColourReplacer::IsInitialised()
00206 {
00207     return ((m_pColourFill != NULL) && (m_pReplaceColour != NULL));
00208 }
00209 
00210 
00211 /***********************************************************************************************
00212 
00213 >   BOOL CNamedColourReplacer::ReplaceColours()
00214 
00215     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00216     Created:    12/4/2000
00217     Inputs:     -
00218     Returns:    TRUE if all went well, FALSE if something went wrong
00219     Purpose:    This function asks the colour fill for its start colour, checks to see
00220                 if they are named, or if they were created by a named colour. If so it copies them 
00221                 and stores them.  It then replaces them with our replacement colour.
00222 
00223 ***********************************************************************************************/
00224 
00225 BOOL CNamedColourReplacer::ReplaceColours()
00226 {
00227 //  PORTNOTETRACE("other","CNamedColourReplacer::ReplaceColours - do nothing");
00228 //#ifndef EXCLUDE_FROM_XARALX
00229     if (m_pColourFill == NULL || m_pReplaceColour == NULL)
00230     {
00231         ERROR3("CNamedColourReplacer not initialised correctly");
00232         return FALSE;
00233     }
00234 
00235     // we only replace the start colour, so as to maintain the effect on
00236     // 2/3/4 colour fills
00237     DocColour* pOrigStartCol = m_pColourFill->GetStartColour();
00238     if (pOrigStartCol != NULL && pOrigStartCol->IsNamed())
00239     {
00240         // we've got one, so stash the original and replace it
00241         m_StartColour = *pOrigStartCol;
00242         m_pColourFill->SetStartColour(m_pReplaceColour);
00243         
00244     }
00245 
00246     return TRUE;
00247 //#else
00248 //  return FALSE;
00249 //#endif
00250 }
00251 
00252 
00253 /***********************************************************************************************
00254 
00255 >   BOOL CNamedColourReplacer::RestoreColours()
00256 
00257     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00258     Created:    12/4/2000
00259     Inputs:     -
00260     Returns:    TRUE if all went well, FALSE if something went wrong
00261     Purpose:    This function assumes that ReplaceColours has been previously called.  It uses its
00262                 pointers to start and end colours to set colours in the attribute.
00263 
00264 ***********************************************************************************************/
00265 
00266 BOOL CNamedColourReplacer::RestoreColours()
00267 {
00268 //  PORTNOTETRACE("other","CNamedColourReplacer::RestoreColours - do nothing");
00269 //#ifndef EXCLUDE_FROM_XARALX
00270     if (m_pColourFill == NULL)
00271     {
00272         ERROR3("Colour fill is NULL in CNamedColourReplacer::RestoreColours");
00273         return FALSE;
00274     }
00275 
00276     // restore our colour
00277     if (m_StartColour.GetReservedFlag() == COL_NAMED)
00278         m_pColourFill->SetStartColour(&m_StartColour);
00279     
00280 
00281     return TRUE;
00282 //#else
00283 //  return FALSE;
00284 //#endif
00285 }
00286 
00287 
00288 /***********************************************************************************************
00289 
00290 >   ColourFillAttribute* CNamedColourReplacer::GetColourFill()
00291 
00292     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00293     Created:    12/4/2000
00294     Inputs:     -
00295     Returns:    pointer to the attribute that we are replacing colours in
00296     Purpose:    access fn.
00297 
00298 ***********************************************************************************************/
00299 
00300 ColourFillAttribute* CNamedColourReplacer::GetColourFill()
00301 {
00302     return m_pColourFill;
00303 }
00304 
00305 
00306 
00307 /***********************************************************************************************
00308 
00309 >   BOOL CNamedColourReplacer::SetColourFill(ColourFillAttribute* pAttr)
00310 
00311     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00312     Created:    12/4/2000
00313     Inputs:     pAttr - pointer to a colour fill attribute that we wish to replace the colours in
00314     Returns:    TRUE, unless you pass in a duff pointer
00315     Purpose:    access fn.
00316 
00317 ***********************************************************************************************/
00318 
00319 BOOL CNamedColourReplacer::SetColourFill(ColourFillAttribute* pAttr)
00320 {
00321     if (pAttr == NULL)
00322         return FALSE;
00323     m_pColourFill = pAttr;
00324     return TRUE;
00325 }
00326 
00327 
00328 
00329 /***********************************************************************************************
00330 
00331 >   DocColour* CNamedColourReplacer::GetReplacementColour()
00332 
00333     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00334     Created:    12/4/2000
00335     Inputs:     -
00336     Returns:    pointer to the the colour we are using to replace
00337     Purpose:    access fn.
00338 
00339 ***********************************************************************************************/
00340 
00341 DocColour* CNamedColourReplacer::GetReplacementColour()
00342 {
00343     return m_pReplaceColour;
00344 }
00345 
00346 
00347 /***********************************************************************************************
00348 
00349 >   BOOL CNamedColourReplacer::SetReplacementColour(DocColour* pColour)
00350 
00351     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00352     Created:    12/4/2000
00353     Inputs:     pColour - the colour we wish to set in our attribute
00354     Returns:    TRUE, unless the colour is NULL
00355     Purpose:    access fn.
00356 
00357 ***********************************************************************************************/
00358 
00359 BOOL CNamedColourReplacer::SetReplacementColour(DocColour* pColour)
00360 {
00361     if (pColour == NULL)
00362         return FALSE;
00363     m_pReplaceColour = pColour;
00364     return TRUE;
00365 }
00366 
00367 
00368 /*-----------------------------------------------------------------------------------------------
00369 -------------------------------------------------------------------------------------------------
00370 ------------------------------CSHVCHANGER CLASS IMPLEMENTATION-----------------------------------
00371 ------------------------------------------------------------------------------------------------*/
00372 
00373 
00374 /***********************************************************************************************
00375 
00376 >   CHSVChanger::CHSVChanger()
00377 
00378     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00379     Created:    12/4/2000
00380 
00381     Purpose:    default constructor
00382 
00383 ***********************************************************************************************/
00384 
00385 CHSVChanger::CHSVChanger() : CNamedColourReplacer()
00386 {
00387     m_HueMultiplier         = 1.0;
00388     m_SaturationMultiplier  = 1.0;
00389     m_ValueMultiplier       = 1.0;
00390     m_HueIncrement          = 0;
00391     m_SatIncrement          = 0;
00392 }
00393 
00394 
00395 /***********************************************************************************************
00396 
00397 >   CHSVChanger::CHSVChanger()
00398 
00399     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00400     Created:    12/4/2000
00401 
00402     Purpose:    default constructor
00403 
00404 ***********************************************************************************************/
00405 
00406 CHSVChanger::CHSVChanger(ColourFillAttribute* pFill, DocColour* pCol) : CNamedColourReplacer(pFill, pCol)
00407 {
00408     m_HueMultiplier         = 1.0;
00409     m_SaturationMultiplier  = 1.0;
00410     m_ValueMultiplier       = 1.0;
00411     m_HueIncrement          = 0;
00412     m_SatIncrement          = 0;
00413 
00414 }
00415 
00416 /***********************************************************************************************
00417 
00418 >   CHSVChanger::~CHSVChanger()
00419 
00420     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00421     Created:    12/4/2000
00422 
00423     Purpose:    destructor
00424 
00425 ***********************************************************************************************/
00426 
00427 CHSVChanger::~CHSVChanger()
00428 {
00429 //  PORTNOTETRACE("other","CHSVChanger::~CHSVChanger - do nothing");
00430 //#ifndef EXCLUDE_FROM_XARALX
00431     // have to do a hack here to ensure that we don't decrement the usage count on 
00432     // indexed colours which we never incremented in the first place
00433     m_OrigStartCol.HackColReplacerPreDestruct();
00434     m_OrigEndCol1.HackColReplacerPreDestruct();
00435     m_OrigEndCol2.HackColReplacerPreDestruct();
00436     m_OrigEndCol3.HackColReplacerPreDestruct();
00437 //#endif
00438 }
00439 
00440 
00441 /***********************************************************************************************
00442 
00443 >   virtual BOOL CHSVChanger::ReplaceColours()
00444 
00445     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00446     Created:    12/4/2000
00447     Inputs:     -
00448     Returns:    TRUE if all went well, FALSE if something went wrong
00449     Purpose:    This function asks the colour fill for its colours one by one, checks to see
00450                 if they are named, or if they were created by a named colour. If so it copies them 
00451                 and stores them.  It then replaces them with our replacement colour.
00452 
00453 ***********************************************************************************************/
00454 
00455 BOOL CHSVChanger::ReplaceColours()
00456 {
00457     // if we also want to replace colours then do that first
00458     if (m_pReplaceColour != NULL)
00459         return CNamedColourReplacer::ReplaceColours();
00460 
00461     return TRUE;
00462 }
00463 
00464 
00465 /***********************************************************************************************
00466 
00467 >   BOOL CHSVChanger::ChangeHSVValues()
00468 
00469     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00470     Created:    12/4/2000
00471     Inputs:     -
00472     Returns:    TRUE if all went well, FALSE if something went wrong
00473     Purpose:    The raison d'etre of this object.  Changes the HSV values of the member fill
00474 ***********************************************************************************************/
00475 
00476 BOOL CHSVChanger::ChangeHSVValues()
00477 {
00478     if (m_pColourFill == NULL)
00479     {
00480         ERROR3("Colour fill is NULL in CHSVChanger::ChangeHSVValues");
00481         return FALSE;
00482     }
00483     
00484     // we need to ask for the colours one by one
00485     DocColour* pStartCol = NULL;
00486     if (m_pReplaceColour != NULL)
00487         pStartCol = m_pReplaceColour;
00488     else
00489         pStartCol = m_pColourFill->GetStartColour();
00490     
00491     if (pStartCol != NULL)
00492     {
00493         m_OrigStartCol = *pStartCol;
00494         ApplyIncrements(pStartCol);
00495         m_pColourFill->SetStartColour(pStartCol);
00496     }
00497 
00498     DocColour* pEndCol1 = m_pColourFill->GetEndColour();
00499     if (pEndCol1 != NULL) 
00500     {
00501         // first record our original values
00502         m_OrigEndCol1 = *pEndCol1;
00503         ApplyIncrements(pEndCol1);
00504     }
00505     
00506     DocColour* pEndCol2 = m_pColourFill->GetEndColour2();
00507     if (pEndCol2 != NULL) 
00508     {
00509         // first record our original values
00510         m_OrigEndCol2 = *pEndCol2;
00511         ApplyIncrements(pEndCol2);
00512     }
00513 
00514     DocColour* pEndCol3 = m_pColourFill->GetEndColour3();
00515     if (pEndCol3 != NULL)
00516     {
00517         // first record our original values
00518         m_OrigEndCol3 = *pEndCol3;
00519         ApplyIncrements(pEndCol3);
00520     }
00521     
00522     return TRUE;
00523 }
00524 
00525 
00526 
00527 /***********************************************************************************************
00528 
00529 >   BOOL CHSVChanger::RestoreColours()
00530 
00531     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00532     Created:    12/4/2000
00533     Inputs:     -
00534     Returns:    TRUE if all went well, FALSE if something went wrong
00535     Purpose:    Restores the colours that were changed
00536 
00537 ***********************************************************************************************/
00538 BOOL CHSVChanger::RestoreColours()
00539 {
00540     if (m_pColourFill == NULL)
00541         return FALSE;
00542 
00543     // here we restore any named colours we replaced
00544     if (m_pReplaceColour != NULL)
00545         return CNamedColourReplacer::RestoreColours();
00546 
00547     // we need to ask for the colours one by one
00548     DocColour* pStartCol = m_pColourFill->GetStartColour();
00549     if (pStartCol != NULL)
00550     {
00551         *pStartCol = m_OrigStartCol;
00552     }
00553 
00554     DocColour* pEndCol1 = m_pColourFill->GetEndColour();
00555     if (pEndCol1 != NULL) 
00556     {
00557         *pEndCol1 = m_OrigEndCol1;
00558 
00559     }
00560     
00561     DocColour* pEndCol2 = m_pColourFill->GetEndColour2();
00562     if (pEndCol2 != NULL) 
00563     {
00564         *pEndCol2 = m_OrigEndCol2;
00565     }
00566 
00567     DocColour* pEndCol3 = m_pColourFill->GetEndColour3();
00568     if (pEndCol3 != NULL)
00569     {
00570         *pEndCol3 = m_OrigEndCol3;
00571     }
00572     
00573     return TRUE;    
00574 
00575 
00576 
00577 }
00578 
00579 
00580 /***********************************************************************************************
00581 
00582 >   BOOL CHSVChanger::IsInitialised()
00583 
00584     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00585     Created:    12/4/2000
00586     Inputs:     -
00587     Returns:    true, if this object was initialised in any way
00588     Purpose:    
00589 ***********************************************************************************************/
00590 
00591 BOOL CHSVChanger::IsInitialised()
00592 {
00593     BOOL Init = m_pReplaceColour != NULL ||
00594                 m_HueMultiplier != 1.0 || 
00595                 m_SaturationMultiplier != 1.0;
00596 
00597     return Init;
00598 }
00599 
00600 /***********************************************************************************************
00601 
00602 >   BOOL CHSVChanger::ShouldChangeHSV()
00603 
00604     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00605     Created:    12/4/2000
00606     Inputs:     -
00607     Returns:    true, if ChangeHSV should be called, FALSE otherwise
00608     Purpose:    does a few checks to see if it is worth changing hsv values, currently we only use
00609                 the multipliers so it just checks to see if they are default or not
00610 ***********************************************************************************************/
00611 
00612 BOOL CHSVChanger::ShouldChangeHSV()
00613 {
00614     BOOL bShouldReplace = (m_HueIncrement != 0 || m_SatIncrement != 0);
00615 
00616     return bShouldReplace;
00617 }
00618 
00619 
00620 
00621 /***********************************************************************************************
00622 
00623 >   void CHSVChanger::ApplyIncrements(DocColour* pCol)
00624 
00625     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00626     Created:    12/4/2000
00627     Inputs:     pCol - the colour to be incremented
00628     Returns:    -
00629     Purpose:    Takes a colour, extracts its HSV values, adds (or subtracts) the increment value
00630 
00631 ***********************************************************************************************/
00632 
00633 void CHSVChanger::ApplyIncrements(DocColour* pCol)
00634 {
00635 //  PORTNOTETRACE("other","CHSVChanger::ApplyIncrements - do nothing");
00636 //#ifndef EXCLUDE_FROM_XARALX
00637     if (pCol == NULL)
00638     {
00639         ERROR3("Colour pointer is NULL in CHSVChanger::ApplyIncrements");
00640         return;
00641     }
00642 
00643     INT32 Hue;
00644     INT32 Sat;
00645     INT32 Dummy;
00646 
00647     pCol->GetHSVValue(&Hue, &Sat, &Dummy);
00648     //TRACEUSER( "Diccon", _T("Original Sat = %d, "), Sat);
00649     //TRACEUSER( "Diccon", _T("Original Hue = %d, "), Hue);
00650     Hue += m_HueIncrement;
00651     if (Hue < 0)
00652         Hue += MAX_HUE_VALUE;
00653     else if (Hue > MAX_HUE_VALUE)
00654         Hue -= MAX_HUE_VALUE;
00655 
00656     Sat -= abs(m_SatIncrement);
00657         if (Sat < 0)
00658         Sat = 1;
00659     else if (Sat > MAX_SAT_VALUE)
00660         Sat = MAX_SAT_VALUE;
00661     
00662 //  TRACEUSER( "Diccon", _T("SatIncr = %d, New Sat = %d\n"), m_SatIncrement, Sat);
00663 //  TRACEUSER( "Diccon", _T("Hue Incr = %d, New Hue = %d\n"), m_HueIncrement, Hue);
00664     pCol->SetHSVValue(Hue, Sat, Dummy);
00665 //#endif
00666 }
00667 
00668 
00669 /***********************************************************************************************
00670 
00671 >   CHSVChanger::GetHueMultiplier()
00672     
00673     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00674     Created:    12/4/2000
00675     Inputs:     -
00676     Outputs:    -
00677     Returns:    the hue multiplier, duh
00678     Purpose:    Access
00679 
00680 ***********************************************************************************************/
00681 
00682 double CHSVChanger::GetHueMultiplier()
00683 {
00684     return m_HueMultiplier;
00685 }
00686 
00687 
00688 /***********************************************************************************************
00689 
00690 >   BOOL CHSVChanger::SetHueMultiplier(double Mult)
00691     
00692     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00693     Created:    12/4/2000
00694     Inputs:     the hue multiplier, duh
00695     Outputs:    -
00696     Returns:    always TRUE at the moment
00697     Purpose:    Sets the Hue multiplier, also calculates the value that will be added/subtracted
00698                 from the colour
00699 
00700 ***********************************************************************************************/
00701 
00702 BOOL CHSVChanger::SetHueMultiplier(double Value)
00703 {
00704     m_HueMultiplier = Value;
00705     m_HueIncrement = (INT32)Value; // * (double)MAX_HUE_VALUE);
00706     //TRACEUSER( "Diccon", _T("Hue Increment = %d\n"), m_HueIncrement);
00707     return TRUE;
00708 }
00709 
00710 /***********************************************************************************************
00711 
00712 >   CHSVChanger::GetSaturationMultiplier()
00713     
00714     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00715     Created:    12/4/2000
00716     Inputs:     -
00717     Outputs:    -
00718     Returns:    the Saturation multiplier, duh
00719     Purpose:    Access
00720 
00721 ***********************************************************************************************/
00722 
00723 double CHSVChanger::GetSaturationMultiplier()
00724 {
00725     return m_SaturationMultiplier;
00726 }
00727 
00728 
00729 /***********************************************************************************************
00730 
00731 >   BOOL CHSVChanger::SetSaturationMultiplier(double Value)
00732     
00733     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00734     Created:    12/4/2000
00735     Inputs:     the Saturation multiplier, as you might expect
00736     Outputs:    -
00737     Returns:    TRUE 
00738     Purpose:    Sets the saturation multiplier, also calculates the addition/subtraction value
00739 
00740 ***********************************************************************************************/
00741 
00742 BOOL CHSVChanger::SetSaturationMultiplier(double Value)
00743 {
00744     m_SaturationMultiplier = Value;
00745 
00746     m_SatIncrement = (INT32)(Value * (double)MAX_SAT_VALUE);
00747     
00748     //TRACEUSER( "Diccon", _T("Sat increment = %d\n"), m_SatIncrement);
00749     return TRUE;
00750 }
00751 
00752 
00753 /***********************************************************************************************
00754 
00755 >   void CHSVChanger::ChangeColour(DocColour* pCol)
00756     
00757     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00758     Created:    12/4/2000
00759     Inputs:     pCol - pointer to the colour we wish to change
00760     Outputs:    Colour with changed values
00761     Returns:    -
00762     Purpose:    Simply changes the values in this one colour alone, in case you're fed up of 
00763                 worrying about attributes and the like
00764 **********************************************************************************************/
00765 
00766 void CHSVChanger::ChangeColour(DocColour* pCol)
00767 {
00768     if (pCol == NULL)
00769         return;
00770     ApplyIncrements(pCol);
00771 }
00772 
00773 
00774 
00775 /*----------------------------------------------------------------------------------------------
00776 ----------------------CTransparency Class implementation----------------------------------------
00777 ------------------------------------------------------------------------------------------------*/
00778 
00779 
00780 /***********************************************************************************************
00781 
00782 >   CTransparencyReplacer::CTransparencyReplacer()
00783 
00784     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00785     Created:    12/4/2000
00786 
00787     Purpose:    default constructor
00788 
00789 ***********************************************************************************************/
00790 
00791 CTransparencyReplacer::CTransparencyReplacer()
00792 {
00793     m_pTranspFill = NULL;
00794     m_OriginalTransp = 0;
00795     m_ReplaceTransp = -1;
00796     m_TranspAdjust  = 1.0;
00797     m_InvertAdjust = 1.0;
00798 }
00799 
00800 
00801 /***********************************************************************************************
00802 
00803 >   BOOL CTransparencyReplacer::SetReplacementValue(INT32 Value)
00804 
00805     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00806     Created:    12/4/2000
00807     Inputs:     the value to use as our replacement
00808     Returns:    TRUE unless Value is outside the legal range
00809     Purpose:    access
00810 
00811 ***********************************************************************************************/
00812 
00813 BOOL CTransparencyReplacer::SetReplacementValue(INT32 Value)
00814 {
00815     if (Value > MAX_TRANSP_VALUE)
00816         return FALSE;
00817 
00818     m_ReplaceTransp = Value;
00819     return TRUE;
00820 }
00821 
00822 
00823 /***********************************************************************************************
00824 
00825 >   INT32 CTransparencyReplacer::GetReplacementValue()
00826 
00827     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00828     Created:    12/4/2000
00829     Inputs:     -
00830     Returns:    out replacement transparency value
00831     Purpose:    access
00832 
00833 ***********************************************************************************************/
00834 
00835 INT32 CTransparencyReplacer::GetReplacementValue()
00836 {
00837     return m_ReplaceTransp;
00838 }
00839 
00840 
00841 /***********************************************************************************************
00842 
00843 >   BOOL CTransparencyReplacer::SetAdjustmentValue(double Value)
00844 
00845     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00846     Created:    12/4/2000
00847     Inputs:     our adjuster value
00848     Returns:    TRUE unless Value is outside the legal range
00849     Purpose:    access
00850 
00851 ***********************************************************************************************/
00852 
00853 BOOL CTransparencyReplacer::SetAdjustmentValue(double Value)
00854 {
00855     if (Value > 3.0 || Value < 0)
00856         return FALSE;
00857     m_TranspAdjust = Value;
00858     
00859     return TRUE;
00860 }
00861 
00862 
00863 /***********************************************************************************************
00864 
00865 >   BOOL CTransparencyReplacer::GetAdjustmentValue(double Value)
00866 
00867     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00868     Created:    12/4/2000
00869     Inputs:     
00870     Returns:    our adjuster value
00871     Purpose:    access
00872 
00873 ***********************************************************************************************/
00874 
00875 double CTransparencyReplacer::GetAdjustmentValue()
00876 {
00877     return m_TranspAdjust;
00878 }
00879 
00880 
00881 /***********************************************************************************************
00882 
00883 >   BOOL CTransparencyReplacer::SetInvertedAdjuster(double Value)
00884 
00885     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00886     Created:    12/4/2000
00887     Inputs:     our adjuster value
00888     Returns:    TRUE unless Value is outside the legal range
00889     Purpose:    access to our inverted adjuster 
00890 
00891 ***********************************************************************************************/
00892 
00893 BOOL CTransparencyReplacer::SetInvertedAdjuster(double Value)
00894 {
00895     if (Value > 3.0 || Value < 0)
00896         return FALSE;
00897     m_InvertAdjust = Value;
00898     
00899     return TRUE;
00900 }
00901 
00902 
00903 /***********************************************************************************************
00904 
00905 >   BOOL CTransparencyReplacer::GetAdjustmentValue1(double Value)
00906 
00907     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00908     Created:    12/4/2000
00909     Inputs:     
00910     Returns:    our inverted adjuster value
00911     Purpose:    access
00912 
00913 ***********************************************************************************************/
00914 
00915 double CTransparencyReplacer::GetInvertedAdjuster()
00916 {
00917     return m_InvertAdjust;
00918 }
00919 
00920 
00921 
00922 /***********************************************************************************************
00923 
00924 >   void CTransparencyReplacer::SetTransparencyAttr(TranspFillAttribute* pAttrVal)
00925 
00926     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00927     Created:    12/4/2000
00928     Inputs:     pAttrVal - the transparency attribute value that we are working on
00929     Returns:    -
00930     Purpose:    access
00931 
00932 ***********************************************************************************************/
00933 
00934 void CTransparencyReplacer::SetTransparencyAttr(TranspFillAttribute* pAttrVal)
00935 {
00936     m_pTranspFill = pAttrVal;
00937 }
00938 
00939 
00940 /***********************************************************************************************
00941 
00942 >   BOOL CTransparencyReplacer::ReplaceTransparency()
00943 
00944     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00945     Created:    12/4/2000
00946     Inputs:     -
00947     Returns:    -
00948     Purpose:    Does the deed of replacing the transparency value in our attribute with the one
00949                 we have been given
00950 
00951 ***********************************************************************************************/
00952 
00953 BOOL CTransparencyReplacer::ReplaceTransparency()
00954 {
00955     if (m_pTranspFill == NULL)
00956         return FALSE;
00957 
00958     // first cache the original value
00959     m_OriginalTransp = *m_pTranspFill->GetStartTransp();
00960     
00961     // recall that a negative replacement value means don't replace
00962     if (m_ReplaceTransp >= 0)
00963         m_pTranspFill->Transp = (UINT32)m_ReplaceTransp;
00964 
00965     if (m_TranspAdjust >= 0)
00966     {
00967         /* Ok, so what is going on here?  Basically this:
00968         - We have two adjusters, they both generate a value which is a proportion of the maximum transparency
00969         - One of the adjusters is inverted (i.e. as its value increases, its output value decreases 
00970         - Both adjusters make sure they are within legal limits 
00971         - The adjuster value is added to the original value
00972         - We take a straight mean of the two adjusted values and set it back to the attribute
00973         */
00974 
00975         double TranspAdj = m_TranspAdjust * MAX_TRANSPARENCY;
00976         double TranspAdj1 = m_InvertAdjust * MAX_TRANSPARENCY;
00977 
00978         INT32 Adjust = INT32(TranspAdj); 
00979         Adjust -= MAX_TRANSPARENCY;
00980 
00981         INT32 InvertAdjust = INT32(MAX_TRANSPARENCY- TranspAdj1);
00982         
00983         INT32 FirstTransp = m_pTranspFill->Transp + Adjust;
00984         
00985         INT32 FinalTransp = FirstTransp + InvertAdjust;
00986 
00987         if (FinalTransp > MAX_TRANSPARENCY)
00988             FinalTransp = MAX_TRANSPARENCY;
00989         if (FinalTransp < 0)
00990             FinalTransp = 0;
00991     //  TRACEUSER( "Diccon", _T("New Transp = %d\n"), FinalTransp);
00992         m_pTranspFill->Transp = UINT32(FinalTransp); 
00993     }
00994 
00995     return TRUE;
00996 }
00997 
00998 
00999 /***********************************************************************************************
01000 
01001 >   BOOL CTransparencyReplacer::RestoreTransparency()
01002 
01003     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
01004     Created:    12/4/2000
01005     Inputs:     -
01006     Returns:    -
01007     Purpose:    Does the deed of replacing the transparency value in our attribute with the one
01008                 we have been given
01009 
01010 ***********************************************************************************************/
01011 
01012 BOOL CTransparencyReplacer::RestoreTransparency()
01013 {
01014     if (m_pTranspFill == NULL)
01015         return FALSE;
01016 
01017     m_pTranspFill->Transp = m_OriginalTransp;
01018 
01019     return TRUE;
01020 }
01021 
01022 
01023 /***********************************************************************************************
01024 
01025 >   BOOL CTransparencyReplacer::IsInitialised()
01026 
01027     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
01028     Created:    12/4/2000
01029     Inputs:     -
01030     Returns:    True if the replacer has been initialised and is ready to replace, false otherwise
01031     Purpose:    as above
01032 ***********************************************************************************************/
01033 
01034 BOOL CTransparencyReplacer::IsInitialised()
01035 {
01036     return (m_pTranspFill != NULL && (m_ReplaceTransp >= 0 || m_TranspAdjust >= 0));
01037 }

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