Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AppImplMsw.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, The Cinder Project, All rights reserved.
3 
4  This code is intended for use with the Cinder C++ library: http://libcinder.org
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7  the following conditions are met:
8 
9  * Redistributions of source code must retain the above copyright notice, this list of conditions and
10  the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12  the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21  POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 #pragma once
25 
26 #include "cinder/Stream.h"
27 #include "cinder/Vector.h"
28 #include "cinder/app/MouseEvent.h"
29 #include "cinder/app/KeyEvent.h"
30 #include "cinder/app/TouchEvent.h"
31 #include "cinder/app/Renderer.h"
32 #include "cinder/Display.h"
33 #include "cinder/app/Window.h"
34 #include <string>
35 #include <vector>
36 #include <list>
37 #include <windows.h>
38 #undef min
39 #undef max
40 
41 // we declare all of the MultiTouch stuff in Win7 here to prevent requiring users to use the Win7 headers
42 #if ! defined( WM_TOUCH )
43 DECLARE_HANDLE(HTOUCHINPUT);
44 typedef struct tagTOUCHINPUT {
45  LONG x;
46  LONG y;
47  HANDLE hSource;
48  DWORD dwID;
49  DWORD dwFlags;
50  DWORD dwMask;
51  DWORD dwTime;
52  ULONG_PTR dwExtraInfo;
53  DWORD cxContact;
54  DWORD cyContact;
56 typedef TOUCHINPUT const * PCTOUCHINPUT;
57 #define TOUCH_COORD_TO_PIXEL(l) ((l) / 100)
58 #define WM_TOUCH 0x0240
59 #endif
60 
61 namespace cinder { namespace app {
62 
63 class AppImplMsw {
64  public:
65  AppImplMsw( class App *aApp );
66  virtual ~AppImplMsw();
67 
68  class App* getApp() { return mApp; }
69 
70  float getFrameRate() const { return mFrameRate; }
71  virtual float setFrameRate( float aFrameRate ) { return -1.0f; }
72  virtual void quit() = 0;
73 
74  virtual WindowRef getWindow() const { return mActiveWindow; }
76 
77  static void hideCursor();
78  static void showCursor();
79 
80  static Buffer loadResource( int id, const std::string &type );
81 
82  static fs::path getAppPath();
83  static fs::path getOpenFilePath( const fs::path &initialPath, std::vector<std::string> extensions );
84  static fs::path getSaveFilePath( const fs::path &initialPath, std::vector<std::string> extensions );
85  static fs::path getFolderPath( const fs::path &initialPath );
86 
87  protected:
88  bool setupHasBeenCalled() const { return mSetupHasBeenCalled; }
89  virtual void closeWindow( class WindowImplMsw *windowImpl ) = 0;
90  virtual void setForegroundWindow( WindowRef window ) = 0;
91 
92  class App *mApp;
93  float mFrameRate;
96  bool mActive;
97  ULONG_PTR mGdiplusToken;
98 
99  friend class WindowImplMsw;
100  friend LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
101 };
102 
104  public:
105  WindowImplMsw( const Window::Format &format, RendererRef sharedRenderer, AppImplMsw *appImpl );
106  WindowImplMsw( HWND hwnd, RendererRef renderer, RendererRef sharedRenderer, AppImplMsw *appImpl );
107  virtual ~WindowImplMsw() {}
108 
109  virtual bool isFullScreen() { return mFullScreen; }
110  virtual void setFullScreen( bool fullScreen, const app::FullScreenOptions &options );
111  virtual Vec2i getSize() const { return Vec2i( mWindowWidth, mWindowHeight ); }
112  virtual void setSize( const Vec2i &size );
113  virtual Vec2i getPos() const { return mWindowOffset; }
114  virtual void setPos( const Vec2i &pos );
115  virtual void close();
116  virtual std::string getTitle() const;
117  virtual void setTitle( const std::string &title );
118  virtual void hide();
119  virtual void show();
120  virtual bool isHidden() const;
121  virtual DisplayRef getDisplay() const { return mDisplay; }
122  virtual RendererRef getRenderer() const { return mRenderer; }
123  virtual const std::vector<TouchEvent::Touch>& getActiveTouches() const { return mActiveTouches; }
124  virtual void* getNative() { return mWnd; }
125 
126  void enableMultiTouch();
127  bool isBorderless() const { return mBorderless; }
128  void setBorderless( bool borderless );
129  bool isAlwaysOnTop() const { return mAlwaysOnTop; }
130  void setAlwaysOnTop( bool alwaysOnTop );
131 
134  virtual void keyDown( const KeyEvent &event );
135  virtual void draw();
136  virtual void redraw();
137  virtual void resize();
138 
139  void privateClose();
140  protected:
141  void createWindow( const Vec2i &windowSize, const std::string &title, DisplayRef display, RendererRef sharedRenderer );
142  void completeCreation();
143  static void registerWindowClass();
144  void getScreenSize( int clientWidth, int clientHeight, int *resultWidth, int *resultHeight );
145  void onTouch( HWND hWnd, WPARAM wParam, LPARAM lParam );
146  virtual void toggleFullScreen( const app::FullScreenOptions &options );
147 
150  HWND mWnd;
151  HDC mDC;
154  bool mHidden;
160  std::map<DWORD,Vec2f> mMultiTouchPrev;
161  std::vector<TouchEvent::Touch> mActiveTouches;
163 
164  friend AppImplMsw;
165  friend LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
166 };
167 
168 typedef std::shared_ptr<class BlankingWindow> BlankingWindowRef;
169 
171  public:
172  static BlankingWindowRef create( DisplayRef display ) { return BlankingWindowRef( new BlankingWindow( display ) ); }
173  BlankingWindow( DisplayRef display );
174 
175  void destroy();
176 
177  protected:
178  static void registerWindowClass();
179 
180  HWND mWnd;
181 };
182 
183 } } // namespace cinder::app
DWORD mWindowStyle
Definition: AppImplMsw.h:152
virtual RendererRef getRenderer() const
Definition: AppImplMsw.h:122
TOUCHINPUT const * PCTOUCHINPUT
Definition: AppImplMsw.h:56
virtual void setPos(const Vec2i &pos)
Definition: AppImplMsw.cpp:534
virtual bool isFullScreen()
Definition: AppImplMsw.h:109
DWORD cyContact
Definition: AppImplMsw.h:54
virtual void setForegroundWindow(WindowRef window)=0
bool mBorderless
Definition: AppImplMsw.h:156
AppImplMsw * mAppImpl
Definition: AppImplMsw.h:148
HWND mWnd
Definition: AppImplMsw.h:150
static fs::path getSaveFilePath(const fs::path &initialPath, std::vector< std::string > extensions)
Definition: AppImplMsw.cpp:254
static void hideCursor()
Definition: AppImplMsw.cpp:70
virtual void hide()
Definition: AppImplMsw.cpp:549
GLsizei const GLchar ** string
Definition: GLee.h:2427
WindowRef getWindow()
Definition: AppImplMsw.h:133
virtual ~WindowImplMsw()
Definition: AppImplMsw.h:107
void destroy()
Definition: AppImplMsw.cpp:1124
float mFrameRate
Definition: AppImplMsw.h:93
virtual std::string getTitle() const
Definition: AppImplMsw.cpp:566
Options passed when entering fullscreen.
Definition: Window.h:110
virtual void draw()
Definition: AppImplMsw.cpp:991
static Buffer loadResource(int id, const std::string &type)
Definition: AppImplMsw.cpp:90
void setBorderless(bool borderless)
Definition: AppImplMsw.cpp:740
WindowRef mActiveWindow
Definition: AppImplMsw.h:94
bool isAlwaysOnTop() const
Definition: AppImplMsw.h:129
static fs::path getOpenFilePath(const fs::path &initialPath, std::vector< std::string > extensions)
Definition: AppImplMsw.cpp:139
bool mSetupHasBeenCalled
Definition: AppImplMsw.h:95
virtual void keyDown(const KeyEvent &event)
Definition: AppImplMsw.cpp:1023
virtual float setFrameRate(float aFrameRate)
Definition: AppImplMsw.h:71
bool mAlwaysOnTop
Definition: AppImplMsw.h:156
AppImplMsw * getAppImpl()
Definition: AppImplMsw.h:132
virtual void quit()=0
DECLARE_HANDLE(HTOUCHINPUT)
virtual void * getNative()
Definition: AppImplMsw.h:124
LONG x
Definition: AppImplMsw.h:45
virtual bool isHidden() const
Definition: AppImplMsw.cpp:561
virtual Vec2i getPos() const
Definition: AppImplMsw.h:113
void setWindow(WindowRef window)
Definition: AppImplMsw.h:75
ULONG_PTR mGdiplusToken
Definition: AppImplMsw.h:97
bool setupHasBeenCalled() const
Definition: AppImplMsw.h:88
std::shared_ptr< Window > WindowRef
Definition: Event.h:49
virtual ~AppImplMsw()
Definition: AppImplMsw.cpp:63
Definition: AppImplMsw.h:44
Definition: Buffer.h:31
void onTouch(HWND hWnd, WPARAM wParam, LPARAM lParam)
Definition: AppImplMsw.cpp:609
class App * mApp
Definition: AppImplMsw.h:92
DWORD cxContact
Definition: AppImplMsw.h:53
bool mIsDragging
Definition: AppImplMsw.h:162
Definition: AppImplMsw.h:103
Definition: App.h:127
void enableMultiTouch()
Definition: AppImplMsw.cpp:599
static void registerWindowClass()
Definition: AppImplMsw.cpp:454
LONG y
Definition: AppImplMsw.h:46
static void showCursor()
Definition: AppImplMsw.cpp:80
virtual void show()
Definition: AppImplMsw.cpp:555
float getFrameRate() const
Definition: AppImplMsw.h:70
int mWindowHeight
Definition: AppImplMsw.h:155
HDC mDC
Definition: AppImplMsw.h:151
DisplayRef mDisplay
Definition: AppImplMsw.h:158
ULONG_PTR dwExtraInfo
Definition: AppImplMsw.h:52
virtual void closeWindow(class WindowImplMsw *windowImpl)=0
bool mFullScreen
Definition: AppImplMsw.h:156
DWORD dwID
Definition: AppImplMsw.h:48
virtual Vec2i getSize() const
Definition: AppImplMsw.h:111
int mWindowWidth
Definition: AppImplMsw.h:155
void completeCreation()
Definition: AppImplMsw.cpp:443
std::map< DWORD, Vec2f > mMultiTouchPrev
Definition: AppImplMsw.h:160
std::shared_ptr< class Renderer > RendererRef
Definition: Renderer.h:85
void setAlwaysOnTop(bool alwaysOnTop)
Definition: AppImplMsw.cpp:773
DWORD dwTime
Definition: AppImplMsw.h:51
BlankingWindow(DisplayRef display)
Definition: AppImplMsw.cpp:1032
void getScreenSize(int clientWidth, int clientHeight, int *resultWidth, int *resultHeight)
Definition: AppImplMsw.cpp:523
friend LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
Definition: AppImplMsw.cpp:789
bool mResizable
Definition: AppImplMsw.h:156
struct tagTOUCHINPUT * PTOUCHINPUT
virtual void setSize(const Vec2i &size)
Definition: AppImplMsw.cpp:586
AppImplMsw(class App *aApp)
Definition: AppImplMsw.cpp:56
DWORD mWindowExStyle
Definition: AppImplMsw.h:152
Vec2i mWindowOffset
Definition: AppImplMsw.h:153
virtual void resize()
Definition: AppImplMsw.cpp:999
static fs::path getAppPath()
Definition: AppImplMsw.cpp:117
std::shared_ptr< class Display > DisplayRef
Definition: Display.h:53
void privateClose()
Definition: AppImplMsw.cpp:1010
Window window
Definition: GLee.h:17134
struct tagTOUCHINPUT TOUCHINPUT
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:963
friend LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
Definition: AppImplMsw.cpp:789
bool mActive
Definition: AppImplMsw.h:96
virtual const std::vector< TouchEvent::Touch > & getActiveTouches() const
Definition: AppImplMsw.h:123
Vec2i mWindowedSize
Definition: AppImplMsw.h:157
Definition: Window.h:140
virtual void redraw()
Definition: AppImplMsw.cpp:1005
Vec2i mWindowedPos
Definition: AppImplMsw.h:157
Definition: AppImplMsw.h:170
WindowImplMsw(const Window::Format &format, RendererRef sharedRenderer, AppImplMsw *appImpl)
Definition: AppImplMsw.cpp:326
bool mHidden
Definition: AppImplMsw.h:154
HANDLE hSource
Definition: AppImplMsw.h:47
virtual void toggleFullScreen(const app::FullScreenOptions &options)
Definition: AppImplMsw.cpp:490
GLenum GLsizei GLenum format
Definition: GLee.h:969
DWORD dwMask
Definition: AppImplMsw.h:50
std::shared_ptr< class BlankingWindow > BlankingWindowRef
Definition: AppImplMsw.h:168
static void registerWindowClass()
Definition: AppImplMsw.cpp:1075
void createWindow(const Vec2i &windowSize, const std::string &title, DisplayRef display, RendererRef sharedRenderer)
Definition: AppImplMsw.cpp:371
static BlankingWindowRef create(DisplayRef display)
Definition: AppImplMsw.h:172
virtual void close()
Definition: AppImplMsw.cpp:593
std::vector< TouchEvent::Touch > mActiveTouches
Definition: AppImplMsw.h:161
HWND mWnd
Definition: AppImplMsw.h:180
DWORD dwFlags
Definition: AppImplMsw.h:49
friend AppImplMsw
Definition: AppImplMsw.h:164
Definition: AppImplMsw.h:63
bool isBorderless() const
Definition: AppImplMsw.h:127
virtual WindowRef getWindow() const
Definition: AppImplMsw.h:74
virtual void setFullScreen(bool fullScreen, const app::FullScreenOptions &options)
Definition: AppImplMsw.cpp:484
Represents a keyboard event.
Definition: KeyEvent.h:32
GLsizeiptr size
Definition: GLee.h:2089
RendererRef mRenderer
Definition: AppImplMsw.h:159
WindowRef mWindowRef
Definition: AppImplMsw.h:149
class App * getApp()
Definition: AppImplMsw.h:68
virtual void setTitle(const std::string &title)
Definition: AppImplMsw.cpp:577
static fs::path getFolderPath(const fs::path &initialPath)
Definition: AppImplMsw.cpp:227
Vec2< int > Vec2i
Definition: Vector.h:1313
virtual DisplayRef getDisplay() const
Definition: AppImplMsw.h:121