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

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

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

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關網站

我的個人網頁

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 495654
  • 排名 - 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 閱讀(2769) 評論(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>
              欧美96在线丨欧| 免费在线欧美黄色| 欧美sm重口味系列视频在线观看| 亚洲一级网站| 欧美日韩另类一区| 欧美激情欧美激情在线五月| 国产亚洲精品bv在线观看| 99在线观看免费视频精品观看| 在线观看欧美黄色| 性久久久久久久久| 午夜老司机精品| 欧美三区在线| 亚洲精品综合精品自拍| 亚洲三级影院| 欧美激情精品久久久久| 欧美电影免费观看高清完整版| 亚洲欧美视频在线观看视频| 亚洲欧美国产精品va在线观看| 欧美日产一区二区三区在线观看| 美女尤物久久精品| 国产精品网站在线观看| 99re在线精品| 亚洲一区二区欧美| 久久影视精品| 欧美高清成人| 亚洲人成啪啪网站| 亚洲国产成人久久综合一区| 久久久夜色精品亚洲| 久久久综合网| 亚洲丰满在线| 奶水喷射视频一区| 亚洲黄色免费网站| 一区二区三区高清| 国产精品99免费看| 亚洲免费伊人电影在线观看av| 午夜视频在线观看一区二区三区 | 欧美在线观看视频一区二区| 国产精品美女久久久久久2018| 亚洲婷婷综合色高清在线| 国产精品素人视频| 欧美亚洲视频在线看网址| 久久久999| 亚洲激情网站| 欧美亚男人的天堂| 欧美一区日韩一区| 欧美国产综合视频| 中国日韩欧美久久久久久久久| 国产精品国产三级国产| 国产精品久久久久9999吃药| 亚洲欧洲av一区二区三区久久| 久久久亚洲影院你懂的| 亚洲国产欧美精品| 国产精品福利在线观看| 欧美在线观看日本一区| 欧美国产日产韩国视频| 亚洲亚洲精品在线观看| 国内成+人亚洲| 欧美区国产区| 久久av在线| 亚洲另类在线一区| 久久免费黄色| 一本色道久久综合亚洲精品高清 | 欧美国产日韩一区二区三区| 亚洲一卡久久| 欧美国产第二页| 亚洲欧美中文字幕| 亚洲精品国产精品国产自| 国产精品一区在线播放| 欧美大胆人体视频| 久久久久久有精品国产| 亚洲精品国产品国语在线app | 狠狠色丁香婷婷综合久久片| 欧美顶级少妇做爰| 欧美一级电影久久| 日韩视频一区二区三区在线播放| 久久精品99国产精品| 亚洲日本精品国产第一区| 亚洲欧美国产精品va在线观看| 1769国内精品视频在线播放| 国产精品久久久久久久久免费桃花| 久久久久九九九| 亚洲一区二区三| 亚洲区一区二| 欧美69wwwcom| 久久精品视频在线播放| 亚洲综合丁香| 在线视频欧美一区| 亚洲欧洲一区二区在线播放| 国产日韩一区二区三区在线| 国产精品激情av在线播放| 欧美成人精品在线播放| 久久一区二区三区国产精品| 欧美在线91| 欧美一区二区三区在线观看视频| 99亚洲一区二区| 亚洲精品一区二区三| 亚洲国产精品久久| 欧美电影免费观看大全| 欧美成人久久| 免费亚洲电影| 亚洲电影免费观看高清完整版| 国产美女精品视频| 国产精品视频网| 国产精品视频yy9299一区| 欧美午夜久久| 国产精品视频1区| 国产欧美日韩亚洲| 国产视频一区免费看| 国产精品亚洲综合一区在线观看| 欧美不卡高清| 亚洲午夜久久久| 亚洲视频在线观看三级| 在线亚洲精品| 亚洲综合精品一区二区| 亚洲欧美一级二级三级| 小嫩嫩精品导航| 久久精品亚洲一区二区三区浴池| 久久黄金**| 欧美1区2区3区| 亚洲激情欧美| 宅男精品导航| 性欧美xxxx大乳国产app| 久久岛国电影| 欧美成人dvd在线视频| 欧美日韩高清免费| 国产精品久久久久久五月尺| 国产日产高清欧美一区二区三区| 国产亚洲一区二区精品| 亚洲高清电影| 亚洲一二三级电影| 久久精品免费看| 欧美国产高潮xxxx1819| 99视频一区二区三区| 午夜精品久久久久99热蜜桃导演| 久久九九热免费视频| 欧美精品www| 国产精品一区二区男女羞羞无遮挡| 久久精品国产第一区二区三区| 久久先锋影音| 欧美视频在线观看一区二区| 国产亚洲综合在线| 亚洲精品美女在线观看播放| 午夜亚洲视频| 免费成人高清视频| 夜色激情一区二区| 久久久久久电影| 欧美视频在线观看一区| 亚洲视频一区二区| 亚洲人www| 欧美一区二区视频网站| 欧美激情视频在线播放| 国产精品亚洲综合色区韩国| 91久久综合| 久久久999成人| 在线一区视频| 欧美成人激情在线| 国产亚洲在线| 亚洲影院一区| 亚洲欧洲日产国码二区| 久久国产精品久久久| 欧美午夜在线一二页| 在线观看国产日韩| 欧美中文字幕| 日韩视频永久免费观看| 老鸭窝亚洲一区二区三区| 国产精品久久久久久久app| 亚洲区欧美区| 欧美aa国产视频| 欧美亚洲免费电影| 欧美调教vk| 99re6热只有精品免费观看 | 一本一道久久综合狠狠老精东影业| 欧美成人免费在线| 午夜精品久久久久久久久 | 欧美va亚洲va香蕉在线| 精品白丝av| 欧美中文字幕| 亚洲资源在线观看| 国产精品电影观看| 夜夜嗨一区二区| 亚洲激情电影在线| 老司机67194精品线观看| 久久久www成人免费精品| 亚洲主播在线| 国产精品久久久对白| 亚洲一区成人| 一本大道av伊人久久综合| 欧美日韩播放| 一区二区欧美在线观看| 91久久中文| 欧美日韩精品一区视频| 亚洲最新中文字幕| 亚洲精品久久久一区二区三区| 免费久久精品视频| 亚洲人午夜精品免费| 欧美激情第五页| 欧美激情亚洲国产| 在线视频亚洲一区| 亚洲视频精选| 国产日韩精品一区二区浪潮av|