📄 guicontrol.c
字号:
#define USING_MEMDC
/**************************GUIControl.c*********************************
*
* Copyright (C) 2003 by ALi Corporation. All Rights Reserved.
*
* File: GUIControl.c
*
* Contents:
* To draw GUI Control -- Implementation
*
* History:
* Date By Reason Ver.
* ====================================
* 2003/07 Gordon J.H. CHEN Create v1.0
*
***********************************************************************/
#include "GUIControl.h"
/*********************************************************************
*********************************************************************/
//Common GUI Attribute
//private: none
#define DOGGIE_RADIUS 8
/*********************************************************************
*********************************************************************/
//Common GUI Operation
//public: shared to MPO_LowLevel.c, MPA_LowLevel.c, VRTitleList.c
//Usage: 1. SetDevMode(lpDevMode...);
// InitializeDC(hdc, lpDevMode);
// 2. Create...(hdc, ...);
// ...
// 3. TerminizeDC(hdc);
void GUI_CreateButtonControl(HDC hdc, RECT *lpRect, COLORREF clBk, COLORREF clTopEdge, COLORREF clBotEdge, COLORREF clText, BYTE *sCaption, BOOL bUniNorm, UINT iAlign, int iSpace); //Create button control using ordinary dc
void GUI_CreateBitmapControl(HDC hdc, RECT *lpRect, COLORREF clBk, COLORREF clTopEdge, COLORREF clBotEdge, UINT iBitmapID, int iLSpace, int iTSpace);//Create bitmap control using ordinary dc
void GUI_CreateLeftMidRightBitmap(HDC hdc, RECT *lpRect, UINT iLeftTopBmpID, UINT iMiddleBmpID, UINT iRightBotBmpID, BOOL isLeftMidRight);//Create composed bitmap control using ordinary dc
//private: if needed, can be shared
void GUI_SetDevMode(DEVMODE *lpDevMode, int iWidth, int iHeight);
void GUI_InitializeDC(HDC *lpHdc, DEVMODE *lpDevMode, float bMplayerMixRatio);
void GUI_TerminizeDC(HDC *lpHdc);
void GUI_CreateButtonControl2(HDC hdc, RECT *lpRect, COLORREF clBk, COLORREF clTopEdge, COLORREF clBotEdge, COLORREF clText, BYTE *sCaption, BOOL bUniNorm, UINT iAlign, int iSpace);
void GUI_CreateBitmapControl2(HDC hdc, RECT *lpRect, COLORREF clBk, COLORREF clTopEdge, COLORREF clBotEdge, UINT iBitmapID, int iLSpace, int iTSpace);
void GUI_CreateLeftMidRightBitmap2(HDC hdc, RECT *lpRect, UINT iLeftTopBmpID, UINT iMiddleBmpID, UINT iRightBotBmpID, BOOL isLeftMidRight);
#if 0
void GUI_CreateLine(HDC hdc, COLORREF clLine, int iFromX, INT iFromY, int iToX, int iToY);
void GUI_CreateCycle(HDC hdc, COLORREF clBk, COLORREF clEdge, int iCenterX, INT iCenterY, INT iRadius);
#endif
/*********************************************************************
*********************************************************************/
// And now, implementation begins ...
/********************************************************************/
// Set DC size
void GUI_SetDevMode(DEVMODE *lpDevMode, int iWidth, int iHeight)
{
lpDevMode->dmSize=sizeof(DEVMODE);
lpDevMode->dmPelsWidth=iWidth;
lpDevMode->dmPelsHeight=iHeight;
lpDevMode->dmBitsPerPel=4; //dq modify this for 16 colors
lpDevMode->dmDriverExtra=0;
lpDevMode->dmFields=DM_BITSPERPEL |DM_PELSWIDTH | DM_PELSHEIGHT;
}
/********************************************************************/
// Create DC
void GUI_InitializeDC(HDC *lpHdc, DEVMODE *lpDevMode, float fMixRation) // if dc is passed in , we share other's dc, don't create new one
{
BYTE mix;
if(*lpHdc)
;
else
*lpHdc=CreateDC("DISPLAY", "OSD", NULL, lpDevMode);
mix=(int)(fMixRation*16);
ExtEscape(*lpHdc, SET_PRIMARY_SURFACE_MIXRATIO, 1, &mix, 0, NULL);
}
/********************************************************************/
// Delete DC
void GUI_TerminizeDC(HDC *lpHdc) // if dc is passed in , we shared other's dc, then should not delete it of course
{
DeleteDC(*lpHdc);
*lpHdc=NULL;
}
/********************************************************************/
// Create Button Control using Memory DC
void GUI_CreateButtonControl(HDC hdc, RECT *lpRect, COLORREF clBk, COLORREF clTopEdge, COLORREF clBotEdge, COLORREF clText, BYTE *sCaption, BOOL bUniNorm, UINT iAlign, int iSpace)
{
// i prefer use COLORREF instead of ColorIndex, for 1. effiency, eg. Flat Button, if use ColorIndex, 3 time of GetColorInDef256Palette will be called
HBRUSH hbr, oldHbr;
HPEN bkPen, leftPen, rightPen, oldPen;
RECT rectText, rectDoggies;
BOOL bDrawLeftBorder, bDrawTopBorder, bDrawRightBorder, bDrawBotBorder;
HDC hMemDC;
HBITMAP hOldBmp;
RECT rect;
if(!hdc)
return;
#ifdef USING_MEMDC
if(clBk==CL_BKNOCARE || clBk==CL_TRANSPARENT)
#else
if(1)
#endif
{
GUI_CreateButtonControl2(hdc, lpRect, clBk, clTopEdge, clBotEdge, clText, sCaption, bUniNorm, iAlign, iSpace);
return;
}
else
{
// I modified lpRect meaning as 0x0000: the highest 4 bits stand for no border or else. the lowest 12 bits stand for real position.
// Temporarily, It should be no problem, for dc at most (608, 416), but 2^12=4096, that is enough.
EvelateBorder(lpRect, &bDrawLeftBorder, &bDrawTopBorder, &bDrawRightBorder, &bDrawBotBorder);
lpRect->left=lpRect->left & 0x0fff;
lpRect->top = lpRect->top & 0x0fff;
lpRect->right=lpRect->right & 0x0fff;
lpRect->bottom=lpRect->bottom & 0x0fff;
// 1
hMemDC=InitMemoryDC(hdc, lpRect->right-lpRect->left+1, lpRect->bottom-lpRect->top+1, &hOldBmp);
rect.left=0;
rect.right=lpRect->right-lpRect->left;
rect.top=0;
rect.bottom=lpRect->bottom-lpRect->top;
DrawEdgedRectangle(hMemDC, &rect, clBk, clTopEdge, clBotEdge,bDrawLeftBorder, bDrawTopBorder, bDrawRightBorder, bDrawBotBorder);
}
if(((bUniNorm==NORMAL_STRING) && (strcmp(sCaption, "")==0)) ||
((bUniNorm==UNICODE_STRING) && (sCaption[0]==0x00) && (sCaption[1]==0x00)))
;
else
{
DrawTextInRectangel(hMemDC, &rect, bDrawRightBorder, clText, sCaption, bUniNorm, iAlign, iSpace);
}
// 2
BitBlt(hdc, lpRect->left, lpRect->top, lpRect->right-lpRect->left, lpRect->bottom-lpRect->top, hMemDC, 1,0,SRCCOPY);
// 3
DelMemoryDC(hMemDC, hOldBmp);
}
void EvelateBorder(RECT *lpRect, BOOL *pbDrawLeftBorder, BOOL *pbDrawTopBorder, BOOL *pbDrawRightBorder, BOOL *pbDrawBotBorder)
{
*pbDrawLeftBorder=((lpRect->left & RECTBORDER_NOLEFT) == RECTBORDER_NOLEFT)? FALSE:TRUE;
*pbDrawTopBorder=((lpRect->top & RECTBORDER_NOTOP) == RECTBORDER_NOTOP)?FALSE:TRUE;
*pbDrawRightBorder=((lpRect->right & RECTBORDER_NORIGHT) == RECTBORDER_NORIGHT)?FALSE:TRUE;
*pbDrawBotBorder=((lpRect->bottom & RECTBORDER_NOBOT)== RECTBORDER_NOBOT)?FALSE:TRUE;
}
/********************************************************************/
// Create Button Control using Ordinary DC, it should be used only for clear some area instead of draw button
void GUI_CreateButtonControl2(HDC hdc, RECT *lpRect, COLORREF clBk, COLORREF clTopEdge, COLORREF clBotEdge, COLORREF clText, BYTE *sCaption, BOOL bUniNorm, UINT iAlign, int iSpace)
{
// i prefer use COLORREF instead of ColorIndex, for 1. effiency, eg. Flat Button, if use ColorIndex, 3 time of GetColorInDef256Palette will be called
HBRUSH hbr, oldHbr;
HPEN bkPen, leftPen, rightPen, oldPen;
RECT rectText, rectDoggies;
BOOL bDrawLeftBorder, bDrawTopBorder, bDrawRightBorder, bDrawBotBorder;
if(!hdc)
return;
// I modified lpRect meaning as 0x0000: the highest 4 bits stand for no border or else. the lowest 12 bits stand for real position.
// Temporarily, It should be no problem, for dc at most (608, 416), but 2^12=4096, that is enough.
EvelateBorder(lpRect, &bDrawLeftBorder, &bDrawTopBorder, &bDrawRightBorder, &bDrawBotBorder);
lpRect->left=lpRect->left & 0x0fff;
lpRect->top = lpRect->top & 0x0fff;
lpRect->right=lpRect->right & 0x0fff;
lpRect->bottom=lpRect->bottom & 0x0fff;
if(clBk==CL_BKNOCARE)
;
else
{
DrawEdgedRectangle(hdc, lpRect, clBk, clTopEdge, clBotEdge,bDrawLeftBorder, bDrawTopBorder, bDrawRightBorder, bDrawBotBorder);
}
if(((bUniNorm==NORMAL_STRING) && (strcmp(sCaption, "")==0)) ||
((bUniNorm==UNICODE_STRING) && (sCaption[0]==0x00) && (sCaption[1]==0x00)))
;
else
{
DrawTextInRectangel(hdc, lpRect, bDrawRightBorder, clText, sCaption, bUniNorm, iAlign, iSpace);
}
}
void DrawEdgedRectangle(HDC hdc, RECT *lpRect, COLORREF clBk, COLORREF clTopEdge, COLORREF clBotEdge, BOOL bDrawLeftBorder, BOOL bDrawTopBorder, BOOL bDrawRightBorder, BOOL bDrawBotBorder)
{
HBRUSH hbr;
HPEN bkPen, leftPen, rightPen, oldPen;
hbr=CreateSolidBrush(clBk);
FillRect(hdc,lpRect,hbr);
DeleteObject((HGDIOBJ)hbr);
bkPen = CreatePen(PS_SOLID, 1, clBk);
leftPen = CreatePen(PS_SOLID, 1, clTopEdge);
//left border
if(bDrawLeftBorder)
oldPen=(HPEN)SelectObject(hdc,(HGDIOBJ)leftPen);
else
oldPen=(HPEN)SelectObject(hdc,(HGDIOBJ)bkPen);
MoveToEx(hdc, lpRect->left , lpRect->top, NULL);
LineTo(hdc,lpRect->left, lpRect->bottom-1);
MoveToEx(hdc, 1 + lpRect->left , 1 + lpRect->top, NULL);
LineTo(hdc,1+lpRect->left,lpRect->bottom-2);
SelectObject(hdc, (HGDIOBJ)oldPen);
//top border
if(bDrawTopBorder)
oldPen=(HPEN)SelectObject(hdc,(HGDIOBJ)leftPen);
else
oldPen=(HPEN)SelectObject(hdc,(HGDIOBJ)bkPen);
MoveToEx(hdc, lpRect->left , lpRect->top, NULL);
LineTo(hdc,lpRect->right-1, lpRect->top);
MoveToEx(hdc, 1 + lpRect->left, 1 + lpRect->top, NULL);
LineTo(hdc,lpRect->right-2,1+lpRect->top);
SelectObject(hdc, (HGDIOBJ)oldPen);
DeleteObject((HGDIOBJ)leftPen);
rightPen = CreatePen(PS_SOLID, 1, clBotEdge);
//right border
if(bDrawRightBorder)
oldPen=(HPEN)SelectObject(hdc,(HGDIOBJ)rightPen);
else
oldPen=(HPEN)SelectObject(hdc,(HGDIOBJ)bkPen);
MoveToEx(hdc, lpRect->right-1, lpRect->bottom-1, NULL);
LineTo(hdc,lpRect->right-1, lpRect->top);
MoveToEx(hdc, lpRect->right-2, lpRect->bottom-2, NULL);
LineTo(hdc,lpRect->right-2, lpRect->top-1);
SelectObject(hdc, (HGDIOBJ)oldPen);
//bottom border
if(bDrawBotBorder)
oldPen=(HPEN)SelectObject(hdc,(HGDIOBJ)rightPen);
else
oldPen=(HPEN)SelectObject(hdc,(HGDIOBJ)bkPen);
MoveToEx(hdc, lpRect->right-1,lpRect->bottom-1, NULL);
LineTo(hdc,lpRect->left,lpRect->bottom-1);
MoveToEx(hdc, lpRect->right-2,lpRect->bottom-2, NULL);
LineTo(hdc,lpRect->left+1,lpRect->bottom-2);
SelectObject(hdc, (HGDIOBJ)oldPen);
DeleteObject((HGDIOBJ)rightPen);
DeleteObject((HGDIOBJ)bkPen);
}
void DrawTextInRectangel(HDC hdc, RECT *lpRect, BOOL bDrawRightBorder, COLORREF clText, BYTE *sCaption, BOOL bUniNorm, UINT iAlign, int iSpace)
{
RECT rectText;
iSpace=iSpace>0?iSpace:-iSpace;
rectText.left=(iAlign==DT_LEFT)?lpRect->left+iSpace:lpRect->left;
if(bDrawRightBorder)
rectText.right=(iAlign==DT_RIGHT)?lpRect->right-iSpace-2:lpRect->right-2;
else
rectText.right=(iAlign==DT_RIGHT)?lpRect->right-iSpace:lpRect->right;
rectText.top=lpRect->top;
rectText.bottom=(iAlign==DT_CENTER)?lpRect->bottom-iSpace:lpRect->bottom;;
SetTextColor(hdc,clText);
SetBkMode(hdc, TRANSPARENT);
if(bUniNorm==NORMAL_STRING)
DrawText(hdc,UNICODE(sCaption),-1,&rectText,iAlign |DT_SINGLELINE|DT_VCENTER | DT_OPAQUE); // | DT_CHARCLIP
else
DrawText(hdc,sCaption,-1,&rectText,iAlign |DT_SINGLELINE|DT_VCENTER | DT_OPAQUE); // | DT_CHARCLIP
}
/********************************************************************/
// Bitmap control
void GUI_CreateBitmapControl(HDC hdc, RECT *lpRect, COLORREF clBk, COLORREF clTopEdge, COLORREF clBotEdge, UINT iBitmapID, int iLSpace, int iTSpace)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -