Page 1 of 1

PostPosted: Thu Feb 01, 2001 6:42 pm
by Velvis
I would like to use a symbol from the PalmOS symbol font in a Ccontrols text button. Does anyone know how to do this?


PostPosted: Fri Feb 02, 2001 2:00 am
by stephane
Hi there.

Whatever your solution, you will have to modify the Ccontrols library, because the font is hardcoded in all of its text drawing functions.

In the case of text buttons, the function you are looking for is <b>Cdb()</b>, in <b>Ccontrols1.c</b>. The "simple" way of getting what you want is to cut and paste this function, and rename it, eg: CdbSymbol(). Change the textattr() in this new function to be textattr(3,1,0), for symbol, and call CdbSymbol( handle ) instead of Cdraw() in your code. You would need one function for each font you use, in this case.

Another way to go about it, is to delve a little deeper into Ccontrols, and modify the Cbutton() function, to define another parameter which would specify the font, then modify Cdb() to use that parameter as a variable in the textattr() call.

For a one shot deal, I think the first solution is quick and easy. If you want to modify your library for general re-use in later projects, try the second.

Cheers, hth,


PostPosted: Fri Feb 02, 2001 3:58 am
by stephane
Here's yet another way, that will be compatible with existing code because no extra parameters are added. What I've done is code the Cdb() function so that it looks for an "escape" sequence of "/f<i>n</i>" at the beginning of a string. This will tell Ccontrols to use font <i>n</i> when printing text for the text and switch buttons. Note that I had to fudge a bit for the LED font, and if you do use that font, the minimum height of the button should be 19 pixels. 'Nuff said, here's the code, "pretty" format from the PDE, cut it down if you're coding on the handheld.

<pre id=code><font face=courier size=2 id=code>
Cdb(pointer p) { // draw button
int c;
string s; // DST - 01/02/2001
int n, y; // DST - 01/02/2001

if (p[0]>0)
c=p[6]; // use defined frame if activated
c=2; // grey frame if de-activated
rect(0, p[1], p[2], p[1]+p[3], p[2]+p[4], p[7]);
frame(c, p[1], p[2], p[1]+p[3], p[2]+p[4], p[7]);
if(p[0]==2) // image button
bitmap( p[1], p[2], *p[5] );
else { // text buttons
// DST - start - 01/02/2001
s = *p[5];
n = 0;
y = p[2] + (p[4]/2)-2;
if( strleft( s, 2 ) == "/f" ) { // look for the font escape sequence
n = substr( s, 2, 1 ); // get the font number..
s = strright( s, strlen(s)-3 ); } // ..and rest of the string
if( n==6 ) // special case for LED font
// make sure height is >= 19 when coding button
y = p[2] + (p[4]/2) - 9;
textattr( n, 1, 0);
// DST - end - 01/02/2001
//text( p[1] + (p[3]/2), p[2] + (p[4]/2)-2, *p[5] ); // DST - 01/02/2001
text( p[1] + (p[3]/2), y, s ); // DST - 01/02/2001
textattr(0,1,0); // DST - 01/02/2001
textalign(0); }
if(p[ 8 ])
</font id=code></pre id=code>

Lines marked <b>DST</b> are my additions to the Ccontrols baseline, other comments are my own based on my understanding of the code.



PostPosted: Fri Feb 02, 2001 5:09 pm
by Velvis
I havent tried it yet,but thanks alot. I was wondering if the line:

text( p[1] + (p[3]/2),p[2]+(p[4]/2)-2, *p[5] );

near the end after textalign(11); was supposed to be commented out.

Thanks again.

PostPosted: Fri Feb 02, 2001 5:20 pm
by stephane
Yes, it is in fact commented out, the line below it is the updated version of the same line. Just the way I keep track of code changes.



PostPosted: Fri Feb 02, 2001 5:31 pm
by Velvis
Ok I compiled it, but I am having trouble getting it to display the proper character.

I have called Csetcontent with "/f4002" & "/f42" (4 being the Symbol11 font and 002 or 2 being the left arrow character as listed from the kisfonts program.
But on the display I just get the "empty box" character.

Any ideas?


PostPosted: Fri Feb 02, 2001 5:38 pm
by Velvis
I figured it out... You must use "/f5"+(char)005)


PostPosted: Fri Feb 02, 2001 5:57 pm
by Velvis
Do you have any ideas on how to make the symbol inside the button centered?
I used the following

which works but the arrow is not centered in the button.

PostPosted: Sat Feb 03, 2001 11:44 pm
by stephane
Yes, you can use: "/f4"+(char)002);
You can also do it this way: "/f4\x02" using the hex character value.

As to the symbol text not being centered, I suspect that you mean it is not centered vertically, although horizontally it is fine. I believe this is because of the font not being a "standard" text font size, much the same case as the LED font. So what needs to be done, if this is the case, is to add more conditions along the lines of the 'if (n==6) etc..' in my original code, where you need to calculate a different vertical offset depending on the font you're dealing with.

I'm trying to streamline this routine a bit, adding the changes mentionned above, but it may be a few days before I can post any code.