Merge remote-tracking branch 'origin/master' into HEAD

This commit is contained in:
Sergii Pylypenko
2019-04-23 18:16:24 +03:00
179 changed files with 6418 additions and 1144 deletions

View File

@@ -27,6 +27,7 @@
#include "newgrf_debug.h"
#include "zoom_func.h"
#include "guitimer_func.h"
#include "build_confirmation_func.h"
#include "widgets/misc_widget.h"
@@ -34,6 +35,10 @@
#include "safeguards.h"
#ifdef __ANDROID__
#include <SDL_screenkeyboard.h>
#endif
/** Method to open the OSK. */
enum OskActivation {
OSKA_DISABLED, ///< The OSK shall not be activated at all.
@@ -42,6 +47,8 @@ enum OskActivation {
OSKA_IMMEDIATELY, ///< Focusing click already opens OSK.
};
static char _android_text_input[512];
static const NWidgetPart _nested_land_info_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -533,6 +540,10 @@ void ShowAboutWindow()
*/
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
{
if (ConfirmationWindowEstimatingCost()) {
ConfirmationWindowSetEstimatedCost(cost);
return;
}
StringID msg = STR_MESSAGE_ESTIMATED_COST;
if (cost < 0) {
@@ -680,10 +691,18 @@ struct TooltipsWindow : public Window
/* Correctly position the tooltip position, watch out for window and cursor size
* Clamp value to below main toolbar and above statusbar. If tooltip would
* go below window, flip it so it is shown above the cursor */
pt.y = Clamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot);
if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height;
pt.y = min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height - GetMinSizing(NWST_STEP);
if (pt.y < scr_top) pt.y = Clamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot) + GetMinSizing(NWST_STEP);
pt.x = sm_width >= _screen.width ? 0 : Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
if (_settings_client.gui.windows_titlebars) {
// Move it to the top of the screen, away from mouse cursor, so it won't steal screen taps on Android
pt.y = GetMainViewTop();
if (_cursor.pos.y < pt.y + GetMinSizing(NWST_STEP)) {
pt.x = _cursor.pos.x > _screen.width / 2 ? GetMinSizing(NWST_STEP) : _screen.width - sm_width - GetMinSizing(NWST_STEP);
}
}
return pt;
}
@@ -692,7 +711,7 @@ struct TooltipsWindow : public Window
/* There is only one widget. */
for (uint i = 0; i != this->paramcount; i++) SetDParam(i, this->params[i]);
size->width = min(GetStringBoundingBox(this->string_id).width, ScaleGUITrad(194));
size->width = min(GetStringBoundingBox(this->string_id).width, ScaleGUITrad(250));
size->height = GetStringHeight(this->string_id, size->width);
/* Increase slightly to have some space around the box. */
@@ -755,6 +774,14 @@ void QueryString::HandleEditBox(Window *w, int wid)
/* For the OSK also invalidate the parent window */
if (w->window_class == WC_OSK) w->InvalidateData();
}
#ifdef __ANDROID__
if (SDL_IsScreenKeyboardShown(NULL)) {
if (SDL_ANDROID_GetScreenKeyboardTextInputAsync(_android_text_input, sizeof(_android_text_input)) == SDL_ANDROID_TEXTINPUT_ASYNC_FINISHED) {
this->text.Assign(_android_text_input);
w->OnEditboxChanged(wid);
}
}
#endif
}
void QueryString::DrawEditBox(const Window *w, int wid) const
@@ -765,7 +792,7 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
bool rtl = _current_text_dir == TD_RTL;
Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
int clearbtn_width = GetMinSizing(NWST_BUTTON, sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT);
int clearbtn_left = wi->pos_x + (rtl ? 0 : wi->current_x - clearbtn_width);
int clearbtn_right = wi->pos_x + (rtl ? clearbtn_width : wi->current_x) - 1;
@@ -776,7 +803,7 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
int bottom = wi->pos_y + wi->current_y - 1;
DrawFrameRect(clearbtn_left, top, clearbtn_right, bottom, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
DrawSprite(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, clearbtn_left + WD_IMGBTN_LEFT + (wi->IsLowered() ? 1 : 0), (top + bottom - sprite_size.height) / 2 + (wi->IsLowered() ? 1 : 0));
DrawSprite(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, Center(clearbtn_left + wi->IsLowered(), clearbtn_width, sprite_size.width), Center(top + wi->IsLowered(), bottom - top, sprite_size.height));
if (this->text.bytes == 1) GfxFillRect(clearbtn_left + 1, top + 1, clearbtn_right - 1, bottom - 1, _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
DrawFrameRect(left, top, right, bottom, wi->colour, FR_LOWERED | FR_DARKENED);
@@ -799,11 +826,12 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
/* If we have a marked area, draw a background highlight. */
if (tb->marklength != 0) GfxFillRect(delta + tb->markxoffs, 0, delta + tb->markxoffs + tb->marklength - 1, bottom - top, PC_GREY);
DrawString(delta, tb->pixels, 0, tb->buf, TC_YELLOW);
DrawString(delta, tb->pixels, Center(0, bottom - top), tb->buf, TC_YELLOW);
bool focussed = w->IsWidgetGloballyFocused(wid) || IsOSKOpenedFor(w, wid);
if (focussed && tb->caret) {
int caret_width = GetStringBoundingBox("_").width;
DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE);
DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, Center(0, bottom - top), "_", TC_WHITE);
}
_cur_dpi = old_dpi;
@@ -934,6 +962,11 @@ void QueryString::ClickEditBox(Window *w, Point pt, int wid, int click_count, bo
/* Open the OSK window */
ShowOnScreenKeyboard(w, wid);
}
#ifdef __ANDROID__
strecpy(_android_text_input, this->text.buf, lastof(_android_text_input));
this->text.DeleteAll();
SDL_ANDROID_GetScreenKeyboardTextInputAsync(_android_text_input, sizeof(_android_text_input));
#endif
}
/** Class for the string query window. */
@@ -1115,6 +1148,7 @@ struct QueryWindow : public Window {
{
if (widget != WID_Q_TEXT) return;
size->width = GetMinSizing(NWST_WINDOW_LENGTH, size->width);
Dimension d = GetStringMultiLineBoundingBox(this->message, *size);
d.width += WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;