Use std::optional as suggested

This commit is contained in:
y5nw
2024-02-08 00:48:03 +01:00
parent 1930b11346
commit ac3f00cd26
2 changed files with 9 additions and 20 deletions

View File

@ -219,29 +219,22 @@ void CIrrDeviceSDL::resetReceiveTextInputEvents() {
gui::IGUIElement *elem = GUIEnvironment->getFocus(); gui::IGUIElement *elem = GUIEnvironment->getFocus();
if (elem && elem->acceptsIME()) if (elem && elem->acceptsIME())
{ {
core::rect<s32> *pos = new core::rect<s32>(elem->getAbsolutePosition()); core::rect<s32> pos = elem->getAbsolutePosition();
if (lastElemPos == NULL || *lastElemPos != *pos) if (!lastElemPos || *lastElemPos != pos)
{ {
if (lastElemPos != NULL)
delete lastElemPos;
lastElemPos = pos; lastElemPos = pos;
SDL_Rect rect; SDL_Rect rect;
rect.x = pos->UpperLeftCorner.X; rect.x = pos.UpperLeftCorner.X;
rect.y = pos->UpperLeftCorner.Y; rect.y = pos.UpperLeftCorner.Y;
rect.w = pos->getWidth(); rect.w = pos.getWidth();
rect.h = pos->getHeight(); rect.h = pos.getHeight();
SDL_SetTextInputRect(&rect); SDL_SetTextInputRect(&rect);
SDL_StartTextInput(); SDL_StartTextInput();
} }
else
{
delete pos;
}
} }
else else
{ {
delete lastElemPos; lastElemPos.reset();
lastElemPos = NULL;
SDL_StopTextInput(); SDL_StopTextInput();
} }
} }
@ -322,8 +315,6 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
createGUIAndScene(); createGUIAndScene();
VideoDriver->OnResize(core::dimension2d<u32>(Width, Height)); VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));
} }
lastElemPos = NULL;
} }
@ -337,9 +328,6 @@ CIrrDeviceSDL::~CIrrDeviceSDL()
for (u32 i=0; i<numJoysticks; ++i) for (u32 i=0; i<numJoysticks; ++i)
SDL_JoystickClose(Joysticks[i]); SDL_JoystickClose(Joysticks[i]);
#endif #endif
if (lastElemPos != NULL) {
delete lastElemPos;
}
if (Window) if (Window)
{ {
SDL_GL_MakeCurrent(Window, NULL); SDL_GL_MakeCurrent(Window, NULL);

View File

@ -24,6 +24,7 @@
#include <SDL_syswm.h> #include <SDL_syswm.h>
#include <memory> #include <memory>
#include <optional>
namespace irr namespace irr
{ {
@ -303,7 +304,7 @@ namespace irr
bool Resizable; bool Resizable;
core::rect<s32> *lastElemPos; std::optional<core::rect<s32>> lastElemPos;
struct SKeyMap struct SKeyMap
{ {