📄 appclasses.cpp
字号:
#include "appclasses.h"
#include "AEEStdLib.h"
Writer::Writer(): m_pIDisplay(0)
{
int charHeight, pnAscent, pnDescent;
IApplet *a = GETAPPINSTANCE();
IShell* pIShell = ((AEEApplet*)a)->m_pIShell;
ISHELL_CreateInstance(pIShell, AEECLSID_DISPLAY, (void **)&m_pIDisplay);
ISHELL_GetDeviceInfo(pIShell,&m_di);
charHeight = IDISPLAY_GetFontMetrics ((IDisplay*)m_pIDisplay, AEE_FONT_NORMAL,
&pnAscent, &pnDescent);
m_cMaxLine = (m_di.cyScreen / charHeight) - 3;
m_cLineNum = 1;
IDISPLAY_EraseRgn((IDisplay*)m_pIDisplay, 0, 0, m_di.cxScreen, m_di.cyScreen);
}
Writer::~Writer()
{
IDISPLAY_Release(m_pIDisplay);
}
void Writer::WriteLine(const char *pszStr)
{
char ellipsis[4];
STRCPY(ellipsis, "...");
if (m_cLineNum > m_cMaxLine)
return;
if (m_cLineNum == m_cMaxLine)
{
DisplayOutput(m_cLineNum++, ellipsis);
return;
}
m_cLineNum += DisplayOutput(m_cLineNum, pszStr);
IDISPLAY_UpdateEx((IDisplay*)m_pIDisplay, TRUE);
return;
}
void Writer::WriteLine(int i)
{
char ch[12];
SPRINTF(ch, "%ld", i);
WriteLine(ch);
}
int Writer::DisplayOutput(int nline, const char *pszStr)
{
AECHAR * szBuf; // a buffer that supports 200 char string
AECHAR * psz = NULL;
int charHeight = 0; // Stores the char height in pixels for given font
int pnAscent = 0; // Stores the ascent in number of pixels
int pnDescent = 0; // Stores the descent in number of pixels
int pixelWidth;
AEEFont font = AEE_FONT_NORMAL;
int pnFits = 0, dy;
int totalCh = 0;
int numLinesPrinted = 0;
if (m_pIDisplay == NULL)
return 0;
if ((szBuf = (AECHAR *) MALLOC(TEXT_BUFFER_SIZE)) == NULL)
return 0;
charHeight = IDISPLAY_GetFontMetrics ((IDisplay*)m_pIDisplay, AEE_FONT_NORMAL,
&pnAscent, &pnDescent);
STR_TO_WSTR ((char *)pszStr, szBuf, TEXT_BUFFER_SIZE);
if (nline < 0) {
dy = m_di.cyScreen*2/5;
}
else{
dy = nline * charHeight + 5;
}
psz = szBuf;
totalCh = STRLEN ((char *)pszStr);
while ((totalCh > 0) && (*psz != NULL))
{
pixelWidth = IDISPLAY_MeasureTextEx((IDisplay*)m_pIDisplay,
font,
(AECHAR *) psz, // Start of the buffer to display,
-1,
m_di.cxScreen - 5, // maxWidth
&pnFits); // Number of chars that will fit a line
// If pnFits is zero there is something wrong in the input to above function.
// Normally this scenario should not occur. But, have the check anyway.
if (pnFits == 0)
{
FREE(szBuf);
return 0;
}
IDISPLAY_DrawText((IDisplay*)m_pIDisplay, AEE_FONT_NORMAL, psz, pnFits, 5 /*start dx*/,
dy, 0 /* use default rectangle coordinates */, 0);
psz += pnFits; // move pointer to the next segment to be displayed
totalCh -= pnFits; // reduce the total number of characters to still display
dy += charHeight; // Place next line charHeight pixels below the
// previous line.
++numLinesPrinted;
IDISPLAY_Update((IDisplay*)m_pIDisplay); //, TRUE);
if (totalCh < pnFits)
pnFits = totalCh; // if total number is less than pnFits, adjust pnFits
}
FREE(szBuf);
return numLinesPrinted;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -