good::gx介面

good::gx是負責繪圖的介面。它很簡單,至少目前來說還很簡單。只有二個介面:Image及Graphics。

Image介面對貼圖作一層薄薄的包裝,good執行的時候,所有使用到的貼圖的地方全都透過這一層介面作存取。下面是Image介面定義。
template<class ImgT>
class Image
{
public:

bool isValid() const;

int getWidth() const;
int getHeight() const;
bool hasKeyColor() const;
int getKeyColor() const;
void setKeyColor(int keycolor);
};
Graphics介面提供了很少的功能,目前只有貼圖和畫色塊二個功能,因為目前good的成像目前只需要這二個功能就足夠畫出所有東西。下面是Graphics介面定義。
template<class ImgT>
class Graphics
{
public:

bool drawImage(int x, int y, ImgT const& img, int srcx, int srcy, int srcw, int srch);

bool drawImage(int x, int y, ImgT const& img)
{
return drawImage(x, y, img, 0, 0, img.getWidth(), img.getHeight());
}

bool fillSolidColor(int left, int top, int width, int height, int color);
};
+ + +

實際應用的時候,只需要針對不同繪圖平台作不同實作品的提供,對於good內部而言,幾乎不必作任何修改。目前good::gx有四種實作品,GDI、SDL、imgp及OpenGL。

留言

這個網誌中的熱門文章

以lex/yacc實作算式計算機

猜數字遊戲 (電腦猜人)

KillSudoku 4顆星精彩數獨詳解 - 鍊技巧