added imgui support
This commit is contained in:
parent
fb0504021a
commit
ff17c973a1
@ -11,6 +11,7 @@ set(EXEC_SRC_LIST src/main.cpp)
|
|||||||
|
|
||||||
#set compilation option
|
#set compilation option
|
||||||
set(IS_LIBRARY True)
|
set(IS_LIBRARY True)
|
||||||
|
set(USE_IMGUI True)
|
||||||
set(SFML_MODULES window system)
|
set(SFML_MODULES window system)
|
||||||
|
|
||||||
set(CMAKE_TEMPLATE_PATH "../CMakeTemplate")
|
set(CMAKE_TEMPLATE_PATH "../CMakeTemplate")
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <SFML/Window.hpp>
|
#include <SFML/Window.hpp>
|
||||||
@ -19,6 +20,29 @@ Input::Input(sf::Window *w) :
|
|||||||
m_heldMouseButtons = std::vector<int>();
|
m_heldMouseButtons = std::vector<int>();
|
||||||
m_actions = std::vector<Action>();
|
m_actions = std::vector<Action>();
|
||||||
m_window->setKeyRepeatEnabled(false);
|
m_window->setKeyRepeatEnabled(false);
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// init keyboard mapping
|
||||||
|
io.KeyMap[ImGuiKey_Tab] = sf::Keyboard::Tab;
|
||||||
|
io.KeyMap[ImGuiKey_LeftArrow] = sf::Keyboard::Left;
|
||||||
|
io.KeyMap[ImGuiKey_RightArrow] = sf::Keyboard::Right;
|
||||||
|
io.KeyMap[ImGuiKey_UpArrow] = sf::Keyboard::Up;
|
||||||
|
io.KeyMap[ImGuiKey_DownArrow] = sf::Keyboard::Down;
|
||||||
|
io.KeyMap[ImGuiKey_PageUp] = sf::Keyboard::PageUp;
|
||||||
|
io.KeyMap[ImGuiKey_PageDown] = sf::Keyboard::PageDown;
|
||||||
|
io.KeyMap[ImGuiKey_Home] = sf::Keyboard::Home;
|
||||||
|
io.KeyMap[ImGuiKey_End] = sf::Keyboard::End;
|
||||||
|
io.KeyMap[ImGuiKey_Delete] = sf::Keyboard::Delete;
|
||||||
|
io.KeyMap[ImGuiKey_Backspace] = sf::Keyboard::BackSpace;
|
||||||
|
io.KeyMap[ImGuiKey_Enter] = sf::Keyboard::Return;
|
||||||
|
io.KeyMap[ImGuiKey_Escape] = sf::Keyboard::Escape;
|
||||||
|
io.KeyMap[ImGuiKey_A] = sf::Keyboard::A;
|
||||||
|
io.KeyMap[ImGuiKey_C] = sf::Keyboard::C;
|
||||||
|
io.KeyMap[ImGuiKey_V] = sf::Keyboard::V;
|
||||||
|
io.KeyMap[ImGuiKey_X] = sf::Keyboard::X;
|
||||||
|
io.KeyMap[ImGuiKey_Y] = sf::Keyboard::Y;
|
||||||
|
io.KeyMap[ImGuiKey_Z] = sf::Keyboard::Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::setKeysMap(IKeysMap km){
|
void Input::setKeysMap(IKeysMap km){
|
||||||
@ -27,6 +51,7 @@ void Input::setKeysMap(IKeysMap km){
|
|||||||
|
|
||||||
void Input::updateEvents(){
|
void Input::updateEvents(){
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
KeyBindings kb;
|
KeyBindings kb;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
@ -67,23 +92,35 @@ void Input::updateEvents(){
|
|||||||
case sf::Event::TextEntered:
|
case sf::Event::TextEntered:
|
||||||
c = (char) event.text.unicode;
|
c = (char) event.text.unicode;
|
||||||
sf::Utf32::encodeAnsi(event.text.unicode,std::back_inserter(m_buffer));
|
sf::Utf32::encodeAnsi(event.text.unicode,std::back_inserter(m_buffer));
|
||||||
|
io.AddInputCharacter(static_cast<ImWchar>(event.text.unicode));
|
||||||
break;
|
break;
|
||||||
case sf::Event::KeyPressed:
|
case sf::Event::KeyPressed:
|
||||||
action = kb.getPressedAction(input::KEYBOARD,event.key.code);
|
action = kb.getPressedAction(input::KEYBOARD,event.key.code);
|
||||||
if(!action.isNull())
|
if(!action.isNull())
|
||||||
m_actions.push_back(action);
|
m_actions.push_back(action);
|
||||||
m_heldKeys.push_back(event.key.code);
|
m_heldKeys.push_back(event.key.code);
|
||||||
|
io.KeysDown[event.key.code] = true;
|
||||||
|
io.KeyCtrl = event.key.control;
|
||||||
|
io.KeyShift = event.key.shift;
|
||||||
|
io.KeyAlt = event.key.alt;
|
||||||
break;
|
break;
|
||||||
case sf::Event::KeyReleased:
|
case sf::Event::KeyReleased:
|
||||||
action = kb.getReleasedAction(input::KEYBOARD,event.key.code);
|
action = kb.getReleasedAction(input::KEYBOARD,event.key.code);
|
||||||
if(!action.isNull())
|
if(!action.isNull())
|
||||||
m_actions.push_back(action);
|
m_actions.push_back(action);
|
||||||
releaseHeldKeys(event.key.code);
|
releaseHeldKeys(event.key.code);
|
||||||
|
io.KeysDown[event.key.code] = false;
|
||||||
|
io.KeyCtrl = event.key.control;
|
||||||
|
io.KeyShift = event.key.shift;
|
||||||
|
io.KeyAlt = event.key.alt;
|
||||||
break;
|
break;
|
||||||
case sf::Event::MouseWheelScrolled:
|
case sf::Event::MouseWheelScrolled:
|
||||||
if (event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel)
|
if (event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel)
|
||||||
m_delta_vertical_scroll = event.mouseWheelScroll.delta;
|
m_delta_vertical_scroll = event.mouseWheelScroll.delta;
|
||||||
break;
|
break;
|
||||||
|
case sf::Event::MouseWheelMoved:
|
||||||
|
io.MouseWheel += static_cast<float>(event.mouseWheel.delta);
|
||||||
|
break;
|
||||||
case sf::Event::MouseButtonPressed:
|
case sf::Event::MouseButtonPressed:
|
||||||
action = kb.getPressedAction(input::MOUSE,event.mouseButton.button);
|
action = kb.getPressedAction(input::MOUSE,event.mouseButton.button);
|
||||||
if(!action.isNull())
|
if(!action.isNull())
|
||||||
@ -98,6 +135,7 @@ void Input::updateEvents(){
|
|||||||
break;
|
break;
|
||||||
case sf::Event::MouseMoved:
|
case sf::Event::MouseMoved:
|
||||||
m_mouse_position = sf::Mouse::getPosition(*m_window);
|
m_mouse_position = sf::Mouse::getPosition(*m_window);
|
||||||
|
io.MousePos = ImVec2(m_mouse_position.x, m_mouse_position.y);
|
||||||
break;
|
break;
|
||||||
case sf::Event::MouseEntered:
|
case sf::Event::MouseEntered:
|
||||||
// action MouseEntered
|
// action MouseEntered
|
||||||
@ -138,8 +176,14 @@ void Input::updateEvents(){
|
|||||||
for (auto key: m_heldKeys)
|
for (auto key: m_heldKeys)
|
||||||
m_actions.push_back(kb.getHoldAction(input::KEYBOARD,key));
|
m_actions.push_back(kb.getHoldAction(input::KEYBOARD,key));
|
||||||
|
|
||||||
for (auto button: m_heldMouseButtons)
|
for (int i = 0; i < 3; i++)
|
||||||
|
io.MouseDown[i] = false;
|
||||||
|
|
||||||
|
for (int button: m_heldMouseButtons)
|
||||||
|
{
|
||||||
m_actions.push_back(kb.getHoldAction(input::MOUSE, button));
|
m_actions.push_back(kb.getHoldAction(input::MOUSE, button));
|
||||||
|
io.MouseDown[button] = true;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto heldJoystickButton : m_heldJoystickButtons)
|
for (auto heldJoystickButton : m_heldJoystickButtons)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user