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

隨筆 - 96  文章 - 255  trackbacks - 0
<2013年3月>
242526272812
3456789
10111213141516
17181920212223
24252627282930
31123456

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

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關網站

我的個人網頁

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 495367
  • 排名 - 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>
              欧美亚洲日本网站| 91久久精品www人人做人人爽| 欧美一级视频一区二区| 欧美小视频在线| 亚洲一区二区三区精品在线| 最新成人av网站| 欧美四级伦理在线| 午夜国产欧美理论在线播放| 欧美一级视频精品观看| 国产亚洲欧美日韩日本| 国产专区一区| 欧美网站大全在线观看| 亚洲欧美视频在线| 99精品免费| 亚洲欧美国产三级| 亚洲欧美经典视频| 亚洲国产一二三| 快播亚洲色图| 亚洲三级性片| 亚洲天堂av高清| 欧美成人综合网站| 欧美日韩国产精品成人| 亚洲综合色激情五月| 在线观看国产精品网站| 91久久线看在观草草青青| 久久亚洲色图| 欧美性做爰毛片| 亚洲国产经典视频| 欧美一区日韩一区| 亚洲国产成人在线| 欧美在线视频日韩| 国产精品久久久久久模特| 国产女优一区| 亚洲伊人观看| 最新热久久免费视频| 亚洲欧美高清| 亚洲午夜av电影| 一区二区三区高清在线观看| 亚洲女爱视频在线| 亚洲另类春色国产| 亚洲电影免费观看高清完整版在线观看| 午夜电影亚洲| 免费在线看成人av| 久久久亚洲国产美女国产盗摄| 亚洲免费高清视频| 欲香欲色天天天综合和网| 国产精品久久久久影院色老大| 毛片一区二区| 亚洲国产第一| 久久精品三级| 欧美成人午夜剧场免费观看| 六月婷婷一区| 久久成人亚洲| 1204国产成人精品视频| 久久精品亚洲热| 亚洲一区视频在线| 国内免费精品永久在线视频| 久久久国产午夜精品| 欧美成人蜜桃| 在线视频一区二区| 欧美日韩欧美一区二区| 亚洲大片在线观看| 欧美国产日韩在线| 欧美午夜欧美| 欧美成人一区二区三区在线观看 | 亚洲麻豆一区| 国产精品成人在线观看| 亚洲人成亚洲人成在线观看图片 | 国产午夜精品一区二区三区欧美| 亚洲第一福利在线观看| 欧美在线观看一二区| 亚洲专区免费| 亚洲精品乱码久久久久久黑人| 亚洲激情欧美| 国内精品视频在线播放| 亚洲九九九在线观看| 国产精品免费看| 亚洲一区中文字幕在线观看| 国产精品一区二区三区观看 | 亚洲视频精品在线| 在线观看三级视频欧美| 日韩小视频在线观看| 韩国三级电影一区二区| 亚洲精品美女| 亚洲先锋成人| 欧美视频在线一区| 久久人人精品| 欧美成年人在线观看| 久久久久se| 亚洲影音先锋| 国产精品久久福利| 欧美成人精品h版在线观看| 国产精品视频免费观看| 99热在线精品观看| 久久婷婷亚洲| 一区二区av在线| 久久久午夜电影| 久久人人爽人人爽爽久久| 欧美激情亚洲| 欧美激情1区| 99精品久久久| 欧美日韩一区二区三区四区五区| 久久www成人_看片免费不卡| 久久精品视频导航| 欧美激情一区二区三区全黄 | 免费观看日韩av| 亚洲国产精品99久久久久久久久| 亚洲一区日本| 亚洲激情在线观看| 久久全球大尺度高清视频| 一区二区视频欧美| 国产麻豆精品久久一二三| 久久综合九色综合欧美就去吻| 久久日韩粉嫩一区二区三区| 欧美激情在线播放| 午夜精品久久久久久99热软件| 99精品免费网| 在线观看日韩av| 国产亚洲精品一区二555| 久久精品系列| 亚洲性感美女99在线| 久久裸体视频| 欧美国产综合视频| 免费成人av| 欧美日韩一二区| 欧美视频不卡| 国产精品久久久久久妇女6080 | 日韩午夜电影| 午夜亚洲视频| 午夜视频在线观看一区二区三区| 国产精品一区二区在线| 欧美一区国产一区| 欧美一区二区三区喷汁尤物| 久久精品人人做人人综合| 亚洲精品综合在线| 亚洲国产精品第一区二区三区| 欧美日韩在线观看一区二区| 香蕉久久一区二区不卡无毒影院| 亚洲黄色在线| 亚洲免费网址| 欧美精品一区在线| 国产日韩欧美电影在线观看| 欧美日韩一区综合| 亚洲国产你懂的| 1000精品久久久久久久久| 国产欧美精品一区| 狠狠久久婷婷| 亚洲少妇一区| 亚洲第一偷拍| 免费一级欧美在线大片| 欧美特黄a级高清免费大片a级| 国产精品久久久久秋霞鲁丝 | 欧美成人在线免费观看| 一区二区三区.www| 久久精品99| 一区二区三区日韩精品| 亚洲一区二区三区中文字幕在线| 亚洲人成网站在线观看播放| 国产精品久久午夜夜伦鲁鲁| 欧美午夜精品久久久久久浪潮| 欧美精品一区二区三区蜜臀| 久久夜色精品国产噜噜av| 欧美日本一区二区视频在线观看| 欧美日韩一区二区三区四区五区| 国产亚洲视频在线| 猛干欧美女孩| 欧美日韩大片一区二区三区| 欧美风情在线观看| 国产精品视频福利| 中文av字幕一区| 亚洲精品一区二区在线| 亚洲一区制服诱惑| 国产精品日韩精品欧美在线| 国产资源精品在线观看| 亚洲午夜影视影院在线观看| 亚洲免费电影在线观看| 亚洲视频自拍偷拍| 欧美肥婆在线| 欧美久久久久久久久| 亚洲天堂激情| 麻豆av一区二区三区| 国产午夜精品理论片a级探花 | 欧美粗暴jizz性欧美20| 欧美在线二区| 一区二区精品| 久久婷婷久久| 一本色道久久综合亚洲精品小说| 久久人人超碰| 欧美福利网址| 另类图片国产| 欧美精品久久久久久久免费观看| 国产主播在线一区| 你懂的视频一区二区| 开心色5月久久精品| 亚洲第一区色| 欧美在线你懂的| 免费久久99精品国产自| 一区二区毛片| 在线观看中文字幕不卡| 欧美激情国产精品|