⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 button.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
📖 第 1 页 / 共 4 页
字号:

						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
					goto err_free;
			}
		}
	}
	
	//if button style include BS_UNDERLINE,draw a underline at the bottom of the caption
	if( LOWORD(btn_style) & BS_UNDERLINE )
	{
		if( bitmap != NULL ){
			rv = ASIX_ERROR;
			goto err_free;
		}
		if( LOWORD(btn_style) & BS_LEFT )
		{
			if ( dcaption != NULL )	//modified by xuanhui 2002/4/4
			{
				//modified by xuanhui 2002/3/28
				if ( btWidth < (U16)(BTN_INTERVAL*2+2+ENGLISH_CHAR_WIDTH) 
				|| btHeight < (U16)(CHINESE_CHAR_HEIGHT+BTN_UNDERLINE_INTERVAL+2) )
					return ASIX_ERROR;
				//modified by xuanhui 2002/3/18
				//DrawLine(pGC, GPC_DARKGREY,(U16)(xSrc+3),(U16)(ySrc+(yDest-ySrc)/2+8),(U16)(xSrc+3+ENGLISH_CHAR_WIDTH*(U16)strlen(dcaption)),(U16)(ySrc+(yDest-ySrc)/2+8),GPC_SOLID_LINE,GPC_REPLACE_STYLE);//something wrong here
				DrawLine(pGC, ColorTheme.form_line,(U16)(xSrc+BTN_INTERVAL+1),(U16)(ySrc+(yDest-ySrc)/2+BTN_UNDERLINE_INTERVAL),(U16)((U16)xSrc+BTN_INTERVAL+1+ENGLISH_CHAR_WIDTH*(U16)strlen(dcaption)),(U16)(ySrc+(yDest-ySrc)/2+BTN_UNDERLINE_INTERVAL),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
			}	
		}else{
			if ( dcaption != NULL )	//modified by xuanhui 2002/4/4
			{
				//modified by xuanhui 2002/3/28
				if (btWidth < (U16)(BTN_INTERVAL*2+2+ENGLISH_CHAR_WIDTH*2)
				|| btHeight < (U16)(CHINESE_CHAR_HEIGHT+BTN_UNDERLINE_INTERVAL+2) )
					return ASIX_ERROR;
				//modified by xuanhui 2002/3/18
				//DrawLine(pGC, GPC_DARKGREY,(U16)(xSrc+(xDest-xSrc)/2-ENGLISH_CHAR_WIDTH*(U16)strlen(dcaption)/2),(U16)(ySrc+(yDest-ySrc)/2+8),(U16)(xSrc+(xDest-xSrc)/2+ENGLISH_CHAR_WIDTH*(U16)strlen(dcaption)/2),(U16)(ySrc+(yDest-ySrc)/2+8),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
				DrawLine(pGC, ColorTheme.form_line,(U16)((U16)(xSrc+(xDest-xSrc)/2)-ENGLISH_CHAR_WIDTH*(U16)strlen(dcaption)/2),(U16)(ySrc+(yDest-ySrc)/2+BTN_UNDERLINE_INTERVAL),(U16)((U16)(xSrc+(xDest-xSrc)/2)+ENGLISH_CHAR_WIDTH*(U16)strlen(dcaption)/2),(U16)(ySrc+(yDest-ySrc)/2+BTN_UNDERLINE_INTERVAL),GPC_SOLID_LINE,GPC_REPLACE_STYLE);
			}
		}
	}
	
	// longn_qi 2002/09/10 delete
	//if button style include BS_INVERT, invert the color of the button 
/*	if( LOWORD(btn_style) & BS_INVERT )
	{
		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;
		}		
		//modified by xuanhui 2002/3/18
		//InvRec( pGC,(U16)(xSrc+1), (U16)(ySrc+1), (U16) (xDest-xSrc-2), (U16) (yDest-ySrc-2));
		//ClearRec(pGC, GPC_LIGHTGREY,(U16)(xSrc+1), (U16)(ySrc+1), (U16) (xDest-xSrc-2), (U16) (yDest-ySrc-2), GPC_OR_STYLE);
		InvRec( pGC,(U16)(xSrc), (U16)(ySrc), (U16) (xDest-xSrc+1), (U16) (yDest-ySrc+1));
		
		//modified by xuanhui 2002/4/3
		//ClearRec(pGC, ColorTheme.obj3D,(U16)(xSrc), (U16)(ySrc), (U16) (xDest-xSrc+1), (U16) (yDest-ySrc+1), GPC_OR_STYLE);
	}
*/	
	ctrl_ptr->bt_state = BTN_STATUS_UP;

err_free:	
	//free the buffer which was allocated for the string of the captionandtag
	
	if( captionandtag != NULL ) 
	{
		// longn_qi 2002/01/25 for monitor memory leak
		asix_bt_memdbgprintf( "button free mem of caption and tag" );
		Lfree(captionandtag);
	}

	if( btcaption != NULL ) 
	{
		// longn_qi 2002/01/25 for monitor memory leak
		asix_bt_memdbgprintf( "button free mem of btcaption" );
		Lfree(btcaption);
	}

	if( dcaption != NULL ) 
	{
		// longn_qi 2002/01/25 for monitor memory leak
		asix_bt_memdbgprintf( "button free mem of dcaption" );
		Lfree(dcaption);
	}

	return rv;
	
}

//the function drawdownbutton() helps to draw a down figure of the button  with the specified style
static STATUS drawdownbutton( void *ctrl_str, S16 xSrc,S16 ySrc,S16 xDest,S16 yDest,U32 btn_style,char *caption_tag,P_U8 tagbk_saved,P_U8 bitmap,S16 bitmap_width,S16 bitmap_hight )
{
	//U8 grey;
	
	char	*dcaption;
	char	*tag;
	
	unsigned int		i;
	
	char	*captionandtag;
	
	STATUS 	rv = ASIX_OK;
	U32		pGC;
	U32		mod = 0;		//modified by xuanhui 2002/3/19

	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_DOWN;
		return ASIX_OK;
	}

	pGC = GetGC();
	//save the face of the button
	/*
	if( ( (ctrl_ptr->bt_face_saved) = Lmalloc( ((xDest-xSrc+2)*(yDest-ySrc+2)/4+1)*sizeof(U8) ) ) == NULL )
		return ASIX_ERROR;
	if( SaveRec( ctrl_ptr->bt_face_saved, (U16)xSrc-1, (U16)ySrc-1, (U16)xDest-xSrc+2,(U16)yDest-ySrc+2,0 ) != PPSM_OK )
		return ASIX_ERROR;
	*/
	//allocate a buffer to store the captionandtag string
	if( caption_tag != NULL )
	{
		// longn_qi 2002/01/25 for monitor memory leak
		asix_bt_memdbgprintf( "button appeal mem for its caption and tag" );
		captionandtag = Lcalloc( (strlen(caption_tag)+2)*sizeof(char) );
		if ( captionandtag == NULL ){
			rv = ASIX_NO_MEM;
			goto err_free2;
		}


		//modified by xuanhui 2002/3/19
		//for(i=0;i<=strlen(caption_tag);i++)
		for(i=0;i<strlen(caption_tag);i++)
		{
			captionandtag[i] = caption_tag[i];
		}
		//modified by xuanhui 2002/3/19
		//captionandtag[i+1] = '\0';
		captionandtag[i] = '\0';
	}else{
		captionandtag = NULL;
	}
	
	//seprate the captionandtag into caption and tag
	if( captionandtag != NULL && *captionandtag != '\0' )
	{
		//modified by xuanhui 2002/3/19
		//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' )
				{
					dcaption = captionandtag;
					tag = NULL;
				}else{
					captionandtag[i]='\0';
					dcaption = captionandtag;
					//modified by xuanhui 2002/3/19
					//tag = captionandtag+i+1;
					tag = captionandtag+(char)(i+1);
				}
				break;
			}
		}
	}else{
		dcaption = NULL;
		tag = NULL;
	}

//	if ( (btn_style & BS_SHADOW) &&( (LOWORD(btn_style)&BS_BOARD) == 0 ) )
//		DrawRec(pGC, ColorTheme.form_board,(U16)xSrc,(U16)ySrc,(U16)xDest,(U16)yDest,GPC_SOLID_LINE,GPC_REPLACE_STYLE);
	//modified by xuanhui 2002/3/27
	if( ctrl_ptr->bt_state & BTN_STATUS_REPAINT )
		drawbutton( ctrl_ptr, xSrc, ySrc, xDest, yDest, btn_style, caption_tag, bitmap, bitmap_width, bitmap_hight );
	
	if( ctrl_ptr->bt_state & BTN_STATUS_DOWN )
	{
		ctrl_ptr->bt_state = BTN_STATUS_UP;
	}
	else
	{
		ctrl_ptr->bt_state = BTN_STATUS_DOWN;
		if ( (btn_style & BS_SHADOW) &&( (LOWORD(btn_style)&BS_BOARD) == 0 ) )
		{
			InvRec(pGC, (U16)(xSrc), (U16)(yDest), (U16) (xDest-xSrc+1), 1);
			InvRec(pGC, (U16)(xDest), (U16)(ySrc), 1, (U16) (yDest-ySrc));	//modified by xuanhui 2002/4/4	
			InvRec(pGC, (U16)(xSrc), (U16)(ySrc), (U16) (xDest-xSrc), 1);		//modified by xuanhui 2002/4/4	
			InvRec(pGC, (U16)(xSrc), (U16)(ySrc+1), 1, (U16) (yDest-ySrc-1));	
		}
			InvRec(pGC, (U16)(xSrc+1), (U16)(ySrc+1), (U16) (xDest-xSrc-1), (U16) (yDest-ySrc-1) );
	}
	
	rv = drawbuttontag( ctrl_ptr, tag );

err_free2:
	
	// longn_qi 2002/01/25 for monitor memory leak
	if( captionandtag  != NULL )
		asix_bt_memdbgprintf( "button free mem of caption and tag" );
	Lfree( captionandtag );


	return rv;
	
}

STATUS drawbuttontag( struct bt_ctrl_str *ctrl_ptr, char *tag )
{
	ASIX_WINDOW		*pwnd;
	STATUS 	rv = ASIX_OK;
	U32		pGC;
	
	S16		xPos,yPos;
	S16		xSrc,ySrc;
	S16		xDest,yDest;
	U16		tag_x;
	U16		tag_y;
	U16		tag_xdest;
	U16		tag_ydest;
	U16		tag_hight;

	U32		mod = 0;		//modified by xuanhui 2002/3/19
	

	pwnd = (ASIX_WINDOW *)ctrl_ptr->wndid;
	pGC = GetGC();
	xSrc = pwnd->x;
	ySrc = pwnd->y;
	xDest = xSrc + pwnd->width -1;
	yDest = ySrc + pwnd->hight -1;

	//draw the tag
	if(tag != NULL )
	//if( strlen(tag)!=0 )			//modified by xuanhui 2002/3/19
	{
		// now fix the tag position for test ( longn_qi 2001/11/15 revised ) 
		//PenGetInput( &xPos, &yPos);
		//if ( xPos<0||xPos>SCREENWIDTH ) 
			xPos = xSrc+BTN_XTAG_INTERVAL;//need to repare
		//if ( yPos<0||yPos>SCREENHIGHT ) 
			yPos = yDest+BTN_YTAG_INTERVAL;
		
		//calculate the coordinate of the tag display the tag with BS_MULTILINE style
		
		//  /*增加了强制转换(U16), 修改了一些tag的坐标*/   modified by xuanhui 2002/3/19
		//if( (strlen(tag)*ENGLISH_CHAR_WIDTH>MAX_TAG_WIDTH) && ((ctrl_ptr->bt_style)&BS_MULTILINE))	//modified by xuanhui 2002/3/19
		if( ((U16)(strlen(tag)*ENGLISH_CHAR_WIDTH)>MAX_TAG_WIDTH) && ((ctrl_ptr->bt_style)&BS_MULTILINE))	//modified by xuanhui 2002/3/19
		{
			//conclude the x coordinate of the tag
			if( xPos > SCREENWIDTH/2 )
			{
				tag_x = (U16)(SCREENWIDTH - MAX_TAG_WIDTH - BTN_INTERVAL);
				tag_xdest = (U16)(SCREENWIDTH - BTN_INTERVAL-1);
			}else{
				tag_x = BTN_INTERVAL;
				tag_xdest = (U16)(MAX_TAG_WIDTH + 1);
			}
			
			if ( ((strlen(tag)*ENGLISH_CHAR_WIDTH)%(MAX_TAG_WIDTH-2)) != 0 )	//modified by xuanhui 2002/3/19
				mod = 1;
			tag_hight = (U16)( CHINESE_CHAR_HEIGHT*(((U16)strlen(tag)*ENGLISH_CHAR_WIDTH)/(MAX_TAG_WIDTH-2)+mod)+BTN_INTERVAL+2 );
			
			//conclude teh y coordinate of the tag
			if( (U16)(yPos + tag_hight +BTN_INTERVAL+1 ) > SCREENHIGHT )
			{
				//modified by xuanhui 2002/3/28
				if ( (U16)(BTN_INTERVAL+tag_hight+ BTN_YTAG_INTERVAL) <= (U16)(ySrc+1) )
					return ASIX_ERROR;
				else
				{
					tag_ydest = (U16)(ySrc - BTN_YTAG_INTERVAL);
					tag_y = (U16)(tag_ydest - tag_hight );
				}
			}else{
				tag_y = (U16)yPos ;
				tag_ydest =(U16)( tag_y + tag_hight );
			}
		}else{
			//calculate the coordinate of the tag if it will be displayed with normal style
			//to conclude if the xDest of the tag would extern the screen
			
			//modified by xuanhui 2002/3/19
			//if( (xPos+strlen(tag)*ENGLISH_CHAR_WIDTH+2) > (SCREENWIDTH-1) )
			if( ((U16)strlen(tag)*ENGLISH_CHAR_WIDTH+BTN_INTERVAL*2+2) > SCREENWIDTH )
			{
				//modified by xuanhui 2002/3/19
				//tag_xdest = SCREENWIDTH-1;
				//tag_x = SCREENWIDTH - strlen(tag)*8-2;//it may cause the x overflow
				//tag_x = (U16)xSrc;
				tag_xdest = (U16)(SCREENWIDTH-BTN_INTERVAL-1);
				tag_x = BTN_INTERVAL;
			}else{
				if( (xPos+strlen(tag)*ENGLISH_CHAR_WIDTH+BTN_INTERVAL+1) > (U16)(SCREENWIDTH-1) )
				{
					tag_xdest = (U16)(SCREENWIDTH-BTN_INTERVAL-1);
					tag_x = (U16)(tag_xdest-strlen(tag)*ENGLISH_CHAR_WIDTH-1);
				}
				else
				{
					tag_x = (U16)xPos;
					tag_xdest = (U16)xPos+(U16)strlen(tag)*ENGLISH_CHAR_WIDTH+BTN_INTERVAL;
				}
			}
			
			//to conclude if the yDest of the tag would extern the screen
			if( (U16)(yPos+BTN_TAG_HEIGHT+BTN_INTERVAL) > SCREENHIGHT )
			{
				//modified by xuanhui 2002/3/28
				if ( (U16)(BTN_INTERVAL+BTN_TAG_HEIGHT+ BTN_YTAG_INTERVAL-1) > (U16)ySrc )
					return ASIX_ERROR;
				else
				{
					tag_ydest = (U16)(ySrc-BTN_YTAG_INTERVAL);
					tag_y = (U16)(tag_ydest-BTN_TAG_HEIGHT);
				}
			}else{
				tag_y = (U16)yPos;
				tag_ydest = (U16)(tag_y+BTN_TAG_HEIGHT);
			}
		}
		
		if( ctrl_ptr->bt_tag_saved != NULL )
		{
			// longn_qi 2002/01/25 for monitor memory leak
			asix_bt_memdbgprintf( "button free mem of bt_tag_saved" );
			Lfree( ctrl_ptr->bt_tag_saved );
		}
				
		//save the backround which will be covered by the tag
		// longn_qi 2002/01/25 for monitor memory leak
		asix_bt_memdbgprintf( "button appeal mem for bt_tag_saved" );
//		if( ( (ctrl_ptr->bt_tag_saved) = Lcalloc( ((tag_xdest-tag_x+4)*(tag_ydest-tag_y+4)*BYTE_PER_PIXEL+2)*sizeof(U8) ) ) == NULL ) {
		if( ( (ctrl_ptr->bt_tag_saved) = (P_U8)GetBlock( (U16)(tag_xdest-tag_x+4), (U16)(tag_ydest-tag_y+4) ) ) == NULL ) {
			rv = ASIX_NO_MEM;
			goto err_free;
		}


		//modified by xuanhui 2002/3/19
		//SaveRec(pGC, (P_U16)ctrl_ptr->bt_tag_saved, (U16)tag_x,(U16)tag_y,(U16)(tag_xdest-tag_x+1),(U16)(tag_ydest-tag_y+1),0 );
		if ( SaveRec(pGC, (P_U16)ctrl_ptr->bt_tag_saved, tag_x,tag_y,(U16)(tag_xdest-tag_x+1),(U16)(tag_ydest-tag_y+1),0 )  != PPSM_OK )
			return ASIX_ERROR;
			
		ctrl_ptr->tag_x = tag_x;
		ctrl_ptr->tag_y = tag_y;
		ctrl_ptr->tag_width = tag_xdest-tag_x+1;
		ctrl_ptr->tag_hight = tag_ydest-tag_y+1;

		//draw the tag
		
		//modified by xuanhui 2002/3/19
		//DrawRec(pGC,GPC_BLACK,(U16)tag_x,(U16)tag_y,(U16)tag_xdest,(U16)tag_ydest,GPC_SOLID_LINE,GPC_REPLACE_STYLE); 
		//ClearRec( pGC,GPC_WHITE,(U16)(tag_x+1), (U16)(tag_y+1), (U16)(tag_xdest - tag_x - 2), (U16)(tag_ydest - tag_y - 2),GPC_REPLACE_STYLE );
		DrawRec(pGC,ColorTheme.form_board,tag_x,tag_y,tag_xdest,tag_ydest,GPC_SOLID_LINE,GPC_REPLACE_STYLE); 
		ClearRec( pGC,ColorTheme.form_backcolor ,(U16)(tag_x+1), (U16)(tag_y+1), (U16)(tag_xdest - tag_x - 1), (U16)(tag_ydest - tag_y - 1),GPC_REPLACE_STYLE );
		//Disp16StringGrey( BLACK,tag,(U16)tag_x+1,(U16)tag_y+1 );
		
		//modified by xuanhui 2002/3/19
		//DisplayMsg( tag, tag_x+1, tag_y+1, tag_xdest-1, tag_ydest-1, GPC_REPLACE_STYLE );
		DisplayMsg( tag, (S16)(tag_x+1), (S16)(tag_y+1+BTN_INTERVAL), (S16)(tag_xdest-1), (S16)(tag_ydest-1), GPC_REPLACE_STYLE );
	}

err_free:
	
	return rv;
}

STATUS MaskButton( U32 btid, U8 mode )
{
	ASIX_WINDOW	*wnd = (ASIX_WINDOW	*)btid;
	struct bt_ctrl_str *ctrl_ptr;

	if( wnd == NULL || wnd->wndclass->wndclass_id != WNDCLASS_BUTTON )
		return ASIX_ERROR;

	ctrl_ptr = (struct bt_ctrl_str *)wnd->ctrl_str;
	if( mode )
	{
		ctrl_ptr->bt_state |= BTN_STATUS_MASKED;
	}
	else
	{
		ctrl_ptr->bt_state &= ~BTN_STATUS_MASKED;
	}
	return ASIX_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -