📄 uibitmap.c
字号:
/*********************************************************
FILE: bitmap.c
Basic Window Widget : bitmap
Copyright (c) 2001, Reality Technology CO. LTD.
AUTHOR: Cangers <gh_chan@sina.com>
HISTORY: >2001-10-11 17:25 changeed OK
**********************************************************/
#include <pr2k.h>
#include <uiwnd.h>
#include <typedefine.h>
#include <uiGui_cfg.h>
#include <uiUtility.h>
#include <uiFont.h>
#include <uiGraph.h>
#include "uibitmap.h"
/*************************<<PRIVATE DECLARE>>**************************/
static STATUS _guiBitmap_Delete( HNDL handle );
static STATUS _guiBitmap_Show( HNDL handle );
static int _guiBitmap_Action(HNDL handle , WORD Pen_Type, WORD x , WORD y);
static int _guiBitmap_ShowString( HNDL handle );
/*************************<<PUBLIC FUN>>****************************/
DLL_EXP(HNDL) guiBitmap_Create( WORD left, WORD top, WORD right, WORD bottom, const BYTE* fg_image,WORD Style)
{
PTGUIBITMAP ptBitmap;
WORD nwi=0,nhi=0;
if(right <= left || bottom <= top)
return 0;
if(fg_image)
{
nwi = guiGetImageWidth(fg_image);
nhi = guiGetImageHeight(fg_image);
}
guiEnterWCS() ;
ptBitmap=(PTGUIBITMAP)kernelMalloc(sizeof(TGUIBITMAP));
if(ptBitmap == NULL)
{
guiExitWCS() ;
return 0;
}
memset(ptBitmap,0,sizeof(TGUIBITMAP));
ptBitmap->base.handle =(HNDL)ptBitmap;//handle is the pointer which point to this structure,identify the control
ptBitmap->base.checkFlag = GUI_CONTROL_CHECK_FLAG;//9296 this field would be a special value, it's able to bToggle_Check,the handle available or not
ptBitmap->base.left = left;
ptBitmap->base.top = top;
ptBitmap->base.right = right;
ptBitmap->base.bottom = bottom;
ptBitmap->bColor = GUI_WHITE;
if(nwi>(ptBitmap->base.right-ptBitmap->base.left+1))
ptBitmap->base.right = ptBitmap->base.left + nwi-1;
if( nhi>(ptBitmap->base.bottom-ptBitmap->base.top+1))
ptBitmap->base.bottom = ptBitmap->base.top + nhi-1;
ptBitmap->base.type = CONTROL_BITMAP; // indicate the type of the control.
ptBitmap->base.style = Style;
ptBitmap->base.status = 0; //ACTIVE or not
ptBitmap->base.vportHandle = NULL;
ptBitmap->base.container = NULL;
ptBitmap->base.font = GUI_DEFAULT_FONT;
ptBitmap->base.actionFun =(PF_ACTION )_guiBitmap_Action;
ptBitmap->base.showFun =(PF_SHOW)_guiBitmap_Show;
ptBitmap->base.delFun =(PF_DELETE)_guiBitmap_Delete;
ptBitmap->bg_image = NULL;
strcpy((char *)ptBitmap->szCaption,"");
ptBitmap->fg_image = (unsigned char*)fg_image;
ptBitmap->bToggle_Check = 0;
ptBitmap->pic_left = 0;
ptBitmap->pic_top = 0;
guiExitWCS() ;
return (DWORD)ptBitmap;
}
//------------------------------------------------------------------------------------------------------
static STATUS _guiBitmap_Delete( HNDL handle )
{
PTGUIBITMAP ptBitmap;
if(handle == NULL)
{
return STATUS_ERR;
}
guiEnterWCS() ;
ptBitmap=(PTGUIBITMAP)handle;
if(ptBitmap->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
kernelFree((PTGUIBITMAP)handle);
handle = 0;
guiExitWCS() ;
return STATUS_OK;
}
//------------------------------------------------------------------------------------------------------
static STATUS _guiBitmap_Show( HNDL handle )
{
PTGUIBITMAP ptBitmap;
WORD style=0;
unsigned short left=0,right=0,top=0,bottom=0;
unsigned short sx,sy,width,height;
if(handle == NULL)
{
return STATUS_ERR;
}
if(!guiControl_IsVisible(handle))
return STATUS_ERR;
guiEnterWCS() ;
ptBitmap=(PTGUIBITMAP)handle;
if(ptBitmap->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
// processCoordinateStart(handle);
left = 0;
right = ptBitmap->base.right-ptBitmap->base.left;
top = 0;
bottom = ptBitmap->base.bottom - ptBitmap->base.top;
// processCoordinateEnd(handle) ;
if(ptBitmap->fg_image == NULL)
{
guiExitWCS() ;
return STATUS_ERR;
}
width = guiGetImageWidth(ptBitmap->fg_image);
height = guiGetImageHeight(ptBitmap->fg_image);
if( ptBitmap->szCaption [0]== '\0')
{
sy = top+(bottom - top +1 - height)/2;
sx = left+(right -left+1 - width)/2;
guiClearBlock(handle, left,top,right,bottom,ptBitmap->bColor,REPLACE_STYLE);
}
else
{
sy = top+ptBitmap->pic_top;
sx = left+ptBitmap->pic_left;
guiClearBlock(handle, left,top,right,bottom,ptBitmap->bColor,REPLACE_STYLE);
}
style = ptBitmap->base.style&0xFF;
if(style&BMP_TOGGLE && ptBitmap->bToggle_Check == TOGGLE_ONCHECKED )
{
if(style&BMP_DIMAGE)
{
width = guiGetImageWidth(ptBitmap->bg_image);
height = guiGetImageHeight(ptBitmap->bg_image);
if(ptBitmap->szCaption [0] != '\0')
{
sy = top+ptBitmap->pic_top;
sx = left+ptBitmap->pic_left;
}
else
{
sx = left+(right -left+1 - width)/2;
sy = top+(bottom - top +1 - height)/2;
}
guiPutImage(handle,sx,sy,sx+width,sy+height,ptBitmap->bg_image);
_guiBitmap_ShowString(handle ) ;
}
else
{
width = guiGetImageWidth(ptBitmap->fg_image);
height = guiGetImageHeight(ptBitmap->fg_image);
if(ptBitmap->szCaption [0] != '\0')
{
sy = top+ptBitmap->pic_top;
sx = left+ptBitmap->pic_left;
}
else
{
sx = left+(right -left+1 - width)/2;
sy = top+(bottom - top +1 - height)/2;
}
guiPutImage(handle,sx,sy,sx+width,sy+height,ptBitmap->fg_image);
_guiBitmap_ShowString(handle );
guiInvertRect (handle,left,top,right,bottom);
}
}
else
{
width = guiGetImageWidth(ptBitmap->fg_image);
height = guiGetImageHeight(ptBitmap->fg_image);
if(ptBitmap->szCaption [0] != '\0')
{
sy = top+ptBitmap->pic_top;
sx = left+ptBitmap->pic_left;
}
else
{
sx = left+(right -left+1 - width)/2;
sy = top+(bottom - top +1 - height)/2;
}
guiPutImage(handle,sx,sy,sx+width,sy+height,ptBitmap->fg_image);
_guiBitmap_ShowString(handle );
}
// ptBitmap->base.status = CONTROL_ACTIVE;
guiExitWCS() ;
return STATUS_OK;
}
//------------------------------------------------------------------------------------------------------------
DLL_EXP(STATUS) guiBitmap_SetImage( HNDL handle, const BYTE *fg_image )
{
PTGUIBITMAP ptBitmap;
WORD nhi,nwi;
if(handle == NULL || fg_image == NULL)
{
return STATUS_ERR;
}
guiEnterWCS() ;
ptBitmap=(PTGUIBITMAP)handle;
if(ptBitmap->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
nwi = guiGetImageWidth(fg_image);
nhi = guiGetImageHeight(fg_image);
if(nwi>(ptBitmap->base.right-ptBitmap->base.left+1))
ptBitmap->base.right = ptBitmap->base.left + nwi-1;
if( nhi>(ptBitmap->base.bottom-ptBitmap->base.top+1))
ptBitmap->base.bottom = ptBitmap->base.top + nhi-1;
ptBitmap->fg_image = (unsigned char*)fg_image;
guiExitWCS() ;
ptBitmap->base.showFun(handle);
return STATUS_OK;
}
//---------------------------------------------------------------------------------------------------------
DLL_EXP(STATUS) guiBitmap_SetDouble( HNDL handle, const BYTE *bg_image )
{
PTGUIBITMAP ptBitmap;
if(handle == NULL || bg_image == NULL)
{
return STATUS_ERR;
}
guiEnterWCS() ;
ptBitmap=(PTGUIBITMAP)handle;
if(ptBitmap->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
ptBitmap->bToggle_Check = 0;
ptBitmap->bg_image = (unsigned char*)bg_image;
if(ptBitmap->base.style&BMP_TOGGLE )//|| BMP_WINCLOSE)
ptBitmap->base.style |= BMP_DIMAGE;
else if(ptBitmap->base.style&BMP_WINCLOSE && !(ptBitmap->base.style&BMP_NON_BUTTON))
ptBitmap->base.style = BMP_DIMAGE|BMP_WINCLOSE;
else ptBitmap->base.style = BMP_DIMAGE;
guiExitWCS() ;
return STATUS_OK;
}
//------------------------------------------------------------------------------------------------------------
//DLL_EXP(STATUS) guiBitmap_SetString( HNDL handle, const char *szCaption )
DLL_EXP(STATUS) guiBitmap_SetString( HNDL handle, TBitmapCaption *szCaption)
{
PTGUIBITMAP ptBitmap;
int i;
if(handle == NULL || szCaption == NULL)
{
return STATUS_ERR;
}
/*
if((szCaption->[0] ==0) && (szCaption[1][0] ==0) && (szCaption[2][0] ==0))
{
return STATUS_ERR;
}
*/
guiEnterWCS() ;
ptBitmap=(PTGUIBITMAP)handle;
if(ptBitmap->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
//strcpy((char *)ptBitmap->szCaption,"");
//strncpy((char *)ptBitmap->szCaption, (char *)szCaption,BMP_STRING_MAX_LENGTH);
strcpy((char *)ptBitmap->szCaption[0],"");
strncpy((char *)ptBitmap->szCaption[0], szCaption->szCaption_ENG, BMP_STRING_MAX_LENGTH);
strcpy((char *)ptBitmap->szCaption[1],"");
strncpy((char *)ptBitmap->szCaption[1], szCaption->szCaption_CHT, BMP_STRING_MAX_LENGTH);
strcpy((char *)ptBitmap->szCaption[2],"");
strncpy((char *)ptBitmap->szCaption[2], szCaption->szCaption_CHS, BMP_STRING_MAX_LENGTH);
guiExitWCS() ;
ptBitmap->base.showFun(handle);
return STATUS_OK;
}
//------------------------------------------------------------------------------------------------------------------
DLL_EXP(STATUS) guiBitmap_SetPicLocation ( HNDL handle, WORD left,WORD top )
{
PTGUIBITMAP ptBitmap;
if(handle == NULL )
{
return STATUS_ERR;
}
guiEnterWCS() ;
ptBitmap=(PTGUIBITMAP)handle;
if(ptBitmap->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
ptBitmap->pic_left = left;
ptBitmap->pic_top = top;
guiExitWCS() ;
ptBitmap->base.showFun(handle);
return STATUS_OK;
}
//----------------------------------------------------------------------------------------------------------------------
DLL_EXP(STATUS) guiBitmap_SetValue( HNDL handle, int bToggle_Check )
{
PTGUIBITMAP ptBitmap;
if(handle == NULL)
{
return STATUS_ERR;
}
ptBitmap=(PTGUIBITMAP)handle;
if( ptBitmap->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
return STATUS_ERR;
if(ptBitmap->base.style & BMP_TOGGLE)
{
if(bToggle_Check>=1) bToggle_Check=1;
else bToggle_Check = 0;
ptBitmap->bToggle_Check = bToggle_Check;
}
else return STATUS_ERR;
ptBitmap->base.showFun(handle);
return STATUS_OK;
}
//-----------------------------------------------------------------------------------------------------------------------
DLL_EXP(int) guiBitmap_GetValue( HNDL handle )
{
PTGUIBITMAP ptBitmap;
int Value;
if(handle == NULL)
{
return STATUS_ERR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -