1 50 51 package org.openlaszlo.iv.flash.commands; 52 53 import org.openlaszlo.iv.flash.parser.*; 54 import org.openlaszlo.iv.flash.api.*; 55 import org.openlaszlo.iv.flash.util.*; 56 import org.openlaszlo.iv.flash.context.Context; 57 58 public class SetCustomColorCommand extends GenericCommand { 59 60 public SetCustomColorCommand() {} 61 62 private int parseNumber( String num, int def, int max ) { 63 if( num == null ) return def; 64 try { 65 double d = Double.valueOf(num).doubleValue(); 66 if( d < 0 || d > max ) { 67 return def; 68 } 69 return (int) d; 70 } catch( NumberFormatException e ) { 71 return def; 72 } 73 } 74 75 private int parsePercent( String num ) { 76 int percent = parseNumber( num, 100, 100 ); 77 return (percent*255)/100; 78 } 79 80 public void doCommand( FlashFile file, Context context, Script parent, int frameNum ) throws IVException { 81 Instance inst = getCommandInstance(file, context, parent, frameNum); 82 83 processFlashDef(inst, file, context); 85 86 int percentred = parsePercent( getParameter( context, "percentred" ) ); 87 int percentgreen = parsePercent( getParameter( context, "percentgreen" ) ); 88 int percentblue = parsePercent( getParameter( context, "percentblue" ) ); 89 int percentalpha = parsePercent( getParameter( context, "percentalpha" ) ); 90 int offsetred = parseNumber( getParameter( context, "offsetred" ), 0, 255 ); 91 int offsetgreen = parseNumber( getParameter( context, "offsetgreen" ), 0, 255 ); 92 int offsetblue = parseNumber( getParameter( context, "offsetblue" ), 0, 255 ); 93 int offsetalpha = parseNumber( getParameter( context, "offsetalpha" ), 0, 255 ); 94 95 CXForm cx = inst.cxform = new CXForm(true); 96 97 cx.setRedMul( percentred ); 98 cx.setGreenMul( percentgreen ); 99 cx.setBlueMul( percentblue ); 100 cx.setAlphaMul( percentalpha ); 101 102 cx.setRedAdd( offsetred ); 103 cx.setGreenAdd( offsetgreen ); 104 cx.setBlueAdd( offsetblue ); 105 cx.setAlphaAdd( offsetalpha ); 106 } 107 108 } 109 | Popular Tags |