Fix #264: Crash before calling SDL_SetTextInputRect with no window focused

pull/266/head
Jonathan G Rennison 3 years ago
parent 62e3bfd684
commit bf87578173

@ -50,6 +50,7 @@ static std::string _editing_text;
static void SetTextInputRect();
bool IsWindowFocused();
Point GetFocusedWindowCaret();
Point GetFocusedWindowTopLeft();
bool FocusedWindowIsConsole();
@ -432,6 +433,8 @@ bool VideoDriver_SDL_Base::ClaimMousePointer()
static void SetTextInputRect()
{
if (!IsWindowFocused()) return;
SDL_Rect winrect;
Point caret = GetFocusedWindowCaret();
Point win = GetFocusedWindowTopLeft();

@ -452,6 +452,11 @@ void SetFocusedWindow(Window *w)
if (_focused_window != nullptr) _focused_window->OnFocus(old_focused);
}
bool IsWindowFocused()
{
return _focused_window != nullptr;
}
Point GetFocusedWindowCaret()
{
return _focused_window->GetCaretPosition();
@ -519,7 +524,7 @@ bool Window::SetFocusedWidget(int widget_index)
if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
}
this->nested_focus = this->GetWidget<NWidgetCore>(widget_index);
if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus();
if (_focused_window == this && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus();
return true;
}

Loading…
Cancel
Save