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

隨筆 - 96  文章 - 255  trackbacks - 0
<2010年7月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

E-mail:zbln426@163.com QQ:85132383 長(zhǎng)期尋找對(duì)戰(zhàn)略游戲感興趣的合作伙伴。

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關(guān)網(wǎng)站

我的個(gè)人網(wǎng)頁(yè)

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 495931
  • 排名 - 39

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

Widows version:

//UVi Soft ( 2008 )
//Long Fei ( lf426 ), E-mail: zbln426@163.com
//Laboratory of ZaiBieLiunNian
//http://m.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://m.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://m.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://m.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楷體,文泉驛字庫(kù)。

last update: 2008-05-12

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

FeedBack:
# re: SurfaceClass 2012-06-08 14:00 周爽
實(shí)現(xiàn)文件可以看一下么?  回復(fù)  更多評(píng)論
  
# re: SurfaceClass 2012-06-08 14:01 周爽
我對(duì)編程跟SDL都是新手,希望指教下  回復(fù)  更多評(píng)論
  

只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   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>
              aⅴ色国产欧美| 欧美精品一区二区三区蜜臀| 欧美在线一区二区| 亚洲欧美在线一区| 亚洲欧美国产一区二区三区| 国产一区二区三区四区老人| 欧美freesex8一10精品| 欧美日韩你懂的| 欧美一区二视频| 久久久青草婷婷精品综合日韩| 亚洲美女诱惑| 亚洲天堂成人| 激情亚洲网站| 亚洲精品一区二区三区四区高清| 国产精品久久久免费| 美女视频网站黄色亚洲| 欧美黑人国产人伦爽爽爽| 亚洲综合激情| 久久久久久久久久久久久女国产乱 | 欧美日韩国产不卡| 新67194成人永久网站| 久久久久久久精| 亚洲深夜影院| 久久精品人人做人人综合 | 欧美国产日本在线| 欧美日韩在线播放一区二区| 久久久之久亚州精品露出| 欧美成人三级在线| 羞羞色国产精品| 男男成人高潮片免费网站| 午夜日韩电影| 免费在线欧美黄色| 校园春色综合网| 免费在线观看一区二区| 欧美在线视频全部完| 欧美成人免费网| 久久激情视频久久| 欧美精品在欧美一区二区少妇| 久久精品99国产精品日本| 欧美伦理a级免费电影| 久久久亚洲人| 欧美三级在线视频| 欧美成人免费播放| 国产欧美一区二区三区在线老狼 | 99精品国产高清一区二区| 黄网站色欧美视频| 在线午夜精品自拍| 91久久国产综合久久蜜月精品 | 欧美在线播放视频| 欧美国产精品| 久久夜色精品国产| 国产精品视频yy9299一区| 亚洲高清免费在线| 国产亚洲成av人在线观看导航| 亚洲片区在线| 在线成人国产| 亚洲欧美一区二区三区极速播放| 99精品热视频只有精品10| 久久人人爽人人爽爽久久| 欧美亚洲三区| 欧美日韩在线第一页| 亚洲高清视频一区| 国产一区观看| 亚洲一区久久| 中文亚洲视频在线| 欧美成人中文字幕在线| 蜜桃精品一区二区三区| 国产视频亚洲| 亚洲女ⅴideoshd黑人| 亚洲影院免费观看| 欧美激情精品久久久久久蜜臀| 免费国产一区二区| 国产一区在线免费观看| 亚洲一区中文| 亚洲午夜视频| 欧美女主播在线| 亚洲国产精品va在看黑人| 亚洲大胆在线| 久久久噜久噜久久综合| 久久久久久穴| 国产亚洲激情视频在线| 亚洲影视中文字幕| 亚洲淫性视频| 欧美日一区二区三区在线观看国产免 | 女同性一区二区三区人了人一| 久久久久免费| 国产亚洲一本大道中文在线| 亚洲男女毛片无遮挡| 午夜精品成人在线| 国产精品久久久| 亚洲无毛电影| 亚洲欧美国产高清va在线播| 国产精品成人久久久久| 亚洲精品专区| 中国成人黄色视屏| 欧美日韩免费在线观看| 9l国产精品久久久久麻豆| 国产原创一区二区| 亚洲精品一二三区| 99日韩精品| 欧美日本中文字幕| 亚洲精品在线视频| 一区二区久久久久| 欧美区亚洲区| 一区二区三区日韩欧美精品| 欧美人体xx| 一个色综合导航| 亚洲欧美在线免费| 国产日产欧美a一级在线| 午夜精品福利电影| 久久深夜福利| 亚洲国产精品一区二区第一页| 久久日韩精品| 亚洲高清自拍| 99亚洲一区二区| 欧美午夜视频| 亚洲欧美制服中文字幕| 久久蜜桃av一区精品变态类天堂| 国内一区二区三区在线视频| 久久噜噜噜精品国产亚洲综合| 欧美高清在线观看| 日韩视频在线免费| 国产精品电影在线观看| 亚洲欧美一级二级三级| 久热精品在线| 亚洲精品偷拍| 欧美亚男人的天堂| 午夜日韩视频| 欧美成人一区在线| 99精品视频一区| 国产精品日韩在线播放| 久久精品人人做人人爽电影蜜月 | 欧美午夜片在线免费观看| 亚洲欧美在线免费观看| 免费的成人av| 日韩亚洲综合在线| 国产精品久久久一本精品| 亚洲综合成人在线| 巨乳诱惑日韩免费av| 亚洲精品视频在线观看免费| 欧美性理论片在线观看片免费| 亚洲欧美三级伦理| 美女999久久久精品视频| 99天天综合性| 国产亚洲一区二区三区在线观看| 久久亚洲精品一区| 亚洲精品日韩一| 久久精品视频99| 91久久国产综合久久91精品网站| 欧美午夜视频一区二区| 久久国产精彩视频| 亚洲精品一区在线观看| 久久精品视频在线观看| 亚洲精品一区二区三区樱花| 国产精品久久久久久久一区探花| 久久久久久久综合狠狠综合| 日韩视频永久免费| 久久久欧美一区二区| 一区二区三区视频观看| 国产一区二区欧美| 欧美日产一区二区三区在线观看| 午夜一级在线看亚洲| 亚洲国产日韩美| 久久动漫亚洲| 一本色道久久88精品综合| 国产一级久久| 欧美日韩一区二| 久久亚洲综合色一区二区三区| 夜夜嗨av色综合久久久综合网| 裸体女人亚洲精品一区| 亚洲免费在线看| 亚洲日本aⅴ片在线观看香蕉| 亚洲欧美在线网| 亚洲国产精品成人综合色在线婷婷| 欧美自拍丝袜亚洲| 一区二区三区毛片| 亚洲第一中文字幕| 国产精品一区二区三区乱码| 欧美高清在线一区| 久久精品日韩欧美| 亚洲天堂男人| 亚洲国产一区二区a毛片| 久久久噜噜噜久久中文字免| 亚洲一区二区三区精品视频 | 亚洲第一综合天堂另类专| 国产精品久久久免费| 欧美福利网址| 久久久www| 亚洲一区三区电影在线观看| 亚洲全黄一级网站| 快she精品国产999| 欧美在线观看天堂一区二区三区| 夜夜嗨av色综合久久久综合网| 在线日本成人| 国产日韩精品在线播放| 国产精品成人播放| 欧美日韩国产美| 免费久久久一本精品久久区| 久久国产精品久久久久久电车| 亚洲午夜精品一区二区|