/* File: ..//src//shared//progressBar.jsx Date: Sat Dec 27 15:17:32 MYT 2008 Author: David Van Brink This script is part of the omino adobe script suite. The latest version can be found at http://omino.com/pixelblog/. I write these because I like to. Please enjoy as you see fit. Questions to poly@omino.com, subject line should start with "plugins" so my spam filter lets it in. This file has been preprocessed to be standalone. I develop them against some reusable libraries -- such as for dialog layout -- but for distribution it's nicer to have just one file. dvb 2007. */ // ----------------------------------------- // #include "psHelpers.jsx" // ----------------------------------------- /* photoshop helper routines dvb07 */ // A helper function for debugging // It also helps the user see what is going on // if you turn it off for this example you // get a flashing cursor for a number (long) time // dvb say: I have NO idea what this is, it's // from the Adobe scripting reference. // some things take a while, so I like to allow // occasional screen draw. function WaitForRedraw() { var eventWait = charIDToTypeID("Wait") var enumRedrawComplete = charIDToTypeID("RdCm") var typeState = charIDToTypeID("Stte") var keyState = charIDToTypeID("Stte") var desc = new ActionDescriptor() desc.putEnumerated(keyState, typeState, enumRedrawComplete) executeAction(eventWait, desc, DialogModes.NO) } function pin(x,lo,hi) { if(x < lo) x = lo; if(x > hi) x = hi; return x; } function getColor(r,g,b) // 0..255 each { r = pin(r,0,255); g = pin(g,0,255); b = pin(b,0,255); var rgbColor = new RGBColor(); rgbColor.red = r; rgbColor.green = g; rgbColor.blue = b; var fc = new SolidColor(); fc.rgb = rgbColor; return fc; } function setUnitsPixels() { app.preferences.rulerUnits = Units.PIXELS; } function addText(doc,text,size,x,y) { var newLayerRef = doc.artLayers.add(); newLayerRef.kind = LayerKind.TEXT; var pos = new Array(x,y); newLayerRef.textItem.contents = text; newLayerRef.textItem.color = getColor(Math.random() * 255,Math.random() * 255,Math.random() * 255); newLayerRef.textItem.size = size; newLayerRef.textItem.position = pos; } // thus ends psHelpers.jsx // ----------------------------------------- function progressBar(title1,title2) { var result = new Object(); result.running = true; result.p = new Window("palette"); result.p.orientation = "column"; result.p.alignChildren = "left"; result.t1 = result.p.add("statictext",undefined,title1); result.t2 = result.p.add("statictext",undefined,title2); result.b = result.p.add("progressbar"); result.c = result.p.add("button",undefined,"Cancel"); result.c.onClick = function() { result.running = false; } result.isRunning = function() { return this.running; } result.setValue = function(x) { this.b.value = x * 100; } result.setTitle1 = function(t1) { this.t1.text = t1; } result.setTitle1 = function(t2) { this.t2.text = t2; } result.close = function() { this.p.close; } result.p.show(); return result; } var a = progressBar("This is a quite long title!","----------------"); var i; var z = 10000; for(i = 0; i < z; i++) { WaitForRedraw(); a.setValue(i / z); a.setTitle1("" + i + " of " + z); if(!a.isRunning()) break; }