brushdlg.cpp

Go to the documentation of this file.
00001 // $Id: brushdlg.cpp 1732 2006-09-03 14:08:16Z alex $
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 #include "camtypes.h"       // the precompiled stuff
00100 
00101 DECLARE_SOURCE("$Revision: 1732 $");
00102 
00103 #include "brushdlg.h"       // include our class header
00104 #include "dlgmgr.h"
00105 
00106 //#include "brdlgres.h"     // include our resources
00107 //#include "barsdlgs.h"
00108 #include "brshattr.h"
00109 #include "brshdata.h"       // for BrushData
00110 #include "ppbrush.h"
00111 //#include "rikdlg.h"           // _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER)
00112 //#include "rik.h"
00113 #include "optsmsgs.h"
00114 //#include "redraw.h"           // for REDRAWCLASS custom control
00115 #include "qualattr.h"
00116 #include "ccdc.h"
00117 
00118 #include "brushop.h"
00119 #include "brushmsg.h"
00120 
00121 #include "opbevel.h"
00122 #include "freeinfo.h"
00123 #include "sgline.h"
00124 //#include "fixstr32.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00125 //#include "resource.h"
00126 #include "freehand.h"
00127 //#include "fixst256.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00128 
00129 // firstly - I apologise for the lack of comments in this code - BUT I have more important
00130 // things to be doing than writing comments at the moment ....
00131 
00132 // BUT here are some helpful ones ....
00133 
00134 // There are two types of Handle function:  Handle_____Msg  =>  which respond to ::message for the
00135 //                                                              active tab
00136 //                                          Handle_____     =>  which handle messages to/from
00137 //                                                              controls; and interact with
00138 //                                                              functions that read the data
00139 
00140 // All Init_____ functions are responsible for initialising the relevant controls
00141 
00142 // All ReInit____ functions firstly reset the state of all relevant controls to active, and then
00143 // call the relevant Init_____ functions to update the controls again (i.e.  this is how controls
00144 // are enabled/disabled depending upon the selection).
00145 
00146 // All Read____ functions get the actual data from the controls
00147 
00148 // The CBrushEditDlg::Message () function is a bit nasty (take a look at it for more details).
00149 // BUT, first and foremost it is a pig because I have tried to make this dialog box behave
00150 // like a normal dialog box:  1) don't shut down when ENTER is pressed, and 2) update the values
00151 // of the brush directly when EDIT is pressed ....
00152 
00153 // CGS
00154 
00155 CC_IMPLEMENT_DYNCREATE( CBrushEditDlg,  DialogTabOp )//DialogOp )
00156 
00157 const INT32 MinSpacingSlider = 0;
00158 const INT32 MaxSpacingSlider = 99;
00159 const INT32 MinOffsetSlider = 0;
00160 const INT32 MaxOffsetSlider = 100;
00161 const INT32 MinScalingSlider = 0;
00162 const INT32 MaxScalingSlider = 99;
00163 const INT32 MinMultiSlider   = 90;
00164 const INT32 MaxMultiSlider  = 110;
00165 const INT32 MinScalingIncrSlider = -50;
00166 const INT32 MaxScalingIncrSlider    = 50;
00167 const double DefaultRotationAngle = 0;
00168 
00169 const INT32   MIN_ROTATION_SLIDER = 0;
00170 const INT32  MAX_ROTATION_SLIDER = 360;
00171 const INT32   MIN_ROTATION_INCR_SLIDER = -180;
00172 const INT32   MAX_ROTATION_INCR_SLIDER = 180;
00173 const INT32  MAX_ROTATION_RANDOM_SLIDER = 360;
00174 const INT32   MIN_RANDOM_SLIDER = 0;
00175 const INT32   MAX_RANDOM_SLIDER = 100;
00176 const INT32  MAX_RANDOM_SAT_SLIDER = 100;
00177 const INT32  MAX_RANDOM_HUE_SLIDER = 360;
00178 const INT32   MIN_SPACING_INCR = -10;
00179 const INT32   MAX_SPACING_INCR = 10;
00180 const INT32  MIN_PRESSURE_SLIDER =  0;
00181 const INT32  MAX_PRESSURE_SLIDER = 100;
00182 const INT32    MAXSPACINGMULTIPLIER = 5;
00183 const INT32  MAXOFFSETMULTIPLIER = 3;
00184 const INT32  MIN_TRANSP_SLIDER   = 0;
00185 const INT32  MAX_TRANSP_SLIDER   = 200;
00186 const double ExpFactor = 1.6;
00187 const double InvFactor = 1/ExpFactor;
00188 
00189 // Bodge alert - MinSliderSpacing should really be equal to the function shown, however
00190 // rounding problems meant that this caused problems.
00191 const double MinSliderSpacing = 75; //pow((double)MIN_BRUSH_SPACING, 1/ExpFactor);
00192 
00193 
00194 const double MinOffset = 0;
00195 const double MaxOffset = 300;
00196 
00197 
00198 #define new CAM_DEBUG_NEW
00199 
00200 const   UINT32      CBrushEditDlg::IDD   =  _R(IDD_BRUSHEDIT);
00201 const   CDlgMode    CBrushEditDlg::Mode  =  MODELESS;
00202 BOOL CBrushEditDlg::m_bIsOpen = FALSE;
00203 
00204 
00205 /********************************************************************************************
00206 
00207 >   CBrushEditDlg::CBrushEditDlg ()
00208 
00209     Author:     This comment by Diccon (function originally by ChrisS)
00210     Created:    Comment added 15/12/2000
00211     Inputs:     -
00212     Outputs:    -
00213     Returns:    -
00214     Purpose:    Default constructor for CBrushEditDlg
00215     Errors:     -
00216     SeeAlso:    -
00217 
00218 ********************************************************************************************/
00219 
00220 CBrushEditDlg::CBrushEditDlg ()
00221     : DialogTabOp/*DialogOp*/( CBrushEditDlg::IDD, CBrushEditDlg::Mode )
00222 {
00223     FirstTime = TRUE;
00224     
00225     EditingBrushDef = FALSE;
00226     
00227     m_Handle   = BrushHandle_NoBrush;
00228 
00229     RenderType = RT_LINE;
00230 
00231     pDocUnitList = NULL;
00232     CurrentUserUnitType = NOTYPE;
00233     
00234     UsingRandomSpacing = FALSE;  
00235     UsingRandomOffset = FALSE;
00236     UsingRandomScaling = FALSE;
00237 
00238     EditGadgetLostFocus = 0;
00239 
00240     pAttrBrush_m = NULL;
00241 }
00242 
00243 
00244 /********************************************************************************************
00245 
00246 >   CBrushEditDlg::~CBrushEditDlg ()
00247 
00248     Author:     This comment by Diccon (function originally by ChrisS)
00249     Created:    Comment added 15/12/2000
00250     Inputs:     -
00251     Outputs:    -
00252     Returns:    -
00253     Purpose:    Destructor
00254     Errors:     -
00255     SeeAlso:    -
00256 
00257 ********************************************************************************************/
00258 
00259 
00260 CBrushEditDlg::~CBrushEditDlg ()
00261 {
00262     if (OriginalData != NULL)
00263         delete (OriginalData);
00264     if (EditData != NULL)
00265         delete (EditData);
00266 }
00267 
00268 
00269 /********************************************************************************************
00270 
00271 >   BOOL CBrushEditDlg::Init ()
00272 
00273     Author:     This comment by Diccon (function originally by ChrisS)
00274     Created:    Comment added 15/12/2000
00275     Inputs:     -
00276     Outputs:    -
00277     Returns:    -
00278     Purpose:    the init function to register us as an Op
00279     Errors:     -
00280     SeeAlso:    -
00281 
00282 ********************************************************************************************/
00283 
00284 
00285 BOOL CBrushEditDlg::Init ()
00286 {
00287     return (
00288     
00289                 RegisterOpDescriptor
00290                 (
00291                     0,                                  // Tool ID
00292                     _R(IDS_BRUSHEDITDLG),                   // String resource ID
00293                     CC_RUNTIME_CLASS (CBrushEditDlg),   // Runtime class
00294                     OPTOKEN_BRUSHEDIT_DLG,              // Token string
00295                     CBrushEditDlg::GetState,            // GetState function
00296                     0,                                  // Help ID
00297                     _R(IDBBL_BRUSHEDIT),                    // Bubble ID
00298                     _R(IDD_BARCONTROLSTORE),                // Resource ID
00299                     _R(IDC_BRUSHEDIT),                      // Control ID
00300                     SYSTEMBAR_EDIT,                     // Bar ID
00301                     TRUE,                               // Recieve system messages
00302                     FALSE,                              // Smart duplicate operation
00303                     TRUE,                               // Clean operation
00304                     0,                                  // No vertical counterpart
00305                     0,                                  // String for one copy only
00306                     ( DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC ) // Auto state flags
00307                 )
00308             );
00309 }
00310 
00311 
00312 /********************************************************************************************
00313 
00314 >   OpState CBrushEditDlg::GetState (String_256* pHelpString,  OpDescriptor*)
00315 
00316     Author:     This comment by Diccon (function originally by ChrisS)
00317     Created:    Comment added 15/12/2000
00318     Inputs:     not used
00319     Outputs:    -
00320     Returns:    the OpState indicating whether or not this op is greyed 
00321     Purpose:    Determines whether or not we can launch this op.  We are allowed to launch in the
00322                 following circumstances:
00323                 - Any tool, one AttrBrushType in the selection
00324                 - FreeHandTool, as above OR brush selected in the brush combo and no document selection
00325 
00326                 Note also that we can only ever have one instance of the dialog open at once
00327     Errors:     -
00328     SeeAlso:    -
00329 
00330 ********************************************************************************************/
00331 
00332 OpState CBrushEditDlg::GetState (String_256* pHelpString,  OpDescriptor*)
00333 {
00334     static OpState DialogState;
00335     
00336     DialogState.Greyed = TRUE;
00337 
00338     // if we have a single brush in the selection then we're ok
00339     AttrBrushType* pAttrBrush = GetSingleSelectedBrushAttribute();
00340     
00341     if (pAttrBrush != NULL && pAttrBrush->GetBrushHandle() != BrushHandle_NoBrush)
00342         DialogState.Greyed = FALSE;
00343 
00344     // if we're in the freehand tool and we our current brush is not default then we're also ok
00345     if (Tool::GetCurrentID() == TOOLID_FREEHAND)
00346     {
00347         FreeHandTool* pTool = (FreeHandTool*)Tool::GetCurrent();
00348         if (pTool->GetBrushHandle() != BrushHandle_NoBrush)
00349             DialogState.Greyed = FALSE;
00350     }
00351 
00352     // we only ever want one instance of the dialog so check our static member
00353     if (m_bIsOpen)
00354         DialogState.Greyed = TRUE;
00355 
00356     return (DialogState);
00357 }
00358 
00359 
00360 /********************************************************************************************
00361 
00362 >   void CBrushEditDlg::Do (OpDescriptor*)
00363 
00364     Author:     This comment by Diccon (function originally by ChrisS)
00365     Created:    Comment added 15/12/2000
00366     Inputs:     not used
00367     Outputs:    -
00368     Returns:    -
00369     Purpose:    launches the brush edit dialog, this method will determine which brush it is
00370                 editing from the document selection.
00371     Errors:     -
00372     SeeAlso:    -
00373 
00374 ********************************************************************************************/
00375 
00376 void CBrushEditDlg::Do (OpDescriptor*)
00377 {
00378     Document * pDocument = Document::GetSelected();
00379     ERROR3IF(pDocument == NULL,"UnitPropertiesDlg::DoWithParam No selected document");
00380 
00381     if (pDocument)
00382         pDocUnitList = pDocument->GetDocUnitList();
00383     ERROR3IF(pDocUnitList == NULL,"UnitPropertiesDlg::DoWithParam No doc unit list attached to this doc yet");
00384 
00385     CurrentUserUnitType = pDocUnitList->GetPageUnits ();
00386 
00387 PORTNOTE("other", "Disabled CBrushGadget")
00388 #ifndef EXCLUDE_FROM_XARALX
00389     // this fn. is called from the ViewContextMenu without any params so here we must initialise it ourselves
00390     //m_pOwningGadget = FreeHandInfoBarOp::GetSpareGadget();
00391     m_pOwningGadget = FreeHandInfoBarOp::GetBrushGadget();
00392     if (m_pOwningGadget != NULL)
00393         m_pOwningGadget->SetBrushDialog(this);
00394 #endif
00395 
00396     EditData = new BrushData;
00397     if (EditData == NULL)
00398         return;
00399     
00400     OriginalData = new BrushData;
00401     m_bDisableGadgets = TRUE;
00402     // we want to see if there is a brush in the selection, in which case grab its data so we
00403     // can initialise everything ok.   Otherwise keep everything disabled
00404     AttrBrushType* pAttrBrush = GetSingleSelectedBrushAttribute();
00405     if (pAttrBrush != NULL)
00406     {
00407         *EditData = pAttrBrush->GetBrushData();
00408         *OriginalData = *EditData;
00409         m_bDisableGadgets = FALSE;
00410         //initialise our opparam with the original data, just in case we want to do change all
00411         ChangeParam_m.SetValues(*EditData);
00412         String_256 Name = EditData->m_Name;
00413         SetName(&Name);
00414     }
00415     else
00416     {
00417         // If we are in the freehand tool then we can launch so long as the tool selected brush is not default
00418         if (Tool::GetCurrentID() == TOOLID_FREEHAND)
00419         {
00420             FreeHandTool* pTool = (FreeHandTool*)Tool::GetCurrent();
00421             BrushHandle Handle = pTool->GetBrushHandle();
00422             if (Handle != BrushHandle_NoBrush)
00423             {
00424                 BrushDefinition* pDef = BrushComponent::FindBrushDefinition(Handle);
00425                 if (pDef != NULL)
00426                 {
00427                     // the definition allocates a new data object for us
00428                     delete EditData;
00429                     EditData = pDef->GetBrushData();
00430                     EditData->m_BrushHandle = Handle;
00431                     *OriginalData = *EditData;
00432                     m_bDisableGadgets = FALSE;
00433                     //initialise our opparam with the original data, just in case we want to do change all
00434                     ChangeParam_m.SetValues(*EditData);
00435                     EditingBrushDef = TRUE;
00436                     String_256 Name = EditData->m_Name;
00437                     SetName(&Name);
00438                 }
00439             }
00440         }
00441     }
00442     
00443     Create ();
00444     Open ();
00445     m_bIsOpen = TRUE;
00446     m_bPreventUpdateSet = FALSE;
00447     m_SliderStarted = FALSE;
00448 }
00449 
00450 
00451 /********************************************************************************************
00452 
00453 >   void CBrushEditDlg::DoWithParam (OpDescriptor*, OpParam* OwningGadgetParams)
00454 
00455     Author:     This comment by Diccon (function originally by ChrisS)
00456     Created:    Comment added 15/12/2000
00457     Inputs:     OwningGadgetParams - recast to get a BrushData object
00458     Outputs:    -
00459     Returns:    -
00460     Purpose:    launches the brush edit dialog, however this the BrushData to initialise the
00461                 dialog is provided through the opparam.
00462                 Note:  I don't think that we use this method anymore.
00463     Errors:     -
00464     SeeAlso:    -
00465 
00466 ********************************************************************************************/
00467 
00468 void CBrushEditDlg::DoWithParam (OpDescriptor*, OpParam* OwningGadgetParams)
00469 {
00470 PORTNOTE("other", "Disabled CBrushGadget")
00471 #ifndef EXCLUDE_FROM_XARALX
00472     m_pOwningGadget  =  reinterpret_cast<CBrushGadget*> (OwningGadgetParams->Param1);
00473     m_pOwningGadget->SetCBrushEditDlg (this);
00474 #endif
00475 
00476     // if theres already one open the don't
00477     if (WindowID != NULL && IsOpen() && IsWindowVisible())
00478         return;
00479 
00480     EditData = new BrushData (*(reinterpret_cast<BrushData*> ((void*)(OwningGadgetParams->Param2))));
00481     // if we're editing the definition then we had to create a brush data from scratch so delete 
00482     // it here
00483     if (EditingBrushDef)
00484     {
00485         BrushData* DeleteData = ((reinterpret_cast<BrushData*> ((void *)(OwningGadgetParams->Param2))));
00486         delete DeleteData;
00487     }
00488     //EditData = reinterpret_cast<BrushData*> (OwningGadgetParams->Param2);
00489     OriginalData = new BrushData (*EditData);
00490 
00491     //initialise our opparam with the original data, just in case we want to do change all
00492     ChangeParam_m.SetValues(*EditData);
00493 
00494     m_bDisableGadgets = FALSE;
00495 
00496 PORTNOTE("other", "Disabled CBrushGadget")
00497 #ifndef EXCLUDE_FROM_XARALX
00498     // get the ID
00499     if (m_pOwningGadget != 0)
00500     {
00501         Id_m = m_pOwningGadget->GetGadgetID ();
00502     }
00503 
00504     if (m_pOwningGadget->GetEditingBrushDefinition ())
00505     {
00506         EditingBrushDef = TRUE;
00507         GetAttributeNodeFromDefinition();
00508     }
00509 #endif
00510 
00511     Document * pDocument = Document::GetSelected();
00512     ERROR3IF(pDocument == NULL,"UnitPropertiesDlg::DoWithParam No selected document");
00513 
00514     if (pDocument)
00515         pDocUnitList = pDocument->GetDocUnitList();
00516     ERROR3IF(pDocUnitList == NULL,"UnitPropertiesDlg::DoWithParam No doc unit list attached to this doc yet");
00517 
00518     CurrentUserUnitType = pDocUnitList->GetPageUnits ();
00519 
00520     String_256 Title (_R(IDS_BRUSHEDITDLGTITLE));
00521     SetName (&Title);
00522     
00523     Create ();
00524     Open ();
00525 
00526 PORTNOTE("other", "Disabled CBrushGadget")
00527 #ifndef EXCLUDE_FROM_XARALX
00528     // tell the owning gadget that this dialog has opened
00529     if (m_pOwningGadget != 0)
00530     {
00531         m_pOwningGadget->DialogHasOpened ();
00532     }
00533 #endif
00534 
00535     m_bIsOpen = TRUE;
00536     m_bPreventUpdateSet = FALSE;
00537     m_SliderStarted = FALSE;
00538 }
00539 
00540 
00541 /********************************************************************************************
00542 
00543 >   BOOL CBrushEditDlg::AddControlsToHelper()
00544 
00545 
00546     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00547     Created:    14/7/2000
00548     Inputs:     -
00549     Outputs:    -
00550     Returns:    TRUE if all went well, FALSE if something went wrong
00551     Purpose:    We need to subclass our edit box controls so we're adding them to the helper here
00552     Errors:     -
00553     SeeAlso:    DialogControlHelper class (DlgCtHlp.h/.cpp)
00554 
00555 ********************************************************************************************/
00556 
00557 BOOL CBrushEditDlg::AddControlsToHelper()
00558 {
00559     // basically we just add 'em in one by one
00560     BOOL ok = AddDialogControlToHelper(_R(IDC_EDITBRUSHSPACING), _R(IDD_BRUSHEDITSPACING));
00561 //  if (ok) ok = AddDialogControlToHelper(_R(IDC_EDITBRUSHSPACINGINCRCONST), _R(IDD_BRUSHEDITSPACING));
00562     if (ok) ok = AddDialogControlToHelper(_R(IDC_EDITPATHOFFSETVALUE), _R(IDD_BRUSHEDITOFFSET));
00563 //  if (ok) ok = AddDialogControlToHelper(_R(IDC_EDITPATHOFFSETINCRCONST), _R(IDD_BRUSHEDITOFFSET));
00564 //  if (ok) ok = AddDialogControlToHelper(_R(IDC_EDITSCALINGINCRCONST), _R(IDD_BRUSHEDITSCALING));
00565     if (ok) ok = AddDialogControlToHelper(_R(IDC_EDITROTATEANGLE), _R(IDD_BRUSHEDITEFFECTS));
00566     if (ok) ok = AddDialogControlToHelper(_R(IDC_EDITROTATEANGLEINCR), _R(IDD_BRUSHEDITEFFECTS));
00567     if (ok) ok = AddDialogControlToHelper(_R(IDC_EDITBRUSHTRANSP), _R(IDD_BRUSHEDITSEQUENCE));
00568 
00569     return ok;
00570 }
00571 
00572 
00573 /********************************************************************************************
00574 
00575 >   BOOL CBrushEditDlg::RemoveControlsFromHelper()
00576 
00577 
00578     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00579     Created:    14/7/2000
00580     Inputs:     -
00581     Outputs:    -
00582     Returns:    -
00583     Purpose:    removing the edit controls from the helper
00584     Errors:     -
00585     SeeAlso:    DialogControlHelper class (DlgCtHlp.h/.cpp)
00586 
00587 ********************************************************************************************/
00588 
00589 void CBrushEditDlg::RemoveControlsFromHelper()
00590 {
00591     BOOL ok = RemoveDialogControlFromHelper(_R(IDC_EDITBRUSHSPACING), _R(IDD_BRUSHEDITSPACING));
00592 //  if (ok) ok = RemoveDialogControlFromHelper(_R(IDC_EDITBRUSHSPACINGINCRCONST), _R(IDD_BRUSHEDITSPACING));
00593     if (ok) ok = RemoveDialogControlFromHelper(_R(IDC_EDITPATHOFFSETVALUE), _R(IDD_BRUSHEDITOFFSET));
00594 //  if (ok) ok = RemoveDialogControlFromHelper(_R(IDC_EDITPATHOFFSETINCRCONST), _R(IDD_BRUSHEDITOFFSET));
00595 //  if (ok) ok = RemoveDialogControlFromHelper(_R(IDC_EDITSCALINGINCRCONST), _R(IDD_BRUSHEDITSCALING));
00596     if (ok) ok = RemoveDialogControlFromHelper(_R(IDC_EDITROTATEANGLE), _R(IDD_BRUSHEDITEFFECTS));
00597     if (ok) ok = RemoveDialogControlFromHelper(_R(IDC_EDITROTATEANGLEINCR), _R(IDD_BRUSHEDITEFFECTS));
00598     if (ok) ok = RemoveDialogControlFromHelper(_R(IDC_EDITBRUSHTRANSP), _R(IDD_BRUSHEDITSEQUENCE));
00599 
00600 
00601     return;
00602 }
00603 
00604 
00605 
00606 /********************************************************************************************
00607 
00608 >   MsgResult CBrushEditDlg::Message (Msg* Message)
00609 
00610 
00611     Author:     This comment by Diccon (function originally by ChrisS)
00612     Created:    Comment added 15/12/2000
00613     Inputs:     -
00614     Outputs:    -
00615     Returns:    -
00616     Purpose:    Message proc for this dialog.  
00617     Errors:     -
00618     SeeAlso:    -
00619 
00620 ********************************************************************************************/
00621 
00622 MsgResult CBrushEditDlg::Message (Msg* Message)
00623 {
00624     BOOL bClose = FALSE;
00625     if (IS_OUR_DIALOG_MSG (Message))
00626     {
00627         DialogMsg* Msg = static_cast<DialogMsg*>( Message );
00628 
00629         CDlgResID ThePage = Msg->PageID;        // the current page
00630 
00631         BOOL MessageAlreadyHandled = FALSE;     // due to the 'multi-pass' nature of the function
00632         INT32 Test = -1;
00633         switch (Msg->DlgMsg)
00634         {
00635             // we don't want the focus ....
00636             case DIM_TITLEFOCUSWARN:
00637             {
00638             //  DialogManager::DefaultKeyboardFocus();
00639             //  MessageAlreadyHandled = TRUE;
00640 
00641                 // this message is sent because the dialog has moved
00642                 BROADCAST_TO_ALL(ScreenChangeMsg());
00643             }
00644             break;
00645 
00646             // we don't want the focus ....
00647             case DIM_CREATE:
00648             {   
00649                 // are we editing a brush definition?
00650                 if (EditingBrushDef)
00651                 {
00652                     // is this the first time the dialog has been created?
00653                     if (FirstTime)
00654                     {
00655                         HideShuffleIrrelevantButtons ();
00656                     
00657                         //ResizeDialogAndCreateBrushPreview ();
00658 
00659                         FirstTime = FALSE;
00660                     }
00661                 }
00662                 else
00663                 {
00664                     if (FirstTime)
00665                     {
00666                         HideShuffleIrrelevantButtons ();
00667                         
00668                         FirstTime = FALSE;
00669                     }
00670                 }
00671                 DialogManager::DefaultKeyboardFocus();
00672             }
00673             break;
00674 
00675             case DIM_SET_ACTIVE:
00676             {
00677                 ReInitPage(ThePage);
00678             }
00679             break;
00680             case DIM_COMMIT:
00681                 // we have renamed the OK button to be Save As New so creat
00682                 // a new brush here
00683                 CreateNewBrush();
00684         
00685             break;
00686         
00687 
00688             case DIM_SOFT_COMMIT:
00689             {
00690                 // soft commit is generated by the apply button, which we have renamed
00691                 // we now wish to save this brush data as the brush definition.
00692                 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_CHANGEBRUSHDEF);
00693                 if (pOpDesc != NULL)
00694                 {
00695                     // make a derived class OpParam from the member, and tell it which definition to edit
00696                     ChangeBrushDefOpParam DefParam;
00697                     DefParam = ChangeParam_m;
00698                     DefParam.ChangeType = CHANGEBRUSH_ALL;
00699                     DefParam.m_Handle = EditData->m_BrushHandle;
00700                     DefParam.m_NewScaling = 1.0;
00701                     pOpDesc->Invoke(&DefParam);
00702 
00703                 }
00704                 EnableGadget(_R(ID_APPLY_NOW), TRUE);
00705             }
00706             break;
00707             // close the dialog ....
00708             case DIM_CANCEL:
00709             {
00710                 TRACEUSER( "Diccon", _T("Closing dialog, EditingBD = %d\n"), EditingBrushDef);
00711                 
00712                 if (EditingBrushDef)
00713                 {
00714                     
00715                     if (pAttrBrush_m != NULL)
00716                         delete pAttrBrush_m;
00717                 }
00718                 m_bIsOpen = FALSE;
00719             
00720             
00721                 Close ();
00722                 bClose = TRUE;
00723                 MessageAlreadyHandled = TRUE;
00724                 
00725             }
00726             break;
00727 
00728         
00729             // handle sliders:
00730             case DIM_SLIDER_POS_CHANGING :
00731             {   
00732                 if (!m_bPreventUpdateSet)
00733                 {
00734                     if (Tool::GetCurrentID() == TOOLID_FREEHAND)
00735                     {
00736                         FreeHandTool* pTool = (FreeHandTool*)Tool::GetCurrent();
00737                         pTool->SetBrushUpdateState(UPDATE_NEVER);
00738                     }
00739                     m_bPreventUpdateSet = TRUE;
00740                 }
00741                 
00742                 HandleSliderPosChanging (Msg);
00743             }
00744             break;
00745 
00746             // handle sliders:  
00747             case DIM_SLIDER_POS_SET:
00748             {
00749             
00750                 if (m_bPreventUpdateSet)
00751                 {
00752                     if (Tool::GetCurrentID() == TOOLID_FREEHAND)
00753                     {
00754                         
00755                         FreeHandTool* pTool = (FreeHandTool*)Tool::GetCurrent();
00756                         pTool->SetBrushUpdateState(UPDATE_ONIDLE);
00757         
00758                     }
00759                     m_bPreventUpdateSet = FALSE;
00760                 }
00761                 
00762                 HandleSliderPosSet (Msg);
00763 
00764             
00765             }
00766             break;
00767             
00768             // handle buttons
00769             case DIM_LFT_BN_CLICKED:
00770             {
00771 
00772                 HandleButtonDown(Msg);
00773                 
00774             }
00775             break;
00776 
00777             // now that we have subclassed our edit boxes this handles both combos and edit boxes
00778             case DIM_SELECTION_CHANGED:
00779             {
00780                 switch (Msg->DlgMsgParam)
00781                 {
00782                     case ENTER_COMMIT:
00783                     Test = 3;
00784                     break;
00785                     case TAB_COMMIT:
00786                         Test = 4;
00787                     break;
00788                     default:
00789 
00790                     break;
00791                 }
00792                 HandleSelectionChange (Msg);
00793             }
00794             break;
00795 
00796             default:
00797                 break;
00798             
00799         }
00800 
00801         // dispatch message to relevant page handler ....
00802         if ( ThePage && !MessageAlreadyHandled)
00803         {
00804             if (FALSE) {}
00805             else if (ThePage == _R(IDD_BRUSHEDITSPACING))
00806                 HandleBrushEditSpacingMsg (Msg);
00807             else if (ThePage == _R(IDD_BRUSHEDITOFFSET))
00808                 HandleBrushEditOffsetMsg (Msg);
00809             else if (ThePage == _R(IDD_BRUSHEDITSCALING))
00810                 HandleBrushEditScalingMsg (Msg);
00811             else if (ThePage == _R(IDD_BRUSHEDITEFFECTS))
00812                 HandleBrushEditEffectMsg (Msg);
00813             else if (ThePage == _R(IDD_BRUSHEDITSEQUENCE))
00814                 HandleBrushEditSequenceMsg (Msg);
00815             else if (ThePage == _R(IDD_BRUSHEDITFILL))
00816                 HandleBrushFillMsg(Msg);
00817             else
00818             {
00819                 ERROR3("Message from unknown tab dialog page");
00820             }
00821         }
00822 
00823     }
00824     else  // deal with non-dialog messages here
00825     {
00826             // this message tells us that the brushdefinition has changed so we need
00827         // to update our preview window
00828         if  (Message->IsKindOf(CC_RUNTIME_CLASS(BrushDefMsg)))
00829         {
00830             
00831             // only if we are editing the definition
00832             if (EditingBrushDef)
00833             {
00834                 // deelete our attribute node, and ask the definition for a new one
00835                 GetAttributeNodeFromDefinition();
00836 
00837             }
00838         }
00839         if (MESSAGE_IS_A(Message, SelChangingMsg))
00840         {
00841             HandleDocSelectionChange();
00842         }
00843     }
00844 
00845     // Pass all unhandled messages to base class for default processing!
00846     MsgResult Result = DialogOp::Message (Message);
00847 
00848     if (bClose)
00849     {   
00850 PORTNOTE("other", "Disabled CBrushGadget")
00851 #ifndef EXCLUDE_FROM_XARALX
00852         // tell the owning gadget that this dialog has closed
00853         if (m_pOwningGadget != 0)
00854         {
00855             m_pOwningGadget->DialogHasClosed();
00856         }
00857 #endif
00858     }
00859 
00860     return Result;
00861 }
00862 
00863 
00864 
00865 /********************************************************************************************
00866 
00867 >   void CBrushEditDlg::HandleBrushEditSpacingMsg (DialogMsg* Msg)
00868 
00869 
00870     Author:     This comment by Diccon (function originally by ChrisS)
00871     Created:    Comment added 15/12/2000
00872     Inputs:     Msg - the message to handle
00873     Outputs:    -
00874     Returns:    -
00875     Purpose:    Subhandler for messages from the spacing tab, except for the
00876                 edit box and sliders, which have their own handlers.  
00877                 
00878     Errors:     -
00879     SeeAlso:    -
00880 
00881 ********************************************************************************************/
00882 
00883 
00884 void CBrushEditDlg::HandleBrushEditSpacingMsg (DialogMsg* Msg)
00885 {
00886     TalkToPage (_R(IDD_BRUSHEDITSPACING));
00887     
00888     switch(Msg->DlgMsg)
00889     {
00890         case DIM_CREATE:
00891             InitBrushSpacing ();
00892         break;
00894         case DIM_COMMIT :
00895         {
00896             HandleCommit (Msg);
00897             DialogManager::DefaultKeyboardFocus ();
00898         }
00899         break;
00900         default:
00901             break;
00902     }
00903 }
00904 
00905 
00906 /********************************************************************************************
00907 
00908 >   void CBrushEditDlg::HandleBrushEditOffsetMsg (DialogMsg* Msg)
00909 
00910 
00911     Author:     This comment by Diccon (function originally by ChrisS)
00912     Created:    Comment added 15/12/2000
00913     Inputs:     Msg - the message to handle
00914     Outputs:    -
00915     Returns:    -
00916     Purpose:    Subhandler for messages from the offset tab, except for the
00917                 edit box and sliders, which have their own handlers.  
00918                 
00919     Errors:     -
00920     SeeAlso:    -
00921 
00922 ********************************************************************************************/
00923 
00924 void CBrushEditDlg::HandleBrushEditOffsetMsg (DialogMsg* Msg)
00925 {
00926     TalkToPage (_R(IDD_BRUSHEDITOFFSET));
00927     
00928     switch(Msg->DlgMsg)
00929     {
00930         case DIM_CREATE:
00931             InitBrushOffset ();
00932         break;
00933         case DIM_COMMIT :
00934         {
00935             HandleCommit (Msg);
00936             DialogManager::DefaultKeyboardFocus ();
00937         }
00938         break;
00939         default:
00940             break;
00941     }
00942 }
00943 
00944 
00945 /********************************************************************************************
00946 
00947 >   void CBrushEditDlg::HandleBrushEditScalingMsg (DialogMsg* Msg)
00948 
00949 
00950     Author:     This comment by Diccon (function originally by ChrisS)
00951     Created:    Comment added 15/12/2000
00952     Inputs:     Msg - the message to handle
00953     Outputs:    -
00954     Returns:    -
00955     Purpose:    Subhandler for messages from the scaling tab, except for the
00956                 edit box and sliders, which have their own handlers.  
00957                 
00958     Errors:     -
00959     SeeAlso:    -
00960 
00961 ********************************************************************************************/
00962 
00963 void CBrushEditDlg::HandleBrushEditScalingMsg (DialogMsg* Msg)
00964 {
00965     TalkToPage (_R(IDD_BRUSHEDITSCALING));
00966     
00967     switch(Msg->DlgMsg)
00968     {
00969         case DIM_CREATE:
00970             InitBrushScaling ();
00971         break;
00972         case DIM_COMMIT :
00973         {
00974             HandleCommit (Msg);
00975             DialogManager::DefaultKeyboardFocus ();
00976         }
00977         break;
00978         default:
00979             break;
00980     }
00981 }
00982 
00983 
00984 
00985 /********************************************************************************************
00986 
00987 >   void CBrushEditDlg::HandleBrushEditEffectMsg (DialogMsg* Msg)
00988 
00989 
00990     Author:     This comment by Diccon (function originally by ChrisS)
00991     Created:    Comment added 15/12/2000
00992     Inputs:     Msg - the message to handle
00993     Outputs:    -
00994     Returns:    -
00995     Purpose:    Subhandler for messages from the rotation tab, except for the
00996                 edit box and sliders, which have their own handlers.  
00997                 
00998     Errors:     -
00999     SeeAlso:    -
01000 
01001 ********************************************************************************************/
01002 
01003 void CBrushEditDlg::HandleBrushEditEffectMsg (DialogMsg* Msg)
01004 {
01005     TalkToPage (_R(IDD_BRUSHEDITEFFECTS));
01006     
01007     switch(Msg->DlgMsg)
01008     {
01009         case DIM_CREATE:
01010             InitBrushEffects ();
01011         break;
01012         case DIM_COMMIT :
01013         {
01014             HandleCommit (Msg);
01015             DialogManager::DefaultKeyboardFocus ();
01016         }
01017         break;
01018         default:
01019             break;
01020     }
01021 }
01022 
01023 
01024 
01025 /********************************************************************************************
01026 
01027 >   void CBrushEditDlg::HandleBrushEditSequenceMsg (DialogMsg* Msg)
01028 
01029 
01030     Author:     This comment by Diccon (function originally by ChrisS)
01031     Created:    Comment added 15/12/2000
01032     Inputs:     Msg - the message to handle
01033     Outputs:    -
01034     Returns:    -
01035     Purpose:    Subhandler for messages from the transparency tab, except for the
01036                 edit box and sliders, which have their own handlers.  
01037                 
01038     Errors:     -
01039     SeeAlso:    -
01040 
01041 ********************************************************************************************/
01042 
01043 void CBrushEditDlg::HandleBrushEditSequenceMsg (DialogMsg* Msg)
01044 {
01045     TalkToPage (_R(IDD_BRUSHEDITSEQUENCE));
01046     
01047     switch(Msg->DlgMsg)
01048     {
01049         case DIM_CREATE:
01050             InitBrushSequence ();
01051         break;
01052         case DIM_COMMIT :
01053         {
01054             HandleCommit (Msg);
01055             DialogManager::DefaultKeyboardFocus ();
01056         }
01057         break;
01058         default:
01059             break;
01060     }
01061 }
01062 
01063 
01064 
01065 /********************************************************************************************
01066 
01067 >   void CBrushEditDlg::HandleBrushFillMsg (DialogMsg* Msg)
01068 
01069 
01070     Author:     This comment by Diccon (function originally by ChrisS)
01071     Created:    Comment added 15/12/2000
01072     Inputs:     Msg - the message to handle
01073     Outputs:    -
01074     Returns:    -
01075     Purpose:    Subhandler for messages from the fill tab, except for the
01076                 edit box and sliders, which have their own handlers.  
01077                 
01078     Errors:     -
01079     SeeAlso:    -
01080 
01081 ********************************************************************************************/
01082 
01083 void CBrushEditDlg::HandleBrushFillMsg (DialogMsg* Msg)
01084 {
01085     TalkToPage (_R(IDD_BRUSHEDITFILL));
01086     
01087     switch(Msg->DlgMsg)
01088     {
01089         case DIM_CREATE:
01090             InitBrushFill ();
01091         break;
01092         case DIM_COMMIT :
01093         {
01094             HandleCommit (Msg);
01095             DialogManager::DefaultKeyboardFocus ();
01096         }
01097         break;
01098         default:
01099             break;
01100     }
01101 }
01102 
01103 PORTNOTE("other", "Disabled CBrushGadget")
01104 #ifndef EXCLUDE_FROM_XARALX
01105 
01106 /********************************************************************************************
01107 
01108 >   void CBrushEditDlg::InvokeVia (CBrushGadget& pInvokeWith, BrushData* pInvokeOn, AttrBrushType* pBrush, BOOL& bMany)
01109 
01110 
01111     Author:     This comment by Diccon (function originally by ChrisS)
01112     Created:    Comment added 15/12/2000
01113     Inputs:     -
01114     Outputs:    -
01115     Returns:    -
01116     Purpose:    I'm not entirely sure what this does, perhaps Chris will be able to elaborate,
01117                  I think they were once used as part of launching the dialog, but I think they are
01118                  no longer used.
01119                 
01120     Errors:     -
01121     SeeAlso:    -
01122 
01123 ********************************************************************************************/
01124 
01125 void CBrushEditDlg::InvokeVia (CBrushGadget& pInvokeWith, BrushData* pInvokeOn, AttrBrushType* pBrush, BOOL& bMany)
01126 {
01127     if (pInvokeOn == NULL)
01128     {
01129         ERROR3("Invalid inputs");
01130         return;
01131     }
01132     
01133     // for various reasons we want to disable the first operation
01134     m_bDisableOps = TRUE;
01135     OpDescriptor*  pOpDescriptor = OpDescriptor::FindOpDescriptor (OPTOKEN_BRUSHEDIT_DLG);
01136     if( pOpDescriptor != 0 )
01137     {
01138         OpParam  Param( reinterpret_cast<INT32>( &pInvokeWith ),  reinterpret_cast<INT32>( pInvokeOn ) );
01139         DoWithParam( pOpDescriptor, &Param );
01140     }
01141 }
01142 
01143 
01144 void CBrushEditDlg::InvokeVia (CBrushGadget& pInvokeWith, BrushHandle Handle)
01145 {
01146     // we need to make sure our handle is valid
01147     Document* pDoc = Document::GetCurrent();
01148     if (pDoc == NULL)
01149         return;
01150     BrushComponent* pBrushComp = (BrushComponent*)pDoc->GetDocComponent(CC_RUNTIME_CLASS(BrushComponent));
01151     if (pBrushComp == NULL)
01152     {
01153         ERROR3("No brush component in our document");
01154         return;
01155     }
01156     BrushDefinition* pBrushDef = pBrushComp->FindBrushDefinition(Handle);
01157     if (pBrushDef == NULL)
01158         return;
01159     
01160     // set the flag so we know what we're doing
01161     EditingBrushDef = TRUE;
01162     
01163     //get some brush data from the definition
01164     BrushData* pInvokeOn = pBrushDef->GetBrushData();
01165     if (pInvokeOn == NULL)
01166         return;
01167     // for various reasons we want to disable the first operation
01168     m_bDisableOps = TRUE;
01169     m_Handle = Handle;
01170 
01171     OpDescriptor*  pOpDescriptor = OpDescriptor::FindOpDescriptor (OPTOKEN_BRUSHEDIT_DLG);
01172     if( pOpDescriptor != 0 )
01173     {
01174         OpParam  Param( reinterpret_cast<INT32>( &pInvokeWith ),  reinterpret_cast<INT32>( pInvokeOn ) );
01175         DoWithParam( pOpDescriptor, &Param );
01176     }
01177 }
01178 
01179             
01180 
01181 void CBrushEditDlg::InvokeVia (CBrushGadget& pInvokeWith, BrushData* pInvokeOn, AttrBrushType* pBrush, AttrBrushType* pOrigBrush, BOOL& bMany)
01182 {
01183     if (pInvokeOn == NULL || pBrush == NULL)
01184     {
01185         ERROR3("Invalid inputs");
01186         return;
01187     }
01188 
01189     OpDescriptor*  pOpDescriptor = OpDescriptor::FindOpDescriptor (OPTOKEN_BRUSHEDIT_DLG);
01190     if( pOpDescriptor != 0 )
01191     {
01192         pAttrBrush_m = pBrush;
01193         pOrigAttrBrush_m = pOrigBrush;
01194         OpParam  Param( reinterpret_cast<INT32>( &pInvokeWith ),  reinterpret_cast<INT32>( pInvokeOn ) );
01195         DoWithParam( pOpDescriptor, &Param );
01196     }
01197 }
01198 #endif
01199 
01200 BOOL CBrushEditDlg::RegisterYourPagesInOrderPlease ()
01201 {
01202     BOOL ok = ( AddAPage (_R(IDD_BRUSHEDITSPACING)) &&
01203                 AddAPage (_R(IDD_BRUSHEDITOFFSET)) &&
01204                 AddAPage (_R(IDD_BRUSHEDITSCALING)) &&
01205                 AddAPage (_R(IDD_BRUSHEDITEFFECTS)) &&
01206                 AddAPage (_R(IDD_BRUSHEDITSEQUENCE)) &&
01207                 AddAPage (_R(IDD_BRUSHEDITFILL))
01208               );
01209 
01210     return (ok);
01211 }
01212 
01213 
01214 
01215 /********************************************************************************************
01216 
01217 >   void CBrushEditDlg::HideShuffleIrrelevantButtons ()
01218 
01219 
01220     Author:     This comment by Diccon (function originally by ChrisS)
01221     Created:    Comment added 15/12/2000
01222     Inputs:     -
01223     Outputs:    -
01224     Returns:    -
01225     Purpose:    Because CPropertySheets only let you have an OK, Apply,Cancel, and Help
01226                 button, we must rename these for our own devious ends and swap their positions
01227                 
01228     Errors:     -
01229     SeeAlso:    -
01230 
01231 ********************************************************************************************/
01232 
01233 void CBrushEditDlg::HideShuffleIrrelevantButtons ()
01234 {
01235     TalkToPage (0);
01236     
01237     // say bye-bye to the ok button!
01238     //HideGadget (IDOK, TRUE);
01239 
01240     // now swap the position of the apply and cancel buttons ....
01241 
01242     TalkToPage (0);
01243     RECT rectApply;
01244     GetGadgetPosition (_R(ID_APPLY_NOW), &rectApply);   // Preview
01245     RECT rectCancel;
01246     GetGadgetPosition (_R(IDCANCEL), &rectCancel);          // Cancel
01247 
01248     SetGadgetPosition (_R(IDCANCEL), rectApply);
01249     SetGadgetPosition (_R(ID_APPLY_NOW), rectCancel);
01250     
01251 
01252     ChangeButtonText();
01253 
01254 }
01255 
01256 
01257 
01258 /********************************************************************************************
01259 
01260 >   void CBrushEditDlg::ChangeButtonText()
01261 
01262 
01263     Author:     This comment by Diccon (function originally by ChrisS)
01264     Created:    Comment added 15/12/2000
01265     Inputs:     -
01266     Outputs:    -
01267     Returns:    -
01268     Purpose:    Because CPropertySheets only let you have an OK, Apply,Cancel, and Help
01269                 button, we must rename these for our own devious ends.
01270                 
01271     Errors:     -
01272     SeeAlso:    -
01273 
01274 ********************************************************************************************/
01275 
01276 void CBrushEditDlg::ChangeButtonText()
01277 {
01278     SetStringGadgetValue(_R(ID_CANCEL), _R(IDS_BRUSH_CLOSEDLG));
01279     SetStringGadgetValue(_R(ID_APPLY_NOW), _R(IDS_BRUSH_SAVE));
01280     SetStringGadgetValue(_R(IDOK), _R(IDS_BRUSH_SAVE_AS));
01281 }
01282 
01283 
01284 
01285 static CGadgetID BrushSpacingGadgetIDs [] =     {
01286                                                 //  _R(IDC_SPINBRUSHSPACING),            //0x5f84
01287                                                     _R(IDC_EDITBRUSHSPACING),            //0x5f85
01288                                             
01289                                                     _R(IDC_EDITBRUSHSPACINGINCRCONST),   //0x5f8b
01290                                                     _R(IDC_SLIDERBRUSHSPACINGMAXRAND),   //0x5f89
01291                                                     _R(IDC_BUTTONBRUSHSPACINGRANDSEED),  //0x5f8c
01292                                                     _R(IDC_STATICBRUSHSPACING),          //0x5fb6
01293                                                     
01294                                                     _R(IDC_STATICBRUSHSPACINGINCRCONST), //0x5fb8
01295                                                     _R(IDC_STATICBRUSHSPACINGMAXRAND),   //0x5fb9
01296                                                     _R(IDC_SLIDERBRUSHSPACINGMULT),
01297                                                     _R(IDC_SLIDERBRUSHSPACING1),
01298                                                     _R(IDC_SLIDERBRUSHSPACINGINCR), 
01299                                                     _R(IDC_STATICBRUSHSPACINGRAND1),
01300                                                     _R(IDC_COMBOSEQUENCETYPE),           //0x5f9c
01301                                                 };
01302 
01303 static INT32 NumberOfBrushSpacingGadgets = sizeof (BrushSpacingGadgetIDs) / sizeof (CGadgetID);
01304 
01305 void CBrushEditDlg::InitBrushSpacing (BOOL OnlyForUnitChange /*= FALSE*/)
01306 {
01307     SetSpacingSlider();
01308 
01309 //  SetSpacingIncrSlider();
01310     
01311     // Edit boxes have their own function
01312 //  UpdateEditBox(_R(IDC_EDITBRUSHSPACINGINCRCONST));
01313     UpdateEditBox (_R(IDC_EDITBRUSHSPACING));
01314 
01315     SetGadgetRange (_R(IDC_SLIDERBRUSHSPACINGMAXRAND), MIN_RANDOM_SLIDER,  MAX_RANDOM_SLIDER);
01316     SetGadgetBitmaps (_R(IDC_SLIDERBRUSHSPACINGMAXRAND), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01317     SetLongGadgetValue (_R(IDC_SLIDERBRUSHSPACINGMAXRAND), MAX_RANDOM_SLIDER - (EditData->m_BrushSpacingMaxRand) + MIN_RANDOM_SLIDER);
01318     SetRandomRangeText(_R(IDC_SLIDERBRUSHSPACINGMAXRAND));
01319 
01320     if (m_bDisableGadgets)
01321     {
01322         ReInitBrushSpacing();
01323         return;
01324     }
01325     
01326     
01327     // now have to share the randomize button between spacing and sequence
01328     if (EditData->m_BrushSpacingMaxRand == 0 && EditData->m_SequenceType != SEQ_RANDOM )            // no random spacing
01329     {
01330         
01331         UsingRandomSpacing = FALSE;
01332         EnableGadget (_R(IDC_BUTTONBRUSHSPACINGRANDSEED), FALSE);
01333         
01334     }
01335     else                                                // we have random spacing
01336     {
01337         UsingRandomSpacing = TRUE;
01338         EnableGadget (_R(IDC_BUTTONBRUSHSPACINGRANDSEED), TRUE);
01339     }   
01340     InitSequenceType ();
01341 }
01342 
01343 static CGadgetID BrushOffsetGadgetIDs [] =  {
01344                                                 //_R(IDC_SPINPATHOFFSETVALUE),         //0x5f9d
01345                                                 _R(IDC_EDITPATHOFFSETVALUE),         //0x5f9
01346                                                 _R(IDC_EDITPATHOFFSETINCRCONST),     //0x5fa2
01347                                                 _R(IDC_SLIDEROFFSETVALUEMAXRAND),    //0x5fa4
01348                                                 _R(IDC_BUTTONOFFSETVALUERANDSEED),   //0x5fa5
01349                                                 _R(IDC_COMBOPATHOFFSETTYPE),         //0x5f99
01350                                                 _R(IDC_STATICPATHOFFSETVALUE),       //0x5fbd
01351                                             
01352                                                 _R(IDC_STATICPATHOFFSETINCRCONST),   //0x5fbf
01353                                                 _R(IDC_STATICPATHOFFSETTYPE),        //0x5fc0
01354                                                 _R(IDC_STATICOFFSETVALUEMAXRAND),    //0x5fc1
01355                                                 _R(IDC_SLIDERPATHOFFSETVAL),
01356                                                 _R(IDC_SLIDEROFFSETINCRCONST)
01357                                             //  _R(IDC_BUTTONOFFSETTYPERANDSEED)
01358                                                 
01359                                             };
01360 
01361 static INT32 NumberOfBrushOffsetGadgets = sizeof (BrushOffsetGadgetIDs) / sizeof (CGadgetID);
01362 
01363 void CBrushEditDlg::InitBrushOffset (BOOL OnlyForUnitChange /*= FALSE*/)
01364 {
01365     SetOffsetValSlider();
01366 
01367     // do the addition slider
01368 //  SetGadgetRange(_R(IDC_SLIDEROFFSETINCRCONST), MIN_SPACING_INCR, MAX_SPACING_INCR);
01369 //  SetGadgetBitmaps(_R(IDC_SLIDEROFFSETINCRCONST), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01370 //  double PercentVal = GetDistanceAsPercentageOfBBox(EditData->m_PathOffsetIncrConst);
01371 //  SetDoubleGadgetValue (_R(IDC_SLIDEROFFSETINCRCONST), MAX_SPACING_INCR - PercentVal + MIN_SPACING_INCR);
01372     
01373     // set up the random slider
01374     SetGadgetRange (_R(IDC_SLIDEROFFSETVALUEMAXRAND), MinOffsetSlider, MaxOffsetSlider);
01375     SetGadgetBitmaps (_R(IDC_SLIDEROFFSETVALUEMAXRAND), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01376     SetRandomRangeText(_R(IDC_SLIDEROFFSETVALUEMAXRAND));
01377 
01378 
01379     if (m_bDisableGadgets)
01380     {
01381         ReInitBrushOffset();
01382         return;
01383     }
01384     EnableGadget (_R(IDC_BUTTONOFFSETVALUERANDSEED), FALSE);
01385     switch (EditData->m_PathOffsetType)
01386     {
01387         case OFFSET_NONE:
01388             UsingRandomOffset = FALSE;
01389             EnableGadget (_R(IDC_STATICPATHOFFSETVALUE), FALSE);
01390             EnableGadget (_R(IDC_SPINPATHOFFSETVALUE), FALSE);
01391             EnableGadget (_R(IDC_EDITPATHOFFSETVALUE), FALSE);
01392             EnableGadget (_R(IDC_STATICPATHOFFSETINCRCONST), FALSE);
01393             EnableGadget (_R(IDC_SPINPATHOFFSETINCRCONST), FALSE);
01394             EnableGadget (_R(IDC_EDITPATHOFFSETINCRCONST), FALSE);
01395             //EnableGadget (_R(IDC_SLIDEROFFSETVALUEMAXRAND), FALSE);
01396             EnableGadget (_R(IDC_SLIDERPATHOFFSETVAL), FALSE);
01397             EnableGadget (_R(IDC_SLIDEROFFSETINCRCONST), FALSE);
01398             //EnableGadget (_R(IDC_STATICOFFSETVALUEMAXRAND), FALSE);
01399             
01400         break;
01401 
01402         case OFFSET_RANDOM:
01403             EnableGadget (_R(IDC_EDITPATHOFFSETVALUE), FALSE);
01404             EnableGadget (_R(IDC_SLIDERPATHOFFSETVAL), FALSE);
01405             EnableGadget (_R(IDC_STATICPATHOFFSETVALUE), FALSE);
01406         break;
01407         
01408         default:
01409             
01410         break;
01411     }
01412     if (EditData->m_OffsetValueMaxRand > 0)
01413         EnableGadget (_R(IDC_BUTTONOFFSETVALUERANDSEED), TRUE);
01414 
01415     InitComboPathOffsetType ();
01416     
01417     SetLongGadgetValue (_R(IDC_SLIDEROFFSETVALUEMAXRAND), MaxOffsetSlider - (EditData->m_OffsetValueMaxRand));
01418 }
01419 
01420 static CGadgetID BrushScalingGadgetIDs [] = {
01421                                                 _R(IDC_EDITBRUSHSCALINGINCR),        //0x5f9a
01422                                                 _R(IDC_SLIDERBRUSHSCALINGMAXRAND),   //0x5f94
01423                                                 _R(IDC_BUTTONBRUSHSCALINGRANDSEED),   //0x5f95
01424                                                 //_R(IDC_STATICBRUSHSCALING),            //0x5fba
01425                                                 _R(IDC_STATICBRUSHSCALINGINCR),      //0x5fbb
01426                                                 _R(IDC_STATICBRUSHSCALINGMAXRAND),   //0x5fbc
01427                                                 _R(IDC_SLIDERBRUSHSCALINGINCR),
01428                                                 _R(IDC_SLIDERSCALINGINCRCONST),
01429                                                 _R(IDC_EDITSCALINGINCRCONST),
01430                                                 _R(IDC_STATICPERCENT),
01431                                                 _R(IDC_STATICPERCENT2),
01432                                                 _R(IDC_SLIDERSCALINGPRESSURE)
01433                                                 
01434                                             };
01435 
01436 static INT32 NumberOfBrushScalingGadgets = sizeof (BrushScalingGadgetIDs) / sizeof (CGadgetID);
01437 
01438 void CBrushEditDlg::InitBrushScaling (BOOL OnlyForUnitChange /*= FALSE*/)
01439 {
01440     // set up the random scaling slider
01441     SetGadgetRange (_R(IDC_SLIDERBRUSHSCALINGMAXRAND), MinScalingSlider, MaxScalingSlider);
01442     SetGadgetBitmaps (_R(IDC_SLIDERBRUSHSCALINGMAXRAND), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01443     SetLongGadgetValue (_R(IDC_SLIDERBRUSHSCALINGMAXRAND), MaxScalingSlider - (EditData->m_BrushScalingMaxRand));
01444     SetRandomRangeText(_R(IDC_SLIDERBRUSHSCALINGMAXRAND));
01445 
01446     // set up the increment slider
01448 //  SetGadgetBitmaps (_R(IDC_SLIDERSCALINGINCRCONST), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01449 //  SetLongGadgetValue (_R(IDC_SLIDERSCALINGINCRCONST), (MaxScalingIncrSlider - (EditData->m_BrushScalingIncrConst)) + MinScalingIncrSlider);
01450 //  SetDoubleGadgetValue(_R(IDC_EDITSCALINGINCRCONST), EditData->m_BrushScalingIncrConst);
01451 
01452     // setup the pressure slider
01453     SetGadgetRange (_R(IDC_SLIDERSCALINGPRESSURE), MIN_PRESSURE_SLIDER, MAX_PRESSURE_SLIDER);
01454     SetGadgetBitmaps (_R(IDC_SLIDERSCALINGPRESSURE), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01455     SetLongGadgetValue (_R(IDC_SLIDERSCALINGPRESSURE), (MAX_PRESSURE_SLIDER - EditData->m_ScalingMaxPressure) + MIN_PRESSURE_SLIDER);
01456     SetRandomRangeText(_R(IDC_SLIDERSCALINGPRESSURE));
01457 
01458     SetStringGadgetValue(_R(IDC_STATICBRUSHSCALEINFO), _R(IDS_BRUSHSCALE));
01459 
01460     if (m_bDisableGadgets)
01461     {
01462         ReInitBrushScaling();
01463         return;
01464     }
01465 
01466     if (EditData->m_BrushScalingMaxRand == 0)               // no random scaling
01467     {
01468         UsingRandomScaling = FALSE;
01469         //EnableGadget (_R(IDC_SLIDERBRUSHSCALINGMAXRAND), FALSE);
01470         //EnableGadget (_R(IDC_STATICBRUSHSCALINGMAXRAND), FALSE);
01471         EnableGadget (_R(IDC_BUTTONBRUSHSCALINGRANDSEED), FALSE);
01472     }
01473     else                                                    // we have random scaling
01474     {
01475         UsingRandomScaling = TRUE;
01476     //  EnableGadget (_R(IDC_STATICBRUSHSCALINGINCR), FALSE);
01477     //  EnableGadget (_R(IDC_SPINBRUSHSCALINGINCR), FALSE);
01478     //  EnableGadget (_R(IDC_EDITBRUSHSCALINGINCR), FALSE);
01479     }
01480 
01481     
01482 }
01483 
01484 static CGadgetID BrushEffectsGadgetIDs [] = {
01485                                                 
01486                                                 _R(IDC_CHECKROTATE),                 //0x5f8e
01487                                                 _R(IDC_EDITROTATEANGLE),              //0x5f8f
01488                                                 _R(IDC_EDITROTATEANGLEINCR),
01489                                                 //_R(IDC_SLIDERROTATEINCR),
01490                                                 _R(IDC_BUTTONROTATEANGLERANDSEED),
01491                                                 _R(IDC_SLIDERROTATEANGLEMAXRAND),
01492                                                 _R(IDC_SLIDERROTATEANGLEINCR),
01493                                                 _R(IDC_SLIDERROTATEANGLE),
01494                                                 _R(IDC_SLIDERROTATEPRESSURE)
01495                                                 //_R(IDC_EDITROTATIONINCRPROP)
01496                                                 
01497                                             };
01498 
01499 static INT32 NumberOfBrushEffectsGadgets = sizeof (BrushEffectsGadgetIDs) / sizeof (CGadgetID);
01500 
01501 void CBrushEditDlg::InitBrushEffects (BOOL OnlyForUnitChange /*= FALSE*/)
01502 {
01503     // set the random slider
01504     SetGadgetRange (_R(IDC_SLIDERROTATEANGLEMAXRAND),   MIN_RANDOM_SLIDER, MAX_ROTATION_RANDOM_SLIDER);
01505     SetGadgetBitmaps (_R(IDC_SLIDERROTATEANGLEMAXRAND), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01506     SetLongGadgetValue (_R(IDC_SLIDERROTATEANGLEMAXRAND), MAX_ROTATION_RANDOM_SLIDER - (EditData->m_RotationMaxRand) + MIN_RANDOM_SLIDER);
01507     SetRandomRangeText(_R(IDC_SLIDERROTATEANGLEMAXRAND));
01508 
01509     // set the rotate angle slider and edit field
01510     SetDoubleGadgetValue (_R(IDC_EDITROTATEANGLE), EditData->m_RotateAngle);
01511     SetGadgetBitmaps (_R(IDC_SLIDERROTATEANGLE), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01512     SetGadgetRange (_R(IDC_SLIDERROTATEANGLE), MIN_ROTATION_SLIDER, MAX_ROTATION_SLIDER);
01513     SetDoubleGadgetValue (_R(IDC_SLIDERROTATEANGLE), (MAX_ROTATION_SLIDER - EditData->m_RotateAngle) + MIN_ROTATION_SLIDER);
01514 
01515     // set the angle increment slider and edit field
01516     SetDoubleGadgetValue (_R(IDC_EDITROTATEANGLEINCR), EditData->m_RotAngleIncrConst);
01517     SetGadgetBitmaps (_R(IDC_SLIDERROTATEANGLEINCR), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01518     SetGadgetRange (_R(IDC_SLIDERROTATEANGLEINCR), MIN_ROTATION_INCR_SLIDER, MAX_ROTATION_INCR_SLIDER);
01519     SetDoubleGadgetValue (_R(IDC_SLIDERROTATEANGLEINCR), (MAX_ROTATION_INCR_SLIDER - EditData->m_RotAngleIncrConst) + MIN_ROTATION_INCR_SLIDER);
01520 
01521     
01522     if (m_bDisableGadgets)
01523     {
01524         ReInitBrushEffects();
01525         return;
01526     }
01527 
01528 
01529     if (EditData->m_RotationMaxRand == 0)
01530     {
01531         EnableGadget (_R(IDC_BUTTONROTATEANGLERANDSEED), FALSE);
01532     }
01533 
01534 
01535     if (EditData->m_bRotate)
01536     {
01537         SetLongGadgetValue (_R(IDC_CHECKROTATE), 1);
01538     }
01539 
01540     
01541 
01542 
01543 }
01544 
01545 /* !!!! SPECIAL NOTE the sequence combo has been moved to the spacing tab for various reasons.
01546 the sequence tab now contains only transparency controls, obviously.
01547 */
01548 
01549 static CGadgetID BrushSequenceGadgetIDs [] = {
01550                                                 _R(IDC_SLIDERTRANSP),
01551                                                 _R(IDC_SLIDERTRANSPPRESSURE),
01552                                                 _R(IDC_EDITBRUSHTRANSP),
01553                                                 _R(IDC_STATICTRANSPPRESSURE)
01554                                             };
01555 
01556 
01557 static INT32 NumberOfBrushSequenceGadgets = sizeof (BrushSequenceGadgetIDs) / sizeof (CGadgetID);
01558 
01559 
01560 void CBrushEditDlg::InitBrushSequence (BOOL OnlyForUnitChange /*= FALSE*/)
01561 {
01562     if (m_bDisableGadgets)
01563     {
01564         ReInitBrushSequence();
01565         return;
01566     }
01567 
01568 
01569     // do the transparency sliders 
01570     SetGadgetBitmaps(_R(IDC_SLIDERTRANSP),  _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01571     SetGadgetRange(_R(IDC_SLIDERTRANSP), MIN_TRANSP_SLIDER, MAX_TRANSP_SLIDER);
01572     SetLongGadgetValue(_R(IDC_SLIDERTRANSP), (MAX_TRANSP_SLIDER - EditData->m_BrushTransparency) + MIN_TRANSP_SLIDER);
01573     
01574     SetGadgetBitmaps(_R(IDC_SLIDERTRANSPPRESSURE),  _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01575     SetGadgetRange(_R(IDC_SLIDERTRANSPPRESSURE), MIN_PRESSURE_SLIDER, MAX_PRESSURE_SLIDER);
01576     SetLongGadgetValue(_R(IDC_SLIDERTRANSPPRESSURE), (MAX_PRESSURE_SLIDER - EditData->m_TranspMaxPressure) + MIN_PRESSURE_SLIDER);
01577 
01578     UpdateEditBox(_R(IDC_EDITBRUSHTRANSP));
01579     SetRandomRangeText(_R(IDC_SLIDERTRANSPPRESSURE));
01580 }
01581 
01582 static CGadgetID BrushFillGadgetIDs [] = {
01583                                             _R(IDC_CHECKTILEING),
01584                                             _R(IDC_RADIOLOCALFILLALL),
01585                                             _R(IDC_RADIOLOCALFILLNAMED), 
01586                                             _R(IDC_RADIOLOCALFILLNONE),
01587                                             _R(IDC_SLIDERHUERANDOM),
01588                                             _R(IDC_SLIDERSATURATIONRANDOM),
01589                                             _R(IDC_BUTTONBRUSHFILLRANDOM),
01590 
01591                                                  };
01592 
01593 static CGadgetID LocalFillRadioGadgets [] = {
01594                                                 _R(IDC_RADIOLOCALFILLALL),
01595                                                 _R(IDC_RADIOLOCALFILLNAMED), 
01596                                                 _R(IDC_RADIOLOCALFILLNONE),
01597                                                 0
01598                                             };
01599 
01600 static INT32 NumberOfBrushFillGadgets = sizeof (BrushFillGadgetIDs) / sizeof (CGadgetID);
01601 static INT32 NumberOfLocalFillRadios = sizeof (LocalFillRadioGadgets) / sizeof (CGadgetID);
01602 
01603 void CBrushEditDlg::InitBrushFill (BOOL OnlyForUnitChange /*= FALSE*/)
01604 {
01605     
01606     if (m_bDisableGadgets)
01607     {
01608         ReInitBrushFill();
01609         return;
01610     }
01611 
01612     // do the hue and saturation sliders
01613     SetGadgetBitmaps(_R(IDC_SLIDERSATURATIONRANDOM),  _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01614     SetGadgetRange(_R(IDC_SLIDERSATURATIONRANDOM), MIN_RANDOM_SLIDER, MAX_RANDOM_SAT_SLIDER);
01615     SetLongGadgetValue(_R(IDC_SLIDERSATURATIONRANDOM), (MAX_RANDOM_SAT_SLIDER - EditData->m_BrushSatMaxRand) + MIN_RANDOM_SLIDER);
01616     SetRandomRangeText(_R(IDC_SLIDERSATURATIONRANDOM));
01617     
01618     SetGadgetBitmaps(_R(IDC_SLIDERHUERANDOM),  _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
01619     SetGadgetRange(_R(IDC_SLIDERHUERANDOM), MIN_RANDOM_SLIDER, MAX_RANDOM_HUE_SLIDER);
01620     SetLongGadgetValue(_R(IDC_SLIDERHUERANDOM), (MAX_RANDOM_HUE_SLIDER - EditData->m_BrushHueMaxRand) + MIN_RANDOM_SLIDER);
01621     SetRandomRangeText(_R(IDC_SLIDERHUERANDOM));
01622 
01623     if (EditData->m_BrushHueMaxRand > 0 || EditData->m_BrushSatMaxRand > 0)
01624         EnableGadget(_R(IDC_BUTTONBRUSHFILLRANDOM), TRUE);
01625     else
01626         EnableGadget(_R(IDC_BUTTONBRUSHFILLRANDOM), FALSE);
01627 
01628     if (EditData->m_bTile)
01629     {
01630         SetLongGadgetValue (_R(IDC_CHECKTILEING), 1);
01631     }
01632     else
01633     {
01634         SetLongGadgetValue (_R(IDC_CHECKTILEING), 0);
01635     }
01636 
01637     // use local options not available for the brush definitions
01638     if (!EditingBrushDef)
01639     {
01640         SetRadioGroupSelected(LocalFillRadioGadgets, _R(IDC_RADIOLOCALFILLNONE));
01641         if (EditData->m_bUseLocalFillColour)
01642         {
01643             SetRadioGroupSelected(LocalFillRadioGadgets, _R(IDC_RADIOLOCALFILLALL));
01644         }
01645         if (EditData->m_bUseNamedColour == FALSE)
01646         {
01647             SetRadioGroupSelected(LocalFillRadioGadgets, _R(IDC_RADIOLOCALFILLNAMED));
01648         }
01649     
01650     }
01651     else
01652     {
01653         
01654         for (INT32 i = 0; i < NumberOfLocalFillRadios - 1; i++)  // -1 because the last value is NULL
01655             EnableGadget(LocalFillRadioGadgets[i], FALSE);
01656         
01657     }
01658 
01659 }
01660 
01661 
01662 void CBrushEditDlg::ReInitBrushFill()
01663 {
01664     BOOL Enable = !m_bDisableGadgets;
01665 
01666     for (INT32 i = 0; i < NumberOfBrushFillGadgets; i++)
01667     {
01668         EnableGadget (BrushSequenceGadgetIDs [i], Enable);
01669     }
01670 
01671     if (Enable)
01672         InitBrushFill ();
01673 
01674 }
01675 
01676 
01677 void CBrushEditDlg::InitComboPathOffsetType ()
01678 {   
01679     DeleteAllValues (_R(IDC_COMBOPATHOFFSETTYPE));
01680     
01681     SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_NONE), TRUE, 0);
01682     SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_ALTERNATE), TRUE, 1);
01683     SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_LEFT), TRUE, 2);
01684     SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_RIGHT), TRUE, 3);
01685     //SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_RANDOM), TRUE, 4);
01686 
01687     switch (EditData->m_PathOffsetType)
01688     {
01689         case OFFSET_NONE:
01690             SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_NONE), FALSE, -1);
01691         break;
01692         case OFFSET_ALTERNATE:
01693             SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_ALTERNATE), FALSE, -1);
01694         break;
01695         case OFFSET_LEFT:
01696             SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_LEFT), FALSE, -1);
01697         break;
01698         case OFFSET_RIGHT:
01699             SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_RIGHT), FALSE, -1);
01700         break;
01701         // We have gotten rid of the random option but some may remain from early files, so
01702         // display the default
01703         default:
01704             SetStringGadgetValue (_R(IDC_COMBOPATHOFFSETTYPE), _R(IDS_OFFSET_NONE), FALSE, -1);
01705         break;
01706     }
01707 }
01708 
01709 void CBrushEditDlg::InitSequenceType ()
01710 {
01711     DeleteAllValues (_R(IDC_COMBOSEQUENCETYPE));
01712     
01713     SetStringGadgetValue (_R(IDC_COMBOSEQUENCETYPE), _R(IDS_SEQ_FORWARD), TRUE, 0);
01714     SetStringGadgetValue (_R(IDC_COMBOSEQUENCETYPE), _R(IDS_SEQ_BACKWARD), TRUE, 1);
01715     SetStringGadgetValue (_R(IDC_COMBOSEQUENCETYPE), _R(IDS_SEQ_MIRROR), TRUE, 2);
01716     SetStringGadgetValue (_R(IDC_COMBOSEQUENCETYPE), _R(IDS_SEQ_RANDOM), TRUE, 3);
01717 
01718     switch (EditData->m_SequenceType)
01719     {
01720         case SEQ_FORWARD:
01721             SetStringGadgetValue (_R(IDC_COMBOSEQUENCETYPE), _R(IDS_SEQ_FORWARD), FALSE, -1);
01722         break;
01723         case SEQ_BACKWARD:
01724             SetStringGadgetValue (_R(IDC_COMBOSEQUENCETYPE), _R(IDS_SEQ_BACKWARD), FALSE, -1);
01725         break;
01726         case SEQ_MIRROR:
01727             SetStringGadgetValue (_R(IDC_COMBOSEQUENCETYPE), _R(IDS_SEQ_MIRROR), FALSE, -1);
01728         break;
01729         case SEQ_RANDOM:
01730             SetStringGadgetValue (_R(IDC_COMBOSEQUENCETYPE), _R(IDS_SEQ_RANDOM), FALSE, -1);
01731         break;
01732     }
01733 
01734     BrushDefinition* pDef = BrushComponent::FindBrushDefinition(EditData->m_BrushHandle);
01735     if (pDef)
01736     {
01737         UINT32 Num = pDef->GetNumBrushObjects();
01738         if (Num == 1)
01739             EnableGadget(_R(IDC_COMBOSEQUENCETYPE), FALSE);
01740 
01741     }
01742 }
01743 
01744 void CBrushEditDlg::ReInitBrushSpacing ()
01745 {
01746     BOOL Enable = !m_bDisableGadgets;
01747     for (INT32 i = 0; i < NumberOfBrushSpacingGadgets; i++)
01748     {
01749         EnableGadget (BrushSpacingGadgetIDs [i], Enable);
01750     }
01751     if (Enable)
01752         InitBrushSpacing ();
01753 }
01754 
01755 void CBrushEditDlg::ReInitBrushOffset ()
01756 {
01757     BOOL Enable = !m_bDisableGadgets;
01758     for (INT32 i = 0; i < NumberOfBrushOffsetGadgets; i++)
01759     {
01760         EnableGadget (BrushOffsetGadgetIDs [i], Enable);
01761     }
01762 
01763     if (Enable)
01764         InitBrushOffset ();
01765 }
01766 
01767 void CBrushEditDlg::ReInitBrushScaling ()
01768 {
01769     BOOL Enable = !m_bDisableGadgets;
01770     for (INT32 i = 0; i < NumberOfBrushScalingGadgets; i++)
01771     {
01772         EnableGadget (BrushScalingGadgetIDs [i], Enable);
01773     }
01774 
01775     if (Enable)
01776         InitBrushScaling ();
01777 }
01778 
01779 void CBrushEditDlg::ReInitBrushEffects ()
01780 {
01781     BOOL Enable = !m_bDisableGadgets;
01782     for (INT32 i = 0; i < NumberOfBrushEffectsGadgets; i++)
01783     {
01784         EnableGadget (BrushEffectsGadgetIDs [i], Enable);
01785     }
01786     
01787     if (Enable)
01788         InitBrushEffects ();
01789 }
01790 
01791 void CBrushEditDlg::ReInitBrushSequence ()
01792 {
01793     BOOL Enable = !m_bDisableGadgets;
01794 
01795     for (INT32 i = 0; i < NumberOfBrushSequenceGadgets; i++)
01796     {
01797         EnableGadget (BrushSequenceGadgetIDs [i], Enable);
01798     }
01799 
01800     if (Enable)
01801         InitBrushSequence ();
01802 }
01803 
01804 void CBrushEditDlg::ReInitUnitDependantFields (CDlgResID ThePage)
01805 {
01806     if (ThePage == _R(IDD_BRUSHEDITSPACING))
01807         InitBrushSpacing (TRUE);
01808     else if (ThePage == _R(IDD_BRUSHEDITOFFSET))
01809         InitBrushOffset (TRUE);
01810     else if (ThePage == _R(IDD_BRUSHEDITSCALING))
01811         InitBrushScaling (TRUE);
01812     else if (ThePage == _R(IDD_BRUSHEDITEFFECTS))
01813         InitBrushEffects (TRUE);
01814     else if (ThePage == _R(IDD_BRUSHEDITSEQUENCE))
01815         InitBrushSequence (TRUE);
01816     else if (ThePage == _R(IDD_BRUSHEDITFILL))
01817         InitBrushFill (TRUE);
01818     else
01819     {
01820         ERROR3("Unknown tab dialog page");
01821     }
01822 }
01823 
01824 void CBrushEditDlg::HandleCommit (DialogMsg* Msg)
01825 {
01826     
01827     ReadEditBox (Msg);
01828     
01829     WriteSliders (Msg);
01830 
01831     BROADCAST_TO_CLASS (DialogMsg (0, Msg->DlgMsg, Id_m, (UINT_PTR) (EditData)),  DialogBarOp);
01832     
01833     LaunchOp();
01834 }
01835 
01836 void CBrushEditDlg::HandleSelectionChange (DialogMsg* Msg)
01837 {
01838     ReadComboBox (Msg);
01839     
01840     // we are now routing edit box messages through Enter_Select so if we didn't get a result in
01841     // the combo boxes then try the edit boxes
01842     if (ChangeType_m == CHANGEBRUSH_NONE)
01843         ReadEditBox(Msg);
01844 
01845     BROADCAST_TO_CLASS (DialogMsg (0, Msg->DlgMsg, Id_m, (UINT_PTR) (EditData)),  DialogBarOp);
01846     // launch the changebrush op
01847     LaunchOp();
01848 }
01849 
01850 void CBrushEditDlg::HandleButtonDown (DialogMsg* Msg)
01851 {
01852     // try reading the checkboxes first
01853     ReadCheckBox (Msg);
01854 
01855     // if it wasn't a checkbox then try the buttons
01856     if (ChangeType_m == CHANGEBRUSH_NONE)
01857         ReadButtons(Msg);
01858 
01859     // still no joy, try the radio buttons
01860     if (ChangeType_m == CHANGEBRUSH_NONE)
01861         ReadRadios(Msg);
01862 
01863     BROADCAST_TO_CLASS (DialogMsg (0, DIM_COMMIT/*Msg->DlgMsg*/, Id_m, (UINT_PTR) (EditData)),  DialogBarOp);
01864     LaunchOp();
01865 }
01866 
01867 void CBrushEditDlg::HandleSliderPosChanging (DialogMsg* Msg)
01868 {
01869     ReadSlider (Msg);
01870 
01871     BROADCAST_TO_CLASS (DialogMsg (0, Msg->DlgMsg, Id_m, (UINT_PTR) (EditData)),  DialogBarOp);
01872     
01873     // ok, so in order to avoid generating an undoable op for each slider movement we will only
01874     // do so on the first movement, so that undo will take it back to its original position
01875     
01876     if (!m_SliderStarted) // our flag that indicates if this is the first slider movement or not
01877     {
01878         TRACEUSER( "Diccon", _T("Launching Op\n"));
01879         LaunchOp();
01880         m_SliderStarted = TRUE;
01881     }
01882     else if (ChangeType_m != CHANGEBRUSH_NONE && EditingBrushDef == FALSE)
01883     {
01884         ChangeParam_m.ChangeType = ChangeType_m;        
01885         ChangeBrushAction Action;
01886 
01887         Action.ChangeSelectionNoUndo(&ChangeParam_m);
01888     }
01889 }
01890 
01891 void CBrushEditDlg::HandleSliderPosSet (DialogMsg* Msg)
01892 {
01893     ReadSlider (Msg);
01894 
01895     BROADCAST_TO_CLASS (DialogMsg (0, Msg->DlgMsg, Id_m, (UINT_PTR) (EditData)),  DialogBarOp);
01896     // don't launch an op, see above for comments
01897     if (ChangeType_m != CHANGEBRUSH_NONE && EditingBrushDef == FALSE)
01898     {
01899         ChangeParam_m.ChangeType = ChangeType_m;        
01900         ChangeBrushAction Action;
01901 
01902         Action.ChangeSelectionNoUndo(&ChangeParam_m);
01903     }
01904     m_SliderStarted = FALSE; 
01905 }
01906 
01907 
01908 void CBrushEditDlg::LaunchOp()
01909 {
01910 
01911     // the op we launch differs slightly depending on whether we are editing a brush from 
01912     // the selection or the brush definition. If its from the selection then its easy
01913     if (ChangeType_m != CHANGEBRUSH_NONE) 
01914     {
01915         if (EditingBrushDef == FALSE)
01916         {
01917             
01918             OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_CHANGEBRUSH);
01919             if (pOpDesc != NULL )
01920             {
01921                 ChangeParam_m.ChangeType = ChangeType_m;        
01922                 pOpDesc->Invoke(&ChangeParam_m);
01923                 m_LastData = *EditData;
01924             }
01925             
01926         }
01927     
01928     }
01929     else
01930         TRACEUSER( "Diccon", _T("NOT LAUNCHING OP!!\n"));
01931 
01932     // reset our member
01933     ChangeType_m = CHANGEBRUSH_NONE;
01934 
01935     // enable the save button
01936     SetPropertyPageModified(TRUE);
01937 }
01938 
01939 BOOL CBrushEditDlg::GetAttributeNodeFromDefinition()
01940 {
01941     // just a quick check to see if we're in the right place
01942     if (!EditingBrushDef)
01943         return FALSE;
01944 
01945     // we need to get hold of the brush component from the document
01946     Document* pDoc = Document::GetCurrent();
01947     if (pDoc == NULL)
01948         return FALSE;
01949 
01950     BrushComponent* pBrushComp = (BrushComponent*)pDoc->GetDocComponent(CC_RUNTIME_CLASS(BrushComponent));
01951     if (pBrushComp == NULL)
01952     {
01953         ERROR3("No brush component in our document");
01954         return FALSE;
01955     }
01956     
01957     // wipe our existing attribute
01958     if (pAttrBrush_m != NULL)
01959     {
01960         delete pAttrBrush_m;
01961         pAttrBrush_m = NULL;
01962     }
01963 
01964     // ask the component for a new one
01965     pAttrBrush_m = pBrushComp->CreateAttributeNode(m_Handle);
01966 
01967     // did we get it?
01968     if (pAttrBrush_m == NULL)
01969         return FALSE;
01970 
01971     return TRUE;
01972 }
01973 
01974 
01975 UINT32 CBrushEditDlg::GetNewRandomNumber(UINT32 OldNumber)
01976 {
01977    // seed the random number generator
01978    srand( (unsigned)time( NULL ) );
01979     
01980    UINT32 Rand = (UINT32)rand();
01981    // make sure its not the same (unlikely)
01982    while (Rand == OldNumber)
01983        Rand = (UINT32)rand();
01984     
01985    return Rand;
01986 }
01987 
01988 /*
01989 
01990                         CHANGEBRUSH_NONE,
01991                         CHANGEBRUSH_SPACING,
01992                         CHANGEBRUSH_SPACING_MAXRAND,
01993                         CHANGEBRUSH_SPACING_RANDSEED,
01994                         CHANGEBRUSH_SCALING,
01995                         CHANGEBRUSH_OFFSET_TYPE,
01996                         CHANGEBRUSH_OFFSET_VAL,
01997                         CHANGEBRUSH_TILED,
01998                         CHANGEBRUSH_TANGENTIAL,
01999                         CHANGEBRUSH_ROTATE_ANGLE,
02000                         CHANGEBRUSH_NAME,
02001                         CHANGEBRUSH_USELOCALFILLCOL,
02002                         CHANGEBRUSH_REGEN,
02003                         CHANGEBRUSH_MULTIPLE
02004 */
02005 void CBrushEditDlg::ReadEditBox (DialogMsg* Msg)
02006 {
02007     MILLIPOINT MilliPointNewVal;
02008     double DoubleNewVal;
02009     INT32 LongNewVal;
02010     BOOL Valid = FALSE;
02011     ChangeType_m = CHANGEBRUSH_NONE;
02012         // brush spacing stuff ....
02013         
02014     if (FALSE) {}
02015     else if (Msg->GadgetID == _R(IDC_EDITBRUSHSPACING))
02016     {
02017         double MinSpacingSlider = 0;
02018         double MaxSpacingSlider = 0;
02019         GetSpacingRange(&MinSpacingSlider, &MaxSpacingSlider);
02020         DoubleNewVal = GetDoubleGadgetValue (_R(IDC_EDITBRUSHSPACING), MinSpacingSlider , MaxSpacingSlider);
02021         MILLIPOINT NewVal  = GetPercentageAsDistance(DoubleNewVal, WIDTH);
02022         DoubleNewVal = pow((double)NewVal, InvFactor);
02023     
02024         if (DoubleNewVal >= MinSpacingSlider && DoubleNewVal <= MaxSpacingSlider)
02025         {   
02026             if (EditData->m_BrushSpacing != NewVal)
02027             {
02028                 
02029                 EditData->m_BrushSpacing = NewVal;
02030                 ChangeType_m = CHANGEBRUSH_SPACING;
02031                 ChangeParam_m.m_NewSpacing = NewVal;
02032                 ReInitBrushSpacing();
02033             }
02034         }
02035         else
02036         {
02037             //InformWarning(_R(IDS_BRUSHSPACING_INVALID));
02038             UpdateEditBox(_R(IDC_EDITBRUSHSPACING));
02039         }
02040     }
02041     else if (Msg->GadgetID == _R(IDC_EDITBRUSHSPACINGINCRCONST))
02042     {
02043         DoubleNewVal = GetDoubleGadgetValue(_R(IDC_EDITBRUSHSPACINGINCRCONST), MIN_SPACING_INCR, MAX_SPACING_INCR, _R(IDS_BRUSHINCRINVALID), &Valid);
02044         
02045         if (DoubleNewVal > MIN_SPACING_INCR && DoubleNewVal < MAX_SPACING_INCR && Valid)
02046         {
02047             // we need to convert the % value we got from the slider into millipoints
02048             MILLIPOINT Distance = GetPercentageAsDistance(DoubleNewVal, WIDTH);
02049             if (abs(Distance - EditData->m_BrushSpacingIncrConst) > 5)
02050             {
02051                 EditData->m_BrushSpacingIncrConst = Distance;
02052                 ChangeType_m = CHANGEBRUSH_SPACING_INCRCONST;
02053                 ChangeParam_m.m_NewSpacingIncrConst = Distance;
02054                 SetSpacingIncrSlider();
02055             }
02056         }
02057         else
02058         {
02059             //InformWarning(_R(IDS_BRUSHINCRINVALID));
02060             UpdateEditBox(_R(IDC_EDITBRUSHSPACINGINCRCONST));
02061         }
02062     }
02063     else if (Msg->GadgetID == _R(IDC_EDITPATHOFFSETVALUE))
02064     {
02065         DoubleNewVal = GetDoubleGadgetValue(_R(IDC_EDITPATHOFFSETVALUE), MinOffset, MaxOffset,0, &Valid );
02066 
02067         if (DoubleNewVal <= MaxOffset && DoubleNewVal >= MinOffset && Valid)
02068         {
02069             // convert the % val into millipoints
02070             MILLIPOINT Offset = GetPercentageAsDistance(DoubleNewVal, HEIGHT);
02071             if (abs(Offset - EditData->m_PathOffsetValue) > 5)
02072             {
02073                 EditData->m_PathOffsetValue = Offset;
02074                 ChangeType_m = CHANGEBRUSH_OFFSET_VAL;
02075                 ChangeParam_m.m_NewPathOffsetVal = Offset;
02076                 ReInitBrushOffset();
02077             }
02078         }
02079         else
02080         {
02081             UpdateEditBox(_R(IDC_EDITPATHOFFSETVALUE));
02082         }
02083     }
02084     else if (Msg->GadgetID == _R(IDC_EDITPATHOFFSETINCRCONST))
02085     {
02086         DoubleNewVal = GetDoubleGadgetValue(_R(IDC_EDITPATHOFFSETINCRCONST), MIN_SPACING_INCR, MAX_SPACING_INCR, _R(IDS_BRUSHINCRINVALID), &Valid);
02087         if (Valid && DoubleNewVal <= MAX_SPACING_INCR && DoubleNewVal >= MIN_SPACING_INCR)
02088         {
02089             MilliPointNewVal = GetPercentageAsDistance(DoubleNewVal, HEIGHT);
02090             if (EditData->m_PathOffsetIncrConst != MilliPointNewVal)
02091             {   
02092                 EditData->m_PathOffsetIncrConst = MilliPointNewVal;
02093                 ChangeParam_m.m_NewOffsetIncrConst = MilliPointNewVal;
02094                 ChangeType_m = CHANGEBRUSH_OFFSET_INCRCONST;
02095                 ReInitBrushOffset();
02096             }
02097         }
02098         else
02099         {
02100             //InformWarning(_R(IDS_BRUSHINCRINVALID));
02101             UpdateEditBox(_R(IDC_EDITPATHOFFSETINCRCONST));
02102         }
02103     }
02104     else if (Msg->GadgetID == _R(IDC_EDITSCALINGINCRCONST))
02105     {
02106         DoubleNewVal = GetDoubleGadgetValue (_R(IDC_EDITSCALINGINCRCONST), MinScalingIncrSlider, MaxScalingIncrSlider, _R(IDS_BRUSHSCALINGINCRINVALID), &Valid);
02107 
02108         if (DoubleNewVal <= MaxScalingIncrSlider && DoubleNewVal >= MinScalingIncrSlider && Valid)
02109         {
02110             // we need to convert the % value we got from the slider into millipoints
02111             if (EditData->m_BrushScalingIncrConst  != DoubleNewVal)
02112             {
02113                 EditData->m_BrushScalingIncrConst = DoubleNewVal;
02114                 ReInitBrushScaling();
02115                 ChangeType_m = CHANGEBRUSH_SCALING_INCRCONST;
02116                 ChangeParam_m.m_NewScalingIncrConst = EditData->m_BrushScalingIncrConst;
02117             }
02118         }
02119         else
02120         {
02121             //InformWarning(_R(IDS_BRUSHSCALINGINCRINVALID));
02122             UpdateEditBox(_R(IDC_EDITSCALINGINCRCONST));
02123         }
02124     }
02125     else if (Msg->GadgetID == _R(IDC_EDITBRUSHSCALINGINCR))
02126     {
02127         DoubleNewVal = GetDoubleGadgetValue (_R(IDC_EDITBRUSHSCALINGINCR), MinMultiSlider, MaxMultiSlider, _R(IDS_INCRPROP_INVALID), &Valid);
02128         if (! Valid || DoubleNewVal < MinMultiSlider || DoubleNewVal > MaxMultiSlider)
02129         {
02130             //InformWarning(_R(IDS_INCRPROP_INVALID));
02131             UpdateEditBox(_R(IDC_EDITBRUSHSCALINGINCR));
02132         }
02133         else
02134         {
02135             if (EditData->m_BrushScalingIncr != DoubleNewVal / 100)
02136             {
02137                 EditData->m_BrushScalingIncr = DoubleNewVal / 100;
02138                 ChangeType_m = CHANGEBRUSH_SCALING_INCR;
02139                 ChangeParam_m.m_NewScalingIncr = DoubleNewVal / 100;
02140                 ReInitBrushScaling();
02141             }
02142         }
02143     }
02144     else if (Msg->GadgetID == _R(IDC_EDITROTATEANGLE))
02145     {
02146         DoubleNewVal = GetDoubleGadgetValue(_R(IDC_EDITROTATEANGLE), 0, MAX_ANGLE_DEG, _R(IDS_BRUSHANGLE_INVALID), &Valid );
02147         if (! Valid || DoubleNewVal < 0 || DoubleNewVal > MAX_ANGLE_DEG)
02148         {
02149             //InformWarning(_R(IDS_BRUSHANGLE_INVALID));
02150             UpdateEditBox(_R(IDC_EDITROTATEANGLE));
02151         }
02152         else
02153         {
02154             if (EditData->m_RotateAngle != DoubleNewVal)
02155             {
02156                 EditData->m_RotateAngle = DoubleNewVal;
02157                 ChangeType_m = CHANGEBRUSH_ROTATE_ANGLE;
02158                 ChangeParam_m.m_NewRotateAngle = DoubleNewVal;
02159                 ReInitBrushEffects();
02160             }
02161         }
02162     }
02163     else if (Msg->GadgetID == _R(IDC_EDITROTATEANGLEINCR))
02164     {
02165         DoubleNewVal = GetDoubleGadgetValue(_R(IDC_EDITROTATEANGLEINCR), MIN_ANGLE_DEG , MAX_ANGLE_DEG, _R(IDS_BRUSHANGLE_INVALID), &Valid);
02166         if (!Valid || DoubleNewVal < MIN_ANGLE_DEG || DoubleNewVal > MAX_ANGLE_DEG)
02167         {
02168             //InformWarning(_R(IDS_BRUSHANGLE_INVALID));
02169             UpdateEditBox(_R(IDC_EDITROTATEANGLEINCR));
02170         }
02171         else 
02172         {
02173             if (EditData->m_RotAngleIncrConst != DoubleNewVal)
02174             {
02175                 EditData->m_RotAngleIncrConst = DoubleNewVal ;
02176                 ChangeType_m = CHANGEBRUSH_ROTATE_INCRCONST;
02177                 ChangeParam_m.m_NewRotationIncrConst = DoubleNewVal ;
02178                 ReInitBrushEffects();
02179             }
02180         }
02181     }
02182     else if (Msg->GadgetID == _R(IDC_EDITBRUSHTRANSP))
02183     {
02184         LongNewVal = GetLongGadgetValue(_R(IDC_EDITBRUSHTRANSP), MIN_TRANSP_SLIDER-100 , MAX_TRANSP_SLIDER-100, _R(IDS_BRUSHTRANSP_INVALID), &Valid);
02185         if (Valid)
02186         {
02187             if (EditData->m_BrushTransparency != LongNewVal + 100)
02188             {
02189                 EditData->m_BrushTransparency = LongNewVal + 100;
02190                 ChangeType_m = CHANGEBRUSH_TRANSP;
02191                 ChangeParam_m.m_NewTransp = EditData->m_BrushTransparency;
02192                 ReInitBrushSequence();
02193             }
02194             
02195                 
02196         }
02197         UpdateEditBox(_R(IDC_EDITBRUSHTRANSP));
02198     }
02199 }
02200 
02201 void CBrushEditDlg::ReadComboBox (DialogMsg* Msg)
02202 {
02203 //  SequenceType NewSeqType;
02204 //  PathOffset NewOffsetType;
02205     WORD Index = (WORD)(-1);
02206 
02207     if (Msg->GadgetID == _R(IDC_COMBOPATHOFFSETTYPE))
02208     {
02209         GetValueIndex(_R(IDC_COMBOPATHOFFSETTYPE), &Index);
02210         UsingRandomOffset = FALSE;
02211         
02212         switch (Index)
02213         {
02214             case -1:
02215                 ERROR3("Invalid index");
02216             break;
02217 
02218             case OFFSET_NONE:
02219                 EditData->m_PathOffsetType = OFFSET_NONE;
02220                 if (EditData->m_OffsetValueMaxRand == 0)
02221                     ChangeParam_m.m_NewPathOffsetType = OFFSET_NONE;
02222                 else
02223                     ChangeParam_m.m_NewPathOffsetType = OFFSET_RANDOM;
02224         
02225                 ChangeType_m = CHANGEBRUSH_OFFSET_TYPE;
02226                 ReInitBrushOffset ();
02227             break;
02228 
02229             case OFFSET_ALTERNATE:
02230                 EditData->m_PathOffsetType = OFFSET_ALTERNATE;
02231                 ChangeType_m = CHANGEBRUSH_OFFSET_TYPE;
02232                 ChangeParam_m.m_NewPathOffsetType = OFFSET_ALTERNATE;
02233                 ReInitBrushOffset ();
02234             break;
02235 
02236             case OFFSET_LEFT:
02237                 EditData->m_PathOffsetType = OFFSET_LEFT;
02238                 ChangeType_m = CHANGEBRUSH_OFFSET_TYPE;
02239                 ChangeParam_m.m_NewPathOffsetType = OFFSET_LEFT;
02240                 ReInitBrushOffset ();
02241             break;
02242 
02243             case OFFSET_RIGHT:
02244                 EditData->m_PathOffsetType = OFFSET_RIGHT;
02245                 ChangeType_m = CHANGEBRUSH_OFFSET_TYPE;
02246                 ChangeParam_m.m_NewPathOffsetType = OFFSET_RIGHT;
02247                 ReInitBrushOffset ();
02248             break;
02249 
02250             case OFFSET_RANDOM:
02251                 UsingRandomOffset = TRUE;
02252                 EditData->m_PathOffsetType = OFFSET_RANDOM;
02253                 ChangeType_m = CHANGEBRUSH_OFFSET_TYPE;
02254                 ChangeParam_m.m_NewPathOffsetType = OFFSET_RANDOM;
02255                 ReInitBrushOffset ();
02256             break;
02257 
02258             default:
02259                 ERROR3("Unrecognised offset type");
02260                 ChangeType_m = CHANGEBRUSH_NONE;
02261             break;
02262         }
02263     }
02264     else if (Msg->GadgetID == _R(IDC_COMBOSEQUENCETYPE))
02265     {
02266         GetValueIndex(_R(IDC_COMBOSEQUENCETYPE), &Index);
02267         switch(Index)
02268         {
02269             case SEQ_FORWARD:
02270                 EditData->m_SequenceType = SEQ_FORWARD;
02271                 ChangeType_m = CHANGEBRUSH_SEQUENCE;
02272                 ChangeParam_m.m_NewSequenceType = SEQ_FORWARD;
02273             break;
02274 
02275             case SEQ_BACKWARD:
02276                 EditData->m_SequenceType = SEQ_BACKWARD;
02277                 ChangeType_m = CHANGEBRUSH_SEQUENCE;
02278                 ChangeParam_m.m_NewSequenceType = SEQ_BACKWARD;
02279             break;
02280 
02281             case SEQ_MIRROR:
02282                 EditData->m_SequenceType = SEQ_MIRROR;
02283                 ChangeType_m = CHANGEBRUSH_SEQUENCE;
02284                 ChangeParam_m.m_NewSequenceType = SEQ_MIRROR;
02285             break;
02286 
02287             case SEQ_RANDOM:
02288                 EditData->m_SequenceType = SEQ_RANDOM;
02289                 ChangeType_m = CHANGEBRUSH_SEQUENCE;
02290                 ChangeParam_m.m_NewSequenceType = SEQ_RANDOM;
02291             break;
02292 
02293             default:
02294                 ERROR3("Unrecognised sequence type");
02295                 ChangeType_m = CHANGEBRUSH_NONE;
02296             break;
02297         }
02298     ReInitBrushSpacing();
02299     }
02300     else
02301         ChangeType_m = CHANGEBRUSH_NONE;
02302 }
02303 
02304 void CBrushEditDlg::ReadCheckBox (DialogMsg* Msg)
02305 {   
02306 //  BOOL Checked;
02307 
02308     if (Msg->GadgetID == _R(IDC_CHECKTILEING))
02309     {
02310         EditData->m_bTile = !(EditData->m_bTile);
02311         //GetBoolGadgetSelected (_R(IDC_CHECKTILEING),0, &Checked);
02312         //EditData->m_bTile = Checked;
02313         ChangeType_m = CHANGEBRUSH_TILED;
02314         ChangeParam_m.m_bNewTiled = EditData->m_bTile;//Checked;
02315         ReInitBrushFill();
02316     }
02317     else if (Msg->GadgetID == _R(IDC_CHECKLOCALFILLCOLOUR))
02318     {
02319         //GetBoolGadgetSelected (_R(IDC_CHECKLOCALFILLCOLOUR),0, &Checked);
02320         EditData->m_bUseLocalFillColour = !(EditData->m_bUseLocalFillColour);//Checked;
02321         ChangeType_m = CHANGEBRUSH_USELOCALFILLCOL;
02322         ChangeParam_m.m_bNewUseLocalFillColour = EditData->m_bUseLocalFillColour;//Checked;
02323         ReInitBrushFill();
02324     }
02325     else if (Msg->GadgetID == _R(IDC_CHECKOVERRIDENAMED))
02326     {
02327         EditData->m_bUseNamedColour = !(EditData->m_bUseNamedColour);
02328         ChangeType_m = CHANGEBRUSH_USENAMEDCOL;
02329         ChangeParam_m.m_bNewUseNamed = EditData->m_bUseNamedColour;
02330         ReInitBrushFill();
02331     }
02332     else if (Msg->GadgetID == _R(IDC_CHECKROTATE))
02333     {
02334         //GetBoolGadgetSelected (_R(IDC_CHECKROTATE),0, &Checked);
02335         EditData->m_bRotate = !(EditData->m_bRotate);//Checked;
02336         ChangeType_m = CHANGEBRUSH_TANGENTIAL;
02337         ChangeParam_m.m_bNewRotated = EditData->m_bRotate;//Checked;
02338         //  ReInitBrushEffects ();
02339 
02340         /*if (!(EditData->m_bRotate))
02341         {
02342             EditData->m_RotateAngle = DefaultRotationAngle;
02343         }*/
02344     }
02345     else
02346     {
02347         //ERROR3 ("Unrecognised gadget"); // not necessarily an error, as it may have been a button
02348         ChangeType_m = CHANGEBRUSH_NONE;
02349     }
02350 }
02351 
02352 void CBrushEditDlg::ReadRadios(DialogMsg* Msg)
02353 {
02354     if (Msg == NULL)
02355         return;
02356 
02357     if (Msg->GadgetID == _R(IDC_RADIOLOCALFILLALL))
02358     {
02359         if (EditData->m_bUseLocalFillColour == FALSE)
02360         {
02361             EditData->m_bUseLocalFillColour = TRUE;
02362             // we need to set this to true to indicate that we are not overriding only named
02363             // colours, the semantics are a little off i'm afraid
02364             EditData->m_bUseNamedColour = TRUE;
02365             ChangeParam_m.m_bNewUseLocalFillColour = TRUE;
02366             ChangeType_m = CHANGEBRUSH_USELOCALFILLCOL;
02367         }
02368     }
02369     else if (Msg->GadgetID == _R(IDC_RADIOLOCALFILLNAMED))
02370     {
02371         // potentially a bit confusing this: if UseNamed == TRUE then we do not use
02372         // any of the local colours, if UseNamed == FALSE then we do
02373         if (EditData->m_bUseNamedColour == TRUE)
02374         {
02375             EditData->m_bUseNamedColour = FALSE;
02376             EditData->m_bUseLocalFillColour = FALSE;
02377             ChangeParam_m.m_bNewUseNamed = FALSE;
02378             ChangeType_m = CHANGEBRUSH_USENAMEDCOL;
02379         }
02380     }
02381     else if (Msg->GadgetID == _R(IDC_RADIOLOCALFILLNONE))
02382     {
02383         // find out which local option was selected and turn it off
02384         if (EditData->m_bUseLocalFillColour)
02385         {
02386             EditData->m_bUseLocalFillColour = FALSE;
02387             ChangeParam_m.m_bNewUseLocalFillColour = FALSE;
02388             ChangeType_m = CHANGEBRUSH_USELOCALFILLCOL;
02389         }
02390 
02391         if (EditData->m_bUseNamedColour == FALSE)
02392         {
02393             EditData->m_bUseNamedColour =   TRUE;
02394             ChangeParam_m.m_bNewUseNamed = TRUE;
02395             ChangeType_m = CHANGEBRUSH_USENAMEDCOL;
02396         }
02397         
02398     }
02399 }
02400 
02401 void CBrushEditDlg::ReadSlider (DialogMsg* Msg)
02402 {
02403     BOOL Valid;
02404     INT32 Result;
02405     
02406     ChangeType_m = CHANGEBRUSH_NONE; // initialise our op type to none
02407     
02408     if (Msg->GadgetID == _R(IDC_SLIDERBRUSHSPACING1))
02409     {
02410         double MinSpacingSlider = 0;
02411         double MaxSpacingSlider = 0;
02412 
02413         GetSpacingRange(&MinSpacingSlider, &MaxSpacingSlider);
02414 
02415         INT32 IntMin = (INT32)(MinSpacingSlider);
02416         INT32 IntMax = (INT32)(MaxSpacingSlider);
02417 
02418         Result = GetLongGadgetValue (_R(IDC_SLIDERBRUSHSPACING1), IntMin, IntMax, 0, &Valid);
02419         Result = (IntMax - Result) + IntMin;
02420         
02421         if (Valid)
02422         {
02423             double ExpVal = pow(Result, ExpFactor);
02424             MILLIPOINT NewSpacing = (MILLIPOINT)ExpVal;
02425     
02426             EditData->m_BrushSpacing = NewSpacing;
02427             ChangeParam_m.m_NewSpacing = NewSpacing;
02428             ChangeType_m = CHANGEBRUSH_SPACING;
02429             SetSpacingSlider();
02430         
02431         
02432         }
02433     }
02434     else if (Msg->GadgetID == _R(IDC_SLIDERBRUSHSPACINGINCR))
02435     {
02436         double dblResult = GetDoubleGadgetValue(_R(IDC_SLIDERBRUSHSPACINGINCR), MIN_SPACING_INCR, MAX_SPACING_INCR, 0, &Valid);
02437         dblResult = (MAX_SPACING_INCR - dblResult) + MIN_SPACING_INCR;
02438         if (Valid)
02439         {
02440             // we need to convert the % value we got from the slider into millipoints
02441             MILLIPOINT Distance = GetPercentageAsDistance(dblResult, WIDTH);
02442     
02443             EditData->m_BrushSpacingIncrConst = Distance;
02444             ChangeParam_m.m_NewSpacingIncrConst = Distance;
02445             ChangeType_m = CHANGEBRUSH_SPACING_INCRCONST;
02446             UpdateEditBox(_R(IDC_EDITBRUSHSPACINGINCRCONST));
02447         
02448         }
02449     }           
02450     else if (Msg->GadgetID == _R(IDC_SLIDERBRUSHSPACINGMAXRAND))
02451     {
02452         Result = GetLongGadgetValue (_R(IDC_SLIDERBRUSHSPACINGMAXRAND), MIN_RANDOM_SLIDER, MAX_RANDOM_SLIDER, 0, &Valid);
02453         Result = MAX_RANDOM_SLIDER - Result;
02454 
02455         if (Valid)
02456         {
02457             EditData->m_BrushSpacingMaxRand = Result;
02458             
02459             if (!UsingRandomSpacing)
02460             {
02461                 if (Result != MIN_RANDOM_SLIDER)
02462                 {
02463                     ReInitBrushSpacing ();
02464                 }
02465             }
02466             else if (Result == MIN_RANDOM_SLIDER)
02467             {
02468                 ReInitBrushSpacing ();
02469             }
02470             ChangeType_m  = CHANGEBRUSH_SPACING_MAXRAND;
02471             ChangeParam_m.m_NewSpacingMaxRand = Result;
02472             SetRandomRangeText(_R(IDC_SLIDERBRUSHSPACINGMAXRAND));
02473         }
02474     }
02475     else if (Msg->GadgetID == _R(IDC_SLIDERPATHOFFSETVAL))
02476     {
02477         double MinOffset = 0;
02478         double MaxOffset = 0;
02479 
02480         GetOffsetRange(&MinOffset, &MaxOffset);
02481 
02482         INT32 lMinOffset  = (INT32)MinOffset;
02483         INT32 lMaxOffset  = (INT32)MaxOffset;
02484 
02485         Result = GetLongGadgetValue(_R(IDC_SLIDERPATHOFFSETVAL), lMinOffset, lMaxOffset, 0, &Valid);
02486         Result = (lMaxOffset - Result) + lMinOffset;
02487 
02488         if (Valid)
02489         {
02490             double ExpVal = pow(Result, ExpFactor);
02491             MILLIPOINT NewOffset = (MILLIPOINT)ExpVal;
02492         
02493             EditData->m_PathOffsetValue = NewOffset;
02494             ChangeParam_m.m_NewPathOffsetVal = NewOffset;
02495             ChangeType_m = CHANGEBRUSH_OFFSET_VAL;
02496             ReInitBrushOffset();
02497             
02498         }
02499         
02500     }
02501     else if (Msg->GadgetID == _R(IDC_SLIDEROFFSETINCRCONST))
02502     {
02503         double NewIncr = GetDoubleGadgetValue(_R(IDC_SLIDEROFFSETINCRCONST), MIN_SPACING_INCR, MAX_SPACING_INCR, 0, &Valid);
02504         
02505         if (Valid)
02506         {
02507             NewIncr = (MAX_SPACING_INCR - NewIncr) + MIN_SPACING_INCR;
02508             MILLIPOINT Incr = GetPercentageAsDistance(NewIncr, HEIGHT);
02509             if (abs(EditData->m_PathOffsetIncrConst - Incr) > 20)
02510             {
02511                 EditData->m_PathOffsetIncrConst = Incr;
02512                 ChangeParam_m.m_NewOffsetIncrConst = Incr;
02513                 ChangeType_m = CHANGEBRUSH_OFFSET_INCRCONST;
02514                 UpdateEditBox(_R(IDC_EDITPATHOFFSETINCRCONST));
02515             }
02516         }
02517     }
02518     else if (Msg->GadgetID == _R(IDC_SLIDEROFFSETVALUEMAXRAND))
02519     {
02520         Result = GetLongGadgetValue (_R(IDC_SLIDEROFFSETVALUEMAXRAND), MinOffsetSlider, MaxOffsetSlider, 0, &Valid);
02521         Result = MaxOffsetSlider - Result;
02522 
02523         if (Valid)
02524         {
02525             EditData->m_OffsetValueMaxRand = Result;
02526         
02527             // if this is the first movement of the slider and our offset type is offset_none then
02528             // surreptitiously change this to offset_random
02529             if (EditData->m_PathOffsetType == OFFSET_NONE)
02530             {
02531                 EditData->m_PathOffsetType = OFFSET_RANDOM;
02532                 ChangeParam_m.m_NewPathOffsetType = OFFSET_RANDOM;
02533                 ChangeType_m = CHANGEBRUSH_ALL;
02534             }
02535             else
02536                 ChangeType_m = CHANGEBRUSH_OFFSET_MAXRAND;
02537             
02538             ChangeParam_m.m_NewOffsetValMaxRand = Result;
02539         }
02540         ReInitBrushOffset();
02541     }
02542     else if (Msg->GadgetID == _R(IDC_SLIDERBRUSHSCALINGMAXRAND))
02543     {
02544         Result = GetLongGadgetValue (_R(IDC_SLIDERBRUSHSCALINGMAXRAND), MinScalingSlider, MaxScalingSlider, 0, &Valid);
02545         Result = MaxScalingSlider - Result;
02546 
02547         if (Valid)
02548         {
02549             EditData->m_BrushScalingMaxRand = Result;
02550 
02551             if (!UsingRandomScaling)
02552             {
02553                 if (Result != MinScalingSlider)
02554                 {
02555                     ReInitBrushScaling ();
02556                 }
02557             }
02558             else if (Result == MinScalingSlider)
02559             {
02560                 ReInitBrushScaling ();
02561             }
02562             SetRandomRangeText(_R(IDC_SLIDERBRUSHSCALINGMAXRAND));
02563             ChangeType_m = CHANGEBRUSH_SCALING_MAXRAND;
02564             ChangeParam_m.m_NewScalingMaxRand = Result;
02565         }
02566     }
02567     else if (Msg->GadgetID == _R(IDC_SLIDERROTATEANGLE))
02568     {
02569         double NewAngle = GetDoubleGadgetValue(_R(IDC_SLIDERROTATEANGLE), MIN_ROTATION_SLIDER, MAX_ROTATION_SLIDER, 0, &Valid);
02570         if (Valid)
02571         {
02572             NewAngle = (MAX_ROTATION_SLIDER - NewAngle) + MIN_ROTATION_SLIDER;
02573         
02574             // make it a whole number
02575             INT32 AngleRounded = (INT32)NewAngle;
02576             ChangeParam_m.m_NewRotateAngle = (double)AngleRounded;
02577             ChangeType_m = CHANGEBRUSH_ROTATE_ANGLE;
02578             EditData->m_RotateAngle = ChangeParam_m.m_NewRotateAngle;
02579             ReInitBrushEffects();
02580                 
02581             
02582         }
02583     }
02584     else if (Msg->GadgetID == _R(IDC_SLIDERROTATEANGLEINCR))
02585     {
02586         double NewIncr = GetDoubleGadgetValue(_R(IDC_SLIDERROTATEANGLEINCR), MIN_ROTATION_INCR_SLIDER, MAX_ROTATION_INCR_SLIDER,
02587                                                 0, &Valid);
02588         if (Valid)
02589         {
02590             NewIncr = (MAX_ROTATION_INCR_SLIDER - NewIncr) + MIN_ROTATION_INCR_SLIDER;
02591         
02592             INT32 IncrRounded = (INT32)NewIncr;
02593             EditData->m_RotAngleIncrConst  =(double)IncrRounded;
02594             ChangeParam_m.m_NewRotationIncrConst = EditData->m_RotAngleIncrConst;
02595             ChangeType_m = CHANGEBRUSH_ROTATE_INCRCONST;
02596             ReInitBrushEffects();
02597             
02598         }
02599     }
02600     else if (Msg->GadgetID == _R(IDC_SLIDERROTATEANGLEMAXRAND))
02601     {
02602         Result = GetLongGadgetValue (_R(IDC_SLIDERROTATEANGLEMAXRAND), MIN_RANDOM_SLIDER, MAX_ROTATION_RANDOM_SLIDER, 0, &Valid);
02603         Result = (MAX_ROTATION_RANDOM_SLIDER - Result) + MIN_RANDOM_SLIDER;
02604         //TRACEUSER( "Diccon", _T("Rotation max rand = %d\n"), Result);
02605         if (Valid)
02606         {
02607             EditData->m_RotationMaxRand = Result;   
02608             ReInitBrushEffects ();
02609         
02610             ChangeType_m = CHANGEBRUSH_ROTATE_MAXRAND;
02611             ChangeParam_m.m_NewRotateMaxRand = Result;
02612             SetRandomRangeText(_R(IDC_SLIDERROTATEANGLEMAXRAND));
02613         }
02614     }
02615     else if (Msg->GadgetID == _R(IDC_SLIDERROTATEINCR))
02616     {
02617         Result = GetLongGadgetValue(_R(IDC_SLIDERROTATEINCR), MinMultiSlider, MaxMultiSlider, 0, &Valid);
02618         Result = (MaxMultiSlider - Result) + MinMultiSlider;
02619         if (Valid)
02620         {
02621         
02622             EditData->m_RotAngleIncrProp = (double)((double)Result / 100);
02623             ReInitBrushEffects();
02624             ChangeType_m = CHANGEBRUSH_ROTATE_INCRPROP;
02625             ChangeParam_m.m_NewRotationIncrProp = EditData->m_RotAngleIncrProp;
02626             
02627         }
02628     }
02629     else if (Msg->GadgetID == _R(IDC_SLIDERBRUSHSCALINGINCR))
02630     {
02631         Result = GetLongGadgetValue (_R(IDC_SLIDERBRUSHSCALINGINCR), MinMultiSlider, MaxMultiSlider, 0, &Valid);
02632         Result = (MaxMultiSlider - Result) + MinMultiSlider;
02633         if (Valid)
02634         {
02635         
02636             EditData->m_BrushScalingIncr = (double)Result / 100;
02637             ReInitBrushScaling();
02638             ChangeType_m = CHANGEBRUSH_SCALING_INCR;
02639             ChangeParam_m.m_NewScalingIncr = EditData->m_BrushScalingIncr;
02640             
02641         }
02642     }
02643     else if (Msg->GadgetID == _R(IDC_SLIDERSCALINGINCRCONST))
02644     {
02645         Result = GetLongGadgetValue(_R(IDC_SLIDERSCALINGINCRCONST), MinScalingIncrSlider, MaxScalingIncrSlider, 0, &Valid);
02646         Result = (MaxScalingIncrSlider - Result) + MinScalingIncrSlider;
02647         if (Valid)
02648         {
02649             if (EditData->m_BrushScalingIncrConst != Result)
02650             {
02651                 EditData->m_BrushScalingIncrConst = (double)Result;
02652                 ReInitBrushScaling();
02653                 ChangeType_m = CHANGEBRUSH_SCALING_INCRCONST;
02654                 ChangeParam_m.m_NewScalingIncrConst = (double)Result;
02655             }
02656         }
02657     }
02658     else if (Msg->GadgetID == _R(IDC_SLIDERSCALINGPRESSURE))
02659     {
02660         Result = GetLongGadgetValue(_R(IDC_SLIDERSCALINGPRESSURE), MIN_PRESSURE_SLIDER, MAX_PRESSURE_SLIDER, 0, &Valid);
02661         if (Valid)
02662         {
02663             Result = (MAX_PRESSURE_SLIDER - Result) + MIN_PRESSURE_SLIDER;
02664     
02665             EditData->m_ScalingMaxPressure = Result;
02666             ReInitBrushScaling();
02667             ChangeType_m = CHANGEBRUSH_SCALING_PRESSURE;
02668             ChangeParam_m.m_NewScalingMaxPressure = Result;
02669             SetRandomRangeText(_R(IDC_SLIDERSCALINGPRESSURE));
02670             
02671         }
02672     }
02673     else if (Msg->GadgetID == _R(IDC_SLIDERSATURATIONRANDOM))
02674     {
02675         Result = GetLongGadgetValue(_R(IDC_SLIDERSATURATIONRANDOM), MIN_RANDOM_SLIDER, MAX_RANDOM_SAT_SLIDER, 0, &Valid);
02676         if (Valid)
02677         {
02678             Result = (MAX_RANDOM_SAT_SLIDER - Result) + MIN_RANDOM_SLIDER;
02679     
02680             EditData->m_BrushSatMaxRand = Result;
02681             ChangeType_m = CHANGEBRUSH_SAT_MAXRAND;
02682             ChangeParam_m.m_NewSatMaxRand = Result;
02683             SetRandomRangeText(_R(IDC_SLIDERSATURATIONRANDOM));
02684             
02685             ReInitBrushFill();
02686         }
02687     }
02688     else if (Msg->GadgetID == _R(IDC_SLIDERHUERANDOM))
02689     {
02690         Result = GetLongGadgetValue(_R(IDC_SLIDERHUERANDOM), MIN_RANDOM_SLIDER, MAX_RANDOM_HUE_SLIDER, 0, &Valid);
02691         if (Valid)
02692         {
02693             Result = (MAX_RANDOM_HUE_SLIDER - Result) + MIN_RANDOM_SLIDER;
02694     
02695             EditData->m_BrushHueMaxRand = Result;
02696             ChangeType_m = CHANGEBRUSH_HUE_MAXRAND;
02697             ChangeParam_m.m_NewHueMaxRand = Result;
02698             SetRandomRangeText(_R(IDC_SLIDERHUERANDOM));
02699             
02700             ReInitBrushFill();
02701         }
02702     }
02703     else if (Msg->GadgetID == _R(IDC_SLIDERTRANSP))
02704     {
02705         Result = GetLongGadgetValue(_R(IDC_SLIDERTRANSP), MIN_TRANSP_SLIDER, MAX_TRANSP_SLIDER, 0, &Valid);
02706         if (Valid)
02707         {
02708             Result = (MAX_TRANSP_SLIDER - Result) + MIN_TRANSP_SLIDER;
02709     
02710             EditData->m_BrushTransparency = Result;
02711             ChangeType_m = CHANGEBRUSH_TRANSP;
02712             ChangeParam_m.m_NewTransp = Result;
02713             UpdateEditBox(_R(IDC_EDITBRUSHTRANSP));
02714             
02715         }
02716     }
02717     else if (Msg->GadgetID == _R(IDC_SLIDERTRANSPPRESSURE))
02718     {
02719         Result = GetLongGadgetValue(_R(IDC_SLIDERTRANSPPRESSURE), MIN_PRESSURE_SLIDER, MAX_PRESSURE_SLIDER, 0, &Valid);
02720         if (Valid)
02721         {
02722             Result = (MAX_PRESSURE_SLIDER - Result) + MIN_PRESSURE_SLIDER;
02723         
02724             EditData->m_TranspMaxPressure = Result;
02725             ChangeType_m = CHANGEBRUSH_TRANSP_PRESSURE;
02726             ChangeParam_m.m_NewTranspPressure = Result;
02727             ReInitBrushSequence();
02728             
02729         }
02730     }
02731 }
02732 
02733 
02734 void CBrushEditDlg::ReadButtons(DialogMsg* Msg)
02735 {
02736     if (Msg->GadgetID == _R(IDC_BUTTONBRUSHSCALINGRANDSEED))
02737     {
02738         ChangeType_m = CHANGEBRUSH_SCALING_RANDSEED;
02739         ChangeParam_m.m_NewScalingRandSeed = GetNewRandomNumber(0);
02740         EditData->m_BrushScalingRandSeed = ChangeParam_m.m_NewScalingRandSeed;
02741     }
02742     else if (Msg->GadgetID == _R(IDC_BUTTONBRUSHSPACINGRANDSEED))
02743     {
02744         ChangeType_m = CHANGEBRUSH_SPACING_RANDSEED;
02745         ChangeParam_m.m_NewSpacingRandSeed = GetNewRandomNumber(0);
02746         EditData->m_BrushSpacingRandSeed = ChangeParam_m.m_NewSpacingRandSeed;
02747         
02748         // We're changing sequence seed too
02749         ChangeParam_m.m_NewSequenceRandSeed = EditData->m_BrushSpacingRandSeed;
02750         EditData->m_SequenceRandSeed = ChangeParam_m.m_NewSequenceRandSeed;
02751     }
02752     else if (Msg->GadgetID == _R(IDC_BUTTONOFFSETVALUERANDSEED))
02753     {
02754         // bit of a change here, we only want to have one random button on the offset tab 
02755         // so this button now changes seeds for both offset value and offset type
02756 
02757         ChangeType_m = CHANGEBRUSH_OFFSET_SEEDS;
02758         ChangeParam_m.m_NewOffsetValRandSeed = GetNewRandomNumber(0);
02759         ChangeParam_m.m_NewOffsetTypeRandSeed = GetNewRandomNumber(0);
02760         EditData->m_OffsetValueRandSeed = ChangeParam_m.m_NewOffsetValRandSeed;
02761         EditData->m_OffsetTypeRandSeed = ChangeParam_m.m_NewOffsetTypeRandSeed;
02762     }
02763     else if (Msg->GadgetID == _R(IDC_BUTTONBRUSHSEQUENCERANDSEED))
02764     {
02765         ChangeType_m = CHANGEBRUSH_SEQUENCE_RANDSEED;
02766         ChangeParam_m.m_NewSequenceRandSeed = GetNewRandomNumber(0);
02767         EditData->m_SequenceRandSeed = ChangeParam_m.m_NewSequenceRandSeed;
02768     }
02769     else if (Msg->GadgetID == _R(IDC_BUTTONROTATEANGLERANDSEED))
02770     {
02771         ChangeType_m = CHANGEBRUSH_ROTATE_RANDSEED;
02772         ChangeParam_m.m_NewRotateRandSeed = GetNewRandomNumber(0);
02773         EditData->m_RotationRandSeed = ChangeParam_m.m_NewRotateRandSeed;
02774     }
02775     else if (Msg->GadgetID == _R(IDC_BUTTONBRUSHFILLRANDOM))
02776     {
02777         ChangeType_m = CHANGEBRUSH_FILL_SEEDS;
02778         ChangeParam_m.m_NewHueRandSeed = GetNewRandomNumber(0);
02779         ChangeParam_m.m_NewSatRandSeed = GetNewRandomNumber(0);
02780         EditData->m_BrushHueRandSeed = ChangeParam_m.m_NewHueRandSeed;
02781         EditData->m_BrushSatRandSeed = ChangeParam_m.m_NewSatRandSeed;
02782     }
02783 }
02784 
02785 void CBrushEditDlg::WriteSliders (DialogMsg* Msg)
02786 {
02787 
02788 }
02789 
02790 void CBrushEditDlg::UpdateEditBox (CGadgetID GadgetToUpdate)
02791 {   
02792     if (GadgetToUpdate == _R(IDC_EDITBRUSHSPACING))
02793     {
02794         // work out the current actual spacing value
02795         double dSpacingValue = (double)EditData->m_BrushSpacing; // * EditData->m_BrushScaling;
02796         MILLIPOINT lSpacingValue = (MILLIPOINT)dSpacingValue;
02797         dSpacingValue = pow(dSpacingValue, 1/ExpFactor);
02798 //      INT32 iSpacingValue = (INT32)dSpacingValue;
02799     
02800         // get the spacing value as a % and set that in the edit field
02801         double SpacingAsPercent = GetDistanceAsPercentageOfBBox(lSpacingValue, WIDTH);
02802         SetDoubleGadgetValue (_R(IDC_EDITBRUSHSPACING), SpacingAsPercent);
02803     
02804     }
02805     /*
02806     else if (GadgetToUpdate == _R(IDC_EDITBRUSHSPACINGINCRCONST))
02807     {
02808         // for the edit box we need to set it as a percentage
02809         double PercentVal = GetDistanceAsPercentageOfBBox(EditData->m_BrushSpacingIncrConst);
02810         SetDoubleGadgetValue(_R(IDC_EDITBRUSHSPACINGINCRCONST), PercentVal);
02811     }
02812     */
02813     else if (GadgetToUpdate == _R(IDC_EDITPATHOFFSETVALUE))
02814     {
02815         double PercentVal = GetDistanceAsPercentageOfBBox(EditData->m_PathOffsetValue, HEIGHT);
02816         SetDoubleGadgetValue(_R(IDC_EDITPATHOFFSETVALUE), PercentVal);
02817     }
02818     /*
02819     else if (GadgetToUpdate == _R(IDC_EDITPATHOFFSETINCRCONST))
02820     {
02821         double PercentVal = GetDistanceAsPercentageOfBBox(EditData->m_PathOffsetIncrConst);
02822         SetDoubleGadgetValue(_R(IDC_EDITPATHOFFSETINCRCONST), PercentVal);
02823     }       
02824     */
02825     else if (GadgetToUpdate == _R(IDC_EDITBRUSHSCALING))
02826     {
02827         SetDoubleGadgetValue (_R(IDC_EDITBRUSHSCALING), EditData->m_BrushScaling);
02828     }
02829     else if (GadgetToUpdate == _R(IDC_EDITBRUSHSCALINGINCR))
02830     {
02831         SetDoubleGadgetValue (_R(IDC_EDITBRUSHSCALINGINCR), EditData->m_BrushScalingIncr*100);
02832     }
02833     /*
02834     else if (GadgetToUpdate == _R(IDC_EDITSCALINGINCRCONST))
02835     {
02836         SetDoubleGadgetValue (_R(IDC_EDITSCALINGINCRCONST), EditData->m_BrushScalingIncrConst);
02837     }
02838     */
02839     else if (GadgetToUpdate == _R(IDC_EDITROTATEANGLEINCR))
02840     {
02841         SetDoubleGadgetValue (_R(IDC_EDITROTATEANGLEINCR), EditData->m_RotAngleIncrConst);
02842     }
02843     else if (GadgetToUpdate == _R(IDC_EDITROTATEANGLE))
02844     {
02845         SetDoubleGadgetValue (_R(IDC_EDITROTATEANGLE), EditData->m_RotAngleIncrConst);
02846     }
02847     else if (GadgetToUpdate == _R(IDC_EDITBRUSHTRANSP))
02848     {
02849         SetLongGadgetValue(_R(IDC_EDITBRUSHTRANSP), EditData->m_BrushTransparency - 100);
02850     }
02851 }
02852 
02853 void CBrushEditDlg::ReInitialiseDialog (BrushData* pData)
02854 {
02855     if (pData != NULL)                  
02856     {
02857         if (EditData != NULL)
02858             delete EditData;
02859         EditData = new BrushData(*pData);
02860         if (EditData == NULL)
02861         {
02862             ERROR3("Argh we failed to allocate new brush data");
02863             return;
02864         }
02865 
02866         // we have to reinit all the pages one by one
02867         ReInitPage(_R(IDD_BRUSHEDITSPACING));
02868         ReInitPage(_R(IDD_BRUSHEDITOFFSET));
02869         ReInitPage(_R(IDD_BRUSHEDITSCALING));
02870         ReInitPage(_R(IDD_BRUSHEDITEFFECTS));
02871         ReInitPage(_R(IDD_BRUSHEDITSEQUENCE));
02872             
02873     } // end if data
02874 }
02875 
02876 void CBrushEditDlg::ReInitPage(CDlgResID PageID)
02877 {
02878     // tell the page we're talking to it
02879     TalkToPage(PageID);
02880     // reinit our active page
02881     if (PageID == _R(IDD_BRUSHEDITSPACING))
02882         ReInitBrushSpacing();
02883     else if (PageID == _R(IDD_BRUSHEDITOFFSET))
02884         ReInitBrushOffset();
02885     else if (PageID == _R(IDD_BRUSHEDITSCALING))
02886         ReInitBrushScaling();
02887     else if (PageID == _R(IDD_BRUSHEDITEFFECTS))
02888         ReInitBrushEffects();
02889     else if (PageID == _R(IDD_BRUSHEDITSEQUENCE))
02890         ReInitBrushSequence();
02891     else if (PageID == _R(IDD_BRUSHEDITFILL))
02892     {
02893     }
02894     else
02895     {
02896         ERROR3("Message from unknown tab dialog page");
02897     }
02898     
02899 }
02900 
02901 
02902 // looks to see if there is one and only one brush attribute in the selection and returns it
02903 AttrBrushType* CBrushEditDlg::GetSingleSelectedBrushAttribute()
02904 {
02905     AttrBrushType* pAttrBrush = NULL;
02906     List NodeList;
02907     BevelTools::BuildListOfSelectedNodes(&NodeList, CC_RUNTIME_CLASS(AttrBrushType));
02908     BrushData Data; // initialises to default values
02909     INT32 NumItems = NodeList.GetCount();
02910     if (NumItems == 1)
02911     {
02912         NodeListItem* pItem = (NodeListItem*)NodeList.GetHead();
02913         if (pItem != NULL)
02914             pAttrBrush = (AttrBrushType*)pItem->pNode;
02915     }
02916     NodeList.DeleteAll();
02917     return pAttrBrush;
02918 }
02919 
02920 // deals with a selection change, essentially if we change from one brush to another
02921 // then we refresh the dialog, if we change to no-brush then we disable everything
02922 void CBrushEditDlg::HandleDocSelectionChange()
02923 {
02924     AttrBrushType* pAttrBrush = GetSingleSelectedBrushAttribute();
02925     if (pAttrBrush == NULL)
02926     {
02927         m_bDisableGadgets = TRUE;
02928         String_32 Title = TEXT("");
02929         SetDialogTitle(Title);
02930 
02931         RefreshActivePage();
02932         return;
02933     }
02934 
02935     // lets get the data from the attribute and into our members
02936     if (EditData == NULL)
02937         EditData = new BrushData;
02938 
02939     if (EditData == NULL)
02940         ERROR3("Unable to allocate brush data in CBrushEditDlg::HandleDocSelectionChange");
02941     
02942     *EditData = pAttrBrush->GetBrushData();
02943 
02944     if (OriginalData == NULL)
02945         OriginalData = new BrushData;
02946     
02947     if (OriginalData == NULL)
02948         ERROR3("Unable to allocate brush data in CBrushEditDlg::HandleDocSelectionChange");
02949 
02950     *OriginalData = *EditData;
02951     m_LastData = *EditData;
02952     m_bDisableGadgets = FALSE;
02953     
02954     // set the name of the new brush
02955     SetDialogTitle(EditData->m_Name);
02956     
02957     //initialise our opparam with the original data, just in case we want to do change all
02958     ChangeParam_m.SetValues(*EditData);
02959     
02960     EditingBrushDef = FALSE;
02961     // now refresh the page that is currently active
02962     RefreshActivePage();
02963     
02964 }
02965 
02966 // finds out which page is currently active and ReInits it
02967 void CBrushEditDlg::RefreshActivePage()
02968 {
02969     CDlgResID ActivePageID = GetCurrentPageID();
02970 
02971     if (ActivePageID == _R(IDD_BRUSHEDITSPACING))
02972     {
02973         ReInitBrushSpacing();
02974     }
02975     else if (ActivePageID == _R(IDD_BRUSHEDITOFFSET))
02976     {
02977         ReInitBrushOffset();
02978     }
02979     else if (ActivePageID == _R(IDD_BRUSHEDITSCALING))
02980     {
02981         ReInitBrushScaling();
02982     }
02983     else if (ActivePageID == _R(IDD_BRUSHEDITEFFECTS))
02984     {
02985         ReInitBrushEffects();
02986     }
02987     else if (ActivePageID == _R(IDD_BRUSHEDITSEQUENCE))
02988     {
02989         ReInitBrushSequence();
02990     }
02991     else if (ActivePageID == _R(IDD_BRUSHEDITFILL))
02992     {
02993         ReInitBrushFill();
02994     }
02995     
02996 }
02997 
02998 // using settitlebarname has no effect as it gets the page window rather than 
02999 // the property sheet, so use this instead
03000 void CBrushEditDlg::SetDialogTitle(String_256 Title)
03001 {
03002     SetTitlebarName(&Title);
03003 }
03004 
03005 // sets up the brush spacing slider to have the correct values etc.
03006 void CBrushEditDlg::SetSpacingSlider()
03007 {
03008     // first work out the maximum and minimum values for the spacing slider
03009     double MinSpacingSlider = 0; double MaxSpacingSlider = 0;
03010 
03011     GetSpacingRange(&MinSpacingSlider, &MaxSpacingSlider);
03012 
03013     INT32 IntMin = (INT32)(MinSpacingSlider);
03014     INT32 IntMax = (INT32)(MaxSpacingSlider);
03015 
03016     // set the range
03017     SetGadgetRange (_R(IDC_SLIDERBRUSHSPACING1), IntMin, IntMax);
03018     SetGadgetBitmaps( _R(IDC_SLIDERBRUSHSPACING1), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
03019 
03020     // work out the current actual spacing value
03021     double dSpacingValue = (double)EditData->m_BrushSpacing; // * EditData->m_BrushScaling;
03022     dSpacingValue = pow(dSpacingValue, 1/ExpFactor);
03023     INT32 iSpacingValue = (INT32)dSpacingValue;
03024     SetLongGadgetValue (_R(IDC_SLIDERBRUSHSPACING1), (IntMax - iSpacingValue) + IntMin);
03025     
03026     UpdateEditBox(_R(IDC_EDITBRUSHSPACING));
03027 }
03028 
03029 void CBrushEditDlg::SetSpacingIncrSlider()
03030 {
03031     SetGadgetRange(_R(IDC_SLIDERBRUSHSPACINGINCR), MIN_SPACING_INCR, MAX_SPACING_INCR);
03032     SetGadgetBitmaps (_R(IDC_SLIDERBRUSHSPACINGINCR), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
03033 
03034     double PercentVal = GetDistanceAsPercentageOfBBox(EditData->m_BrushSpacingIncrConst, WIDTH);
03035     SetDoubleGadgetValue(_R(IDC_SLIDERBRUSHSPACINGINCR), (MAX_SPACING_INCR - PercentVal) + MIN_SPACING_INCR);
03036 }
03037 
03038 
03039 void CBrushEditDlg::SetOffsetValSlider()
03040 {
03041     double MinSlider = 0; double MaxSlider = 0;
03042 
03043     GetOffsetRange(&MinSlider, &MaxSlider);
03044 
03045     INT32 IntMin = (INT32)MinSlider;
03046     INT32 IntMax = (INT32)MaxSlider;
03047 
03048     SetGadgetRange(_R(IDC_SLIDERPATHOFFSETVAL), IntMin, IntMax);
03049     SetGadgetBitmaps (_R(IDC_SLIDERPATHOFFSETVAL), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
03050 
03051     double dOffsetVal = pow((double)EditData->m_PathOffsetValue, InvFactor);
03052     INT32 iOffsetVal = (INT32)dOffsetVal;
03053 
03054     SetLongGadgetValue(_R(IDC_SLIDERPATHOFFSETVAL), (IntMax - iOffsetVal) + IntMin);
03055 
03056     UpdateEditBox(_R(IDC_EDITPATHOFFSETVALUE));
03057 }
03058 
03059 
03060 
03061 
03062 // retrieves the range to set the spacing slider. This is calculated by finding the logarithm
03063 // of the minimum spacing and 5x the bounding box size of the object
03064 void CBrushEditDlg::GetSpacingRange(double* pMinimum, double* pMaximum)
03065 {
03066     if (pMinimum == NULL || pMaximum == NULL)
03067     {
03068         ERROR3("Null pointers in CBrushEditDlg::GetSpacingRange");
03069         return;
03070     }
03071 
03072     *pMinimum = MinSliderSpacing;
03073 
03074     MILLIPOINT Width = GetSideOfBoundingBox(WIDTH);
03075     if (Width == 0)
03076     {
03077         ERROR3("Bounding rect is empty in CBrushEditDlg::GetSpacingRange");
03078         return;
03079     }
03080 
03081     Width = Width * MAXSPACINGMULTIPLIER;
03082 
03083     if (Width> MAX_BRUSH_SPACING)
03084         Width = MAX_BRUSH_SPACING;
03085 
03086     double ExpRootWidth = pow((double)Width, 1/ExpFactor);
03087     
03088     *pMaximum = ExpRootWidth;
03089 }
03090 
03091 // as above but for offsets
03092 void CBrushEditDlg::GetOffsetRange(double* pMin, double* pMax)
03093 {
03094     if (pMin == NULL || pMax == NULL)
03095     {
03096         ERROR3("Null pointers in CBrushEditDlg::GetOffsetRange");
03097         return;
03098     }
03099 
03100     *pMin = MinOffset;
03101 
03102     MILLIPOINT Height = GetSideOfBoundingBox(HEIGHT);
03103     if (Height == 0)
03104     {
03105     //  ERROR3("Bounding rect is empty in CBrushEditDlg::GetSpacingRange");
03106         return;
03107     }
03108 
03109     Height = Height * MAXOFFSETMULTIPLIER;
03110 
03111     if (Height > MAX_BRUSH_OFFSET)
03112         Height = MAX_BRUSH_OFFSET;
03113 
03114     double ExpRootHeight = pow((double)Height, 1/ExpFactor);
03115     
03116     *pMax = ExpRootHeight;
03117 }
03118 
03119 // pretty much what the title says
03120 double CBrushEditDlg::GetDistanceAsPercentageOfBBox(MILLIPOINT Distance, RectSideInfo Side)
03121 {
03122     MILLIPOINT RectSide = GetSideOfBoundingBox(Side);
03123     if (RectSide == 0)
03124     {
03125 //      ERROR3("Bounding rect is empty in CBrushEditDlg::GetSpacingRange");
03126         return 0;
03127     }
03128 
03129     double Percent = (double)Distance / (double)RectSide;
03130     return Percent * 100;
03131 }
03132 
03133 MILLIPOINT CBrushEditDlg::GetSideOfBoundingBox(RectSideInfo RectSide)
03134 {
03135     BrushDefinition* pBrushDef = BrushComponent::FindBrushDefinition(EditData->m_BrushHandle);
03136     if (pBrushDef == NULL)
03137     {
03138     //  ERROR3("No brush definition in CBrushEditDlg::GetLongestSideOfBoundingBox");
03139         return 0;
03140     }
03141     
03142     DocRect BRect = pBrushDef->GetLargestBoundingBox();
03143     if (BRect.IsEmpty())
03144     {
03145         //ERROR3("Bounding rect is empty in CBrushEditDlg::GetSpacingRange");
03146         return 0;
03147     }
03148 
03149     MILLIPOINT Side = 0;
03150     switch (RectSide)
03151     {
03152         case WIDTH:
03153             Side = BRect.Width();
03154             break;
03155         case HEIGHT:
03156             Side = BRect.Height();
03157             break;
03158         case LONGEST:
03159             Side = BRect.Width() > BRect.Height() ? BRect.Width() : BRect.Height();
03160             break;
03161         default:
03162             ERROR3("Invalid side info passed to CBrushEditDlg::GetSideOfBoundingBox");
03163             Side = BRect.Width();
03164             break;
03165     }
03166 
03167     return Side;
03168 }
03169 
03170 MILLIPOINT CBrushEditDlg::GetPercentageAsDistance(double Percent, RectSideInfo RectSide)
03171 {
03172     MILLIPOINT Side = GetSideOfBoundingBox(RectSide);
03173 
03174     MILLIPOINT ReturnVal = (MILLIPOINT)(((double)Side) * (Percent / 100));
03175     return ReturnVal;
03176 }
03177 
03178 
03179 // returns the text showing the range of random values for the current slider setting
03180 // Note that SliderVal should be the value adjusted for position, i.e. the value that 
03181 String_32 CBrushEditDlg::GetRandomRangeText(INT32 SliderVal)
03182 {
03183     String_32 RangeText(_T(" "));
03184     if (SliderVal < MIN_RANDOM_SLIDER || SliderVal > MAX_RANDOM_SLIDER)
03185     {
03186         ERROR3("Slider value is out of range in CBrushEditDlg::GetRandomRangeText");
03187         return RangeText;
03188     }
03189     UINT32 BaseVal = 100;
03190     UINT32 MinVal = 100 ;
03191     UINT32 MaxVal = 100 ;
03192 
03193     // the actual limits are worked out in the PPB static function
03194     PathProcessorBrush::GetRandomLimits(BaseVal, SliderVal, &MinVal, &MaxVal);
03195 
03196     // annoyingly we now need to recast our values as long
03197     String_32 MinString;
03198     String_32 MaxString;
03199     String_32 MiddleString = _T(" - ");
03200     Convert::LongToString((INT32)MinVal, &MinString);
03201     Convert::LongToString((INT32)MaxVal, &MaxString);
03202 
03203 
03204     RangeText += MinString;
03205     RangeText += MiddleString;
03206     RangeText += MaxString;
03207 
03208     return RangeText;
03209 
03210 }
03211 
03212 // essentially the same as above except that after we get the limits we convert them into degrees
03213 String_32 CBrushEditDlg::GetRotationRandomText(INT32 SliderVal)
03214 {
03215     String_32 RangeText(_T(" "));
03216     if (SliderVal < MIN_RANDOM_SLIDER || SliderVal > MAX_RANDOM_SLIDER)
03217     {
03218         ERROR3("Slider value is out of range in CBrushEditDlg::GetRandomRangeText");
03219         return RangeText;
03220     }
03221     UINT32 BaseVal = 100;
03222     UINT32 MinVal = 100 ;
03223     UINT32 MaxVal = 100 ;
03224 
03225     // the actual limits are worked out in the PPB static function
03226     PathProcessorBrush::GetRotationRandomLimits(BaseVal, SliderVal, &MinVal, &MaxVal);
03227 
03228     //double MinValDegrees = 
03229     // annoyingly we now need to recast our values as long
03230     String_32 MinString;
03231     String_32 MaxString;
03232     String_32 MiddleString = _T(" - ");
03233     Convert::LongToString((INT32)MinVal, &MinString);
03234     Convert::LongToString((INT32)MaxVal, &MaxString);
03235 
03236 
03237     RangeText += MinString;
03238     RangeText += MiddleString;
03239     RangeText += MaxString;
03240 
03241     return RangeText;
03242 }
03243 
03244 // this function gets the current slider value and then sets the accompanying
03245 // label with a string representing the possible random range
03246 void CBrushEditDlg::SetRandomRangeText(CGadgetID SliderID)
03247 {
03248     BOOL Valid = FALSE;
03249     INT32 SliderVal = 0;
03250     if (SliderID == _R(IDC_SLIDERBRUSHSPACINGMAXRAND))
03251     {
03252         SliderVal = GetLongGadgetValue (_R(IDC_SLIDERBRUSHSPACINGMAXRAND), MIN_RANDOM_SLIDER, MAX_RANDOM_SLIDER, 0, &Valid);
03253         if (Valid)
03254         {
03255             SliderVal = (MAX_RANDOM_SLIDER - SliderVal) + MIN_RANDOM_SLIDER;
03256             String_32 RangeText = GetRandomRangeText(SliderVal);
03257             SetStringGadgetValue(_R(IDC_STATICBRUSHSPACINGRAND1), RangeText);
03258         }
03259     }
03260     else if (SliderID == _R(IDC_SLIDEROFFSETVALUEMAXRAND))
03261     {
03262             SliderVal = GetLongGadgetValue(_R(IDC_SLIDEROFFSETVALUEMAXRAND), MIN_RANDOM_SLIDER, MAX_RANDOM_SLIDER, 0, &Valid);
03263             if (Valid)
03264             {
03265             SliderVal = (MAX_RANDOM_SLIDER - SliderVal) + MIN_RANDOM_SLIDER;
03266             String_32 RangeText = TEXT(""); //GetRandomRangeText(SliderVal);
03267             
03268             String_32 MinString = TEXT("0 - ");
03269             String_32 MaxString = TEXT("");;
03270             Convert::LongToString((INT32)SliderVal, &MaxString);
03271 
03272             RangeText += MinString;
03273             RangeText += MaxString;
03274             SetStringGadgetValue(_R(IDC_STATICOFFSETRAND), RangeText);
03275             }
03276     }
03277     else if (SliderID == _R(IDC_SLIDERBRUSHSCALINGMAXRAND))
03278     {
03279         SliderVal = GetLongGadgetValue(_R(IDC_SLIDERBRUSHSCALINGMAXRAND), MinScalingSlider, MaxScalingSlider, 0, &Valid);
03280         if (Valid)
03281         {
03282             SliderVal = (MaxScalingSlider - SliderVal) + MinScalingSlider;
03283             String_32 RangeText = GetRandomRangeText(SliderVal);
03284             SetStringGadgetValue(_R(IDC_STATICSCALINGRAND), RangeText);
03285         }
03286     }
03287     else if (SliderID == _R(IDC_SLIDERROTATEANGLEMAXRAND))
03288     {
03289         // This is a little different as we go from 0 - Max degrees, where Max is determined by
03290         // SliderVal * 360
03291         SliderVal = GetLongGadgetValue(_R(IDC_SLIDERROTATEANGLEMAXRAND), MIN_RANDOM_SLIDER, MAX_ROTATION_RANDOM_SLIDER, 0, &Valid);
03292         if (Valid)
03293         {
03294             SliderVal = (MAX_ROTATION_RANDOM_SLIDER - SliderVal) + MIN_RANDOM_SLIDER;
03295             //SliderVal = (SliderVal * 2) + 100; 
03296             double MaxAngle = double(SliderVal); // * 360;
03297             //MaxAngle = (MaxAngle * 0.01) - 360;
03298 
03299             String_32 RangeText(_T("")); 
03300             String_32 MinString;
03301             String_32 MaxString;
03302             String_32 MiddleString = _T(" - ");
03303             Convert::LongToString(0, &MinString);
03304             Convert::LongToString(INT32(MaxAngle), &MaxString);
03305 
03306             RangeText = MinString;
03307             RangeText += MiddleString;
03308             RangeText += MaxString;
03309     
03310             SetStringGadgetValue(_R(IDC_STATICROTATIONRAND), RangeText);
03311         }
03312     }
03313     else if (SliderID == _R(IDC_SLIDERSCALINGPRESSURE))
03314     {
03315         SliderVal = GetLongGadgetValue(_R(IDC_SLIDERSCALINGPRESSURE), MIN_PRESSURE_SLIDER, MAX_PRESSURE_SLIDER, 0, &Valid);
03316         if (Valid)
03317         {
03318 //          INT32 lSlider = MAX_PRESSURE_SLIDER - (INT32)SliderVal;
03319             
03320             String_32 MinString = TEXT("");
03321             Convert::LongToString((INT32)SliderVal, &MinString);
03322             
03323             // our maximum is always 100%
03324             String_32 MaxString = TEXT(" - 100");
03325 
03326             MinString += MaxString;
03327             SetStringGadgetValue(_R(IDC_STATICSCALINGPRESS), MinString);
03328         }
03329     }
03330     else if (SliderID == _R(IDC_SLIDERSATURATIONRANDOM))
03331     {
03332         // this is a little different as it only goes from 0 - SliderVal;
03333         SliderVal = GetLongGadgetValue(_R(IDC_SLIDERSATURATIONRANDOM), MIN_RANDOM_SLIDER, MAX_RANDOM_SAT_SLIDER, 0, &Valid);
03334         if (Valid)
03335         {
03336             SliderVal = MAX_RANDOM_SAT_SLIDER - SliderVal;
03337             String_32 RangeText(_T("")); 
03338             String_32 MinString;
03339             String_32 MaxString;
03340             String_32 MiddleString = _T(" - ");
03341             Convert::LongToString(0, &MinString);
03342             Convert::LongToString(SliderVal, &MaxString);
03343 
03344             RangeText = MinString;
03345             RangeText += MiddleString;
03346             RangeText += MaxString;
03347         
03348             SetStringGadgetValue(_R(IDC_STATICSATRAND), RangeText);
03349         }
03350     }
03351     else if (SliderID == _R(IDC_SLIDERHUERANDOM))
03352     {
03353         SliderVal = GetLongGadgetValue(_R(IDC_SLIDERHUERANDOM), MIN_RANDOM_SLIDER, MAX_RANDOM_HUE_SLIDER, 0, &Valid);
03354         if (Valid)
03355         {
03356             SliderVal = MAX_RANDOM_HUE_SLIDER - SliderVal;
03357             //  String_32 RangeText = GetRandomText(SliderVal, MAX_RANDOM_HUE_SLIDER);
03358             //  SetStringGadgetValue(_R(IDC_STATICHUERAND), &RangeText);
03359 
03360 
03361             String_32 MinString = TEXT("0 - ");
03362             String_32 MaxString = TEXT("");
03363             Convert::LongToString((INT32)SliderVal, &MaxString);
03364 
03365             MinString += MaxString;
03366             SetStringGadgetValue(_R(IDC_STATICSCALINGPRESS), MinString);
03367         
03368         }
03369     }
03370     else if (SliderID == _R(IDC_SLIDERTRANSPPRESSURE))
03371     {
03372         SliderVal = GetLongGadgetValue(_R(IDC_SLIDERTRANSPPRESSURE), MIN_RANDOM_SLIDER, MAX_RANDOM_SLIDER, 0, &Valid);
03373         if (Valid)
03374         {
03375             SliderVal = MAX_RANDOM_SLIDER - SliderVal;
03376             String_32 RangeText = GetRandomText(SliderVal, MAX_RANDOM_SLIDER);
03377             SetStringGadgetValue(_R(IDC_STATICTRANSPPRESSURE), RangeText);
03378         }
03379     }
03380 }
03381 
03382 String_32 CBrushEditDlg::GetRandomText(INT32 Rand, INT32 MaxRand)
03383 {
03384     INT32 Base = 100;
03385     INT32 MinVal = Base;
03386     INT32 MaxVal = Base;
03387 
03388     double RandomFactor = (double)Rand / 100;
03389     RandomFactor++; // = (RandomFactor * MaxRand);
03390 
03391     if (RandomFactor != 0)
03392     {
03393         MinVal = (INT32)((double)Base  / RandomFactor);
03394         MaxVal  =(INT32)((double)Base * RandomFactor);
03395     }
03396 
03397 
03398     String_32 RangeText(_T(""));
03399 
03400     // annoyingly we now need to recast our values as long
03401     String_32 MinString;
03402     String_32 MaxString;
03403     String_32 MiddleString = _T(" - ");
03404     Convert::LongToString(MinVal, &MinString);
03405     Convert::LongToString(MaxVal, &MaxString);
03406 
03407 
03408     RangeText += MinString;
03409     RangeText += MiddleString;
03410     RangeText += MaxString;
03411 
03412     return RangeText;
03413 }
03414 
03415 
03416 // make a new brush and insert it into the brush component
03417 void CBrushEditDlg::CreateNewBrush()
03418 {
03419     // as we are basically making a copy of an existing definition we can use the nodetree
03420     // of the existing definition, so we need to obtain a pointer to it.
03421     BrushHandle ThisHandle = EditData->m_BrushHandle;
03422 
03423     // get the brush component from the document
03424     Document* pDoc = Document::GetCurrent();
03425     if (pDoc == NULL)
03426     {
03427         ERROR3("Document is NULL in CBrushEditDlg::BrushEditDlgOnOK");
03428         return;
03429     }
03430 
03431     BrushComponent* pBrushComp = (BrushComponent*)pDoc->GetDocComponent(CC_RUNTIME_CLASS(BrushComponent));
03432     if (pBrushComp == NULL)
03433     {
03434         ERROR3("Brush component is null in CBrushEditDlg::BrushEditDlgOnOK");
03435         return;
03436     }
03437 
03438     BrushDefinition* pBrushDef = pBrushComp->FindBrushDefinition(ThisHandle);
03439 
03440     if (pBrushDef == NULL)
03441     {
03442         ERROR3("Brush definition is NULL in CBrushEditDlg::BrushEditDlgOnOK");
03443         return;
03444     }
03445     
03446     // ask the definition to copy itself
03447     BrushDefinition* pNewBrushDef = pBrushDef->Copy();
03448 
03449     if (pNewBrushDef == NULL)
03450         return;
03451 
03452     // copy our brush data to the definition
03453     pNewBrushDef->SetMembersFromData(*EditData);
03454     pNewBrushDef->SetBrushScaling(1.0);
03455     // find out how many brushes there are
03456     UINT32 LastBrush = pBrushComp->GetNumberOfBrushes() - 1;
03457 
03458     BrushHandle NewHandle = pBrushComp->AddNewItem(pNewBrushDef, TRUE);
03459 
03460     // tell the world who we are
03461     if (NewHandle > LastBrush)
03462         BROADCAST_TO_ALL(NewBrushMsg());
03463     else
03464         //ERROR3("Tried to make an identical brush");
03465         TRACEUSER( "Diccon", _T("Tried to make an identical brush\n"));
03466 
03467     EditData->m_BrushHandle = NewHandle;
03468 
03469 
03470 }
03471 

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