SDXFrameWork  0.13
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Film.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5 #include <Multimedia/SDX.h>
6 #include <Multimedia/Image.h>
7 #include <Framework/ImagePack.h>
8 
9 namespace SDX
10 {
13  enum class NextFrame
14  {
15  Normal = -10000,
16  ToFront,
17  ToBack,
18  End,
19  };
20 
22  enum class FilmType
23  {
24  Normal,
25  Reverse,
26  End
27  };
28 
32  class Film : public ImagePack
33  {
34  friend class Anime;
35  private:
36  std::vector<unsigned int> times;
37  std::vector<int> nexts;
38  public:
39  Film() = default;
40 
42  Film(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦, int 1コマの再生時間 = 1) :
43  ImagePack(ファイル名, 総コマ数, コマ割り横, コマ割り縦)
44  {
45  for (int a = 0; a < 総コマ数; ++a)
46  {
47  times.push_back(1コマの再生時間);
48  nexts.push_back((int)NextFrame::Normal);
49  }
50  }
51 
53  Film(const char* ファイル名, const char *拡張子, int 総コマ数, int 1コマの再生時間 = 1, const char* 書式 = "%03d.")
54  {
55  Load(ファイル名, 拡張子, 総コマ数, 1コマの再生時間 ,書式);
56  }
57 
59  bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦, int 1コマの再生時間 = 1)
60  {
61  if (Loading::IsLoading())
62  {
63  Loading::AddLoading([=]{ Load(ファイル名, 総コマ数, コマ割り横, コマ割り縦, 1コマの再生時間); });
64  return true;
65  }
66 
67  if (!ImagePack::Load(ファイル名, 総コマ数, コマ割り横, コマ割り縦)) { return false; }
68 
69  for (int a = 0; a < 総コマ数; ++a)
70  {
71  times.push_back(1コマの再生時間);
72  nexts.push_back((int)NextFrame::Normal);
73  }
74 
75  return true;
76  }
77 
79  bool Load(const char* ファイル名, const char *拡張子, int 総コマ数, int 1コマの再生時間 = 1, const char* 書式 = "%03d.")
80  {
81  if (Loading::IsLoading())
82  {
83  Loading::AddLoading([=]{ Load(ファイル名, 拡張子, 総コマ数, 1コマの再生時間 , 書式); });
84  return true;
85  }
86 
87  for (int a = 0; a < 総コマ数; ++a)
88  {
89  char fileBuf[8];
90  sprintf_s(fileBuf, 8, 書式, a);
91  std::string fileName = ファイル名;
92  fileName += fileBuf;
93  fileName += 拡張子;
94 
95  this->Add(new Image(fileName.c_str()), 1コマの再生時間);
96  }
97 
98  return true;
99  }
100 
102  void Add(Image *追加イメージ, int 再生フレーム数 = 1)
103  {
104  if (Loading::IsLoading())
105  {
106  Loading::AddLoading([=]{ Add(追加イメージ, 再生フレーム数); });
107  return;
108  }
109 
110  ImagePack::Add(追加イメージ);
111  times.push_back(再生フレーム数);
112  nexts.push_back((int)NextFrame::Normal);
113  }
115  void Add(const char *ファイル名, int 再生フレーム数 = 1)
116  {
117  if (Loading::IsLoading())
118  {
119  Loading::AddLoading([=]{ Add(ファイル名, 再生フレーム数); });
120  return;
121  }
122 
123  Add(new Image(ファイル名), 再生フレーム数);
124  }
125 
127  void Release() override
128  {
130  times.clear();
131  nexts.clear();
132  }
133 
135  void SetFrameTime(const std::vector<int> &フレーム時間)
136  {
137  if (Loading::IsLoading())
138  {
139  Loading::AddLoading([=]{ SetFrameTime(フレーム時間); });
140  return;
141  }
142 
143  for (unsigned int a = 0; a < times.size(); ++a)
144  {
145  times[a] = フレーム時間[a];
146  }
147  }
148 
151  void SetType(FilmType 再生方法)
152  {
153  if (Loading::IsLoading())
154  {
155  Loading::AddLoading([=]{SetType(再生方法); });
156  return;
157  }
158 
159  switch (再生方法)
160  {
161  case FilmType::Normal:
162  nexts[nexts.size() - 1] = (int)NextFrame::Normal;
163  break;
164  case FilmType::Reverse:
165  nexts[0] = (int)NextFrame::ToFront;
166  nexts[nexts.size() - 1] = (int)NextFrame::ToBack;
167  break;
168  case FilmType::End:
169  nexts[nexts.size() - 1] = (int)NextFrame::End;
170  break;
171  }
172  }
173 
176  void SetType(int コマ番号, int 次フレーム)
177  {
178  if (Loading::IsLoading())
179  {
180  Loading::AddLoading([=]{nexts[コマ番号] = 次フレーム; });
181  return;
182  }
183 
184  nexts[コマ番号] = 次フレーム;
185  }
186 
189  void SetType(int コマ番号, NextFrame 次フレーム)
190  {
191  if (Loading::IsLoading())
192  {
193  Loading::AddLoading([=]{ nexts[コマ番号] = (int)次フレーム; });
194  return;
195  }
196 
197  nexts[コマ番号] = (int)次フレーム;
198  }
199 
201  int GetAnimeTime() const
202  {
203  int totalTime = 0;
204 
205  for (auto it : times)
206  {
207  totalTime += it;
208  }
209 
210  return totalTime;
211  }
212  };
213 }
最後まで再生すると、再生方向を反転
次のコマに進む
void SetType(int コマ番号, NextFrame 次フレーム)
指定コマの次フレームを設定する.
Definition: Film.h:189
void SetType(FilmType 再生方法)
全体の再生方法を指定する.
Definition: Film.h:151
virtual void Release()
Imageをメモリから開放.
Definition: ImagePack.h:175
int GetAnimeTime() const
全コマの合計フレーム時間を返す.
Definition: Film.h:201
Film(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦, int 1コマの再生時間=1)
画像ファイルを分割してメモリへ読み込む.
Definition: Film.h:42
void SetType(int コマ番号, int 次フレーム)
指定コマの次フレームを設定する.
Definition: Film.h:176
NextFrame
次コマの移動先.
Definition: Film.h:13
bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦, int 1コマの再生時間=1)
画像ファイルを分割してメモリへ読み込む.
Definition: Film.h:59
static bool IsLoading()
非同期読み込み登録中かどうか.
Definition: Loading.h:90
画像データを表すクラス.
Definition: Image.h:17
コマの進む向きをマイナスにしてから進む
void Add(const char *ファイル名, int 再生フレーム数=1)
末尾にImageを追加する.
Definition: Film.h:115
bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
1つの画像を分割して読み込む.
Definition: ImagePack.h:47
Film(const char *ファイル名, const char *拡張子, int 総コマ数, int 1コマの再生時間=1, const char *書式="%03d.")
連番ファイルを一括して読み込む.
Definition: Film.h:53
void Add(Image *追加イメージ, int 再生フレーム数=1)
末尾にImageを追加する.
Definition: Film.h:102
static void AddLoading(std::function< void(void)> &&読み込み関数)
非同期読み込み処理に追加.
Definition: Loading.h:96
bool Load(const char *ファイル名, const char *拡張子, int 総コマ数, int 1コマの再生時間=1, const char *書式="%03d.")
連番ファイルを一括して読み込む.
Definition: Film.h:79
ImagePackにコマ毎の再生時間を追加したクラス.
Definition: Film.h:32
Filmに再生状態を付与したクラス.
Definition: Anime.h:11
コマの進む向きをプラスにしてから進む
複数のImageをまとめるクラス.
Definition: ImagePack.h:17
void Add(Image *追加イメージ)
Imageを末尾に追加.
Definition: ImagePack.h:162
FilmType
アニメの再生方法.
Definition: Film.h:22
このコマでアニメーションを停止する
最終フレームで再生を停止
最後まで再生するとまた最初からループ再生
void SetFrameTime(const std::vector< int > &フレーム時間)
各コマのフレーム数を設定する.
Definition: Film.h:135
void Release() override
Imageを開放し初期化する.
Definition: Film.h:127