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

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

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

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關網站

我的個人網頁

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 495350
  • 排名 - 39

最新評論

閱讀排行榜

評論排行榜

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

//FileName: ButtonClass.hpp

#ifndef BUTTON_CLASS_HPP
#define BUTTON_CLASS_HPP

#include 
"SurfaceClass.hpp"

class BaseButton
{
private:
    
//
protected:
    
int atX;
    
int atY;
    
int offset;
    
int w;
    
int h;
    
//ButtonEffect
    bool inBox;
    
bool clickDown;
    
bool clickUp;
public:
    BaseButton();
    
virtual ~BaseButton();
    
void setup(int at_x, int at_y, int _offset = 0);
    
virtual void colorKey(Uint8 r, Uint8 g, Uint8 b) = 0;
    
virtual void blitOut() const = 0;
    
virtual void blitOver() const = 0;
    
virtual void blitDown() const = 0;
    
virtual void addText(const TextSurface& out_text, const TextSurface& over_text) = 0;
    
bool mouseOver(const SDL_Event& gameEvent) const;
    
bool mouseDown(const SDL_Event& gameEvent) const;
    
bool mouseUp(const SDL_Event& gameEvent) const;
    
bool mouseUpOutside(const SDL_Event& gameEvent) const;
    
bool effectiveClick(const SDL_Event& game_event);
};

class Button: public BaseButton
{
private:
    
//
protected:
    BaseSurface outImg;
    BaseSurface overImg;
public:
    Button(
const std::string& outImg_fileName, const std::string& overImg_fileName, const ScreenSurface& screen);
    Button(
const BaseSurface& out_img, const BaseSurface& over_img);
    Button(
const std::string buttonText, const ScreenSurface& screen,
        Uint8 out_r 
= 0xFF, Uint8 out_g = 0xFF, Uint8 out_b = 0xFF, Uint8 on_r = 0, Uint8 on_g = 0, Uint8 on_b = 0xFF,
        
int ttf_size = 28const std::string& ttf_fileName = "./fonts/gkai00mp.ttf");
    
virtual ~Button();
    
virtual void colorKey(Uint8 r = 0, Uint8 g = 0xFF, Uint8 b = 0xFF);
    
virtual void blitOut() const;
    
virtual void blitOver() const;
    
virtual void blitDown() const;
    
virtual void addText(const TextSurface& out_text, const TextSurface& over_text);
};

class ButtonPlus: public Button
{
private:
    BaseSurface downImg;
public:
    ButtonPlus(
const std::string& outImg_fileName, const std::string& overImg_fileName, const std::string& downImg_fileName,
        
const ScreenSurface& screen);
    ButtonPlus(
const BaseSurface& out_img, const BaseSurface& over_img, const BaseSurface& down_img);
    
virtual void colorKey(Uint8 r = 0, Uint8 g = 0xFF, Uint8 b = 0xFF);
    
virtual void blitDown() const;
    
virtual void addText(const TextSurface& out_text, const TextSurface& over_text);
};

class SpriteButton: public BaseButton
{
private:
    PictureSurface spriteSheet;
    
int outX;
    
int outY;
    
int overX;
    
int overY;
    
int downX;
    
int downY;
public:
    SpriteButton(
const std::string& spriteSheet_fileName, const ScreenSurface& screen,
        
int button_w, int button_h,
        
int out_x, int out_y, int over_x, int over_y, int down_x, int down_y);
    
virtual void colorKey(Uint8 r = 0, Uint8 g = 0xFF, Uint8 b = 0xFF);
    
virtual void blitOut() const;
    
virtual void blitOver() const;
    
virtual void blitDown() const;
    
virtual void addText(const TextSurface& out_text, const TextSurface& over_text);
};

#endif

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

#include 
"ButtonClass.hpp"

//*************************
//class BaseButton

BaseButton::BaseButton():
atX(
0), atY(0), w(0), h(0), offset(0),
inBox(
false), clickDown(false), clickUp(false)
{}

BaseButton::
~BaseButton()
{}

void BaseButton::setup(int at_x, int at_y, int _offset)
{
    atX 
= at_x;
    atY 
= at_y;
    offset 
= _offset;
}

bool BaseButton::mouseOver(const SDL_Event& gameEvent) const
{
    
if ( gameEvent.type == SDL_MOUSEMOTION ){
        
int mouse_at_x = gameEvent.motion.x;
        
int mouse_at_y = gameEvent.motion.y;
        
if ( mouse_at_x >= atX && mouse_at_x <= atX + w &&
            mouse_at_y 
>= atY && mouse_at_y <= atY + h )
                
return true;
        
else return false;
    }
    
else return false;
}

bool BaseButton::mouseDown(const SDL_Event& gameEvent) const
{
    
if ( gameEvent.type == SDL_MOUSEBUTTONDOWN )
        
if( gameEvent.button.button == SDL_BUTTON_LEFT ){
            
int mouse_at_x = gameEvent.button.x;
            
int mouse_at_y = gameEvent.button.y;
            
if ( mouse_at_x >= atX && mouse_at_x <= atX + w &&
                mouse_at_y 
>= atY && mouse_at_y <= atY + h )
                
return true;
            
else return false;
        }
        
else return false;
    
else return false;
}

bool BaseButton::mouseUp(const SDL_Event& gameEvent) const
{
    
if ( gameEvent.type == SDL_MOUSEBUTTONUP )
        
if( gameEvent.button.button == SDL_BUTTON_LEFT ){
            
int mouse_at_x = gameEvent.button.x;
            
int mouse_at_y = gameEvent.button.y;
            
if ( mouse_at_x >= atX && mouse_at_x <= atX + w &&
                mouse_at_y 
>= atY && mouse_at_y <= atY + h )
                
return true;
            
else return false;
        }
        
else return false;
    
else return false;
}

bool BaseButton::mouseUpOutside(const SDL_Event& gameEvent) const
{
    
if ( gameEvent.type == SDL_MOUSEBUTTONUP )
        
if( gameEvent.button.button == SDL_BUTTON_LEFT ){
            
int mouse_at_x = gameEvent.button.x;
            
int mouse_at_y = gameEvent.button.y;
            
if ( mouse_at_x <= atX || mouse_at_x >= atX + w ||
                mouse_at_y 
<= atY || mouse_at_y >= atY + h )
                
return true;
            
else return false;
        }
        
else return false;
    
else return false;
}

bool BaseButton::effectiveClick(const SDL_Event& game_event)
{
    inBox 
= this->mouseOver(game_event);
    
if ( this->mouseDown(game_event) == true ){
        clickDown 
= true;
        inBox 
= true;
    }
    
if ( this->mouseUp(game_event) == true ){
        
if ( clickDown == true )
            clickUp 
= true;
        inBox 
= true;
    }
    
if ( this->mouseUpOutside(game_event) == true )
        clickDown 
= false;

    
if ( inBox == true && clickDown == false ){
        
this->blitOver();
        
return false;
    }
    
else if ( inBox == true && clickDown == true ){
        
if ( clickUp == true ){
            clickUp 
= false;
            clickDown 
= false;
            
this->blitOver();
            
return true;
        } 
else {
            
this->blitDown();
            
return false;
        }
    }
    
else {
        
this->blitOut();
        
return false;
    }
}

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


//*************************
//class Button
Button::Button(const std::string& outImg_fileName, const std::string& overImg_fileName, const ScreenSurface& screen):
BaseButton(),
outImg(PictureSurface(outImg_fileName, screen)),
overImg(PictureSurface(overImg_fileName, screen))
{
    w 
= outImg.point()->w;
    h 
= outImg.point()->h;
}

Button::Button(
const BaseSurface& out_img, const BaseSurface& over_img):
BaseButton(),
outImg(out_img), overImg(over_img)
{
    w 
= outImg.point()->w;
    h 
= outImg.point()->h;
}

Button::Button(
const std::string buttonText, const ScreenSurface& screen,
               Uint8 out_r, Uint8 out_g, Uint8 out_b, Uint8 on_r, Uint8 on_g, Uint8 on_b,
               
int ttf_size, const std::string& ttf_fileName):
BaseButton(),
outImg(TextSurface(buttonText, screen, out_r, out_g, out_b, ttf_size, ttf_fileName)),
overImg(TextSurface(buttonText, screen, on_r, on_g, on_b, ttf_size, ttf_fileName))
{
    w 
= outImg.point()->w;
    h 
= outImg.point()->h;
}

Button::
~Button()
{}

void Button::colorKey(Uint8 r, Uint8 g, Uint8 b)
{
    outImg.colorKey(r, g, b);
    overImg.colorKey(r, g, b);
}

void Button::blitOut() const
{
    outImg.blit(atX, atY);
}

void Button::blitOver() const
{
    overImg.blit(atX, atY);
}

void Button::blitDown() const
{
    overImg.blit(atX
+offset, atY+offset);
}

void Button::addText(const TextSurface& out_text, const TextSurface& over_text)
{
    out_text.blit(outImg);
    over_text.blit(overImg);
}

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

//****************************
//class ButtonPlus
ButtonPlus::ButtonPlus(const std::string& outImg_fileName, const std::string& overImg_fileName, const std::string& downImg_fileName,
        
const ScreenSurface& screen):
Button(outImg_fileName, overImg_fileName, screen),
downImg(PictureSurface(downImg_fileName, screen))
{}

ButtonPlus::ButtonPlus(
const BaseSurface& out_img, const BaseSurface& over_img, const BaseSurface& down_img):
Button(out_img, over_img),
downImg(down_img)
{}

void ButtonPlus::colorKey(Uint8 r, Uint8 g, Uint8 b)
{
    Button::colorKey(r, g, b);
    downImg.colorKey(r, g, b);
}

void ButtonPlus::blitDown() const
{
    downImg.blit(atX
+offset, atY+offset);
}

void ButtonPlus::addText(const TextSurface& out_text, const TextSurface& over_text)
{
    Button::addText(out_text, over_text);
    over_text.blit(downImg);
}

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

//****************************
//class SpriteButton

SpriteButton::SpriteButton(
const std::string& spriteSheet_fileName, const ScreenSurface& screen,
        
int button_w, int button_h,
        
int out_x, int out_y, int over_x, int over_y, int down_x, int down_y):
BaseButton(),
spriteSheet(spriteSheet_fileName, screen),
outX(out_x), outY(out_y), overX(over_x), overY(over_y), downX(down_x), downY(down_y)
{
    w 
= button_w;
    h 
= button_h;
}

void SpriteButton::colorKey(Uint8 r, Uint8 g, Uint8 b)
{
    spriteSheet.colorKey(r, g, b);
}

void SpriteButton::blitOut() const
{
    spriteSheet.blit(atX, atY, outX, outY, w, h);
}

void SpriteButton::blitOver() const
{
    spriteSheet.blit(atX, atY, overX, overY, w, h);
}

void SpriteButton::blitDown() const
{
    spriteSheet.blit(atX
+offset, atY+offset, downX, downY, w, h);
}

void SpriteButton::addText(const TextSurface& out_text, const TextSurface& over_text)
{
    
const int DELTA_outX = (w - out_text.point()->w) / 2;
    
const int DELTA_outY = (h - out_text.point()->h) / 2;
    
const int DELTA_overX = (w - over_text.point()->w) / 2;
    
const int DELTA_overY = (h - over_text.point()->h) / 2;

    out_text.blit(spriteSheet, outX
+DELTA_outX, outY+DELTA_outY);
    over_text.blit(spriteSheet, overX
+DELTA_overX, overY+DELTA_overY);
    over_text.blit(spriteSheet, downX
+DELTA_overX, downY+DELTA_overY);
}

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

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-04-15

posted on 2008-04-15 21:29 lf426 閱讀(2768) 評論(1)  編輯 收藏 引用 所屬分類: mySDL_GameEngine

FeedBack:
# re: ButtonClass 2012-08-06 00:09 hehe
樓主給個示例吧, 不用啊.  回復  更多評論
  

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   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>
              国产精品入口| 亚洲免费av观看| 一区二区日韩精品| 一个色综合导航| 亚洲一区在线免费观看| 午夜精品久久久| 久久精品视频免费| 久久综合九九| 亚洲国产毛片完整版| 亚洲人精品午夜| 亚洲综合视频1区| 久久九九有精品国产23| 欧美成年人视频网站欧美| 欧美日韩无遮挡| 国产午夜精品久久| 亚洲精选一区二区| 欧美一区在线看| 猛干欧美女孩| 一区二区三区蜜桃网| 久久激情视频久久| 欧美日韩在线精品| 伊人久久久大香线蕉综合直播| 夜色激情一区二区| 久久婷婷激情| 国产精品99久久99久久久二8| 欧美在线播放一区| 欧美人成在线| 极品少妇一区二区| 亚洲在线观看免费视频| 欧美国产日韩一区| 久久动漫亚洲| 国产精品一区二区男女羞羞无遮挡| 亚洲精华国产欧美| 久久午夜精品| 午夜精品久久久久久久久久久 | 欧美日韩中文字幕在线| 久久成人精品无人区| 欧美精品日韩综合在线| 国产一区二区三区成人欧美日韩在线观看 | 91久久精品国产| 欧美一区二区视频在线观看| 欧美日韩国产在线看| 亚洲经典三级| 欧美成年人网站| 久久www成人_看片免费不卡| 国产精品视频免费在线观看| 日韩一区二区精品| 免费亚洲婷婷| 久久国产精品一区二区三区| 国产伦精品一区二区三区高清版| 亚洲精选在线观看| 欧美激情免费观看| 欧美xx69| 亚洲精品综合在线| 亚洲国产日韩欧美在线99| 免费成人av在线看| 亚洲日本中文字幕| 亚洲高清资源综合久久精品| 美女国产精品| 亚洲欧洲日本专区| 亚洲成色777777女色窝| 欧美电影在线观看完整版| 在线看片欧美| 亚洲国产成人一区| 欧美另类女人| 亚洲欧美日本另类| 欧美一级艳片视频免费观看| 国内精品久久久久久影视8| 久久亚洲一区二区| 免费成年人欧美视频| 日韩午夜激情电影| 亚洲午夜羞羞片| 国产综合欧美| 亚洲电影观看| 欧美午夜精品理论片a级按摩| 亚洲欧美在线网| 欧美一区二区三区四区视频| 樱花yy私人影院亚洲| 亚洲精品一区中文| 国产精品黄视频| 久久国产精彩视频| 美玉足脚交一区二区三区图片| 亚洲精品免费电影| 一本色道久久综合亚洲91| 国产精品影音先锋| 欧美1区2区| 国产精品久久999| 麻豆精品视频在线| 欧美日韩专区在线| 蜜桃av一区二区三区| 欧美日韩影院| 免费不卡中文字幕视频| 欧美成人激情在线| 亚洲激情偷拍| 国产精品腿扒开做爽爽爽挤奶网站| 久久人人97超碰人人澡爱香蕉 | 久久精品中文字幕免费mv| 亚洲精品视频免费观看| 亚洲欧美日韩天堂| 夜夜夜久久久| 久久嫩草精品久久久精品一| 亚洲在线成人精品| 欧美不卡在线| 久久五月天婷婷| 国产精品久久激情| 亚洲国产激情| 韩日在线一区| 亚洲午夜视频| 亚洲图片在线| 欧美肥婆在线| 欧美 日韩 国产一区二区在线视频 | 久久精品视频在线免费观看| 欧美三区在线视频| 亚洲电影免费观看高清| 狠狠色丁香久久婷婷综合_中| 亚洲网友自拍| 亚洲专区一区| 欧美天堂在线观看| 亚洲激情小视频| 亚洲黄色成人网| 美女网站在线免费欧美精品| 另类av导航| 国内精品国产成人| 欧美一区观看| 久久久久网址| 狠狠色噜噜狠狠狠狠色吗综合| 亚洲男女毛片无遮挡| 亚洲欧美在线高清| 国产精品爽爽爽| 亚洲图片欧美午夜| 午夜视频在线观看一区二区| 国产精品久久久久久妇女6080| 日韩一二三区视频| 亚洲一区二区综合| 国产精品乱人伦一区二区 | 葵司免费一区二区三区四区五区| 国产日韩一区二区| 欧美一区二区私人影院日本| 久久久久久久一区二区| 伊人狠狠色丁香综合尤物| 久久男女视频| 亚洲国产一区在线| av成人老司机| 国产精品久久久一区二区| 亚洲免费网址| 久久亚洲综合网| 亚洲青色在线| 欧美视频精品在线| 午夜欧美视频| 欧美jizz19性欧美| 亚洲精品国产系列| 亚洲九九九在线观看| 欧美日韩欧美一区二区| 一本色道婷婷久久欧美| 午夜视频在线观看一区二区| 国产日韩在线播放| 老司机久久99久久精品播放免费| 亚洲国产天堂网精品网站| 亚洲一区二区三区高清| 国产日韩精品久久| 久久一区二区精品| 亚洲精品一区二区三区不| 欧美怡红院视频| 亚洲国产日韩欧美| 欧美午夜精品电影| 久久天天躁狠狠躁夜夜爽蜜月| 亚洲欧洲日本专区| 久久精彩视频| 99精品热视频只有精品10| 国产精品网站在线播放| 久热精品视频在线观看一区| 一本久久a久久精品亚洲| 久久久综合精品| 国产精品99久久久久久久女警| 国产午夜精品久久| 欧美精品一区二区三区在线看午夜| 亚洲在线视频免费观看| 亚洲国产精品悠悠久久琪琪| 久久经典综合| 亚洲午夜电影在线观看| 影音先锋亚洲视频| 国产精品视频999| 欧美高清hd18日本| 久久经典综合| 亚洲欧美日韩国产一区二区| 亚洲欧洲日韩综合二区| 久久免费视频网站| 亚洲欧美另类久久久精品2019| 亚洲国产日本| 精品不卡一区| 国产欧美一区二区三区视频| 欧美日韩亚洲一区二区三区在线观看 | 这里只有精品视频| 亚洲国产二区| 国产一级久久| 国产精品一区一区三区| 欧美午夜精品久久久久久久| 欧美黄色网络| 欧美成人一区二区三区在线观看 | 国产精品网站在线|