home *** CD-ROM | disk | FTP | other *** search
/ CorelDRAW! 10 / cd10_pgrm.iso / Corel / Graphics10 / Draw / Scripts / Misc / accelcon.csc < prev    next >
Encoding:
Text File  |  1999-03-22  |  64.5 KB  |  1,703 lines

  1. REM Accelerated Contour Tool
  2. REM Creates a contour effect with varying offsets.
  3.  
  4. '********************************************************************
  5. '   Script:    AccelCon.csc
  6. '   Copyright 1996 Corel Corporation.  All rights reserved.
  7. '   Description: CorelDRAW script to create the effect
  8. '                of having "acceleration" with contours.
  9. '                Each contour line gets farther apart/closer
  10. '                together.
  11. '********************************************************************
  12.  
  13. #addfol  "..\..\..\scripts"
  14. #include "ScpConst.csi"
  15. #include "DrwConst.csi"
  16.  
  17. '/////FUNCTION & SUBROUTINE DECLARATIONS/////////////////////////////
  18. DECLARE SUB ActivateTab( TabNum AS INTEGER, From AS INTEGER )
  19. DECLARE SUB UpdateBlendButtons()
  20. DECLARE SUB UpdateTabTops()
  21. DECLARE SUB ApplyContours()
  22. DECLARE FUNCTION ValidateOffset() AS BOOLEAN
  23. DECLARE FUNCTION Min( Val1 AS INTEGER, Val2 AS INTEGER ) AS INTEGER
  24. DECLARE SUB MakeHSB( BYVAL InRed AS LONG,   \\
  25.                  BYVAL InGreen AS LONG, \\
  26.                  BYVAL InBlue AS LONG,  \\
  27.                  BYREF OutHue AS LONG,  \\
  28.                  BYREF OutSat AS LONG,  \\
  29.                  BYREF OutBri AS LONG )
  30. DECLARE FUNCTION Mod256( InNum AS LONG ) AS LONG
  31. DECLARE FUNCTION Mod360( InNum AS LONG ) AS LONG
  32. DECLARE SUB UndoLastApply( RequireSelection AS BOOLEAN )
  33. DECLARE FUNCTION CheckForSelection() AS BOOLEAN
  34. DECLARE FUNCTION CheckForContour() AS BOOLEAN
  35.  
  36. '/////GLOBAL VARIABLES & CONSTANTS///////////////////////////////////
  37. GLOBAL CONST TITLE_ERRORBOX$        = "Accelerated Contour Tool Error"
  38. GLOBAL CONST TITLE_INFOBOX$        = "Accelerated Contour Tool Information"
  39.  
  40. ' These are single and double newlines.
  41. #define NL CHR(10) + CHR(13)
  42. #define NL2 CHR(10) + CHR(13) + CHR(10) + CHR(13)
  43.  
  44. ' The graphics used for the tabs.
  45. GLOBAL CONST TAB1_BITMAP$ = "\ConDU.bmp"
  46. GLOBAL CONST TAB2_BITMAP$ = "\ConCU.bmp"
  47. GLOBAL CONST TAB3_BITMAP$ = "\ConAU.bmp"
  48.  
  49. ' The graphics used for the color blend type buttons.
  50. GLOBAL CONST COLOR_DIRECT_UNPRESSED_BITMAP$ = "\ColDirec.bmp"
  51. GLOBAL CONST COLOR_DIRECT_PRESSED_BITMAP$ = "\ColDireP.bmp"
  52. GLOBAL CONST COLOR_CCW_UNPRESSED_BITMAP$ = "\ColCCW.bmp"
  53. GLOBAL CONST COLOR_CCW_PRESSED_BITMAP$ = "\ColCCWP.bmp"
  54. GLOBAL CONST COLOR_CW_UNPRESSED_BITMAP$ = "\ColCW.bmp"
  55. GLOBAL CONST COLOR_CW_PRESSED_BITMAP$ = "\ColCWP.bmp"
  56.  
  57. ' Keys for searching the registry.
  58. GLOBAL CONST REG_CORELDRAW_PATH$ = "SOFTWARE\Corel\CorelDRAW\9.0"
  59. GLOBAL CONST REG_CORELDRAW_MAIN_DIR_KEY$ = "Destination"
  60.  
  61. '/////GLOBAL VARIABLES////////////////////////////////////////////////
  62. GLOBAL IDLastFullContour& AS LONG    ' The last contour created.
  63. GLOBAL IDOriginal& AS LONG        ' The original object selected by
  64.                             ' the user.
  65. GLOBAL CurDir$ AS STRING            ' The directory where the script
  66.                             ' was started from.
  67.  
  68. '/////CONNECT TO THE DRAW OBJECT/////////////////////////////////////
  69. ON ERROR RESUME NEXT
  70. ERRNUM = 0
  71. WITHOBJECT OBJECT_DRAW
  72. IF ERRNUM <> 0 THEN
  73.     ERRNUM = 0
  74.     DIM NoDrawReturn AS LONG    ' The code returned by MESSAGEBOX.
  75.     NoDrawReturn& = MESSAGEBOX("Cannot not find CorelDRAW." + NL2 + \\
  76.                                "If this error persists, you may need" + \\
  77.                                " to re-install CorelDRAW.", \\ 
  78.                           TITLE_ERRORBOX$, \\
  79.                           MB_STOP_ICON)
  80.     STOP
  81. ENDIF
  82. ON ERROR EXIT
  83.  
  84. '/////PARAMETERS DIALOG//////////////////////////////////////////////
  85.  
  86. ' Retrieve the directory where the script was started.
  87. CurDir$ = GETCURRFOLDER()
  88. IF MID(CurDir$, LEN(CurDir$), 1) = "\" THEN
  89.     CurDir$ = LEFT(CurDir$, LEN(CurDir$) - 1)
  90. ENDIF
  91.  
  92. ' Images for tab 1.
  93. GLOBAL Tab1Bitmaps(4) AS STRING
  94. Tab1Bitmaps(1) = CurDir$ + TAB1_BITMAP$
  95. Tab1Bitmaps(2) = CurDir$ + TAB1_BITMAP$
  96. Tab1Bitmaps(3) = CurDir$ + TAB1_BITMAP$
  97. Tab1Bitmaps(4) = CurDir$ + TAB1_BITMAP$
  98.  
  99. ' Images for tab 2.
  100. GLOBAL Tab2Bitmaps(4) AS STRING
  101. Tab2Bitmaps(1) = CurDir$ + TAB2_BITMAP$
  102. Tab2Bitmaps(2) = CurDir$ + TAB2_BITMAP$
  103. Tab2Bitmaps(3) = CurDir$ + TAB2_BITMAP$
  104. Tab2Bitmaps(4) = CurDir$ + TAB2_BITMAP$
  105.  
  106. ' Images for tab 3.
  107. GLOBAL Tab3Bitmaps(4) AS STRING
  108. Tab3Bitmaps(1) = CurDir$ + TAB3_BITMAP$
  109. Tab3Bitmaps(2) = CurDir$ + TAB3_BITMAP$
  110. Tab3Bitmaps(3) = CurDir$ + TAB3_BITMAP$
  111. Tab3Bitmaps(4) = CurDir$ + TAB3_BITMAP$
  112.  
  113. ' The array of possible units the user may select from.
  114. GLOBAL UnitsArray(10) AS STRING
  115. UnitsArray(1) = "1 in."
  116. UnitsArray(2) = "1/36 in."
  117. UnitsArray(3) = "0.1 in."
  118. UnitsArray(4) = "0.01 in."
  119. UnitsArray(5) = "0.001 in."
  120. UnitsArray(6) = "1 cm."
  121. UnitsArray(7) = "0.1 cm."
  122. UnitsArray(8) = "0.01 cm."
  123. UnitsArray(9) = "0.001 cm."
  124. UnitsArray(10) = "1 pt."
  125.  
  126. ' Multiplicative conversion factors to convert from the units to
  127. ' tenths of a micron.
  128. GLOBAL ConversionFactors(10) AS SINGLE
  129. ConversionFactors(1) = 1 * LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 1)
  130. ConversionFactors(2) = (1/36) * LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 1)
  131. ConversionFactors(3) = 0.1 * LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 1)
  132. ConversionFactors(4) = 0.01 * LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 1)
  133. ConversionFactors(5) = 0.001 * LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 1)
  134. ConversionFactors(6) = 1 * LENGTHCONVERT(LC_CENTIMETERS, LC_TENTHS_OFA_MICRON, 1)
  135. ConversionFactors(7) = 0.1 * LENGTHCONVERT(LC_CENTIMETERS, LC_TENTHS_OFA_MICRON, 1)
  136. ConversionFactors(8) = 0.01 * LENGTHCONVERT(LC_CENTIMETERS, LC_TENTHS_OFA_MICRON, 1)
  137. ConversionFactors(9) = 0.001 * LENGTHCONVERT(LC_CENTIMETERS, LC_TENTHS_OFA_MICRON, 1)
  138. ConversionFactors(10) = 1 * LENGTHCONVERT(LC_POINTS, LC_TENTHS_OFA_MICRON, 1)
  139.  
  140. ' Ways to specify the offset.
  141. GLOBAL CONST AC_OFFSET_PER_STEP%    = 2
  142. GLOBAL CONST AC_OFFSET_TOTAL%        = 1
  143.  
  144. ' Variables needed for this dialog.
  145. GLOBAL CurTab AS INTEGER            ' Which tab is selected (1-3).
  146. GLOBAL ColorBlendType AS INTEGER     ' Which color blend type is currently selected.
  147. GLOBAL Offset AS INTEGER            ' The size of the offset.
  148. GLOBAL ChosenUnit AS INTEGER        ' Which unit the user has chosen for the offset.
  149. GLOBAL Steps AS INTEGER            ' How many steps to use.
  150. GLOBAL Direction AS INTEGER        ' The direction to apply the contour.
  151. GLOBAL OffsetType AS INTEGER        ' How is the offset specified; one of AC_OFFSET_*.
  152. GLOBAL OffsetAccel AS INTEGER        ' The speed of the offset acceleration.
  153. GLOBAL FillAccel AS INTEGER        ' The speed of the fill acceleration.
  154. GLOBAL OriginalFillType AS LONG    ' The fill type of the originally selected object.
  155.  
  156. ' The color variables.
  157. GLOBAL ToOutlineRed AS LONG
  158. GLOBAL ToOutlineGreen AS LONG
  159. GLOBAL ToOutlineBlue AS LONG
  160. GLOBAL ToOutlineHue AS LONG        ' We duplicate the RGB values as HSB here
  161. GLOBAL ToOutlineSat AS LONG        ' instead of in the contour subroutine 
  162. GLOBAL ToOutlineBri AS LONG        ' in order to move some calculations out
  163. GLOBAL ToFill1Red AS LONG        ' and improve efficiency.
  164. GLOBAL ToFill1Green AS LONG
  165. GLOBAL ToFill1Blue AS LONG
  166. GLOBAL ToFill1Hue AS LONG
  167. GLOBAL ToFill1Sat AS LONG
  168. GLOBAL ToFill1Bri AS LONG
  169. GLOBAL ToFill2Red AS LONG
  170. GLOBAL ToFill2Green AS LONG
  171. GLOBAL ToFill2Blue AS LONG
  172. GLOBAL ToFill2Hue AS LONG
  173. GLOBAL ToFill2Sat AS LONG
  174. GLOBAL ToFill2Bri AS LONG
  175. GLOBAL FromFill1Red AS LONG        ' The original fill color's red component.
  176. GLOBAL FromFill1Green AS LONG        ' The original fill color's green component.
  177. GLOBAL FromFill1Blue AS LONG        ' The original fill color's blue component.
  178. GLOBAL FromFill1Hue AS LONG
  179. GLOBAL FromFill1Sat AS LONG
  180. GLOBAL FromFill1Bri AS LONG
  181. GLOBAL FromFill2Red AS LONG        ' For fountain fills, there is a second red component.
  182. GLOBAL FromFill2Green AS LONG        ' For fountain fills, there is a second green component.
  183. GLOBAL FromFill2Blue AS LONG        ' For fountain fills, there is a second blue component.
  184. GLOBAL FromFill2Hue AS LONG
  185. GLOBAL FromFill2Sat AS LONG
  186. GLOBAL FromFill2Bri AS LONG
  187. GLOBAL FromOutlineRed AS LONG        ' The original outline color's red component.
  188. GLOBAL FromOutlineGreen AS LONG    ' The original outline color's green component.
  189. GLOBAL FromOutlineBlue AS LONG    ' The original outline color's blue component.
  190. GLOBAL FromOutlineHue AS LONG
  191. GLOBAL FromOutlineSat AS LONG
  192. GLOBAL FromOutlineBri AS LONG
  193.  
  194. ' Set up default values.
  195. CurTab% = 1
  196. ColorBlendType% = DRAW_BLEND_DIRECT%
  197. Offset% = 2
  198. ChosenUnit% = 3
  199. Steps% = 3
  200. OffsetType% = AC_OFFSET_PER_STEP%
  201. Direction% = DRAW_CONTOUR_OUTSIDE&
  202. ToOutlineRed& = 0
  203. ToOutlineGreen& = 0
  204. ToOutlineBlue& = 0
  205. ToOutlineHue& = 0
  206. ToOutlineSat& = 0
  207. ToOutlineBri& = 0
  208. ToFill1Red& = 0
  209. ToFill1Green& = 0
  210. ToFill1Blue& = 255
  211. ToFill1Hue& = 240
  212. ToFill1Sat& = 255
  213. ToFill1Bri& = 255
  214. ToFill2Red& = 255
  215. ToFill2Green& = 0
  216. ToFill2Blue& = 0
  217. ToFill2Hue& = 0
  218. ToFill2Sat& = 255
  219. ToFill2Bri& = 255
  220. OffsetAccel% = 0
  221. FillAccel% = 0
  222. OriginalFillType& = DRAW_FILL_UNIFORM& ' We are guessing that the first
  223.                                 ' contour will be applied to an
  224.                                 ' object with a uniform fill.
  225.                                 ' If this isn't true, the user will
  226.                                 ' be warned.
  227.  
  228. BEGIN DIALOG OBJECT ParamDialog 118, 185, "Accelerated Contour", SUB ParamDialogEventHandler
  229.     ' Main controls.
  230.     BITMAPBUTTON  5, 4, 21, 17, .Tab1Button
  231.     BITMAPBUTTON  26, 4, 21, 17, .Tab2Button
  232.     BITMAPBUTTON  47, 4, 21, 17, .Tab3Button
  233.     PUSHBUTTON  3, 21, 111, 145, .MainTabBackground, ""
  234.     TEXT  48, 20, 19, 4, .Tab3Cover, ""
  235.     TEXT  6, 20, 19, 4, .Tab1Cover, ""
  236.     TEXT  27, 20, 19, 4, .Tab2Cover, ""
  237.     PUSHBUTTON  3, 169, 54, 13, .UndoButton, "Undo"
  238.     PUSHBUTTON  60, 169, 54, 13, .ApplyButton, "Apply"
  239.     ' First tab controls.
  240.     GROUPBOX  8, 27, 98, 52, .DirectionGroupBox, "Direction"
  241.     OPTIONGROUP .TypeGroup
  242.         OPTIONBUTTON  16, 106, 64, 11, .TotalOption, "Total offset"
  243.         OPTIONBUTTON  16, 94, 64, 11, .PerStepOption, "Per step"
  244.     OPTIONGROUP .DirectionGroup
  245.         OPTIONBUTTON  16, 37, 64, 11, .CenterOption, "To center"
  246.         OPTIONBUTTON  16, 49, 64, 11, .InsideOption, "Inside"
  247.         OPTIONBUTTON  16, 61, 64, 11, .OutsideOption, "Outside"
  248.     SPINCONTROL  33, 128, 24, 13, .OffsetSpin
  249.     TEXT  10, 148, 24, 11, .StepsText, "Steps:"
  250.     DDLISTBOX  63, 128, 45, 100, .UnitsListBox
  251.     TEXT  58, 130, 5, 9, .XText, "x"
  252.     SPINCONTROL  33, 146, 75, 13, .StepsSpin
  253.     TEXT  10, 130, 21, 11, .OffsetText, "Offset:"
  254.     GROUPBOX  10, 84, 97, 38, .TypeGroupBox, "Offset type"
  255.     ' Second tab controls.
  256.     GROUPBOX  10, 28, 97, 70, .BlendGroupBox, "Color blend type"
  257.     BITMAPBUTTON  20, 45, 14, 14, .DirectButton
  258.     BITMAPBUTTON  20, 59, 14, 14, .CWButton
  259.     BITMAPBUTTON  20, 73, 14, 14, .CCWButton
  260.     TEXT  38, 76, 60, 10, .CCWText, "Counter-clockwise"
  261.     TEXT  38, 62, 55, 8, .CWText, "Clockwise"
  262.     TEXT  38, 47, 20, 9, .DirectText, "Direct"
  263.     PUSHBUTTON  10, 124, 97, 13, .FillButton1, "Choose target fill color"
  264.     PUSHBUTTON  10, 142, 97, 13, .FillButton2, "Choose target fill color #2"
  265.     PUSHBUTTON  10, 106, 97, 13, .OutlineButton, "Choose target outline color"
  266.     ' Third tab controls.
  267.     HSLIDER 10, 100, 95, 12, .FillSlider
  268.     TEXT  15, 89, 76, 11, .FillAccelerateText, "Accelerate fills/outlines:"
  269.     TEXT  15, 33, 76, 11, .OffsetAccelerateText, "Accelerate offsets:"
  270.     HSLIDER 10, 44, 95, 12, .OffsetSlider
  271.     PUSHBUTTON  33, 115, 45, 13, .CenterFillButton, "Center"
  272.     PUSHBUTTON  33, 58, 45, 13, .CenterOffsetButton, "Center"
  273. END DIALOG
  274.  
  275. SUB ParamDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  276.  
  277.     DIM MsgReturn AS LONG    ' The return value of MESSAGEBOX.
  278.  
  279.     IF Event% = EVENT_INITIALIZATION& THEN
  280.         ' We want a 3-D background for the pseudo-tab control.
  281.         ParamDialog.MainTabBackground.Enable FALSE
  282.         
  283.         ' Set up all the images for the tabs.
  284.         ParamDialog.Tab1Button.SetArray Tab1Bitmaps$
  285.         ParamDialog.Tab2Button.SetArray Tab2Bitmaps$
  286.         ParamDialog.Tab3Button.SetArray Tab3Bitmaps$
  287.         
  288.         ' Make sure the images resize to the image box size
  289.         ' so they look good in large fonts.
  290.         ParamDialog.Tab1Button.SetStyle STYLE_IMAGE_AUTO_RESIZE
  291.         ParamDialog.Tab2Button.SetStyle STYLE_IMAGE_AUTO_RESIZE
  292.         ParamDialog.Tab3Button.SetStyle STYLE_IMAGE_AUTO_RESIZE
  293.         
  294.         ' Set up the blend type buttons.
  295.         ParamDialog.DirectButton.SetStyle STYLE_IMAGE_CENTERED
  296.         ParamDialog.CWButton.SetStyle STYLE_IMAGE_CENTERED
  297.         ParamDialog.CCWButton.SetStyle STYLE_IMAGE_CENTERED
  298.         UpdateBlendButtons
  299.         
  300.         ' Set up the units-related material.
  301.         ParamDialog.UnitsListBox.SetArray UnitsArray$
  302.         ParamDialog.UnitsListBox.SetSelect ChosenUnit%
  303.         ParamDialog.OffsetSpin.SetValue Offset%
  304.         
  305.         ' Set up the steps-related material.
  306.         ParamDialog.StepsSpin.SetValue Steps%
  307.         SELECT CASE Direction%
  308.             CASE DRAW_CONTOUR_OUTSIDE&
  309.                 ParamDialog.OutsideOption.SetValue 1
  310.             CASE DRAW_CONTOUR_INSIDE&
  311.                 ParamDialog.InsideOption.SetValue 1
  312.             CASE DRAW_CONTOUR_TO_CENTER&
  313.                 ParamDialog.CenterOption.SetValue 1
  314.                 OffsetType% = AC_OFFSET_PER_STEP%
  315.                 ParamDialog.TotalOption.Enable FALSE
  316.                 ParamDialog.StepsSpin.Enable FALSE
  317.                 ParamDialog.StepsText.Enable FALSE
  318.         END SELECT
  319.         IF OffsetType% = AC_OFFSET_PER_STEP% THEN
  320.             ParamDialog.PerStepOption.SetValue 1
  321.         ELSE
  322.             ParamDialog.TotalOption.SetValue 1
  323.         ENDIF
  324.  
  325.         ' Set up the acceleration bars.
  326.         ParamDialog.OffsetSlider.SetMinRange -50
  327.         ParamDialog.OffsetSlider.SetMaxRange 50
  328.         ParamDialog.OffsetSlider.SetIncrement 1
  329.         ParamDialog.OffsetSlider.SetValue OffsetAccel%
  330.         ParamDialog.FillSlider.SetMinRange -20
  331.         ParamDialog.FillSlider.SetMaxRange 20
  332.         ParamDialog.FillSlider.SetIncrement 1
  333.         ParamDialog.FillSlider.SetValue FillAccel%
  334.         
  335.         ' There is initially nothing to Undo.
  336.         ParamDialog.UndoButton.Enable FALSE
  337.         
  338.         ' Activate the current tab.
  339.         ActivateTab CurTab%, 0
  340.         
  341.     ELSEIF Event% = EVENT_MOUSE_CLICK& THEN
  342.         SELECT CASE ControlID% 
  343.         
  344.             CASE ParamDialog.Tab1Button.GetID()
  345.                 IF CurTab% <> 1 THEN
  346.                     ActivateTab 1, CurTab%
  347.                 ENDIF
  348.                 
  349.             CASE ParamDialog.Tab2Button.GetID()
  350.                 IF CurTab% <> 2 THEN
  351.                     ActivateTab 2, CurTab%
  352.                 ENDIF
  353.                 
  354.             CASE ParamDialog.Tab3Button.GetID()
  355.                 IF CurTab% <> 3 THEN
  356.                     ActivateTab 3, CurTab%
  357.                 ENDIF
  358.             
  359.             CASE ParamDialog.DirectButton.GetID()
  360.                 ColorBlendType% = DRAW_BLEND_DIRECT%
  361.                 UpdateBlendButtons
  362.                     
  363.             CASE ParamDialog.CCWButton.GetID()
  364.                 ColorBlendType% = DRAW_BLEND_RAINBOW_CCW%
  365.                 UpdateBlendButtons
  366.                 
  367.             CASE ParamDialog.CWButton.GetID()
  368.                 ColorBlendType% = DRAW_BLEND_RAINBOW_CW%
  369.                 UpdateBlendButtons
  370.                 
  371.             CASE ParamDialog.UnitsListBox.GetID()
  372.                 ChosenUnit% = ParamDialog.UnitsListBox.GetSelect()
  373.  
  374.             CASE ParamDialog.FillButton1.GetID()
  375.                 GETCOLOR ToFill1Red&, ToFill1Green&, ToFill1Blue&
  376.                 ' We convert to HSB here for efficiency.
  377.                 MakeHSB ToFill1Red&, ToFill1Green&, ToFill1Blue&, \\
  378.                         ToFill1Hue&, ToFill1Sat&, ToFill1Bri&
  379.                 
  380.             CASE ParamDialog.FillButton2.GetID()
  381.                 GETCOLOR ToFill2Red&, ToFill2Green&, ToFill2Blue&
  382.                 ' We convert to HSB here for efficiency.
  383.                 MakeHSB ToFill2Red&, ToFill2Green&, ToFill2Blue&, \\
  384.                         ToFill2Hue&, ToFill2Sat&, ToFill2Bri&
  385.             
  386.             CASE ParamDialog.OutlineButton.GetID()
  387.                 GETCOLOR ToOutlineRed&, ToOutlineGreen&, ToOutlineBlue&
  388.                 ' We convert to HSB here for efficiency.
  389.                 MakeHSB ToOutlineRed&, ToOutlineGreen&, ToOutlineBlue&, \\
  390.                         ToOutlineHue&, ToOutlineSat&, ToOutlineBri&
  391.  
  392.             CASE ParamDialog.CenterOption.GetID()
  393.                 Direction% = DRAW_CONTOUR_TO_CENTER&
  394.                 ParamDialog.TotalOption.Enable FALSE
  395.                 ParamDialog.PerStepOption.SetValue 1
  396.                 ParamDialog.StepsSpin.Enable FALSE
  397.                 ParamDialog.StepsText.Enable FALSE
  398.                 
  399.             CASE ParamDialog.InsideOption.GetID()
  400.                 Direction% = DRAW_CONTOUR_INSIDE&
  401.                 ParamDialog.TotalOption.Enable TRUE
  402.                 ParamDialog.StepsSpin.Enable TRUE
  403.                 ParamDialog.StepsText.Enable TRUE
  404.                 
  405.             CASE ParamDialog.OutsideOption.GetID()
  406.                 Direction% = DRAW_CONTOUR_OUTSIDE&
  407.                 ParamDialog.TotalOption.Enable TRUE
  408.                 ParamDialog.StepsSpin.Enable TRUE
  409.                 ParamDialog.StepsText.Enable TRUE
  410.                 
  411.             CASE ParamDialog.TotalOption.GetID()
  412.                 OffsetType% = AC_OFFSET_TOTAL%
  413.                 
  414.             CASE ParamDialog.PerStepOption.GetID()
  415.                 OffsetType% = AC_OFFSET_PER_STEP%
  416.  
  417.             CASE ParamDialog.ApplyButton.GetID()
  418.                 IF ValidateOffset() THEN
  419.                     UndoLastApply TRUE
  420.                     ApplyContours
  421.                 ENDIF
  422.                 
  423.             CASE ParamDialog.FillSlider.GetID()
  424.                 FillAccel% = ParamDialog.FillSlider.GetValue()
  425.             
  426.             CASE ParamDialog.OffsetSlider.GetID()
  427.                 OffsetAccel% = ParamDialog.OffsetSlider.GetValue()
  428.                 
  429.             CASE ParamDialog.UndoButton.GetID()
  430.                 UndoLastApply FALSE
  431.                 
  432.             CASE ParamDialog.CenterFillButton.GetID()
  433.                 ParamDialog.FillSlider.SetValue 0
  434.                 FillAccel% = 0
  435.  
  436.             CASE ParamDialog.CenterOffsetButton.GetID()
  437.                 ParamDialog.OffsetSlider.SetValue 0
  438.                 OffsetAccel% = 0
  439.  
  440.         END SELECT
  441.     
  442.     ELSEIF Event% = EVENT_CHANGE_IN_CONTENT& THEN
  443.         SELECT CASE ControlID%
  444.             CASE ParamDialog.OffsetSpin.GetID()
  445.                 IF (ParamDialog.OffsetSpin.GetValue() < 1) THEN
  446.                     MsgReturn& = MESSAGEBOX("Please enter an offset value " + \\
  447.                                                  "between 1 and 99.", \\
  448.                                                  TITLE_INFOBOX$, \\
  449.                                                  MB_INFORMATION_ICON&)
  450.                     ParamDialog.OffsetSpin.SetValue 1
  451.                     Offset% = 1
  452.                 ELSEIF (ParamDialog.OffsetSpin.GetValue() > 99) THEN
  453.                     MsgReturn& = MESSAGEBOX("Please enter an offset value " + \\
  454.                                                  "between 1 and 99.", \\
  455.                                                  TITLE_INFOBOX$, \\
  456.                                                  MB_INFORMATION_ICON&)
  457.                     ParamDialog.OffsetSpin.SetValue 99
  458.                     Offset% = 99
  459.                 ELSE
  460.                     Offset% = ParamDialog.OffsetSpin.GetValue()
  461.                 ENDIF
  462.             
  463.             CASE ParamDialog.StepsSpin.GetID()
  464.                 IF (ParamDialog.StepsSpin.GetValue() < 1) THEN
  465.                     MsgReturn& = MESSAGEBOX("Please enter a number of steps " + \\
  466.                                                  "between 1 and 99.", \\
  467.                                                  TITLE_INFOBOX$, \\
  468.                                                  MB_INFORMATION_ICON&)
  469.                     ParamDialog.StepsSpin.SetValue 1
  470.                     Steps% = 1
  471.                 ELSEIF (ParamDialog.StepsSpin.GetValue() > 99) THEN
  472.                     MsgReturn& = MESSAGEBOX("Please enter a number of steps " + \\
  473.                                                  "between 1 and 99.", \\
  474.                                                  TITLE_INFOBOX$, \\
  475.                                                  MB_INFORMATION_ICON&)
  476.                     ParamDialog.StepsSpin.SetValue 99
  477.                     Steps% = 99
  478.                 ELSE
  479.                     Steps% = ParamDialog.StepsSpin.GetValue()
  480.                 ENDIF
  481.                 
  482.             CASE ParamDialog.FillSlider.GetID()
  483.                 FillAccel% = ParamDialog.FillSlider.GetValue()
  484.             
  485.             CASE ParamDialog.OffsetSlider.GetID()
  486.                 OffsetAccel% = ParamDialog.OffsetSlider.GetValue()
  487.  
  488.         END SELECT
  489.     
  490.     ELSEIF Event% = EVENT_RECEIVE_FOCUS& THEN
  491.         ' Make sure the focus change does not destroy
  492.         ' our pseudo-tab effect.
  493.         UpdateTabTops
  494.         
  495.     ENDIF
  496.  
  497. END SUB
  498.  
  499. '********************************************************************
  500. '
  501. '    Name:    ValidateOffset (dialog function)
  502. '
  503. '    Action:    Checks to make sure that the user's chosen offset
  504. '              value is greater than 0.  If not, displays an error
  505. '              message and sets the offset to 1.
  506. '
  507. '    Params:    None.  Since this is intended to be a dialog function,
  508. '              it inspects ParamDialog.OffsetSpin and may alter 
  509. '              Offset%.
  510. '
  511. '    Returns:    If an error message had to be displayed, returns
  512. '              FALSE.  Otherwise returns TRUE.
  513. '
  514. '    Comments:    None.
  515. '
  516. '********************************************************************
  517. FUNCTION ValidateOffset() AS BOOLEAN
  518.  
  519.     DIM MsgReturn AS LONG    ' The return value of MESSAGEBOX.
  520.  
  521.     IF ParamDialog.OffsetSpin.GetValue() < 1 THEN
  522.         MsgReturn& = MESSAGEBOX("The offset value you select must be " + \\
  523.                                 "greater than 0." + NL2 + \\
  524.                                 "Please select another offset value and " + \\
  525.                                 "try again.", TITLE_ERRORBOX$, \\
  526.                                 MB_OK_ONLY& OR MB_EXCLAMATION_ICON&)
  527.         Offset% = 1
  528.         ParamDialog.OffsetSpin.SetValue Offset%
  529.         ValidateOffset = FALSE
  530.     ELSE
  531.         ValidateOffset = TRUE
  532.     ENDIF
  533.  
  534. END FUNCTION
  535.  
  536. '********************************************************************
  537. '
  538. '    Name:    ActivateTab (dialog subroutine)
  539. '
  540. '    Action:    Activates a specified tab in ParamDialog
  541. '              (ie. makes it look like it has been pressed and
  542. '              brings it to the front).
  543. '
  544. '    Params:    TabNum - Which tab to bring forward (1-3)?
  545. '            From - Which tab are we coming from? (0 means repaint all)
  546. '
  547. '    Returns:    None.
  548. '
  549. '    Comments:    If TabNum < 1 OR TabNum > 3 does nothing.
  550. '
  551. '********************************************************************
  552. SUB ActivateTab(TabNum AS INTEGER, From AS INTEGER)
  553.  
  554.     SELECT CASE TabNum%
  555.         CASE 1
  556.             ' Do the main tab controls. (We are not calling
  557.             ' UpdateTabTops to avoid procedure call-overhead.)
  558.             ParamDialog.Tab1Cover.SetStyle STYLE_VISIBLE 
  559.             ParamDialog.Tab2Cover.SetStyle STYLE_INVISIBLE 
  560.             ParamDialog.Tab3Cover.SetStyle STYLE_INVISIBLE 
  561.             ParamDialog.MainTabBackground.SetStyle STYLE_VISIBLE
  562.             
  563.             IF (From% = 2) OR (From% = 0) THEN
  564.                 ' Tab 2 controls.
  565.                 ParamDialog.BlendGroupBox.SetStyle STYLE_INVISIBLE
  566.                 ParamDialog.DirectButton.SetStyle STYLE_INVISIBLE
  567.                 ParamDialog.CWButton.SetStyle STYLE_INVISIBLE
  568.                 ParamDialog.CCWButton.SetStyle STYLE_INVISIBLE
  569.                 ParamDialog.CCWText.SetStyle STYLE_INVISIBLE
  570.                 ParamDialog.CWText.SetStyle STYLE_INVISIBLE
  571.                 ParamDialog.DirectText.SetStyle STYLE_INVISIBLE
  572.                 ParamDialog.FillButton1.SetStyle STYLE_INVISIBLE
  573.                 ParamDialog.FillButton2.SetStyle STYLE_INVISIBLE
  574.                 ParamDialog.OutlineButton.SetStyle STYLE_INVISIBLE
  575.             ENDIF
  576.             
  577.             IF (From% = 3) OR (From% = 0) THEN
  578.                 ' Tab 3 controls.
  579.                 ParamDialog.FillSlider.SetStyle STYLE_INVISIBLE
  580.                 ParamDialog.FillAccelerateText.SetStyle STYLE_INVISIBLE
  581.                 ParamDialog.OffsetAccelerateText.SetStyle STYLE_INVISIBLE
  582.                 ParamDialog.OffsetSlider.SetStyle STYLE_INVISIBLE
  583.                 ParamDialog.CenterOffsetButton.SetStyle STYLE_INVISIBLE
  584.                 ParamDialog.CenterFillButton.SetStyle STYLE_INVISIBLE
  585.             ENDIF
  586.                         
  587.             ' Tab 1 controls.
  588.             ParamDialog.DirectionGroupBox.SetStyle STYLE_VISIBLE
  589.             ParamDialog.TotalOption.SetStyle STYLE_VISIBLE
  590.             ParamDialog.PerStepOption.SetStyle STYLE_VISIBLE
  591.             ParamDialog.CenterOption.SetStyle STYLE_VISIBLE
  592.             ParamDialog.OutsideOption.SetStyle STYLE_VISIBLE
  593.             ParamDialog.InsideOption.SetStyle STYLE_VISIBLE
  594.             ParamDialog.OffsetSpin.SetStyle STYLE_VISIBLE
  595.             ParamDialog.UnitsListBox.SetStyle STYLE_VISIBLE
  596.             ParamDialog.XText.SetStyle STYLE_VISIBLE
  597.             ParamDialog.StepsText.SetStyle STYLE_VISIBLE
  598.             ParamDialog.StepsSpin.SetStyle STYLE_VISIBLE
  599.             ParamDialog.OffsetText.SetStyle STYLE_VISIBLE
  600.             ParamDialog.TypeGroupBox.SetStyle STYLE_VISIBLE
  601.             
  602.             ' Set the current tab number.
  603.             CurTab% = 1
  604.             
  605.         CASE 2
  606.             ' Do the main tab controls.
  607.             ParamDialog.Tab1Cover.SetStyle STYLE_INVISIBLE 
  608.             ParamDialog.Tab2Cover.SetStyle STYLE_VISIBLE 
  609.             ParamDialog.Tab3Cover.SetStyle STYLE_INVISIBLE 
  610.             ParamDialog.MainTabBackground.SetStyle STYLE_VISIBLE
  611.  
  612.             IF (From% = 1) OR (From% = 0) THEN
  613.                 ' Tab 1 controls.
  614.                 ParamDialog.DirectionGroupBox.SetStyle STYLE_INVISIBLE
  615.                 ParamDialog.TotalOption.SetStyle STYLE_INVISIBLE
  616.                 ParamDialog.PerStepOption.SetStyle STYLE_INVISIBLE
  617.                 ParamDialog.CenterOption.SetStyle STYLE_INVISIBLE
  618.                 ParamDialog.OutsideOption.SetStyle STYLE_INVISIBLE
  619.                 ParamDialog.InsideOption.SetStyle STYLE_INVISIBLE
  620.                 ParamDialog.OffsetSpin.SetStyle STYLE_INVISIBLE
  621.                 ParamDialog.UnitsListBox.SetStyle STYLE_INVISIBLE
  622.                 ParamDialog.XText.SetStyle STYLE_INVISIBLE
  623.                 ParamDialog.StepsText.SetStyle STYLE_INVISIBLE
  624.                 ParamDialog.StepsSpin.SetStyle STYLE_INVISIBLE
  625.                 ParamDialog.OffsetText.SetStyle STYLE_INVISIBLE
  626.                 ParamDialog.TypeGroupBox.SetStyle STYLE_INVISIBLE
  627.             ENDIF
  628.                         
  629.             IF (From% = 3) OR (From% = 0) THEN
  630.                 ' Tab 3 controls.
  631.                 ParamDialog.FillSlider.SetStyle STYLE_INVISIBLE
  632.                 ParamDialog.FillAccelerateText.SetStyle STYLE_INVISIBLE
  633.                 ParamDialog.OffsetAccelerateText.SetStyle STYLE_INVISIBLE
  634.                 ParamDialog.OffsetSlider.SetStyle STYLE_INVISIBLE
  635.                 ParamDialog.CenterOffsetButton.SetStyle STYLE_INVISIBLE
  636.                 ParamDialog.CenterFillButton.SetStyle STYLE_INVISIBLE
  637.             ENDIF
  638.             
  639.             ' Tab 2 controls.
  640.             ParamDialog.BlendGroupBox.SetStyle STYLE_VISIBLE
  641.             ParamDialog.DirectButton.SetStyle STYLE_VISIBLE
  642.             ParamDialog.CWButton.SetStyle STYLE_VISIBLE
  643.             ParamDialog.CCWButton.SetStyle STYLE_VISIBLE
  644.             ParamDialog.CCWText.SetStyle STYLE_VISIBLE
  645.             ParamDialog.CWText.SetStyle STYLE_VISIBLE
  646.             ParamDialog.DirectText.SetStyle STYLE_VISIBLE
  647.             ParamDialog.FillButton1.SetStyle STYLE_VISIBLE
  648.             
  649.             ' Since the user may select different objects and expect
  650.             ' the contour to be applied to those objects, check the
  651.             ' fill type before displaying controls.
  652.             ON ERROR GOTO STNoSelection
  653.                 OriginalFillType& = .GetFillType()
  654.             ON ERROR EXIT
  655.             Continue:
  656.             SELECT CASE OriginalFillType&
  657.                 CASE DRAW_FILL_UNIFORM&
  658.                     ParamDialog.FillButton1.Enable TRUE
  659.                     ParamDialog.FillButton1.SetText "Choose target fill color"
  660.                     ParamDialog.FillButton2.SetStyle STYLE_INVISIBLE
  661.                 CASE DRAW_FILL_FOUNTAIN&
  662.                     ParamDialog.FillButton1.Enable TRUE
  663.                     ParamDialog.FillButton1.SetText "Choose target fill color #1"
  664.                     ParamDialog.FillButton2.SetStyle STYLE_VISIBLE
  665.                 CASE ELSE
  666.                     ParamDialog.FillButton1.SetText "Choose target fill color"
  667.                     ParamDialog.FillButton1.Enable FALSE
  668.                     ParamDialog.FillButton2.SetStyle STYLE_INVISIBLE
  669.             END SELECT
  670.             ParamDialog.OutlineButton.SetStyle STYLE_VISIBLE
  671.  
  672.             ' Set the current tab number.
  673.             CurTab% = 2
  674.             
  675.         CASE 3
  676.             ' Do the main tab controls.
  677.             ParamDialog.Tab1Cover.SetStyle STYLE_INVISIBLE 
  678.             ParamDialog.Tab2Cover.SetStyle STYLE_INVISIBLE 
  679.             ParamDialog.Tab3Cover.SetStyle STYLE_VISIBLE 
  680.             ParamDialog.MainTabBackground.SetStyle STYLE_VISIBLE
  681.  
  682.             IF (From% = 1) OR (From% = 0) THEN
  683.                 ' Tab 1 controls.
  684.                 ParamDialog.DirectionGroupBox.SetStyle STYLE_INVISIBLE
  685.                 ParamDialog.TotalOption.SetStyle STYLE_INVISIBLE
  686.                 ParamDialog.PerStepOption.SetStyle STYLE_INVISIBLE
  687.                 ParamDialog.CenterOption.SetStyle STYLE_INVISIBLE
  688.                 ParamDialog.OutsideOption.SetStyle STYLE_INVISIBLE
  689.                 ParamDialog.InsideOption.SetStyle STYLE_INVISIBLE
  690.                 ParamDialog.OffsetSpin.SetStyle STYLE_INVISIBLE
  691.                 ParamDialog.UnitsListBox.SetStyle STYLE_INVISIBLE
  692.                 ParamDialog.XText.SetStyle STYLE_INVISIBLE
  693.                 ParamDialog.StepsText.SetStyle STYLE_INVISIBLE
  694.                 ParamDialog.StepsSpin.SetStyle STYLE_INVISIBLE
  695.                 ParamDialog.OffsetText.SetStyle STYLE_INVISIBLE
  696.                 ParamDialog.TypeGroupBox.SetStyle STYLE_INVISIBLE
  697.             ENDIF
  698.             
  699.             IF (From% = 2) OR (From% = 0) THEN
  700.                 ' Tab 2 controls.
  701.                 ParamDialog.BlendGroupBox.SetStyle STYLE_INVISIBLE
  702.                 ParamDialog.DirectButton.SetStyle STYLE_INVISIBLE
  703.                 ParamDialog.CWButton.SetStyle STYLE_INVISIBLE
  704.                 ParamDialog.CCWButton.SetStyle STYLE_INVISIBLE
  705.                 ParamDialog.CCWText.SetStyle STYLE_INVISIBLE
  706.                 ParamDialog.CWText.SetStyle STYLE_INVISIBLE
  707.                 ParamDialog.DirectText.SetStyle STYLE_INVISIBLE
  708.                 ParamDialog.FillButton1.SetStyle STYLE_INVISIBLE
  709.                 ParamDialog.FillButton2.SetStyle STYLE_INVISIBLE
  710.                 ParamDialog.OutlineButton.SetStyle STYLE_INVISIBLE
  711.             ENDIF
  712.             
  713.             ' Tab 3 controls.
  714.             ParamDialog.FillSlider.SetStyle STYLE_VISIBLE
  715.             ParamDialog.FillAccelerateText.SetStyle STYLE_VISIBLE
  716.             ParamDialog.OffsetAccelerateText.SetStyle STYLE_VISIBLE
  717.             ParamDialog.OffsetSlider.SetStyle STYLE_VISIBLE
  718.             ParamDialog.CenterOffsetButton.SetStyle STYLE_VISIBLE
  719.             ParamDialog.CenterFillButton.SetStyle STYLE_VISIBLE
  720.  
  721.             ' Set the current tab number.
  722.             CurTab% = 3
  723.             
  724.     END SELECT
  725.  
  726.     EXIT SUB
  727.     
  728. STNoSelection:
  729.     ERRNUM = 0
  730.     RESUME AT Continue
  731.  
  732. END SUB
  733.  
  734. '********************************************************************
  735. '
  736. '    Name:    UpdateTabTops (dialog subroutine)
  737. '
  738. '    Action:    Makes sure that the top of the pseudo-tab control
  739. '              retains a proper z-ordering of controls.
  740. '
  741. '    Params:    None.  As this is intended to be a dialog subroutine,
  742. '              it makes use of a variable global to UpdateTabTops,
  743. '              CurTab%.  This tells us which tab should be active.
  744. '
  745. '    Returns:    None.
  746. '
  747. '    Comments:    None.
  748. '
  749. '********************************************************************
  750. SUB UpdateTabTops
  751.  
  752.     ' Uncommenting the three commented lines in this routine will
  753.     ' remove some display artifacts which may occur when using the
  754.     ' keyboard to tab through the controls, but it causes unpleasant
  755.     ' flicker and so has been disabled.
  756.     SELECT CASE CurTab%
  757.         CASE 1
  758.             ParamDialog.Tab1Cover.SetStyle STYLE_VISIBLE 
  759.             ParamDialog.Tab2Cover.SetStyle STYLE_INVISIBLE 
  760.             ParamDialog.Tab3Cover.SetStyle STYLE_INVISIBLE 
  761.             'ParamDialog.MainTabBackground.SetStyle STYLE_VISIBLE
  762.                         
  763.         CASE 2
  764.             ParamDialog.Tab1Cover.SetStyle STYLE_INVISIBLE 
  765.             ParamDialog.Tab2Cover.SetStyle STYLE_VISIBLE 
  766.             ParamDialog.Tab3Cover.SetStyle STYLE_INVISIBLE 
  767.             'ParamDialog.MainTabBackground.SetStyle STYLE_VISIBLE
  768.  
  769.         CASE 3
  770.             ParamDialog.Tab1Cover.SetStyle STYLE_INVISIBLE 
  771.             ParamDialog.Tab2Cover.SetStyle STYLE_INVISIBLE 
  772.             ParamDialog.Tab3Cover.SetStyle STYLE_VISIBLE 
  773.             'ParamDialog.MainTabBackground.SetStyle STYLE_VISIBLE
  774.     END SELECT
  775.  
  776. END SUB
  777.  
  778. '********************************************************************
  779. '
  780. '    Name:    UpdateBlendButtons (dialog subroutine)
  781. '
  782. '    Action:    Updates which of the blend buttons appears
  783. '              to be pressed down and which appears to be
  784. '              pressed up based on the value of ColorBlendType.
  785. '
  786. '    Params:    None.  As this is intended to be a dialog function,
  787. '              it makes use of the variable global to ParamDialog:
  788. '              ColorBlendType.
  789. '
  790. '    Returns:    None.
  791. '
  792. '    Comments: None.
  793. '
  794. '********************************************************************
  795. SUB UpdateBlendButtons()
  796.  
  797.     DIM Bitmaps(3) AS STRING    ' Will hold the images to use.
  798.     
  799.     ' Normally, all buttons should appear to be up.
  800.     Bitmaps$(1) = CurDir$ + COLOR_DIRECT_UNPRESSED_BITMAP$
  801.     Bitmaps$(2) = CurDir$ + COLOR_DIRECT_PRESSED_BITMAP$
  802.     Bitmaps$(3) = CurDir$ + COLOR_DIRECT_UNPRESSED_BITMAP$
  803.     ParamDialog.DirectButton.SetArray Bitmaps$
  804.     Bitmaps$(1) = CurDir$ + COLOR_CCW_UNPRESSED_BITMAP$
  805.     Bitmaps$(2) = CurDir$ + COLOR_CCW_PRESSED_BITMAP$
  806.     Bitmaps$(3) = CurDir$ + COLOR_CCW_UNPRESSED_BITMAP$
  807.     ParamDialog.CCWButton.SetArray Bitmaps$
  808.     Bitmaps$(1) = CurDir$ + COLOR_CW_UNPRESSED_BITMAP$
  809.     Bitmaps$(2) = CurDir$ + COLOR_CW_PRESSED_BITMAP$
  810.     Bitmaps$(3) = CurDir$ + COLOR_CW_UNPRESSED_BITMAP$
  811.     ParamDialog.CWButton.SetArray Bitmaps$
  812.  
  813.     ' Make the appropriate button look like it's pressed down.
  814.     SELECT CASE ColorBlendType%
  815.     
  816.         CASE DRAW_BLEND_DIRECT%
  817.             Bitmaps$(1) = CurDir$ + COLOR_DIRECT_PRESSED_BITMAP$
  818.             Bitmaps$(2) = CurDir$ + COLOR_DIRECT_UNPRESSED_BITMAP$
  819.             Bitmaps$(3) = CurDir$ + COLOR_DIRECT_PRESSED_BITMAP$
  820.             ParamDialog.DirectButton.SetArray Bitmaps$
  821.             
  822.         CASE DRAW_BLEND_RAINBOW_CCW%
  823.             Bitmaps$(1) = CurDir$ + COLOR_CCW_PRESSED_BITMAP$
  824.             Bitmaps$(2) = CurDir$ + COLOR_CCW_UNPRESSED_BITMAP$
  825.             Bitmaps$(3) = CurDir$ + COLOR_CCW_PRESSED_BITMAP$
  826.             ParamDialog.CCWButton.SetArray Bitmaps$
  827.             
  828.         CASE DRAW_BLEND_RAINBOW_CW%
  829.             Bitmaps$(1) = CurDir$ + COLOR_CW_PRESSED_BITMAP$
  830.             Bitmaps$(2) = CurDir$ + COLOR_CW_UNPRESSED_BITMAP$
  831.             Bitmaps$(3) = CurDir$ + COLOR_CW_PRESSED_BITMAP$
  832.             ParamDialog.CWButton.SetArray Bitmaps$
  833.             
  834.     END SELECT    
  835.  
  836. END SUB
  837.  
  838. '********************************************************************
  839. '
  840. '    Name:    UndoLastApply (dialog subroutine)
  841. '
  842. '    Action:    Deletes the last created contour if possible.
  843. '
  844. '    Params:    RequireASelection - If TRUE, this routine
  845. '              will only perform the undo if the actual
  846. '              contour is currently selected.
  847. '              As this is intended to be a dialog subroutine,
  848. '              it makes use of variables global to ParamDialog.
  849. '
  850. '    Returns:    None.
  851. '
  852. '    Comments:    None.
  853. '
  854. '********************************************************************
  855. SUB UndoLastApply( RequireSelection AS BOOLEAN )
  856.  
  857.     DIM MessageText AS STRING
  858.     DIM MsgReturn AS LONG
  859.     DIM CurObj AS LONG
  860.  
  861.     ON ERROR GOTO ULAISError
  862.     
  863.     IF IDLastFullContour& > 0 THEN
  864.         IF RequireSelection THEN
  865.             IF NOT CheckForSelection() THEN
  866.                 EXIT SUB
  867.             ELSE
  868.                 CurObj& = .GetObjectsCDRStaticID()
  869.             ENDIF
  870.             IF (CurObj& <> IDLastFullContour&)  THEN
  871.                 EXIT SUB
  872.             ENDIF
  873.         ENDIF
  874.         IF .SelectObjectOfCDRStaticID(IDLastFullContour&) THEN
  875.             .DeleteObject
  876.         ELSE
  877.             ' The object has somehow been deleted!
  878.             ' Hence, our undo fails.
  879.             FAIL 5000 ' Trigger the error handler.
  880.         ENDIF
  881.         .SelectObjectOfCDRStaticID IDOriginal&
  882.         IDLastFullContour& = 0
  883.     ELSEIF NOT RequireSelection THEN
  884.         FAIL 5000 ' Trigger the error handler.
  885.     ENDIF
  886.  
  887.     VeryEnd:
  888.         IF NOT RequireSelection THEN
  889.             ParamDialog.UndoButton.Enable FALSE
  890.         ENDIF
  891.         EXIT SUB
  892.  
  893. ULAISError:
  894.     ' The operation cannot be done.
  895.     ERRNUM = 0
  896.     MessageText$ = "Sorry.  Cannot undo the last contour." + NL2 + \\
  897.                    "Perhaps the contour group has already been deleted."
  898.     MsgReturn& = MESSAGEBOX( MessageText$, TITLE_INFOBOX$, MB_OK_ONLY& )
  899.     RESUME AT VeryEnd
  900.  
  901. END SUB
  902.  
  903. '********************************************************************
  904. '
  905. '    Name:    ApplyContours(dialog subroutine)
  906. '
  907. '    Action:    Applies the contour effect specified in ParamDialog.
  908. '
  909. '    Params:    None.  Since this routine is intended to be
  910. '              a dialog subroutine, it makes use of variables
  911. '              global to ParamDialog.
  912. '
  913. '    Returns:    None.
  914. '
  915. '    Comments:    None.
  916. '
  917. '********************************************************************
  918. SUB ApplyContours
  919.  
  920.     CONST BaseAdjustment# = 0.000001 ' Avoids asymptotic logarithm problems.
  921.     CONST Precision! = 0.95        ' The percentage by which inside and
  922.                             ' to center blends miss the center.
  923.                             ' (Higher precisions take longer.)
  924.  
  925.     DIM MsgReturn AS LONG        ' The return value of MESSAGEBOX.
  926.     DIM Counter AS INTEGER        ' A counter variable for loops.
  927.     DIM LastUOffset AS DOUBLE    ' The last uniform offset distance we applied.
  928.     DIM CurUOffset AS DOUBLE        ' The current uniform offset we will apply.
  929.     DIM UniformFill AS DOUBLE    ' The uniform fill/outline logarithmic range.
  930.     DIM CurUFill AS DOUBLE        ' The current uniform fill/outline we will apply.
  931.     DIM CurRealOffset AS LONG    ' How much offset to apply (accelerated).
  932.     DIM BaseOff AS DOUBLE        ' The base of the offset accel. logarithm.
  933.     DIM BaseCol AS DOUBLE        ' The base of the color accel. logarithm.
  934.     DIM SpeedOUp AS BOOLEAN        ' Whether the offset acceleration speeds up
  935.                             ' or slows down.
  936.     DIM SpeedCUp AS BOOLEAN        ' Whether the color acceleration speeds up
  937.                             ' or slows down.
  938.     DIM WholeOffset AS LONG        ' The total offset that the final 
  939.                             ' contour line should have (tm).
  940.     DIM WholeRedDeltaOutline AS LONG    ' The total red delta on a direct color blend.
  941.     DIM WholeGreenDeltaOutline AS LONG ' The total green delta on a direct color blend.
  942.     DIM WholeBlueDeltaOutline AS LONG    ' The total blue delta on a direct color blend.
  943.     DIM WholeHueDeltaOutline AS LONG    ' The total hue delta on CW or CCW blends.
  944.     DIM WholeSatDeltaOutline AS LONG    ' The total saturation delta.
  945.     DIM WholeBriDeltaOutline AS LONG    ' The total brightness delta.
  946.     DIM WholeRedDeltaFill1 AS LONG    ' The total red delta on a direct color blend (1).
  947.     DIM WholeGreenDeltaFill1 AS LONG    ' The total green delta on a direct color blend (1).
  948.     DIM WholeBlueDeltaFill1 AS LONG    ' The total blue delta on a direct color blend (1).
  949.     DIM WholeHueDeltaFill1 AS LONG    ' The total hue delta on CW or CCW blends (1).
  950.     DIM WholeSatDeltaFill1 AS LONG    ' The total saturation delta.
  951.     DIM WholeBriDeltaFill1 AS LONG    ' The total brightness delta.
  952.     DIM WholeRedDeltaFill2 AS LONG    ' The total red delta on a direct color blend (2).
  953.     DIM WholeGreenDeltaFill2 AS LONG    ' The total green delta on a direct color blend (2).
  954.     DIM WholeBlueDeltaFill2 AS LONG    ' The total blue delta on a direct color blend (2).
  955.     DIM WholeHueDeltaFill2 AS LONG    ' The total hue delta on CW or CCW blends (2).
  956.     DIM WholeSatDeltaFill2 AS LONG    ' The total saturation delta.
  957.     DIM WholeBriDeltaFill2 AS LONG    ' The total brightness delta.
  958.     DIM UniformStep AS DOUBLE    ' The size of a uniform step.
  959.     DIM IDLast AS LONG            ' The CDRStaticID of the last object we had.
  960.     DIM IDCurrent AS LONG        ' The CDRStaticID of the current object we have.
  961.     DIM IDContoured AS LONG        ' The CDRStaticID of the newest contoured object.
  962.     DIM OrigXPos AS LONG        ' The X coordinate of the original.
  963.     DIM OrigYPos AS LONG        ' The Y coordinate of the original.
  964.     DIM ColTmpModel AS LONG        ' The color model of a temporary color.
  965.     DIM ColTmp1 AS LONG            ' The first component of a temporary color.
  966.     DIM ColTmp2 AS LONG            ' The second component of a temporary color.
  967.     DIM ColTmp3 AS LONG            ' The third component of a temporary color.
  968.     DIM ColTmp4 AS LONG            ' The fourth component of a temporary color.
  969.     DIM ColTmp5 AS LONG            ' The fifth component of a temporary color.
  970.     DIM ColTmp6 AS LONG            ' The sixth component of a temporary color.
  971.     DIM ColTmp7 AS LONG            ' The seventh component of a temporary color.
  972.     DIM ColTmpPosition AS LONG    ' For fountain fills, the position of this color.    
  973.     DIM CurOutlineRed AS LONG    ' The current contour line's red component.
  974.     DIM CurOutlineGreen AS LONG    ' The current contour line's green component.
  975.     DIM CurOutlineBlue AS LONG    ' The current contour line's blue component.
  976.     DIM CurOutlineHue AS LONG    ' The current contour line's hue component.
  977.     DIM CurOutlineSat AS LONG    ' The current contour line's saturation component.
  978.     DIM CurOutlineBri AS LONG    ' The current contour line's brightness component.
  979.     DIM CurFill1Red AS LONG        ' The current contour fill 1's red component.
  980.     DIM CurFill1Green AS LONG    ' The current contour fill 1's green component.
  981.     DIM CurFill1Blue AS LONG        ' The current contour fill 1's blue component.
  982.     DIM CurFill1Hue AS LONG        ' The current contour fill 1's hue component.
  983.     DIM CurFill1Sat AS LONG        ' The current contour fill 1's saturation component.
  984.     DIM CurFill1Bri AS LONG        ' The current contour fill 1's brightness component.
  985.     DIM CurFill2Red AS LONG        ' The current contour fill 2's red component.
  986.     DIM CurFill2Green AS LONG    ' The current contour fill 2's green component.
  987.     DIM CurFill2Blue AS LONG        ' The current contour fill 2's blue component.
  988.     DIM CurFill2Hue AS LONG        ' The current contour fill 2's hue component.
  989.     DIM CurFill2Sat AS LONG        ' The current contour fill 2's saturation component.
  990.     DIM CurFill2Bri AS LONG        ' The current contour fill 2's brightness component.
  991.  
  992.     IF NOT CheckForSelection() THEN
  993.         MsgReturn& = MESSAGEBOX("Please select an object in CorelDRAW before " + \\
  994.                                 "pressing the Apply button.", TITLE_INFOBOX$, \\
  995.                                 MB_OK_ONLY&) 
  996.         EXIT SUB
  997.     ENDIF
  998.     
  999.     ' Check to see that the object is contourable.  If it is not contourable,
  1000.     ' then we need to proceed.
  1001.     IF NOT CheckForContour() THEN
  1002.         MsgReturn& = MESSAGEBOX("Sorry.  Cannot apply a contour to the selected object." + NL2 + \\
  1003.                                 "In CorelDRAW, certain types of objects can have the " + \\
  1004.                                 "contour effect applied to them, and certain types of " + \\
  1005.                                 "objects cannot.  As a general rule, if the built-in " + \\
  1006.                                 "contour tool will not work with something, the accelerated " + \\
  1007.                                 "contour tool will not work either." + NL2 + \\
  1008.                                 "Please select a different object and try again.", \\
  1009.                                 TITLE_INFOBOX$, \\
  1010.                                 MB_OK_ONLY& OR MB_EXCLAMATION_ICON&)
  1011.         EXIT SUB
  1012.     ENDIF
  1013.     IDOriginal& = .GetObjectsCDRStaticID()
  1014.  
  1015.      ' Before doing anything, check to see that the user has not changed
  1016.      ' the fill type of the original object.  (They're allowed to change
  1017.      ' the color(s), but the fill type requires updating our dialog box.)
  1018.      IF .GetFillType() <> OriginalFillType& THEN
  1019.          MsgReturn& = MESSAGEBOX("The currently selected object has a different fill " + \\
  1020.                                   "type than the Accelerated Contour tool expected." + NL2 + \\
  1021.                                   "As a result, the fill color selections you have made " + \\
  1022.                                   "in the Accelerated Contour tool may not still be " + \\
  1023.                                  "appropriate.  Take a moment to verify that " + \\
  1024.                                  "you are satisfied with your choice of fill colors " + \\
  1025.                                  "and then press Apply again to apply your contour.", \\
  1026.                                  TITLE_INFOBOX$, \\
  1027.                                  MB_INFORMATION_ICON&)
  1028.          OriginalFillType& = .GetFillType()
  1029.          ActivateTab 2, 0
  1030.          EXIT SUB
  1031.      ENDIF
  1032.  
  1033.     ' Retrieve the colors of the original object.  Though it would
  1034.     ' be more efficient to do this once (on initialization) instead
  1035.     ' of each time, this approach allows the user to change the
  1036.     ' object's colour between clicks on the "Apply" button and have
  1037.     ' the contour tool still work properly.
  1038.     .GetOutlineColor ColTmpModel&, ColTmp1&, ColTmp2&, ColTmp3&, \\
  1039.                      ColTmp4&, ColTmp5&, ColTmp6&, ColTmp7&
  1040.     .StoreColor ColTmpModel&, ColTmp1&, ColTmp2&, ColTmp3&, ColTmp4&, \\
  1041.                  ColTmp5&, ColTmp6&, ColTmp7&
  1042.     .ConvertColor DRAW_COLORMODEL_RGB&, \\
  1043.                   FromOutlineRed&, FromOutlineGreen&, FromOutlineBlue&
  1044.     MakeHSB FromOutlineRed&, FromOutlineGreen&, FromOutlineBlue&, \\
  1045.             FromOutlineHue&, FromOutlineSat&, FromOutlineBri&
  1046.     SELECT CASE OriginalFillType&
  1047.         CASE DRAW_FILL_UNIFORM&
  1048.             .GetUniformFillColor ColTmpModel&, ColTmp1&, ColTmp2&, ColTmp3&, \\
  1049.                                  ColTmp4&, ColTmp5&, ColTmp6&, ColTmp7&
  1050.             .StoreColor ColTmpModel&, ColTmp1&, ColTmp2&, ColTmp3&, ColTmp4&, \\
  1051.                            ColTmp5&, ColTmp6&, ColTmp7&
  1052.             .ConvertColor DRAW_COLORMODEL_RGB&, \\
  1053.                           FromFill1Red&, FromFill1Green&, FromFill1Blue&
  1054.             MakeHSB FromFill1Red&, FromFill1Green&, FromFill1Blue&, \\
  1055.                     FromFill1Hue&, FromFill1Sat&, FromFill1Bri&
  1056.             
  1057.         CASE DRAW_FILL_FOUNTAIN&
  1058.             .GetFountainFillColor 0, ColTmpPosition&, ColTmpModel&, \\
  1059.                               ColTmp1&, ColTmp2&, ColTmp3&, ColTmp4&, \\
  1060.                                    ColTmp5&, ColTmp6&, ColTmp7&
  1061.             .StoreColor ColTmpModel&, ColTmp1&, ColTmp2&, ColTmp3&, \\
  1062.                            ColTmp4&, ColTmp5&, ColTmp6&, ColTmp7&, ColTmpPosition&
  1063.             .ConvertColor DRAW_COLORMODEL_RGB&, \\
  1064.                         FromFill1Red&, FromFill1Green&, FromFill1Blue&
  1065.             .GetFountainFillColor 100, ColTmpPosition&, ColTmpModel&, \\
  1066.                               ColTmp1&, ColTmp2&, ColTmp3&, ColTmp4&, \\
  1067.                                    ColTmp5&, ColTmp6&, ColTmp7&
  1068.             .StoreColor ColTmpModel&, ColTmp1&, ColTmp2&, ColTmp3&, \\
  1069.                            ColTmp4&, ColTmp5&, ColTmp6&, ColTmp7&, ColTmpPosition&
  1070.             .ConvertColor DRAW_COLORMODEL_RGB&, \\
  1071.                         FromFill2Red&, FromFill2Green&, FromFill2Blue&
  1072.             MakeHSB FromFill1Red&, FromFill1Green&, FromFill1Blue&, \\
  1073.                     FromFill1Hue&, FromFill1Sat&, FromFill1Bri&
  1074.             MakeHSB FromFill2Red&, FromFill2Green&, FromFill2Blue&, \\
  1075.                     FromFill2Hue&, FromFill2Sat&, FromFill2Bri&
  1076.  
  1077.         CASE ELSE
  1078.             ' Do nothing.
  1079.     END SELECT
  1080.  
  1081. REM     ' If there is an existing contour, erase it and start over.
  1082. REM     IF IDLastFullContour& > 0 THEN
  1083. REM         .SelectObjectOfCDRStaticID IDLastFullContour&
  1084. REM         .DeleteObject
  1085. REM     ENDIF
  1086.     .SelectObjectOfCDRStaticID IDOriginal&
  1087.     .GetPosition OrigXPos&, OrigYPos&
  1088.     .DuplicateObject
  1089.     .SetPosition OrigXPos&, OrigYPos&
  1090.     
  1091.     ' Based on the selections in the sliders, calculate the
  1092.     ' bases of the logarithms to use for the accelerations.
  1093.     BaseOff# = 1 + ABS(OffsetAccel%) + BaseAdjustment#
  1094.     IF OffsetAccel% >= 0 THEN
  1095.         SpeedOUp = TRUE
  1096.     ELSE
  1097.         SpeedOUp = FALSE
  1098.     ENDIF
  1099.     BaseCol# = 1 + ABS(FillAccel%) + BaseAdjustment#
  1100.     IF FillAccel% >= 0 THEN
  1101.         SpeedCUp = TRUE
  1102.     ELSE
  1103.         SpeedCUp = FALSE
  1104.     ENDIF
  1105.     
  1106.     ' Calculate the offset of the final contour line.
  1107.     IF OffsetType% = AC_OFFSET_PER_STEP% THEN
  1108.         WholeOffset& = Steps% * Offset% * ConversionFactors!(ChosenUnit%)
  1109.     ELSE
  1110.         WholeOffset& = Offset% * ConversionFactors!(ChosenUnit%)
  1111.     ENDIF
  1112.     
  1113.     ' Calculate the necessary color deltas.
  1114.     SELECT CASE ColorBlendType%
  1115.         CASE DRAW_BLEND_DIRECT%
  1116.             WholeRedDeltaOutline& = ToOutlineRed& - FromOutlineRed&
  1117.             WholeGreenDeltaOutline& = ToOutlineGreen& - FromOutlineGreen&
  1118.             WholeBlueDeltaOutline& = ToOutlineBlue& - FromOutlineBlue&
  1119.             WholeRedDeltaFill1& = ToFill1Red& - FromFill1Red&
  1120.             WholeGreenDeltaFill1& = ToFill1Green& - FromFill1Green&
  1121.             WholeBlueDeltaFill1& = ToFill1Blue& - FromFill1Blue&
  1122.             IF OriginalFillType& = DRAW_FILL_FOUNTAIN& THEN
  1123.                 WholeRedDeltaFill2& = ToFill2Red& - FromFill2Red&
  1124.                 WholeGreenDeltaFill2& = ToFill2Green& - FromFill2Green&
  1125.                 WholeBlueDeltaFill2& = ToFill2Blue& - FromFill2Blue&                
  1126.             ENDIF
  1127.             
  1128.         CASE DRAW_BLEND_RAINBOW_CW%
  1129.             WholeHueDeltaOutline& = ToOutlineHue& - FromOutlineHue&
  1130.             WholeSatDeltaOutline& = ToOutlineSat& - FromOutlineSat&
  1131.             WholeBriDeltaOutline& = ToOutlineBri& - FromOutlineBri&
  1132.             WholeSatDeltaFill1& = ToFill1Sat& - FromFill1Sat&
  1133.             WholeBriDeltaFill1& = ToFill1Bri& - FromFill1Bri&
  1134.             IF OriginalFillType& = DRAW_FILL_FOUNTAIN& THEN
  1135.                 WholeHueDeltaFill2& = ToFill2Hue& - FromFill2Hue& 
  1136.                 WholeSatDeltaFill2& = ToFill2Sat& - FromFill2Sat&
  1137.                 WholeBriDeltaFill2& = ToFill2Bri& - FromFill2Bri&
  1138.             ENDIF
  1139.             ' Rotate clockwise around the color wheel.
  1140.             IF (ToOutlineHue& - FromOutlineHue&) >= 0 THEN
  1141.                 WholeHueDeltaOutline& = ToOutlineHue& - FromOutlineHue&
  1142.             ELSE
  1143.                 WholeHueDeltaOutline& = 360 - FromOutlineHue& + ToOutlineHue&
  1144.             ENDIF            
  1145.             IF (ToFill1Hue& - FromFill1Hue&) >= 0 THEN
  1146.                 WholeHueDeltaFill1& = ToFill1Hue& - FromFill1Hue&
  1147.             ELSE
  1148.                 WholeHueDeltaFill1& = 360 - FromFill1Hue& + ToFill1Hue&
  1149.             ENDIF
  1150.             IF (ToFill2Hue& - FromFill2Hue&) >= 0 THEN
  1151.                 WholeHueDeltaFill2& = ToFill2Hue& - FromFill2Hue&
  1152.             ELSE
  1153.                 WholeHueDeltaFill2& = 360 - FromFill2Hue& + ToFill2Hue&
  1154.             ENDIF
  1155.  
  1156.         CASE DRAW_BLEND_RAINBOW_CCW%
  1157.             WholeHueDeltaOutline& = ToOutlineHue& - FromOutlineHue&
  1158.             WholeSatDeltaOutline& = ToOutlineSat& - FromOutlineSat&
  1159.             WholeBriDeltaOutline& = ToOutlineBri& - FromOutlineBri&
  1160.             IF (ToFill1Hue& - FromFill1Hue&) >= 0 THEN
  1161.                 WholeHueDeltaFill1& = ToFill1Hue& - FromFill1Hue&
  1162.             ELSE
  1163.                 WholeHueDeltaFill1& = 360 - FromFill1Hue& + ToFill1Hue&
  1164.             ENDIF
  1165.             WholeSatDeltaFill1& = ToFill1Sat& - FromFill1Sat&
  1166.             WholeBriDeltaFill1& = ToFill1Bri& - FromFill1Bri&
  1167.             IF OriginalFillType& = DRAW_FILL_FOUNTAIN& THEN
  1168.                 WholeHueDeltaFill2& = ToFill2Hue& - FromFill2Hue& 
  1169.                 WholeSatDeltaFill2& = ToFill2Sat& - FromFill2Sat&
  1170.                 WholeBriDeltaFill2& = ToFill2Bri& - FromFill2Bri&
  1171.             ENDIF
  1172.             ' Rotate counter-clockwise around the color wheel.
  1173.             IF (ToOutlineHue& - FromOutlineHue&) >= 0 THEN
  1174.                 WholeHueDeltaOutline& = -1 * FromOutlineHue& + ToOutlineHue& - 360
  1175.             ELSE
  1176.                 WholeHueDeltaOutline& = ToOutlineHue& - FromOutlineHue&
  1177.             ENDIF            
  1178.             IF (ToFill1Hue& - FromFill1Hue&) >= 0 THEN
  1179.                 WholeHueDeltaFill1& = -1 * FromFill1Hue& + ToFill1Hue& - 360
  1180.             ELSE
  1181.                 WholeHueDeltaFill1& = ToFill1Hue& - FromFill1Hue&
  1182.             ENDIF
  1183.             IF (ToFill2Hue& - FromFill2Hue&) >= 0 THEN
  1184.                 WholeHueDeltaFill2& = -1 * FromFill2Hue& + ToFill2Hue& - 360
  1185.             ELSE
  1186.                 WholeHueDeltaFill2& = ToFill2Hue& - FromFill2Hue&
  1187.             ENDIF
  1188.                     
  1189.         CASE ELSE
  1190.             MESSAGE "ASSERTION FAILURE"
  1191.             STOP
  1192.     END SELECT
  1193.     
  1194.     ' If we are going to the center or inside, we have a special case, and
  1195.     ' since there's no way of determining how far we have to go, we have
  1196.     ' to find it the hard way.
  1197.     IF (Direction% = DRAW_CONTOUR_TO_CENTER&) OR \\
  1198.        (Direction% = DRAW_CONTOUR_INSIDE&) THEN
  1199.         
  1200.         DIM Highest AS LONG    ' The highest offset we've tried so far.
  1201.         DIM XSize AS LONG    ' The current selection's x size.
  1202.         DIM YSize AS LONG    ' The current selection's y size.
  1203.         DIM TmpSteps AS INTEGER    ' A temporary variable for calculating the
  1204.                             ' number of steps.
  1205.         
  1206.         ' Use the selection's size as a start.
  1207.         .GetSize XSize&, YSize&
  1208.         IF XSize& > YSize& THEN
  1209.             Highest& = YSize&
  1210.         ELSE
  1211.             Highest& = XSize&
  1212.         ENDIF
  1213.         
  1214.         ' Instead of algorithmically determining the number
  1215.         ' of contours that are possible, we can estimate this
  1216.         ' number mathematically for speed reasons.
  1217.         ' (We divide by 2, plus a little bit extra so the inside
  1218.         ' contour line does not look too small.)
  1219.         Highest& = Highest& / 2.2
  1220.     
  1221.         IF OffsetType% = AC_OFFSET_PER_STEP% THEN
  1222.             TmpSteps% = FIX(Highest& / \\
  1223.                      (Offset% * ConversionFactors!(ChosenUnit%)))
  1224.             IF (TmpSteps% > 0) THEN
  1225.                 IF Direction% = DRAW_CONTOUR_TO_CENTER& THEN
  1226.                     Steps% = TmpSteps%
  1227.                     WholeOffset& = Highest&
  1228.                 ELSE ' DRAW_OFFSET_INSIDE&
  1229.                     Steps% = MIN(TmpSteps%, Steps%)
  1230.                     WholeOffset& = Steps% * Offset% * \\
  1231.                                    ConversionFactors!(ChosenUnit%)
  1232.                 ENDIF
  1233.                 ParamDialog.StepsSpin.SetValue Steps%
  1234.             ELSE
  1235.                 MsgReturn& = MESSAGEBOX("The offset you selected " + \\
  1236.                                        "is so large that it will " + \\
  1237.                                        "not produce any contour lines."+\\
  1238.                                        NL2 + "Please select a "+\\
  1239.                                        "smaller offset and try again.",\\
  1240.                                        TITLE_INFOBOX$, \\
  1241.                                        MB_OK_ONLY& OR \\
  1242.                                        MB_EXCLAMATION_ICON&)
  1243.                 EXIT SUB
  1244.             ENDIF
  1245.         ELSE
  1246.             IF Highest& < WholeOffset& THEN
  1247.                 ' If the user has specified a too large total
  1248.                 ' offset, adjust it automatically.
  1249.                 WholeOffset& = Highest&
  1250.             ENDIF
  1251.             Offset% = MIN(CINT(FIX(Highest& / \\
  1252.                       ConversionFactors!(ChosenUnit%))), Offset%)
  1253.             ParamDialog.OffsetSpin.SetValue Offset%
  1254.         ENDIF
  1255.  
  1256.     ENDIF
  1257.     
  1258.     ' We calculate a uniform step offset from 1 to BaseOff#.
  1259.     ' Later, we take the logarithm of each step offset to
  1260.     ' get the accelerated offset.
  1261.     UniformStep# = (BaseOff# - 1) / Steps%
  1262.     
  1263.     ' Do the same for the colors.
  1264.     UniformFill# = (BaseCol# - 1) / Steps%
  1265.  
  1266.     ' Apply each contour.
  1267.     IF SpeedOUp THEN
  1268.         LastUOffset# = 1
  1269.     ELSE
  1270.         LastUOffset# = BaseOff#
  1271.     ENDIF
  1272.         
  1273.     FOR Counter% = 1 TO Steps%
  1274.     
  1275.         ' Calculate the offset for this individual contour line.
  1276.         IF SpeedOUp THEN
  1277.             CurUOffset# = UniformStep# * Counter% + 1
  1278.             CurRealOffset& = ((LOG(CurUOffset#)/LOG(BaseOff#)) * \\
  1279.                              WholeOffset&) - \\
  1280.                           ((LOG(LastUOffset#)/LOG(BaseOff#)) * \\
  1281.                           WholeOffset&)
  1282.         ELSE
  1283.             CurUOffset# = BaseOff# - UniformStep# * Counter%
  1284.             CurRealOffset& = ((LOG(LastUOffset#)/LOG(BaseOff#)) * \\
  1285.                           WholeOffset&) - \\
  1286.                           ((LOG(CurUOffset#)/LOG(BaseOff#)) * \\
  1287.                              WholeOffset&)
  1288.         ENDIF
  1289.         
  1290.         ' Calculate the fill color(s) for this contour line.
  1291.         ' This is the most important part of the code.
  1292.         IF SpeedCUp THEN
  1293.             CurUFill# = BaseCol# - UniformFill# * Counter%
  1294.             IF ColorBlendType% = DRAW_BLEND_DIRECT% THEN
  1295.                 ' Calculate RGB color values.
  1296.                 CurOutlineRed& = ToOutlineRed& - ((LOG(CurUFill#)/LOG(BaseCol#) * WholeRedDeltaOutline&) MOD 256)
  1297.                 CurOutlineGreen& = ToOutlineGreen& - ((LOG(CurUFill#)/LOG(BaseCol#) * WholeGreenDeltaOutline&) MOD 256)
  1298.                 CurOutlineBlue& = ToOutlineBlue& - ((LOG(CurUFill#)/LOG(BaseCol#) * WholeBlueDeltaOutline&) MOD 256)
  1299.                 CurFill1Red& = ToFill1Red& - ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeRedDeltaFill1&) MOD 256
  1300.                 CurFill1Green& = ToFill1Green& - ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeGreenDeltaFill1&) MOD 256
  1301.                 CurFill1Blue& = ToFill1Blue& - ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeBlueDeltaFill1&) MOD 256
  1302.                 IF OriginalFillType& = DRAW_FILL_FOUNTAIN& THEN
  1303.                     CurFill2Red& = ToFill2Red& - ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeRedDeltaFill2&) MOD 256
  1304.                     CurFill2Green& = ToFill2Green& - ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeGreenDeltaFill2&) MOD 256
  1305.                     CurFill2Blue& = ToFill2Blue& - ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeBlueDeltaFill2&) MOD 256
  1306.                 ENDIF
  1307.             ELSE
  1308.                 ' Calculate HSB color values.
  1309.                 CurOutlineHue& = Mod360( CLNG(ToOutlineHue& - (LOG(CurUFill#)/LOG(BaseCol#))*WholeHueDeltaOutline&) )
  1310.                 CurOutlineSat& = Mod256( CLNG(ToOutlineSat& - (LOG(CurUFill#)/LOG(BaseCol#))*WholeSatDeltaOutline&) )
  1311.                 CurOutlineBri& = Mod256( CLNG(ToOutlineBri& - (LOG(CurUFill#)/LOG(BaseCol#))*WholeBriDeltaOutline&) )
  1312.                 CurFill1Hue& = Mod360( CLNG(ToFill1Hue& - (LOG(CurUFill#)/LOG(BaseCol#))*WholeHueDeltaFill1&) )
  1313.                 CurFill1Sat& = Mod256( CLNG(ToFill1Sat& - (LOG(CurUFill#)/LOG(BaseCol#))*WholeSatDeltaFill1&) )
  1314.                 CurFill1Bri& = Mod256( CLNG(ToFill1Bri& - (LOG(CurUFill#)/LOG(BaseCol#))*WholeBriDeltaFill1&) )
  1315.                 IF OriginalFillType& = DRAW_FILL_FOUNTAIN& THEN
  1316.                     CurFill2Hue& = Mod360( CLNG(ToFill2Hue& - (LOG(CurUFill#)/LOG(BaseCol#))*WholeHueDeltaFill2&) )
  1317.                     CurFill2Sat& = Mod256( CLNG(ToFill2Sat& - (LOG(CurUFill#)/LOG(BaseCol#))*WholeSatDeltaFill2&) )
  1318.                     CurFill2Bri& = Mod256( CLNG(ToFill2Bri& - (LOG(CurUFill#)/LOG(BaseCol#))*WholeBriDeltaFill2&) )                    
  1319.                 ENDIF
  1320.             ENDIF
  1321.         ELSE
  1322.             CurUFill# = UniformFill# * Counter% + 1
  1323.             IF ColorBlendType% = DRAW_BLEND_DIRECT% THEN
  1324.                 ' Calculate the RGB color values.
  1325.                 CurOutlineRed& = FromOutlineRed& + ((LOG(CurUFill#)/LOG(BaseCol#) * WholeRedDeltaOutline&) MOD 256)
  1326.                 CurOutlineGreen& = FromOutlineGreen& + ((LOG(CurUFill#)/LOG(BaseCol#) * WholeGreenDeltaOutline&) MOD 256)
  1327.                 CurOutlineBlue& = FromOutlineBlue& + ((LOG(CurUFill#)/LOG(BaseCol#) * WholeBlueDeltaOutline&) MOD 256)
  1328.                 CurFill1Red& = FromFill1Red& + ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeRedDeltaFill1&) MOD 256
  1329.                 CurFill1Green& = FromFill1Green& + ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeGreenDeltaFill1&) MOD 256
  1330.                 CurFill1Blue& = FromFill1Blue& + ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeBlueDeltaFill1&) MOD 256    
  1331.                 IF OriginalFillType& = DRAW_FILL_FOUNTAIN& THEN
  1332.                     CurFill2Red& = FromFill2Red& + ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeRedDeltaFill2&) MOD 256
  1333.                     CurFill2Green& = FromFill2Green& + ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeGreenDeltaFill2&) MOD 256
  1334.                     CurFill2Blue& = FromFill2Blue& + ((LOG(CurUFill#)/LOG(BaseCol#)) * WholeBlueDeltaFill2&) MOD 256                    
  1335.                 ENDIF
  1336.             ELSE
  1337.                 ' Calculate HSB color values.
  1338.                 CurOutlineHue& = Mod360( CLNG(FromOutlineHue& + (LOG(CurUFill#)/LOG(BaseCol#))*WholeHueDeltaOutline&) )
  1339.                 CurOutlineSat& = Mod256( CLNG(FromOutlineSat& + (LOG(CurUFill#)/LOG(BaseCol#))*WholeSatDeltaOutline&) )
  1340.                 CurOutlineBri& = Mod256( CLNG(FromOutlineBri& + (LOG(CurUFill#)/LOG(BaseCol#))*WholeBriDeltaOutline&) )
  1341.                 CurFill1Hue& = Mod360( CLNG(FromFill1Hue& + (LOG(CurUFill#)/LOG(BaseCol#))*WholeHueDeltaFill1&) )
  1342.                 CurFill1Sat& = Mod256( CLNG(FromFill1Sat& + (LOG(CurUFill#)/LOG(BaseCol#))*WholeSatDeltaFill1&) )
  1343.                 CurFill1Bri& = Mod256( CLNG(FromFill1Bri& + (LOG(CurUFill#)/LOG(BaseCol#))*WholeBriDeltaFill1&) )
  1344.                 IF OriginalFillType& = DRAW_FILL_FOUNTAIN& THEN
  1345.                     CurFill2Hue& = Mod360( CLNG(FromFill2Hue& + (LOG(CurUFill#)/LOG(BaseCol#))*WholeHueDeltaFill2&) )
  1346.                     CurFill2Sat& = Mod256( CLNG(FromFill2Sat& + (LOG(CurUFill#)/LOG(BaseCol#))*WholeSatDeltaFill2&) )
  1347.                     CurFill2Bri& = Mod256( CLNG(FromFill2Bri& + (LOG(CurUFill#)/LOG(BaseCol#))*WholeBriDeltaFill2&) )                    
  1348.                 ENDIF
  1349.             ENDIF
  1350.         ENDIF
  1351.     
  1352.         ' Actually make a contour object.
  1353.         .Separate
  1354.         .Ungroup    
  1355.         .SelectPreviousObject FALSE
  1356.         .SelectNextObject FALSE
  1357.         IDCurrent& = .GetObjectsCDRStaticID()
  1358.         
  1359.         ON ERROR GOTO ErrBadOffset
  1360.         IF Direction% = DRAW_CONTOUR_OUTSIDE& THEN
  1361.             IF ColorBlendType% = DRAW_BLEND_DIRECT% THEN
  1362.                 .StoreColor   DRAW_COLORMODEL_RGB&, CurOutlineRed&, CurOutlineGreen&, CurOutlineBlue&, 0
  1363.                 .StoreColor   DRAW_COLORMODEL_RGB&, CurFill1Red&, CurFill1Green&, CurFill1Blue&, 0
  1364.                 .StoreColor   DRAW_COLORMODEL_RGB&, CurFill2Red&, CurFill2Green&, CurFill2Blue&, 0
  1365.                 .ApplyContour DRAW_CONTOUR_OUTSIDE&, CurRealOffset&, 1, DRAW_BLEND_DIRECT%
  1366.             ELSE
  1367.                 .StoreColor   DRAW_COLORMODEL_HSB&, CurOutlineHue&, CurOutlineSat&, CurOutlineBri&, 0
  1368.                 .StoreColor   DRAW_COLORMODEL_HSB&, CurFill1Hue&, CurFill1Sat&, CurFill1Bri&, 0
  1369.                 .StoreColor   DRAW_COLORMODEL_HSB&, CurFill2Hue&, CurFill2Sat&, CurFill2Bri&, 0
  1370.                 .ApplyContour DRAW_CONTOUR_OUTSIDE&, CurRealOffset&, 1, DRAW_BLEND_DIRECT%
  1371.                 ' The DRAW_BLEND_DIRECT% is not a typo.  It has no effect since we're only applying 1 contour line.
  1372.             ENDIF
  1373.         ELSE
  1374.             ' We simulate to-center contours, we do not use the built-in
  1375.             ' functionality.
  1376.             
  1377.             ' Since we may not have accurately predicted the maximum number of offset lines,
  1378.             ' we need to check whether applying this contour is possible.
  1379.             DIM CurTestSizeX AS LONG
  1380.             DIM CurTestSizeY AS LONG
  1381.             DIM MaximumAllowableOffset AS LONG
  1382.             .GetSize CurTestSizeX&, CurTestSizeY&
  1383.             IF CurTestSizeX& > CurTestSizeY& THEN
  1384.                 MaximumAllowableOffset& = CurTestSizeY& / 2.2
  1385.             ELSE
  1386.                 MaximumAllowableOffset& = CurTestSizeX& / 2.2
  1387.             ENDIF
  1388.             IF CurRealOffset& > MaximumAllowableOffset& THEN
  1389.             
  1390.                 ' We no longer need to apply any other contour lines,
  1391.                 ' since we're out of space.
  1392.                 Counter% = Steps%
  1393.                 Steps% = Counter%
  1394.                 ParamDialog.StepsSpin.SetValue Steps%
  1395.  
  1396.             ELSE
  1397.  
  1398.                 IF ColorBlendType% = DRAW_BLEND_DIRECT% THEN
  1399.                     .StoreColor   DRAW_COLORMODEL_RGB&, CurOutlineRed&, CurOutlineGreen&, CurOutlineBlue&, 0
  1400.                     .StoreColor   DRAW_COLORMODEL_RGB&, CurFill1Red&, CurFill1Green&, CurFill1Blue&, 0
  1401.                     .StoreColor   DRAW_COLORMODEL_RGB&, CurFill2Red&, CurFill2Green&, CurFill2Blue&, 0
  1402.                     .ApplyContour DRAW_CONTOUR_INSIDE&, CurRealOffset&, 1, DRAW_BLEND_DIRECT%
  1403.                 ELSE
  1404.                     .StoreColor   DRAW_COLORMODEL_HSB&, CurOutlineHue&, CurOutlineSat&, CurOutlineBri&, 0
  1405.                     .StoreColor   DRAW_COLORMODEL_HSB&, CurFill1Hue&, CurFill1Sat&, CurFill1Bri&, 0
  1406.                     .StoreColor   DRAW_COLORMODEL_HSB&, CurFill2Hue&, CurFill2Sat&, CurFill2Bri&, 0
  1407.                     .ApplyContour DRAW_CONTOUR_INSIDE&, CurRealOffset&, 1, DRAW_BLEND_DIRECT%
  1408.                     ' The DRAW_BLEND_DIRECT% is not a typo.  It has no effect since we're only applying 1 contour line.
  1409.                 ENDIF
  1410.     
  1411.             ENDIF
  1412.  
  1413.         ENDIF
  1414.         ON ERROR EXIT
  1415.         
  1416.         .Separate
  1417.         .Ungroup    
  1418.         .SelectPreviousObject FALSE
  1419.         .SelectNextObject FALSE
  1420.         IDContoured& = .GetObjectsCDRStaticID()
  1421.         .SelectObjectOfCDRStaticID IDCurrent&
  1422.         IF IDLast& > 0 THEN
  1423.             .AppendObjectToSelection IDLast&
  1424.             .Group
  1425.         ENDIF
  1426.         IDLast& = .GetObjectsCDRStaticID()
  1427.         .SelectObjectOfCDRStaticID IDContoured&
  1428.                 
  1429.         ' Update LastUOffset#.
  1430.         LastUOffset# = CurUOffset#
  1431.         
  1432.     NEXT Counter%
  1433.  
  1434.     IF IDLast& > 0 THEN
  1435.         .AppendObjectToSelection IDLast&
  1436.         .Group
  1437.     ENDIF
  1438.     
  1439.     ' Retrieve the ID of this new "contour group" in case the user
  1440.     ' wants to erase it and start again.
  1441.     IDLastFullContour& = .GetObjectsCDRStaticID()
  1442.     ParamDialog.UndoButton.Enable TRUE
  1443.  
  1444.     VeryEnd:
  1445.         EXIT SUB
  1446.     
  1447. ErrBadOffset:
  1448.     ' This is just a precaution, and should never happen
  1449.     ' in practice.
  1450.     ERRNUM = 0
  1451.  
  1452.     ' Retrieve the main CorelDRAW directory and path from the registry.
  1453.     DIM MainDrawDir AS STRING
  1454.     MainDrawDir$ = REGISTRYQUERY (HKEY_LOCAL_MACHINE, \\
  1455.                                   REG_CORELDRAW_PATH$, \\
  1456.                                   REG_CORELDRAW_MAIN_DIR_KEY$)
  1457.     MainDrawDir$ = MainDrawDir$ + "\Draw"
  1458.     .FileSave MainDrawDir$ + "\ACBackup.cdr", 3, FALSE, 0, TRUE
  1459.     MsgReturn& = MESSAGEBOX("A very severe error has occurred in the " + \\
  1460.                              "Accelerated Contour Tool." + NL2 + \\
  1461.                              "As a precaution, your document has been saved as " + \\
  1462.                              MainDrawDir$ + "\ACBackup.cdr." + NL2 + \\
  1463.                              "If you experience any problems, re-load Draw and " + \\
  1464.                              "open this file.", \\
  1465.                         TITLE_ERRORBOX$, MB_STOP_ICON&)
  1466.     STOP
  1467.     Steps% = Counter% - 1
  1468.     ParamDialog.StepsSpin.SetValue Steps%
  1469.     RESUME AT VeryEnd
  1470.  
  1471. END SUB
  1472.  
  1473. '********************************************************************
  1474. '
  1475. ' MAIN PROGRAM
  1476. '
  1477. '********************************************************************
  1478. DIM GenReturn AS LONG        ' The return value of various routines.
  1479.  
  1480. REM     ' Retrieve the ID of the currently selected object in DRAW.
  1481. REM     IDOriginal& = .GetObjectsCDRStaticID()
  1482. REM 
  1483. REM     ' Retrieve its fill type.
  1484. REM     OriginalFillType& = .GetFillType()
  1485.     
  1486.     ' Show the dialog.
  1487.     GenReturn& = DIALOG(ParamDialog)
  1488. REM     IF GenReturn& = DIALOG_RETURN_OK% THEN
  1489. REM 
  1490. REM         ' Delete the original object, since the user wants
  1491. REM         ' to keep the contour effect.
  1492. REM         .SelectObjectOfCDRStaticID IDOriginal&
  1493. REM         IF IDLastFullContour& > 0 THEN
  1494. REM             .DeleteObject
  1495. REM             .SelectObjectOfCDRStaticID IDLastFullContour&
  1496. REM         ENDIF
  1497. REM 
  1498. REM     ELSE
  1499. REM 
  1500. REM         ' The user does not want to keep whatever effect
  1501. REM         ' was applied.
  1502. REM         IF (IDLastFullContour& > 0) THEN
  1503. REM             .SelectObjectOfCDRStaticID IDLastFullContour&
  1504. REM             .DeleteObject
  1505. REM         ENDIF
  1506. REM         .SelectObjectOfCDRStaticID IDOriginal&
  1507. REM                 
  1508. REM     ENDIF
  1509.  
  1510. STOP
  1511.  
  1512. '********************************************************************
  1513. '
  1514. '    Name:    Min (function)
  1515. '
  1516. '    Action:    Returns the lowest of two numbers.
  1517. '
  1518. '    Params:    Val1 - The first number.
  1519. '            Val2 - The second number.
  1520. '
  1521. '    Returns:    Whichever is smallest, Val1 or Val2.
  1522. '
  1523. '    Comments:    None.
  1524. '
  1525. '********************************************************************
  1526. FUNCTION Min( Val1 AS INTEGER, Val2 AS INTEGER ) AS INTEGER
  1527.  
  1528.     IF Val1% < Val2% THEN
  1529.         Min% = Val1%
  1530.     ELSE
  1531.         Min% = Val2%
  1532.     ENDIF
  1533.  
  1534. END FUNCTION
  1535.  
  1536. '********************************************************************
  1537. '
  1538. '    Name:    MakeHSB (subroutine)
  1539. '
  1540. '    Action:    Converts an RGB color to its HSB equivalent.
  1541. '
  1542. '    Params:    InRed - The red component of the color to convert.
  1543. '            InGreen - The green component of the color to convert.
  1544. '            InBlue - The blue component of the color to convert.
  1545. '            OutHue - The hue component of the HSB equivalent.
  1546. '            OutSat - The saturation component of the HSB equivalent.
  1547. '              OutBri - The brightness component of the HSB equivalent.
  1548. '
  1549. '    Returns:    None.
  1550. '
  1551. '    Comments:    None.
  1552. '
  1553. '********************************************************************
  1554. SUB MakeHSB( BYVAL InRed AS LONG,   \\
  1555.              BYVAL InGreen AS LONG, \\
  1556.              BYVAL InBlue AS LONG,  \\
  1557.              BYREF OutHue AS LONG,  \\
  1558.              BYREF OutSat AS LONG,  \\
  1559.              BYREF OutBri AS LONG )
  1560.  
  1561.     DIM OutComponent4 AS LONG
  1562.     
  1563.     .StoreColor DRAW_COLORMODEL_RGB&, InRed&, InGreen&, InBlue&, 0
  1564.     .ConvertColor DRAW_COLORMODEL_HSB&, OutHue&, OutSat&, OutBri&, OutComponent4&
  1565.  
  1566. END SUB
  1567.  
  1568. '********************************************************************
  1569. '
  1570. '    Name:    Mod256 (function)
  1571. '
  1572. '    Action:    Takes a long integer and adds or subtracts a
  1573. '            multiple of 256 so that the number is between
  1574. '            0 and 255 inclusive.
  1575. '
  1576. '    Params:    InNum - The number to perform the operation on.
  1577. '
  1578. '    Returns:    A LONG between 0 and 255 inclusive.
  1579. '
  1580. '    Comments:    None.
  1581. '
  1582. '********************************************************************
  1583. FUNCTION Mod256( InNum AS LONG ) AS LONG
  1584.  
  1585.     IF (InNum& >= 0) THEN
  1586.         Mod256& = InNum& MOD 256
  1587.     ELSE
  1588.         Mod256& = (CLNG(InNum& / 256) * -256 + 256 + InNum&) MOD 256
  1589.     ENDIF
  1590.  
  1591. END FUNCTION
  1592.  
  1593. '********************************************************************
  1594. '
  1595. '    Name:    Mod360 (function)
  1596. '
  1597. '    Action:    Takes a long integer and adds or subtracts a
  1598. '            multiple of 360 so that the number is between
  1599. '            0 and 360 inclusive.
  1600. '
  1601. '    Params:    InNum - The number to perform the operation on.
  1602. '
  1603. '    Returns:    A LONG between 0 and 360 inclusive.
  1604. '
  1605. '    Comments:    None.
  1606. '
  1607. '********************************************************************
  1608. FUNCTION Mod360( InNum AS LONG ) AS LONG
  1609.  
  1610.     IF (InNum& >= 0) THEN
  1611.         Mod360& = InNum& MOD 360
  1612.     ELSE
  1613.         Mod360& = (CLNG(InNum& / 360) * -360 + 360 + InNum&) MOD 360
  1614.     ENDIF
  1615.  
  1616. END FUNCTION
  1617.  
  1618. '********************************************************************
  1619. '
  1620. '    Name:    CheckForSelection (function)
  1621. '
  1622. '    Action:    Checks whether an object is currently selected
  1623. '            in CorelDRAW.
  1624. '
  1625. '    Params:    None.
  1626. '
  1627. '    Returns:    TRUE if an object is currently selected;  FALSE
  1628. '              otherwise.
  1629. '
  1630. '    Comments:    Never raises any errors. 
  1631. '
  1632. '********************************************************************
  1633. FUNCTION CheckForSelection AS BOOLEAN
  1634.  
  1635.     DIM ObjType AS LONG     ' The currently selected object type.
  1636.  
  1637.     ON ERROR GOTO CFSNothingError
  1638.     
  1639.     ObjType& = .GetObjectType()
  1640.     IF (ObjType& <= DRAW_OBJECT_TYPE_RESERVED) THEN
  1641.         CheckForSelection = FALSE
  1642.     ELSE
  1643.         CheckForSelection = TRUE
  1644.     ENDIF
  1645.  
  1646.     ExitPart:
  1647.         EXIT FUNCTION
  1648.  
  1649. CFSNothingError:
  1650.     ERRNUM = 0
  1651.     CheckForSelection = FALSE
  1652.     RESUME AT ExitPart
  1653.  
  1654. END FUNCTION
  1655.  
  1656. '********************************************************************
  1657. '
  1658. '    Name:    CheckForContour (function)
  1659. '
  1660. '    Action:    Checks whether the currently selected object in
  1661. '              CorelDRAW can have the contour effect applied to
  1662. '              it.
  1663. '
  1664. '    Params:    None.
  1665. '
  1666. '    Returns:    FALSE if there is nothing selected in CorelDRAW or
  1667. '              if there is something selected but it cannot have
  1668. '              the contour effect applied to it.  TRUE otherwise.
  1669. '
  1670. '    Comments:    Never raises any errors. 
  1671. '
  1672. '********************************************************************
  1673. FUNCTION CheckForContour AS BOOLEAN
  1674.  
  1675.     ON ERROR GOTO CFCNotContourableError
  1676.  
  1677.     ' We're just doing a simple contour, so omit most of the
  1678.     ' optional parameters.
  1679.     .ApplyContour 2, 25400, 1
  1680.     
  1681.     ' Undo what we just did.
  1682.     .Undo
  1683.     
  1684.     ' We've been successful, so return TRUE.
  1685.     CheckForContour = TRUE    
  1686.  
  1687.     ExitPart:
  1688.         EXIT FUNCTION
  1689.  
  1690. CFCNotContourableError:
  1691.     ERRNUM = 0
  1692.     CheckForContour = FALSE
  1693.     RESUME AT ExitPart
  1694.  
  1695. END FUNCTION
  1696.  
  1697. END WITHOBJECT
  1698.  
  1699.