PDA

View Full Version : [CC3-TIP] Building Hotspots in a macro



DaltonSpence
11-21-2006, 10:18 AM
The macro below draws a hotspot button at a specified location. I use it to create a control panel for multilevel floorplans that use layers for levels. The following variables must be set before running it:
"pButtonL" and "pButtonH": point variables containing lower left and upper right corners of the hotspot button,
"nCurLvl": a numeric variable containing the current structure level number.

MACRO ML_DRAWBTN
sheet MAP BORDER
setlayer BUTTONS
color 15
fstyle Hollow
box pButtonL pButtonHThe box drawn above will be the button's visible frame.
gl sMacCmd ~gn nCur
apnd sMacCmd Lvl
apnd sMacCmd;
apnd sMacCmd nCurLvl
apnd sMacCmd;
apnd sMacCmd GoCur
apnd sMacCmd Lvl
apnd sMacCmd;
color 2
tspech 1
actionm sMacCmd
pButtonL pButtonH"GoCurLvl" is a macro that converts the level number into a layer name which it then makes current. Note how I split the variable and macro names while building the macro command string (sMacCmd) so they don't expand and terminate the string with a delimiter.
sheet TEXT
color 15
getx vX1 pButtonL
gety vY1 pButtonL
getx vX2 pButtonH
gety vY2 pButtonH
gp pButtonC (vX1+vX2)/2,(vY1+vY2)/2
tspech (vY2-vY1)/2
textm nCurLvl
pButtonCThe above code finds the center of the hotspot and places the level number there as a text label. On my maps the TEXT sheet is above the MAP BORDER one. Note how the text height is half the button height.
sheet MAP BORDER
GoCurLvl
color 4
fstyle Solid
box pButtonL pButtonH
ENDMThe above code draws a yellow box that "backlights" the button of the currently active level.

--

Dalton "who hopes that this idea stays clever" Spence

Arcana
11-21-2006, 10:28 AM
Oh now that is just cool...Can't wait to check it out when I get home.

RPMiller
11-21-2006, 11:51 AM
Very nice indeed Dalton! I'm assuming that the dimensions are set with button clicks? I'm not on my CC machine, but will be testing it over the holiday for sure. Thanks for sharing it.

DaltonSpence
11-21-2006, 02:10 PM
At the moment it's used by a parent macro that calculates the button corners for each structure level to produce an elevator style button panel, but a shell macro that draws a single button is easily written.
MACRO ML_OneBtn
gp pButtonL ^DSelect lower left corner of button:
gp pButtonH ^DSelect upper right corner of button:
getx vX1 pButtonL
getx vX2 pButtonH
gety vY1 pButtonL
gety vY2 pButtonH
ifn vX1-vX2 ML1B_FlipX
getx vX2 pButtonL
getx vX1 pButtonH
:ML1B_FlipX
ifn vY1-vY2 ML1B_FlipY
getY vY2 pButtonL
getY vY1 pButtonH
:ML1B_FlipY
gp pButtonL vX1,vY1
gp pButtonH vX2,vY2
gn nCurLvl ^DEnter level # button goes to:
ML_DRAWBTN
ENDM Note that most of this macro is about making sure that pButtonL is the lower left corner and pButtonH is the upper right. I also made a slight change in the ML_DRAWBTN macro code by placing the last section (that draws the yellow "backlit" box) first so the out-of-range error check in the GoCurLvl macro is run before anything is drawn. The revised code is
MACRO ML_DRAWBTN
GoCurLvl
sheet MAP BORDER
color 4
fstyle Solid
box pButtonL pButtonH
setlayer BUTTONS
color 15
fstyle Hollow
box pButtonL pButtonH
gl sMacCmd ~gn nCur
apnd sMacCmd Lvl
apnd sMacCmd;
apnd sMacCmd nCurLvl
apnd sMacCmd;
apnd sMacCmd GoCur
apnd sMacCmd Lvl
apnd sMacCmd;
color 2
tspech 1
actionm sMacCmd
pButtonL pButtonH
sheet TEXT
color 15
getx vX1 pButtonL
gety vY1 pButtonL
getx vX2 pButtonH
gety vY2 pButtonH
gp pButtonC (vX1+vX2)/2,(vY1+vY2)/2
tspech (vY2-vY1)/2
textm nCurLvl
pButtonC
ENDM
--

Dalton "who loves feedback; it makes me smarter ;)" Spence

Arcana
11-21-2006, 03:02 PM
Dalton yer awesome. since you seem to be a hella-scripter do you think you could answer the fillstyle question in my stair shading macro thread?