Setting textColor quickly

External developers... This forum's for you!

Setting textColor quickly

Postby HairyHighlandCow » Tue Feb 28, 2012 1:25 am

Hi,
I have a script which changes chunks of text in a field to different colours. Working out the chunks of text happens very fast, but setting 'the textcolor of char x to y of cd fld 1' many times is a speed bottleneck. Would it be worth writing an external using internals toolbox that could set the textcolor of several different chunks of a field in one go? Am I likely to see a speed benefit?
Thanks
Alec
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 240
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK

Re: Setting textColor quickly

Postby codegreen » Tue Feb 28, 2012 3:36 am

Yes. Using GetUIWEHandle or GetUIWEHandleLong to obtain the display WERec and then using that to set the textColor directly should speed this operation up dramatically.

-Mark
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm

Re: Setting textColor quickly

Postby HairyHighlandCow » Tue Feb 28, 2012 12:36 pm

Thanks Mark!
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 240
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK

Re: Setting textColor quickly

Postby HairyHighlandCow » Sun Mar 25, 2012 7:56 am

Hi,
I've just got round to having a go at this. I found a useful command in SuperWASTE_472.h called 'weSetStyle'-- I am guessing this is the easiest way to set the style of a chunk of text once you have a valid WEHandle. I think for setting text color it wants 'kModeColor' in the third parameter. However, I'm not sure what to pass it in the fourth parameter. It appears to be expecting a 'const TextStyle' but there is no information about this type of variable in SuperWASTE_472.h. Could you give me an example of what it wants?
Thanks
Alec
Code: Select all
   
const TextStyle      *ts;
   if ((err = weSetStyle(par, hWE, kModeColor, ts)!= isOK)) {
      ReturnError(err, CFSTR("changing text color"));
      return;
   }
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 240
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK

Re: Setting textColor quickly

Postby codegreen » Sun Mar 25, 2012 11:54 am

HairyHighlandCow wrote:However, I'm not sure what to pass it in the fourth parameter. It appears to be expecting a 'const TextStyle' but there is no information about this type of variable in SuperWASTE_472.h. Could you give me an example of what it wants?

TextStyle is a Carbon struct defined in TextEdit.h. You'll want to use it something like this:

Code: Select all
   TextStyle   ts;
   RGBColor    red = {0xFFFF, 0, 0};
   
   ts.tsColor = red;
   
   if ((err = weSetStyle(par, hWE, kModeColor, &ts)!= isOK))

-Mark
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm

Re: Setting textColor quickly

Postby HairyHighlandCow » Sun Mar 25, 2012 12:23 pm

Hi Mark,

Thanks for that. What is the effect of setting text colour in this way with regards to the 256 available colours? Will SC find the closest match in the CLUT table to the RGB colour value supplied? Or will SC set the colour exactly but future reading of the textColor of that chunk will return the value 'unknown'?

Cheers

Alec
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 240
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK

Re: Setting textColor quickly

Postby codegreen » Sun Mar 25, 2012 8:17 pm

HairyHighlandCow wrote:Will SC find the closest match in the CLUT table to the RGB colour value supplied? Or will SC set the colour exactly but future reading of the textColor of that chunk will return the value 'unknown'?

The latter.
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest