by stephane on Fri Feb 02, 2001 3:58 am
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
else
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(0,1,0);
textattr( n, 1, 0);
// DST - end - 01/02/2001
textalign(11);
//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[0]==3)
if(p[ 8 ])
Cib(p);
}
</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.
Cheers,
St?ɬ©phane
Stéphane