SDXFrameWork  0.13
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
SubWindow.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/Screen.h>
7 
8 namespace SDX
9 {
14  class SubWindow
15  {
16  friend class System;
17  friend class Mouse;
18  friend class Gesture;
19  friend class Touch;
20  friend class Window;
21  friend class Renderer;
22  private:
23  SDL_Window* handle = nullptr;
24  Renderer renderer;
25  bool isFullScreen = false;
26  int width;
27  int height;
28  int logicWidth = -1;
29  int logicheight = -1;
30  double aspect;
31  static std::list<SubWindow*> windowS;
32 
33  static void CheckWindowID(int 削除するWindowのID)
34  {
35  for (auto it : windowS)
36  {
37  if (SDL_GetWindowID(it->handle) == 削除するWindowのID)
38  {
39  it->Destroy();
40  break;
41  }
42  }
43  }
44  public:
45 
47 
48  SubWindow() = default;
49 
50  ~SubWindow()
51  {
52  Destroy();
53  }
54 
56  SubWindow(const char* ウィンドウ名, int 幅, int 高さ, bool フルスクリーンフラグ = false)
57  {
58  Create(ウィンドウ名, 幅, 高さ, フルスクリーンフラグ);
59  }
60 
63  SDL_Window* GetHandle()
64  {
65  return handle;
66  }
67 
71  {
72  return renderer;
73  }
74 
77  bool Create(const char* ウィンドウ名, int 幅, int 高さ, bool フルスクリーンフラグ = false)
78  {
79  if (handle != nullptr){ return false; }
80 
81  width = 幅;
82  height = 高さ;
83  isFullScreen = フルスクリーンフラグ;
84 
85  int flag = 0;
86  if ( isFullScreen )
87  {
88  flag = SDL_WINDOW_FULLSCREEN;
89  }
90 
91  handle = SDL_CreateWindow(ウィンドウ名, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 幅, 高さ, flag);
92 
93  renderer.Create(handle);
94 
95  windowS.push_back(this);
96 
97  return true;
98  }
99 
102  bool Destroy()
103  {
104  if (handle == nullptr){ return false; }
105 
106  renderer.isWindow = false;//ウィンドウ対応フラグを折らないと削除出来ない
107  renderer.Destroy();
108  SDL_DestroyWindow(handle);
109 
110  if (windowS.size() >= 2)
111  {
112  windowS.remove(this);
113  }
114  handle = nullptr;
115 
116  return true;
117  }
118 
121  bool SetShowFlag(bool 表示フラグ)
122  {
123  if (handle == nullptr){ return false; }
124 
125  if (表示フラグ)
126  {
127  SDL_ShowWindow(handle);
128  }
129  else
130  {
131  SDL_HideWindow(handle);
132  }
133 
134  return true;
135  }
136 
138  bool SetFullscreen(bool フルスクリーンフラグ)
139  {
140  if (handle == nullptr){ return false; }
141 
142  isFullScreen = フルスクリーンフラグ;
143 
144  if ( isFullScreen)
145  {
146  SDL_RenderSetLogicalSize(Screen::GetHandle(), GetWidth(), GetHeight());
147  SDL_SetWindowFullscreen( handle, SDL_WINDOW_FULLSCREEN_DESKTOP);
148  }
149  else
150  {
151  SDL_SetWindowFullscreen( handle, 0);
152  SDL_SetWindowSize( handle, GetWidth(), GetHeight());
153  }
154  return true;
155  }
156 
158  bool SetTitle(const char *タイトル名)
159  {
160 #ifdef TABLET
161  return false;
162 #endif
163  if (handle == nullptr){ return false; }
164 
165  SDL_SetWindowTitle(handle, タイトル名);
166  return true;
167  }
168 
170  bool SetSize(int 幅, int 高さ)
171  {
172  if (handle == nullptr){ return false; }
173 
174  width = 幅;
175  height = 高さ;
176 
177  SDL_RenderSetLogicalSize(renderer.GetHandle(), 幅, 高さ);
178  SDL_SetWindowSize(handle, 幅, 高さ);
179 
180  if (logicWidth != -1)
181  {
182  SDL_RenderSetLogicalSize(renderer.GetHandle(), logicWidth, logicheight);
183  }
184 
185  return true;
186  }
187 
189  int GetWidth()
190  {
191  return width;
192  }
193 
195  int GetHeight()
196  {
197  return height;
198  }
199 
202  {
203  if (handle == nullptr){ return{ 0, 0, 0, 0 }; }
204 
205  int x, y;
206  SDL_GetWindowPosition(handle, &x, &y);
207 
208  return{ x, y, width, height };
209  }
210 
212  bool SetIcon(const char *ファイル名)
213  {
214 #ifdef TABLET
215  return false;
216 #endif
217  if (handle == nullptr){ return false; }
218 
219  SDL_Surface* icon = IMG_Load(ファイル名);
220  if (icon == nullptr){ return false; }
221 
222  SDL_SetWindowIcon(handle, icon);
223  SDL_FreeSurface(icon);
224 
225  return true;
226  }
227 
229  void Update()
230  {
231  SDL_RenderPresent(renderer.GetHandle());
232  renderer.Clear();
233  }
234 
237  void SetLogicalSize(int 幅, int 高さ)
238  {
239  logicWidth = 幅;
240  logicheight = 高さ;
241  SDL_RenderSetLogicalSize(renderer.GetHandle(), 幅, 高さ);
242  }
243  };
244 }
Renderer & GetRenderer()
対応Rendererの取得.
Definition: SubWindow.h:70
bool SetFullscreen(bool フルスクリーンフラグ)
スクリーンモードを設定する.
Definition: SubWindow.h:138
マウスの状態を表すクラス.
Definition: Mouse.h:30
矩形を表す図形クラス.
Definition: Rect.h:22
int GetHeight()
高さの取得.
Definition: SubWindow.h:195
bool SetTitle(const char *タイトル名)
タイトルを設定.
Definition: SubWindow.h:158
int GetWidth()
幅の取得.
Definition: SubWindow.h:189
void Update()
描画処理を反映する.
Definition: SubWindow.h:229
タッチ操作の各種ジェスチャー.
Definition: Gesture.h:12
ライブラリの初期化やシステム的な処理を行う関数群.
Definition: System.h:23
bool Create(const char *ウィンドウ名, int 幅, int 高さ, bool フルスクリーンフラグ=false)
Windowの初期化と生成.
Definition: SubWindow.h:77
bool Destroy()
Rendererを削除.
Definition: Renderer.h:90
SDL_Renderer * GetHandle()
描画ハンドルを取得.
Definition: Renderer.h:69
bool SetIcon(const char *ファイル名)
ウィンドウのアイコンを設定.
Definition: SubWindow.h:212
SubWindow(const char *ウィンドウ名, int 幅, int 高さ, bool フルスクリーンフラグ=false)
Windowの初期化と生成.
Definition: SubWindow.h:56
描画先を表すクラス.
Definition: Renderer.h:27
bool Clear()
画面を消去する.
Definition: Renderer.h:161
SDL_Window * GetHandle()
Windowハンドルの取得.
Definition: SubWindow.h:63
static SDL_Renderer * GetHandle()
スクリーンハンドルを取得.
Definition: Screen.h:26
ウィンドウを表すクラス.
Definition: SubWindow.h:14
bool SetSize(int 幅, int 高さ)
ウィンドウサイズの設定.
Definition: SubWindow.h:170
static SubWindow mainWindow
現在アクティブなウィンドウ
Definition: SubWindow.h:46
bool Destroy()
SubWindowを削除.
Definition: SubWindow.h:102
タッチ操作.
Definition: Touch.h:12
Rect GetSize()
ウィンドウの位置と座標を取得.
Definition: SubWindow.h:201
bool SetShowFlag(bool 表示フラグ)
ウィンドウの表示/非表示設定.
Definition: SubWindow.h:121
アクティブなSubWindowを操作するクラス.
Definition: Window.h:14
void SetLogicalSize(int 幅, int 高さ)
描画領域の大きさを設定する.
Definition: SubWindow.h:237