YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
E/include/YCLib/Win32GUI.h
浏览该文件的文档.
1 /*
2  © 2013 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
29 #ifndef YCL_MinGW32_INC_Win32GUI_h_
30 #define YCL_MinGW32_INC_Win32GUI_h_ 1
31 
32 #include "MinGW32.h"
33 #include <YSLib/Core/ygdibase.h>
34 #include <mutex> // for std::mutex;
35 #include <atomic>
36 
37 namespace platform_ex
38 {
39 
41 using NativeWindowHandle = ::HWND;
42 
43 inline namespace Windows
44 {
45 
52 class YF_API WindowReference
53 {
54 protected:
55  NativeWindowHandle hWindow;
56 
57 public:
59  : hWindow(h)
60  {}
61  DefDeMoveCtor(WindowReference)
62 
63 
64 
65  YSLib::Drawing::Rect
66  GetClientBounds() const;
67  YSLib::Drawing::Point
68  GetClientLocation() const;
69  YSLib::Drawing::Size
70  GetClientSize() const;
72  YSLib::Drawing::Point
73  GetLocation() const;
74  DefGetter(const ynothrow, NativeWindowHandle, NativeHandle, hWindow)
81  YSLib::Drawing::AlphaType
82  GetOpacity() const;
83  YSLib::Drawing::Size
84  GetSize() const;
85 
87  void
88  SetClientBounds(const YSLib::Drawing::Rect&);
94  void
95  SetOpacity(YSLib::Drawing::AlphaType);
100  void
101  SetText(const wchar_t*);
102 
104  void
105  Close();
106 
111  void
112  Invalidate();
113 
118  void
119  Move(const YSLib::Drawing::Point&);
120 
125  void
126  Resize(const YSLib::Drawing::Size&);
127 
132  void
133  ResizeClient(const YSLib::Drawing::Size&);
134 
139  bool
140  Show() ynothrow;
141 };
142 
143 
148 YF_API NativeWindowHandle
149 CreateNativeWindow(const wchar_t*, const YSLib::Drawing::Size&,
150  const wchar_t* = L"", ::DWORD = WS_POPUP, ::DWORD = WS_EX_LTRREADING);
151 
152 
154 
155 
160 class YF_API ScreenBuffer
161 {
162 private:
165 
166 protected:
168  ::HBITMAP hBitmap;
169 
170 public:
171  ScreenBuffer(const YSLib::Drawing::Size&);
173  ScreenBuffer(ScreenBuffer&&) ynothrow;
174  ~ScreenBuffer();
175 
177  ScreenBuffer&
178  operator=(ScreenBuffer&&);
179 
181 
182  DefGetter(const ynothrow, YSLib::Drawing::BitmapPtr, BufferPtr, pBuffer)
183  DefGetter(const ynothrow, ::HBITMAP, NativeHandle, hBitmap)
184  DefGetter(const ynothrow, const YSLib::Drawing::Size&, Size, size)
185 
192  void
193  Premultiply(YSLib::Drawing::BitmapPtr) ynothrow;
194 
200  void
201  Resize(const YSLib::Drawing::Size&);
202 
208  void
209  UpdateFrom(YSLib::Drawing::BitmapPtr) ynothrow;
211 
212  /*
213  \brief 交换。
214  \since build 430
215  */
216  void
217  swap(ScreenBuffer&) ynothrow;
218 };
219 
221 inline DefSwap(ynothrow, ScreenBuffer)
222 
223 
229 class YF_API ScreenRegionBuffer : private ScreenBuffer
230 {
231 private:
232  std::mutex mtx;
233 
234 public:
236  : ScreenBuffer(s), mtx()
237  {}
238 
239  using ScreenBuffer::GetBufferPtr;
240  using ScreenBuffer::GetNativeHandle;
241  using ScreenBuffer::GetSize;
242  DefGetter(ynothrow, ScreenBuffer&, ScreenBufferRef, *this)
243 
244 
245  using ScreenBuffer::Premultiply;
247  using ScreenBuffer::Resize;
248 
249  void
250  UpdateFrom(YSLib::Drawing::BitmapPtr) ynothrow;
251 
253  void
254  UpdatePremultipliedTo(NativeWindowHandle, YSLib::Drawing::AlphaType = 0xFF,
255  const YSLib::Drawing::Point& = {}) ynothrow;
256 
257  void
258  UpdateTo(NativeWindowHandle, const YSLib::Drawing::Point& = {}) ynothrow;
259 };
261 
262 
264 
265 
269 class YF_API WindowMemorySurface
270 {
271 private:
272  ::HDC h_owner_dc, h_mem_dc;
273 
274 public:
276  : h_owner_dc(h_dc), h_mem_dc(::CreateCompatibleDC(h_dc))
277  {}
279  {
280  ::DeleteDC(h_mem_dc);
281  }
282 
283  DefGetter(const ynothrow, ::HDC, OwnerHandle, h_owner_dc)
284  DefGetter(const ynothrow, ::HDC, NativeHandle, h_mem_dc)
285 
287  void
288  Update(ScreenBuffer&, const YSLib::Drawing::Point& = {}) ynothrow;
290  void
292  ynothrow
293  {
294  Update(rbuf.GetScreenBufferRef(), pt);
295  }
296 
298  void
299  UpdatePremultiplied(ScreenBuffer&, NativeWindowHandle,
301  ynothrow;
303  void
304  UpdatePremultiplied(ScreenRegionBuffer& rbuf, NativeWindowHandle h_wnd,
305  YSLib::Drawing::AlphaType a = 0xFF,
306  const YSLib::Drawing::Point& pt = {}) ynothrow
307  {
308  UpdatePremultiplied(rbuf.GetScreenBufferRef(), h_wnd, a, pt);
309  }
310 };
311 
312 
313 class YF_API WindowDeviceContextBase
314 {
315 protected:
316  NativeWindowHandle hWindow;
317  ::HDC hDC;
318 
319  WindowDeviceContextBase(NativeWindowHandle h_wnd, ::HDC h_dc)
320  : hWindow(h_wnd), hDC(h_dc)
321  {}
323 
324 public:
325  DefGetter(const ynothrow, ::HDC, DeviceContextHandle, hDC)
326  DefGetter(const ynothrow, NativeWindowHandle, WindowHandle, hWindow)
327 };
328 
329 
335 {
336 protected:
337  WindowDeviceContext(NativeWindowHandle h_wnd)
338  : WindowDeviceContextBase(h_wnd, ::GetDC(h_wnd))
339  {}
341  {
342  ::ReleaseDC(hWindow, hDC);
343  }
344 };
345 
346 
351 class YF_API WindowRegionDeviceContext : public WindowDeviceContextBase
352 {
353 private:
354  ::PAINTSTRUCT ps;
355 
356 protected:
357  WindowRegionDeviceContext(NativeWindowHandle h_wnd)
358  : WindowDeviceContextBase(h_wnd, ::BeginPaint(h_wnd, &ps))
359  {}
361  {
362  ::EndPaint(hWindow, &ps);
363  }
364 };
366 
367 
373 template<typename _type = WindowDeviceContext>
374 class GSurface : public _type, public WindowMemorySurface
375 {
376 public:
378  GSurface(NativeWindowHandle h_wnd)
379  : _type(h_wnd), WindowMemorySurface(_type::GetDeviceContextHandle())
380  {}
381 };
382 
383 
388 class YF_API WindowClass
389 {
390 private:
391  ::HINSTANCE h_instance;
392 
393 public:
394  WindowClass(const wchar_t*, ::WNDPROC, ::UINT = 0,
395  ::HBRUSH = ::HBRUSH(COLOR_MENU + 1));
396  ~WindowClass();
397 };
398 
399 
401 yconstexpr wchar_t WindowClassName[]{L"YFramework Window"};
402 
403 
408 class YF_API HostWindow : private WindowReference, private YSLib::noncopyable
409 {
410 public:
416  std::atomic<bool> BoundsLimited{false};
417 
419  HostWindow(NativeWindowHandle);
420  DefDelMoveCtor(HostWindow)
421  virtual
422  ~HostWindow();
423 
425 
426  using WindowReference::GetClientBounds;
427  using WindowReference::GetClientLocation;
428  using WindowReference::GetClientSize;
430 
432  using WindowReference::GetLocation;
433  using WindowReference::GetNativeHandle;
435  using WindowReference::GetOpacity;
436  using WindowReference::GetSize;
437 
439  using WindowReference::SetClientBounds;
441  using WindowReference::SetOpacity;
443  using WindowReference::SetText;
444 
445  using WindowReference::Close;
446 
448  using WindowReference::Invalidate;
449 
450  using WindowReference::Move;
452 
453  virtual void
454  OnDestroy();
455 
456  virtual void
457  OnLostFocus();
458 
459  virtual void
460  OnPaint();
461 
463 
464  using WindowReference::Resize;
465 
466  using WindowReference::ResizeClient;
467 
468  using WindowReference::Show;
470 };
471 
472 } // namespace Windows;
473 
474 } // namespace platform_ex;
475 
476 #endif
477 
yconstexpr wchar_t WindowClassName[]
#define DefDeDtor(_t)
定义默认析构函数。
Definition: YBaseMacro.h:146
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
#define YF_API
Definition: Platform.h:64
DefGetter(const ynothrow,::HKEY, Key, h_key)}
void UpdateFrom(YSLib::Drawing::BitmapPtr) ynothrow
YF_API void Show(IWidget &)
显示部件。
Definition: ywidget.cpp:206
hBitmap(sbuf.hBitmap)
Definition: Win32GUI.cpp:248
void Update(ScreenRegionBuffer &rbuf, const YSLib::Drawing::Point &pt={}) ynothrow
YF_API NativeWindowHandle CreateNativeWindow(const wchar_t *, const YSLib::Drawing::Size &, const wchar_t *=L"",::DWORD=WS_POPUP,::DWORD=WS_EX_LTRREADING)
按指定窗口类名、客户区大小、标题文本、样式和附加样式创建本机顶层窗口。
Definition: Win32GUI.cpp:222
void UpdatePremultiplied(ScreenRegionBuffer &rbuf, NativeWindowHandle h_wnd, YSLib::Drawing::AlphaType a=0xFF, const YSLib::Drawing::Point &pt={}) ynothrow
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
不可复制对象:禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: utility.hpp:75
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
Definition: ygdibase.h:235
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:141
WindowDeviceContextBase(NativeWindowHandle h_wnd,::HDC h_dc)
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
void UpdateTo(NativeWindowHandle, const YSLib::Drawing::Point &={}) ynothrow
ScreenRegionBuffer(const YSLib::Drawing::Size &s)
虚拟屏幕区域缓存。
void UpdatePremultipliedTo(NativeWindowHandle, YSLib::Drawing::AlphaType=0xFF, const YSLib::Drawing::Point &={}) ynothrow
Definition: Win32GUI.cpp:313
窗口内存表面:储存窗口上的二维图形绘制状态。
::ANativeWindow * NativeWindowHandle
Definition: Android.h:50
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
PixelType * BitmapPtr
Definition: Video.h:295
屏幕区域大小。
Definition: ygdibase.h:249
平台无关的基础图形学对象。
ystdex::octet AlphaType
Definition: Video.h:186
void Close(IWidget &wgt)
Definition: ywidget.cpp:95
#define DefDelMoveCtor(_t)
Definition: YBaseMacro.h:143