2
0
Эх сурвалжийг харах

Examples: DirectX examples uses WM_KEYDOWN/WM_KEYUP

Fixes pressing Enter in IME being caught by application right after
validating an IME input.
ocornut 10 жил өмнө
parent
commit
be9fe9489c

+ 14 - 10
examples/directx11_example/main.cpp

@@ -358,6 +358,14 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
         io.MousePos.x = (signed short)(lParam);
         io.MousePos.x = (signed short)(lParam);
         io.MousePos.y = (signed short)(lParam >> 16); 
         io.MousePos.y = (signed short)(lParam >> 16); 
         return true;
         return true;
+    case WM_KEYDOWN:
+        if (wParam >= 0 && wParam < 256)
+            io.KeysDown[wParam] = 1;
+        return true;
+    case WM_KEYUP:
+        if (wParam >= 0 && wParam < 256)
+            io.KeysDown[wParam] = 0;
+        return true;
     case WM_CHAR:
     case WM_CHAR:
         // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
         // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
         if (wParam > 0 && wParam < 0x10000)
         if (wParam > 0 && wParam < 0x10000)
@@ -379,7 +387,7 @@ void LoadFontsTexture()
     //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
     //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
     //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
     //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
     //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
     //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
-    //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 20.0f, io.Fonts->GetGlyphRangesJapanese());
+    //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
 
 
     // Build
     // Build
     unsigned char* pixels;
     unsigned char* pixels;
@@ -500,15 +508,11 @@ void UpdateImGui()
     io.DeltaTime = (float)(current_time - last_time) / ticks_per_second;
     io.DeltaTime = (float)(current_time - last_time) / ticks_per_second;
     last_time = current_time;
     last_time = current_time;
 
 
-    // Setup inputs
-    // (we already got mouse position, buttons, wheel from the window message callback)
-    BYTE keystate[256];
-    GetKeyboardState(keystate);
-    for (int i = 0; i < 256; i++)
-        io.KeysDown[i] = (keystate[i] & 0x80) != 0;
-    io.KeyCtrl = (keystate[VK_CONTROL] & 0x80) != 0;
-    io.KeyShift = (keystate[VK_SHIFT] & 0x80) != 0;
-    // io.MousePos : filled by WM_MOUSEMOVE event
+    // Read keyboard modifiers inputs
+    io.KeyCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
+    io.KeyShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
+    // io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events
+    // io.MousePos : filled by WM_MOUSEMOVE events
     // io.MouseDown : filled by WM_*BUTTON* events
     // io.MouseDown : filled by WM_*BUTTON* events
     // io.MouseWheel : filled by WM_MOUSEWHEEL events
     // io.MouseWheel : filled by WM_MOUSEWHEEL events
 
 

+ 14 - 10
examples/directx9_example/main.cpp

@@ -160,6 +160,14 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
         io.MousePos.x = (signed short)(lParam);
         io.MousePos.x = (signed short)(lParam);
         io.MousePos.y = (signed short)(lParam >> 16); 
         io.MousePos.y = (signed short)(lParam >> 16); 
         return true;
         return true;
+    case WM_KEYDOWN:
+        if (wParam >= 0 && wParam < 256)
+            io.KeysDown[wParam] = 1;
+        return true;
+    case WM_KEYUP:
+        if (wParam >= 0 && wParam < 256)
+            io.KeysDown[wParam] = 0;
+        return true;
     case WM_CHAR:
     case WM_CHAR:
         // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
         // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
         if (wParam > 0 && wParam < 0x10000)
         if (wParam > 0 && wParam < 0x10000)
@@ -181,7 +189,7 @@ void LoadFontsTexture()
     //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
     //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
     //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
     //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
     //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
     //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
-    //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 20.0f, io.Fonts->GetGlyphRangesJapanese());
+    //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
 
 
     // Build
     // Build
     unsigned char* pixels;
     unsigned char* pixels;
@@ -265,15 +273,11 @@ void UpdateImGui()
     io.DeltaTime = (float)(current_time - last_time) / ticks_per_second;
     io.DeltaTime = (float)(current_time - last_time) / ticks_per_second;
     last_time = current_time;
     last_time = current_time;
 
 
-    // Setup inputs
-    // (we already got mouse position, buttons, wheel from the window message callback)
-    BYTE keystate[256];
-    GetKeyboardState(keystate);
-    for (int i = 0; i < 256; i++)
-        io.KeysDown[i] = (keystate[i] & 0x80) != 0;
-    io.KeyCtrl = (keystate[VK_CONTROL] & 0x80) != 0;
-    io.KeyShift = (keystate[VK_SHIFT] & 0x80) != 0;
-    // io.MousePos : filled by WM_MOUSEMOVE event
+    // Read keyboard modifiers inputs
+    io.KeyCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
+    io.KeyShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
+    // io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events
+    // io.MousePos : filled by WM_MOUSEMOVE events
     // io.MouseDown : filled by WM_*BUTTON* events
     // io.MouseDown : filled by WM_*BUTTON* events
     // io.MouseWheel : filled by WM_MOUSEWHEEL events
     // io.MouseWheel : filled by WM_MOUSEWHEEL events
 
 

+ 1 - 1
examples/opengl3_example/main.cpp

@@ -244,7 +244,7 @@ void LoadFontsTexture()
     //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
     //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
     //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
     //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
     //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
     //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
-    //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 20.0f, io.Fonts->GetGlyphRangesJapanese());
+    //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
 
 
     unsigned char* pixels;
     unsigned char* pixels;
     int width, height;
     int width, height;

+ 1 - 1
examples/opengl_example/main.cpp

@@ -155,7 +155,7 @@ void LoadFontsTexture()
     //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
     //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
     //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
     //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
     //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
     //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
-    //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 20.0f, io.Fonts->GetGlyphRangesJapanese());
+    //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
 
 
     unsigned char* pixels;
     unsigned char* pixels;
     int width, height;
     int width, height;

+ 1 - 1
imgui.cpp

@@ -3289,7 +3289,7 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
     ImGuiState& g = *GImGui;
     ImGuiState& g = *GImGui;
 
 
     ImVec2* pvar = GetStyleVarVec2Addr(idx);
     ImVec2* pvar = GetStyleVarVec2Addr(idx);
-    IM_ASSERT(pvar != NULL); // Called function with wrong-type? Varialble is not a ImVec2.
+    IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a ImVec2.
     ImGuiStyleMod backup;
     ImGuiStyleMod backup;
     backup.Var = idx;
     backup.Var = idx;
     backup.PreviousValue = *pvar;
     backup.PreviousValue = *pvar;