📄 utility.h
字号:
//////////////////////////////////////////////////////////////////////
// File: Utility.h
//////////////////////////////////////////////////////////////////////
#include "AEEShell.h" // Shell interface definitions
#include "AEEStdLib.h"
#include "AEEDisp.h"
#include "AEEGraphics.h"
#include "AEEFile.h"
#include "JString.h"
#define HCENTER 1
#define VCENTER 2
#define LEFT 4
#define RIGHT 8
#define TOP 16
#define BOTTOM 32
#define BASELINE 64
#define MAKERGB(r,g,b)(RGBVAL) ( (uint32)0xFF + ((uint32)(r)<<8) + ((uint32)(g)<<16) + ((uint32)(b)<<24) )
//Misc Global Helper functions
int GetRandom( void );
int GetRandom( int low, int high );
AEEImageInfo GetImageInfo(IImage* pImage);
int GetImageWidth(IImage* pImage);
int GetImageHeight(IImage* pImage);
void AdjustCoordsByAnchor( AEEPoint* pPt, int width, int height, int anchor );
void Str2wstr( const char* pSrc, int nlen, AECHAR* pDest );
// 2005 02 25 眠啊内靛
void Util_AECHARToKSC5601(const AECHAR *src, char *dest);
void Util_KSC5601ToAECHAR(const char *src, AECHAR *dest);
#ifdef TINY
class Graphics;
class Font
{
public:
//================================================================================
// Public Services - Constructors & Destructors.
//================================================================================
Font();
~Font();
//================================================================================
// Public Services - General
//================================================================================
boolean init(const int aName, IImage *aFontImg, AECHAR aCharAlpha, AECHAR aCharOmega, const int16 *aCharWidths, int16 aCharHeight, Graphics *g_);
const int getName() const;
int16 charWidth(AECHAR aChar) const;
int16 charHeight(AECHAR aChar) const;
int16 stringWidth(const AECHAR *aStr) const;
int16 stringHeight(const AECHAR *aStr) const;
int16 drawChar(const AECHAR aChar, AEERect *pRect, int16 *aXPos, int16 *aYPos) const;
int16 drawString(const AECHAR *aStr, AEERect *pRect, int16 *aXPos, int16 *aYPos) const;
private:
int name;
IImage *fontImg;
AECHAR charAlpha;
AECHAR charOmega;
const int16 *charWidths;
int16 charHeights;
Graphics *g;
};
const AECHAR tinyFontCharAlpha = ' ';
const AECHAR tinyFontCharOmega = 'z';
//const int16 tinyFontCharWidths[] = { 4, 2, 5, 8, 5, 8, 7,2,4,4, 5, 6,2, 4,2, 4, 5,3, 5, 5, 6, 5, 5, 5, 5, 5,2,2, 5, 5, 5, 5, 8, 7, 6, 7, 6, 5, 5, 7, 6,2,5, 6, 6, 9, 6, 7, 6, 7, 7, 6, 6 ,6, 7,11, 6, 6, 6,3,4,3,6, 6,3,5, 6,5,6,6,5,6,6,2,3,6,2,10,6,6,6,6,4,6,4,6,5, 9, 5, 5, 5,4,2,4, 5};
//const int16 tinyFontCharWidths[] = { 3, 2, 5, 8, 5, 8, 6,2,3,3, 5, 6,2, 3,2, 4, 4,2, 4, 4, 4, 4, 4, 4, 5, 4,1,2, 4, 3, 4, 4, 7, 5, 5, 5, 5, 4, 4, 6, 5,2,4, 5, 5, 9, 6, 5, 5, 7, 6, 6, 6 ,6, 5, 9, 6, 6, 5,3,4,3,6, 4,3,4, 4,4,5,5,4,5,4,2,3,5,2, 8,5,5,5,5,4,5,4,5,5, 9, 5, 5, 5,4,2,4, 5 };
const int16 tinyFontCharWidths[] = { 3, 1, 3, 7, 5, 7, 6,1,2,2, 5, 5,2, 4,1, 4, 5,2, 5, 5, 5, 5, 5, 5, 5, 5,1,2, 5, 4, 5, 4, 7, 5, 5, 5, 5, 4, 4, 6, 5,1,4, 5, 4, 7, 5, 7, 5, 7, 5, 5, 5 ,5, 5, 9, 5, 5, 4,2,4,2,5, 6,2,4, 4,4,4,4,4,4,4,1,2,4,1, 7,4,4,4,4,4,4,3,4,5, 7, 5, 5, 4,3,1,3, 6 };
const int16 tinyFontCharHeight = 7;
#endif
class Graphics
{
public:
Graphics(IGraphics* pIGraphics, IDisplay* pIDisplay);
~Graphics();
//Image draw
void DrawImage(IImage* pImage, int posX, int posY);
void DrawImage(IImage* pImage, int posX, int posY, int anchor );
//Clipping
void SetScreenClip(int posX, int posY, int width, int height);
void SetBitmapClip(int posX, int posY, int width, int height);
void ResetBitmapClip();
//Colour
uint32 GetColor();
void SetColor(int red, int green, int blue);
void SetColor(uint32 rgb);
void SetTextColor(int red, int green, int blue);
void SetTextColor(uint32 rgb);
void SetFillColor(int red, int green, int blue);
void SetFillColor(uint32 rgb);
//Vector graphics
void DrawLine(int x0, int y0, int x1, int y1);
void FillRect(int posX, int posY, int width, int height);
void DrawRect(int posX, int posY, int width, int height);
void FillTriangle(int x0, int y0, int x1, int y1, int x2, int y2);
void DrawTriangle(int x0, int y0, int x1, int y1, int x2, int y2);
void FillArc(int posX, int posY, int width, int height);
void DrawArc(int posX, int posY, int width, int height);
void FillRoundRect(int posX, int posY, int width, int height, int arcWidth, int arcHeight);
void DrawRoundRect(int posX, int posY, int width, int height, int arcWidth, int arcHeight);
//Draw text
void getFontMetrics(IDisplay* pIDisplay, AEEFont font, int *pascent, int *pdescent);
int measureText(IDisplay* pIDisplay, AEEFont font, AECHAR *szBuf);
void drawText(IDisplay* pIDisplay, AEEFont font, AECHAR *szBuf, int length, int x, int y, AEERect *pRect, uint32 dwFlags);
bool SetMaxFontHeight(int height);
int GetFontHeight(AEEFont font);
int GetFontHeight();
AEEFont GetFont();
void SetFont(AEEFont font);
int GetTextWidth( JString text );
int GetTextWidth( JString text, AEEFont font );
void DrawString(const JString& string, int x, int y, AEERect* rect, uint32 dwFlags );
//void DrawString(JString string, int x, int y, uint32 dwFlags );
void DrawString(JString string, int x, int y, int anchor);
#ifdef TINY
Font *tinyFont;
void initTinyFont(IImage *pImage);
void deleteTinyFont();
#endif
#ifndef BREW20
AEEClip StoreClip;
AEERect DisplayClip;
#endif
private:
IGraphics* m_pIGraphics;
IDisplay* m_pIDisplay;
AEEFont m_currentFont;
int FONT_STEP;
int FONT_SHIFT;
};
// Random class to emulate JAVA
/*
#define MULTIPLIER 0x5deece66d
#define ADDEND 11
#define MASK 0xffffffffffff
*/
#define BITS_PER_BYTE 8
#define BYTES_PER_INT 4
#define __int64 int
class Random
{
public:
Random();
Random(__int64 seed);
~Random();
void SetSeed(__int64 seed);
int Next(int bits);
int NextInt();
long NextLong();
private:
__int64 m_seed;
};
class SOUND_STREAM {
unsigned char *pBuffer;
int size;
IMemAStream *Stream;
public:
SOUND_STREAM() { pBuffer=NULL; }
SOUND_STREAM(IShell *Shell, IFileMgr *FileMgr, const char *FileName) { Init(Shell,FileMgr,FileName); }
~SOUND_STREAM() { Release(); }
void Init(IShell *Shell, IFileMgr *FileMgr, const char *FileName);
void Release();
IMemAStream *getStream() { return Stream; }
bool Exist() { return pBuffer!=NULL; }
};
#define assert(x) (void(0))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -