home *** CD-ROM | disk | FTP | other *** search
/ CorelDRAW! 10 / cd10_pgrm.iso / Corel / Graphics10 / Draw / Scripts / Misc / fillout.csc < prev    next >
Encoding:
Text File  |  1997-09-24  |  30.0 KB  |  864 lines

  1. REM Applies a fountain filled outline 
  2. REM to the currently selected object.
  3.  
  4. '********************************************************************
  5. '   Script:    FillOut.csc
  6. '   Copyright 1996 Corel Corporation.  All rights reserved.
  7. '   Description: CorelDRAW script to apply a fountain filled outline
  8. '                to the currently selected object.  Uses contour
  9. '                and creates a grouped object.
  10. '********************************************************************
  11.  
  12. #addfol  "..\..\..\scripts"
  13. #include "ScpConst.csi"
  14. #include "DrwConst.csi"
  15.  
  16. '/////FUNCTION & SUBROUTINE DECLARATIONS/////////////////////////////
  17. DECLARE SUB UpdateBlendButtons()
  18. DECLARE SUB UpdateDisabledControls()
  19. DECLARE FUNCTION IsInteger( InString AS STRING ) AS BOOLEAN
  20. DECLARE FUNCTION CheckForSelection() AS BOOLEAN
  21. DECLARE FUNCTION CheckForContour() AS BOOLEAN
  22.  
  23. '/////GLOBAL VARIABLES & CONSTANTS///////////////////////////////////
  24. GLOBAL CONST TITLE_ERRORBOX$      = "Filled Outline Maker Error"
  25. GLOBAL CONST TITLE_INFOBOX$       = "Filled Outline Maker Information"
  26. GLOBAL NL AS STRING         ' These must be declared as 
  27. GLOBAL NL2 AS STRING     ' variables, not constants, because
  28. NL$ = CHR(10) + CHR(13)    ' we cannot assign expressions
  29. NL2$ = NL + NL             ' to constants.
  30.  
  31. GLOBAL Bitmaps(3) AS STRING    ' Will hold the images to assign to buttons.
  32.     
  33. ' The dialog return values.
  34. GLOBAL CONST DIALOG_RETURN_OK%     = 1
  35. GLOBAL CONST DIALOG_RETURN_CANCEL% = 2
  36.     
  37. ' The CDRStaticID of the duplicated object.
  38. GLOBAL IDDuplicate AS LONG
  39.  
  40. ' The current directory when this script was started.
  41. GLOBAL CurDir AS STRING
  42.  
  43. '/////PARAMETERS DIALOG//////////////////////////////////////////////
  44.  
  45. ' The graphics used for the color blend type buttons.
  46. GLOBAL CONST COLOR_DIRECT_UNPRESSED_BITMAP$ = "\ColDirec.bmp"
  47. GLOBAL CONST COLOR_DIRECT_PRESSED_BITMAP$ = "\ColDireP.bmp"
  48. GLOBAL CONST COLOR_CCW_UNPRESSED_BITMAP$ = "\ColCCW.bmp"
  49. GLOBAL CONST COLOR_CCW_PRESSED_BITMAP$ = "\ColCCWP.bmp"
  50. GLOBAL CONST COLOR_CW_UNPRESSED_BITMAP$ = "\ColCW.bmp"
  51. GLOBAL CONST COLOR_CW_PRESSED_BITMAP$ = "\ColCWP.bmp"
  52.  
  53. ' The array of possible units the user may select from.
  54. GLOBAL UnitsArray(6) AS STRING
  55. UnitsArray(1) = "1 in."
  56. UnitsArray(2) = "1/36 in."
  57. UnitsArray(3) = "0.001 in."
  58. UnitsArray(4) = "1 cm."
  59. UnitsArray(5) = "0.001 cm."
  60. UnitsArray(6) = "1 pt."
  61.  
  62. ' Multiplicative conversion factors to convert from the units to
  63. ' tenths of a micron.
  64. GLOBAL ConversionFactors(6) AS SINGLE
  65. ConversionFactors(1) = 1 * LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 1)
  66. ConversionFactors(2) = (1/36) * LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 1)
  67. ConversionFactors(3) = 0.001 * LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 1)
  68. ConversionFactors(4) = 1 * LENGTHCONVERT(LC_CENTIMETERS, LC_TENTHS_OFA_MICRON, 1)
  69. ConversionFactors(5) = 0.001 * LENGTHCONVERT(LC_CENTIMETERS, LC_TENTHS_OFA_MICRON, 1)
  70. ConversionFactors(6) = 1 * LENGTHCONVERT(LC_POINTS, LC_TENTHS_OFA_MICRON, 1)
  71.  
  72. ' Constants used for this dialog.
  73. GLOBAL CONST FILL_TYPE_LINEAR%    = 1
  74. GLOBAL CONST FILL_TYPE_RADIAL%    = 2
  75. GLOBAL CONST FILL_TYPE_CONICAL%    = 3
  76. GLOBAL CONST FILL_TYPE_SQUARE%    = 4
  77.  
  78. ' Variables needed for this dialog.
  79. GLOBAL FillType AS INTEGER        ' The fill type (linear, etc.)
  80. GLOBAL HorizOffset AS INTEGER        ' The horizontal offset percentage.
  81. GLOBAL VertOffset AS INTEGER        ' The vertical offset percentage.
  82. GLOBAL ColorBlendType AS INTEGER    ' Direct, CCW, or CW.
  83. GLOBAL Midpoint AS INTEGER        ' The midpoint (rate) for the fill.
  84. GLOBAL Angle AS INTEGER            ' The fill's angle.
  85. GLOBAL Steps AS INTEGER            ' The number of steps to use for
  86.                             ' the fill.
  87. GLOBAL Pad AS INTEGER            ' The amount of padding on the fill.
  88. GLOBAL MsgReturn AS LONG            ' The return value of MESSAGEBOX.
  89. GLOBAL FromRed AS INTEGER        ' The From color, red component.
  90. GLOBAL FromGreen AS INTEGER        ' The From color, green component.
  91. GLOBAL FromBlue AS INTEGER        ' The From color, blue component.
  92. GLOBAL ToRed AS INTEGER            ' The To color, red component.
  93. GLOBAL ToGreen AS INTEGER        ' The To color, green component.
  94. GLOBAL ToBlue AS INTEGER            ' The To color, blue component.
  95. GLOBAL Width AS INTEGER            ' The outline width.
  96. GLOBAL ChosenUnit AS INTEGER        ' The unit chosen by the user.
  97.  
  98. ' Set up the fill descriptions.
  99. GLOBAL FillDesc(4) AS STRING        ' The fill type descriptions.
  100. FillDesc$(1) = "Linear"
  101. FillDesc$(2) = "Radial"
  102. FillDesc$(3) = "Conical"
  103. FillDesc$(4) = "Square"
  104.  
  105. ' Set up the defaults.
  106. FillType% = FILL_TYPE_LINEAR%
  107. HorizOffset% = 0
  108. VertOffset% = 0
  109. Angle% = 0
  110. Steps% = 50
  111. Pad% = 0
  112. ColorBlendType% = DRAW_BLEND_DIRECT%
  113. Midpoint% = 50
  114. FromRed% = 0 
  115. FromGreen% = 0
  116. FromBlue% = 255
  117. ToRed% = 255
  118. ToGreen% = 0
  119. ToBlue% = 0
  120. Width% = 10
  121. ChosenUnit% = 2
  122.  
  123. BEGIN DIALOG OBJECT ParamDialog 238, 236, "Filled Outline Maker", SUB ParamDialogEventHandler
  124.     TEXT  12, 4, 214, 21, .Text1, "This tool automatically creates a fountain filled outline effect for the currently selected object."
  125.     GROUPBOX  12, 107, 214, 79, .GroupBox2, "Two color blend"
  126.     DDLISTBOX  36, 26, 80, 78, .TypeListBox
  127.     TEXT  22, 60, 37, 11, .HorizText, "Horizontal:"
  128.     SPINCONTROL  60, 58, 37, 12, .HorizSpin
  129.     TEXT  100, 60, 8, 11, .HorizPercentText, "%"
  130.     TEXT  100, 80, 8, 11, .VertPercentText, "%"
  131.     TEXT  22, 80, 30, 10, .VertText, "Vertical:"
  132.     SPINCONTROL  60, 78, 37, 12, .VertSpin
  133.     SPINCONTROL  173, 38, 37, 12, .AngleSpin
  134.     TEXT  136, 41, 25, 11, .AngleText, "Angle:"
  135.     TEXT  12, 28, 22, 11, .Text14, "Type:"
  136.     GROUPBOX  13, 44, 104, 56, .GroupBox5, "Center offset"
  137.     GROUPBOX  127, 22, 100, 78, .GroupBox6, "Options"
  138.     SPINCONTROL  173, 58, 37, 12, .StepsSpin
  139.     TEXT  136, 60, 25, 11, .Text6, "Steps:"
  140.     SPINCONTROL  173, 78, 37, 12, .PadSpin
  141.     TEXT  136, 80, 34, 11, .PadText, "Edge pad:"
  142.     TEXT  213, 80, 8, 9, .PadPercentText, "%"
  143.     TEXT  22, 125, 22, 9, .Text11, "From:"
  144.     PUSHBUTTON  56, 123, 57, 14, .FromButton, "Choose Color"
  145.     PUSHBUTTON  56, 143, 57, 14, .ToButton, "Choose Color"
  146.     TEXT  22, 164, 30, 10, .Text10, "Mid-point:"
  147.     HSLIDER 53, 163, 79, 16, .MidSlider
  148.     TEXT  22, 145, 22, 9, .Text13, "To:"
  149.     TEXTBOX  135, 161, 14, 14, .MidText
  150.     BITMAPBUTTON  180, 124, 14, 14, .DirectButton
  151.     BITMAPBUTTON  180, 138, 14, 14, .CCWButton
  152.     BITMAPBUTTON  180, 152, 14, 14, .CWButton
  153.     TEXT  140, 125, 36, 11, .Text16, "Blend type:"
  154.     TEXT  198, 126, 20, 9, .Text17, "Direct"
  155.     TEXT  198, 155, 20, 9, .Text19, "CW"
  156.     TEXT  198, 141, 20, 9, .Text18, "CCW"
  157.     TEXT  28, 195, 87, 11, .Text20, "Fountain-filled outline width:"
  158.     SPINCONTROL  119, 193, 27, 13, .WidthSpin
  159.     DDLISTBOX  156, 193, 47, 138, .UnitsListBox
  160.     TEXT  149, 195, 5, 11, .Text21, "x"
  161.     PUSHBUTTON  71, 214, 48, 14, .OkButton, "OK"
  162.     PUSHBUTTON  123, 214, 48, 14, .CancelButton, "Cancel"
  163. END DIALOG
  164.  
  165. SUB ParamDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  166.  
  167.     DIM MsgReturn AS LONG    ' The return value of MESSAGEBOX.
  168.  
  169.     SELECT CASE Event%
  170.     
  171.         CASE EVENT_INITIALIZATION&
  172.  
  173.             ' Set up the fill types list box.
  174.             ParamDialog.TypeListbox.SetArray FillDesc$
  175.             ParamDialog.TypeListbox.SetSelect FillType%
  176.             UpdateDisabledControls
  177.             
  178.             ' Set up the midpoint slider.
  179.             ParamDialog.MidSlider.SetMinRange 1
  180.             ParamDialog.MidSlider.SetMaxRange 99
  181.             ParamDialog.MidSlider.SetIncrement 1
  182.             ParamDialog.MidSlider.SetValue Midpoint%
  183.             ParamDialog.MidText.SetText CSTR(Midpoint%)
  184.         
  185.             ' Set up the offsets.
  186.             ParamDialog.HorizSpin.SetValue HorizOffset%
  187.             ParamDialog.VertSpin.SetValue VertOffset%
  188.         
  189.             ' Set up the other options.
  190.             ParamDialog.AngleSpin.SetValue Angle%
  191.             ParamDialog.StepsSpin.SetValue Steps%
  192.             ParamDialog.PadSpin.SetValue Pad%
  193.         
  194.             ' Set up the blend type buttons.
  195.             UpdateBlendButtons
  196.             
  197.             ' Set up the outline width related controls.
  198.             ParamDialog.WidthSpin.SetValue Width%
  199.             ParamDialog.UnitsListBox.SetArray UnitsArray$
  200.             ParamDialog.UnitsListBox.SetSelect ChosenUnit%
  201.             
  202.         CASE EVENT_MOUSE_CLICK&
  203.             SELECT CASE ControlID%
  204.                 CASE ParamDialog.TypeListBox.GetID()
  205.                     FillType% = ParamDialog.TypeListBox.GetSelect()
  206.                     UpdateDisabledControls
  207.                         
  208.                 CASE ParamDialog.DirectButton.GetID()
  209.                     ColorBlendType% = DRAW_BLEND_DIRECT%
  210.                     UpdateBlendButtons
  211.                     
  212.                 CASE ParamDialog.CCWButton.GetID()
  213.                     ColorBlendType% = DRAW_BLEND_RAINBOW_CCW%
  214.                     UpdateBlendButtons
  215.                 
  216.                 CASE ParamDialog.CWButton.GetID()
  217.                     ColorBlendType% = DRAW_BLEND_RAINBOW_CW%
  218.                     UpdateBlendButtons
  219.                 
  220.                 CASE ParamDialog.MidSlider.GetID()
  221.                     Midpoint% = ParamDialog.MidSlider.GetValue()
  222.                     ParamDialog.MidText.SetText \\
  223.                          CSTR(ParamDialog.MidSlider.GetValue())
  224.  
  225.                 CASE ParamDialog.FromButton.GetID()
  226.                     GETCOLOR FromRed%, FromGreen%, FromBlue%
  227.  
  228.                 CASE ParamDialog.ToButton.GetID()
  229.                     GETCOLOR ToRed%, ToGreen%, ToBlue%
  230.                     
  231.                 CASE ParamDialog.OkButton.GetID()
  232.                     ParamDialog.CloseDialog DIALOG_RETURN_OK%    
  233.                 
  234.                 CASE ParamDialog.CancelButton.GetID()
  235.                     ParamDialog.CloseDialog DIALOG_RETURN_CANCEL%
  236.     
  237.                 CASE ParamDialog.UnitsListBox.GetID()
  238.                     ChosenUnit% = ParamDialog.UnitsListBox.GetSelect()
  239.             
  240.             END SELECT
  241.         
  242.         CASE EVENT_CHANGE_IN_CONTENT&
  243.             SELECT CASE ControlID%
  244.                 CASE ParamDialog.WidthSpin.GetID()
  245.                     ' Make sure the button does not allow values
  246.                     ' less than or equal to 0 or greater than 99.
  247.                     IF (ParamDialog.WidthSpin.GetValue() <= 0) THEN
  248.                         MsgReturn& = MESSAGEBOX("Please enter a width value between " + \\
  249.                                                       "1 and 99.", \\
  250.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  251.                         ParamDialog.WidthSpin.SetValue 1
  252.                         Width% = 1
  253.                     ELSEIF (ParamDialog.WidthSpin.GetValue() > 99) THEN
  254.                         MsgReturn& = MESSAGEBOX("Please enter a width value between " + \\
  255.                                                       "1 and 99.", \\
  256.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  257.                         ParamDialog.WidthSpin.SetValue 99
  258.                         Width% = 99
  259.                     ELSE
  260.                         Width% = ParamDialog.WidthSpin.GetValue()
  261.                     ENDIF
  262.             
  263.                 CASE ParamDialog.HorizSpin.GetID()
  264.                     ' Make sure the horizontal offset spin button
  265.                     ' does not allow invalid values.
  266.                     IF (ParamDialog.HorizSpin.GetValue() < -100) THEN
  267.                         MsgReturn& = MESSAGEBOX("Please enter a horizontal offset " + \\
  268.                                                       "value between -100 and 100.", \\
  269.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  270.                         ParamDialog.HorizSpin.SetValue -100
  271.                         HorizOffset% = -100
  272.                     ELSEIF (ParamDialog.HorizSpin.GetValue() > 100) THEN
  273.                         MsgReturn& = MESSAGEBOX("Please enter a horizontal offset " + \\
  274.                                                       "value between -100 and 100.", \\
  275.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  276.                         ParamDialog.HorizSpin.SetValue 100
  277.                         HorizOffset% = 100
  278.                     ELSE
  279.                         HorizOffset% = ParamDialog.HorizSpin.GetValue()
  280.                     ENDIF
  281.                     
  282.                 CASE ParamDialog.VertSpin.GetID()
  283.                     ' Make sure the vertical offset spin button
  284.                     ' does not allow invalid values.
  285.                     IF (ParamDialog.VertSpin.GetValue() < -100) THEN
  286.                         MsgReturn& = MESSAGEBOX("Please enter a vertical offset " + \\
  287.                                                       "value between -100 and 100.", \\
  288.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  289.                         ParamDialog.VertSpin.SetValue -100
  290.                         VertOffset% = -100
  291.                     ELSEIF (ParamDialog.VertSpin.GetValue() > 100) THEN
  292.                         MsgReturn& = MESSAGEBOX("Please enter a vertical offset " + \\
  293.                                                       "value between -100 and 100.", \\
  294.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  295.                         ParamDialog.VertSpin.SetValue 100
  296.                         VertOffset% = 100
  297.                     ELSE
  298.                         VertOffset% = ParamDialog.HorizSpin.GetValue()
  299.                     ENDIF
  300.                     
  301.                 CASE ParamDialog.AngleSpin.GetID()
  302.                     ' Only allow angles from -360 to +360.
  303.                     IF (ParamDialog.AngleSpin.GetValue() < -360) THEN
  304.                         MsgReturn& = MESSAGEBOX("Please enter an angle between " + \\
  305.                                                       "-360 and 360 degrees.", \\
  306.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  307.                         ParamDialog.AngleSpin.SetValue -360
  308.                         Angle% = -360
  309.                     ELSEIF (ParamDialog.AngleSpin.GetValue() > 360) THEN
  310.                         MsgReturn& = MESSAGEBOX("Please enter an angle between " + \\
  311.                                                       "-360 and 360 degrees.", \\
  312.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  313.                         ParamDialog.AngleSpin.SetValue 360
  314.                         Angle% = 360
  315.                     ELSE
  316.                         Angle% = ParamDialog.AngleSpin.GetValue()
  317.                     ENDIF
  318.  
  319.                 CASE ParamDialog.StepsSpin.GetID()
  320.                     ' Only allow values from 2 to 256.
  321.                     IF (ParamDialog.StepsSpin.GetValue() < 2) THEN
  322.                         MsgReturn& = MESSAGEBOX("Please enter a number of steps " + \\
  323.                                                       "between 2 and 256.", \\
  324.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  325.                         ParamDialog.StepsSpin.SetValue 2
  326.                         Steps% = 2
  327.                     ELSEIF (ParamDialog.StepsSpin.GetValue() > 256) THEN
  328.                         MsgReturn& = MESSAGEBOX("Please enter a number of steps " + \\
  329.                                                       "between 2 and 256.", \\
  330.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  331.                         ParamDialog.StepsSpin.SetValue 256
  332.                         Steps% = 256
  333.                     ELSE
  334.                         Steps% = ParamDialog.StepsSpin.GetValue()
  335.                     ENDIF
  336.  
  337.                 CASE ParamDialog.PadSpin.GetID()
  338.                     ' Only allow values from 0 to 45.
  339.                     IF (ParamDialog.PadSpin.GetValue() < 0) THEN
  340.                         MsgReturn& = MESSAGEBOX("Please enter a pad " + \\
  341.                                                       "value between 0 and 45.", \\
  342.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  343.                         ParamDialog.PadSpin.SetValue 0
  344.                         Pad% = 0
  345.                     ELSEIF (ParamDialog.PadSpin.GetValue() > 45) THEN
  346.                         MsgReturn& = MESSAGEBOX("Please enter a pad " + \\
  347.                                                       "value between 0 and 45.", \\
  348.                                                       TITLE_INFOBOX$, MB_INFORMATION_ICON%)
  349.                         ParamDialog.PadSpin.SetValue 45
  350.                         Pad% = 45
  351.                     ELSE
  352.                         Pad% = ParamDialog.PadSpin.GetValue()
  353.                     ENDIF
  354.                         
  355.                 CASE ParamDialog.MidText.GetID()
  356.                     DIM UserText AS STRING    ' The text entered by the user.
  357.                     UserText$ = ParamDialog.MidText.GetText()
  358.                     IF LEN(UserText$) = 0 THEN
  359.                         ' The user has not entered anything
  360.                         ' yet.  Ignore it.
  361.                     ELSEIF NOT IsInteger(UserText$) THEN
  362.                         MsgReturn& = MESSAGEBOX( \\
  363.                            "Please enter a number.", \\
  364.                            TITLE_ERRORBOX$, \\
  365.                            MB_OK_ONLY& )
  366.                         ParamDialog.MidText.SetText CSTR(Midpoint%)
  367.                     ELSEIF (CINT(UserText$) > 99) OR \\
  368.                            (CINT(UserText$) < 1) THEN
  369.                         MsgReturn& = MESSAGEBOX( \\
  370.                            "Sorry.  You have entered an invalid " + \\
  371.                            "value for the mid-point." + NL2 + \\
  372.                            "Allowable values range from 1 to 99." + \\
  373.                            NL2 + "Please try again.", \\
  374.                            TITLE_ERRORBOX$, \\
  375.                            MB_OK_ONLY& )
  376.                         ParamDialog.MidText.SetText CSTR(Midpoint%)
  377.                     ELSE
  378.                         Midpoint% = CINT(UserText$)
  379.                         ParamDialog.MidSlider.SetValue Midpoint%
  380.                     ENDIF
  381.                     
  382.                 CASE ParamDialog.MidSlider.GetID()
  383.                     Midpoint% = ParamDialog.MidSlider.GetValue()
  384.                     ParamDialog.MidText.SetText \\
  385.                          CSTR(ParamDialog.MidSlider.GetValue())
  386.     
  387.             END SELECT
  388.     
  389.     END SELECT
  390.  
  391. END SUB
  392.  
  393. '********************************************************************
  394. '
  395. '    Name:    UpdateDisabledControls (dialog subroutine)
  396. '
  397. '    Action:    Updates which of the dialog controls are enabled
  398. '              or disabled based on the value of FillType.
  399. '
  400. '    Params:    None.  As this is intended to be a dialog function,
  401. '              it makes use of the variable global to ParamDialog:
  402. '              FillType.
  403. '
  404. '    Returns:    None.
  405. '
  406. '    Comments: None.
  407. '
  408. '********************************************************************
  409. SUB UpdateDisabledControls()
  410.  
  411.     ' Certain dialog items may need to be
  412.     ' enabled/disabled depending on the 
  413.     ' fill type.
  414.     SELECT CASE FillType%
  415.         CASE FILL_TYPE_LINEAR%
  416.             ParamDialog.HorizSpin.Enable FALSE
  417.             ParamDialog.HorizText.Enable FALSE
  418.             ParamDialog.HorizPercentText.Enable FALSE
  419.             ParamDialog.VertSpin.Enable FALSE
  420.             ParamDialog.VertText.Enable FALSE
  421.             ParamDialog.VertPercentText.Enable FALSE
  422.             ParamDialog.AngleSpin.Enable TRUE
  423.             ParamDialog.AngleText.Enable TRUE
  424.             ParamDialog.PadSpin.Enable TRUE
  425.             ParamDialog.PadText.Enable TRUE
  426.             ParamDialog.PadPercentText.Enable TRUE
  427.             
  428.         CASE FILL_TYPE_RADIAL%
  429.             ParamDialog.HorizSpin.Enable TRUE
  430.             ParamDialog.HorizText.Enable TRUE
  431.             ParamDialog.HorizPercentText.Enable TRUE
  432.             ParamDialog.VertSpin.Enable TRUE
  433.             ParamDialog.VertText.Enable TRUE
  434.             ParamDialog.VertPercentText.Enable TRUE
  435.             ParamDialog.AngleSpin.Enable FALSE
  436.             ParamDialog.AngleText.Enable FALSE
  437.             ParamDialog.PadSpin.Enable TRUE
  438.             ParamDialog.PadText.Enable TRUE
  439.             ParamDialog.PadPercentText.Enable TRUE
  440.             
  441.         CASE FILL_TYPE_CONICAL%
  442.             ParamDialog.HorizSpin.Enable TRUE
  443.             ParamDialog.HorizText.Enable TRUE
  444.             ParamDialog.HorizPercentText.Enable TRUE
  445.             ParamDialog.VertSpin.Enable TRUE
  446.             ParamDialog.VertText.Enable TRUE
  447.             ParamDialog.VertPercentText.Enable TRUE
  448.             ParamDialog.AngleSpin.Enable TRUE
  449.             ParamDialog.AngleText.Enable TRUE
  450.             ParamDialog.PadSpin.Enable FALSE
  451.             ParamDialog.PadText.Enable FALSE
  452.             ParamDialog.PadPercentText.Enable FALSE
  453.  
  454.         CASE FILL_TYPE_SQUARE%
  455.             ParamDialog.HorizSpin.Enable TRUE
  456.             ParamDialog.HorizText.Enable TRUE
  457.             ParamDialog.HorizPercentText.Enable TRUE
  458.             ParamDialog.VertSpin.Enable TRUE
  459.             ParamDialog.VertText.Enable TRUE
  460.             ParamDialog.VertPercentText.Enable TRUE
  461.             ParamDialog.AngleSpin.Enable TRUE
  462.             ParamDialog.AngleText.Enable TRUE
  463.             ParamDialog.PadSpin.Enable TRUE
  464.             ParamDialog.PadText.Enable TRUE
  465.             ParamDialog.PadPercentText.Enable TRUE
  466.     END SELECT
  467.  
  468. END SUB
  469.  
  470. '********************************************************************
  471. '
  472. '    Name:    UpdateBlendButtons (dialog subroutine)
  473. '
  474. '    Action:    Updates which of the blend buttons appears
  475. '              to be pressed down and which appears to be
  476. '              pressed up based on the value of ColorBlendType.
  477. '
  478. '    Params:    None.  As this is intended to be a dialog function,
  479. '              it makes use of the variable global to ParamDialog:
  480. '              ColorBlendType.
  481. '
  482. '    Returns:    None.
  483. '
  484. '    Comments: None.
  485. '
  486. '********************************************************************
  487. SUB UpdateBlendButtons()
  488.  
  489.     ' Normally, all buttons should appear to be up.
  490.     Bitmaps$(1) = CurDir$ + COLOR_DIRECT_UNPRESSED_BITMAP$
  491.     Bitmaps$(2) = CurDir$ + COLOR_DIRECT_PRESSED_BITMAP$
  492.     Bitmaps$(3) = CurDir$ + COLOR_DIRECT_UNPRESSED_BITMAP$
  493.     ParamDialog.DirectButton.SetArray Bitmaps$
  494.     ParamDialog.DirectButton.SetStyle STYLE_IMAGE_CENTERED
  495.     Bitmaps$(1) = CurDir$ + COLOR_CCW_UNPRESSED_BITMAP$
  496.     Bitmaps$(2) = CurDir$ + COLOR_CCW_PRESSED_BITMAP$
  497.     Bitmaps$(3) = CurDir$ + COLOR_CCW_UNPRESSED_BITMAP$
  498.     ParamDialog.CCWButton.SetArray Bitmaps$
  499.     ParamDialog.CCWButton.SetStyle STYLE_IMAGE_CENTERED
  500.     Bitmaps$(1) = CurDir$ + COLOR_CW_UNPRESSED_BITMAP$
  501.     Bitmaps$(2) = CurDir$ + COLOR_CW_PRESSED_BITMAP$
  502.     Bitmaps$(3) = CurDir$ + COLOR_CW_UNPRESSED_BITMAP$
  503.     ParamDialog.CWButton.SetArray Bitmaps$
  504.     ParamDialog.CWButton.SetStyle STYLE_IMAGE_CENTERED
  505.  
  506.     ' Make the appropriate button look like it's pressed down.
  507.     SELECT CASE ColorBlendType%
  508.     
  509.         CASE DRAW_BLEND_DIRECT%
  510.             Bitmaps$(1) = CurDir$ + COLOR_DIRECT_PRESSED_BITMAP$
  511.             Bitmaps$(2) = CurDir$ + COLOR_DIRECT_UNPRESSED_BITMAP$
  512.             Bitmaps$(3) = CurDir$ + COLOR_DIRECT_PRESSED_BITMAP$
  513.             ParamDialog.DirectButton.SetArray Bitmaps$
  514.             
  515.         CASE DRAW_BLEND_RAINBOW_CCW%
  516.             Bitmaps$(1) = CurDir$ + COLOR_CCW_PRESSED_BITMAP$
  517.             Bitmaps$(2) = CurDir$ + COLOR_CCW_UNPRESSED_BITMAP$
  518.             Bitmaps$(3) = CurDir$ + COLOR_CCW_PRESSED_BITMAP$
  519.             ParamDialog.CCWButton.SetArray Bitmaps$
  520.             
  521.         CASE DRAW_BLEND_RAINBOW_CW%
  522.             Bitmaps$(1) = CurDir$ + COLOR_CW_PRESSED_BITMAP$
  523.             Bitmaps$(2) = CurDir$ + COLOR_CW_UNPRESSED_BITMAP$
  524.             Bitmaps$(3) = CurDir$ + COLOR_CW_PRESSED_BITMAP$
  525.             ParamDialog.CWButton.SetArray Bitmaps$
  526.             
  527.     END SELECT    
  528.  
  529. END SUB
  530.  
  531. '/////CHOICE DIALOG///////////////////////////////////////////////
  532.  
  533. ' What this dialog should return if the user wants to try again.
  534. GLOBAL CONST DIALOG_RETURN_TRY_AGAIN% = 3
  535.  
  536. BEGIN DIALOG OBJECT ChoiceDialog 299, 84, "Filled Outline Maker", SUB ChoiceDialogEventHandler
  537.     TEXT  11, 24, 281, 44, .Text1, "If you are satisfied with the effect, you can make it permanent by pressing the OK button.  You may also cancel the effect by pressing the Cancel button.  If you would like to go back and alter your previous choices, press the Try Again button."
  538.     TEXT  11, 8, 172, 11, .Text2, "The filled outline has been applied."
  539.     PUSHBUTTON  47, 60, 59, 13, .OkButton, "OK"
  540.     PUSHBUTTON  116, 60, 59, 13, .CancelButton, "Cancel"
  541.     PUSHBUTTON  186, 60, 59, 13, .TryAgainButton, "Try Again"
  542. END DIALOG
  543.  
  544. SUB ChoiceDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  545.  
  546.     SELECT CASE Event%
  547.         CASE EVENT_MOUSE_CLICK&
  548.             
  549.             SELECT CASE ControlID%
  550.                 CASE ChoiceDialog.OkButton.GetID()
  551.                     ChoiceDialog.CloseDialog DIALOG_RETURN_OK%
  552.  
  553.                 CASE ChoiceDialog.CancelButton.GetID()
  554.                     ChoiceDialog.CloseDialog DIALOG_RETURN_CANCEL%
  555.  
  556.                 CASE ChoiceDialog.TryAgainButton.GetID()
  557.                     ChoiceDialog.CloseDialog DIALOG_RETURN_TRY_AGAIN%
  558.     
  559.             END SELECT
  560.  
  561.     END SELECT
  562.  
  563. END SUB
  564.  
  565. '********************************************************************
  566. ' MAIN
  567. '
  568. '
  569. '********************************************************************
  570.  
  571. '/////LOCAL VARIABLES////////////////////////////////////////////////
  572. DIM MessageText AS STRING    ' Text to use in a MESSAGEBOX.
  573. DIM GenReturn AS LONG        ' The return value of various routines.
  574. DIM Valid AS BOOLEAN        ' Whether the user's input was valid.
  575. DIM IDOriginal AS LONG        ' The CDRStaticID of the user's
  576.                         ' originally selected object.
  577. DIM IDFirst AS LONG            ' The CDRStaticID of the duplicate.
  578. DIM IDMiddle AS LONG          ' The CDRStaticID of the duplicate's non-contoured part.                        
  579. DIM IDContour AS LONG        ' The CDRStaticID of the contoured object.
  580. DIM FillParam AS INTEGER        ' The first parameter of ApplyFountainFill.
  581. DIM XPos AS LONG            ' The x-coordinate of the original selection.
  582. DIM YPos AS LONG            ' The y-coordinate of the original selection.
  583.  
  584. ' Check to see if CorelDRAW's automation object is available.
  585. ON ERROR GOTO ErrorNoDrawHandler
  586. WITHOBJECT OBJECT_DRAW
  587.  
  588. ' Install the general error handler.
  589. ON ERROR GOTO MainErrorHandler
  590.  
  591. ' Retrieve the directory where the script was started.
  592. CurDir$ = GETCURRFOLDER()
  593. IF MID(CurDir$, LEN(CurDir$), 1) = "\" THEN
  594.     CurDir$ = LEFT(CurDir$, LEN(CurDir$) - 1)
  595. ENDIF
  596.  
  597. ' Check to see whether anything is selected in DRAW.
  598. IF NOT CheckForSelection() THEN
  599.     MessageText$ = "Please select an object in CorelDRAW " + \\
  600.                     "before running the Filled Outline Maker." + \\
  601.                     NL2 + "The filled outline effect will be applied " + \\
  602.                     "to the objects you select."
  603.     GenReturn& = MESSAGEBOX(MessageText$, TITLE_INFOBOX$, \\
  604.                             MB_OK_ONLY& OR MB_INFORMATION_ICON&)
  605.     STOP
  606. ENDIF
  607.  
  608. ' Check to see if we are allowed to apply contour to the object.
  609. IF NOT CheckForContour() THEN
  610.     MessageText$ = "Cannot add a filled outline to the currently " + \\
  611.                    "selected object." + NL2 + "Filled outlines " + \\
  612.                    "can only be applied to objects that can have " + \\
  613.                    "the Contour effect applied to them." + NL2 + \\
  614.                    "Please verify that the object you select can " + \\
  615.                    "be contoured and try again."
  616.     GenReturn& = MESSAGEBOX(MessageText$, TITLE_INFOBOX$, \\
  617.                             MB_OK_ONLY& OR MB_INFORMATION_ICON&)
  618.     STOP
  619. ENDIF
  620.  
  621. ' Show the dialog.
  622. Start:
  623. GenReturn& = DIALOG(ParamDialog)
  624. IF (GenReturn& = DIALOG_RETURN_OK%) THEN
  625.  
  626.     ' Retrieve the CDRStaticID of the selected object so we
  627.     ' can group it later.  Also get the location.
  628.     IDOriginal& = .GetObjectsCDRStaticID()
  629.     .GetPosition XPos&, YPos&    
  630.     
  631.     ' Make a duplicate that we can work with and that will be
  632.     ' safe for undo purposes.
  633.     .DuplicateObject
  634.     IDFirst& = .GetObjectsCDRStaticID()
  635.     .SetPosition XPos&, YPos&
  636.  
  637.     ' Remove the existing outline.
  638.     .ApplyOutline 0, 0, 0, 0, 0, 0, 0, -1, -1, FALSE, 0, 0, FALSE
  639.     
  640.     ' Apply an appropriately sized outside contour to a duplicate.
  641.     .DuplicateObject
  642.     IDMiddle& = .GetObjectsCDRStaticID()
  643.     .SetPosition XPos&, YPos&    
  644.     .OrderBackOne        
  645.     .ApplyContour 2, Width% * ConversionFactors!(ChosenUnit%), 1
  646.     
  647.     ' Separate the contoured object, so we can apply a fountain
  648.     ' fill to the contour part.
  649.     .Separate
  650.     .Ungroup    
  651.     .Trim
  652.     
  653.     ' Here we delete all but the outer contoured part.
  654.     '.SelectNextObject TRUE
  655.     .Ungroup
  656.     IDContour& = .GetObjectsCDRStaticID()
  657.     .SelectObjectOfCDRStaticID IDMiddle&
  658.     .DeleteObject
  659.     
  660.     ' Apply a fountain fill.
  661.     .SelectObjectOfCDRStaticID IDContour&
  662.     SELECT CASE FillType%
  663.         CASE FILL_TYPE_LINEAR%
  664.             FillParam% = DRAW_FOUNTAIN_LINEAR%
  665.             HorizOffset% = 0
  666.             VertOffset% = 0
  667.         CASE FILL_TYPE_RADIAL%
  668.             FillParam% = DRAW_FOUNTAIN_RADIAL%
  669.             Angle% = 0
  670.         CASE FILL_TYPE_CONICAL%
  671.             FillParam% = DRAW_FOUNTAIN_CONICAL%
  672.             Pad% = 0
  673.         CASE FILL_TYPE_SQUARE%
  674.             FillParam% = DRAW_FOUNTAIN_SQUARE%
  675.     END SELECT
  676.     
  677.     ' Set the start and end colors.
  678.     .StoreColor DRAW_COLORMODEL_RGB&, FromRed%, FromGreen%, FromBlue%, 0, 0, 0, 100, 0
  679.     .StoreColor DRAW_COLORMODEL_RGB&, ToRed%, ToGreen%, ToBlue%, 0, 0, 0, 100, 100
  680.     .ApplyFountainFill FillParam%, \\
  681.                      HorizOffset%, \\
  682.                      VertOffset%, \\
  683.                      Angle% * 10, \\
  684.                      Steps%, \\
  685.                      Pad%, \\
  686.                      ColorBlendType%, \\
  687.                      Midpoint
  688.  
  689.     ' Group the newly coloured 'outline' with the original selection.
  690.     .AppendObjectToSelection IDFirst&
  691.     .Group
  692.  
  693.     ' Give the user the chance to remove the fill if it is not
  694.     ' satisfactory.
  695.     GenReturn& = DIALOG(ChoiceDialog)
  696.     IF GenReturn& = DIALOG_RETURN_OK% THEN
  697.         ' The user is satisfied with the fill.  Delete the original.
  698.         .SelectObjectOfCDRStaticID IDOriginal&
  699.         .DeleteObject
  700.         STOP
  701.     ENDIF
  702.  
  703.     ' Otherwise, we should remove the filled object since it 
  704.     ' is not what the user wanted.
  705.     .DeleteObject
  706.     .SelectObjectOfCDRStaticID IDOriginal&
  707.     IF GenReturn& = DIALOG_RETURN_TRY_AGAIN% THEN
  708.         GOTO Start
  709.     ENDIF
  710.  
  711. ENDIF
  712.  
  713. VeryEnd:
  714.     STOP
  715.  
  716. MainErrorHandler:
  717.     IF ERRNUM > 0 THEN
  718.         ERRNUM = 0
  719.         MessageText$ = "A general error occurred during "
  720.         MessageText$ = MessageText$ + "processing." + NL2
  721.         MessageText$ = MessageText$ + "You may wish to try again."
  722.         GenReturn& = MESSAGEBOX(MessageText$, TITLE_ERRORBOX$, \\
  723.                                 MB_OK_ONLY& OR MB_EXCLAMATION_ICON&)
  724.     ENDIF
  725.     RESUME AT VeryEnd
  726.     
  727. ErrorNoDrawHandler:
  728.     ' Failed to create the automation object.
  729.     ERRNUM = 0
  730.     GenReturn = MESSAGEBOX( "Could not find CorelDRAW."+NL2+\\
  731.                         "If this error persists, you "+ \\
  732.                         "may need to re-install "+      \\
  733.                         "CorelDRAW.",                 \\
  734.                            TITLE_ERRORBOX,                 \\
  735.                         MB_OK_ONLY& OR MB_STOP_ICON& )
  736.     RESUME AT VeryEnd
  737.     STOP
  738.  
  739. '********************************************************************
  740. '
  741. '    Name:    IsInteger (function)
  742. '
  743. '    Action:    Determines if a given string contains an integer.
  744. '
  745. '    Params:    InString -- The string to test for integer-ness.
  746. '
  747. '    Returns:    TRUE if InString contains an integer (and would
  748. '              not cause an overflow if converted to an integer),
  749. '              and FALSE otherwise.
  750. '
  751. '    Comments: None.
  752. '
  753. '********************************************************************
  754. FUNCTION IsInteger( InString AS STRING ) AS BOOLEAN
  755.  
  756.     DIM ReturnVal AS BOOLEAN        ' The value to be returned.
  757.     DIM Converted AS INTEGER        ' The integer representation of
  758.                             ' InString.
  759.  
  760.     ' Set up an error handler to trap conversion errors.
  761.     ON ERROR GOTO II_ConversionError
  762.  
  763.     ' Attempt a conversion.
  764.     Converted% = CINT( InString )
  765.     ReturnVal = TRUE
  766.  
  767.     ExitPoint:
  768.         IsInteger = ReturnVal
  769.         EXIT FUNCTION
  770.  
  771. II_ConversionError:
  772.     ERRNUM = 0
  773.     ReturnVal = FALSE
  774.     RESUME AT ExitPoint
  775.  
  776. END FUNCTION
  777.  
  778. '********************************************************************
  779. '
  780. '    Name:    CheckForSelection (function)
  781. '
  782. '    Action:    Checks whether an object is currently selected
  783. '            in CorelDRAW.
  784. '
  785. '    Params:    None.
  786. '
  787. '    Returns:    TRUE if an object is currently selected;  FALSE
  788. '              otherwise.
  789. '
  790. '    Comments:    Never raises any errors. 
  791. '
  792. '********************************************************************
  793. FUNCTION CheckForSelection AS BOOLEAN
  794.  
  795.     DIM ObjType AS LONG     ' The currently selected object type.
  796.  
  797.     ON ERROR GOTO CFSNothingError
  798.     
  799.     ObjType& = .GetObjectType()
  800.     IF (ObjType& <= DRAW_OBJECT_TYPE_RESERVED) THEN
  801.         CheckForSelection = FALSE
  802.     ELSE
  803.         CheckForSelection = TRUE
  804.     ENDIF
  805.  
  806.  
  807.     ExitPart:
  808.         EXIT FUNCTION
  809.  
  810. CFSNothingError:
  811.     ERRNUM = 0
  812.     CheckForSelection = FALSE
  813.     RESUME AT ExitPart
  814.  
  815. END FUNCTION
  816.  
  817. '********************************************************************
  818. '
  819. '    Name:    CheckForContour (function)
  820. '
  821. '    Action:    Checks whether the currently selected object in
  822. '              CorelDRAW can have the contour effect applied to
  823. '              it.
  824. '
  825. '    Params:    None.
  826. '
  827. '    Returns:    FALSE if there is nothing selected in CorelDRAW or
  828. '              if there is something selected but it cannot have
  829. '              the contour effect applied to it.  TRUE otherwise.
  830. '
  831. '    Comments:    Never raises any errors. 
  832. '
  833. '********************************************************************
  834. FUNCTION CheckForContour AS BOOLEAN
  835.  
  836.     ON ERROR GOTO CFCNotContourableError
  837.  
  838.     ' We're just doing a simple contour, so omit most of the
  839.     ' optional parameters.
  840.     .ApplyContour 2, 25400, 1
  841.     
  842.     ' Undo what we just did.
  843.     .Undo
  844.     
  845.     ' We've been successful, so return TRUE.
  846.     CheckForContour = TRUE    
  847.     
  848.     ExitPart:
  849.         EXIT FUNCTION
  850.  
  851. CFCNotContourableError:
  852.     ERRNUM = 0
  853.     CheckForContour = FALSE
  854.     RESUME AT ExitPart
  855.  
  856. END FUNCTION
  857.  
  858. END WITHOBJECT
  859.  
  860.