青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 96  文章 - 255  trackbacks - 0
<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

E-mail:zbln426@163.com QQ:85132383 長期尋找對戰略游戲感興趣的合作伙伴。

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關網站

我的個人網頁

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 496251
  • 排名 - 39

最新評論

閱讀排行榜

評論排行榜

Widows version:

//UVi Soft ( 2008 )
//Long Fei ( lf426 ), E-mail: zbln426@163.com
//Laboratory of ZaiBieLiunNian
//http://www.shnenglu.com/lf426/

//FileName: SurfaceClass.hpp
//For Windows only

#ifndef SURFACE_CLASS_HPP
#define SURFACE_CLASS_HPP

#include 
<iostream>
#include 
<string>
#include 
"SDL/SDL.h"
#include 
"SDL/SDL_image.h"
#include 
"SDL/SDL_ttf.h"
//Windows only
#include "SDL_render_Chinese.h"

class ScreenSurface
{
private:
    
//number of screen, make sure there is only ONE screen
    static int screenNum;
    
//size & bpp  of screen
    int width;
    
int height;
    
int bpp;
    
//common flags:SDL_SWSURFACE, SDL_HWSURFACE, SDL_DOUBLEBUF, SDL_FULLSCREEN
    
//more: http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode
    Uint32 flags;
    
//other attribute
    SDL_Surface* pScreen;
    std::
string windowName;
public:
    
//construct & deconstruct
    ScreenSurface();
    ScreenSurface(
int w, int h, const std::string& window_name = "NULL"int b = 0, Uint32 f = 0);
    
~ScreenSurface();
    
//screen's point
    SDL_Surface* point() const;
    
//flip the screen
    void flip() const;
    
//fill the screen with some color, default is black.
    void fillColor(Uint8 r = 0, Uint8 g = 0, Uint8 b = 0const;
};

class BaseSurface
{
private:
    
//
protected:
    SDL_Surface
* pScreen;
    SDL_Surface
* pSurface;
    BaseSurface();
public:
    BaseSurface(
const BaseSurface& copy);
    
virtual ~BaseSurface();
    BaseSurface
& operator=(const BaseSurface& copy);
    
//surface's point
    SDL_Surface* point() const;
    
//blit surface to screen
    void blit() const;
    
void blit(int any_num) const;
    
void blit(int at_x, int at_y) const;
    
void blit(int at_x, int at_y,
                
int from_x, int from_y, int w, int h,
                
int delta_x = 0int delta_y = 0const;
    
//blit surface to another surface
    void blit(const BaseSurface& dst_surface) const;
    
void blit(const BaseSurface& dst_surface, int any_num) const;
    
void blit(const BaseSurface& dst_surface,
                        
int at_x, int at_y) const;
    
void blit(const BaseSurface& dst_surface,
                        
int at_x, int at_y,
                        
int from_x, int from_y, int w, int h,
                        
int delta_x = 0int delta_y = 0const;
    
//color keying
    void colorKey(Uint8 r = 0, Uint8 g = 0xFF, Uint8 b = 0xFF, Uint32 flag = SDL_SRCCOLORKEY);
};

class PictureSurface: public BaseSurface
{
private:
    std::
string fileName;
public:
    PictureSurface(
const std::string& file_name, const ScreenSurface& screen);
};

class TextSurface: public BaseSurface
{
private:
    
static int textNum;
    std::
string message;
    std::
string TTF_fileName;
    
int TTF_size;
    Uint8 r, g, b;
public:
    TextSurface(
const std::string& _message, const ScreenSurface& screen,
        Uint8 _r 
= 0xFF, Uint8 _g = 0xFF, Uint8 _b = 0xFF
        
int ttf_size = 28const std::string& ttf_fileName = "./fonts/gkai00mp.ttf");
    TextSurface(
const TextSurface& copy);
    
~TextSurface();
    
//text tools
    void toBlended();
    
void toSolid();
    
void toShaded(Uint8 _r, Uint8 _g, Uint8 _b);
    
void setColor(Uint8 _r, Uint8 _g, Uint8 _b);
    
void setSize(int ttf_size);
    
void setFont(const std::string& ttf_fileName);
};

class ErrorInfo
{
private:
    std::
string info;
public:
    ErrorInfo():info(
"Unknown ERROR!")
    {}
    ErrorInfo(
const char* c_str)
    {
        info 
= std::string(c_str);
    }
    ErrorInfo(
const std::string& str):info(str)
    {}
    
void show() const
    {
        std::cerr 
<< info << std::endl;
    }
};

#endif

 

//UVi Soft ( 2008 )
//Long Fei ( lf426 ), E-mail: zbln426@163.com
//Laboratory of ZaiBieLiunNian
//http://www.shnenglu.com/lf426/

//FileName: SurfaceClass.cpp
//For Windows only

#include 
"SurfaceClass.hpp"

//*****************************************
//class ScreenSurface

int ScreenSurface::screenNum = 0;

ScreenSurface::ScreenSurface():
width(
640), height(480), bpp(32), flags(0), windowName("NULL")
{
    
if ( screenNum > 0 )
        
throw ErrorInfo("DONOT create more than ONE screen!");
    
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
        
throw ErrorInfo(SDL_GetError());
    pScreen 
= SDL_SetVideoMode(width, height, bpp, flags);
    screenNum
++;
}

ScreenSurface::ScreenSurface(
int w, int h, const std::string& window_name, int b, Uint32 f):
width(w), height(h), bpp(b), flags(f)
{
    
if ( screenNum > 0 )
        
throw ErrorInfo("DONOT create more than ONE screen!");
    
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
        
throw ErrorInfo(SDL_GetError());
    pScreen 
= SDL_SetVideoMode(width, height, bpp, flags);
    screenNum
++;
    
if ( window_name != "NULL" ) {
        windowName 
= window_name;
        SDL_WM_SetCaption(windowName.c_str(), 
0);
    }
    
else
        windowName 
= "NULL";
}

ScreenSurface::
~ScreenSurface()
{
    SDL_Quit();
}

//***

SDL_Surface
* ScreenSurface::point() const
{
    
return pScreen;
}

void ScreenSurface::flip() const
{
    
if ( SDL_Flip(pScreen) < 0 )
        
throw ErrorInfo(SDL_GetError());
}


void ScreenSurface::fillColor(Uint8 r, Uint8 g, Uint8 b) const
{
     
if ( SDL_FillRect(pScreen, 0, SDL_MapRGB(pScreen->format, r, g, b)) < 0 )
         
throw ErrorInfo(SDL_GetError());
}

//************************************



//************************************
//class BaseSurface

//protected
BaseSurface::BaseSurface():
pScreen(
0), pSurface(0)
{}

//public
BaseSurface::BaseSurface(const BaseSurface& copy):
pScreen(copy.pScreen)
{
    pSurface 
= SDL_ConvertSurface(copy.pSurface, copy.pSurface->format, SDL_SWSURFACE);
    
if ( pSurface == 0 )
        
throw ErrorInfo(SDL_GetError());
}

BaseSurface::
~BaseSurface()
{
    SDL_FreeSurface(pSurface);
}

BaseSurface
& BaseSurface::operator=(const BaseSurface& copy)
{
    SDL_FreeSurface(pSurface);
    pSurface 
= SDL_ConvertSurface(copy.pSurface, copy.pSurface->format, SDL_SWSURFACE);
    
if ( pSurface == 0 )
        
throw ErrorInfo(SDL_GetError());
    
return *this;
}

//***

SDL_Surface
* BaseSurface::point() const
{
    
return pSurface;
}

//***

void BaseSurface::blit() const
{
    
const int SRC_W = pSurface->w;
    
const int SRC_H = pSurface->h;
    
const int DST_W = pScreen->w;
    
const int DST_H = pScreen->h;

    SDL_Rect offset;
    offset.x 
= ( DST_W - SRC_W ) / 2;
    offset.y 
= ( DST_H - SRC_H ) / 2;
    
if ( SDL_BlitSurface(pSurface, 0, pScreen, &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

void BaseSurface::blit(int any_num) const
{
    
if ( SDL_BlitSurface(pSurface, 0, pScreen, 0< 0 )
        
throw ErrorInfo(SDL_GetError());
}

void BaseSurface::blit(int at_x, int at_y) const
{
    SDL_Rect offset;
    offset.x 
= at_x;
    offset.y 
= at_y;

    
if ( SDL_BlitSurface(pSurface, 0, pScreen, &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

void BaseSurface::blit(int at_x, int at_y,
                       
int from_x, int from_y, int w, int h,
                       
int delta_x, int delta_y) const
{
    SDL_Rect offset;
    offset.x 
= at_x - delta_x;
    offset.y 
= at_y - delta_y;

    SDL_Rect dest;
    dest.x 
= from_x - delta_x;
    dest.y 
= from_y - delta_y;
    dest.w 
= w + delta_x*2;
    dest.h 
= h + delta_y*2;

    
if ( SDL_BlitSurface(pSurface, &dest, pScreen, &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

//***

void BaseSurface::blit(const BaseSurface& dst_surface) const
{
    
const int SRC_W = pSurface->w;
    
const int SRC_H = pSurface->h;
    
const int DST_W = dst_surface.point()->w;
    
const int DST_H = dst_surface.point()->h;

    SDL_Rect offset;
    offset.x 
= ( DST_W - SRC_W ) / 2;
    offset.y 
= ( DST_H - SRC_H ) / 2;

    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");

    
if ( SDL_BlitSurface(pSurface, 0, dst_surface.point(), &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

void BaseSurface::blit(const BaseSurface& dst_surface, int any_num) const
{
    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");

    
if ( SDL_BlitSurface(pSurface, 0, dst_surface.point(), 0< 0 )
        
throw ErrorInfo(SDL_GetError());
}

void BaseSurface::blit(const BaseSurface& dst_surface, int at_x, int at_y) const
{
    SDL_Rect offset;
    offset.x 
= at_x;
    offset.y 
= at_y;

    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");

    
if ( SDL_BlitSurface(pSurface, 0, dst_surface.point(), &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

void BaseSurface::blit(const BaseSurface& dst_surface,
                       
int at_x, int at_y,
                       
int from_x, int from_y, int w, int h,
                       
int delta_x, int delta_y) const
{
    SDL_Rect offset;
    offset.x 
= at_x - delta_x;
    offset.y 
= at_y - delta_y;

    SDL_Rect dest;
    dest.x 
= from_x - delta_x;
    dest.y 
= from_y - delta_y;
    dest.w 
= w + delta_x*2;
    dest.h 
= h + delta_y*2;

    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");

    
if ( SDL_BlitSurface(pSurface, &dest, dst_surface.point(), &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

//***

void BaseSurface::colorKey(Uint8 r, Uint8 g, Uint8 b, Uint32 flag)
{
    Uint32 colorkey 
= SDL_MapRGB(pSurface->format, r, g, b);
    
if ( SDL_SetColorKey(pSurface, flag, colorkey ) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

//************************************


//************************************
//class PictureSurface

PictureSurface::PictureSurface(
const std::string& file_name, const ScreenSurface& screen):
BaseSurface(),
fileName(file_name)
{
    SDL_Surface
* pSurfaceTemp = IMG_Load(fileName.c_str());
    
if ( pSurfaceTemp == 0 )
        
throw ErrorInfo(IMG_GetError());
    pSurface 
= SDL_DisplayFormat(pSurfaceTemp);
    
if ( pSurface == 0 )
        
throw ErrorInfo(SDL_GetError());
    SDL_FreeSurface(pSurfaceTemp);

    pScreen 
= screen.point();
}

//************************************



//************************************
//class TextSurface

int TextSurface::textNum = 0;

TextSurface::TextSurface(
const std::string& _message, const ScreenSurface& screen,
        Uint8 _r, Uint8 _g, Uint8 _b, 
        
int ttf_size, const std::string& ttf_fileName):
BaseSurface(),
message(_message), TTF_fileName(ttf_fileName), TTF_size(ttf_size), 
r(_r), g(_g), b(_b)
{
    
if ( textNum == 0 ){
        
if ( TTF_Init() < 0 ){
            
throw ErrorInfo(TTF_GetError());
        }
    }

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= myTTF_RenderString_Blended(pFont, message, textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);

    pScreen 
= screen.point();

    textNum
++;
}


TextSurface::TextSurface(
const TextSurface& copy):
BaseSurface(copy),
message(copy.message), TTF_fileName(copy.TTF_fileName), TTF_size(copy.TTF_size), 
r(copy.r), g(copy.g), b(copy.b)
{
    textNum
++;
}


TextSurface::
~TextSurface()
{
    textNum
--;
    
if ( textNum == 0 ){
        TTF_Quit();
    }
}

//***

void TextSurface::toBlended()
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= myTTF_RenderString_Blended(pFont, message, textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::toSolid()
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= myTTF_RenderString_Solid(pFont, message, textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::toShaded(Uint8 _r, Uint8 _g, Uint8 _b)
{
    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;
    
    SDL_Color bgColor;
    bgColor.r 
= _r;
    bgColor.g 
= _g;
    bgColor.b 
= _b;

    SDL_FreeSurface(pSurface);

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= myTTF_RenderString_Shaded(pFont, message, textColor, bgColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::setColor(Uint8 _r, Uint8 _g, Uint8 _b)
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r = _r;
    textColor.g 
= g = _g;
    textColor.b 
= b = _b;

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= myTTF_RenderString_Blended(pFont, message, textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::setSize(int ttf_size)
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;
    
    TTF_size 
= ttf_size;
    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= myTTF_RenderString_Blended(pFont, message, textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::setFont(const std::string& ttf_fileName)
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;
    
    TTF_fileName 
= ttf_fileName;
    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());

    pSurface 
= myTTF_RenderString_Blended(pFont, message, textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}
//*************************************

Linux version:


//UVi Soft ( 2008 ) 
//Long Fei ( lf426 ), E-mail: zbln426@163.com 
//Laboratory of ZaiBieLiunNian 
//http://www.shnenglu.com/lf426/ 
 
//FileName: SurfaceClass.hpp
//For Linux and other UTF-8 OS 
 
#ifndef SURFACE_CLASS_HPP 
#define SURFACE_CLASS_HPP 
 
#include 
<iostream> 
#include 
<string> 
#include 
"SDL/SDL.h" 
#include 
"SDL/SDL_image.h" 
#include 
"SDL/SDL_ttf.h"
//Linux can render UTF-8 Chinese directly
//For Windows (simple Chinese), include below 
//#include "SDL_render_Chinese.h" 
 
class ScreenSurface 

private
    
//number of screen, make sure there is only ONE screen 
    static int screenNum; 
    
//size & bpp  of screen 
    int width; 
    
int height; 
    
int bpp; 
    
//common flags:SDL_SWSURFACE, SDL_HWSURFACE, SDL_DOUBLEBUF, SDL_FULLSCREEN 
    
//more: http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode 
    Uint32 flags; 
    
//other attribute 
    SDL_Surface* pScreen; 
    std::
string windowName; 
public
    
//construct & deconstruct 
    ScreenSurface(); 
    ScreenSurface(
int w, int h, const std::string& window_name = "NULL"int b = 0, Uint32 f = 0); 
    
~ScreenSurface(); 
    
//screen's point 
    SDL_Surface* point() const
    
//flip the screen 
    void flip() const
    
//fill the screen with some color, default is black. 
    void fillColor(Uint8 r = 0, Uint8 g = 0, Uint8 b = 0const
}; 
 
class BaseSurface 

private
    
// 
protected
    SDL_Surface
* pScreen; 
    SDL_Surface
* pSurface; 
    BaseSurface(); 
public
    BaseSurface(
const BaseSurface& copy); 
    
virtual ~BaseSurface(); 
    BaseSurface
& operator=(const BaseSurface& copy); 
    
//surface's point 
    SDL_Surface* point() const
    
//blit surface to screen 
    void blit() const
    
void blit(int any_num) const
    
void blit(int at_x, int at_y) const
    
void blit(int at_x, int at_y, 
                
int from_x, int from_y, int w, int h, 
                
int delta_x = 0int delta_y = 0const
    
//blit surface to another surface 
    void blit(const BaseSurface& dst_surface) const
    
void blit(const BaseSurface& dst_surface, int any_num) const
    
void blit(const BaseSurface& dst_surface, 
                        
int at_x, int at_y) const
    
void blit(const BaseSurface& dst_surface, 
                        
int at_x, int at_y, 
                        
int from_x, int from_y, int w, int h, 
                        
int delta_x = 0int delta_y = 0const
    
//color keying 
    void colorKey(Uint8 r = 0, Uint8 g = 0xFF, Uint8 b = 0xFF, Uint32 flag = SDL_SRCCOLORKEY); 
}; 
 
class PictureSurface: public BaseSurface 

private
    std::
string fileName; 
public
    PictureSurface(
const std::string& file_name, const ScreenSurface& screen); 
}; 
 
class TextSurface: public BaseSurface 

private
    
static int textNum; 
    std::
string message; 
    std::
string TTF_fileName; 
    
int TTF_size; 
    Uint8 r, g, b; 
public
    TextSurface(
const std::string& _message, const ScreenSurface& screen, 
        Uint8 _r 
= 0xFF, Uint8 _g = 0xFF, Uint8 _b = 0xFF,  
        
int ttf_size = 28const std::string& ttf_fileName = "./fonts/gkai00mp.ttf"); 
    TextSurface(
const TextSurface& copy); 
    
~TextSurface(); 
    
//text tools 
    void toBlended(); 
    
void toSolid(); 
    
void toShaded(Uint8 _r, Uint8 _g, Uint8 _b); 
    
void setColor(Uint8 _r, Uint8 _g, Uint8 _b); 
    
void setSize(int ttf_size); 
    
void setFont(const std::string& ttf_fileName); 
}; 
 
class ErrorInfo 

private
    std::
string info; 
public
    ErrorInfo():info(
"Unknown ERROR!"
    {} 
    ErrorInfo(
const char* c_str) 
    { 
        info 
= std::string(c_str); 
    } 
    ErrorInfo(
const std::string& str):info(str) 
    {} 
    
void show() const 
    { 
        std::cerr 
<< info << std::endl; 
    } 
}; 
 
#endif 

//UVi Soft ( 2008 ) 
//Long Fei ( lf426 ), E-mail: zbln426@163.com 
//Laboratory of ZaiBieLiunNian 
//http://www.shnenglu.com/lf426/

//FileName: SurfaceClass.cpp
//For Linux and other UTF-8 OS 
 
#include 
"SurfaceClass.hpp" 
 
//***************************************** 
//class ScreenSurface 
 
int ScreenSurface::screenNum = 0
 
ScreenSurface::ScreenSurface(): 
width(
640), height(480), bpp(32), flags(0), windowName("NULL"

    
if ( screenNum > 0 ) 
        
throw ErrorInfo("DONOT create more than ONE screen!"); 
    
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 
        
throw ErrorInfo(SDL_GetError()); 
    pScreen 
= SDL_SetVideoMode(width, height, bpp, flags); 
    screenNum
++

 
ScreenSurface::ScreenSurface(
int w, int h, const std::string& window_name, int b, Uint32 f):
width(w), height(h), bpp(b), flags(f)

    
if ( screenNum > 0 )
        
throw ErrorInfo("DONOT create more than ONE screen!");
    
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 
        
throw ErrorInfo(SDL_GetError());
    pScreen 
= SDL_SetVideoMode(width, height, bpp, flags);
    screenNum
++
    
if ( window_name != "NULL" ) {
        windowName 
= window_name;
        SDL_WM_SetCaption(windowName.c_str(), 
0);
    } 
    
else 
        windowName 
= "NULL";

 
ScreenSurface::
~ScreenSurface()

    SDL_Quit();

 
//***
 
SDL_Surface
* ScreenSurface::point() const

    
return pScreen;

 
void ScreenSurface::flip() const

    
if ( SDL_Flip(pScreen) < 0 )
        
throw ErrorInfo(SDL_GetError());


void ScreenSurface::fillColor(Uint8 r, Uint8 g, Uint8 b) const

     
if ( SDL_FillRect(pScreen, 0, SDL_MapRGB(pScreen->format, r, g, b)) < 0 )
         
throw ErrorInfo(SDL_GetError()); 

 
//************************************
 
 
 
//************************************
//class BaseSurface 
 
//protected
BaseSurface::BaseSurface(): 
pScreen(
0), pSurface(0
{} 
 
//public
BaseSurface::BaseSurface(const BaseSurface& copy):
pScreen(copy.pScreen) 

    pSurface 
= SDL_ConvertSurface(copy.pSurface, copy.pSurface->format, SDL_SWSURFACE);
    
if ( pSurface == 0 )
        
throw ErrorInfo(SDL_GetError()); 

 
BaseSurface::
~BaseSurface()

    SDL_FreeSurface(pSurface);

 
BaseSurface
& BaseSurface::operator=(const BaseSurface& copy)

    SDL_FreeSurface(pSurface);
    pSurface 
= SDL_ConvertSurface(copy.pSurface, copy.pSurface->format, SDL_SWSURFACE);
    
if ( pSurface == 0 )
        
throw ErrorInfo(SDL_GetError());
    
return *this

 
//***
 
SDL_Surface
* BaseSurface::point() const

    
return pSurface;

 
//***
 
void BaseSurface::blit() const

    
const int SRC_W = pSurface->w;
    
const int SRC_H = pSurface->h; 
    
const int DST_W = pScreen->w; 
    
const int DST_H = pScreen->h; 
 
    SDL_Rect offset;
    offset.x 
= ( DST_W - SRC_W ) / 2;
    offset.y 
= ( DST_H - SRC_H ) / 2;
    
if ( SDL_BlitSurface(pSurface, 0, pScreen, &offset) < 0 )
        
throw ErrorInfo(SDL_GetError()); 

 
void BaseSurface::blit(int any_num) const
{
    
if ( SDL_BlitSurface(pSurface, 0, pScreen, 0< 0 )
        
throw ErrorInfo(SDL_GetError()); 

 
void BaseSurface::blit(int at_x, int at_y) const

    SDL_Rect offset;
    offset.x 
= at_x; 
    offset.y 
= at_y; 
 
    
if ( SDL_BlitSurface(pSurface, 0, pScreen, &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());

 
void BaseSurface::blit(int at_x, int at_y,
                       
int from_x, int from_y, int w, int h,
                       
int delta_x, int delta_y) const 

    SDL_Rect offset;
    offset.x 
= at_x - delta_x; 
    offset.y 
= at_y - delta_y; 
 
    SDL_Rect dest; 
    dest.x 
= from_x - delta_x;
    dest.y 
= from_y - delta_y;
    dest.w 
= w + delta_x*2;
    dest.h 
= h + delta_y*2;
 
    
if ( SDL_BlitSurface(pSurface, &dest, pScreen, &offset) < 0 )
        
throw ErrorInfo(SDL_GetError()); 

 
//***
 
void BaseSurface::blit(const BaseSurface& dst_surface) const

    
const int SRC_W = pSurface->w;
    
const int SRC_H = pSurface->h; 
    
const int DST_W = dst_surface.point()->w;
    
const int DST_H = dst_surface.point()->h; 
 
    SDL_Rect offset;
    offset.x 
= ( DST_W - SRC_W ) / 2;
    offset.y 
= ( DST_H - SRC_H ) / 2;
 
    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");
 
    
if ( SDL_BlitSurface(pSurface, 0, dst_surface.point(), &offset) < 0 )
        
throw ErrorInfo(SDL_GetError()); 

 
void BaseSurface::blit(const BaseSurface& dst_surface, int any_num) const

    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");
 
    
if ( SDL_BlitSurface(pSurface, 0, dst_surface.point(), 0< 0 )
        
throw ErrorInfo(SDL_GetError()); 

 
void BaseSurface::blit(const BaseSurface& dst_surface, int at_x, int at_y) const

    SDL_Rect offset;
    offset.x 
= at_x;
    offset.y 
= at_y; 
 
    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");
 
    
if ( SDL_BlitSurface(pSurface, 0, dst_surface.point(), &offset) < 0 )
        
throw ErrorInfo(SDL_GetError()); 

 
void BaseSurface::blit(const BaseSurface& dst_surface,
                       
int at_x, int at_y,
                       
int from_x, int from_y, int w, int h,
                       
int delta_x, int delta_y) const 

    SDL_Rect offset;
    offset.x 
= at_x - delta_x;
    offset.y 
= at_y - delta_y;
 
    SDL_Rect dest;
    dest.x 
= from_x - delta_x;
    dest.y 
= from_y - delta_y;
    dest.w 
= w + delta_x*2
    dest.h 
= h + delta_y*2
 
    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");
 
    
if ( SDL_BlitSurface(pSurface, &dest, dst_surface.point(), &offset) < 0 )
        
throw ErrorInfo(SDL_GetError()); 

 
//*** 
 
void BaseSurface::colorKey(Uint8 r, Uint8 g, Uint8 b, Uint32 flag)

    Uint32 colorkey 
= SDL_MapRGB(pSurface->format, r, g, b);
    
if ( SDL_SetColorKey(pSurface, flag, colorkey ) < 0 )
        
throw ErrorInfo(SDL_GetError()); 

 
//************************************
 
 
//************************************
//class PictureSurface 
 
PictureSurface::PictureSurface(
const std::string& file_name, const ScreenSurface& screen):
BaseSurface(), 
fileName(file_name)
{
    SDL_Surface
* pSurfaceTemp = IMG_Load(fileName.c_str());
    
if ( pSurfaceTemp == 0 )
        
throw ErrorInfo(IMG_GetError());
    pSurface 
= SDL_DisplayFormat(pSurfaceTemp);
    
if ( pSurface == 0 )
        
throw ErrorInfo(SDL_GetError());
    SDL_FreeSurface(pSurfaceTemp);

    pScreen 
= screen.point();
}

//************************************



//************************************
//class TextSurface

int TextSurface::textNum = 0;

TextSurface::TextSurface(
const std::string& _message, const ScreenSurface& screen,
        Uint8 _r, Uint8 _g, Uint8 _b, 
        
int ttf_size, const std::string& ttf_fileName):
BaseSurface(),
message(_message), TTF_fileName(ttf_fileName), TTF_size(ttf_size), 
r(_r), g(_g), b(_b)
{
    
if ( textNum == 0 ){
        
if ( TTF_Init() < 0 ){
            
throw ErrorInfo(TTF_GetError());
        }
    }

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= TTF_RenderUTF8_Blended(pFont, message.c_str(), textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);

    pScreen 
= screen.point();

    textNum
++;
}


TextSurface::TextSurface(
const TextSurface& copy):
BaseSurface(copy),
message(copy.message), TTF_fileName(copy.TTF_fileName), TTF_size(copy.TTF_size), 
r(copy.r), g(copy.g), b(copy.b)
{
    textNum
++;
}


TextSurface::
~TextSurface()
{
    textNum
--;
    
if ( textNum == 0 ){
        TTF_Quit();
    }
}

//***

void TextSurface::toBlended()
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= TTF_RenderUTF8_Blended(pFont, message.c_str(), textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::toSolid()
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= TTF_RenderUTF8_Solid(pFont, message.c_str(), textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::toShaded(Uint8 _r, Uint8 _g, Uint8 _b)
{
    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;
    
    SDL_Color bgColor;
    bgColor.r 
= _r;
    bgColor.g 
= _g;
    bgColor.b 
= _b;

    SDL_FreeSurface(pSurface);

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= TTF_RenderUTF8_Shaded(pFont, message.c_str(), textColor, bgColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::setColor(Uint8 _r, Uint8 _g, Uint8 _b)
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r = _r;
    textColor.g 
= g = _g;
    textColor.b 
= b = _b;

    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= TTF_RenderUTF8_Blended(pFont, message.c_str(), textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::setSize(int ttf_size)
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;
    
    TTF_size 
= ttf_size;
    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());
    pSurface 
= TTF_RenderUTF8_Blended(pFont, message.c_str(), textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}

void TextSurface::setFont(const std::string& ttf_fileName)
{
    SDL_FreeSurface(pSurface);

    SDL_Color textColor;
    textColor.r 
= r;
    textColor.g 
= g;
    textColor.b 
= b;
    
    TTF_fileName 
= ttf_fileName;
    TTF_Font
* pFont = TTF_OpenFont(TTF_fileName.c_str(), TTF_size);
    
if ( pFont == 0 )
        
throw ErrorInfo(TTF_GetError());

    pSurface 
= TTF_RenderUTF8_Blended(pFont, message.c_str(), textColor);
    
if ( pSurface == 0 )
        
throw ErrorInfo(TTF_GetError());
    TTF_CloseFont(pFont);
}
//*************************************

lib: iconv.lib
     SDL_ttf.lib
     SDL.lib, SDLmain.lib
     SDL_image.lib

dll: iconv.dll
     SDL_ttf.dll, libfreetype-6.dll, zlib1.dll
     SDL.dll
     jpeg.dll, libpng12-0.dll, libtiff-3.dll, SDL_image.dll, zlib1.dll

gkai00mp.ttf為Debian楷體,文泉驛字庫。

last update: 2008-05-12

posted on 2008-04-14 14:03 lf426 閱讀(2373) 評論(2)  編輯 收藏 引用 所屬分類: mySDL_GameEngine

FeedBack:
# re: SurfaceClass 2012-06-08 14:00 周爽
實現文件可以看一下么?  回復  更多評論
  
# re: SurfaceClass 2012-06-08 14:01 周爽
我對編程跟SDL都是新手,希望指教下  回復  更多評論
  

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              亚洲激情偷拍| 午夜免费日韩视频| 麻豆9191精品国产| 欧美电影免费观看网站 | 最新日韩中文字幕| 一区二区av在线| 欧美一区二区精美| 欧美高清在线观看| 亚洲一区二区精品在线| 久久超碰97人人做人人爱| 欧美国产精品一区| 国产农村妇女精品一二区| 亚洲第一色在线| 午夜视频在线观看一区二区三区| 亚洲无吗在线| 欧美高清免费| 亚洲综合国产| 亚洲国产欧美国产综合一区| 西瓜成人精品人成网站| 欧美日韩一区在线| 在线观看视频一区二区| 欧美一区三区二区在线观看| 久久精品30| 亚洲精品乱码久久久久久久久| 久久精品国产99精品国产亚洲性色 | 国产精品久久久久久一区二区三区| 激情亚洲网站| 午夜精品视频在线观看| 久久精品视频播放| 国产日产亚洲精品| 欧美电影资源| 欧美色大人视频| 亚洲美女精品久久| 亚洲成人在线网| 美国十次了思思久久精品导航| 一本久道久久综合中文字幕| 欧美专区日韩专区| 黄色在线成人| 一区二区三区回区在观看免费视频| 欧美日韩国产影片| 中文亚洲视频在线| 亚洲免费精品| 欧美日韩在线播放三区| 老司机精品视频网站| 久久精品国产综合精品| 亚洲午夜精品视频| 亚洲一区二三| 一本久久精品一区二区| 久久欧美中文字幕| 最新高清无码专区| 久久精品成人| 欧美一区二区三区的| 欧美日韩播放| 亚洲观看高清完整版在线观看| 欧美人体xx| 亚洲在线国产日韩欧美| 欧美福利视频| 欧美大片在线看免费观看| 国产亚洲成年网址在线观看| 久久久免费观看视频| 美女国产精品| 麻豆九一精品爱看视频在线观看免费| 国产精品影音先锋| 欧美不卡视频一区| 欧美日韩免费观看一区三区| 亚洲高清色综合| 亚洲成色www8888| 久久免费的精品国产v∧| 久久久久久夜| 狠狠入ady亚洲精品经典电影| 欧美大片免费观看在线观看网站推荐 | 夜久久久久久| 狠狠色伊人亚洲综合成人| 欧美亚洲一区二区三区| 亚洲日本va午夜在线影院| 久久久欧美精品| 亚洲天堂成人| 国产精品免费看| 亚洲一区在线播放| 久久成人精品电影| 欧美黑人国产人伦爽爽爽| 亚洲激情成人网| 在线综合亚洲| 免费一级欧美片在线播放| 欧美在线视频导航| 韩国女主播一区二区三区| 久久精品亚洲精品| 欧美激情精品久久久六区热门| 国产麻豆9l精品三级站| 久久aⅴ国产欧美74aaa| 欧美大色视频| 国产精品99久久久久久白浆小说| 欧美视频一区在线| 欧美在线|欧美| 亚洲国产精品一区二区第一页| 99精品视频免费| 免费久久精品视频| 一本色道久久88精品综合| 亚洲一区久久久| 国产一区二区三区久久悠悠色av| 亚洲免费福利视频| 久久精品99无色码中文字幕| 1000部国产精品成人观看| 欧美日韩一级黄| 欧美一区二区女人| 亚洲黄色片网站| 欧美一区二区三区四区夜夜大片| 在线精品视频免费观看| 欧美午夜理伦三级在线观看| 久久综合九色综合久99| 国产精品入口夜色视频大尺度| 日韩香蕉视频| 久久精品最新地址| 国产欧美精品日韩精品| 麻豆91精品91久久久的内涵| 亚洲一级二级在线| 欧美激情精品久久久久久| 欧美一区二区日韩一区二区| 日韩午夜在线| 精品电影在线观看| 国产乱码精品一区二区三区忘忧草| 免费看的黄色欧美网站| 先锋影音久久| 一区二区三区日韩欧美| 亚洲国产精品毛片| 久久综合导航| 久久疯狂做爰流白浆xx| 妖精成人www高清在线观看| 伊人久久噜噜噜躁狠狠躁| 国产精品黄视频| 欧美一区1区三区3区公司| 99精品热视频| 亚洲黄色尤物视频| 欧美高清不卡在线| 久热精品视频在线观看一区| 欧美在线首页| 欧美亚洲日本国产| 黄色在线成人| 国产一区二区三区黄| 国产欧美日韩免费| 国产精品视频xxx| 国产精品久久久久久久午夜 | 久久综合色8888| 亚洲日本激情| 久久精品女人的天堂av| 亚洲欧美网站| 亚洲专区欧美专区| 亚洲自拍啪啪| 性18欧美另类| 久久国产精品亚洲77777| 性视频1819p久久| 久久国产加勒比精品无码| 欧美一区二区播放| 久久激情中文| 老牛影视一区二区三区| 欧美 日韩 国产 一区| 欧美电影免费观看| 91久久精品一区二区别| 最近中文字幕mv在线一区二区三区四区| 欧美黄色一级视频| 亚洲日本成人女熟在线观看| 亚洲欧洲日本mm| 一区二区三区四区五区在线| 欧美成年人在线观看| 欧美激情一区二区三区全黄| 亚洲国产精品一区二区www在线| 亚洲人成网站在线播| 亚洲久久一区| 欧美激情第六页| 亚洲毛片在线| 午夜精品福利视频| 一区二区国产精品| 午夜精品久久久久久久久久久久久 | 欧美黄色小视频| 亚洲另类在线视频| 欧美一级二级三级蜜桃| 另类专区欧美制服同性| 欧美日韩18| 国产亚洲精品高潮| 亚洲美女诱惑| 欧美一区亚洲| 亚洲国产高清高潮精品美女| 一区二区三区黄色| 久久久久久网站| 国产精品mm| 亚洲第一网站| 欧美一级播放| 最新成人av网站| 午夜国产不卡在线观看视频| 女人香蕉久久**毛片精品| 国产精品一区二区欧美| 亚洲人被黑人高潮完整版| 欧美伊人久久久久久午夜久久久久| 男女激情久久| 亚洲免费在线看| 亚洲欧美综合另类中字| 欧美精品成人91久久久久久久| 欧美激情国产精品| 国模一区二区三区| 亚洲国产一区二区三区青草影视|