Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AppImplWinRT.h
Go to the documentation of this file.
1 // The copyright in this software is being made available under the BSD License, included below.
2 // This software may be subject to other third party and contributor rights, including patent rights,
3 // and no such rights are granted under this license.
4 //
5 // Copyright (c) 2013, Microsoft Open Technologies, Inc.
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without modification,
9 // are permitted provided that the following conditions are met:
10 //
11 // - Redistributions of source code must retain the above copyright notice,
12 // this list of conditions and the following disclaimer.
13 // - Redistributions in binary form must reproduce the above copyright notice,
14 // this list of conditions and the following disclaimer in the documentation
15 // and/or other materials provided with the distribution.
16 // - Neither the name of Microsoft Open Technologies, Inc. nor the names of its contributors
17 // may be used to endorse or promote products derived from this software
18 // without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 
30 #pragma once
31 
32 #include "cinder/Stream.h"
33 #include "cinder/Vector.h"
34 #include "cinder/app/MouseEvent.h"
35 #include "cinder/app/KeyEvent.h"
36 #include "cinder/app/TouchEvent.h"
37 #include "cinder/app/Renderer.h"
38 #include "cinder/Display.h"
39 #include "cinder/app/Window.h"
40 #include <string>
41 #include <vector>
42 #include <list>
43 #undef min
44 #undef max
45 
46 
47 namespace cinder { namespace app {
48 
49 class AppImplWinRT {
50  public:
51  AppImplWinRT( class App *aApp );
52  virtual ~AppImplWinRT();
53 
54  class App* getApp() { return mApp; }
55 
56  float getFrameRate() const { return mFrameRate; }
57  virtual float setFrameRate( float aFrameRate ) { return -1.0f; }
58  virtual void quit() = 0;
59 
60  virtual WindowRef getWindow() const { return mActiveWindow; }
62 
63  static void hideCursor();
64  static void showCursor();
65 
66  static Buffer loadResource( int id, const std::string &type );
67 
68  static fs::path getAppPath();
69  static void getOpenFilePath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>(), std::function<void (fs::path)> f = nullptr );
70 
71  static void getSaveFilePath( const fs::path &initialPath, std::vector<std::string> extensions, std::function<void (fs::path)> f = nullptr );
72  static void getFolderPath( const fs::path &initialPath, std::vector<std::string> extensions, std::function<void (fs::path)> f = nullptr );
73 
74  virtual void handleKeyDown(Windows::UI::Core::KeyEventArgs^ args);
75  virtual void handleKeyUp(Windows::UI::Core::KeyEventArgs^ args);
76 
77  protected:
78  bool setupHasBeenCalled() const { return mSetupHasBeenCalled; }
79  virtual void closeWindow( class WindowImplWinRT *windowImpl ) = 0;
80  virtual void setForegroundWindow( WindowRef window ) = 0;
82 
83  class App *mApp;
84  float mFrameRate;
87  bool mAltKey;
88  bool mShiftKey;
90 
91  friend class WindowImplWinRT;
92 
93 };
94 
96  public:
98  WindowImplWinRT( DX_WINDOW_TYPE DX_WINDOW_TYPE, RendererRef renderer, AppImplWinRT *appImpl );
99 
100  virtual bool isFullScreen() { return mFullScreen; }
101  virtual void setFullScreen( bool fullScreen, const FullScreenOptions &options );
102  virtual Vec2i getSize() const { return Vec2i( mWindowWidth, mWindowHeight ); }
103  virtual void setSize( const Vec2i &size );
104  virtual Vec2i getPos() const { return mWindowOffset; }
105  virtual void setPos( const Vec2i &pos );
106  virtual void close();
107  virtual std::string getTitle() const;
108  virtual void setTitle( const std::string &title );
109  virtual void hide();
110  virtual void show();
111  virtual bool isHidden() const;
112  virtual DisplayRef getDisplay() const { return mDisplay; }
113  virtual RendererRef getRenderer() const { return mRenderer; }
114  virtual const std::vector<TouchEvent::Touch>& getActiveTouches() const { return mActiveTouches; }
115  virtual void* getNative() {throw (std::string(__FUNCTION__) + "Use getNativeCoreWindow()").c_str();};
116 
117 
118  DX_WINDOW_TYPE getNativeCoreWindow() { return mWnd; }
119 
120  void enableMultiTouch();
121  bool isBorderless() const { return mBorderless; }
122  void setBorderless( bool borderless );
123  bool isAlwaysOnTop() const { return mAlwaysOnTop; }
124  void setAlwaysOnTop( bool alwaysOnTop );
125 
128  virtual void keyDown( const KeyEvent &event );
129  virtual void draw();
130  virtual void redraw();
131  virtual void resize();
132 
133  void privateClose();
134  protected:
135  void createWindow( const Vec2i &windowSize, const std::string &title );
136  void completeCreation();
137  static void registerWindowClass();
138  void getScreenSize( int clientWidth, int clientHeight, int *resultWidth, int *resultHeight );
139  //void onTouch( DX_WINDOW_TYPE DX_WINDOW_TYPE, WPARAM wParam, LPARAM lParam );
140  void toggleFullScreen();
141 
142  void handlePointerDown(Windows::UI::Core::PointerEventArgs^ args);
143  void handlePointerMoved(Windows::UI::Core::PointerEventArgs^ args);
144  void handlePointerUp(Windows::UI::Core::PointerEventArgs^ args);
145  void handleTouchDown(Windows::UI::Core::PointerEventArgs^ args);
146  void handleMouseDown(Windows::UI::Core::PointerEventArgs^ args);
147  void handleTouchMoved(Windows::UI::Core::PointerEventArgs^ args);
148  void handleMouseMoved(Windows::UI::Core::PointerEventArgs^ args);
149  void handleTouchUp(Windows::UI::Core::PointerEventArgs^ args);
150  void handleMouseUp(Windows::UI::Core::PointerEventArgs^ args);
151  void updateActiveTouches();
152 
155  DX_WINDOW_TYPE mWnd;
157  bool mHidden;
164  // MultiTouch
166  std::map<DWORD,Vec2f> mMultiTouchPrev;
167  std::map<DWORD,DWORD> mTouchIds;
168  std::vector<TouchEvent::Touch> mActiveTouches;
169  DWORD mTouchId;
170 
172  friend AppImplWinRT;
173 };
174 
175 
176 
177 
178 } } // namespace cinder::app
std::map< DWORD, DWORD > mTouchIds
Definition: AppImplWinRT.h:167
bool mHidden
Definition: AppImplWinRT.h:157
DX_WINDOW_TYPE mWnd
Definition: AppImplWinRT.h:155
bool mIsMultiTouchEnabled
Definition: AppImplWinRT.h:165
Vec2i mWindowOffset
Definition: AppImplWinRT.h:156
static void getFolderPath(const fs::path &initialPath, std::vector< std::string > extensions, std::function< void(fs::path)> f=nullptr)
Definition: AppImplWinRT.cpp:140
std::vector< TouchEvent::Touch > mActiveTouches
Definition: AppImplWinRT.h:168
virtual WindowRef getWindow() const
Definition: AppImplWinRT.h:60
WindowRef mActiveWindow
Definition: AppImplWinRT.h:85
bool isAlwaysOnTop() const
Definition: AppImplWinRT.h:123
bool mResizable
Definition: AppImplWinRT.h:159
bool mControlKey
Definition: AppImplWinRT.h:89
virtual void closeWindow(class WindowImplWinRT *windowImpl)=0
GLsizei const GLchar ** string
Definition: GLee.h:2427
float mFrameRate
Definition: AppImplWinRT.h:84
Options passed when entering fullscreen.
Definition: Window.h:110
virtual bool isHidden() const
Definition: AppImplWinRT.cpp:372
virtual DisplayRef getDisplay() const
Definition: AppImplWinRT.h:112
virtual void setSize(const Vec2i &size)
Definition: AppImplWinRT.cpp:387
void getScreenSize(int clientWidth, int clientHeight, int *resultWidth, int *resultHeight)
Definition: AppImplWinRT.cpp:330
AppImplWinRT * getAppImpl()
Definition: AppImplWinRT.h:126
AppImplWinRT(class App *aApp)
Definition: AppImplWinRT.cpp:76
float getFrameRate() const
Definition: AppImplWinRT.h:56
virtual void * getNative()
Definition: AppImplWinRT.h:115
static fs::path getAppPath()
Definition: AppImplWinRT.cpp:131
virtual void setFullScreen(bool fullScreen, const FullScreenOptions &options)
Definition: AppImplWinRT.cpp:319
bool mAltKey
Definition: AppImplWinRT.h:87
static void hideCursor()
Definition: AppImplWinRT.cpp:90
virtual ~AppImplWinRT()
Definition: AppImplWinRT.cpp:85
void handleMouseMoved(Windows::UI::Core::PointerEventArgs^args)
Definition: AppImplWinRT.cpp:685
virtual void close()
Definition: AppImplWinRT.cpp:393
virtual void setForegroundWindow(WindowRef window)=0
void handleTouchDown(Windows::UI::Core::PointerEventArgs^args)
Definition: AppImplWinRT.cpp:636
void privateClose()
Definition: AppImplWinRT.cpp:747
virtual void setPos(const Vec2i &pos)
Definition: AppImplWinRT.cpp:343
static Buffer loadResource(int id, const std::string &type)
Definition: AppImplWinRT.cpp:101
virtual void redraw()
Definition: AppImplWinRT.cpp:742
bool mAlwaysOnTop
Definition: AppImplWinRT.h:159
virtual void hide()
Definition: AppImplWinRT.cpp:360
virtual void resize()
Definition: AppImplWinRT.cpp:736
std::shared_ptr< Window > WindowRef
Definition: Event.h:49
std::map< DWORD, Vec2f > mMultiTouchPrev
Definition: AppImplWinRT.h:166
virtual void handleKeyUp(Windows::UI::Core::KeyEventArgs^args)
Definition: AppImplWinRT.cpp:562
bool isBorderless() const
Definition: AppImplWinRT.h:121
virtual Vec2i getPos() const
Definition: AppImplWinRT.h:104
static void getOpenFilePath(const fs::path &initialPath="", std::vector< std::string > extensions=std::vector< std::string >(), std::function< void(fs::path)> f=nullptr)
Definition: AppImplWinRT.cpp:172
bool mSetupHasBeenCalled
Definition: AppImplWinRT.h:86
Definition: Buffer.h:31
virtual bool isFullScreen()
Definition: AppImplWinRT.h:100
void createWindow(const Vec2i &windowSize, const std::string &title)
Definition: AppImplWinRT.cpp:301
Definition: App.h:127
void setAlwaysOnTop(bool alwaysOnTop)
Definition: AppImplWinRT.cpp:586
bool mBorderless
Definition: AppImplWinRT.h:159
void handlePointerMoved(Windows::UI::Core::PointerEventArgs^args)
Definition: AppImplWinRT.cpp:626
static void showCursor()
Definition: AppImplWinRT.cpp:95
virtual void keyDown(const KeyEvent &event)
Definition: AppImplWinRT.cpp:722
class App * mApp
Definition: AppImplWinRT.h:83
int mWindowHeight
Definition: AppImplWinRT.h:158
friend AppImplWinRT
Definition: AppImplWinRT.h:172
AppImplWinRT * mAppImpl
Definition: AppImplWinRT.h:153
void enableMultiTouch()
Definition: AppImplWinRT.cpp:400
static void registerWindowClass()
bool mFullScreen
Definition: AppImplWinRT.h:159
DWORD mTouchId
Definition: AppImplWinRT.h:169
virtual Vec2i getSize() const
Definition: AppImplWinRT.h:102
std::shared_ptr< class Renderer > RendererRef
Definition: Renderer.h:85
void completeCreation()
Definition: AppImplWinRT.cpp:306
void handleMouseDown(Windows::UI::Core::PointerEventArgs^args)
Definition: AppImplWinRT.cpp:655
unsigned int prepKeyEventModifiers()
Definition: AppImplMsw.cpp:730
virtual void draw()
Definition: AppImplWinRT.cpp:728
bool mIsDragging
Definition: AppImplWinRT.h:163
DisplayRef mDisplay
Definition: AppImplWinRT.h:161
void setBorderless(bool borderless)
Definition: AppImplWinRT.cpp:520
virtual void handleKeyDown(Windows::UI::Core::KeyEventArgs^args)
Definition: AppImplWinRT.cpp:538
Definition: AppImplWinRT.h:95
void toggleFullScreen()
Definition: AppImplWinRT.cpp:325
virtual std::string getTitle() const
Definition: AppImplWinRT.cpp:377
virtual RendererRef getRenderer() const
Definition: AppImplWinRT.h:113
std::shared_ptr< class Display > DisplayRef
Definition: Display.h:53
virtual void show()
Definition: AppImplWinRT.cpp:366
Window window
Definition: GLee.h:17134
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:963
WindowRef getWindow()
Definition: AppImplWinRT.h:127
Definition: AppImplWinRT.h:49
WindowImplWinRT(const Window::Format &format, AppImplWinRT *appImpl)
Definition: AppImplWinRT.cpp:255
class App * getApp()
Definition: AppImplWinRT.h:54
bool setupHasBeenCalled() const
Definition: AppImplWinRT.h:78
virtual const std::vector< TouchEvent::Touch > & getActiveTouches() const
Definition: AppImplWinRT.h:114
Definition: Window.h:140
void handleTouchMoved(Windows::UI::Core::PointerEventArgs^args)
Definition: AppImplWinRT.cpp:666
void handlePointerUp(Windows::UI::Core::PointerEventArgs^args)
Definition: AppImplWinRT.cpp:631
Vec2i mWindowedSize
Definition: AppImplWinRT.h:160
void setWindow(WindowRef window)
Definition: AppImplWinRT.h:61
int mWindowWidth
Definition: AppImplWinRT.h:158
GLenum GLsizei GLenum format
Definition: GLee.h:969
RendererRef mRenderer
Definition: AppImplWinRT.h:162
Vec2i mWindowedPos
Definition: AppImplWinRT.h:160
void handleTouchUp(Windows::UI::Core::PointerEventArgs^args)
Definition: AppImplWinRT.cpp:697
void handlePointerDown(Windows::UI::Core::PointerEventArgs^args)
Definition: AppImplWinRT.cpp:621
virtual float setFrameRate(float aFrameRate)
Definition: AppImplWinRT.h:57
GLclampf f
Definition: GLee.h:15307
void handleMouseUp(Windows::UI::Core::PointerEventArgs^args)
Definition: AppImplWinRT.cpp:712
Represents a keyboard event.
Definition: KeyEvent.h:32
virtual void setTitle(const std::string &title)
Definition: AppImplWinRT.cpp:382
GLsizeiptr size
Definition: GLee.h:2089
DX_WINDOW_TYPE getNativeCoreWindow()
Definition: AppImplWinRT.h:118
virtual void quit()=0
WindowRef mWindowRef
Definition: AppImplWinRT.h:154
bool mShiftKey
Definition: AppImplWinRT.h:88
static void getSaveFilePath(const fs::path &initialPath, std::vector< std::string > extensions, std::function< void(fs::path)> f=nullptr)
Definition: AppImplWinRT.cpp:204
Vec2< int > Vec2i
Definition: Vector.h:1313
std::string mTitle
Definition: AppImplWinRT.h:171