YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
include/YCLib/Win32GUI.h
浏览该文件的文档.
1 /*
2  © 2013-2014 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 "YCLib/YModules.h"
33 #include YFM_MinGW32_YCLib_MinGW32
34 #include YFM_YSLib_Core_YGDIBase
35 #include YFM_YSLib_Core_YEvent
36 #include <mutex> // for std::mutex;
37 #include <atomic>
38 
39 namespace platform_ex
40 {
41 
43 using NativeWindowHandle = ::HWND;
44 
45 inline namespace Windows
46 {
47 
55 {
56 protected:
58 
59 public:
61  : hWindow(h)
62  {}
67  : hWindow(r.hWindow)
68  {
69  r.hWindow = {};
70  }
71 
73 
75  GetClientBounds() const;
77  GetClientLocation() const;
79  GetClientSize() const;
82  GetLocation() const;
83  DefGetter(const ynothrow, NativeWindowHandle, NativeHandle, hWindow)
90  YSLib::Drawing::AlphaType
91  GetOpacity() const;
92  YSLib::Drawing::Size
93  GetSize() const;
94 
96  void
97  SetClientBounds(const YSLib::Drawing::Rect&);
103  void
104  SetOpacity(YSLib::Drawing::AlphaType);
109  void
110  SetText(const wchar_t*);
111 
113  void
114  Close();
115 
120  void
121  Invalidate();
122 
127  void
128  Move(const YSLib::Drawing::Point&);
129 
134  void
135  Resize(const YSLib::Drawing::Size&);
136 
141  void
142  ResizeClient(const YSLib::Drawing::Size&);
143 
148  bool
149  Show() ynothrow;
150 };
151 
152 
158 CreateNativeWindow(const wchar_t*, const YSLib::Drawing::Size&,
159  const wchar_t* = L"", ::DWORD = WS_POPUP, ::DWORD = WS_EX_LTRREADING);
160 
161 
163 
164 
170 {
171 private:
174 
175 protected:
177  ::HBITMAP hBitmap;
178 
179 public:
180  ScreenBuffer(const YSLib::Drawing::Size&);
182  ScreenBuffer(ScreenBuffer&&) ynothrow;
183  ~ScreenBuffer();
184 
186  ScreenBuffer&
187  operator=(ScreenBuffer&&);
188 
190 
191  DefGetter(const ynothrow, YSLib::Drawing::BitmapPtr, BufferPtr, pBuffer)
192  DefGetter(const ynothrow, ::HBITMAP, NativeHandle, hBitmap)
193  DefGetter(const ynothrow, const YSLib::Drawing::Size&, Size, size)
194 
201  void
202  Premultiply(YSLib::Drawing::BitmapPtr) ynothrow;
203 
209  void
210  Resize(const YSLib::Drawing::Size&);
211 
218  void
219  UpdateFrom(YSLib::Drawing::BitmapPtr) ynothrow;
221 
222  /*
223  \brief 交换。
224  \since build 430
225  */
226  void
227  swap(ScreenBuffer&) ynothrow;
228 };
229 
234 inline DefSwap(ynothrow, ScreenBuffer)
235 
236 
242 class YF_API ScreenRegionBuffer : private ScreenBuffer
243 {
244 private:
245  std::mutex mtx;
246 
247 public:
249  : ScreenBuffer(s), mtx()
250  {}
251 
252  using ScreenBuffer::GetBufferPtr;
253  using ScreenBuffer::GetNativeHandle;
254  using ScreenBuffer::GetSize;
255  DefGetter(ynothrow, ScreenBuffer&, ScreenBufferRef, *this)
256 
257 
258  using ScreenBuffer::Premultiply;
260  using ScreenBuffer::Resize;
261 
263  void
264  UpdateFrom(YSLib::Drawing::BitmapPtr) ynothrow;
265 
267  void
268  UpdatePremultipliedTo(NativeWindowHandle, YSLib::Drawing::AlphaType = 0xFF,
269  const YSLib::Drawing::Point& = {}) ynothrow;
270 
271  void
272  UpdateTo(NativeWindowHandle, const YSLib::Drawing::Point& = {}) ynothrow;
273 };
275 
276 
278 
279 
284 {
285 private:
286  ::HDC h_owner_dc, h_mem_dc;
287 
288 public:
290  : h_owner_dc(h_dc), h_mem_dc(::CreateCompatibleDC(h_dc))
291  {}
293  {
294  ::DeleteDC(h_mem_dc);
295  }
296 
297  DefGetter(const ynothrow, ::HDC, OwnerHandle, h_owner_dc)
298  DefGetter(const ynothrow, ::HDC, NativeHandle, h_mem_dc)
299 
301  void
302  Update(ScreenBuffer&, const YSLib::Drawing::Point& = {}) ynothrow;
304  PDefH(void, Update, ScreenRegionBuffer& rbuf,
305  const YSLib::Drawing::Point& pt = {}) ynothrow
306  ImplExpr(Update(rbuf.GetScreenBufferRef(), pt))
307 
308 
309  void
310  UpdatePremultiplied(ScreenBuffer&, NativeWindowHandle,
311  YSLib::Drawing::AlphaType = 0xFF, const YSLib::Drawing::Point& = {})
312  ynothrow;
314  void
316  YSLib::Drawing::AlphaType a = 0xFF,
317  const YSLib::Drawing::Point& pt = {}) ynothrow
318  {
319  UpdatePremultiplied(rbuf.GetScreenBufferRef(), h_wnd, a, pt);
320  }
321 };
322 
323 
325 {
326 protected:
328  ::HDC hDC;
329 
331  : hWindow(h_wnd), hDC(h_dc)
332  {}
334 
335 public:
336  DefGetter(const ynothrow, ::HDC, DeviceContextHandle, hDC)
337  DefGetter(const ynothrow, NativeWindowHandle, WindowHandle, hWindow)
338 };
339 
340 
346 {
347 protected:
348  WindowDeviceContext(NativeWindowHandle h_wnd)
349  : WindowDeviceContextBase(h_wnd, ::GetDC(h_wnd))
350  {}
352  {
353  ::ReleaseDC(hWindow, hDC);
354  }
355 };
356 
357 
363 {
364 private:
365  ::PAINTSTRUCT ps;
366 
367 protected:
369  : WindowDeviceContextBase(h_wnd, ::BeginPaint(h_wnd, &ps))
370  {}
372  {
373  ::EndPaint(hWindow, &ps);
374  }
375 };
377 
378 
384 template<typename _type = WindowDeviceContext>
385 class GSurface : public _type, public WindowMemorySurface
386 {
387 public:
390  : _type(h_wnd), WindowMemorySurface(_type::GetDeviceContextHandle())
391  {}
392 };
393 
394 
400 {
401 private:
402  ::HINSTANCE h_instance;
403 
404 public:
405  WindowClass(const wchar_t*, ::WNDPROC, ::UINT = 0,
406  ::HBRUSH = ::HBRUSH(COLOR_MENU + 1));
407  ~WindowClass();
408 };
409 
410 
412 yconstexpr wchar_t WindowClassName[]{L"YFramework Window"};
413 
414 
420 {
421 public:
426  std::atomic<bool> BoundsLimited{false};
427 
432  std::map<::UINT, YSLib::GEvent<void(::WPARAM, ::LPARAM)>> MessageMap;
433 
437  virtual
438  ~HostWindow();
439 
441 
442  using WindowReference::GetClientBounds;
443  using WindowReference::GetClientLocation;
444  using WindowReference::GetClientSize;
446 
448  using WindowReference::GetLocation;
449  using WindowReference::GetNativeHandle;
451  using WindowReference::GetOpacity;
452  using WindowReference::GetSize;
453 
455  using WindowReference::SetClientBounds;
457  using WindowReference::SetOpacity;
459  using WindowReference::SetText;
460 
461  using WindowReference::Close;
462 
464  using WindowReference::Invalidate;
465 
466  using WindowReference::Move;
468 
470 
471  using WindowReference::Resize;
472 
473  using WindowReference::ResizeClient;
474 
475  using WindowReference::Show;
477 };
478 
479 } // namespace Windows;
480 
481 } // namespace platform_ex;
482 
483 #endif
484 
yconstexpr wchar_t WindowClassName[]
#define DefDeDtor(_t)
定义默认析构函数。
Definition: YBaseMacro.h:146
显式区域表面:储存显式区域上的二维图形绘制状态。
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
std::map<::UINT, YSLib::GEvent< void(::WPARAM,::LPARAM)> > MessageMap
窗口消息转发事件映射。
#define YF_API
Definition: Platform.h:64
DefGetter(const ynothrow,::HKEY, Key, h_key)}
void UpdateFrom(YSLib::Drawing::BitmapPtr) ynothrow
DefDeCopyCtor(WindowReference) WindowReference(WindowReference &&r) ynothrow
YF_API void Show(IWidget &)
显示部件。
Definition: ywidget.cpp:206
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
GSurface(NativeWindowHandle h_wnd)
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
Definition: ygdibase.h:235
WindowDeviceContextBase(NativeWindowHandle h_wnd,::HDC h_dc)
#define ImplExpr(...)
Definition: YBaseMacro.h:93
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
void UpdateTo(NativeWindowHandle, const YSLib::Drawing::Point &={}) ynothrow
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
ScreenRegionBuffer(const YSLib::Drawing::Size &s)
虚拟屏幕区域缓存。
屏幕二元组。
Definition: ygdibase.h:54
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
bounds & r
Definition: ydraw.h:220
屏幕区域大小。
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