Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > ed1483a4d9709d82850bb84cf25535e7 > files > 173

sfml-1.5-1mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>SFML - Simple and Fast Multimedia Library</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="tabs.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="logo">
            <img src="./logo.jpg" width="770" height="200" title="SFML home" alt="SFML logo" />
        </div>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.htm"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.htm"><span>Namespaces</span></a></li>
      <li><a href="annotated.htm"><span>Classes</span></a></li>
      <li class="current"><a href="files.htm"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.htm"><span>File&nbsp;List</span></a></li>
    </ul>
  </div>
<h1>WindowImplCocoa.mm</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// SFML - Simple and Fast Multimedia Library</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (C) 2007-2009 Lucas Soltic (ceylow@gmail.com) and Laurent Gomila (laurent.gom@gmail.com)</span>
<a name="l00005"></a>00005 <span class="comment">//</span>
<a name="l00006"></a>00006 <span class="comment">// This software is provided 'as-is', without any express or implied warranty.</span>
<a name="l00007"></a>00007 <span class="comment">// In no event will the authors be held liable for any damages arising from the use of this software.</span>
<a name="l00008"></a>00008 <span class="comment">//</span>
<a name="l00009"></a>00009 <span class="comment">// Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00010"></a>00010 <span class="comment">// including commercial applications, and to alter it and redistribute it freely,</span>
<a name="l00011"></a>00011 <span class="comment">// subject to the following restrictions:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// 1. The origin of this software must not be misrepresented;</span>
<a name="l00014"></a>00014 <span class="comment">//    you must not claim that you wrote the original software.</span>
<a name="l00015"></a>00015 <span class="comment">//    If you use this software in a product, an acknowledgment</span>
<a name="l00016"></a>00016 <span class="comment">//    in the product documentation would be appreciated but is not required.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018 <span class="comment">// 2. Altered source versions must be plainly marked as such,</span>
<a name="l00019"></a>00019 <span class="comment">//    and must not be misrepresented as being the original software.</span>
<a name="l00020"></a>00020 <span class="comment">//</span>
<a name="l00021"></a>00021 <span class="comment">// 3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00022"></a>00022 <span class="comment">//</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00025"></a>00025 
<a name="l00027"></a>00027 <span class="comment">// Headers</span>
<a name="l00029"></a>00029 <span class="comment"></span><span class="preprocessor">#import &lt;SFML/Window/Cocoa/WindowImplCocoa.hpp&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#import &lt;SFML/Window/Cocoa/AppController.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#import &lt;SFML/Window/Cocoa/GLKit.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#import &lt;SFML/Window/WindowStyle.hpp&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#import &lt;SFML/System.hpp&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#import &lt;OpenGL/OpenGL.h&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#import &lt;OpenGL/gl.h&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#import &lt;CoreFoundation/CoreFoundation.h&gt;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#import &lt;iostream&gt;</span>
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="keyword">namespace </span>sf
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042 <span class="keyword">namespace </span>priv
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 <span class="comment">// Do something only once (useful in loops)</span>
<a name="l00046"></a>00046 <span class="preprocessor">#define ONCE(make) \</span>
<a name="l00047"></a>00047 <span class="preprocessor">{ static int __done = 0;\</span>
<a name="l00048"></a>00048 <span class="preprocessor">if (!__done) {\</span>
<a name="l00049"></a>00049 <span class="preprocessor">make;\</span>
<a name="l00050"></a>00050 <span class="preprocessor">__done = 1;\</span>
<a name="l00051"></a>00051 <span class="preprocessor">} }</span>
<a name="l00052"></a>00052 <span class="preprocessor"></span>
<a name="l00053"></a>00053 
<a name="l00057"></a>00057 <span class="keyword">static</span> Key::Code        KeyForVirtualCode(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> vCode);
<a name="l00058"></a>00058 <span class="keyword">static</span> Key::Code        KeyForUnicode(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> uniCode);
<a name="l00059"></a>00059 <span class="keyword">static</span> <span class="keywordtype">bool</span>             IsTextEvent(NSEvent *event);
<a name="l00060"></a>00060 
<a name="l00061"></a>00061 
<a name="l00066"></a>00066     <span class="keyword">static</span> WindowImplCocoa *globalWin = NULL;
<a name="l00067"></a>00067 WindowImplCocoa::WindowImplCocoa() :
<a name="l00068"></a>00068 myWrapper(nil),
<a name="l00069"></a>00069 myUseKeyRepeat(false),
<a name="l00070"></a>00070 myMouseIn(false),
<a name="l00071"></a>00071 myWheelStatus(0.0f)
<a name="l00072"></a>00072 {
<a name="l00073"></a>00073     [AppController sharedController];
<a name="l00074"></a>00074     
<a name="l00075"></a>00075     <span class="comment">// Create the shared OpenGL context</span>
<a name="l00076"></a>00076     <span class="keywordflow">if</span> ([<a class="code" href="interfaceGLContext.htm" title="Window independant OpenGL context class.">GLContext</a> sharedContext]) {
<a name="l00077"></a>00077         <span class="comment">// Then we make it the current active OpenGL context</span>
<a name="l00078"></a>00078         <a class="code" href="classsf_1_1Window.htm#9fc1e745594d5cf6a30225ec9ea36675" title="Activate of deactivate the window as the current target for rendering.">SetActive</a>();
<a name="l00079"></a>00079     } <span class="keywordflow">else</span> {
<a name="l00080"></a>00080         std::cerr &lt;&lt; <span class="stringliteral">"Unable to make the main shared OpenGL context"</span> &lt;&lt; std::endl;
<a name="l00081"></a>00081     }
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083 
<a name="l00084"></a>00084 
<a name="l00088"></a>00088 WindowImplCocoa::WindowImplCocoa(WindowHandle Handle, WindowSettings&amp; params) :
<a name="l00089"></a>00089 myWrapper(NULL),
<a name="l00090"></a>00090 myUseKeyRepeat(false),
<a name="l00091"></a>00091 myMouseIn(false),
<a name="l00092"></a>00092 myWheelStatus(0.0f)
<a name="l00093"></a>00093 {
<a name="l00094"></a>00094     <span class="keywordflow">if</span> (Handle)
<a name="l00095"></a>00095     {
<a name="l00096"></a>00096         <span class="keywordflow">if</span> (![(NSWindow *)Handle isKindOfClass:[NSWindow <span class="keyword">class</span>]])
<a name="l00097"></a>00097             std::cerr &lt;&lt; <span class="stringliteral">"Cannot import this Window Handle because it is not a &lt;NSWindow *&gt; object"</span>
<a name="l00098"></a>00098             &lt;&lt; <span class="stringliteral">"(or one of its subclasses). You gave a &lt;"</span> 
<a name="l00099"></a>00099             &lt;&lt; [[(NSWindow *)Handle className] UTF8String]
<a name="l00100"></a>00100             &lt;&lt; <span class="stringliteral">"&gt; object."</span> &lt;&lt; std::endl;
<a name="l00101"></a>00101         <span class="keywordflow">else</span>
<a name="l00102"></a>00102         {
<a name="l00103"></a>00103             
<a name="l00104"></a>00104             <span class="comment">// We create the window according to the given handle</span>
<a name="l00105"></a>00105             myWrapper = [[<a class="code" href="interfaceWindowWrapper.htm" title="WindowWrapper class : handles both imported and self-built windows.">WindowWrapper</a> alloc] initWithWindow:(NSWindow *)Handle
<a name="l00106"></a>00106                                                      settings:params
<a name="l00107"></a>00107                                                      delegate:this];
<a name="l00108"></a>00108             
<a name="l00109"></a>00109             <span class="keywordflow">if</span> (myWrapper)
<a name="l00110"></a>00110             {
<a name="l00111"></a>00111                 <span class="comment">// initial mouse state</span>
<a name="l00112"></a>00112                 myMouseIn = [myWrapper mouseInside];
<a name="l00113"></a>00113                 
<a name="l00114"></a>00114                 <span class="comment">// We set the myWidth and myHeight members to the correct values</span>
<a name="l00115"></a>00115                 myWidth = (int) [[myWrapper glView] frame].size.width;
<a name="l00116"></a>00116                 myHeight = (<span class="keywordtype">int</span>) [[myWrapper glView] frame].size.height;
<a name="l00117"></a>00117             } <span class="keywordflow">else</span> {
<a name="l00118"></a>00118                 std::cerr &lt;&lt; <span class="stringliteral">"Failed to make the public window"</span> &lt;&lt; std::endl;
<a name="l00119"></a>00119             }
<a name="l00120"></a>00120         }
<a name="l00121"></a>00121     }
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123 
<a name="l00124"></a>00124 
<a name="l00128"></a>00128 WindowImplCocoa::WindowImplCocoa(VideoMode Mode, <span class="keyword">const</span> std::string&amp; Title, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> WindowStyle, WindowSettings&amp; params) :
<a name="l00129"></a>00129 myWrapper(NULL),
<a name="l00130"></a>00130 myUseKeyRepeat(false),
<a name="l00131"></a>00131 myMouseIn(false),
<a name="l00132"></a>00132 myWheelStatus(0.0f)
<a name="l00133"></a>00133 {
<a name="l00134"></a>00134     <span class="comment">// Create a new window with given size, title and style</span>
<a name="l00135"></a>00135     <span class="comment">// First we define some objects used for our window</span>
<a name="l00136"></a>00136     NSString *title = [NSString stringWithUTF8String:(Title.c_str()) ? (Title.c_str()) : ""];
<a name="l00137"></a>00137     
<a name="l00138"></a>00138     <span class="comment">// We create the window</span>
<a name="l00139"></a>00139     myWrapper = [[<a class="code" href="interfaceWindowWrapper.htm" title="WindowWrapper class : handles both imported and self-built windows.">WindowWrapper</a> alloc] initWithSettings:params
<a name="l00140"></a>00140                                                videoMode:Mode
<a name="l00141"></a>00141                                                    style:WindowStyle
<a name="l00142"></a>00142                                                    title:title
<a name="l00143"></a>00143                                                 delegate:this];
<a name="l00144"></a>00144     
<a name="l00145"></a>00145     <span class="keywordflow">if</span> (myWrapper)
<a name="l00146"></a>00146     {
<a name="l00147"></a>00147         <span class="comment">// initial mouse state</span>
<a name="l00148"></a>00148         myMouseIn = [myWrapper mouseInside];
<a name="l00149"></a>00149         
<a name="l00150"></a>00150         <span class="comment">// We set the myWidth and myHeight members to the correct values</span>
<a name="l00151"></a>00151         myWidth = Mode.Width;
<a name="l00152"></a>00152         myHeight = Mode.Height;
<a name="l00153"></a>00153     } <span class="keywordflow">else</span> {
<a name="l00154"></a>00154         std::cerr &lt;&lt; <span class="stringliteral">"Failed to make the public window"</span> &lt;&lt; std::endl;
<a name="l00155"></a>00155     }
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 
<a name="l00158"></a>00158 
<a name="l00162"></a>00162 WindowImplCocoa::~WindowImplCocoa()
<a name="l00163"></a>00163 {
<a name="l00164"></a>00164     <span class="comment">// Release the window wrapper</span>
<a name="l00165"></a>00165     [myWrapper release];
<a name="l00166"></a>00166 }
<a name="l00167"></a>00167 
<a name="l00168"></a>00168 
<a name="l00172"></a>00172 <span class="keywordtype">bool</span> WindowImplCocoa::IsContextActive()
<a name="l00173"></a>00173 {
<a name="l00174"></a>00174     <span class="keywordflow">return</span> ([NSOpenGLContext currentContext] != NULL);
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 
<a name="l00177"></a>00177 
<a name="l00181"></a>00181 <span class="keywordtype">void</span> WindowImplCocoa::HandleNotifiedEvent(Event&amp; event)
<a name="l00182"></a>00182 {
<a name="l00183"></a>00183     <span class="comment">// Set myWidth and myHeight to correct value if</span>
<a name="l00184"></a>00184     <span class="comment">// window size changed</span>
<a name="l00185"></a>00185     <span class="keywordflow">switch</span> (event.Type) {
<a name="l00186"></a>00186         <span class="keywordflow">case</span> Event::Resized:
<a name="l00187"></a>00187             myWidth = <span class="keyword">event</span>.Size.Width;
<a name="l00188"></a>00188             myHeight = <span class="keyword">event</span>.Size.Height;
<a name="l00189"></a>00189             <span class="keywordflow">break</span>;
<a name="l00190"></a>00190             
<a name="l00191"></a>00191         <span class="keywordflow">default</span>:
<a name="l00192"></a>00192             <span class="keywordflow">break</span>;
<a name="l00193"></a>00193     }
<a name="l00194"></a>00194     
<a name="l00195"></a>00195     <span class="comment">// And send the event</span>
<a name="l00196"></a>00196     SendEvent(event);
<a name="l00197"></a>00197 }
<a name="l00198"></a>00198 
<a name="l00199"></a>00199 
<a name="l00203"></a>00203 <span class="keywordtype">void</span> WindowImplCocoa::HandleKeyDown(<span class="keywordtype">void</span> *eventRef)
<a name="l00204"></a>00204 {
<a name="l00205"></a>00205     NSEvent *<span class="keyword">event</span> = reinterpret_cast &lt;NSEvent *&gt; (eventRef);
<a name="l00206"></a>00206     
<a name="l00207"></a>00207     Event sfEvent;
<a name="l00208"></a>00208     unichar chr = 0, rawchr = 0;
<a name="l00209"></a>00209     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> length = [[event characters] length];
<a name="l00210"></a>00210     <span class="keywordtype">unsigned</span> mods = [event modifierFlags];
<a name="l00211"></a>00211     
<a name="l00212"></a>00212     <span class="keywordflow">if</span> (length) {
<a name="l00213"></a>00213         chr = [[event characters] characterAtIndex:0];
<a name="l00214"></a>00214         
<a name="l00215"></a>00215         <span class="comment">// Note : I got a crash (out of bounds exception) while typing so now I test...</span>
<a name="l00216"></a>00216         <span class="keywordflow">if</span> ([[event charactersIgnoringModifiers] length])
<a name="l00217"></a>00217             rawchr = [[event charactersIgnoringModifiers] characterAtIndex:0];
<a name="l00218"></a>00218         
<a name="l00219"></a>00219         
<a name="l00220"></a>00220         <span class="comment">// Don't handle repeated events if we chose not to send them</span>
<a name="l00221"></a>00221         <span class="keywordflow">if</span> (!myUseKeyRepeat &amp;&amp; [event isARepeat])
<a name="l00222"></a>00222             <span class="keywordflow">return</span>;
<a name="l00223"></a>00223         
<a name="l00224"></a>00224         <span class="comment">// Is it also a text event ?</span>
<a name="l00225"></a>00225         <span class="keywordflow">if</span> (IsTextEvent(event)) {
<a name="l00226"></a>00226             <span class="comment">// buffer for the UTF-32 characters</span>
<a name="l00227"></a>00227             Uint32 utf32Characters[2] = {0};
<a name="l00228"></a>00228             
<a name="l00229"></a>00229             <span class="comment">// convert the characters</span>
<a name="l00230"></a>00230             <span class="comment">// note: using CFString in order to keep compatibility with Mac OS X 10.4</span>
<a name="l00231"></a>00231             <span class="comment">// (NSUTF32StringEncoding only defined since Mac OS X 10.5)</span>
<a name="l00232"></a>00232             <span class="keywordflow">if</span> (!CFStringGetCString ((CFStringRef)[event characters],
<a name="l00233"></a>00233                                      (<span class="keywordtype">char</span> *)utf32Characters,
<a name="l00234"></a>00234                                      <span class="keyword">sizeof</span>(utf32Characters),
<a name="l00235"></a>00235                                      kCFStringEncodingUTF32))
<a name="l00236"></a>00236             {
<a name="l00237"></a>00237                 <span class="keyword">const</span> <span class="keywordtype">char</span> *utf8Char = NULL;
<a name="l00238"></a>00238                 <span class="keywordflow">if</span> ([[event characters] lengthOfBytesUsingEncoding:NSUTF8StringEncoding])
<a name="l00239"></a>00239                     utf8Char = [[event characters] UTF8String]; 
<a name="l00240"></a>00240                 
<a name="l00241"></a>00241                 std::cerr &lt;&lt; <span class="stringliteral">"Error while converting character to UTF32 : "</span>
<a name="l00242"></a>00242                 &lt;&lt; ((utf8Char) ? utf8Char : <span class="stringliteral">"(undefined)"</span>) &lt;&lt; std::endl;
<a name="l00243"></a>00243             }
<a name="l00244"></a>00244             <span class="keywordflow">else</span>
<a name="l00245"></a>00245             {
<a name="l00246"></a>00246                 sfEvent.Type = Event::TextEntered;
<a name="l00247"></a>00247                 sfEvent.Text.Unicode = utf32Characters[0];
<a name="l00248"></a>00248                 
<a name="l00249"></a>00249                 SendEvent(sfEvent);
<a name="l00250"></a>00250             }
<a name="l00251"></a>00251         }
<a name="l00252"></a>00252         
<a name="l00253"></a>00253         <span class="comment">// Anyway it's also a KeyPressed event</span>
<a name="l00254"></a>00254         sfEvent.Type = Event::KeyPressed;
<a name="l00255"></a>00255         
<a name="l00256"></a>00256         <span class="comment">// Get the keys</span>
<a name="l00257"></a>00257         <span class="keywordflow">if</span> (<a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0) == (sfEvent.Key.Code = KeyForUnicode(rawchr))) {
<a name="l00258"></a>00258             sfEvent.Key.Code = KeyForVirtualCode([event keyCode]);
<a name="l00259"></a>00259         }
<a name="l00260"></a>00260         
<a name="l00261"></a>00261         <span class="comment">// Get the modifiers</span>
<a name="l00262"></a>00262         sfEvent.Key.Alt = mods &amp; NSAlternateKeyMask;
<a name="l00263"></a>00263         sfEvent.Key.Control = mods &amp; NSControlKeyMask;
<a name="l00264"></a>00264         sfEvent.Key.Shift = mods &amp; NSShiftKeyMask;
<a name="l00265"></a>00265         
<a name="l00266"></a>00266         <span class="comment">// Send the event</span>
<a name="l00267"></a>00267         SendEvent(sfEvent);
<a name="l00268"></a>00268     }
<a name="l00269"></a>00269 }
<a name="l00270"></a>00270 
<a name="l00271"></a>00271 
<a name="l00275"></a>00275 <span class="keywordtype">void</span> WindowImplCocoa::HandleKeyUp(<span class="keywordtype">void</span> *eventRef)
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277     NSEvent *<span class="keyword">event</span> = reinterpret_cast &lt;NSEvent *&gt; (eventRef);
<a name="l00278"></a>00278     
<a name="l00279"></a>00279     Event sfEvent;
<a name="l00280"></a>00280     <span class="keywordtype">unsigned</span> mods = [event modifierFlags];
<a name="l00281"></a>00281     unichar chr = 0, rawchr = 0;
<a name="l00282"></a>00282     
<a name="l00283"></a>00283     <span class="keywordflow">if</span> ([[event characters] length]) {
<a name="l00284"></a>00284         chr = [[event characters] characterAtIndex:0];
<a name="l00285"></a>00285         
<a name="l00286"></a>00286         <span class="keywordflow">if</span> ([[event charactersIgnoringModifiers] length])
<a name="l00287"></a>00287             rawchr = [[event charactersIgnoringModifiers] characterAtIndex:0];
<a name="l00288"></a>00288         
<a name="l00289"></a>00289         sfEvent.Type = Event::KeyReleased;
<a name="l00290"></a>00290         
<a name="l00291"></a>00291         <span class="comment">// Get the code</span>
<a name="l00292"></a>00292         <span class="keywordflow">if</span> (<a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0) == (sfEvent.Key.Code = KeyForUnicode(rawchr))) {
<a name="l00293"></a>00293             sfEvent.Key.Code = KeyForVirtualCode([event keyCode]);
<a name="l00294"></a>00294         }
<a name="l00295"></a>00295         
<a name="l00296"></a>00296         <span class="comment">// Get the modifiers</span>
<a name="l00297"></a>00297         sfEvent.Key.Alt = mods &amp; NSAlternateKeyMask;
<a name="l00298"></a>00298         sfEvent.Key.Control = mods &amp; NSControlKeyMask;
<a name="l00299"></a>00299         sfEvent.Key.Shift = mods &amp; NSShiftKeyMask;
<a name="l00300"></a>00300         
<a name="l00301"></a>00301         <span class="comment">// Send the event</span>
<a name="l00302"></a>00302         SendEvent(sfEvent);
<a name="l00303"></a>00303     }
<a name="l00304"></a>00304 }
<a name="l00305"></a>00305 
<a name="l00306"></a>00306 
<a name="l00310"></a>00310 <span class="keywordtype">void</span> WindowImplCocoa::HandleModifierKey(<span class="keywordtype">void</span> *eventRef)
<a name="l00311"></a>00311 {
<a name="l00312"></a>00312     NSEvent *<span class="keyword">event</span> = reinterpret_cast &lt;NSEvent *&gt; (eventRef);
<a name="l00313"></a>00313     Event sfEvent;
<a name="l00314"></a>00314     <span class="keywordtype">unsigned</span> mods = [event modifierFlags];
<a name="l00315"></a>00315     
<a name="l00316"></a>00316     sfEvent.Type = Event::KeyPressed;
<a name="l00317"></a>00317     
<a name="l00318"></a>00318     <span class="comment">// Get the code</span>
<a name="l00319"></a>00319     sfEvent.Key.Code = KeyForVirtualCode([event keyCode]);
<a name="l00320"></a>00320     
<a name="l00321"></a>00321     <span class="comment">// Get the modifiers</span>
<a name="l00322"></a>00322     sfEvent.Key.Alt = mods &amp; NSAlternateKeyMask;
<a name="l00323"></a>00323     sfEvent.Key.Control = mods &amp; NSControlKeyMask;
<a name="l00324"></a>00324     sfEvent.Key.Shift = mods &amp; NSShiftKeyMask;
<a name="l00325"></a>00325     
<a name="l00326"></a>00326     <span class="comment">// Guess whether it's a pressed or released event</span>
<a name="l00327"></a>00327     <span class="comment">// Note: this does not work fine is both left and right modifiers are pressed</span>
<a name="l00328"></a>00328     <span class="comment">// I did not find any way to fix this.</span>
<a name="l00329"></a>00329     <span class="comment">// TODO: fix handling of modifier flags for use of left and right key at the same time</span>
<a name="l00330"></a>00330     <span class="keywordflow">if</span> (!(mods &amp; NSAlternateKeyMask) &amp;&amp;
<a name="l00331"></a>00331         (sfEvent.Key.Code == Key::LAlt || sfEvent.Key.Code == Key::RAlt)) {
<a name="l00332"></a>00332         sfEvent.Type = Event::KeyReleased;
<a name="l00333"></a>00333     }
<a name="l00334"></a>00334     
<a name="l00335"></a>00335     <span class="keywordflow">if</span> (!(mods &amp; NSControlKeyMask) &amp;&amp;
<a name="l00336"></a>00336         (sfEvent.Key.Code == Key::LControl || sfEvent.Key.Code == Key::RControl)) {
<a name="l00337"></a>00337         sfEvent.Type = Event::KeyReleased;
<a name="l00338"></a>00338     }
<a name="l00339"></a>00339     
<a name="l00340"></a>00340     <span class="keywordflow">if</span> (!(mods &amp; NSShiftKeyMask) &amp;&amp;
<a name="l00341"></a>00341         (sfEvent.Key.Code == Key::LShift || sfEvent.Key.Code == Key::RShift)) {
<a name="l00342"></a>00342         sfEvent.Type = Event::KeyReleased;
<a name="l00343"></a>00343     }
<a name="l00344"></a>00344     
<a name="l00345"></a>00345     <span class="keywordflow">if</span> (!(mods &amp; NSCommandKeyMask) &amp;&amp;
<a name="l00346"></a>00346         (sfEvent.Key.Code == <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81819a5d0739e89a6543b8a1d3b2ed4bdb" title="OS specific key (left side) : windows (Win and Linux), apple (MacOS), ...">Key::LSystem</a> || sfEvent.Key.Code == <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81461545de42376b666cb38860a0beec49" title="OS specific key (right side) : windows (Win and Linux), apple (MacOS), ...">Key::RSystem</a>)) {
<a name="l00347"></a>00347         sfEvent.Type = Event::KeyReleased;
<a name="l00348"></a>00348     }
<a name="l00349"></a>00349     
<a name="l00350"></a>00350     <span class="comment">// Send the event</span>
<a name="l00351"></a>00351     SendEvent(sfEvent);
<a name="l00352"></a>00352 }
<a name="l00353"></a>00353 
<a name="l00354"></a>00354 
<a name="l00358"></a>00358 <span class="keywordtype">void</span> WindowImplCocoa::HandleMouseDown(<span class="keywordtype">void</span> *eventRef)
<a name="l00359"></a>00359 {
<a name="l00360"></a>00360     NSEvent *<span class="keyword">event</span> = reinterpret_cast &lt;NSEvent *&gt; (eventRef);
<a name="l00361"></a>00361     Event sfEvent;
<a name="l00362"></a>00362     NSPoint loc = {0, 0};
<a name="l00363"></a>00363     <span class="keywordtype">unsigned</span> mods = [event modifierFlags];
<a name="l00364"></a>00364     
<a name="l00365"></a>00365     <span class="keywordflow">switch</span> ([event type]) {
<a name="l00366"></a>00366         <span class="keywordflow">case</span> NSLeftMouseDown:
<a name="l00367"></a>00367             sfEvent.Type = Event::MouseButtonPressed;
<a name="l00368"></a>00368             
<a name="l00369"></a>00369             <span class="comment">// Guess whether it's a mouse left or mouse right event</span>
<a name="l00370"></a>00370             <span class="keywordflow">if</span> (mods &amp; NSControlKeyMask) {
<a name="l00371"></a>00371                 sfEvent.MouseButton.Button = Mouse::Right;
<a name="l00372"></a>00372             } <span class="keywordflow">else</span> {
<a name="l00373"></a>00373                 sfEvent.MouseButton.Button = Mouse::Left;
<a name="l00374"></a>00374             }
<a name="l00375"></a>00375             
<a name="l00376"></a>00376             <span class="comment">// Get mouse position relative to the window</span>
<a name="l00377"></a>00377             loc = [myWrapper mouseLocation];
<a name="l00378"></a>00378             
<a name="l00379"></a>00379             sfEvent.MouseButton.X = (int) loc.x;
<a name="l00380"></a>00380             sfEvent.MouseButton.Y = (<span class="keywordtype">int</span>) loc.y;
<a name="l00381"></a>00381             
<a name="l00382"></a>00382             <span class="comment">// Send the event</span>
<a name="l00383"></a>00383             SendEvent(sfEvent);
<a name="l00384"></a>00384             <span class="keywordflow">break</span>;
<a name="l00385"></a>00385             
<a name="l00386"></a>00386         <span class="keywordflow">case</span> NSRightMouseDown:
<a name="l00387"></a>00387             sfEvent.Type = Event::MouseButtonPressed;
<a name="l00388"></a>00388             sfEvent.MouseButton.Button = Mouse::Right;
<a name="l00389"></a>00389             
<a name="l00390"></a>00390             <span class="comment">// Get mouse position relative to the window</span>
<a name="l00391"></a>00391             loc = [myWrapper mouseLocation];
<a name="l00392"></a>00392             
<a name="l00393"></a>00393             sfEvent.MouseButton.X = (int) loc.x;
<a name="l00394"></a>00394             sfEvent.MouseButton.Y = (<span class="keywordtype">int</span>) loc.y;
<a name="l00395"></a>00395             
<a name="l00396"></a>00396             <span class="comment">// Send the event</span>
<a name="l00397"></a>00397             SendEvent(sfEvent);
<a name="l00398"></a>00398             <span class="keywordflow">break</span>;
<a name="l00399"></a>00399             
<a name="l00400"></a>00400         <span class="keywordflow">default</span>:
<a name="l00401"></a>00401             <span class="keywordflow">break</span>;
<a name="l00402"></a>00402     }
<a name="l00403"></a>00403 }
<a name="l00404"></a>00404 
<a name="l00405"></a>00405 
<a name="l00409"></a>00409 <span class="keywordtype">void</span> WindowImplCocoa::HandleMouseUp(<span class="keywordtype">void</span> *eventRef)
<a name="l00410"></a>00410 {
<a name="l00411"></a>00411     NSEvent *<span class="keyword">event</span> = reinterpret_cast &lt;NSEvent *&gt; (eventRef);
<a name="l00412"></a>00412     Event sfEvent;
<a name="l00413"></a>00413     NSPoint loc = {0, 0};
<a name="l00414"></a>00414     <span class="keywordtype">unsigned</span> mods = [event modifierFlags];
<a name="l00415"></a>00415     
<a name="l00416"></a>00416     <span class="keywordflow">switch</span> ([event type]) {
<a name="l00417"></a>00417         <span class="keywordflow">case</span> NSLeftMouseUp:
<a name="l00418"></a>00418             sfEvent.Type = Event::MouseButtonReleased;
<a name="l00419"></a>00419             
<a name="l00420"></a>00420             <span class="comment">// Guess whether it's a mouse left or mouse right event</span>
<a name="l00421"></a>00421             <span class="keywordflow">if</span> (mods &amp; NSControlKeyMask) {
<a name="l00422"></a>00422                 sfEvent.MouseButton.Button = Mouse::Right;
<a name="l00423"></a>00423             } <span class="keywordflow">else</span> {
<a name="l00424"></a>00424                 sfEvent.MouseButton.Button = Mouse::Left;
<a name="l00425"></a>00425             }
<a name="l00426"></a>00426             
<a name="l00427"></a>00427             <span class="comment">// Get mouse position relative to the window</span>
<a name="l00428"></a>00428             loc = [myWrapper mouseLocation];
<a name="l00429"></a>00429             
<a name="l00430"></a>00430             sfEvent.MouseButton.X = (int) loc.x;
<a name="l00431"></a>00431             sfEvent.MouseButton.Y = (<span class="keywordtype">int</span>) loc.y;
<a name="l00432"></a>00432             
<a name="l00433"></a>00433             <span class="comment">// Send the event</span>
<a name="l00434"></a>00434             SendEvent(sfEvent);
<a name="l00435"></a>00435             <span class="keywordflow">break</span>;
<a name="l00436"></a>00436             
<a name="l00437"></a>00437         <span class="keywordflow">case</span> NSRightMouseUp:
<a name="l00438"></a>00438             sfEvent.Type = Event::MouseButtonReleased;
<a name="l00439"></a>00439             sfEvent.MouseButton.Button = Mouse::Right;
<a name="l00440"></a>00440             
<a name="l00441"></a>00441             <span class="comment">// Get mouse position relative to the window</span>
<a name="l00442"></a>00442             loc = [myWrapper mouseLocation];
<a name="l00443"></a>00443             
<a name="l00444"></a>00444             sfEvent.MouseButton.X = (int) loc.x;
<a name="l00445"></a>00445             sfEvent.MouseButton.Y = (<span class="keywordtype">int</span>) loc.y;
<a name="l00446"></a>00446             
<a name="l00447"></a>00447             <span class="comment">// Send the event</span>
<a name="l00448"></a>00448             SendEvent(sfEvent);
<a name="l00449"></a>00449             <span class="keywordflow">break</span>;
<a name="l00450"></a>00450             
<a name="l00451"></a>00451         <span class="keywordflow">default</span>:
<a name="l00452"></a>00452             <span class="keywordflow">break</span>;
<a name="l00453"></a>00453     }
<a name="l00454"></a>00454 }
<a name="l00455"></a>00455 
<a name="l00456"></a>00456 
<a name="l00460"></a>00460 <span class="keywordtype">void</span> WindowImplCocoa::HandleMouseMove(<span class="keywordtype">void</span> *eventRef)
<a name="l00461"></a>00461 {
<a name="l00462"></a>00462     Event sfEvent;
<a name="l00463"></a>00463     NSPoint loc = {0, 0};
<a name="l00464"></a>00464     
<a name="l00465"></a>00465     loc = [myWrapper mouseLocation];
<a name="l00466"></a>00466     sfEvent.Type = Event::MouseMoved;
<a name="l00467"></a>00467     
<a name="l00468"></a>00468     sfEvent.MouseMove.X = (int) loc.x;
<a name="l00469"></a>00469     sfEvent.MouseMove.Y = (<span class="keywordtype">int</span>) loc.y;
<a name="l00470"></a>00470     
<a name="l00471"></a>00471     SendEvent(sfEvent);
<a name="l00472"></a>00472     
<a name="l00473"></a>00473     <span class="keywordflow">if</span> ([myWrapper mouseInside] &amp;&amp; !myMouseIn) {
<a name="l00474"></a>00474         <span class="comment">// If mouse IS inside but WAS not inside last time</span>
<a name="l00475"></a>00475         sfEvent.Type = Event::MouseEntered;
<a name="l00476"></a>00476         myMouseIn = <span class="keyword">true</span>;
<a name="l00477"></a>00477         
<a name="l00478"></a>00478         SendEvent(sfEvent);
<a name="l00479"></a>00479     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (![myWrapper mouseInside] &amp;&amp; myMouseIn) {
<a name="l00480"></a>00480         <span class="comment">// Is mouse WAS not inside but IS now inside</span>
<a name="l00481"></a>00481         sfEvent.Type = Event::MouseLeft;
<a name="l00482"></a>00482         myMouseIn   = <span class="keyword">false</span>;
<a name="l00483"></a>00483         
<a name="l00484"></a>00484         SendEvent(sfEvent);
<a name="l00485"></a>00485     }
<a name="l00486"></a>00486 }
<a name="l00487"></a>00487 
<a name="l00488"></a>00488 
<a name="l00492"></a>00492 <span class="keywordtype">void</span> WindowImplCocoa::HandleMouseWheel(<span class="keywordtype">void</span> *eventRef)
<a name="l00493"></a>00493 {
<a name="l00494"></a>00494     NSEvent *<span class="keyword">event</span> = reinterpret_cast &lt;NSEvent *&gt; (eventRef);
<a name="l00495"></a>00495     
<a name="l00496"></a>00496     <span class="comment">// SFML uses integer values for delta but Cocoa uses float and it is mostly fewer than 1.0</span>
<a name="l00497"></a>00497     <span class="comment">// Therefore I chose to add the float value to a 'wheel status' and</span>
<a name="l00498"></a>00498     <span class="comment">// send a sf event only when it's greater than 1.0</span>
<a name="l00499"></a>00499     myWheelStatus += [event deltaY];
<a name="l00500"></a>00500     
<a name="l00501"></a>00501     <span class="keywordflow">if</span> (fabs(myWheelStatus) &gt; 1.0f) {
<a name="l00502"></a>00502         <span class="comment">// Make the event and send it</span>
<a name="l00503"></a>00503         Event sfEvent;
<a name="l00504"></a>00504         sfEvent.Type = Event::MouseWheelMoved;
<a name="l00505"></a>00505         sfEvent.MouseWheel.Delta = (int) myWheelStatus;
<a name="l00506"></a>00506         SendEvent(sfEvent);
<a name="l00507"></a>00507         
<a name="l00508"></a>00508         <span class="comment">// Remove as much integer units as the one that have been put in the event</span>
<a name="l00509"></a>00509         <span class="comment">// (was a mistake to set this to 0)</span>
<a name="l00510"></a>00510         myWheelStatus -= (int) myWheelStatus;
<a name="l00511"></a>00511     }
<a name="l00512"></a>00512 }
<a name="l00513"></a>00513     
<a name="l00514"></a>00514     
<a name="l00518"></a>00518 <span class="keywordtype">void</span> WindowImplCocoa::Display()
<a name="l00519"></a>00519 {
<a name="l00520"></a>00520     <span class="comment">// Forward flush call to the window</span>
<a name="l00521"></a>00521     [myWrapper flushBuffer];
<a name="l00522"></a>00522 }
<a name="l00523"></a>00523 
<a name="l00524"></a>00524 
<a name="l00528"></a>00528 <span class="keywordtype">void</span> WindowImplCocoa::ProcessEvents()
<a name="l00529"></a>00529 {
<a name="l00530"></a>00530     <span class="comment">// Forward event handling call to the application controller</span>
<a name="l00531"></a>00531     [SharedAppController processEvents];
<a name="l00532"></a>00532 }
<a name="l00533"></a>00533 
<a name="l00534"></a>00534 
<a name="l00538"></a>00538 <span class="keywordtype">void</span> WindowImplCocoa::SetActive(<span class="keywordtype">bool</span> Active)<span class="keyword"> const</span>
<a name="l00539"></a>00539 <span class="keyword"></span>{
<a name="l00540"></a>00540     <span class="comment">// Forward the call to the window</span>
<a name="l00541"></a>00541     [myWrapper setActive:Active];
<a name="l00542"></a>00542 }
<a name="l00543"></a>00543 
<a name="l00544"></a>00544 
<a name="l00548"></a>00548 <span class="keywordtype">void</span> WindowImplCocoa::UseVerticalSync(<span class="keywordtype">bool</span> Enabled)
<a name="l00549"></a>00549 {
<a name="l00550"></a>00550     <span class="comment">// Forward the call to the window</span>
<a name="l00551"></a>00551     [myWrapper enableVerticalSync:Enabled];
<a name="l00552"></a>00552 }
<a name="l00553"></a>00553 
<a name="l00554"></a>00554 
<a name="l00558"></a>00558 <span class="keywordtype">void</span> WindowImplCocoa::ShowMouseCursor(<span class="keywordtype">bool</span> flag)
<a name="l00559"></a>00559 {
<a name="l00560"></a>00560     <span class="keywordflow">if</span> (flag) {
<a name="l00561"></a>00561         [NSCursor unhide];
<a name="l00562"></a>00562     } <span class="keywordflow">else</span> {
<a name="l00563"></a>00563         [NSCursor hide];
<a name="l00564"></a>00564     }
<a name="l00565"></a>00565 }
<a name="l00566"></a>00566 
<a name="l00567"></a>00567 
<a name="l00571"></a>00571 <span class="keywordtype">void</span> WindowImplCocoa::SetCursorPosition(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Left, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Top)
<a name="l00572"></a>00572 {
<a name="l00573"></a>00573     NSPoint pos = NSMakePoint ((<span class="keywordtype">float</span>) Left, (<span class="keywordtype">float</span>) Top);
<a name="l00574"></a>00574     
<a name="l00575"></a>00575     <span class="keywordflow">if</span> (myWrapper) {
<a name="l00576"></a>00576         <span class="comment">// Flip for SFML window coordinate system</span>
<a name="l00577"></a>00577         pos.y = [[myWrapper window] frame].size.height - pos.y;
<a name="l00578"></a>00578         
<a name="l00579"></a>00579         <span class="comment">// Adjust for view reference instead of window</span>
<a name="l00580"></a>00580         pos.y -= [[myWrapper window] frame].size.height - [[myWrapper glView] frame].size.height;
<a name="l00581"></a>00581         
<a name="l00582"></a>00582         <span class="comment">// Convert to screen coordinates</span>
<a name="l00583"></a>00583         NSPoint absolute = [[myWrapper window] convertBaseToScreen:pos];
<a name="l00584"></a>00584         
<a name="l00585"></a>00585         <span class="comment">// Flip screen coodinates</span>
<a name="l00586"></a>00586         absolute.y = [[NSScreen mainScreen] frame].size.height - absolute.y;
<a name="l00587"></a>00587         
<a name="l00588"></a>00588         <span class="comment">// Move cursor</span>
<a name="l00589"></a>00589         CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, CGPointMake(absolute.x, absolute.y));
<a name="l00590"></a>00590     }
<a name="l00591"></a>00591 }
<a name="l00592"></a>00592 
<a name="l00593"></a>00593 
<a name="l00597"></a>00597 <span class="keywordtype">void</span> WindowImplCocoa::SetPosition(<span class="keywordtype">int</span> Left, <span class="keywordtype">int</span> Top)
<a name="l00598"></a>00598 {
<a name="l00599"></a>00599     [myWrapper setPosition:NSMakePoint(Left, Top)];
<a name="l00600"></a>00600 }
<a name="l00601"></a>00601 
<a name="l00602"></a>00602 
<a name="l00607"></a>00607 <span class="keywordtype">void</span> WindowImplCocoa::SetSize(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Width, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Height)
<a name="l00608"></a>00608 {
<a name="l00609"></a>00609     [myWrapper setSize:NSMakeSize(Width, Height)];
<a name="l00610"></a>00610 }
<a name="l00611"></a>00611 
<a name="l00612"></a>00612 
<a name="l00616"></a>00616 <span class="keywordtype">void</span> WindowImplCocoa::Show(<span class="keywordtype">bool</span> State)
<a name="l00617"></a>00617 {
<a name="l00618"></a>00618     [myWrapper show:State];
<a name="l00619"></a>00619 }
<a name="l00620"></a>00620 
<a name="l00621"></a>00621 
<a name="l00625"></a>00625 <span class="keywordtype">void</span> WindowImplCocoa::EnableKeyRepeat(<span class="keywordtype">bool</span> Enabled)
<a name="l00626"></a>00626 {
<a name="l00627"></a>00627     myUseKeyRepeat = Enabled;
<a name="l00628"></a>00628 }
<a name="l00629"></a>00629 
<a name="l00630"></a>00630 
<a name="l00634"></a>00634 <span class="keywordtype">void</span> WindowImplCocoa::SetIcon(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Width, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Height, <span class="keyword">const</span> Uint8* Pixels)
<a name="l00635"></a>00635 {
<a name="l00636"></a>00636     <span class="comment">// Nothing to do</span>
<a name="l00637"></a>00637 }
<a name="l00638"></a>00638 
<a name="l00639"></a>00639 
<a name="l00643"></a>00643 <span class="keyword">static</span> <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a> KeyForVirtualCode(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> vCode)
<a name="l00644"></a>00644 {
<a name="l00645"></a>00645     <span class="keyword">static</span> <span class="keyword">struct </span>{
<a name="l00646"></a>00646         <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> code;
<a name="l00647"></a>00647         <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a> sfKey;
<a name="l00648"></a>00648     } virtualTable[] =
<a name="l00649"></a>00649     {
<a name="l00650"></a>00650         {0x35, Key::Escape},
<a name="l00651"></a>00651         {0x31, Key::Space},
<a name="l00652"></a>00652         {0x24, Key::Return},    <span class="comment">// main Return key</span>
<a name="l00653"></a>00653         {0x4C, Key::Return},    <span class="comment">// pav Return key</span>
<a name="l00654"></a>00654         {0x33, Key::Back},
<a name="l00655"></a>00655         {0x30, Key::Tab},
<a name="l00656"></a>00656         {0x74, Key::PageUp},
<a name="l00657"></a>00657         {0x79, Key::PageDown},
<a name="l00658"></a>00658         {0x77, Key::End},
<a name="l00659"></a>00659         {0x73, Key::Home},
<a name="l00660"></a>00660         {0x72, Key::Insert},
<a name="l00661"></a>00661         {0x75, Key::Delete},
<a name="l00662"></a>00662         {0x45, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81c1a4bc755e274027f79cd34a6951977e" title="+">Key::Add</a>},
<a name="l00663"></a>00663         {0x4E, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c8161d59029edf2f17e0c562a674e2a1865" title="-">Key::Subtract</a>},
<a name="l00664"></a>00664         {0x43, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c810c2cf360fb1665c3387f205a001a6814" title="*">Key::Multiply</a>},
<a name="l00665"></a>00665         {0x4B, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81f0ef65e172118c443e123935e64269e2" title="/">Key::Divide</a>},
<a name="l00666"></a>00666         
<a name="l00667"></a>00667         {0x7A, Key::F1}, {0x78, Key::F2}, {0x63, Key::F3},
<a name="l00668"></a>00668         {0x76, Key::F4}, {0x60, Key::F5}, {0x61, Key::F6},
<a name="l00669"></a>00669         {0x62, Key::F7}, {0x64, Key::F8}, {0x65, Key::F9},
<a name="l00670"></a>00670         {0x6D, Key::F10}, {0x67, Key::F11}, {0x6F, Key::F12},
<a name="l00671"></a>00671         {0x69, Key::F13}, {0x6B, Key::F14}, {0x71, Key::F15},
<a name="l00672"></a>00672         
<a name="l00673"></a>00673         {0x7B, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c811b48e9fd546b2afdcbb64ae95047be94" title="Left arrow.">Key::Left</a>},
<a name="l00674"></a>00674         {0x7C, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c8132eb7e9964eda306d83efd2442991f8e" title="Right arrow.">Key::Right</a>},
<a name="l00675"></a>00675         {0x7E, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c8193a664cfe6ee856cf5027a01f03954ff" title="Up arrow.">Key::Up</a>},
<a name="l00676"></a>00676         {0x7D, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81db621980e92786cf06b6fb65d622bb62" title="Down arrow.">Key::Down</a>},
<a name="l00677"></a>00677         
<a name="l00678"></a>00678         {0x52, Key::Numpad0}, {0x53, Key::Numpad1}, {0x54, Key::Numpad2},
<a name="l00679"></a>00679         {0x55, Key::Numpad3}, {0x56, Key::Numpad4}, {0x57, Key::Numpad5},
<a name="l00680"></a>00680         {0x58, Key::Numpad6}, {0x59, Key::Numpad7}, {0x5B, Key::Numpad8},
<a name="l00681"></a>00681         {0x5C, Key::Numpad9},
<a name="l00682"></a>00682         
<a name="l00683"></a>00683         {0x1D, Key::Num0}, {0x12, Key::Num1}, {0x13, Key::Num2},
<a name="l00684"></a>00684         {0x14, Key::Num3}, {0x15, Key::Num4}, {0x17, Key::Num5},
<a name="l00685"></a>00685         {0x16, Key::Num6}, {0x1A, Key::Num7}, {0x1C, Key::Num8},
<a name="l00686"></a>00686         {0x19, Key::Num9},
<a name="l00687"></a>00687         
<a name="l00688"></a>00688         {0x3B, Key::LControl},  <span class="comment">//&lt; Left Ctrl</span>
<a name="l00689"></a>00689         {0x3A, Key::LAlt},      <span class="comment">//&lt; Left Option/Alt</span>
<a name="l00690"></a>00690         {0x37, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81819a5d0739e89a6543b8a1d3b2ed4bdb" title="OS specific key (left side) : windows (Win and Linux), apple (MacOS), ...">Key::LSystem</a>},   <span class="comment">//&lt; Left Command</span>
<a name="l00691"></a>00691         {0x38, Key::LShift},    <span class="comment">//&lt; Left Shift</span>
<a name="l00692"></a>00692         {0x3E, Key::RControl},  <span class="comment">//&lt; Right Ctrl</span>
<a name="l00693"></a>00693         {0x3D, Key::RAlt},      <span class="comment">//&lt; Right Option/Alt</span>
<a name="l00694"></a>00694         {0x36, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81461545de42376b666cb38860a0beec49" title="OS specific key (right side) : windows (Win and Linux), apple (MacOS), ...">Key::RSystem</a>},   <span class="comment">//&lt; Right Command</span>
<a name="l00695"></a>00695         {0x3C, Key::RShift},    <span class="comment">//&lt; Right Shift</span>
<a name="l00696"></a>00696         
<a name="l00697"></a>00697         {0x39, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}    <span class="comment">//&lt; Caps Lock (not handled by SFML for now)</span>
<a name="l00698"></a>00698     };
<a name="l00699"></a>00699     
<a name="l00700"></a>00700     <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a> result = <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0);
<a name="l00701"></a>00701     
<a name="l00702"></a>00702     <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0;virtualTable[i].code;i++) {
<a name="l00703"></a>00703         <span class="keywordflow">if</span> (virtualTable[i].code == vCode) {
<a name="l00704"></a>00704             result = virtualTable[i].sfKey;
<a name="l00705"></a>00705             <span class="keywordflow">break</span>;
<a name="l00706"></a>00706         }
<a name="l00707"></a>00707     }
<a name="l00708"></a>00708     
<a name="l00709"></a>00709     <span class="keywordflow">return</span> result;
<a name="l00710"></a>00710 }
<a name="l00711"></a>00711 
<a name="l00712"></a>00712 
<a name="l00716"></a>00716 <span class="keyword">static</span> <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a> KeyForUnicode(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> uniCode)
<a name="l00717"></a>00717 {
<a name="l00718"></a>00718     <span class="comment">// TODO: find a better way to get the language independant key</span>
<a name="l00719"></a>00719     <span class="keyword">static</span> <span class="keyword">struct </span>{
<a name="l00720"></a>00720         <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> character;
<a name="l00721"></a>00721         <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a> sfKey;
<a name="l00722"></a>00722     } unicodeTable[] =
<a name="l00723"></a>00723     {
<a name="l00724"></a>00724         {<span class="charliteral">'!'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00725"></a>00725         {<span class="charliteral">'"'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00726"></a>00726         {<span class="charliteral">'#'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00727"></a>00727         {<span class="charliteral">'$'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00728"></a>00728         {<span class="charliteral">'%'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00729"></a>00729         {<span class="charliteral">'&amp;'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00730"></a>00730         {<span class="charliteral">'\''</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81d8e07863826f31633566959e55fbd1b9" title="&amp;#39;">Key::Quote</a>},
<a name="l00731"></a>00731         {<span class="charliteral">'('</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00732"></a>00732         {<span class="charliteral">')'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00733"></a>00733         {<span class="charliteral">'*'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c810c2cf360fb1665c3387f205a001a6814" title="*">Key::Multiply</a>},
<a name="l00734"></a>00734         {<span class="charliteral">'+'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81c1a4bc755e274027f79cd34a6951977e" title="+">Key::Add</a>},
<a name="l00735"></a>00735         {<span class="charliteral">','</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81d7c3cca627323fa271fd141a0bfec207" title=",">Key::Comma</a>},
<a name="l00736"></a>00736         {<span class="charliteral">'-'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00737"></a>00737         {<span class="charliteral">'.'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c8150ec4d0d46359708e3337f7c5c9a00b8" title=".">Key::Period</a>},
<a name="l00738"></a>00738         {<span class="charliteral">'/'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00739"></a>00739         {<span class="charliteral">'0'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00740"></a>00740         {<span class="charliteral">'1'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00741"></a>00741         {<span class="charliteral">'2'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00742"></a>00742         {<span class="charliteral">'3'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00743"></a>00743         {<span class="charliteral">'4'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00744"></a>00744         {<span class="charliteral">'5'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00745"></a>00745         {<span class="charliteral">'6'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00746"></a>00746         {<span class="charliteral">'7'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00747"></a>00747         {<span class="charliteral">'8'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00748"></a>00748         {<span class="charliteral">'9'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; Handled by KeyForVirtualCode()</span>
<a name="l00749"></a>00749         {<span class="charliteral">':'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00750"></a>00750         {<span class="charliteral">';'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c819221b62140c199d7d4babe3ab45bdb01" title=";">Key::SemiColon</a>},
<a name="l00751"></a>00751         {<span class="charliteral">'&lt;'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00752"></a>00752         {<span class="charliteral">'='</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c815f4b9b3ede3db0e0a009ae02aaf81359" title="=">Key::Equal</a>},
<a name="l00753"></a>00753         {<span class="charliteral">'&gt;'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00754"></a>00754         {<span class="charliteral">'?'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00755"></a>00755         {<span class="charliteral">'@'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00756"></a>00756         {<span class="charliteral">'A'</span>, Key::A}, {<span class="charliteral">'B'</span>, Key::B}, {<span class="charliteral">'C'</span>, Key::C},
<a name="l00757"></a>00757         {<span class="charliteral">'D'</span>, Key::D}, {<span class="charliteral">'E'</span>, Key::E}, {<span class="charliteral">'F'</span>, Key::F},
<a name="l00758"></a>00758         {<span class="charliteral">'G'</span>, Key::G}, {<span class="charliteral">'H'</span>, Key::H}, {<span class="charliteral">'I'</span>, Key::I},
<a name="l00759"></a>00759         {<span class="charliteral">'J'</span>, Key::J}, {<span class="charliteral">'K'</span>, Key::K}, {<span class="charliteral">'L'</span>, Key::L},
<a name="l00760"></a>00760         {<span class="charliteral">'M'</span>, Key::M}, {<span class="charliteral">'N'</span>, Key::N}, {<span class="charliteral">'O'</span>, Key::O},
<a name="l00761"></a>00761         {<span class="charliteral">'P'</span>, Key::P}, {<span class="charliteral">'Q'</span>, Key::Q}, {<span class="charliteral">'R'</span>, Key::R},
<a name="l00762"></a>00762         {<span class="charliteral">'S'</span>, Key::S}, {<span class="charliteral">'T'</span>, Key::T}, {<span class="charliteral">'U'</span>, Key::U},
<a name="l00763"></a>00763         {<span class="charliteral">'V'</span>, Key::V}, {<span class="charliteral">'W'</span>, Key::W}, {<span class="charliteral">'X'</span>, Key::X},
<a name="l00764"></a>00764         {<span class="charliteral">'Y'</span>, Key::Y}, {<span class="charliteral">'Z'</span>, Key::Z},
<a name="l00765"></a>00765         {<span class="charliteral">'['</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c817c927ff513554092cbd16d275542ca93" title="[">Key::LBracket</a>},
<a name="l00766"></a>00766         {<span class="charliteral">'\\'</span>, Key::BackSlash},
<a name="l00767"></a>00767         {<span class="charliteral">']'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c819b950e8ca9b87c679c0dd34b978323a5" title="]">Key::RBracket</a>},
<a name="l00768"></a>00768         {<span class="charliteral">'^'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00769"></a>00769         {<span class="charliteral">'_'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00770"></a>00770         {<span class="charliteral">'`'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00771"></a>00771         {<span class="charliteral">'a'</span>, Key::A}, {<span class="charliteral">'b'</span>, Key::B}, {<span class="charliteral">'c'</span>, Key::C},
<a name="l00772"></a>00772         {<span class="charliteral">'d'</span>, Key::D}, {<span class="charliteral">'e'</span>, Key::E}, {<span class="charliteral">'f'</span>, Key::F},
<a name="l00773"></a>00773         {<span class="charliteral">'g'</span>, Key::G}, {<span class="charliteral">'h'</span>, Key::H}, {<span class="charliteral">'i'</span>, Key::I},
<a name="l00774"></a>00774         {<span class="charliteral">'j'</span>, Key::J}, {<span class="charliteral">'k'</span>, Key::K}, {<span class="charliteral">'l'</span>, Key::L},
<a name="l00775"></a>00775         {<span class="charliteral">'m'</span>, Key::M}, {<span class="charliteral">'n'</span>, Key::N}, {<span class="charliteral">'o'</span>, Key::O},
<a name="l00776"></a>00776         {<span class="charliteral">'p'</span>, Key::P}, {<span class="charliteral">'q'</span>, Key::Q}, {<span class="charliteral">'r'</span>, Key::R},
<a name="l00777"></a>00777         {<span class="charliteral">'s'</span>, Key::S}, {<span class="charliteral">'t'</span>, Key::T}, {<span class="charliteral">'u'</span>, Key::U},
<a name="l00778"></a>00778         {<span class="charliteral">'v'</span>, Key::V}, {<span class="charliteral">'w'</span>, Key::W}, {<span class="charliteral">'x'</span>, Key::X},
<a name="l00779"></a>00779         {<span class="charliteral">'y'</span>, Key::Y}, {<span class="charliteral">'z'</span>, Key::Z},
<a name="l00780"></a>00780         {<span class="charliteral">'{'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00781"></a>00781         {<span class="charliteral">'|'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00782"></a>00782         {<span class="charliteral">'}'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}, <span class="comment">//&lt; No Key for this code</span>
<a name="l00783"></a>00783         {<span class="charliteral">'~'</span>, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81e1e8ba49e9a03ae9db79d671372baf67" title="~">Key::Tilde</a>},
<a name="l00784"></a>00784         {0, <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0)}
<a name="l00785"></a>00785     };
<a name="l00786"></a>00786     
<a name="l00787"></a>00787     <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a> result = <a class="code" href="namespacesf_1_1Key.htm#d32ed01d3448273340bd25af5cdd9c81">Key::Code</a>(0);
<a name="l00788"></a>00788     
<a name="l00789"></a>00789     <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0;unicodeTable[i].character;i++) {
<a name="l00790"></a>00790         <span class="keywordflow">if</span> (unicodeTable[i].character == uniCode) {
<a name="l00791"></a>00791             result = unicodeTable[i].sfKey;
<a name="l00792"></a>00792             <span class="keywordflow">break</span>;
<a name="l00793"></a>00793         }
<a name="l00794"></a>00794     }
<a name="l00795"></a>00795     
<a name="l00796"></a>00796     <span class="keywordflow">return</span> result;
<a name="l00797"></a>00797 }
<a name="l00798"></a>00798 
<a name="l00799"></a>00799 
<a name="l00803"></a>00803 <span class="keyword">static</span> <span class="keywordtype">bool</span> IsTextEvent(NSEvent *event)
<a name="l00804"></a>00804 {
<a name="l00805"></a>00805     <span class="keywordtype">bool</span> res = <span class="keyword">false</span>;
<a name="l00806"></a>00806     
<a name="l00807"></a>00807     <span class="keywordflow">if</span> (event &amp;&amp; [event type] == NSKeyDown &amp;&amp; [[event characters] length]) {
<a name="l00808"></a>00808         unichar code = [[event characters] characterAtIndex:0];
<a name="l00809"></a>00809         
<a name="l00810"></a>00810         <span class="comment">// Codes from 0xF700 to 0xF8FF are non text keys (see NSEvent.h)</span>
<a name="l00811"></a>00811         <span class="keywordflow">if</span> (code &lt; 0xF700 || code &gt; 0xF8FF)
<a name="l00812"></a>00812             res = <span class="keyword">true</span>;
<a name="l00813"></a>00813     }
<a name="l00814"></a>00814     
<a name="l00815"></a>00815     <span class="keywordflow">return</span> res;
<a name="l00816"></a>00816 }
<a name="l00817"></a>00817 
<a name="l00818"></a>00818 
<a name="l00819"></a>00819 } <span class="comment">// namespace priv</span>
<a name="l00820"></a>00820 
<a name="l00821"></a>00821 } <span class="comment">// namespace sf</span>
<a name="l00822"></a>00822 
</pre></div></div>

        <p id="footer">
            &nbsp;::&nbsp; Copyright &copy; 2007-2008 Laurent Gomila, all rights reserved &nbsp;::&nbsp;
            Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen 1.5.2</a> &nbsp;::&nbsp;
        </p>

    </body>
</html>