home *** CD-ROM | disk | FTP | other *** search
/ CorelDRAW! 10 / cd10_pgrm.iso / Corel / Graphics10 / Draw / Scripts / Misc / neonwiz.csc < prev    next >
Encoding:
Text File  |  1999-03-29  |  31.5 KB  |  904 lines

  1. REM Neon Effect Wizard
  2. REM Applies an interactive neon effect.
  3.  
  4. '********************************************************************
  5. '   Script:    NeonWiz.csc
  6. '   Copyright 1996 Corel Corporation.  All rights reserved.
  7. '   Description: CorelDRAW script to apply a neon effect to the
  8. '                currently selected object or to text that the
  9. '                user enters.
  10. '********************************************************************
  11.  
  12. #addfol  "..\..\..\Scripts"
  13. #include "ScpConst.csi"
  14. #include "DrwConst.csi"
  15.  
  16. '/////FUNCTION & SUBROUTINE DECLARATIONS/////////////////////////////
  17. DECLARE FUNCTION CheckForSelection() AS BOOLEAN
  18. DECLARE FUNCTION ValidateInput(InText AS STRING) AS BOOLEAN
  19. DECLARE FUNCTION CheckSelectedForBlend() AS BOOLEAN
  20. DECLARE SUB CreateText(InText AS STRING, InFontName AS STRING, InPointSize AS INTEGER, \\
  21.                        InStrikeout AS BOOLEAN, InUnderline AS BOOLEAN, \\
  22.                        InBold AS BOOLEAN, InItalic AS BOOLEAN)
  23. DECLARE SUB ApplyEffect(InApplyCenterColor AS BOOLEAN, \\
  24.                     InRed AS INTEGER, InGreen AS INTEGER, InBlue AS INTEGER, \\
  25.                     InWidth AS INTEGER)
  26.  
  27. DECLARE FUNCTION CreateDC LIB "gdi32" (BYVAL lpDriverName AS STRING, \\
  28.                                        BYVAL lpDeviceName AS LONG, \\
  29.                                        BYVAL lpOutput AS LONG, \\
  30.                                        BYVAL lpInitData AS LONG) AS LONG ALIAS "CreateDCA"
  31. DECLARE FUNCTION GetDeviceCaps LIB "gdi32" (BYVAL hDC AS LONG, \\
  32.                                             BYVAL nIndex AS LONG) AS LONG ALIAS "GetDeviceCaps"
  33. DECLARE FUNCTION DeleteDC LIB "gdi32" (BYVAL hDC AS LONG) AS LONG ALIAS "DeleteDC"
  34. DECLARE FUNCTION GetNumberOfDisplayColors( ) AS LONG
  35.  
  36. '/////GLOBAL VARIABLES & CONSTANTS///////////////////////////////////
  37. GLOBAL CONST TITLE_ERRORBOX$      = "Neon Effect Wizard Error"
  38. GLOBAL CONST TITLE_INFOBOX$       = "Neon Effect Wizard Information"
  39. GLOBAL NL AS STRING         ' These must be declared as 
  40. GLOBAL NL2 AS STRING     ' variables, not constants, because
  41. NL$ = CHR(10) + CHR(13)    ' we cannot assign expressions
  42. NL2$ = NL + NL             ' to constants.
  43.  
  44. 'Constants for Dialog Return Values
  45. GLOBAL CONST DIALOG_RETURN_OK%     = 1
  46. GLOBAL CONST DIALOG_RETURN_CANCEL% = 2
  47. GLOBAL CONST DIALOG_RETURN_NEXT% = 3
  48. GLOBAL CONST DIALOG_RETURN_BACK% = 4
  49.  
  50. ' The bitmap graphic names.
  51. GLOBAL CONST BITMAP_PARAMSDIALOG_ORIGINAL$ = "\NeonOrig.bmp"
  52. GLOBAL CONST BITMAP_PARAMSDIALOG_BLUE$     = "\NeonBlue.bmp"
  53. GLOBAL CONST BITMAP_PARAMSDIALOG_BLACK$    = "\NeonBlak.bmp"
  54. GLOBAL BITMAP_INTRODIALOG AS STRING
  55. GLOBAL BITMAP_COLORDIALOG AS STRING
  56. GLOBAL BITMAP_WIDTHDIALOG AS STRING
  57. GLOBAL BITMAP_TEXTDIALOG AS STRING
  58. GLOBAL BITMAP_PARAMSDIALOG AS STRING
  59. DIM NumColors AS LONG
  60. NumColors& = GetNumberOfDisplayColors()
  61. IF NumColors& <= 256 THEN
  62.     BITMAP_INTRODIALOG$ = "\NeonB16.bmp"
  63.     BITMAP_COLORDIALOG$ = "\NeonB16.bmp"
  64.     BITMAP_WIDTHDIALOG$ = "\NeonB16.bmp"
  65.     BITMAP_TEXTDIALOG$ = "\NeonB16.bmp"
  66.     BITMAP_PARAMSDIALOG$ = "\NeonB16.bmp"
  67. ELSE
  68.     BITMAP_INTRODIALOG$ = "\NeonB.bmp"
  69.     BITMAP_COLORDIALOG$ = "\NeonB.bmp"
  70.     BITMAP_WIDTHDIALOG$ = "\NeonB.bmp"
  71.     BITMAP_TEXTDIALOG$ = "\NeonB.bmp"
  72.     BITMAP_PARAMSDIALOG$ = "\NeonB.bmp"
  73. ENDIF
  74.  
  75. ' The current directory when the script starts.
  76. GLOBAL CurDir AS STRING
  77.  
  78. ' The previous wizard page's position.
  79. GLOBAL LastPageX AS LONG
  80. GLOBAL LastPageY AS LONG
  81. LastPageX& = -1
  82. LastPageY& = -1
  83.  
  84. '/////INTRODUCTORY DIALOG//////////////////////////////////////////////
  85.  
  86. BEGIN DIALOG OBJECT IntroDialog 290, 180, "Neon Effect Wizard", SUB IntroDialogEventHandler
  87.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Next >"
  88.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Back"
  89.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  90.     TEXT  93, 10, 181, 20, .Text1, "Welcome to the Corel Neon Effect Wizard."
  91.     TEXT  94, 54, 189, 36, .Text2, "If you selected an object in CorelDRAW prior to running this wizard, the neon effect will be applied to that object.  Otherwise, you will be prompted to enter the text you want to generate with a neon look."
  92.     TEXT  93, 96, 187, 18, .Text3, "To begin creating your effect, click Next."
  93.     IMAGE  10, 10, 75, 130, .IntroImage
  94.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  95.     TEXT  93, 28, 189, 21, .Text4, "This wizard will guide you through the steps necessary to create an eye-catching neon effect."
  96. END DIALOG
  97.  
  98. SUB IntroDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  99.     IF Event% = EVENT_INITIALIZATION THEN         
  100.         IntroDialog.BackButton.Enable FALSE 
  101.     ENDIF
  102.     IF Event% = EVENT_MOUSE_CLICK THEN     ' Mouse click event.
  103.         SELECT CASE ControlID%
  104.             CASE IntroDialog.NextButton.GetID()
  105.                 LastPageX& = IntroDialog.GetLeftPosition()
  106.                 LastPageY& = IntroDialog.GetTopPosition()
  107.                 IntroDialog.CloseDialog DIALOG_RETURN_NEXT%
  108.             CASE IntroDialog.CancelButton.GetID()
  109.                 IntroDialog.CloseDialog DIALOG_RETURN_CANCEL%
  110.         END SELECT
  111.     ENDIF
  112.  
  113. END FUNCTION
  114.  
  115. '/////TEXT ENTRY DIALOG//////////////////////////////////////////////
  116. ' The text defaults.
  117. GLOBAL CONST NS_DEFAULT_TEXT_SIZE% = 24
  118. GLOBAL CONST NS_DEFAULT_TEXT_FONT$ = "Arial"
  119. GLOBAL CONST NS_DEFAULT_TEXT_STYLE$ = "Regular"
  120.  
  121. ' Variables needed for the dialog.
  122. GLOBAL EffectText AS STRING    ' The text entered by the user.
  123. GLOBAL FontName AS STRING    ' The selected font name.
  124. GLOBAL PointSize AS INTEGER    ' The selected font size.
  125. GLOBAL Red AS INTEGER        ' The selected font's red component.
  126. GLOBAL Green AS INTEGER        ' The selected font's green component.
  127. GLOBAL Blue AS INTEGER        ' The selected font's blue component.
  128. GLOBAL Weight AS INTEGER        ' The selected font's weight.
  129. GLOBAL StrikeOut AS BOOLEAN    ' The selected font's strikeout setting.
  130. GLOBAL Underline AS BOOLEAN    ' The selected font's underline setting.
  131. GLOBAL Bold AS BOOLEAN        ' The selected font's bold setting.
  132. GLOBAL Italic AS BOOLEAN        ' The selected font's italic setting.
  133.  
  134. ' Set up defaults.
  135. EffectText$ = ""
  136. FontName$ = NS_DEFAULT_TEXT_FONT$
  137. PointSize% = NS_DEFAULT_TEXT_SIZE%
  138. Red% = 0
  139. Green% = 0
  140. Blue% = 255
  141. Weight% = FONT_NORMAL&
  142. Strikeout = FALSE
  143. Underline = FALSE
  144. Bold = FALSE
  145. Italic = FALSE
  146.  
  147. BEGIN DIALOG OBJECT GetTextDialog 290, 180, "Neon Effect Wizard", SUB GetTextDialogEventHandler
  148.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Next >"
  149.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Back"
  150.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  151.     TEXT  94, 10, 181, 20, .Text1, "Please enter the text you wish to appear in neon, then press the Choose Font button to select a font and color:"
  152.     IMAGE  10, 10, 75, 130, .GetTextImage
  153.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  154.     PUSHBUTTON  223, 33, 56, 14, .FontButton, "Choose Font"
  155.     TEXTBOX  95, 33, 123, 14, .EffectTextBox
  156.     TEXT  113, 80, 166, 20, .Text3, "To do this, press Cancel, then select an object in CorelDRAW and run this wizard again."
  157.     TEXT  95, 56, 13, 11, .Text2, "Tip:"
  158.     TEXT  113, 57, 166, 19, .Text4, "You can apply this wizard to an object that already exists in your drawing, instead of to new text."
  159. END DIALOG
  160.  
  161. SUB GetTextDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  162.  
  163.     DIM FontReturn AS INTEGER    ' The return value of the font dialog.
  164.  
  165.     SELECT CASE Event%
  166.         CASE EVENT_INITIALIZATION&
  167.             GetTextDialog.EffectTextBox.SetText EffectText$
  168.  
  169.         CASE EVENT_MOUSE_CLICK&
  170.             SELECT CASE ControlID%
  171.                 CASE GetTextDialog.BackButton.GetID()
  172.                     LastPageX& = GetTextDialog.GetLeftPosition()
  173.                     LastPageY& = GetTextDialog.GetTopPosition()                
  174.                     EffectText$ = GetTextDialog.EffectTextBox.GetText()
  175.                     GetTextDialog.CloseDialog DIALOG_RETURN_BACK%
  176.                 CASE GetTextDialog.NextButton.GetID()
  177.                     LastPageX& = GetTextDialog.GetLeftPosition()
  178.                     LastPageY& = GetTextDialog.GetTopPosition()                
  179.                     EffectText$ = GetTextDialog.EffectTextBox.GetText()
  180.                     IF ValidateInput(EffectText$) THEN
  181.                         GetTextDialog.CloseDialog DIALOG_RETURN_NEXT%
  182.                     ENDIF
  183.                 CASE GetTextDialog.CancelButton.GetID()
  184.                     GetTextDialog.CloseDialog DIALOG_RETURN_CANCEL%
  185.                 CASE GetTextDialog.FontButton.GetID()
  186.     
  187.                     ' Display the font dialog box.
  188.                     FontReturn% = GetFont(FontName$,                 \\
  189.                                       PointSize%,                 \\
  190.                                       Weight%,                 \\
  191.                                       Italic,                 \\
  192.                                       Underline,                 \\
  193.                                       Strikeout,                 \\
  194.                                       Red%,                     \\
  195.                                       Green%,                     \\
  196.                                       Blue%) 
  197.                     IF NOT FontReturn% THEN
  198.                         ' The user pressed cancel.  We should not have
  199.                         ' to restore the defaults, but if GetFont
  200.                         ' empties FontName and Style, we must.
  201.                         IF (LEN(FontName$) = 0) THEN
  202.                             FontName$ = NS_DEFAULT_TEXT_FONT$
  203.                         ENDIF
  204.                         IF (PointSize% = 0) THEN
  205.                             PointSize% = NS_DEFAULT_TEXT_SIZE%
  206.                         ENDIF
  207.                     ENDIF
  208.                     ' Convert the weight value to either bold or non-bold.
  209.                     IF (Weight% > FONT_NORMAL&) THEN
  210.                         Bold = TRUE
  211.                     ELSE
  212.                         Bold = FALSE
  213.                     ENDIF
  214.                     
  215.         END SELECT
  216.     END SELECT
  217.  
  218. END FUNCTION
  219.  
  220. '/////EFFECTS PARAMETERS DIALOG//////////////////////////////////////
  221.  
  222. ' Variables needed for the dialog.
  223. GLOBAL ApplyCenterColor AS BOOLEAN    ' Whether to apply color to the
  224.                             ' center of the selection.
  225.  
  226. ' Set up defaults.
  227. ApplyCenterColor = TRUE
  228.  
  229. BEGIN DIALOG OBJECT GetParamsDialog 290, 180, "Neon Effect Wizard", SUB GetParamsDialogEventHandler
  230.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Next >"
  231.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Back"
  232.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  233.     TEXT  96, 10, 181, 31, .Text1, "You can customize the neon effect by choosing whether it should be applied to just the outline or to the entire object."
  234.     IMAGE  10, 10, 75, 130, .GetParamsImage
  235.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  236.     GROUPBOX  96, 77, 182, 63, .GroupBox2, "Apply neon effect to what?"
  237.     OPTIONGROUP .OptionGroup1
  238.         OPTIONBUTTON  196, 91, 67, 11, .OptionButtonEntire, "The entire object"
  239.         OPTIONBUTTON  113, 91, 67, 11, .OptionButtonOutline, "Just the outline"
  240.     IMAGE  107, 105, 75, 26, .ImageBlack
  241.     IMAGE  192, 105, 75, 26, .ImageBlue
  242.     IMAGE  136, 42, 75, 26, .ImageOrig
  243.     TEXT  97, 42, 35, 10, .Text2, "Example:"
  244. END DIALOG
  245.  
  246. SUB GetParamsDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  247.  
  248.     SELECT CASE Event%
  249.         CASE EVENT_INITIALIZATION&
  250.             IF ApplyCenterColor THEN
  251.                 GetParamsDialog.OptionButtonEntire.SetValue TRUE
  252.             ELSE
  253.                 GetParamsDialog.OptionButtonOutline.SetValue TRUE
  254.             ENDIF
  255.  
  256.         CASE EVENT_MOUSE_CLICK&
  257.             SELECT CASE ControlID%
  258.                 CASE GetParamsDialog.BackButton.GetID()
  259.                     LastPageX& = GetParamsDialog.GetLeftPosition()
  260.                     LastPageY& = GetParamsDialog.GetTopPosition()                
  261.                     IF GetParamsDialog.OptionButtonEntire.GetValue() = 1 THEN
  262.                         ApplyCenterColor = TRUE
  263.                     ELSE
  264.                         ApplyCenterColor = FALSE
  265.                     ENDIF
  266.                     GetParamsDialog.CloseDialog DIALOG_RETURN_BACK%
  267.  
  268.                 CASE GetParamsDialog.NextButton.GetID()
  269.                     LastPageX& = GetParamsDialog.GetLeftPosition()
  270.                     LastPageY& = GetParamsDialog.GetTopPosition()                
  271.                     IF GetParamsDialog.OptionButtonEntire.GetValue() = 1 THEN
  272.                         ApplyCenterColor = TRUE
  273.                     ELSE
  274.                         ApplyCenterColor = FALSE
  275.                     ENDIF
  276.                     GetParamsDialog.CloseDialog DIALOG_RETURN_NEXT%
  277.  
  278.                 CASE GetParamsDialog.CancelButton.GetID()
  279.                     STOP
  280.     
  281.         END SELECT
  282.     END SELECT
  283.  
  284. END SUB
  285.  
  286. '/////WIDTH SELECTION DIALOG/////////////////////////////////////////
  287.  
  288. ' Variables needed for the dialog.
  289. GLOBAL Width AS INTEGER    ' The width of the requested neon effect.
  290.  
  291. ' Set up defaults.
  292. Width% = 50
  293.  
  294. BEGIN DIALOG OBJECT GetWidthDialog 290, 180, "Neon Effect Wizard", SUB GetWidthDialogEventHandler
  295.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Finish"
  296.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Back"
  297.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  298.     TEXT  94, 9, 181, 23, .Text1, "You can use the slider below to adjust how wide your neon effect will be."
  299.     IMAGE  10, 10, 75, 130, .GetWidthImage
  300.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  301.     TEXT  113, 72, 166, 12, .Text3, "In most cases, the default will give you a nice effect."
  302.     TEXT  95, 72, 13, 11, .Text2, "Tip:"
  303.     HSLIDER 108, 31, 151, 16, .WidthSlider
  304.     TEXT  236, 49, 34, 11, .Text4, "Very Wide"
  305.     TEXT  104, 49, 25, 11, .Text5, "Narrow"
  306. END DIALOG
  307.  
  308. SUB GetWidthDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  309.  
  310.     SELECT CASE Event%
  311.         CASE EVENT_INITIALIZATION&
  312.             GetWidthDialog.WidthSlider.SetMinRange 5
  313.             GetWidthDialog.WidthSlider.SetMaxRange 100
  314.             GetWidthDialog.WidthSlider.SetIncrement 1
  315.             GetWidthDialog.WidthSlider.SetValue Width%
  316.  
  317.         CASE EVENT_MOUSE_CLICK&
  318.             SELECT CASE ControlID%
  319.                 CASE GetWidthDialog.BackButton.GetID()
  320.                     LastPageX& = GetWidthDialog.GetLeftPosition()
  321.                     LastPageY& = GetWidthDialog.GetTopPosition()                
  322.                     GetWidthDialog.CloseDialog DIALOG_RETURN_BACK%
  323.                 CASE GetWidthDialog.NextButton.GetID()
  324.                     LastPageX& = GetWidthDialog.GetLeftPosition()
  325.                     LastPageY& = GetWidthDialog.GetTopPosition()                
  326.                     GetWidthDialog.CloseDialog DIALOG_RETURN_NEXT%
  327.                 CASE GetWidthDialog.CancelButton.GetID()
  328.                     GetWidthDialog.CloseDialog DIALOG_RETURN_CANCEL%
  329.                 CASE GetWidthDialog.WidthSlider.GetID()
  330.                     Width% = GetWidthDialog.WidthSlider.GetValue()
  331.         END SELECT
  332.     END SELECT
  333.  
  334. END FUNCTION
  335.  
  336. '/////COLOR SELECTION DIALOG/////////////////////////////////////////
  337.  
  338. BEGIN DIALOG OBJECT GetColorDialog 290, 180, "Neon Effect Wizard", SUB GetColorDialogEventHandler
  339.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Next >"
  340.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Back"
  341.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  342.     TEXT  94, 9, 181, 23, .Text1, "Your neon effect will be applied to the currently selected object in CorelDRAW."
  343.     IMAGE  10, 10, 75, 130, .GetColorImage
  344.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  345.     PUSHBUTTON  154, 54, 56, 14, .ColorButton, "Choose Color"
  346.     TEXT  113, 85, 166, 28, .Text3, "If you do not want to apply the neon effect to the object you have selected in CorelDRAW, you can apply it to new text of your choice."
  347.     TEXT  95, 85, 13, 11, .Text2, "Tip:"
  348.     TEXT  113, 120, 166, 20, .Text4, "To do this, press Cancel, deselect the current object in CorelDRAW, then run this wizard again."
  349.     TEXT  94, 32, 181, 19, .Text5, "You can select the color you want for your neon effect by pressing the Choose Color button below."
  350. END DIALOG
  351.  
  352. SUB GetColorDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  353.  
  354.     SELECT CASE Event%
  355.         CASE EVENT_MOUSE_CLICK&
  356.             SELECT CASE ControlID%
  357.                 CASE GetColorDialog.BackButton.GetID()
  358.                     LastPageX& = GetColorDialog.GetLeftPosition()
  359.                     LastPageY& = GetColorDialog.GetTopPosition()                
  360.                     GetColorDialog.CloseDialog DIALOG_RETURN_BACK%
  361.                 CASE GetColorDialog.NextButton.GetID()
  362.                     LastPageX& = GetColorDialog.GetLeftPosition()
  363.                     LastPageY& = GetColorDialog.GetTopPosition()                
  364.                     GetColorDialog.CloseDialog DIALOG_RETURN_NEXT%
  365.                 CASE GetColorDialog.CancelButton.GetID()
  366.                     GetColorDialog.CloseDialog DIALOG_RETURN_CANCEL%
  367.                 CASE GetColorDialog.ColorButton.GetID()
  368.                     GetColor Red%, Green%, Blue%
  369.         END SELECT
  370.     END SELECT
  371.  
  372. END FUNCTION
  373.  
  374. '********************************************************************
  375. ' MAIN
  376. '
  377. '
  378. '********************************************************************
  379.  
  380. '/////LOCAL VARIABLES////////////////////////////////////////////////
  381. DIM MessageText AS STRING    ' Text to use in a MESSAGEBOX.
  382. DIM GenReturn AS INTEGER        ' The return value of various routines.
  383. DIM Selection AS BOOLEAN        ' Whether any object is selected in draw.
  384. DIM Valid AS BOOLEAN        ' Whether the user's input was valid.
  385. DIM CurStep AS INTEGER        ' The user's current dialog number.
  386. DIM FirstTime AS BOOLEAN        ' Is this the user's first time through?
  387.  
  388. ' Retrieve the directory where the script was started.
  389. CurDir$ = GETCURRFOLDER()
  390. IF MID(CurDir$, LEN(CurDir$), 1) = "\" THEN
  391.     CurDir$ = LEFT(CurDir$, LEN(CurDir$) - 1)
  392. ENDIF
  393.  
  394. ' Check to see if CorelDRAW's automation object is available.
  395. ON ERROR RESUME NEXT
  396. WITHOBJECT OBJECT_DRAW
  397.     IF (ERRNUM > 0) THEN
  398.         ' Failed to create the automation object.
  399.         ERRNUM = 0
  400.         GenReturn% = MESSAGEBOX( "Could not find CorelDRAW."+NL2+\\
  401.                              "If this error persists, you "+ \\
  402.                              "may need to re-install "+      \\
  403.                              "CorelDRAW.",                 \\
  404.                                 TITLE_ERRORBOX,             \\
  405.                              MB_OK_ONLY )
  406.         STOP
  407.     ENDIF
  408.  
  409. ' Set up a general error handler.
  410. ON ERROR GOTO MainErrorHandler
  411.  
  412. CONST NS_FINISH%         = 0
  413. CONST NS_INTRODIALOG%     = 1
  414. CONST NS_GETTEXTDIALOG%   = 2
  415. CONST NS_GETPARAMSDIALOG% = 3
  416. CONST NS_GETCOLORDIALOG%  = 4
  417. CONST NS_GETWIDTHDIALOG%  = 5
  418.  
  419. ' Loop, displaying dialogs in the required order.
  420. CurStep% = NS_INTRODIALOG%
  421. FirstTime = TRUE
  422. WHILE (CurStep% <> NS_FINISH%)
  423.  
  424.     SELECT CASE CurStep%
  425.         CASE NS_INTRODIALOG
  426.             IF (LastPageX& <> -1) THEN
  427.                 IntroDialog.Move LastPageX&, LastPageY&
  428.             ENDIF        
  429.             IntroDialog.IntroImage.SetImage CurDir$ + BITMAP_INTRODIALOG$
  430.             IntroDialog.IntroImage.SetStyle STYLE_SUNKEN
  431.             IntroDialog.IntroImage.SetStyle STYLE_IMAGE_CENTERED
  432.             IntroDialog.SetStyle STYLE_NOMINIMIZEBOX
  433.             GenReturn% = DIALOG(IntroDialog)
  434.             SELECT CASE GenReturn%
  435.                 CASE DIALOG_RETURN_NEXT%
  436.                     IF FirstTime THEN
  437.                         ' Check whether anything is selected.
  438.                         Selection = CheckForSelection() 
  439.                     ENDIF
  440.                     IF Selection AND FirstTime THEN
  441.                     
  442.                         IF NOT CheckSelectedForBlend() THEN
  443.                     
  444.                             GenReturn = MESSAGEBOX( "Cannot add a neon effect to the "+\\
  445.                                                 "currently selected object(s)."+NL2+\\
  446.                                                 "This wizard only supports those "+\\
  447.                                                 "objects which are supported by " +\\
  448.                                                 "the Blend tool.  For example, "  +\\
  449.                                                 "blocks of paragraph "            +\\
  450.                                                 "text, bitmaps, OLE objects, and "+\\
  451.                                                 "groups containing such objects " +\\
  452.                                                 "are not supported.  Artistic "   +\\
  453.                                                 "text, however, is supported."+NL2+\\
  454.                                                 "If you have selected several "+   \\
  455.                                                 "objects, you should group them "+ \\
  456.                                                  "before running this wizard.",     \\
  457.                                                 TITLE_ERRORBOX,                    \\
  458.                                                 MB_OK_ONLY )
  459.                             STOP        
  460.                     
  461.                         ENDIF
  462.                         CurStep% = NS_GETCOLORDIALOG%
  463.                     
  464.                     ELSEIF Selection THEN
  465.                         CurStep% = NS_GETCOLORDIALOG%
  466.  
  467.                     ELSE 
  468.                         CurStep% = NS_GETTEXTDIALOG%
  469.                     ENDIF
  470.                     
  471.                 CASE ELSE
  472.                     STOP
  473.             END SELECT
  474.  
  475.         CASE NS_GETTEXTDIALOG%
  476.             GetTextDialog.Move LastPageX&, LastPageY&
  477.             FirstTime = FALSE
  478.             GetTextDialog.GetTextImage.SetImage CurDir$ + BITMAP_TEXTDIALOG$
  479.             GetTextDialog.GetTextImage.SetStyle STYLE_SUNKEN
  480.             GetTextDialog.GetTextImage.SetStyle STYLE_IMAGE_CENTERED
  481.             GetTextDialog.SetStyle STYLE_NOMINIMIZEBOX
  482.             GenReturn% = DIALOG(GetTextDialog)
  483.             SELECT CASE GenReturn%
  484.  
  485.                 CASE DIALOG_RETURN_NEXT%
  486.                     CurStep% = NS_GETPARAMSDIALOG%                    
  487.                 CASE DIALOG_RETURN_BACK%
  488.                     CurStep% = NS_INTRODIALOG%
  489.                 CASE ELSE
  490.                     STOP
  491.  
  492.             END SELECT
  493.  
  494.         CASE NS_GETPARAMSDIALOG%
  495.             GetParamsDialog.Move LastPageX&, LastPageY&
  496.             GetParamsDialog.GetParamsImage.SetImage CurDir$ + BITMAP_PARAMSDIALOG$
  497.             GetParamsDialog.ImageBlack.SetImage CurDir$ + BITMAP_PARAMSDIALOG_BLACK
  498.             GetParamsDialog.ImageOrig.SetImage CurDir$ + BITMAP_PARAMSDIALOG_ORIGINAL
  499.             GetParamsDialog.ImageBlue.SetImage CurDir$ + BITMAP_PARAMSDIALOG_BLUE
  500.             GetParamsDialog.GetParamsImage.SetStyle STYLE_SUNKEN
  501.             GetParamsDialog.GetParamsImage.SetStyle STYLE_IMAGE_CENTERED
  502.             GetParamsDialog.ImageBlack.SetStyle STYLE_IMAGE_CENTERED
  503.             GetParamsDialog.ImageBlack.SetStyle STYLE_SUNKEN
  504.             GetParamsDialog.ImageOrig.SetStyle STYLE_IMAGE_CENTERED
  505.             GetParamsDialog.ImageOrig.SetStyle STYLE_SUNKEN
  506.             GetParamsDialog.ImageBlue.SetStyle STYLE_IMAGE_CENTERED
  507.             GetParamsDialog.ImageBlue.SetStyle STYLE_SUNKEN
  508.             GetParamsDialog.SetStyle STYLE_NOMINIMIZEBOX
  509.             GenReturn% = DIALOG(GetParamsDialog)
  510.             SELECT CASE GenReturn%
  511.  
  512.                 CASE DIALOG_RETURN_NEXT%
  513.                     CurStep% = NS_GETWIDTHDIALOG%                    
  514.                 CASE DIALOG_RETURN_BACK%
  515.                     IF Selection THEN
  516.                         CurStep% = NS_GETCOLORDIALOG%
  517.                     ELSE
  518.                         CurStep% = NS_GETTEXTDIALOG%
  519.                     ENDIF
  520.                 CASE ELSE
  521.                     STOP
  522.  
  523.             END SELECT
  524.  
  525.         CASE NS_GETCOLORDIALOG%
  526.             GetColorDialog.Move LastPageX&, LastPageY&
  527.             FirstTime = FALSE
  528.             GetColorDialog.GetColorImage.SetImage CurDir$ + BITMAP_COLORDIALOG$
  529.             GetColorDialog.GetColorImage.SetStyle STYLE_SUNKEN
  530.             GetColorDialog.GetColorImage.SetStyle STYLE_IMAGE_CENTERED
  531.             GetColorDialog.SetStyle STYLE_NOMINIMIZEBOX
  532.             GenReturn% = DIALOG(GetColorDialog)
  533.             SELECT CASE GenReturn%
  534.  
  535.                 CASE DIALOG_RETURN_NEXT%
  536.                     CurStep% = NS_GETPARAMSDIALOG%                
  537.                 CASE DIALOG_RETURN_BACK%
  538.                     CurStep% = NS_INTRODIALOG%
  539.                 CASE ELSE
  540.                     STOP
  541.  
  542.             END SELECT
  543.         
  544.         CASE NS_GETWIDTHDIALOG%
  545.             GetWidthDialog.Move LastPageX&, LastPageY&            
  546.             GetWidthDialog.GetWidthImage.SetImage CurDir$ + BITMAP_WIDTHDIALOG$
  547.             GetWidthDialog.GetWidthImage.SetStyle STYLE_SUNKEN
  548.             GetWidthDialog.GetWidthImage.SetStyle STYLE_IMAGE_CENTERED
  549.             GetWidthDialog.SetStyle STYLE_NOMINIMIZEBOX
  550.             GenReturn% = DIALOG(GetWidthDialog)
  551.             SELECT CASE GenReturn%
  552.  
  553.                 CASE DIALOG_RETURN_NEXT%
  554.                     CurStep% = NS_FINISH%                
  555.                 CASE DIALOG_RETURN_BACK%
  556.                     CurStep% = NS_GETPARAMSDIALOG%
  557.                 CASE ELSE
  558.                     STOP
  559.  
  560.             END SELECT
  561.     
  562.     END SELECT
  563.  
  564. WEND
  565.  
  566. ' Create the user's text, if needed.
  567. IF NOT Selection THEN
  568.     CreateText EffectText$, FontName$, PointSize%, Strikeout, Underline, Bold, Italic
  569. ENDIF
  570.  
  571. ' Finish off script execution by applying the neon effect.
  572. ApplyEffect ApplyCenterColor, Red%, Green%, Blue%, Width%
  573. STOP
  574.  
  575. MainErrorHandler:
  576.     MessageText$ = "A general error occurred during the "
  577.     MessageText$ = MessageText$ + "wizard's processing." + NL2
  578.     MessageText$ = MessageText$ + "You may wish to try again."
  579.     GenReturn% = MESSAGEBOX(MessageText$, TITLE_ERRORBOX$, \\
  580.                             MB_OK_ONLY& OR MB_EXCLAMATION_ICON&)
  581.     STOP
  582.  
  583. '********************************************************************
  584. '
  585. '    Name:    CheckForSelection (function)
  586. '
  587. '    Action:    Checks whether an object is currently selected
  588. '            in CorelDRAW.
  589. '
  590. '    Params:    None.
  591. '
  592. '    Returns:    TRUE if an object is currently selected;  FALSE
  593. '              otherwise.
  594. '
  595. '    Comments:    Never raises any errors. 
  596. '
  597. '********************************************************************
  598. FUNCTION CheckForSelection AS BOOLEAN
  599.  
  600.     DIM ObjType AS LONG     ' The currently selected object type.
  601.  
  602.     ON ERROR RESUME NEXT
  603.     
  604.     ObjType& = .GetObjectType()
  605.     IF (ObjType& <= DRAW_OBJECT_TYPE_RESERVED) OR (ERRNUM > 0) THEN
  606.         ERRNUM = 0
  607.         CheckForSelection = FALSE
  608.     ELSE
  609.         CheckForSelection = TRUE
  610.     ENDIF
  611.  
  612. END FUNCTION
  613.  
  614. '********************************************************************
  615. '
  616. '    Name:    CheckSelectedForBlend (function)
  617. '
  618. '    Action:    Checks whether the currently selected object in
  619. '              CorelDRAW can have a blend operation applied to it.
  620. '
  621. '    Params:    None.
  622. '
  623. '    Returns:    FALSE if no object is selected in CorelDRAW.  If an
  624. '              object is selected, returns TRUE if it can have a
  625. '              blend applied to it and FALSE otherwise.
  626. '
  627. '    Comments:    None.
  628. '
  629. '********************************************************************
  630. FUNCTION CheckSelectedForBlend AS BOOLEAN
  631.  
  632.     DIM ReturnVal AS BOOLEAN    ' The return value of this function.
  633.  
  634.     ' Make sure an object was selected.
  635.     IF NOT CheckForSelection() THEN
  636.         CheckSelectedForBlend = False
  637.         EXIT FUNCTION
  638.     ENDIF
  639.  
  640.     ' Prepare for a blend by making a duplicate of the
  641.     ' selected object.
  642.     .StartOfRecording 
  643.     .SuppressPainting FALSE
  644.     .RecorderStorePreselectedObjects FALSE
  645.     .RecorderSelectObjectByIndex TRUE, 1
  646.     .DuplicateObject 
  647.     .RecorderSelectObjectByIndex TRUE, 2
  648.     
  649.     ' Try to apply a simple blend.  If this fails, then the
  650.     ' object is not blendable.
  651.     ON ERROR GOTO ErrorInBlending
  652.     ReturnVal = TRUE
  653.     .RecorderSelectObjectsByIndex TRUE, 1, 2, -1, -1, -1
  654.     .ApplyBlend TRUE, 1, 0, FALSE, 0, FALSE, FALSE, 0, 0, 0, TRUE, TRUE, FALSE, FALSE, 0, 0, 0, 0
  655.     .Undo
  656.     .Undo
  657.     .ResumePainting 
  658.     .EndOfRecording 
  659.     CheckSelectedForBlend = ReturnVal
  660.     EXIT FUNCTION
  661.  
  662.     ErrorInBlending:
  663.         ERRNUM = 0
  664.         ReturnVal = FALSE
  665.         RESUME NEXT
  666.  
  667. END FUNCTION
  668.  
  669. '********************************************************************
  670. '
  671. '    Name:    ValidateInput (function)
  672. '
  673. '    Action:    Makes sure the user entered some text.
  674. '
  675. '    Params:    EffectText
  676. '
  677. '    Returns:    TRUE if EffectText is empty, FALSE otherwise.
  678. '
  679. '    Comments:    None.
  680. '
  681. '********************************************************************
  682. FUNCTION ValidateInput(InText AS STRING) AS BOOLEAN
  683.  
  684.     DIM ReturnVal% AS INTEGER    ' The return value of MESSAGEBOX.
  685.  
  686.     IF (LEN(InText$) <= 0) THEN
  687.         ReturnVal% = MESSAGEBOX("You must enter some text or "+\\
  688.                             "press Cancel.", TITLE_ERRORBOX$,    \\
  689.                                   MB_OK_ONLY)    
  690.         ValidateInput = FALSE
  691.     ELSE
  692.         ValidateInput = TRUE
  693.     ENDIF
  694.  
  695. END FUNCTION
  696.  
  697. '********************************************************************
  698. '
  699. '    Name:    CreateText (subroutine)
  700. '
  701. '    Action:    Creates a text string in CorelDRAW with a set of given
  702. '              parameters related to font, color, etc.
  703. '
  704. '    Params:    InText - The text to create.
  705. '            InFontName - The font to use.
  706. '            InPointSize - The font's point size.
  707. '            InStrikeout - Use strikeout?
  708. '            InUnderline - Use underline?
  709. '            InBold      - Use bold?
  710. '            InItalic    - Use italic?
  711. '
  712. '    Returns:    None.
  713. '
  714. '    Comments:    None.
  715. '
  716. '********************************************************************
  717. SUB CreateText(InText AS STRING, InFontName AS STRING, InPointSize AS INTEGER, \\
  718.                        InStrikeout AS BOOLEAN, InUnderline AS BOOLEAN, \\
  719.                        InBold AS BOOLEAN, InItalic AS BOOLEAN)
  720.  
  721.     DIM DrawStyleCode AS INTEGER ' The font style to send to DRAW.
  722.     DIM DrawPointSize AS INTEGER ' The font size to send to DRAW.
  723.     DIM DrawUnderline AS INTEGER ' The underline code to send to DRAW.
  724.     DIM DrawStrikeout AS INTEGER ' The strikeout code to send to DRAW.
  725.  
  726.     ' Create the user's text.
  727.     .CreateArtisticText InText$, 0, 0
  728.  
  729.     ' Determine the settings to send to DRAW.
  730.     IF InBold AND InItalic THEN
  731.         DrawStyleCode% = DRAW_FONT_STYLE_BOLD_ITALIC%
  732.     ELSEIF Bold THEN
  733.         DrawStyleCode% = DRAW_FONT_STYLE_BOLD%
  734.     ELSEIF Italic THEN
  735.         DrawStyleCode% = DRAW_FONT_STYLE_NORMAL_ITALIC%
  736.     ELSE
  737.         DrawStyleCode% = DRAW_FONT_STYLE_NORMAL%
  738.     ENDIF 
  739.     DrawPointSize% = InPointSize% * 10
  740.     IF InUnderline THEN
  741.         DrawUnderline% = DRAW_FONT_UNDERLINE_SINGLE_THICK%
  742.     ELSE
  743.         DrawUnderline% = DRAW_FONT_UNDERLINE_NONE%
  744.     ENDIF
  745.     IF InStrikeout THEN
  746.         DrawStrikeout% = DRAW_FONT_STRIKEOUT_SINGLE_THICK%
  747.     ELSE
  748.         DrawStrikeout% = DRAW_FONT_STRIKEOUT_NONE%
  749.     ENDIF
  750.  
  751.     ' Apply the formatting.
  752.     .SetCharacterAttributes 0, \\
  753.                         30000, \\
  754.                         InFontName$, \\
  755.                         DrawStyleCode%, \\
  756.                         DrawPointSize%, \\
  757.                         DrawUnderline%, \\
  758.                         DRAW_FONT_OVERLINE_NONE%, \\
  759.                         DrawStrikeout%, \\
  760.                         DRAW_FONT_PLACEMENT_NORMAL%, \\
  761.                         0,    \\ 
  762.                         1000, \\ 
  763.                         1000, \\
  764.                         DRAW_FONT_ALIGNMENT_NONE%
  765.  
  766. END SUB
  767.  
  768. '********************************************************************
  769. '
  770. '    Name:    ApplyEffect (subroutine)
  771. '
  772. '    Action:    Applies a neon effect to the currently selected
  773. '            object(s) in CorelDRAW.
  774. '
  775. '    Params:    InApplyCenterColor - Should we apply the neon
  776. '                             color to the whole object?
  777. '            InRed - The red component of the desired color.
  778. '            InGreen - The green component of the desired color.
  779. '            InBlue - The blue component of the desired color.
  780. '            InWidth - The width of the neon effect desired.
  781. '
  782. '    Returns:    None.
  783. '
  784. '    Comments:    There must be currently selected object(s) in
  785. '              CorelDRAW when this routine is called, and
  786. '              they must support blending.
  787. '
  788. '********************************************************************
  789. SUB ApplyEffect(InApplyCenterColor AS BOOLEAN, \\
  790.              InRed AS INTEGER, InGreen AS INTEGER, InBlue AS INTEGER, \\
  791.              InWidth AS INTEGER)
  792.  
  793.     CONST NeonF! = 0.4        ' The color darkening factor for the neon edges.
  794.     CONST XIdeal& = 991578    ' The ideal object width (x-direction).
  795.     CONST YIdeal& = 286869    ' The ideal object height (y-direction).
  796.     CONST BigOIdeal& = 84582    ' The big outline to use if we have an ideal object.
  797.     CONST LittleOIdeal& = 7112    ' The little outline to use if we have an ideal object.
  798.  
  799.     DIM Proportion AS SINGLE    ' The multiplicative factor relative to the ideal.
  800.     DIM ObjX AS LONG        ' The width of the current CorelDRAW selection.
  801.     DIM ObjY AS LONG        ' The height of the current CorelDRAW selection.
  802.     DIM WidthAdj AS SINGLE    ' The multiplicative factor to adjust for the user's
  803.                         ' width selection.
  804.     DIM XPos AS LONG        ' The x-coordinate of the current CorelDRAW selection.
  805.     DIM YPos AS LONG        ' The y-coordinate of the current CorelDRAW selection.
  806.  
  807.     ' Calculate the proportionality constant.  This is so that we do
  808.     ' not apply a thick outline to very small objects.
  809.     .GetSize ObjX&, ObjY&
  810.     IF ObjX > ObjY THEN
  811.         Proportion! = ObjY& / YIdeal&
  812.     ELSE
  813.         Proportion! = ObjX& / XIdeal&
  814.     ENDIF        
  815.  
  816.     ' Calculate the width adjustment based on the user's selection.
  817.     WidthAdj! = (InWidth% * 2) /100
  818.  
  819.     ' Apply the neon effect.
  820.      .StartOfRecording 
  821.      .SuppressPainting FALSE
  822.      .RecorderStorePreselectedObjects FALSE
  823.      .RecorderSelectObjectByIndex TRUE, 1
  824.     .ApplyOutline 0, 0, 0, 0, 0, 0, 0, -1, -1, FALSE, 0, 0, FALSE
  825.     .RecorderSelectObjectByIndex TRUE, 1
  826.     .ApplyOutline CLNG(BigOIdeal& * Proportion! * WidthAdj!), 1, 1, 1, 100, -900, 0, -1, -1, FALSE, 2, 0, TRUE
  827.     .StoreColor DRAW_COLORMODEL_RGB&, CINT(InRed% * NeonF!), \\
  828.               CINT(InGreen%*NeonF!), CINT(InBlue%*NeonF!), 0
  829.     .SetOutlineColor
  830.     .RecorderSelectObjectByIndex TRUE, 1
  831.     .GetPosition XPos&, YPos&
  832.     .DuplicateObject 
  833.     .SetPosition XPos&, YPos&
  834.      .RecorderSelectObjectByIndex TRUE, 2
  835.     .ApplyOutline 0, 0, 0, 0, 0, 0, 0, -1, -1, FALSE, 0, 0, FALSE
  836.     .RecorderSelectObjectByIndex TRUE, 2
  837.      .ApplyOutline CLNG(LittleOIdeal& * Proportion! * WidthAdj!), 1, 1, 1, 100, -900, 0, -1, -1, FALSE, 2, 0, TRUE
  838.      .StoreColor DRAW_COLORMODEL_RGB&, InRed%, InGreen%, InBlue%, 0
  839.      .SetOutlineColor
  840.     .RecorderSelectObjectsByIndex TRUE, 1, 2, -1, -1, -1
  841.      .ApplyBlend TRUE, 20, 0, FALSE, 0, FALSE, FALSE, 0, 0, 0
  842.      .ResumePainting 
  843.     .EndOfRecording 
  844.  
  845.     ' If we are neon-ing the whole object, apply a uniform fill in the neon color.
  846.     IF InApplyCenterColor THEN
  847.         .StoreColor DRAW_COLORMODEL_RGB&, InRed%, InGreen%, InBlue%, 0
  848.         .ApplyUniformFillColor
  849.     ENDIF
  850.  
  851. END SUB
  852.  
  853. '********************************************************************
  854. '
  855. '    Name:    GetNumberOfDisplayColors (function)
  856. '
  857. '    Action:    Returns the number of colors the user's screen
  858. '              currently supports.
  859. '
  860. '    Params:    None.  
  861. '
  862. '    Returns:    None.
  863. '
  864. '    Comments:    To avoid overflows, this routine never returns
  865. '              a number of colors greater than 16777216.  If there
  866. '              are more colors, it returns this maximum.
  867. '
  868. '********************************************************************
  869. FUNCTION GetNumberOfDisplayColors( ) AS LONG
  870.  
  871.     ' Constants to send to GetDeviceCaps.
  872.     CONST BITSPIXEL& = 12    ' Gets the number of color bits per pixel.
  873.     CONST PLANES& = 14        ' Gets the number of color planes.
  874.     
  875.     DIM hDC AS LONG        ' A display DC to query.
  876.     DIM NumColors AS SINGLE    ' The retrieved number of colors.    
  877.     DIM NumPlanes AS LONG    ' The retrieved number of planes.
  878.     DIM NumBitsPixel AS LONG ' The retrieved number of bits per pixel.
  879.     DIM RetVal AS LONG        
  880.     
  881.     ' Create a DC, then query it for the number of colors.
  882.     hDC& = CreateDC("DISPLAY", 0, 0, 0)
  883.     NumPlanes& = GetDeviceCaps(hDC, Planes&)
  884.     NumBitsPixel& = GetDeviceCaps(hDC, BitsPixel&)
  885.     NumColors! = CSNG(2) ^ CSNG(CSNG(NumPlanes&) * CSNG(NumBitsPixel&))
  886.     RetVal& = DeleteDC(hDC)
  887.     
  888.     ' To avoid overflows with really high color displays, the
  889.     ' maximum will be 24 bit color.
  890.     IF NumColors! > 16777216 THEN
  891.         GetNumberOfDisplayColors = 16777216
  892.     ELSE
  893.         GetNumberOfDisplayColors = NumColors!
  894.     ENDIF
  895.     
  896. END FUNCTION
  897.  
  898. END WITHOBJECT
  899.  
  900.