Hi all,
I've been trying to do a color picker. I have managed to get it running with a UI and all looks sweet, but I have no clue how to actually do anything! Photoshop launches it just fine.
Simple stuff really:
1. How do you set the tool to the eyedropper? (I already have code working that detects when the mouse moves outside the window)
2. How do you set the color? Looking for a function like setColor() so that the current context get the color and user can preview the result (i.e. color overlay)
To me it sounds like these two would be simple one liners, but I can't for the love of God figure out how to do it!
Documentation for JS is pretty good though, but I haven't been able to run JS code from my color picker. Here's my attempt att running javascript code:
bool runJavascript(const char* jscode)
{
// Sanity check
if (sSPBasic == nil)
{
NSLog(@"sSPBasic is NULL");
return false;
}
ASErr err = 0;
JSScriptingSuite2* sScriptingSuite = NULL;
err = sSPBasic->AcquireSuite(kJSScriptingSuite, kJSScriptingSuiteVersion2, (const void**)&sScriptingSuite);
if (sScriptingSuite == NULL) //Also support Photoshop CS1-CS4 and Elements 6-10
err = sSPBasic->AcquireSuite( kJSScriptingSuite, kJSScriptingSuiteVersion1, (const void**)&sScriptingSuite);
if (sScriptingSuite == NULL) return false;
JSEngineRef engineRef = NULL;
err = sScriptingSuite->CreateEngine(&engineRef);
if (err == kSPNoError)
{
//Convert ascii to unicode
wchar_t * wcode;
size_t codelength = strlen(jscode)+1;
wcode = (wchar_t *)malloc(codelength*sizeof(wchar_t));
mbstowcs(wcode, jscode, codelength);
const ASUnicode * result = NULL;
err = sScriptingSuite->ExecuteScript(engineRef, (ASUnicode*)wcode, kJSExecutionModeNoDebug, &result);
if (err != kSPNoError)
{
NSLog(@"JavaScript error (%d). Script: %s", (int)*result, jscode);
}
else
{
NSLog(@"JavaScript OK!");
}
free(wcode);
}
else
{
return false;
}
if (engineRef)
{
sScriptingSuite->DeleteEngine( engineRef);
}
return true;
}
Which doesn't really work. It seems like the culprit is the conversion from char* to ASUnicode. In the example they had
const ASUnicode test[] = {'a', 'l', 'e', 'r', 't', '(', '\'', 'h', 'i', '\'', ')', ';', 0 } ;
which works just fine. But apparently I don't convert my string to ASUnicode the correct way. Any ideas or comments are very appreciated!