📄 button.c
字号:
//ClearRec(WHITE,xSrc-1,ySrc-1,xDest-xSrc+2,yDest-ySrc+2,REPLACE_STYLE);
//ClearRec(WHITE,xSrc,ySrc,xDest-xSrc+1,yDest-ySrc+1,REPLACE_STYLE);
if ( (lparam&BS_INVERT) == BS_INVERT ){
//ClearRec(pGC, GPC_WHITE,(U16)xSrc,(U16)ySrc,(U16)(xDest-xSrc+1),(U16)(yDest-ySrc+1),GPC_REPLACE_STYLE);
ctrl_ptr->bt_state ^= BTN_STATUS_DOWN;
}
ctrl_ptr->bt_state |= BTN_STATUS_REPAINT;
if( ctrl_ptr->bt_state & BTN_STATUS_DOWN )
drawdownbutton( ctrl_ptr, xSrc, ySrc, xDest, yDest,ctrl_ptr->bt_style,
ctrl_ptr->bt_caption, NULL, ctrl_ptr->bt_icon,ctrl_ptr->bt_icon_width,ctrl_ptr->bt_icon_hight );
else
drawbutton( ctrl_ptr, xSrc,ySrc,xDest,yDest,ctrl_ptr->bt_style,ctrl_ptr->bt_caption,
ctrl_ptr->bt_icon,ctrl_ptr->bt_icon_width,ctrl_ptr->bt_icon_hight );
// longn_qi 2002/10/06 added
{
ASIX_WINDOW *wndptr = (ASIX_WINDOW *)ctrl_ptr->wndid;
if( wndptr->status & WST_FOCUS )
DrawRec( pGC, GPC_BLACK, xSrc+2, ySrc+2, xDest-2, yDest-2, GPC_DOT_LINE, GPC_XOR_STYLE );
}
return ASIX_OK;
}
// the function drawbutton() helps to draw the figure of the button with the specified style
STATUS drawbutton( void *ctrl_str, S16 xSrc,S16 ySrc,S16 xDest,S16 yDest,U32 btn_style,char *caption_tag,P_U8 bitmap,S16 bitmap_width,S16 bitmap_hight )
{
U32 grey;
char *tag = NULL;
char *captionandtag;
char *dcaption = NULL; //the caption which will display on the button
U16 i;
char *btcaption = NULL; //the caption which the utility programmer filled
int k;
int captionlength = (xDest-xSrc-1)/ENGLISH_CHAR_WIDTH; //modified by xuanhui 2002/3/27
STATUS rv = ASIX_OK;
U32 pGC;
U16 strX, strY, btWidth = xDest - xSrc +1, btHeight = yDest - ySrc +1;
struct bt_ctrl_str *ctrl_ptr;
ctrl_ptr = (struct bt_ctrl_str *)ctrl_str;
if( ctrl_ptr->bt_state & BTN_STATUS_MASKED )
{
ctrl_ptr->bt_state |= BTN_STATUS_UP;
return ASIX_OK;
}
pGC = GetGC();
SetDotWidth(pGC,1,0);
//in order to modify the caption string, alloc a piece of memory as a buffer to store the const string--caption
if( caption_tag != NULL )
{
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button appeal mem for caption and tag" );
captionandtag = Lcalloc( (strlen(caption_tag)+2)*sizeof(char) );
if (captionandtag == NULL) return ASIX_NO_MEM;
for( i = 0;i < strlen( caption_tag ); i++ )
{
captionandtag[i] = caption_tag[i];
}
//modified by xuanhui 2002/3/14
//captionandtag[i+1] = '\0';
captionandtag[i] = '\0';
}else{
captionandtag = NULL;
}
//seprate the caption and the tag from the captionandtag
if( captionandtag != NULL )
{
// longn_qi 2002/01/25 for monitor memory leak
// asix_bt_memdbgprintf( "button appeal mem for btcaption" );
//modified by xuanhui 2002/3/14
// btcaption = Lcalloc( (strlen(captionandtag))*sizeof(char) );
/* if ( btcaption == NULL )
{
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of caption and tag" );
Lfree(captionandtag);
return ASIX_ERROR;
}
*/
//modified by xuanhui 2002/3/14
//for( i = 0; i <= strlen(captionandtag); i++ )
for( i = 0; i < strlen(captionandtag); i++ )
{
if( captionandtag[i] == '\\' || captionandtag[i+1] == '\0' )
{
if( captionandtag[i+1] == '\0' )
{
btcaption = captionandtag;
tag = NULL;
}else{
captionandtag[i]='\0';
btcaption = captionandtag;
//modified by xuanhui 2002/3/14
//tag = captionandtag+i+1;
tag = captionandtag+(char)(i+1);
}
break;
}
}
//conclude if the caption of the button(btcaption) extends the active area
//modified by xuanhui 2002/3/14
//if( strlen(btcaption)*ENGLISH_CHAR_WIDTH > (xDest-xSrc) )
if( btcaption != NULL && strlen(btcaption)*ENGLISH_CHAR_WIDTH > (U16)(xDest-xSrc-1) )
{
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button appeal mem for dcaption" );
dcaption = Lcalloc( ( captionlength+1)*sizeof(char) ); //allocate a buffer to store the string that can be displayed on the button surface
if ( dcaption == NULL ) {
rv = ASIX_ERROR;
goto err_free;
}
for( k=0;k<captionlength-1;k++ )
{
dcaption[k] = btcaption[k];
}
dcaption[captionlength-1] = '\0';
}else{
dcaption = btcaption;
}
}
//conclude if the button which will be created is Enable or Disable and it will be reflected on the COLOR of the button
if( btn_style & WS_DISABLED )
{
//modified by xuanhui 2002/3/14
//grey = GPC_DARKGREY;
if( btn_style & BS_FLAT )
grey = ColorTheme.form_disabletext;
else
grey = ColorTheme.obj3D_disabletext;
} else {
//modified by xuanhui 2002/3/14
//grey = GPC_BLACK;
if( btn_style & BS_FLAT )
grey = ColorTheme.form_text;
else
grey = ColorTheme.obj3D_text;
}
if( btn_style & BS_FLAT )
ClearRec(pGC, ColorTheme.form_client,xSrc,ySrc,xDest-xSrc+1,yDest-ySrc+1,GPC_REPLACE_STYLE);
else if( !( btn_style & BS_TRANSPARENT ) )
ClearRec(pGC, ColorTheme.obj3D,xSrc,ySrc,xDest-xSrc+1,yDest-ySrc+1,GPC_REPLACE_STYLE);
//if the button style include BS_BOARD ,draw the board of the button
if( btn_style & BS_BOARD )
{
if ( dcaption != NULL ) //modified by xuanhui 2002/4/4
{
//modified by xuanhui 2002/3/28
if ( btWidth < (U16)(ENGLISH_CHAR_WIDTH +2)
|| btHeight < (U16)(CHINESE_CHAR_HEIGHT+2) )
return ASIX_ERROR;
}
//modified by xuanhui 2002/3/14
//DrawRec(pGC, GPC_BLACK,(U16)xSrc,(U16)ySrc,(U16)xDest,(U16)yDest,GPC_SOLID_LINE,GPC_REPLACE_STYLE);
//ClearRec(pGC, GPC_LIGHTGREY,(U16)(xSrc+1),(U16)(ySrc+1),(U16)(xDest-xSrc-2),(U16)(yDest-ySrc-2),GPC_REPLACE_STYLE);
DrawRec(pGC, ColorTheme.form_board,(U16)xSrc,(U16)ySrc,(U16)xDest,(U16)yDest,GPC_SOLID_LINE,GPC_REPLACE_STYLE);
}
//if the button style include BS_SHADOW,draw the shade of the button
if ( btn_style & BS_SHADOW )
{
if( (LOWORD(btn_style)&BS_BOARD) == 0 )
{
if ( dcaption != NULL ) //modified by xuanhui 2002/4/4
{
//modified by xuanhui 2002/3/28
if ( btWidth < (U16)(ENGLISH_CHAR_WIDTH+3)
|| btHeight < (U16)(CHINESE_CHAR_HEIGHT+3) )
return ASIX_ERROR;
}else{
if ( btWidth < 3 || btHeight < 3)
return ASIX_ERROR;
}
//modified by xuanhui 2002/3/14
//rv = ASIX_ERROR; //if the button will have a shade it must have a board at first
//goto err_free;
/* the button will have a shade without a board */
// DrawLine(pGC, ColorTheme.obj3D_shadow,(U16)(xSrc),(U16)(yDest),(U16)(xDest),(U16)(yDest),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
// DrawLine(pGC, ColorTheme.obj3D_shadow,(U16)(xDest),(U16)(ySrc),(U16)(xDest),(U16)(yDest),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
if( btn_style & BS_FLAT )
{
ClearRec( pGC, ColorTheme.form_client,(U16)(xSrc+BTN_INTERVAL),(U16)(ySrc+BTN_INTERVAL),(U16)(xDest-xSrc-BTN_INTERVAL),(U16)(yDest-ySrc-BTN_INTERVAL),GPC_REPLACE_STYLE);
}
else
{
DrawLine(pGC, ColorTheme.form_line,(U16)(xSrc),(U16)(yDest),(U16)(xDest),(U16)(yDest),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.form_line,(U16)(xDest),(U16)(ySrc),(U16)(xDest),(U16)(yDest),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_highlight,(U16)(xSrc),(U16)(ySrc),(U16)(xDest),(U16)(ySrc),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_highlight,(U16)(xSrc),(U16)(ySrc),(U16)(xSrc),(U16)(yDest),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_highlight,(U16)(xSrc+1),(U16)(ySrc+1),(U16)(xDest-1),(U16)(ySrc+1),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_highlight,(U16)(xSrc+1),(U16)(ySrc+1),(U16)(xSrc+1),(U16)(yDest-1),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
ClearRec(pGC, ColorTheme.obj3D,(U16)(xSrc+BTN_INTERVAL),(U16)(ySrc+BTN_INTERVAL),(U16)(xDest-xSrc-BTN_INTERVAL),(U16)(yDest-ySrc-BTN_INTERVAL),GPC_REPLACE_STYLE);
}
}else{
if ( dcaption != NULL ) //modified by xuanhui 2002/4/4
{
//modified by xuanhui 2002/3/28
if ( (U16)(xDest-xSrc+1) < (U16)(ENGLISH_CHAR_WIDTH +2)
|| (U16)(yDest-ySrc+1) < (U16)(CHINESE_CHAR_HEIGHT+2) )
return ASIX_ERROR;
}else{
if ( (U16)(xDest-xSrc+1) < 5 || (U16)(yDest-ySrc+1) < 5 )
return ASIX_ERROR;
}
if( !( btn_style & BS_FLAT ) )
{
//modified by xuanhui 2002/3/14
DrawLine(pGC, ColorTheme.form_line,(U16)(xSrc+1),(U16)(yDest-1),(U16)(xDest-1),(U16)(yDest-1),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.form_line,(U16)(xDest-1),(U16)(yDest-1),(U16)(xDest-1),(U16)(ySrc+1),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_shadow ,(U16)xSrc,(U16)ySrc,(U16)xDest,(U16)ySrc,GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_highlight,(U16)(xSrc+1),(U16)(ySrc+1),(U16)(xDest-1),(U16)(ySrc+1),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_shadow ,(U16)xSrc,(U16)ySrc,(U16)xSrc,(U16)yDest,0,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_highlight,(U16)(xSrc+1),(U16)(ySrc+1),(U16)(xSrc+1),(U16)(yDest-1),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_highlight,(U16)(xSrc+2),(U16)(ySrc+2),(U16)(xDest-2),(U16)(ySrc+2),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
DrawLine(pGC, ColorTheme.obj3D_highlight,(U16)(xSrc+2),(U16)(ySrc+2),(U16)(xSrc+2),(U16)(yDest-2),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
}
}
}
// if the button style include BS_LEFT ,draw left align caption or left align bitmap
if( LOWORD(btn_style) & BS_LEFT )
{
if(bitmap == NULL)
{
if ( dcaption != NULL ) //modified by xuanhui 2002/4/4
{
if( LOWORD(btn_style) & BS_MULTILINE )//changed 2001/4/10
{
//modified by xuanhui 2002/3/28
if ( btWidth < (U16)(BTN_MULTILINE_INTERVAL*2+ ENGLISH_CHAR_WIDTH+2)
|| btHeight < (U16)(BTN_MULTILINE_INTERVAL*2+ CHINESE_CHAR_HEIGHT+2) )
return ASIX_ERROR;
//modified by xuanhui 2002/3/14
//DisplayMsg(btcaption, xSrc+4, ySrc+4, xDest-4, yDest-4, GPC_REPLACE_STYLE );
DisplayMsg(btcaption, (S16)(xSrc+BTN_MULTILINE_INTERVAL), (S16)(ySrc+BTN_MULTILINE_INTERVAL), (S16)(xDest-BTN_MULTILINE_INTERVAL), (S16)(yDest-BTN_MULTILINE_INTERVAL), GPC_REPLACE_STYLE );
}else{
//modified by xuanhui 2002/3/28
// if ( (U16)(xDest-xSrc+1) < (U16)(BTN_INTERVAL*2+2+ ENGLISH_CHAR_WIDTH)
// || (U16)(BTN_REGULAR_STR_INTERVAL+ (U16)((yDest-ySrc+1)/2)-1) < CHINESE_CHAR_HEIGHT
// || (U16)(CHINESE_CHAR_HEIGHT/2) < BTN_REGULAR_STR_INTERVAL )
// return ASIX_ERROR;
//Disp16StringGrey( grey,dcaption,(U16)(xSrc+BTN_INTERVAL+1),(U16)(ySrc+(yDest-ySrc)/2-BTN_REGULAR_STR_INTERVAL) );
strX = AlignString( dcaption, xSrc +BTN_INTERVAL+1, btWidth - BTN_INTERVAL*2, GPC_ALIGN_LEFT );
strY = ySrc + ( ( btHeight - BTN_INTERVAL*2 - CHINESE_CHAR_HEIGHT )>>1 );
TextOut( pGC, dcaption, strX, strY, NULL, grey, GPC_REPLACE_STYLE );
}
}
// ppsm use follow function to make transparent background
// but in new gpc function we have realized it
// so remove it ( longn_qi 2001/11/15 revised )
//if( LOWORD(btn_style)&BS_BOARD )
// ClearRec(pGC, GPC_LIGHTGREY,(U16)(xSrc+2), (U16)(ySrc+2), (U16) (xDest-xSrc-2), (U16) (yDest-ySrc-2),GPC_OR_STYLE);
}else{
//switchonetotwo( (char*)bitmap,xSrc+3,(ySrc+(yDest-ySrc)/2-bitmap_width/2),bitmap_width,bitmap_hight);
//modified by xuanhui 2002/3/14
//DrawMonoImage(pGC, bitmap, xSrc+3, (ySrc+(yDest-ySrc)/2-bitmap_width/2), bitmap_width, bitmap_hight, ColorTheme.form_text , ColorTheme.form_client);
// DrawMonoImage(pGC, bitmap, (U16)(xSrc+BTN_INTERVAL+1), (U16)(ySrc+(yDest-ySrc)/2-bitmap_hight/2), (U16)bitmap_width, (U16)bitmap_hight, ColorTheme.form_frontcolor , ColorTheme.form_backcolor);
{
U32 hbmp;
U16 lx,ly;
U16 bmp_w, bmp_h;
U32 palette[2];
if( btn_style & WS_DISABLED )
{
palette[0] = ColorTheme.form_client;
if( btn_style & BS_TRANSPARENT )
palette[1] = ColorTheme.obj3D_disablecolor;
else
palette[1] = ColorTheme.form_disablecolor;
hbmp = GrizzleBitmap( bitmap, palette );
}
else
hbmp = LoadBitmap( bitmap, NULL );
bmp_w = ((BITMAP *)hbmp)->info.width;
bmp_h = ((BITMAP *)hbmp)->info.height;
if( bmp_w < btWidth )
lx = xSrc + ( btWidth - bmp_w )/2;
else
lx = 0;
if( bmp_h < btHeight )
ly = ySrc + ( btHeight - bmp_h )/2;
else
ly = 0;
if( hbmp != 0 )
{
//SetBMPPalette( hbmp, palette, NULL );
if( btn_style & BS_TRANSPARENT )
{
U32 trColor;
SetBkFillMode( pGC, MAKELONG( GPC_REPLACE_STYLE, GPC_TRANSPARENT_STYLE ) );
trColor = ((BITMAP *)hbmp)->palette[0];
DisplayBMPEx( pGC, lx, ly, hbmp, GPC_TRANSPARENT_STYLE, trColor );
}
else
DisplayBMP( pGC, lx, ly, hbmp );
FreeBitmap( hbmp );
}
}
}
}else{
if( bitmap == NULL )
{
if ( dcaption != NULL ) //modified by xuanhui 2002/4/4
{
if( LOWORD(btn_style) & BS_MULTILINE )//changed 2001/4/10
{
//modified by xuanhui 2002/3/28
if ( (U16)(xDest-xSrc+1) < (U16)(BTN_MULTILINE_INTERVAL*2+ ENGLISH_CHAR_WIDTH+2)
|| (U16)(yDest-ySrc+1) < (U16)(BTN_MULTILINE_INTERVAL*2+ CHINESE_CHAR_HEIGHT+2) )
return ASIX_ERROR;
//modified by xuanhui 2002/3/14 btcaption
//DisplayMsg(btcaption, xSrc+4, ySrc+4, xDest-4, yDest-4, GPC_REPLACE_STYLE );
DisplayMsg(btcaption, (S16)(xSrc+BTN_MULTILINE_INTERVAL), (S16)(ySrc+BTN_MULTILINE_INTERVAL), (S16)(xDest-BTN_MULTILINE_INTERVAL), (S16)(yDest-BTN_MULTILINE_INTERVAL), GPC_REPLACE_STYLE );
}else{
//modified by xuanhui 2002/3/28
// if ( (U16)(xDest-xSrc+1) < (U16)(BTN_INTERVAL*2+2+ENGLISH_CHAR_WIDTH)
// || (U16)(BTN_REGULAR_STR_INTERVAL+(U16)((yDest-ySrc+1)/2)-1) < CHINESE_CHAR_HEIGHT
// || (U16)(CHINESE_CHAR_HEIGHT/2) < BTN_REGULAR_STR_INTERVAL )
// return ASIX_ERROR;
//modified by xuanhui 2002/3/14
//Disp16StringCenterGrey( grey,dcaption,(U16)(xSrc+3),(U16)(xDest-xSrc-2),(U16)((yDest-ySrc-16)/2+ySrc) );
//Disp16StringGrey( grey,dcaption,(U16)(xSrc+BTN_INTERVAL+1),(U16)(ySrc+(yDest-ySrc)/2-BTN_REGULAR_STR_INTERVAL) );
strX = AlignString( dcaption, xSrc + BTN_INTERVAL, btWidth - BTN_INTERVAL*2, GPC_ALIGN_CENTER );
strY = ySrc + BTN_INTERVAL + ( ( btHeight - BTN_INTERVAL*2 - CHINESE_CHAR_HEIGHT )>>1 );
TextOut( pGC, dcaption, strX, strY, NULL, grey, GPC_REPLACE_STYLE );
}
// ppsm use follow function to make transparent background
// but in new gpc function we have realized it
// so remove it ( longn_qi 2001/11/15 revised )
//if( LOWORD(btn_style)&BS_BOARD )
// ClearRec(pGC, GPC_LIGHTGREY,(U16)(xSrc+2), (U16)(ySrc+2), (U16) (xDest-xSrc-2), (U16) (yDest-ySrc-2),GPC_OR_STYLE);
}
} else {
//switchonetotwo( (char*)bitmap,xSrc+(xDest-xSrc)/2-bitmap_width/2,(ySrc+(yDest-ySrc)/2-bitmap_hight/2),bitmap_width,bitmap_hight);
//modified by xuanhui 2002/3/14
//DrawMonoImage(pGC, bitmap, xSrc+(xDest-xSrc+1)/2-bitmap_width/2, (ySrc+(yDest-ySrc+1)/2-bitmap_width/2), bitmap_width, bitmap_hight, ColorTheme.form_text, ColorTheme.form_client);
//DrawMonoImage(pGC, bitmap, (U16)(xSrc+(xDest-xSrc+1)/2-bitmap_width/2), (U16)(ySrc+(yDest-ySrc+1)/2-bitmap_hight/2), (U16)bitmap_width, (U16)bitmap_hight, ColorTheme.form_frontcolor , ColorTheme.form_backcolor);
{
U32 hbmp;
U16 lx,ly;
U16 bmp_w, bmp_h;
U32 palette[2];
if( btn_style & WS_DISABLED )
{
palette[0] = ColorTheme.form_client;
if( btn_style & BS_TRANSPARENT )
palette[1] = ColorTheme.obj3D_disablecolor;
else
palette[1] = ColorTheme.form_disablecolor;
hbmp = GrizzleBitmap( bitmap, palette );
}
else
hbmp = LoadBitmap( bitmap, NULL );
bmp_w = ((BITMAP *)hbmp)->info.width;
bmp_h = ((BITMAP *)hbmp)->info.height;
if( bmp_w <= btWidth )
lx = xSrc + ( btWidth - bmp_w )/2;
else
lx = xSrc;
if( bmp_h <= btHeight )
ly = ySrc + ( btHeight - bmp_h )/2;
else
ly = ySrc;
if( hbmp != 0 )
{
if( btn_style & BS_TRANSPARENT )
{
U32 trColor;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -