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

隨筆 - 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://www.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://www.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>
              在线欧美三区| 亚洲人屁股眼子交8| 亚洲欧洲99久久| 亚洲在线1234| 国产综合久久| 亚洲国产第一页| 欧美日本亚洲视频| 午夜久久美女| 久久国产精品久久精品国产| 国产午夜精品理论片a级大结局| 久久精品导航| 欧美69wwwcom| 亚洲欧美不卡| 久久亚洲不卡| 亚洲一区久久| 久久精品国产亚洲精品| 亚洲高清资源| 亚洲素人一区二区| 亚洲第一精品电影| 一本综合久久| 国产综合网站| 亚洲美女免费精品视频在线观看| 国产精品一卡二| 欧美高清视频在线观看| 国产精品久久久久9999高清| 久久精品视频在线观看| 欧美成人国产| 久久久久国产精品www| 嫩草伊人久久精品少妇av杨幂| 亚洲视屏在线播放| 久久国产一区二区| 亚洲图片在区色| 久久久久国产成人精品亚洲午夜| av成人免费在线| 久久青草欧美一区二区三区| 亚洲综合日韩在线| 老司机成人网| 欧美在线日韩在线| 欧美日韩一区二区免费视频| 另类欧美日韩国产在线| 国产精品第2页| 亚洲黄一区二区三区| 国产日韩欧美一区二区| 一本色道久久综合一区 | 亚洲人成人77777线观看| 国产精品视屏| 在线视频欧美一区| 一本一道久久综合狠狠老精东影业| 小嫩嫩精品导航| 亚洲夜晚福利在线观看| 欧美大成色www永久网站婷| 久久天堂成人| 国产日韩亚洲欧美综合| 亚洲午夜一区| 亚洲欧美日韩精品在线| 欧美体内she精视频| 亚洲经典一区| 亚洲精选视频在线| 蜜臀99久久精品久久久久久软件| 欧美在线视频播放| 国产精品中文在线| 亚洲影视在线播放| 欧美一二三区精品| 国产精品美女一区二区| 99在线热播精品免费| 一区二区三区蜜桃网| 欧美日韩精品欧美日韩精品一| 亚洲第一色中文字幕| 亚洲第一久久影院| 免费中文日韩| 亚洲久久视频| 亚洲视频在线免费观看| 欧美性开放视频| 中日韩视频在线观看| 亚洲欧美日韩国产中文在线| 国产精品久久久久aaaa| 午夜精品久久久久久久久久久| 性久久久久久| 国产一区二区三区久久| 久久久久久久国产| 亚洲日本va午夜在线电影| 亚洲精选在线观看| 欧美色精品天天在线观看视频| 日韩图片一区| 久久精品av麻豆的观看方式| 韩国v欧美v日本v亚洲v| 久久男人资源视频| 亚洲看片一区| 欧美综合国产精品久久丁香| 国内精品久久久| 欧美成人tv| 在线天堂一区av电影| 久久九九全国免费精品观看| 亚洲国产欧美日韩另类综合| 欧美国产精品久久| 亚洲综合99| 欧美激情精品久久久久久黑人 | 欧美午夜片欧美片在线观看| 亚洲天堂av综合网| 狂野欧美激情性xxxx欧美| 日韩天堂在线视频| 国产午夜亚洲精品理论片色戒| 久久综合综合久久综合| 一本色道久久综合亚洲精品婷婷 | 欧美专区在线| 亚洲欧洲视频| 国产欧美一区二区精品婷婷| 老**午夜毛片一区二区三区| 一本高清dvd不卡在线观看| 久久久国产精彩视频美女艺术照福利 | 亚洲国产婷婷香蕉久久久久久| 亚洲女女女同性video| 亚洲第一天堂av| 国产精品视频一二三| 欧美激情视频一区二区三区免费| 亚洲中午字幕| 日韩一本二本av| 欧美福利一区| 久久一综合视频| 午夜日韩视频| 在线中文字幕一区| 最新日韩欧美| 在线日韩av| 国产自产v一区二区三区c| 国产精品福利在线观看| 美女网站在线免费欧美精品| 欧美一级免费视频| 午夜精品视频网站| 99热这里只有精品8| 亚洲第一区在线| 欧美69视频| 另类国产ts人妖高潮视频| 欧美一区二区视频97| 亚洲免费视频在线观看| 一本色道精品久久一区二区三区| 亚洲电影第1页| 伊人成人网在线看| 国产亚洲精品bv在线观看| 国产精品卡一卡二| 国产精品久久久久三级| 国产精品v日韩精品| 国产精品sss| 国产精品久久国产三级国电话系列 | 亚洲精品之草原avav久久| 欧美国产成人精品| 欧美激情一区二区三区在线视频观看 | 中日韩午夜理伦电影免费| 亚洲黄一区二区| 日韩亚洲一区二区| 一区二区三区精品在线| 夜色激情一区二区| 一区二区三区视频在线看| 夜夜精品视频| 亚洲一区二区三区乱码aⅴ| 99精品欧美一区二区三区| 亚洲精品一品区二品区三品区| 亚洲日本中文字幕| 一区二区三区黄色| 亚洲欧美在线磁力| 久久久久久久久综合| 久久天堂成人| 欧美日韩国产色综合一二三四 | 伊人久久av导航| 亚洲欧洲一级| 亚洲一区精品在线| 久久精品国产综合精品| 麻豆精品传媒视频| 亚洲福利小视频| 一区二区国产在线观看| 亚洲欧美另类国产| 蜜桃av噜噜一区二区三区| 欧美美女喷水视频| 国产精品入口| 亚洲高清中文字幕| 在线天堂一区av电影| 欧美在线视频在线播放完整版免费观看 | 毛片精品免费在线观看| 亚洲国产美女精品久久久久∴| 日韩午夜黄色| 久久精品九九| 欧美亚一区二区| 在线欧美电影| 欧美自拍偷拍午夜视频| 亚洲国产精品成人久久综合一区| 在线视频中文亚洲| 久久综合中文色婷婷| 国产精品久久久久久av下载红粉 | 欧美视频免费| 黄色成人在线免费| 亚洲一区尤物| 亚洲高清免费视频| 久久大逼视频| 国产精品你懂的| 日韩亚洲欧美中文三级| 久久婷婷av| 亚洲欧美国产高清| 欧美日韩国产精品自在自线| 国产综合色在线视频区| 午夜精品福利电影| 日韩视频精品在线|