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 SetTintCommand extends GenericCommand { 59 60 public SetTintCommand() {} 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 public void doCommand( FlashFile file, Context context, Script parent, int frameNum ) throws IVException { 76 Instance inst = getCommandInstance(file, context, parent, frameNum); 77 78 processFlashDef(inst, file, context); 80 81 int percent = parseNumber( getParameter( context, "percent" ), 100, 100 ); 82 int red = parseNumber( getParameter( context, "red" ), 0, 255 ); 83 int green = parseNumber( getParameter( context, "green" ), 0, 255 ); 84 int blue = parseNumber( getParameter( context, "blue" ), 0, 255 ); 85 87 CXForm cx = inst.cxform = CXForm.newIdentity(true); 88 89 double perc = percent/100.0; 90 percent = (int) ((1.0-perc)*255.0); 91 cx.setRedMul(percent); 92 cx.setGreenMul(percent); 93 cx.setBlueMul(percent); 94 96 cx.setRedAdd( (int) (red*perc) ); 97 cx.setGreenAdd( (int) (green*perc) ); 98 cx.setBlueAdd( (int) (blue*perc) ); 99 } 101 102 } 103 | Popular Tags |