Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Sprite.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * スプライトヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef SPRITE_H_
00026 #define SPRITE_H_
00027 
00028 #include <Graphics2D/Renderer/SpriteRequest.h>
00029 
00030 namespace Lamp{
00031 
00032 class SpritePicture;
00033 
00034 //------------------------------------------------------------------------------
00035 /**
00036  * スプライト
00037  */
00038 class Sprite : public SpriteRequest{
00039 public:
00040     //--------------------------------------------------------------------------
00041     // 生成、破棄
00042     //--------------------------------------------------------------------------
00043     /**
00044      * コンストラクタ
00045      */
00046     Sprite();
00047 
00048     /**
00049      * コピーコンストラクタ
00050      * @param copy コピー元
00051      */
00052     explicit Sprite(const Sprite& copy);
00053 
00054     /**
00055      * 代入コピー
00056      * @param copy コピー元
00057      */
00058     Sprite& operator =(const Sprite& copy);
00059 
00060     /**
00061      * デストラクタ
00062      */
00063     virtual ~Sprite();
00064 
00065     //--------------------------------------------------------------------------
00066     // レンダリング
00067     //--------------------------------------------------------------------------
00068     /**
00069      * レンダリング
00070      * @param renderState レンダーステート
00071      */
00072     virtual void render(SpriteRenderState* renderState);
00073 
00074     //--------------------------------------------------------------------------
00075     // ピクチャ
00076     //--------------------------------------------------------------------------
00077     /**
00078      * ピクチャのロード
00079      * @param fileName ファイル名
00080      * @return 成功すればtrue
00081      */
00082     virtual bool loadPicture(const String& fileName);
00083 
00084     /**
00085      * ピクチャの設定
00086      * @param picture ピクチャ
00087      */
00088     virtual void setPicture(SpritePicture* picture);
00089 
00090     /**
00091      * ピクチャの取得
00092      * @return ピクチャ
00093      */
00094     virtual SpritePicture* getPicture(){ return picture_; }
00095 
00096     //--------------------------------------------------------------------------
00097     // 矩形
00098     //--------------------------------------------------------------------------
00099     /**
00100      * 矩形の設定
00101      * @param rectangle 設定する矩形
00102      */
00103     virtual void setRectangle(const RectangleF& rectangle){
00104         rectangle_ = rectangle;
00105     }
00106 
00107     /**
00108      * 矩形の設定
00109      * @param position 設定する矩形の位置
00110      * @param size 設定する矩形のサイズ
00111      */
00112     virtual void setRectangle(const Point2f& position, const DimensionF& size){
00113         rectangle_.set(position.x, position.y, size.width, size.height);
00114     }
00115 
00116     /**
00117      * 矩形の設定
00118      * @param x 設定する矩形のX位置
00119      * @param y 設定する矩形のY位置
00120      * @param width 設定する矩形の幅
00121      * @param height 設定する矩形の高さ
00122      */
00123     virtual void setRectangle(float x, float y, float width, float height){
00124         rectangle_.set(x, y, width, height);
00125     }
00126 
00127     /**
00128      * 矩形の取得
00129      * @return 矩形
00130      */
00131     virtual const RectangleF& getRectangle() const{ return rectangle_; }
00132 
00133     //--------------------------------------------------------------------------
00134     /**
00135      * 位置の設定
00136      * @param position 設定する位置
00137      */
00138     virtual void setPosition(const Point2f& position){
00139         rectangle_.x = position.x;
00140         rectangle_.y = position.y;
00141     }
00142 
00143     /**
00144      * 位置の設定
00145      * @param x X位置
00146      * @param y Y位置
00147      */
00148     virtual void setPosition(float x, float y){
00149         rectangle_.x = x;
00150         rectangle_.y = y;
00151     }
00152 
00153     /**
00154      * 位置の取得
00155      * @return 位置
00156      */
00157     virtual Point2f getPosition() const{
00158         return Point2f(rectangle_.x, rectangle_.y);
00159     }
00160 
00161     //--------------------------------------------------------------------------
00162     /**
00163      * サイズの設定
00164      * @param size 設定するサイズ
00165      */
00166     virtual void setSize(const DimensionF& size){
00167         rectangle_.width = size.width;
00168         rectangle_.height = size.height;
00169     }
00170 
00171     /**
00172      * サイズの設定
00173      * @param width 幅
00174      * @param height 高さ
00175      */
00176     virtual void setSize(float width, float height){
00177         rectangle_.width = width;
00178         rectangle_.height = height;
00179     }
00180 
00181     /**
00182      * サイズの取得
00183      * @return サイズ
00184      */
00185     virtual DimensionF getSize() const{
00186         return DimensionF(rectangle_.width, rectangle_.height);
00187     }
00188 
00189     //--------------------------------------------------------------------------
00190     // イメージ矩形
00191     //--------------------------------------------------------------------------
00192     /**
00193      * イメージ矩形の設定
00194      * @param imageRectangle 設定するイメージ矩形
00195      */
00196     virtual void setImageRectangle(const RectangleF& imageRectangle){
00197         imageRectangle_ = imageRectangle;
00198     }
00199 
00200     /**
00201      * イメージ矩形の設定
00202      * @param position 設定するイメージ矩形の位置
00203      * @param size 設定するイメージ矩形のサイズ
00204      */
00205     virtual void setImageRectangle(
00206         const Point2f& position, const DimensionF& size){
00207         imageRectangle_.set(position.x, position.y, size.width, size.height);
00208     }
00209 
00210     /**
00211      * イメージ矩形の設定
00212      * @param x 設定するイメージ矩形のX位置
00213      * @param y 設定するイメージ矩形のY位置
00214      * @param width 設定するイメージ矩形の幅
00215      * @param height 設定するイメージ矩形の高さ
00216      */
00217     virtual void setImageRectangle(
00218         float x, float y, float width, float height){
00219         imageRectangle_.set(x, y, width, height);
00220     }
00221 
00222     /**
00223      * イメージ矩形の取得
00224      * @return イメージ矩形
00225      */
00226     virtual const RectangleF& getImageRectangle() const{
00227         return imageRectangle_;
00228     }
00229 
00230     //--------------------------------------------------------------------------
00231     /**
00232      * イメージ位置の設定
00233      * @param position 設定するイメージ位置
00234      */
00235     virtual void setImagePosition(const Point2f& position){
00236         imageRectangle_.x = position.x;
00237         imageRectangle_.y = position.y;
00238     }
00239 
00240     /**
00241      * イメージ位置の設定
00242      * @param x Xイメージ位置
00243      * @param y Yイメージ位置
00244      */
00245     virtual void setImagePosition(float x, float y){
00246         imageRectangle_.x = x;
00247         imageRectangle_.y = y;
00248     }
00249 
00250     /**
00251      * イメージ位置の取得
00252      * @return イメージ位置
00253      */
00254     virtual Point2f getImagePosition() const{
00255         return Point2f(imageRectangle_.x, imageRectangle_.y);
00256     }
00257 
00258     //--------------------------------------------------------------------------
00259     /**
00260      * イメージサイズの設定
00261      * @param size 設定するイメージサイズ
00262      */
00263     virtual void setImageSize(const DimensionF& size){
00264         imageRectangle_.width = size.width;
00265         imageRectangle_.height = size.height;
00266     }
00267 
00268     /**
00269      * イメージサイズの設定
00270      * @param width イメージ幅
00271      * @param height イメージ高さ
00272      */
00273     virtual void setImageSize(float width, float height){
00274         imageRectangle_.width = width;
00275         imageRectangle_.height = height;
00276     }
00277 
00278     /**
00279      * イメージサイズの取得
00280      * @return イメージサイズ
00281      */
00282     virtual DimensionF getImageSize() const{
00283         return DimensionF(imageRectangle_.width, imageRectangle_.height);
00284     }
00285 
00286     //--------------------------------------------------------------------------
00287     /**
00288      * アニメーションの設定
00289      * @param animationDivision アニメーション分割
00290      * @param animation アニメーション
00291      * @param imageRectangle イメージ矩形
00292      */
00293     virtual void setAnimation(const DimensionI& animationDivision,
00294         int animation, const RectangleF& imageRectangle = RectangleF::unit);
00295 
00296     //--------------------------------------------------------------------------
00297     // アライン
00298     //--------------------------------------------------------------------------
00299     /// アライン
00300     enum Align{
00301         alignNone = 0,
00302         alignTopLeft,
00303         alignTop,
00304         alignTopRight,
00305         alignLeft,
00306         alignCenter,
00307         alignRight,
00308         alignBottomLeft,
00309         alignBottom,
00310         alignBottomRight,
00311         alignMax,
00312     };
00313 
00314     /**
00315      * アラインの設定
00316      * @param align アライン
00317      */
00318     virtual void setAlign(Align align){
00319         Assert((align >= 0) && (align < alignMax));
00320         align_ = align;
00321     }
00322 
00323     /**
00324      * アラインの取得
00325      * @return アライン
00326      */
00327     virtual Align getAlign() const{ return align_; }
00328 
00329     //--------------------------------------------------------------------------
00330     // フィット
00331     //--------------------------------------------------------------------------
00332     /// フィット
00333     enum Fit{
00334         fitNone = 0,
00335         fitScreen,
00336         fitScreenWidth,
00337         fitScreenHeight,
00338         fitMax,
00339     };
00340 
00341     /**
00342      * フィットの設定
00343      * @param fit フィット
00344      */
00345     virtual void setFit(Fit fit){
00346         Assert((fit >= 0) && (fit < fitMax));
00347         fit_ = fit;
00348     }
00349 
00350     /**
00351      * フィットの取得
00352      * @return フィット
00353      */
00354     virtual Fit getFit() const{ return fit_; }
00355 
00356     //--------------------------------------------------------------------------
00357     // 有効、無効
00358     //--------------------------------------------------------------------------
00359     /**
00360      * 有効、無効の設定
00361      * @param enabled trueなら有効、falseなら無効
00362      */
00363     virtual void setEnabled(bool enabled){ enabled_ = enabled; }
00364 
00365     /**
00366      * 有効、無効の取得
00367      * @return trueなら有効、falseなら無効
00368      */
00369     virtual bool isEnabled() const{ return enabled_; }
00370 
00371     //--------------------------------------------------------------------------
00372     // RTTI
00373     //--------------------------------------------------------------------------
00374     /**
00375      * スプライトかどうか
00376      * @return スプライトならtrue
00377      */
00378     virtual bool isSprite() const{ return true; }
00379 
00380 protected:
00381     //--------------------------------------------------------------------------
00382     // レンダリング
00383     //--------------------------------------------------------------------------
00384     /**
00385      * フィットの適用
00386      * @param rectangle 矩形
00387      * @param renderTargetSize レンダーターゲットサイズ
00388      * @return 矩形
00389      */
00390     virtual RectangleF applyFit(const RectangleF& rectangle,
00391         const DimensionF& renderTargetSize);
00392 
00393     /**
00394      * アラインの適用
00395      * @param rectangle 矩形
00396      * @param renderTargetSize レンダーターゲットサイズ
00397      * @return 矩形
00398      */
00399     virtual RectangleF applyAlign(const RectangleF& rectangle,
00400         const DimensionF& renderTargetSize);
00401 
00402 private:
00403     //--------------------------------------------------------------------------
00404     // ピクチャ
00405     SpritePicture* picture_;
00406     // 矩形
00407     RectangleF rectangle_;
00408     // イメージ矩形
00409     RectangleF imageRectangle_;
00410     // アライン
00411     Align align_;
00412     // フィット
00413     Fit fit_;
00414     // 有効、無効
00415     bool enabled_;
00416 
00417 };
00418 
00419 //------------------------------------------------------------------------------
00420 } // End of namespace Lamp
00421 #endif // End of SPRITE_H_
00422 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:36 2005 for Lamp by doxygen 1.3.2