diff options
author | LaG1924 <lag1924@gmail.com> | 2021-06-13 18:20:25 +0200 |
---|---|---|
committer | LaG1924 <lag1924@gmail.com> | 2021-06-13 18:20:25 +0200 |
commit | cc937302964a04aa8e7cdc0e6796503559efaa69 (patch) | |
tree | 3a6b890d32ed735d42f042a08c1af9637cb62b70 /src/Render.cpp | |
parent | Fixed Linux build of RmlUi (diff) | |
download | AltCraft-cc937302964a04aa8e7cdc0e6796503559efaa69.tar AltCraft-cc937302964a04aa8e7cdc0e6796503559efaa69.tar.gz AltCraft-cc937302964a04aa8e7cdc0e6796503559efaa69.tar.bz2 AltCraft-cc937302964a04aa8e7cdc0e6796503559efaa69.tar.lz AltCraft-cc937302964a04aa8e7cdc0e6796503559efaa69.tar.xz AltCraft-cc937302964a04aa8e7cdc0e6796503559efaa69.tar.zst AltCraft-cc937302964a04aa8e7cdc0e6796503559efaa69.zip |
Diffstat (limited to 'src/Render.cpp')
-rw-r--r-- | src/Render.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Render.cpp b/src/Render.cpp index 0f04992..48bbadd 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -3,6 +3,7 @@ #include <easylogging++.h> #include <optick.h> #include <RmlUi/Core.h> +#include <RmlUi/Lua.h> #include "Shader.hpp" #include "AssetManager.hpp" @@ -276,6 +277,13 @@ void Render::HandleEvents() { case SDL_SCANCODE_SLASH: case SDL_SCANCODE_T: { + auto state = GetState(); + if (state == State::Playing) { + SetState(State::Chat); + } + else if (state == State::Chat) { + SetState(State::Playing); + } break; } @@ -287,14 +295,50 @@ void Render::HandleEvents() { } case SDL_MOUSEMOTION: { + if (isMouseCaptured) { + double deltaX = event.motion.xrel; + double deltaY = event.motion.yrel; + deltaX *= sensetivity; + deltaY *= sensetivity * -1; + PUSH_EVENT("MouseMove", std::make_tuple(deltaX, deltaY)); + } else { + int mouseX, mouseY; + SDL_GetMouseState(&mouseX, &mouseY); + rmlContext->ProcessMouseMove(mouseX, mouseY, 0); + } break; } case SDL_MOUSEBUTTONDOWN: { + if (isMouseCaptured) { + if (event.button.button == SDL_BUTTON_LEFT) + PUSH_EVENT("LmbPressed", 0); + else if (event.button.button == SDL_BUTTON_RIGHT) + PUSH_EVENT("RmbPressed", 0); + } else { + if (event.button.button == SDL_BUTTON_MIDDLE) + event.button.button = SDL_BUTTON_RIGHT; + else if (event.button.button == SDL_BUTTON_RIGHT) + event.button.button = SDL_BUTTON_MIDDLE; + rmlContext->ProcessMouseButtonDown(event.button.button - 1, 0); + } + break; } case SDL_MOUSEBUTTONUP: { + if (isMouseCaptured) { + if (event.button.button == SDL_BUTTON_LEFT) + PUSH_EVENT("LmbReleased", 0); + else if (event.button.button == SDL_BUTTON_RIGHT) + PUSH_EVENT("RmbReleased", 0); + } else { + if (event.button.button == SDL_BUTTON_MIDDLE) + event.button.button = SDL_BUTTON_RIGHT; + else if (event.button.button == SDL_BUTTON_RIGHT) + event.button.button = SDL_BUTTON_MIDDLE; + rmlContext->ProcessMouseButtonUp(event.button.button - 1, 0); + } break; } @@ -437,6 +481,8 @@ void Render::InitRml() { if (!Rml::Initialise()) LOG(WARNING) << "Rml not initialized"; + Rml::Lua::Initialise(PluginSystem::GetLuaState()); + rmlContext = Rml::CreateContext("default", Rml::Vector2i(renderState.WindowWidth, renderState.WindowHeight)); if (!Rml::LoadFontFace("OpenSans-Regular.ttf")) |