📄 brewlogincanvasbase.cpp
字号:
// BrewLoginCanvasBase.cpp: implementation of the CBrewLoginCanvasBase class.
//
//////////////////////////////////////////////////////////////////////
#include "BrewLoginCanvasBase.h"
#include "brewlogin.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBrewLoginCanvasBase::CBrewLoginCanvasBase()
{
m_nOldID = 0;
m_pSelTag = NULL;
m_bSelLine = true;
m_nBGID = 0;
m_pBkgrd = m_bmpBG = NULL;
m_nFontSpace = FONT_SPACE;
m_aCtls = NULL;
m_nLChSize = 0;
m_nNChSize = 0;
m_bRedraw = 2;
m_nTotalLine = 0;
m_nControls = m_nTotalDisplayLine = m_nFirstLine = m_nCurrent = 0;
m_bTopBar = m_bBottomBar = true;
m_nTitle = IDS_LOGIN_TEXT;
m_bWelcome = FALSE;
m_pWelcome = NULL;
m_nWelcome = 0;
m_nVScrollBarWidth = 0;
m_bSaveBK = false;
}
CBrewLoginCanvasBase::~CBrewLoginCanvasBase()
{
RELEASEIF(m_bmpBG,IBITMAP);
RELEASEIF(m_pBkgrd,IBITMAP);
RELEASEIF(m_pSelTag,IBITMAP);
}
void CBrewLoginCanvasBase::paint(IDisplay *d, IGraphics *g)
{
if(m_nNChSize == 0)
{
SetDisplayInfo(d);
m_pIGraphics = g;
}
//IDISPLAY_ClearScreen(d);
DrawBackGround();
AEERect rt;
if(m_bTopBar)
{
GetTopBarRect(rt);
IDISPLAY_DrawRect(d,&rt,
RGB_WHITE,MAKE_RGB(181,182,173),IDF_RECT_FILL);
IDISPLAY_DrawText(d, // Display instance
AEE_FONT_LARGE, // Use BOLD font
GetDispText(m_nTitle), // Text - Normally comes from resource
-1, // -1 = Use full string length
0, // Ignored - IDF_ALIGN_CENTER
0, // Ignored - IDF_ALIGN_MIDDLE
&rt, // No clipping
IDF_ALIGN_LEFT | IDF_TEXT_TRANSPARENT | IDF_ALIGN_MIDDLE );
}
if(m_bBottomBar)
{
GetBottomBarRect(rt);
IDISPLAY_DrawRect(d,&rt,
RGB_WHITE,MAKE_RGB(181,182,173),IDF_RECT_FILL);
IDISPLAY_DrawText(d, // Display instance
AEE_FONT_LARGE, // Use BOLD font
GetDispText(IDS_CMN_OK), // Text - Normally comes from resource
-1, // -1 = Use full string length
0, // Ignored - IDF_ALIGN_CENTER
0, // Ignored - IDF_ALIGN_MIDDLE
&rt, // No clipping
IDF_ALIGN_RIGHT | IDF_TEXT_TRANSPARENT | IDF_ALIGN_MIDDLE );
IDISPLAY_DrawText(d, // Display instance
AEE_FONT_LARGE, // Use BOLD font
GetDispText(IDS_CMN_BACK), // Text - Normally comes from resource
-1, // -1 = Use full string length
0, // Ignored - IDF_ALIGN_CENTER
0, // Ignored - IDF_ALIGN_MIDDLE
&rt, // No clipping
IDF_ALIGN_LEFT | IDF_TEXT_TRANSPARENT | IDF_ALIGN_MIDDLE );
}
if(m_bWelcome)
{
if(m_rtWelcome.dx == 0)
{
int n = IDISPLAY_MeasureText( d, m_nNowFont, m_pWelcome);
SETAEERECT(&m_rtWelcome,0,0,n,m_nNowSize+m_nFontSpace);
m_nWelcome = m_offsetX;
}
if(m_nWelcome < -(m_rtWelcome.dx))
m_nWelcome = m_offsetX + m_cxScreen;
m_nWelcome -= 2;
AEERect rt,rtButton;
SETAEERECT(&rt,m_nWelcome,m_rtWelcome.y+m_offsetY,m_rtWelcome.dx,m_rtWelcome.dy);
SETAEERECT(&rtButton,m_offsetX,m_offsetY,m_cxScreen,m_rtWelcome.dy);
DrawButton(&rtButton);
IDISPLAY_DrawText(d, // Display instance
m_nNowFont, // Use BOLD font
m_pWelcome, // Text - Normally comes from resource
-1, // -1 = Use full string length
0, // Ignored - IDF_ALIGN_CENTER
0, // Ignored - IDF_ALIGN_MIDDLE
&rt, // No clipping
IDF_ALIGN_LEFT | IDF_TEXT_TRANSPARENT | IDF_ALIGN_MIDDLE );
DrawButton(&rtButton,false);
}
DrawScrollBar();
//if(m_bRedraw != 0)
// m_bRedraw--;
}
boolean CBrewLoginCanvasBase::keyPressed(UINT16 code, UINT32 param)
{
return false;
}
boolean CBrewLoginCanvasBase::keyReleased(UINT16 code, UINT32 param)
{
return false;
}
boolean CBrewLoginCanvasBase::keyRepeated(UINT16 code, UINT32 param)
{
//DBGPRINTF("oo\n");
if(code == AVK_UP || code == AVK_DOWN ||
code == AVK_LEFT || code == AVK_RIGHT)
return key(code,param);
return false;
}
boolean CBrewLoginCanvasBase::key(UINT16 code, UINT32 param)
{
IControl* p = GetActiveCtrl();
//if(p)
{
switch(code )
{
case AVK_UP:
{
if(m_bSelLine)
{
if(!(m_nFirstLine == m_nCurrent && m_nCurrent == 0))
{
if(m_nFirstLine > 0 && m_nCurrent == m_nFirstLine)
{
m_nFirstLine--;
SetActiveCtrl(-1);
}
else //if(m_nFirstLine != m_nCurrent)
SetActiveCtrl(-1);
}
else
{
m_nCurrent = m_nTotalLine - 1;
m_nFirstLine = m_nCurrent - m_nTotalDisplayLine + 1;
if(m_nFirstLine < 0)
m_nFirstLine = 0;
SetActiveCtrl(0);
}
}
else
{
if(m_nFirstLine > 0)
m_nFirstLine--;
}
Invalidate();
int i;
if(m_aCtls && m_nCurrent < m_nControls)
for(i = 0; i < 20; i++)
ICONTROL_HandleEvent(m_aCtls[m_nCurrent],EVT_KEY,AVK_RIGHT,0);
return true;
}
break;
case AVK_DOWN:
{
if(m_bSelLine)
{
if(m_nCurrent == m_nTotalLine - 1)
{
m_nFirstLine = m_nCurrent = 0;
SetActiveCtrl(0);
}
else if(m_nFirstLine < m_nTotalLine - m_nTotalDisplayLine && m_nCurrent+1 == m_nFirstLine+
m_nTotalDisplayLine)
{
m_nFirstLine++;
SetActiveCtrl(1);
}
else if(m_nCurrent+1 < m_nFirstLine +
m_nTotalDisplayLine && m_nCurrent + 1 < m_nTotalLine)
SetActiveCtrl(1);
}
else
{
if(m_nFirstLine + m_nTotalDisplayLine < m_nTotalLine)
m_nFirstLine++;
}
Invalidate();
int i;
if(m_aCtls && m_nCurrent < m_nControls)
for(i = 0; i < 20; i++)
ICONTROL_HandleEvent(m_aCtls[m_nCurrent],EVT_KEY,AVK_RIGHT,0);
return true;
}
break;
}
boolean bb = false;
if(p)
bb = ICONTROL_HandleEvent(p,EVT_KEY,code,param);
return bb;
//bb++;
}
return false;
}
void CBrewLoginCanvasBase::GetTopBarRect(AEERect& rt)
{
//rt.x = 0;
//rt.y = 0;
rt.x = m_offsetX;
rt.y = m_offsetY;
rt.dx = m_cxScreen;
rt.dy = m_nNowSize + m_nFontSpace;
}
void CBrewLoginCanvasBase::GetBottomBarRect(AEERect& rt)
{
//rt.x = 0;
rt.x = m_offsetX;
rt.y = m_offsetY;
rt.y += m_cyScreen - m_nNowSize - m_nFontSpace;
rt.dx = m_cxScreen;
rt.dy = m_nNowSize + m_nFontSpace;
}
void CBrewLoginCanvasBase::GetMainRect(AEERect& rt)
{
//rt.x = 0;
rt.x = m_offsetX;
rt.y = m_offsetY;
if(m_bTopBar)
rt.y += m_nNowSize + m_nFontSpace;
else if(m_bWelcome)
rt.y += m_nNowSize + m_nFontSpace;
//else
//rt.y = 0;
rt.dx = m_cxScreen;
rt.dy = m_cyScreen;
if(m_bBottomBar)
rt.dy = rt.dy - m_nNowSize - m_nFontSpace;
if(m_bTopBar)
rt.dy = rt.dy - m_nNowSize - m_nFontSpace;
if(m_bWelcome)
rt.dy = rt.dy - m_nNowSize - m_nFontSpace;
}
int CBrewLoginCanvasBase::GetLineRect(int whichline,AEERect& rt)
{
//if(m_aCtls == NULL)
// return -1;
AEERect rtmain,rttop;
GetInfoRect();
SETAEERECT(&rtmain,m_rtInfo.x,m_rtInfo.y,m_rtInfo.dx,
m_rtInfo.dy);
GetTopBarRect(rttop);
int nPerline = (m_nNowSize+m_nFontSpace);
int ntotal = rtmain.dy / nPerline;
if(whichline - m_nFirstLine >= ntotal || whichline < m_nFirstLine )
{
SETAEERECT(&rt,0,0,0,0);
return -1;
}
else
{
//rt.x = 0;
rt.x = rtmain.x;
rt.y = rtmain.y;
//if(!m_bTopBar)
rttop.dy = 0;
rt.y += nPerline*(whichline - m_nFirstLine) + rttop.dy;
rt.dx = rtmain.dx;
rt.dy = nPerline;
}
return ntotal;
}
void CBrewLoginCanvasBase::SetActiveCtrl(int8 pos)
{
if(pos == 0)
{
int i;
if(m_aCtls != NULL)
for(i = 0; i < m_nControls; i++)
if(i == m_nCurrent)
if(!ICONTROL_IsActive(m_aCtls[i]))
ICONTROL_SetActive(m_aCtls[i],true);
return;
}
int i;
if(m_aCtls != NULL)
for(i = 0; i < m_nControls; i++)
if(ICONTROL_IsActive(m_aCtls[i]))
ICONTROL_SetActive(m_aCtls[i],false);
m_nCurrent += pos;
if(m_nCurrent < 0)
m_nCurrent += m_nTotalLine;
if(m_nCurrent >= m_nTotalLine)
m_nCurrent -= m_nTotalLine;
if(m_nCurrent >= m_nTotalLine || m_nCurrent < 0)
m_nCurrent = 0;
if(m_aCtls != NULL && m_nCurrent < m_nControls)
ICONTROL_SetActive(m_aCtls[m_nCurrent],true);
}
IControl* CBrewLoginCanvasBase::GetActiveCtrl()
{
if(m_aCtls == NULL || m_nCurrent >= m_nControls)
return NULL;
return m_aCtls[m_nCurrent];
}
void CBrewLoginCanvasBase::Invalidate()
{
m_bRedraw = 2;
}
void CBrewLoginCanvasBase::SetDisplayInfo(IDisplay* d)
{
int nAscent, nDescent;
AEEDeviceInfo * pdi;
//pdi = (AEEDeviceInfo*)MALLOC(sizeof(AEEDeviceInfo));
//ISHELL_GetDeviceInfo(((CBrewLogin*)frame)->m_pIShell, pdi);
pdi = m_pdi;
if (!pdi)
return;
m_cxScreen = pdi->cxScreen;
m_cyScreen = pdi->cyScreen;
m_nColorDepth = pdi->nColorDepth;
//FREEIF(pdi);
IDISPLAY_GetFontMetrics(d, AEE_FONT_LARGE, &nAscent, &nDescent);
m_nLChSize = nAscent + nDescent;
IDISPLAY_GetFontMetrics(d, AEE_FONT_NORMAL, &nAscent, &nDescent);
m_nNChSize = nAscent + nDescent;
SetFont(AEE_FONT_NORMAL);
AEERect rt;
m_nTotalDisplayLine = GetLineRect(0,rt);
m_pIDisplay = d;
GetInfoRect();
if(m_nBGID != 0)
{
m_bmpBG = ISHELL_LoadResBitmap(m_pShell,GAMEVV_RES_FILE,
m_nBGID);
if(m_bmpBG != NULL)
{
AEEBitmapInfo bi;
IBITMAP_GetInfo(m_bmpBG,&bi,sizeof(bi));
SETAEERECT(&m_rtBG,0,0,bi.cx,bi.cy);
}
}
}
void CBrewLoginCanvasBase::GetFitRect(AEERect* pInRtBig,AEERect* pInRtSmall,
AEERect* pOutRt,uint32 dwFlags )
{
if(dwFlags & IDF_ALIGN_CENTER)
{
pOutRt->x = pInRtBig->x + (pInRtBig->dx - pInRtSmall->dx) / 2;
pOutRt->dx = pInRtSmall->dx;
}
else if(dwFlags & IDF_ALIGN_RIGHT)
{
pOutRt->x = pInRtBig->x + pInRtBig->dx - pInRtSmall->dx;
pOutRt->dx = pInRtSmall->dx;
}
else
// if(dwFlags & IDF_ALIGN_LEFT || dwFlags == 0)
{
pOutRt->x = pInRtBig->x;
pOutRt->dx = pInRtSmall->dx;
}
if(dwFlags & IDF_ALIGN_MIDDLE)
{
pOutRt->y = pInRtBig->y + (pInRtBig->dy - pInRtSmall->dy) / 2;
pOutRt->dy = pInRtSmall->dy;
}
else if(dwFlags & IDF_ALIGN_BOTTOM)
{
pOutRt->y = pInRtBig->y + pInRtBig->dy - pInRtSmall->dy;
pOutRt->dy = pInRtSmall->dy;
}
//if(dwFlags & IDF_ALIGN_TOP || dwFlags == 0)
else
{
pOutRt->y = pInRtBig->y;
pOutRt->dy = pInRtSmall->dy;
}
}
void CBrewLoginCanvasBase::DrawScrollBar()
{
if(m_nTotalDisplayLine >= m_nTotalLine)
return;
AEERect rt = m_rtInfo;
rt.x = rt.x + rt.dx;
rt.dx = m_nVScrollBarWidth;
AEERect rtsc = rt;
rtsc.dy = (m_nTotalDisplayLine* rt.dy) / m_nTotalLine;
rtsc.y = (m_nFirstLine)* rt.dy / m_nTotalLine
+ rt.y;
if(m_nFirstLine + m_nTotalDisplayLine >= m_nTotalLine)
rtsc.y = rt.y + rt.dy - rtsc.dy; //已经是最后一屏
IDISPLAY_FillRect(m_pIDisplay,&rt,MAKE_RGB(255,255,255));
//rt.x += 1;
//rt.dx -= 1;
IDISPLAY_DrawRect(m_pIDisplay,&rt,
MAKE_RGB(201,233,197),0,IDF_RECT_FRAME);
IDISPLAY_FillRect(m_pIDisplay,&rtsc,MAKE_RGB(0,255,0));
DrawButton(&rtsc);
//AEERect lbtn;
//SETAEERECT(&lbtn,rt.x,rt.y,m_nVScrollBarWidth,m_nVScrollBarWidth);
//DrawButton(&lbtn);
/*
AEEPoint pt[3];
AEEPolyline polyline;
polyline.len = 3;
polyline.points = pt;
pt[0].x = m_rtInfo.x + m_rtInfo.dx - m_offsetX;
pt[0].y = m_rtInfo.y + m_nVScrollBarWidth - m_offsetY;
pt[1].x = pt[0].x + m_nVScrollBarWidth / 2;
pt[1].y = m_rtInfo.y - m_offsetY;
pt[2].x = pt[0].x + m_nVScrollBarWidth;
pt[2].y = m_rtInfo.y + m_nVScrollBarWidth - m_offsetY;
IGRAPHICS_SetColor(m_pIGraphics,0,0,0,255);
IGRAPHICS_DrawPolyline(m_pIGraphics,&polyline);
*/
}
void CBrewLoginCanvasBase::DrawBackGround()
{
if(m_nBGID == 0)
return;
AEERect rt;
GetMainRect(rt);
if(m_pBkgrd == NULL)
{
if(m_bSaveBK)
{
IBitmap* pDeviceBitmap;
if( IDISPLAY_GetDeviceBitmap( m_pIDisplay, &pDeviceBitmap ) != SUCCESS )
return ;
if( IBITMAP_CreateCompatibleBitmap( pDeviceBitmap, &m_pBkgrd,
m_cxScreen+2*rt.x,m_cyScreen+2*rt.y) != SUCCESS )
{
IBITMAP_Release( pDeviceBitmap );
return;
}
IBITMAP_Release( pDeviceBitmap );
}
int x,y;
y = 0;
while(y < rt.dy)
{
x = 0;
while(x < rt.dx)
{
int dx = MIN(m_rtBG.dx,rt.dx - x);
int dy = MIN(m_rtBG.dy,rt.dy - y);
if(!m_bSaveBK)
IDISPLAY_BitBlt(m_pIDisplay, rt.x + x, rt.y + y,
dx,dy ,(void*)m_bmpBG,0,0,AEE_RO_COPY);
else
IBITMAP_BltIn(m_pBkgrd, rt.x + x, rt.y + y,
dx,dy ,m_bmpBG,0,0,AEE_RO_COPY);
x += m_rtBG.dx;
}
y += m_rtBG.dy;
}
//RELEASEIF(m_bmpBG,IBITMAP);
}
if(m_bSaveBK)
IDISPLAY_BitBlt(m_pIDisplay, rt.x, rt.y,
rt.dx,rt.dy ,(void*)m_pBkgrd,rt.x,rt.y,AEE_RO_COPY);
}
void CBrewLoginCanvasBase::DrawButton(AEERect* prt,boolean bFill)
{
//prt->x += 1;
//prt->dx -= 2;
AEERect rtcopy;
MEMCPY(&rtcopy,prt,sizeof(AEERect));
if(bFill)
{
IDISPLAY_FillRect(m_pIDisplay,prt,MAKE_RGB(236,233,216));
IDISPLAY_FillRect(m_pIDisplay,prt,MAKE_RGB(181,182,173));
}
prt->x -= m_offsetX;
prt->y -= m_offsetY;
//return;
AEEPoint pt[3];
AEEPolyline polyline;
polyline.len = 3;
polyline.points = pt;
pt[0].x = prt->x;
pt[0].y = prt->y + prt->dy;
pt[1].x = prt->x;
pt[1].y = prt->y;
pt[2].x = prt->x + prt->dx;
pt[2].y = prt->y;
IGRAPHICS_SetColor(m_pIGraphics,255,255,255,255);
IGRAPHICS_DrawPolyline(m_pIGraphics,&polyline);
pt[1].x = prt->x + prt->dx;
pt[1].y = prt->y + prt->dy;
IGRAPHICS_SetColor(m_pIGraphics,0,0,0,255);
IGRAPHICS_DrawPolyline(m_pIGraphics,&polyline);
MEMCPY(prt,&rtcopy,sizeof(AEERect));
}
AECHAR* CBrewLoginCanvasBase::GetDispText(int nID)
{
if(nID != m_nOldID)
{
MEMSET(m_pDispText,0,sizeof(m_pDispText));
ISHELL_LoadResString(m_pShell,GAMEVV_RES_FILE,
nID,m_pDispText,sizeof(m_pDispText));
}
return m_pDispText;
}
void CBrewLoginCanvasBase::DrawSelTag(int nStrID)
{
if(m_pSelTag == NULL)
{
m_pSelTag = ISHELL_LoadResBitmap(m_pShell,GAMEVV_RES_FILE,IDB_MAIN_BARROW);
if(m_pSelTag == NULL)
return;
NativeColor color;
color = IBITMAP_RGBToNative(m_pSelTag, MAKE_RGB(255,0,255));
IBITMAP_SetTransparencyColor(m_pSelTag, color);
}
int n = IDISPLAY_MeasureText(m_pIDisplay,m_nNowFont,GetDispText(nStrID));
AEEBitmapInfo bi;
IBITMAP_GetInfo(m_pSelTag, &bi, sizeof(bi));
AEERect rtline,rtdraw,rtin;
GetLineRect(m_nCurrent,rtline);
SETAEERECT(&rtin,0,0,n,bi.cy);
GetFitRect(&rtline,&rtin,&rtdraw,IDF_ALIGN_MIDDLE|IDF_ALIGN_CENTER);
rtdraw.x -= (int16)bi.cx + 2;
rtdraw.dx = (int16)bi.cx;
IDISPLAY_BitBlt(m_pIDisplay,rtdraw.x,rtdraw.y,bi.cx,bi.cy,(void*)m_pSelTag,0,0,AEE_RO_TRANSPARENT);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -