Skip to content

Instantly share code, notes, and snippets.

@k2052
Created February 12, 2011 20:50
Show Gist options
  • Save k2052/824103 to your computer and use it in GitHub Desktop.
Save k2052/824103 to your computer and use it in GitHub Desktop.
def drawRoundedRec(offset, width, height, radius, color = nil)
x = offset['left']
y = offset['top']
ry = y + height
rx = x + width
str = <<-eos
var idMk = charIDToTypeID( "Mk " );
var desc77 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref42 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
ref42.putClass( idcontentLayer );
desc77.putReference( idnull, ref42 );
var idUsng = charIDToTypeID( "Usng" );
var desc78 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc78.putClass( idType, idsolidColorLayer );
var idShp = charIDToTypeID( "Shp " );
var desc79 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc79.putUnitDouble( idTop, idPxl, #{y} );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc79.putUnitDouble( idLeft, idPxl, #{x} );
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc79.putUnitDouble( idBtom, idPxl, #{ry} );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc79.putUnitDouble( idRght, idPxl, #{rx} );
var idRds = charIDToTypeID( "Rds " );
var idPxl = charIDToTypeID( "#Pxl" );
desc79.putUnitDouble( idRds, idPxl, #{radius.gsub('px', '')} ); // Border radius
var idRctn = charIDToTypeID( "Rctn" );
desc78.putObject( idShp, idRctn, desc79 );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
desc77.putObject( idUsng, idcontentLayer, desc78 );
executeAction( idMk, desc77, DialogModes.NO );
eos
do_javascript(str)
if color != nil
color_js = <<-eos
var idsetd = charIDToTypeID( "setd" );
var desc23 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref15 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref15.putEnumerated( idcontentLayer, idOrdn, idTrgt );
desc23.putReference( idnull, ref15 );
var idT = charIDToTypeID( "T " );
var desc24 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc25 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc25.putDouble( idRd, #{color[:red]} );
var idGrn = charIDToTypeID( "Grn " );
desc25.putDouble( idGrn, #{color[:green]} );
var idBl = charIDToTypeID( "Bl " );
desc25.putDouble( idBl, #{color[:blue]} );
var idRGBC = charIDToTypeID( "RGBC" );
desc24.putObject( idClr, idRGBC, desc25 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc23.putObject( idT, idsolidColorLayer, desc24 );
executeAction( idsetd, desc23, DialogModes.NO );
eos
do_javascript(color_js)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment