📄 gui.c
字号:
if(pRgn->ClipArray[i].hWnd==hWnd)
return TRUE;
}
return FALSE;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
BOOL AddClipRect(CLIPRGN* pRgn,CLIPRECT ClipRect)
{
if(pRgn->ClipNum>=64) return FALSE;
pRgn->ClipArray[pRgn->ClipNum]=ClipRect;
pRgn->ClipNum++;
return TRUE;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
BOOL EditClipRect(CLIPRGN* pRgn,HWND hWnd,CLIPRECT ClipRect)
{
int i;
for(i=0;i<pRgn->ClipNum;i++)
if(pRgn->ClipArray[i].hWnd==hWnd)
{
pRgn->ClipArray[i]=ClipRect;
}
return TRUE;
}
//--------------------------------------------------------------------------
// check3
//--------------------------------------------------------------------------
BOOL DelClipRect(CLIPRGN* pRgn,HWND hWnd)
{
int aPos,i;
if(pRgn->ClipNum==0) return FALSE;
for(i=0;i<pRgn->ClipNum;i++)
if(pRgn->ClipArray[i].hWnd==hWnd) break;
if(i==pRgn->ClipNum) return FALSE;
aPos=i;
for(i=aPos;i<pRgn->ClipNum-1;i++)
pRgn->ClipArray[i]=pRgn->ClipArray[i+1];
memset(&pRgn->ClipArray[i],0,sizeof(CLIPRECT));
pRgn->ClipNum--;
return TRUE;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
BOOL ClipRectLoop(RECTRGN* pInvRgn,RECT* pClipRect)
{
RECT ISRect; //相交矩形
RESIDUALRGN ResRng; //残余矩形
RECTRGN tempRng;
int i,j;
tempRng.rcNum=0;
for(i=0;i<pInvRgn->rcNum;i++)
if(IntersectRect(&ISRect,&(pInvRgn->rc[i]),pClipRect))
{
InciseClipRect(&ResRng,&(pInvRgn->rc[i]),pClipRect);
for(j=0;j<ResRng.rcNum;j++)
{
tempRng.rc[tempRng.rcNum]=ResRng.rc[j];
tempRng.rcNum++;
}
if(ResRng.rcNum<=0) //相交且不剩余则为全部遮挡区
{
pInvRgn->rc[i]=SetRect(0,0,0,0);
}
}
else
{
tempRng.rc[tempRng.rcNum]=pInvRgn->rc[i];
tempRng.rcNum++;
}
if(tempRng.rcNum!=0)
{
memcpy(pInvRgn,&tempRng,sizeof(RECTRGN));
}
return TRUE;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void InvalidRectToVram(HDC hdc,RECT* pInvRect)
{
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void SendInvalidRect(HWND hWnd,RECT InvRect)
{
KnlMes mes;
HINSTANCE hInstance;
hInstance=0;
mes.MessageType=MES_ERASE;
mes.Param1=SETLONGWORD(InvRect.left,InvRect.top);
mes.Param2=SETLONGWORD(InvRect.right-InvRect.left,InvRect.bottom-InvRect.top);
mes.hWnd= (unsigned long)(hWnd);
mes.hInstance=hInstance;
KnlSendMessage(hWnd,mes);
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void SetAboveClipRgn(HWND hWnd)
{
HWND CurHWnd=hWnd;
CLIPRECT ClipRect;
RECT winRect;
HDC hdc;
WINSTRUCT* pWin=GetCurWinSolt(hWnd);
if(CurHWnd==hWinTail) return;
winRect=pWin->winRect;
ClipRect.bExist=TRUE;
while(CurHWnd!=hWinTail)
{
CurHWnd=GetNextWinSolt(CurHWnd);
hdc=GetDC(CurHWnd);
if(!FindClipRect(&(pWin->winHDC->ecrgn),CurHWnd))
{
if(IntersectRect(&ClipRect.rc,&hdc->Bounds,&winRect))
{
ClipRect.hWnd=CurHWnd;
AddClipRect(&(pWin->winHDC->ecrgn),ClipRect);
}
}
else
{
if(IntersectRect(&ClipRect.rc,&hdc->Bounds,&winRect))
{
ClipRect.hWnd=CurHWnd;
EditClipRect(&(pWin->winHDC->ecrgn),CurHWnd,ClipRect);
}
else
{
DelClipRect(&(pWin->winHDC->ecrgn),CurHWnd);
}
}
}
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void SetBelowClipRgn(HWND hWnd)
{
HWND CurHWnd=hWnd;
CLIPRECT ClipRect;
RECT winRect;
HDC hdc=GetDC(hWnd);
winRect=hdc->Bounds;
ClipRect.bExist=TRUE;
ClipRect.hWnd=hWnd;
while(CurHWnd!=hWinHead)
{
CurHWnd=GetPrevWinSolt(CurHWnd);
hdc=GetDC(CurHWnd);
if(!FindClipRect(&hdc->ecrgn,hWnd))
{
if(IntersectRect(&ClipRect.rc,&hdc->Bounds,&winRect))
AddClipRect(&hdc->ecrgn,ClipRect);
}
else
{
if(IntersectRect(&ClipRect.rc,&hdc->Bounds,&winRect))
EditClipRect(&hdc->ecrgn,hWnd,ClipRect);
else
DelClipRect(&hdc->ecrgn,hWnd);
}
}
}
//------------------------------------------------------------------------
//
//------------------------------------------------------------------------
void HdcSetPixel(HDC hdc,int x,int y)
{
int sw=hdc->Bounds.right-hdc->Bounds.left;
int sh=hdc->Bounds.bottom-hdc->Bounds.top;
if(x<0 || x>sw-1 || y<0 || y>sh-1) return;
hdc->mBuf[y*sw+x]=hdc->penColor;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void HdcDrawVline(HDC hdc,int x1,int x2,int y)
{
register int i;
for(i=x1;i<x2;i++)
HdcSetPixel(hdc,i,y);
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void HdcDrawHline(HDC hdc,int y1,int y2,int x)
{
register int i;
for(i=y1;i<y2;i++)
HdcSetPixel(hdc,x,i);
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void HdcSetBkColor(HDC hdc,unsigned long color)
{
hdc->bkColor=color;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void HdcSetBrushColor(HDC hdc,unsigned long color)
{
hdc->brushColor=color;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void HdcSetPenColor(HDC hdc,unsigned long color)
{
hdc->penColor=color;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void HdcSetTextColor(HDC hdc,unsigned long color)
{
hdc->textColor=color;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void HdcFillRect(HDC hdc,int x,int y,int w,int h)
{
int i;
HdcSetPenColor(hdc,hdc->brushColor);
for(i=y;i<y+h;i++)
HdcDrawVline(hdc,x,x+w,i);
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
__inline RGB GetRGB(unsigned char r,unsigned char g,unsigned char b)
{
register unsigned long RGBr;
register unsigned long RGBg;
register unsigned long RGBb;
RGBr=(unsigned long)r;
RGBr=RGBr<<16;
RGBg=(unsigned long)g;
RGBg=RGBg<<8;
RGBb=(unsigned long)b;
return (unsigned long)(RGBr | RGBg | RGBb);
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
unsigned char GetRGBr(RGB aRGB)
{
aRGB = aRGB & 0xFF0000;
aRGB = aRGB >> 16;
return (unsigned char)aRGB;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
unsigned char GetRGBg(RGB aRGB)
{
aRGB = aRGB & 0x00FF00;
aRGB = aRGB >> 8;
return (unsigned char)aRGB;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
unsigned char GetRGBb(RGB aRGB)
{
aRGB = aRGB & 0x0000FF;
return (unsigned char)aRGB;
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void DrawFadeColor(HDC hdc,int x,int y,int w,int h,RGB FromColor)
{
int i;
int scale;
unsigned char FR;
unsigned char FG;
unsigned char FB;
FR = GetRGBr(FromColor);
FG = GetRGBg(FromColor);
FB = GetRGBb(FromColor);
scale=12*w/255;
for(i=0;i<w;i++)
{
HdcSetPenColor(hdc,GetRGB(FR+2*(i/scale),FG+2*(i/scale),FB+2*(i/scale)));
HdcDrawHline(hdc,y,y+h,x+i);
}
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void DrawWinTitleBar(HDC hdc,int x,int y,int w,int h,RGB aColor)
{
RGB FromColor=aColor;
DrawFadeColor(hdc,x,y,w,h,FromColor);
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void DrawWinUpFram(HDC hdc,int x,int y,int w,int h)
{
HdcSetPenColor(hdc,0xFFFFFF);
HdcDrawHline(hdc,y,y+h,x);
HdcDrawVline(hdc,x,x+w,y);
HdcSetPenColor(hdc,0x000000);
HdcDrawHline(hdc,y,y+h-1,x+w-1);
HdcDrawVline(hdc,x,x+w-1,y+h-1);
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void SetBelowInvalidRng(HWND hWnd,RECT OldRect)
{
RECT InvRect;
RECT ISRect;
RESIDUALRGN ResRgn;
HDC hdc;
HWND CurHWnd=hWnd;
int i;
hdc=GetDC(hWnd);
if(IntersectRect(&ISRect,&hdc->Bounds,&OldRect))
InciseClipRect(&ResRgn,&OldRect,&hdc->Bounds);
else
{
ResRgn.rcNum=1;
ResRgn.rc[0]=OldRect;
}
while(CurHWnd!=hWinHead)
{
CurHWnd=GetPrevWinSolt(CurHWnd);
for(i=0;i<ResRgn.rcNum;i++)
{
InvRect=ScreenRectToDC(GetDC(CurHWnd),&ResRgn.rc[i]);
SendInvalidRect(CurHWnd,InvRect);
}
}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------------------------------------------------------------------
void SetActiveWindow(HWND hWnd)
{
WINSTRUCT* pWin;
KnlMes mes;
SetTopWindow(hWnd);
pWin=GetCurWinSolt(hWinTail);
while(pWin->hWnd!=hWinHead)
{
if(pWin->winStyle==eWinNormal && pWin->hWnd!=hWnd)
{
mes.MessageType=MES_WND_KILL_ACTIVE;
KnlSendMessage(pWin->hWnd,mes);
}
pWin=GetCurWinSolt(pWin->hWinPrev);
}
pWin=GetCurWinSolt(hWnd);
if(pWin->winStyle==eWinNormal)
{
mes.MessageType=MES_WND_ACTIVE;
KnlSendMessage(pWin->hWnd,mes);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -