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