diff --git a/.gitignore b/.gitignore index c244c0e0..e9e19297 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ Version.txt Source/OpenTK/OpenTK.xml Source/GLControl/OpenTK.GLControl.xml Documentation/Source +opentk*.exe +opentk*.zip # OpenTK Resource files that seem like they should be ignored: Source/Compatibility/Properties/Resources.resources diff --git a/Installers/Nsis/Build.Installer.Nsis.csproj b/Installers/Nsis/Build.Installer.Nsis.csproj index d9d6b979..f58e10eb 100644 --- a/Installers/Nsis/Build.Installer.Nsis.csproj +++ b/Installers/Nsis/Build.Installer.Nsis.csproj @@ -52,7 +52,7 @@ - + diff --git a/Installers/Nsis/opentk.nsi b/Installers/Nsis/opentk.nsi index f79fe406..299afe6f 100644 --- a/Installers/Nsis/opentk.nsi +++ b/Installers/Nsis/opentk.nsi @@ -10,9 +10,7 @@ SetCompressor /SOLID lzma ; HM NIS Edit Wizard helper defines !define PRODUCT_NAME "OpenTK" -!define PRODUCT_VERSION "1.0" ; To be replaced by Build.exe -;!define PRODUCT_VERSION_REVISION "{{revision}}" ; To be replaced by Build.exe -;!define PRODUCT_VERSION_EXTRA "{{extra}}" ; To be replaced by Build.exe +!define PRODUCT_VERSION "1.1" ; To be replaced by Build.exe !define PRODUCT_PUBLISHER "The Open Toolkit team" !define PRODUCT_WEB_SITE "http://www.opentk.com" !define PRODUCT_UNINST_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" @@ -177,40 +175,16 @@ Section "Source code" SEC02 File /r /x .svn /x obj /x opentk /x opentk-actual.* /x *.exe /x *.msi /x *.deb /x *.rpm /x *.zip ..\..\Installers SectionEnd -Section "OpenAL drivers" SEC03 - SetOutPath $INSTDIR\Installers\Dependencies - NSISdl::download /TIMEOUT=5000 http://www.opentk.net/files/dependencies/win32/oalinst.exe oalinst.exe - NSISdl::download /TIMEOUT=5000 http://www.opentk.net/files/dependencies/win32/oalinst-license.txt oalinst-license.txt - ExecShell "open" '"$INSTDIR\Installers\Dependencies\oalinst.exe"' /S -SectionEnd - -Section "NShader plugin (VS2010)" SEC04 - SetOutPath $INSTDIR\Installers\Dependencies - NSISdl::download /TIMEOUT=5000 http://www.opentk.net/files/dependencies/win32/NShaderVS2010.vsix NShaderVS2010.vsix - NSISdl::download /TIMEOUT=5000 http://www.opentk.net/files/dependencies/win32/nshader-license.txt nshader-license.txt - ExecShell "open" '"$INSTDIR\Installers\Dependencies\NShaderVS2010.vsix"' -SectionEnd - -Section "NShader plugin (VS2008)" SEC05 - SetOutPath $INSTDIR\Installers\Dependencies - NSISdl::download /TIMEOUT=5000 http://www.opentk.net/files/dependencies/win32/NShaderVS2008.msi NShaderVS2008.msi - NSISdl::download /TIMEOUT=5000 http://www.opentk.net/files/dependencies/win32/nshader-license.txt nshader-license.txt - ExecShell "open" '"$INSTDIR\Installers\Dependencies\NShaderVS2008.msi"' -SectionEnd - Section -AdditionalIcons SetOutPath $INSTDIR - WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}" CreateDirectory "$SMPROGRAMS\OpenTK" SetOutPath "$INSTDIR\Binaries\OpenTK\Release" ; Make sure the working directory is correct CreateShortCut "$SMPROGRAMS\OpenTK\OpenTK Example Browser.lnk" "$INSTDIR\Binaries\OpenTK\Release\Examples.exe" SetOutPath $INSTDIR - CreateShortCut "$SMPROGRAMS\OpenTK\Function Reference (PDF).lnk" "$INSTDIR\Documentation\Reference.pdf" - CreateShortCut "$SMPROGRAMS\OpenTK\Project Manual (PDF).lnk" "$INSTDIR\Documentation\Manual.pdf" - ;CreateShortCut "$SMPROGRAMS\OpenTK\Release Notes.lnk" "$INSTDIR\Documentation\Release.txt" - ;CreateShortCut "$SMPROGRAMS\OpenTK\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url" + CreateShortCut "$SMPROGRAMS\OpenTK\OpenGL Reference.lnk" "$INSTDIR\Documentation\OpenGL 4.4 API Reference.pdf" + CreateShortCut "$SMPROGRAMS\OpenTK\Documentation.lnk" "$INSTDIR\Documentation\" SectionEnd Section -Post @@ -229,16 +203,10 @@ SectionEnd LangString DESC_Section1 ${LANG_ENGLISH} "Installs the Open Toolkit library, documentation and samples." LangString DESC_Section2 ${LANG_ENGLISH} "Installs the source code for the Open Toolkit library." -LangString DESC_Section3 ${LANG_ENGLISH} "Installs OpenAL sound drivers from Creative Inc. Required for OpenAL support." -LangString DESC_Section4 ${LANG_ENGLISH} "Adds support for GLSL syntax highlighting to Visual Studio 2010. Requires Professional edition or higher." -LangString DESC_Section5 ${LANG_ENGLISH} "Adds support for GLSL syntax highlighting to Visual Studio 2008. Requires Professional edition or higher." !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SEC01} $(DESC_Section1) !insertmacro MUI_DESCRIPTION_TEXT ${SEC02} $(DESC_Section2) - !insertmacro MUI_DESCRIPTION_TEXT ${SEC03} $(DESC_Section3) - !insertmacro MUI_DESCRIPTION_TEXT ${SEC04} $(DESC_Section4) - !insertmacro MUI_DESCRIPTION_TEXT ${SEC05} $(DESC_Section5) !insertmacro MUI_FUNCTION_DESCRIPTION_END Function un.onUninstSuccess diff --git a/Installers/Zip/Build.Installer.Zip.csproj b/Installers/Zip/Build.Installer.Zip.csproj index 6bf48a26..79c8a9c4 100644 --- a/Installers/Zip/Build.Installer.Zip.csproj +++ b/Installers/Zip/Build.Installer.Zip.csproj @@ -15,7 +15,6 @@ {ADC34399-7613-44D2-90B2-19250F06FE7B} v2.0 - ..\..\ .\opentk\ Debug AnyCPU @@ -50,12 +49,12 @@ - + - + diff --git a/Source/Examples/OpenTK/Test/GameWindowStates.cs b/Source/Examples/OpenTK/Test/GameWindowStates.cs index 6977de2a..73d81002 100644 --- a/Source/Examples/OpenTK/Test/GameWindowStates.cs +++ b/Source/Examples/OpenTK/Test/GameWindowStates.cs @@ -21,6 +21,7 @@ namespace Examples.Tests { static readonly Font TextFont = new Font(FontFamily.GenericSansSerif, 11); Bitmap TextBitmap = new Bitmap(1024, 1024); + StringBuilder TypedText = new StringBuilder(); int texture; bool mouse_in_window = false; bool viewport_changed = true; @@ -33,7 +34,8 @@ namespace Examples.Tests { VSync = VSyncMode.On; Keyboard.KeyRepeat = true; - Keyboard.KeyDown += KeyDownHandler; + KeyDown += KeyDownHandler; + KeyPress += KeyPressHandler; MouseEnter += delegate { mouse_in_window = true; }; MouseLeave += delegate { mouse_in_window = false; }; @@ -54,6 +56,14 @@ namespace Examples.Tests } } + private void KeyPressHandler(object sender, KeyPressEventArgs e) + { + if (TypedText.Length > 32) + TypedText.Remove(0, 1); + + TypedText.Append(e.KeyChar); + } + void KeyDownHandler(object sender, KeyboardKeyEventArgs e) { switch (e.Key) @@ -222,10 +232,10 @@ namespace Examples.Tests DrawString(gfx, String.Format("Window.Location: {0}, Size: {1}", Location, Size), line++); DrawString(gfx, String.Format("Window: {{X={0},Y={1},Width={2},Height={3}}}", X, Y, Width, Height), line++); DrawString(gfx, String.Format("Window.ClientRectangle: {0}", ClientRectangle), line++); + DrawString(gfx, TypedText.ToString(), line++); DrawKeyboard(gfx, keyboard, line++); DrawMouse(gfx, mouse, line++); DrawJoysticks(gfx, Joysticks, line++); - } } diff --git a/Source/GLControl/GLControl.cs b/Source/GLControl/GLControl.cs index b648a5e6..bafed945 100644 --- a/Source/GLControl/GLControl.cs +++ b/Source/GLControl/GLControl.cs @@ -165,15 +165,12 @@ namespace OpenTK const int CS_VREDRAW = 0x1; const int CS_HREDRAW = 0x2; const int CS_OWNDC = 0x20; - const int WS_CLIPCHILDREN = 0x02000000; - const int WS_CLIPSIBLINGS = 0x04000000; CreateParams cp = base.CreateParams; if (Configuration.RunningOnWindows) { // Setup necessary class style for OpenGL on windows cp.ClassStyle |= CS_VREDRAW | CS_HREDRAW | CS_OWNDC; - cp.Style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS; } return cp; } diff --git a/Source/OpenTK/NativeWindow.cs b/Source/OpenTK/NativeWindow.cs index 66dcbba7..28c51019 100644 --- a/Source/OpenTK/NativeWindow.cs +++ b/Source/OpenTK/NativeWindow.cs @@ -999,12 +999,24 @@ namespace OpenTK #endregion + #region OnKeyDownInternal + + private void OnKeyDownInternal(object sender, KeyboardKeyEventArgs e) { OnKeyDown(e); } + + #endregion + #region OnKeyPressInternal private void OnKeyPressInternal(object sender, KeyPressEventArgs e) { OnKeyPress(e); } #endregion + #region OnKeyUpInternal + + private void OnKeyUpInternal(object sender, KeyboardKeyEventArgs e) { OnKeyUp(e); } + + #endregion + #region OnMouseEnterInternal private void OnMouseEnterInternal(object sender, EventArgs e) { OnMouseEnter(e); } @@ -1074,7 +1086,9 @@ namespace OpenTK implementation.Disposed += OnDisposedInternal; implementation.FocusedChanged += OnFocusedChangedInternal; implementation.IconChanged += OnIconChangedInternal; + implementation.KeyDown += OnKeyDownInternal; implementation.KeyPress += OnKeyPressInternal; + implementation.KeyUp += OnKeyUpInternal; implementation.MouseEnter += OnMouseEnterInternal; implementation.MouseLeave += OnMouseLeaveInternal; implementation.Move += OnMoveInternal; @@ -1092,7 +1106,9 @@ namespace OpenTK implementation.Disposed -= OnDisposedInternal; implementation.FocusedChanged -= OnFocusedChangedInternal; implementation.IconChanged -= OnIconChangedInternal; + implementation.KeyDown -= OnKeyDownInternal; implementation.KeyPress -= OnKeyPressInternal; + implementation.KeyUp -= OnKeyUpInternal; implementation.MouseEnter -= OnMouseEnterInternal; implementation.MouseLeave -= OnMouseLeaveInternal; implementation.Move -= OnMoveInternal; diff --git a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs index 2970183b..204d482f 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs @@ -37,6 +37,7 @@ using System.Drawing.Imaging; using System.Runtime.InteropServices; using OpenTK; using OpenTK.Input; +using System.Text; namespace OpenTK.Platform.SDL2 { @@ -78,7 +79,10 @@ namespace OpenTK.Platform.SDL2 flags |= WindowFlags.OPENGL; flags |= WindowFlags.RESIZABLE; flags |= WindowFlags.HIDDEN; - flags |= WindowFlags.ALLOW_HIGHDPI; + if (Toolkit.Options.EnableHighResolution) + { + flags |= WindowFlags.ALLOW_HIGHDPI; + } if ((flags & WindowFlags.FULLSCREEN_DESKTOP) != 0 || (flags & WindowFlags.FULLSCREEN) != 0) @@ -150,6 +154,14 @@ namespace OpenTK.Platform.SDL2 } break; + case EventType.TEXTINPUT: + if (windows.TryGetValue(ev.Text.WindowID, out window)) + { + ProcessTextInputEvent(window, ev.Text); + processed = true; + } + break; + case EventType.KEYDOWN: case EventType.KEYUP: if (windows.TryGetValue(ev.Key.WindowID, out window)) @@ -214,9 +226,42 @@ namespace OpenTK.Platform.SDL2 { bool key_pressed = ev.Key.State == State.Pressed; var key = ev.Key.Keysym; + var args = new KeyboardKeyEventArgs() + { + Key = TranslateKey(key.Scancode), + ScanCode = (uint)key.Scancode + }; + if (key_pressed) + window.KeyDown(window, args); + else + window.KeyUp(window, args); //window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed); } + static unsafe void ProcessTextInputEvent(Sdl2NativeWindow window, TextInputEvent ev) + { + var keyPress = window.KeyPress; + if (keyPress != null) + { + var length = 0; + byte* pText = ev.Text; + while (*pText != 0) + { + length++; + pText++; + } + using (var stream = new System.IO.UnmanagedMemoryStream(ev.Text, length)) + using (var reader = new System.IO.StreamReader(stream, Encoding.UTF8)) + { + var text = reader.ReadToEnd(); + foreach (var c in text) + { + keyPress(window, new KeyPressEventArgs(c)); + } + } + } + } + static void ProcessMotionEvent(Sdl2NativeWindow window, Event ev) { float scale = window.ClientSize.Width / (float)window.Size.Width; diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs index 4210342d..b9107d7a 100644 --- a/Source/OpenTK/Platform/Windows/API.cs +++ b/Source/OpenTK/Platform/Windows/API.cs @@ -1623,6 +1623,7 @@ namespace OpenTK.Platform.Windows internal const byte PFD_UNDERLAY_PLANE = unchecked((byte)-1); // Device mode types (found in wingdi.h) + internal const int DM_LOGPIXELS = 0x00020000; internal const int DM_BITSPERPEL = 0x00040000; internal const int DM_PELSWIDTH = 0x00080000; internal const int DM_PELSHEIGHT = 0x00100000; diff --git a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs index a42b16d1..2ff578f7 100644 --- a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs +++ b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs @@ -124,10 +124,12 @@ namespace OpenTK.Platform.Windows { VerifyMode(dev1, monitor_mode); + float scale = GetScale(ref monitor_mode); opentk_dev_current_res = new DisplayResolution( - monitor_mode.Position.X, monitor_mode.Position.Y, - monitor_mode.PelsWidth, monitor_mode.PelsHeight, + (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale), + (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale), monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency); + opentk_dev_primary = (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None; } @@ -138,9 +140,10 @@ namespace OpenTK.Platform.Windows { VerifyMode(dev1, monitor_mode); + float scale = GetScale(ref monitor_mode); DisplayResolution res = new DisplayResolution( - monitor_mode.Position.X, monitor_mode.Position.Y, - monitor_mode.PelsWidth, monitor_mode.PelsHeight, + (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale), + (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale), monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency); opentk_dev_available_res.Add(res); @@ -167,6 +170,15 @@ namespace OpenTK.Platform.Windows } } + private float GetScale(ref DeviceMode monitor_mode) + { + float scale = 1.0f; + if ((monitor_mode.Fields & Constants.DM_LOGPIXELS) != 0) + { + scale = monitor_mode.LogPixels / 96.0f; + } + return scale; + } static void VerifyMode(WindowsDisplayDevice device, DeviceMode mode) { diff --git a/Source/OpenTK/Platform/Windows/WinFactory.cs b/Source/OpenTK/Platform/Windows/WinFactory.cs index 74f27038..b0fc8224 100644 --- a/Source/OpenTK/Platform/Windows/WinFactory.cs +++ b/Source/OpenTK/Platform/Windows/WinFactory.cs @@ -50,10 +50,13 @@ namespace OpenTK.Platform.Windows if (System.Environment.OSVersion.Version.Major >= 6) { - // Enable high-dpi support - // Only available on Windows Vista and higher - bool result = Functions.SetProcessDPIAware(); - Debug.Print("SetProcessDPIAware() returned {0}", result); + if (Toolkit.Options.EnableHighResolution) + { + // Enable high-dpi support + // Only available on Windows Vista and higher + bool result = Functions.SetProcessDPIAware(); + Debug.Print("SetProcessDPIAware() returned {0}", result); + } } } diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index b17470ee..da59889f 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -124,23 +124,24 @@ namespace OpenTK.Platform.Windows // Move(this, EventArgs.Empty); //}; - // CreateWindow takes values in pixels. - // According to the high-dpi guidelines, - // we need to scale these values by the - // current DPI. - // Search MSDN for "How to Ensure That - // Your Application Displays Properly on - // High-DPI Displays" - int scale_width = ScaleX(width); - int scale_height = ScaleY(height); + int scale_width = width; + int scale_height = height; int scale_x = x; int scale_y = y; - // If width or height were scaled, re-calculate - // the x and y coordinates to compensate - if (width != scale_width) - scale_x = x - UnscaleX(scale_width - width); - if (height != scale_height) - scale_y = y - UnscaleY(scale_height - height); + if (Toolkit.Options.EnableHighResolution) + { + // CreateWindow takes values in pixels. + // According to the high-dpi guidelines, + // we need to scale these values by the + // current DPI. + // Search MSDN for "How to Ensure That + // Your Application Displays Properly on + // High-DPI Displays" + scale_width = ScaleX(width); + scale_height = ScaleY(height); + scale_x = ScaleX(x); + scale_y = ScaleY(y); + } // To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be // bound to the top-level window, but rather to a child window docked in the parent. diff --git a/Source/OpenTK/Toolkit.cs b/Source/OpenTK/Toolkit.cs index 5c1c476c..88665b09 100644 --- a/Source/OpenTK/Toolkit.cs +++ b/Source/OpenTK/Toolkit.cs @@ -134,6 +134,7 @@ namespace OpenTK { initialized = true; Configuration.Init(options); + Options = options; // The actual initialization takes place in the // platform-specific factory constructors. @@ -145,6 +146,12 @@ namespace OpenTK #endregion + #region Internal Members + + internal static ToolkitOptions Options { get; private set; } + + #endregion + #region IDisposable Members /// diff --git a/Source/OpenTK/ToolkitOptions.cs b/Source/OpenTK/ToolkitOptions.cs index 957f4758..91a16a9a 100644 --- a/Source/OpenTK/ToolkitOptions.cs +++ b/Source/OpenTK/ToolkitOptions.cs @@ -68,6 +68,7 @@ namespace OpenTK static ToolkitOptions() { Default = new ToolkitOptions(); + Default.EnableHighResolution = true; } /// @@ -76,6 +77,16 @@ namespace OpenTK /// public PlatformBackend Backend { get; set; } + /// + /// Gets or sets a value indicating whether high + /// resolution modes are supported on high-DPI + /// ("Retina") displays. Enabled by default. + /// Set to false for applications that are not + /// DPI-aware (e.g. WinForms.) + /// + /// + public bool EnableHighResolution { get; set; } + /// /// Gets a ToolkitOptions instance with /// default values.