• <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  文章 - 255  trackbacks - 0
            <2008年2月>
            272829303112
            3456789
            10111213141516
            17181920212223
            2425262728291
            2345678

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

            常用鏈接

            留言簿(21)

            隨筆分類

            隨筆檔案

            SDL相關網站

            我的個人網頁

            我的小游戲

            資源下載

            搜索

            •  

            積分與排名

            • 積分 - 493120
            • 排名 - 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 閱讀(2754) 評論(1)  編輯 收藏 引用 所屬分類: mySDL_GameEngine

            FeedBack:
            # re: ButtonClass 2012-08-06 00:09 hehe
            樓主給個示例吧, 不用啊.  回復  更多評論
              
            青草国产精品久久久久久| 国内高清久久久久久| www.久久热.com| 久久精品国产福利国产琪琪| 开心久久婷婷综合中文字幕| 狠狠色综合网站久久久久久久高清| 亚洲乱码精品久久久久.. | 久久免费精品一区二区| 婷婷久久综合九色综合98| 久久久精品波多野结衣| 久久人人爽人人爽人人片av高请| 国产一区二区三区久久精品| 无码精品久久一区二区三区| 久久无码人妻一区二区三区午夜| 国产精品激情综合久久| 乱亲女H秽乱长久久久| 久久精品这里只有精99品| 久久亚洲AV成人无码电影| 色综合久久天天综线观看| 青草影院天堂男人久久| 亚洲午夜无码久久久久| 一本大道久久香蕉成人网| 久久噜噜电影你懂的| 久久久久人妻一区精品色 | AAA级久久久精品无码片| 无码乱码观看精品久久| 久久久久久国产精品美女| 久久99国产精品久久久| 人妻少妇久久中文字幕一区二区| 伊色综合久久之综合久久| 日韩欧美亚洲综合久久影院Ds| 日本福利片国产午夜久久| 久久99精品久久久久久久不卡| 午夜天堂av天堂久久久| 久久国产亚洲精品| 久久久久久久久久久精品尤物| 午夜精品久久久久| 欧美国产成人久久精品| 午夜福利91久久福利| 午夜精品久久久久久| 亚洲午夜久久久|