SDL example: tweaks (#233 #226)

docking
ocornut 9 years ago
parent 19e3c1506f
commit 1845ff4690

@ -95,39 +95,39 @@ static void ImGui_ImplSdl_SetClipboardText(const char* text)
SDL_SetClipboardText(text); SDL_SetClipboardText(text);
} }
bool ImGui_ImplSdl_EventCallback(const SDL_Event& event) bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
switch (event.type) switch (event->type)
{ {
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
{ {
if (event.wheel.y > 0) if (event->wheel.y > 0)
g_MouseWheel = 1; g_MouseWheel = 1;
if (event.wheel.y < 0) if (event->wheel.y < 0)
g_MouseWheel = -1; g_MouseWheel = -1;
return true; return true;
} }
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
{ {
if (event.button.button == SDL_BUTTON_LEFT) g_MousePressed[0] = true; if (event->button.button == SDL_BUTTON_LEFT) g_MousePressed[0] = true;
if (event.button.button == SDL_BUTTON_RIGHT) g_MousePressed[1] = true; if (event->button.button == SDL_BUTTON_RIGHT) g_MousePressed[1] = true;
if (event.button.button == SDL_BUTTON_MIDDLE) g_MousePressed[2] = true; if (event->button.button == SDL_BUTTON_MIDDLE) g_MousePressed[2] = true;
return true; return true;
} }
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
unsigned int c = event.text.text[0]; unsigned int c = event->text.text[0];
if (c > 0 && c < 0x10000) if (c > 0 && c < 0x10000)
io.AddInputCharacter((unsigned short)event.text.text[0]); io.AddInputCharacter((unsigned short)c);
return true; return true;
} }
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: case SDL_KEYUP:
{ {
int key = event.key.keysym.sym & ~SDLK_SCANCODE_MASK; int key = event->key.keysym.sym & ~SDLK_SCANCODE_MASK;
io.KeysDown[key] = (event.type == SDL_KEYDOWN); io.KeysDown[key] = (event->type == SDL_KEYDOWN);
io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0); io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0); io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0); io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);

@ -7,7 +7,7 @@ typedef union SDL_Event SDL_Event;
bool ImGui_ImplSdl_Init(SDL_Window *window); bool ImGui_ImplSdl_Init(SDL_Window *window);
void ImGui_ImplSdl_Shutdown(); void ImGui_ImplSdl_Shutdown();
void ImGui_ImplSdl_NewFrame(SDL_Window *window); void ImGui_ImplSdl_NewFrame(SDL_Window *window);
bool ImGui_ImplSdl_EventCallback(const SDL_Event& event); bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event);
// Use if you want to reset your rendering device without losing ImGui state. // Use if you want to reset your rendering device without losing ImGui state.
void ImGui_ImplSdl_InvalidateDeviceObjects(); void ImGui_ImplSdl_InvalidateDeviceObjects();

@ -44,7 +44,7 @@ int SDL_main(int, char**)
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
ImGui_ImplSdl_EventCallback(event); ImGui_ImplSdl_ProcessEvent(&event);
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
done = true; done = true;
} }

Loading…
Cancel
Save