mirror of
https://github.com/joel16/VITA-Homebrew-Sorter.git
synced 2024-11-26 21:00:27 +00:00
imGui: Add full gamepad support using io.AddKeyEvent() and fix includes
This commit is contained in:
parent
8bdd30672a
commit
28cfa5a63c
@ -1,5 +1,24 @@
|
||||
// dear imgui: Renderer Backend for OpenGL2 (legacy OpenGL, fixed pipeline)
|
||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||
|
||||
// Implemented features:
|
||||
// [X] User texture binding. Cast 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
|
||||
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||
|
||||
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
|
||||
// **Prefer using the code in imgui_impl_opengl3.cpp**
|
||||
// This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read.
|
||||
// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more
|
||||
// complicated, will require your code to reset every single OpenGL attributes to their initial state, and might
|
||||
// confuse your GPU driver.
|
||||
// The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API.
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
|
||||
IMGUI_API bool ImGui_ImplVitaGL_Init(void);
|
||||
IMGUI_API void ImGui_ImplVitaGL_Shutdown(void);
|
||||
|
@ -1,6 +0,0 @@
|
||||
#ifndef _IMGUI_VITA_
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_vitagl.h"
|
||||
|
||||
#endif
|
@ -1,12 +1,12 @@
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <imgui_vita.h>
|
||||
#include <psp2/power.h>
|
||||
#include <psp2/kernel/clib.h>
|
||||
#include <vitaGL.h>
|
||||
|
||||
#include "applist.h"
|
||||
#include "fs.h"
|
||||
#include "imgui_impl_vitagl.h"
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include "imgui_internal.h"
|
||||
#include "loadouts.h"
|
||||
|
@ -56,38 +56,41 @@ void ImGui_ImplVitaGL_Shutdown(void) {
|
||||
|
||||
static void ImGui_ImplVitaGL_UpdateGamepads(void) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
sceClibMemset(io.NavInputs, 0, sizeof(io.NavInputs));
|
||||
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
|
||||
return;
|
||||
|
||||
// Get gamepad
|
||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||
|
||||
SceCtrlData pad;
|
||||
sceCtrlPeekBufferPositive(0, &pad, 1);
|
||||
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||
|
||||
int rstick_x = (pad.rx - 127) * 256;
|
||||
int rstick_y = (pad.ry - 127) * 256;
|
||||
|
||||
// Update gamepad inputs
|
||||
#define MAP_BUTTON(NAV_NO, BUTTON_NO) { io.NavInputs[NAV_NO] = pad.buttons & BUTTON_NO? 1.0f : 0.0f; }
|
||||
#define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float vn = (float)(AXIS_NO - V0) / (float)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; }
|
||||
#define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V)
|
||||
#define MAP_BUTTON(KEY_NO, BUTTON_NO) { io.AddKeyEvent(KEY_NO, (pad.buttons & BUTTON_NO)); }
|
||||
#define MAP_ANALOG(KEY_NO, AXIS_NO, V0, V1) { float vn = (float)(AXIS_NO - V0) / (float)(V1 - V0); vn = IM_SATURATE(vn); io.AddKeyAnalogEvent(KEY_NO, vn > 0.1f, vn); }
|
||||
const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
|
||||
MAP_BUTTON(ImGuiNavInput_Activate, SCE_CTRL_ENTER); // Cross / A
|
||||
MAP_BUTTON(ImGuiNavInput_Cancel, SCE_CTRL_CANCEL); // Circle / B
|
||||
MAP_BUTTON(ImGuiNavInput_Menu, SCE_CTRL_SQUARE); // Square / X
|
||||
MAP_BUTTON(ImGuiNavInput_Input, SCE_CTRL_TRIANGLE); // Triangle / Y
|
||||
MAP_BUTTON(ImGuiNavInput_DpadLeft, SCE_CTRL_LEFT); // D-Pad Left
|
||||
MAP_BUTTON(ImGuiNavInput_DpadRight, SCE_CTRL_RIGHT); // D-Pad Right
|
||||
MAP_BUTTON(ImGuiNavInput_DpadUp, SCE_CTRL_UP); // D-Pad Up
|
||||
MAP_BUTTON(ImGuiNavInput_DpadDown, SCE_CTRL_DOWN); // D-Pad Down
|
||||
MAP_BUTTON(ImGuiNavInput_FocusPrev, SCE_CTRL_LTRIGGER); // L1 / LB
|
||||
MAP_BUTTON(ImGuiNavInput_FocusNext, SCE_CTRL_RTRIGGER); // R1 / RB
|
||||
MAP_BUTTON(ImGuiNavInput_TweakSlow, SCE_CTRL_LTRIGGER); // L1 / LB
|
||||
MAP_BUTTON(ImGuiNavInput_TweakFast, SCE_CTRL_RTRIGGER); // R1 / RB
|
||||
MAP_ANALOG(ImGuiNavInput_LStickLeft, rstick_x, -thumb_dead_zone, -32768);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickRight, rstick_x, +thumb_dead_zone, +32767);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickUp, rstick_y, -thumb_dead_zone, -32767);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickDown, rstick_y, +thumb_dead_zone, +32767);
|
||||
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||
MAP_BUTTON(ImGuiKey_GamepadStart, SCE_CTRL_ENTER);
|
||||
MAP_BUTTON(ImGuiKey_GamepadBack, SCE_CTRL_CANCEL);
|
||||
MAP_BUTTON(ImGuiKey_GamepadFaceDown, SCE_CTRL_ENTER);
|
||||
MAP_BUTTON(ImGuiKey_GamepadFaceRight, SCE_CTRL_CANCEL);
|
||||
MAP_BUTTON(ImGuiKey_GamepadFaceLeft, SCE_CTRL_SQUARE);
|
||||
MAP_BUTTON(ImGuiKey_GamepadFaceUp, SCE_CTRL_TRIANGLE);
|
||||
MAP_BUTTON(ImGuiKey_GamepadDpadLeft, SCE_CTRL_LEFT);
|
||||
MAP_BUTTON(ImGuiKey_GamepadDpadRight, SCE_CTRL_RIGHT);
|
||||
MAP_BUTTON(ImGuiKey_GamepadDpadUp, SCE_CTRL_UP);
|
||||
MAP_BUTTON(ImGuiKey_GamepadDpadDown, SCE_CTRL_DOWN);
|
||||
MAP_BUTTON(ImGuiKey_GamepadL1, SCE_CTRL_LTRIGGER);
|
||||
MAP_BUTTON(ImGuiKey_GamepadR1, SCE_CTRL_RTRIGGER);
|
||||
MAP_ANALOG(ImGuiKey_GamepadLStickLeft, rstick_x, -thumb_dead_zone, -32768);
|
||||
MAP_ANALOG(ImGuiKey_GamepadLStickRight, rstick_x, +thumb_dead_zone, +32767);
|
||||
MAP_ANALOG(ImGuiKey_GamepadLStickUp, rstick_y, -thumb_dead_zone, -32767);
|
||||
MAP_ANALOG(ImGuiKey_GamepadLStickDown, rstick_y, +thumb_dead_zone, +32767);
|
||||
#undef MAP_BUTTON
|
||||
#undef MAP_ANALOG
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <psp2/sysmodule.h>
|
||||
#include <imgui_vita.h>
|
||||
#include <vitaGL.h>
|
||||
|
||||
#include "fs.h"
|
||||
#include "gui.h"
|
||||
#include "imgui_impl_vitagl.h"
|
||||
#include "log.h"
|
||||
#include "power.h"
|
||||
#include "textures.h"
|
||||
|
Loading…
Reference in New Issue
Block a user