📄 rscreenutils.cpp
字号:
// Copyright 2002 Kenneth Guy,
//
// RScreenUtils.cpp
/** \file RScreenUtils.cpp
implementation of class RScreenUtils */
#include <e32std.h>
#include <e32svr.h>
//data
#include "numbers.h"
#include "RScreenUtils.h"
/** Draw a picture on the screen.
\param aPicture picture to draw */
void RScreenUtils::DrawPicture(TPicture &aPicture) {
DrawPictureAsm(&aPicture);
}
/** Blank an area of the screen
\param aBlank area to blank */
void RScreenUtils::BlankArea(TBlank &aBlank) {
BlankAreaAsm(&aBlank);
}
/** constuctor */
RScreenUtils::RScreenUtils() : iScreenBase(NULL) {
}
/** Initialize class.
Gets the screen info and works out the screen base address.
\return KErrNone if successful, KErrNotSupported if: the screen is not 640x200 or the screen info is not available.
*/
TInt RScreenUtils::Open() {
// get the screen info so we can work out the base address of the screen
TPckgBuf<TScreenInfoV01> info;
UserSvr::ScreenInfo(info);
if(info().iScreenAddressValid==EFalse ||
info().iScreenSize.iWidth!=640 ||
info().iScreenSize.iHeight!=200) {
return KErrNotSupported;
}
// screen memory is 2 bytes per pixel, top 4 bits unused,
// 4 bits green, 4 bits blue.
iScreenBase=STATIC_CAST(TUint16*,info().iScreenAddress);
// there is palette information at the start of the screen
// memory, for 12 bits per pixel this is 16 2 byte entries,
// the first of which defines that the pixel size is 12 bits.
// actual pallete information is ignored.
iScreenBase += 16;
return (KErrNone);
}
/** Base address of screen memory */
TUint16 *RScreenUtils::ScreenBase() {
return iScreenBase;
}
/** Close */
void RScreenUtils::Close() {
iScreenBase=NULL;
}
/** Draw a number in decimal.
Converts the number to binary coded decimal then calls HexNumber()
to plot it.
\param aX X position to draw at (0-319)
\param aY Y position to draw at (0-199)
\param aNumber number to draw (0-999999), will wrap after that
\param aForeColor foreground color
\param aBackColor background color
*/
void RScreenUtils::Number(TUint aX,TUint aY,TUint32 aNumber,
TUint16 aForeColor,TUint16 aBackColor){
HexNumber(aX,aY,BCDNumber(aNumber),aForeColor,aBackColor);
}
/** Draw a number in hexdecimal.
\param aX X position to draw at (0-319)
\param aY Y position to draw at (0-199)
\param aNumber number to draw (0-FFFFFFF), will wrap after that
\param aForeColor foreground color
\param aBackColor background color
*/
void RScreenUtils::HexNumber(TUint aX,TUint aY,TUint32 aNumber,
TUint16 aForeColor,TUint16 aBackColor){
if(iScreenBase==NULL)
return;
TUint offset=aX+aY*640;
NumberAsm(iScreenBase+offset,aNumber,aForeColor,aBackColor);
}
/** Clear screen to color.
\param aColor color to fill the screen with
*/
void RScreenUtils::Blank(TUint16 aColor) {
if(iScreenBase==NULL)
return;
BlankAsm(aColor);
}
/** Convert a number to BCD */
TUint32 RScreenUtils::BCDNumber(TUint32 aNumber) {
TUint32 out=0;
TInt digit=0;
while(aNumber!=0) {
out += (aNumber%10) << (4*digit);
digit++;
aNumber /= 10;
}
return out;
}
/** \fn static void RScreenUtils::NumberAsm(TUint16 *aPos,TUint32 aNumber, TUint16 aForeColor,TUint16 aBackColor)
Draws a hex number on the screen.
\param aPos memory location to draw number
\param aNumber number to draw (0-FFFFFFF), will wrap after that
\param aForeColor foreground color
\param aBackColor background color
defined in the file number.s
*/
/** \fn void RScreenUtils::BlankAsm(TUint16 aColor);
Blank the whole screen
\param aColor color to fill the screen with
defined in the file blank.s
*/
/** \fn void RScreenUtils::BlankAreaAsm(TBlank *aBlank)
Blank an area of the screen
\param aBlank area and color to clear
defined in the file blankarea.s
*/
/** \fn void RScreenUtils::DrawPictureAsm(TPicture *aPicture)
Draw a picture on the screen
\param aPicture sprite information and location
defined in the file drawpicture.s
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -