📄 winbas.c
字号:
/******************************************************************************
*
* Copyright 2006 National ASIC Center, All right Reserved
*
* FILE NAME: winbas.c
* PROGRAMMER: ming.c
* Date of Creation: 2006/08/8
*
* DESCRIPTION:
*
* NOTE:
*
* FUNCTIONS LIST:
* -----------------------------------------------------------------------------
*
* -----------------------------------------------------------------------------
*
* MODIFICATION HISTORY
* LastModify 2006/09/20
******************************************************************************/
#include "mingui.h"
//--------------------------------------------------------------------------------
void DrawFrame(HDC dc,int left,int top,int width,int height,int focused,BOOL DownOrUp)
{ SetPenLogic(dc,PL_REPLACE);
#if (BITS_PER_PIXEL==1)
SetColor(dc,CL_WHITE);
DrawRect(dc, left,top,width,height);
SetColor(dc,CL_BLACK);
DrawRect(dc, left+1,top+1,width-2,height-2);
#elif 1 /*TButton按钮方式*/
if(focused)SetColor(dc,CL_BLACK);
else SetColor(dc,CL_DARKGRAY);
DrawVerLine(dc,left,top,height);
DrawHorLine(dc,left,top,width);
DrawVerLine(dc,left+width-1,top,height);
DrawHorLine(dc,left,top+height-1,width);
if(DownOrUp)
{ SetColor(dc,CL_DARKGRAY);
DrawVerLine(dc,left+1,top+1,height-2);
DrawHorLine(dc,left+1,top+1,width-2);
DrawVerLine(dc,left+width-2,top+1,height-2);
DrawHorLine(dc,left+1,top+height-2,width-2);
SetColor(dc,CL_LIGHTGRAY);
DrawVerLine(dc,left+width-3,top+2,height-4);
DrawHorLine(dc,left+2,top+height-3,width-4);
}
else
{ SetColor(dc,CL_WHITE);
DrawVerLine(dc,left+1,top+1,height-2);
DrawHorLine(dc,left+1,top+1,width-2);
SetColor(dc,CL_DARKGRAY);
DrawVerLine(dc,left+width-2,top+1,height-2);
DrawHorLine(dc,left+1,top+height-2,width-2);
if(focused)
{ DrawVerLine(dc,left+width-3,top+2,height-4);
DrawHorLine(dc,left+2,top+height-3,width-4);
}
}
#else /*TSpeedButton按钮方式*/
if(DownOrUp)
{ SetColor(dc,CL_DARKGRAY);
DrawVerLine(dc,left,top,height);
DrawHorLine(dc,left,top,width);
DrawVerLine(dc,left+1,top+1,height-2);
DrawHorLine(dc,left+1,top+1,width-2);
SetColor(dc,CL_WHITE);
DrawVerLine(dc,left+width-1,top,height);
DrawHorLine(dc,left,top+height-1,width);
DrawVerLine(dc,left+width-2,top+1,height-2);
DrawHorLine(dc,left+1,top+height-2,width-2);
}
else
{ SetColor(dc,CL_WHITE);
DrawVerLine(dc,left+1,top+1,height-2);
DrawHorLine(dc,left+1,top+1,width-2);
SetColor(dc,CL_DARKGRAY);
DrawVerLine(dc,left+width-2,top+1,height-2);
DrawHorLine(dc,left+1,top+height-2,width-2);
if(focused) SetColor(dc,CL_BLACK);
DrawVerLine(dc,left,top,height);
DrawHorLine(dc,left,top,width);
DrawVerLine(dc,left+width-1,top,height);
DrawHorLine(dc,left,top+height-1,width);
}
#endif
}
/*
* WIN Draw Library
* Draw3dShadow - draws a shadow with bottom-left and top-right missing
* Draw3dBox - draws a complete shadow
* Draw3dInset - draw a 2 line 3d inset
* Draw3dOutset - draw a 2 line 3d outset
*/
/*
* Draw3dShadow
* NOINDENT_BLACK T=white, B=black
* NOINDENT_GRAY T=white, B=dkgray
* INDENT_BLACK T=black, B=white
* INDENT_GRAY T=dkgray, B=white
*
* TTTTTTTTTTTTTT
* T B
* T B
* BBBBBBBBBBBBBB
*/
void Draw3dShadow(HDC hDC,int x,int y,int w,int h,TCOLOR crTop,TCOLOR crBottom)
{ SetColor(hDC,crTop);
DrawVerLine(hDC,x,y,h-1); /* left side*/
DrawHorLine(hDC,x+1,y,w-2); /* top side*/
SetColor(hDC,crBottom);
DrawVerLine(hDC,x+w-1,y+1,h-1); /* right side*/
DrawHorLine(hDC,x+1,y+h-1,w-2); /* bottom side*/
}
/*
* Draw3dBox
*
* TTTTTTTTTTTTTTB
* T B
* T B
* BBBBBBBBBBBBBBB
*/
void Draw3dBox(HDC hDC,int x,int y,int w,int h,TCOLOR crTop,TCOLOR crBottom)
{ SetColor(hDC,crTop);
DrawVerLine(hDC,x,y,h-1); /* left side*/
DrawHorLine(hDC,x+1,y,w-2); /* top side*/
SetColor(hDC,crBottom);
DrawVerLine(hDC,x+w-1,y,h); /* right side*/
DrawHorLine(hDC,x,y+h-1,w-1); /* bottom side*/
}
/*
* Draw 2 line deep 3d inset
*/
void Draw3dInset(HDC hDC,int x,int y,int w,int h)
{ PIXEL saved_color=((TWndCanvas *)hDC)->Foreground;
#if (BITS_PER_PIXEL==1)
SetColor(hDC,CL_WHITE);
DrawRect(hDC, x,y,w,h);
SetColor(hDC,CL_BLACK);
DrawRect(hDC, x+1,y+1,w-2,h-2);
#else
Draw3dBox(hDC, x, y, w, h,CL_BTNSHADOW, CL_BTNHIGHLIGHT);
Draw3dBox(hDC, x+1,y+1,w-2,h-2,CL_WINDOWFRAME,CL_3DLIGHT);
#endif
((TWndCanvas *)hDC)->Foreground=saved_color;
}
/*
* Draw 2 line deep 3d outset
*/
void Draw3dOutset(HDC hDC,int x,int y,int w,int h)
{ PIXEL saved_color=((TWndCanvas *)hDC)->Foreground;
#if (BITS_PER_PIXEL==1)
SetColor(hDC,CL_WHITE);
DrawRect(hDC, x,y,w,h);
SetColor(hDC,CL_BLACK);
DrawRect(hDC, x+1,y+1,w-2,h-2);
#else
Draw3dBox(hDC, x, y, w, h,CL_3DLIGHT, CL_WINDOWFRAME);
Draw3dBox(hDC, x+1,y+1,w-2,h-2,CL_BTNHIGHLIGHT, CL_BTNSHADOW);
#endif
((TWndCanvas *)hDC)->Foreground=saved_color;
}
//---------------------------------------------------------------------------
void IntToStr(char *strbuf,int data)
{ char tempbuf[16];
int pos=16;
tempbuf[--pos]=0;
do
{ tempbuf[--pos]='0'+(data%10);
data=data/10;
}while(data);
strcpy(strbuf,&tempbuf[pos]);
}
//---------------------------------------------------------------------------
void FloatToStr(char *strbuf,int iw,int fw,float fd)
{ char tempbuf[16];
int intdata=(int)fd;
int pos=16;
int iwidth=iw,fwidth=fw; /*ARM ADS对于char类型与int类型的带符号数之间的比较有问题*/
tempbuf[--pos]=0;
while(intdata && pos>0)
{ tempbuf[--pos]='0'+(intdata%10);
intdata=intdata/10;
iwidth--;
}
while(pos>0 && iwidth>0)
{ tempbuf[--pos]='0';
iwidth--;
}
strcpy(strbuf,&tempbuf[pos]);
pos=16-pos-1;
strbuf[pos++]='.';
fd=fd-(int)fd;
while(fwidth>0)
{ fd=fd*10;
strbuf[pos++]='0'+((int)fd % 10);
fwidth--;
}
strbuf[pos++]='\0';
}
//---------------------------------------------------------------------------
int StrToInt(char *data)
{ int ret=0;
if(data)
{ char ch;
for(ch=*data;ch!=0;ch=*++data)
{ if(ch>='0' && ch<='9')ret=ret*10+ (ch-'0');
}
}
return ret;
}
//---------------------------------------------------------------------------
int strcasecmp(const char *s1, const char *s2)
{ char c1, c2;
if(!s1 || !s2)
{ return (int)s1-(int)s2;
}
while (1)
{ if (*s1 == 0 || *s2 == 0) return 0;
c1 = *s1 | 0x20;;
c2 = *s2 | 0x20;;
if (c1 != c2) break;
s1++;
s2++;
}
return ((unsigned char)c1 - (unsigned char)c2);
}
//---------------------------------------------------------------------------
/* Pseudo-Random Number Generator", */
/* ACM Transactions on Modeling and Computer Simulation, */
/* Vol. 8, No. 1, January 1998, pp 3--30. */
/* Period parameters */
#define RND_N 624
#define RND_M 397
#define MATRIX_A 0x9908b0df /* constant vector a */
#define UPPER_MASK 0x80000000 /* most significant w-r bits */
#define LOWER_MASK 0x7fffffff /* least significant r bits */
/* Tempering parameters */
#define TEMPERING_MASK_B 0x9d2c5680
#define TEMPERING_MASK_C 0xefc60000
#define TEMPERING_SHIFT_U(y) (y >> 11)
#define TEMPERING_SHIFT_S(y) (y << 7)
#define TEMPERING_SHIFT_T(y) (y << 15)
#define TEMPERING_SHIFT_L(y) (y >> 18)
static unsigned long rnd_mt[RND_N]; /* the array for the state vector */
static int rnd_mti=RND_N+1; /* mti==N+1 means mt[N] is not initialized */
/* initializing the array with a NONZERO seed */
/* if sgenrand() has not been called,a default initial seed is used */
void InitRandom(unsigned long seed)
{ rnd_mt[0]= seed & 0xffffffff;
for (rnd_mti=1; rnd_mti<RND_N; rnd_mti++) rnd_mt[rnd_mti] = (69069 * rnd_mt[rnd_mti-1]) & 0xffffffff;
}
/* return a random ineger between 0 and 0xffffffff*/
unsigned long GenRandomWord(void)
{ unsigned long y;
static unsigned long mag01[2]={0x0, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */
if (rnd_mti >= RND_N) /* generate N words at one time */
{ int kk;
if (rnd_mti== RND_N+1) InitRandom(4357);
for (kk=0;kk<RND_N-RND_M;kk++)
{ y = (rnd_mt[kk]&UPPER_MASK)|(rnd_mt[kk+1]&LOWER_MASK);
rnd_mt[kk] = rnd_mt[kk+RND_M] ^ (y >> 1) ^ mag01[y & 0x1];
}
for (;kk<RND_N-1;kk++)
{ y = (rnd_mt[kk]&UPPER_MASK)|(rnd_mt[kk+1]&LOWER_MASK);
rnd_mt[kk] = rnd_mt[kk+(RND_M-RND_N)] ^ (y >> 1) ^ mag01[y & 0x1];
}
y = (rnd_mt[RND_N-1]&UPPER_MASK)|(rnd_mt[0]&LOWER_MASK);
rnd_mt[RND_N-1] = rnd_mt[RND_M-1] ^ (y >> 1) ^ mag01[y & 0x1];
rnd_mti = 0;
}
y = rnd_mt[rnd_mti++];
y ^= TEMPERING_SHIFT_U(y);
y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;
y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C;
y ^= TEMPERING_SHIFT_L(y);
return y;
}
/* return a random ineger between 0 and max*/
int GenRandom(int max)
{ return (int)(((double)max/0xffff)*((double)GenRandomWord()/0xffff));
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -