-
Creating a AE numeric slider style Extendscript
Hi, in this empty days i’m testing some ScriptUI features. Now I’m trying to build an AE numeric slider like in the propertys on the layers, effects etc:
I’m using this event handler file I found on the web. I have some working aproach, but I have some questions, if someone have the time to help(code below).
1- I can slide the numbers, but when the mouse goes out of the window, it stops dragging. When the mouse return to the window it continues sliding the value, like a mouseDown event, even if I’m not clicking. Can I extend the eventListener out of the window?
2- It is posible to use app mouse icons on certain events? Like in AE when you have the mouse over the value of a property or when you drag the value?
3- Is there some code out there tha does all the job? lol
I know achieve something similar would not be trivial, but I love challenges.
Code:
{#include 'EventHandler.jsinc'
function buildUI(thisObj) {
var mouseStartX = 0;
var lastMouseX = 0;
var mouseX = 0;
var activeObject = 0;
var slideBoxActive = false;
var settings = new Object();
settings.duration = new Object();
settings.random = new Object();settings.duration.value = 5;
settings.duration.min = 0;
settings.duration.max = 20;settings.random.value = 5;
settings.random.min = 0;
settings.random.max = 20;this.buildAeSlider = function(container, settings) {
var boxObj = new Object ();
var main_grp = container.add("group{orientation:'stack'}");
var box = main_grp.add("edittext{ text:'"+ settings.value +"', visible:false, preferredSize:[100, 19]}");
var text = main_grp.add("statictext{ text:'"+ settings.value +"', name:'text', preferredSize:[100, 19]}");
text.kt_boxtype = true;
box.kt_boxtype = true;function activate (obj) {
if(obj == text){
text.visible = false;
box.active = true;
box.visible = true;
}
}function deactivate() {
box.active = false;
box.visible = false;
text.text = box.text;
text.visible = true;
}function slideBox (obj) {
if (activeObject == text) {
if(mouseX > lastMouseX){
var value = parseFloat(text.text) + 0.1;
text.text = value;
box.text = value;
$.writeln(mouseX)
} else {
var value = parseFloat(text.text) - 0.1;
text.text = value;
box.text = value;
}
}
lastMouse = value;
}text.addEventListener("click", activate);
box.addEventListener("keydown", function(k) {
if(k.keyName == "Enter") {deactivate()}
})EventManager.addEventListener("DEACTIVATE_BOX", deactivate);
EventManager.addEventListener("ACTIVATE_BOX", activate);
EventManager.addEventListener("SLIDE_BOX", slideBox);}
var win= (thisObj instanceof Panel)? thisObj: new Window('palette', 'Slider testing', undefined);
win.preferredSize = [200, 200];
var ae_slider = this.buildAeSlider(win, settings.duration);
var ae_slider = this.buildAeSlider(win, settings.random);
var panel = win.add("panel{text:'Test Panel', preferredSize: [200, 100]}")function deactivateBox () {
EventManager.dispatchEvent("DEACTIVATE_BOX");
}function activateBox (e) {
EventManager.dispatchEvent("ACTIVATE_BOX", e);
}function slideBox (p) {
mouseX = p.clientX;
EventManager.dispatchEvent("SLIDE_BOX");
}win.addEventListener("click", function(p) {
if (!p.target.kt_boxtype) {
deactivateBox();
} else {
deactivateBox();
activateBox(p.target);
}
});win.addEventListener("mousedown", function(p) {
if(p.target.kt_boxtype){
activeObject = p.target;mouseStartX = p.clientX;
win.addEventListener("mousemove", slideBox);
}});
win.addEventListener("mouseup", function(p) {
win.removeEventListener("mousemove", slideBox);
activeObject = 0;
deactivateBox();
});return win;
}var myWin = buildUI(this);
myWin.center();
myWin.show();
}
Sorry, there were no replies found.
