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