mirror of https://github.com/OpenRCT2/OpenRCT2.git
Fix build
This commit is contained in:
parent
f736e8ff96
commit
9d24e47e6f
|
@ -19,13 +19,13 @@
|
|||
#include <openrct2/core/Math.hpp>
|
||||
#include <openrct2/core/Memory.hpp>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include <openrct2/localisation/localisation.h>
|
||||
#include "TextComposition.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <openrct2/interface/console.h>
|
||||
#include <openrct2/interface/window.h>
|
||||
#include <openrct2/localisation/localisation.h>
|
||||
}
|
||||
|
||||
#ifdef __MACOSX__
|
||||
|
@ -43,7 +43,7 @@ bool TextComposition::IsActive()
|
|||
return SDL_IsTextInputActive() && _session.Buffer != nullptr;
|
||||
}
|
||||
|
||||
const TextInputSession * TextComposition::Start(utf8 * buffer, size_t bufferSize)
|
||||
TextInputSession * TextComposition::Start(utf8 * buffer, size_t bufferSize)
|
||||
{
|
||||
Guard::ArgumentNotNull(buffer);
|
||||
|
||||
|
@ -250,7 +250,7 @@ void TextComposition::InsertCodepoint(codepoint_t codepoint)
|
|||
size_t remainingSize = _session.BufferSize - _session.Size;
|
||||
if (codepointLength <= remainingSize)
|
||||
{
|
||||
utf8 * buffer = (utf8 *)_session.Buffer;
|
||||
utf8 * buffer = _session.Buffer;
|
||||
utf8 * insertPtr = buffer + _session.SelectionStart;
|
||||
if (_session.SelectionStart < _session.Size)
|
||||
{
|
||||
|
@ -274,7 +274,7 @@ void TextComposition::InsertCodepoint(codepoint_t codepoint)
|
|||
|
||||
void TextComposition::Clear()
|
||||
{
|
||||
utf8 * buffer = (utf8 *)_session.Buffer;
|
||||
utf8 * buffer = _session.Buffer;
|
||||
buffer[0] = 0;
|
||||
_session.Size = 0;
|
||||
_session.Length = 0;
|
||||
|
@ -284,7 +284,7 @@ void TextComposition::Clear()
|
|||
|
||||
void TextComposition::Delete()
|
||||
{
|
||||
utf8 * buffer = (utf8 *)_session.Buffer;
|
||||
utf8 * buffer = _session.Buffer;
|
||||
utf8 * targetShiftPtr = buffer + _session.SelectionStart;
|
||||
utf8 * sourceShiftPtr = targetShiftPtr + _session.SelectionSize;
|
||||
size_t shiftSize = _session.SelectionSize - _session.SelectionStart - _session.SelectionSize + 1;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#pragma endregion
|
||||
|
||||
#include <openrct2/common.h>
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/ui/UiContext.h>
|
||||
|
||||
union SDL_Event;
|
||||
|
@ -38,7 +39,7 @@ namespace OpenRCT2
|
|||
|
||||
public:
|
||||
bool IsActive();
|
||||
const TextInputSession * TextComposition::Start(utf8 * buffer, size_t bufferSize);
|
||||
TextInputSession * TextComposition::Start(utf8 * buffer, size_t bufferSize);
|
||||
void Stop();
|
||||
void HandleMessage(const SDL_Event * e);
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/drawing/IDrawingEngine.h>
|
||||
#include <openrct2/interface/window.h>
|
||||
#include <openrct2/ui/UiContext.h>
|
||||
#include <openrct2/Version.h>
|
||||
#include "CursorRepository.h"
|
||||
|
@ -32,8 +31,9 @@
|
|||
|
||||
extern "C"
|
||||
{
|
||||
#include <openrct2/interface/console.h>
|
||||
#include <openrct2/input.h>
|
||||
#include <openrct2/interface/console.h>
|
||||
#include <openrct2/interface/window.h>
|
||||
}
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
@ -135,6 +135,7 @@ public:
|
|||
|
||||
std::vector<Resolution> GetFullscreenResolutions() override
|
||||
{
|
||||
UpdateFullscreenResolutions();
|
||||
return _fsResolutions;
|
||||
}
|
||||
|
||||
|
@ -207,7 +208,7 @@ public:
|
|||
return _textComposition.IsActive();
|
||||
}
|
||||
|
||||
const TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) override
|
||||
TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) override
|
||||
{
|
||||
return _textComposition.Start(buffer, bufferSize);
|
||||
}
|
||||
|
@ -217,7 +218,7 @@ public:
|
|||
_textComposition.Stop();
|
||||
}
|
||||
|
||||
void ProcessMessages()
|
||||
void ProcessMessages() override
|
||||
{
|
||||
_lastKeyPressed = 0;
|
||||
_cursorState.left &= ~CURSOR_CHANGED;
|
||||
|
@ -412,6 +413,27 @@ public:
|
|||
_keysState = SDL_GetKeyboardState(&numKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to set various render target features.
|
||||
* Does not get triggered on resize, but rather manually on config changes.
|
||||
*/
|
||||
void TriggerResize() override
|
||||
{
|
||||
char scaleQualityBuffer[4];
|
||||
uint8 scaleQuality = gConfigGeneral.scale_quality;
|
||||
if (gConfigGeneral.use_nn_at_integer_scales &&
|
||||
gConfigGeneral.window_scale == std::floor(gConfigGeneral.window_scale))
|
||||
{
|
||||
scaleQuality = 0;
|
||||
}
|
||||
snprintf(scaleQualityBuffer, sizeof(scaleQualityBuffer), "%u", scaleQuality);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaleQualityBuffer);
|
||||
|
||||
sint32 width, height;
|
||||
SDL_GetWindowSize(_window, &width, &height);
|
||||
OnResize(width, height);
|
||||
}
|
||||
|
||||
private:
|
||||
void CreateWindow()
|
||||
{
|
||||
|
@ -506,27 +528,6 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to set various render target features.
|
||||
* Does not get triggered on resize, but rather manually on config changes.
|
||||
*/
|
||||
void TriggerResize()
|
||||
{
|
||||
char scaleQualityBuffer[4];
|
||||
uint8 scaleQuality = gConfigGeneral.scale_quality;
|
||||
if (gConfigGeneral.use_nn_at_integer_scales &&
|
||||
gConfigGeneral.window_scale == std::floor(gConfigGeneral.window_scale))
|
||||
{
|
||||
scaleQuality = 0;
|
||||
}
|
||||
snprintf(scaleQualityBuffer, sizeof(scaleQualityBuffer), "%u", scaleQuality);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaleQualityBuffer);
|
||||
|
||||
sint32 width, height;
|
||||
SDL_GetWindowSize(_window, &width, &height);
|
||||
OnResize(width, height);
|
||||
}
|
||||
|
||||
void UpdateFullscreenResolutions()
|
||||
{
|
||||
// Query number of display modes
|
||||
|
@ -552,20 +553,20 @@ private:
|
|||
}
|
||||
|
||||
// Sort by area
|
||||
std::sort(resolutions.begin(), resolutions.end());
|
||||
// [](const Resolution &a, const Resolution &b) -> bool
|
||||
// {
|
||||
// sint32 areaA = a.Width * a.Height;
|
||||
// sint32 areaB = b.Width * b.Height;
|
||||
// return areaA < areaB;
|
||||
// });
|
||||
std::sort(resolutions.begin(), resolutions.end(),
|
||||
[](const Resolution &a, const Resolution &b) -> bool
|
||||
{
|
||||
sint32 areaA = a.Width * a.Height;
|
||||
sint32 areaB = b.Width * b.Height;
|
||||
return areaA < areaB;
|
||||
});
|
||||
|
||||
// Remove duplicates
|
||||
auto last = std::unique(resolutions.begin(), resolutions.end());
|
||||
// [](const Resolution &a, const Resolution &b) -> bool
|
||||
// {
|
||||
// return (a.Width == b.Width && a.Height == b.Height);
|
||||
// });
|
||||
auto last = std::unique(resolutions.begin(), resolutions.end(),
|
||||
[](const Resolution &a, const Resolution &b) -> bool
|
||||
{
|
||||
return (a.Width == b.Width && a.Height == b.Height);
|
||||
});
|
||||
resolutions.erase(last, resolutions.end());
|
||||
|
||||
// Update config fullscreen resolution if not set
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#pragma endregion
|
||||
|
||||
#include <exception>
|
||||
#include "core/Memory.hpp"
|
||||
#include "config/Config.h"
|
||||
#include "Context.h"
|
||||
#include "OpenRCT2.h"
|
||||
|
@ -134,9 +135,9 @@ extern "C"
|
|||
return GetContext()->GetUiContext()->GetKeysPressed();
|
||||
}
|
||||
|
||||
void context_start_text_input(utf8 * buffer, size_t maxLength)
|
||||
TextInputSession * context_start_text_input(utf8 * buffer, size_t maxLength)
|
||||
{
|
||||
GetContext()->GetUiContext()->StartTextInput(buffer, maxLength);
|
||||
return GetContext()->GetUiContext()->StartTextInput(buffer, maxLength);
|
||||
}
|
||||
|
||||
void context_stop_text_input()
|
||||
|
@ -148,4 +149,23 @@ extern "C"
|
|||
{
|
||||
return GetContext()->GetUiContext()->IsTextInputActive();
|
||||
}
|
||||
|
||||
void context_trigger_resize()
|
||||
{
|
||||
return GetContext()->GetUiContext()->TriggerResize();
|
||||
}
|
||||
|
||||
void context_set_fullscreen_mode(sint32 mode)
|
||||
{
|
||||
return GetContext()->GetUiContext()->SetFullscreenMode((FULLSCREEN_MODE)mode);
|
||||
}
|
||||
|
||||
sint32 context_get_resolutions(Resolution * * outResolutions)
|
||||
{
|
||||
auto resolutions = GetContext()->GetUiContext()->GetFullscreenResolutions();
|
||||
sint32 count = (sint32)resolutions.size();
|
||||
*outResolutions = Memory::AllocateArray<Resolution>(count);
|
||||
Memory::CopyArray(*outResolutions, resolutions.data(), count);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,22 @@ typedef struct CursorState
|
|||
uint32 touchDownTimestamp;
|
||||
} CursorState;
|
||||
|
||||
typedef struct TextInputSession
|
||||
{
|
||||
utf8 * Buffer; // UTF-8 stream
|
||||
size_t BufferSize; // Maximum number of bytes (excluding null terminator)
|
||||
size_t Size; // Number of bytes (excluding null terminator)
|
||||
size_t Length; // Number of codepoints
|
||||
size_t SelectionStart; // Selection start, in bytes
|
||||
size_t SelectionSize; // Selection length in bytes
|
||||
} TextInputSession;
|
||||
|
||||
struct Resolution
|
||||
{
|
||||
sint32 Width;
|
||||
sint32 Height;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CURSOR_UP = 0,
|
||||
|
@ -77,9 +93,12 @@ extern "C"
|
|||
const CursorState * context_get_cursor_state();
|
||||
const uint8 * context_get_keys_state();
|
||||
const uint8 * context_get_keys_pressed();
|
||||
void context_start_text_input(utf8 * buffer, size_t maxLength);
|
||||
TextInputSession * context_start_text_input(utf8 * buffer, size_t maxLength);
|
||||
void context_stop_text_input();
|
||||
bool context_is_input_active();
|
||||
void context_trigger_resize();
|
||||
void context_set_fullscreen_mode(sint32 mode);
|
||||
sint32 context_get_resolutions(struct Resolution * * outResolutions);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -26,17 +26,18 @@
|
|||
#include "chat.h"
|
||||
|
||||
bool gChatOpen = false;
|
||||
char _chatCurrentLine[CHAT_MAX_MESSAGE_LENGTH];
|
||||
char _chatHistory[CHAT_HISTORY_SIZE][CHAT_INPUT_SIZE];
|
||||
uint32 _chatHistoryTime[CHAT_HISTORY_SIZE];
|
||||
uint32 _chatHistoryIndex = 0;
|
||||
uint32 _chatCaretTicks = 0;
|
||||
sint32 _chatLeft;
|
||||
sint32 _chatTop;
|
||||
sint32 _chatRight;
|
||||
sint32 _chatBottom;
|
||||
sint32 _chatWidth;
|
||||
sint32 _chatHeight;
|
||||
static char _chatCurrentLine[CHAT_MAX_MESSAGE_LENGTH];
|
||||
static char _chatHistory[CHAT_HISTORY_SIZE][CHAT_INPUT_SIZE];
|
||||
static uint32 _chatHistoryTime[CHAT_HISTORY_SIZE];
|
||||
static uint32 _chatHistoryIndex = 0;
|
||||
static uint32 _chatCaretTicks = 0;
|
||||
static sint32 _chatLeft;
|
||||
static sint32 _chatTop;
|
||||
static sint32 _chatRight;
|
||||
static sint32 _chatBottom;
|
||||
static sint32 _chatWidth;
|
||||
static sint32 _chatHeight;
|
||||
static TextInputSession * _chatTextInputSession;
|
||||
|
||||
static const char* chat_history_get(uint32 index);
|
||||
static uint32 chat_history_get_time(uint32 index);
|
||||
|
@ -45,7 +46,7 @@ static void chat_clear_input();
|
|||
void chat_open()
|
||||
{
|
||||
gChatOpen = true;
|
||||
context_start_text_input(_chatCurrentLine, sizeof(_chatCurrentLine));
|
||||
_chatTextInputSession = context_start_text_input(_chatCurrentLine, sizeof(_chatCurrentLine));
|
||||
}
|
||||
|
||||
void chat_close()
|
||||
|
@ -161,8 +162,8 @@ void chat_draw(rct_drawpixelinfo * dpi)
|
|||
|
||||
// TODO: Show caret if the input text has multiple lines
|
||||
if (_chatCaretTicks < 15 && gfx_get_string_width(lineBuffer) < (_chatWidth - 10)) {
|
||||
memcpy(lineBuffer, _chatCurrentLine, gTextInput.selection_offset);
|
||||
lineBuffer[gTextInput.selection_offset] = 0;
|
||||
memcpy(lineBuffer, _chatCurrentLine, _chatTextInputSession->SelectionStart);
|
||||
lineBuffer[_chatTextInputSession->SelectionStart] = 0;
|
||||
sint32 caretX = x + gfx_get_string_width(lineBuffer);
|
||||
sint32 caretY = y + 14;
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ static sint32 _consoleCaretTicks;
|
|||
static utf8 _consolePrintfBuffer[CONSOLE_BUFFER_2_SIZE];
|
||||
static utf8 _consoleErrorBuffer[CONSOLE_BUFFER_2_SIZE];
|
||||
static sint32 _consoleScrollPos = 0;
|
||||
static TextInputSession * _consoleTextInputSession;
|
||||
|
||||
static utf8 _consoleHistory[CONSOLE_HISTORY_SIZE][CONSOLE_INPUT_SIZE];
|
||||
static sint32 _consoleHistoryIndex = 0;
|
||||
|
@ -92,7 +93,7 @@ void console_open()
|
|||
_consoleScrollPos = 0;
|
||||
console_refresh_caret();
|
||||
console_update_scroll();
|
||||
context_start_text_input(_consoleCurrentLine, sizeof(_consoleCurrentLine));
|
||||
_consoleTextInputSession = context_start_text_input(_consoleCurrentLine, sizeof(_consoleCurrentLine));
|
||||
}
|
||||
|
||||
void console_close()
|
||||
|
@ -236,8 +237,8 @@ void console_draw(rct_drawpixelinfo *dpi)
|
|||
|
||||
// Draw caret
|
||||
if (_consoleCaretTicks < 15) {
|
||||
memcpy(lineBuffer, _consoleCurrentLine, gTextInput.selection_offset);
|
||||
lineBuffer[gTextInput.selection_offset] = 0;
|
||||
memcpy(lineBuffer, _consoleCurrentLine, _consoleTextInputSession->SelectionStart);
|
||||
lineBuffer[_consoleTextInputSession->SelectionStart] = 0;
|
||||
sint32 caretX = x + gfx_get_string_width(lineBuffer);
|
||||
sint32 caretY = y + lineHeight;
|
||||
|
||||
|
@ -271,15 +272,17 @@ void console_input(sint32 c)
|
|||
_consoleHistoryIndex--;
|
||||
memcpy(_consoleCurrentLine, _consoleHistory[_consoleHistoryIndex], 256);
|
||||
}
|
||||
textinputbuffer_recalculate_length(&gTextInput);
|
||||
gTextInput.selection_offset = strlen(_consoleCurrentLine);
|
||||
_consoleTextInputSession->Size = strlen(_consoleTextInputSession->Buffer);
|
||||
_consoleTextInputSession->Length = utf8_length(_consoleTextInputSession->Buffer);
|
||||
_consoleTextInputSession->SelectionStart = strlen(_consoleCurrentLine);
|
||||
break;
|
||||
case SDL_SCANCODE_DOWN:
|
||||
if (_consoleHistoryIndex < _consoleHistoryCount - 1) {
|
||||
_consoleHistoryIndex++;
|
||||
memcpy(_consoleCurrentLine, _consoleHistory[_consoleHistoryIndex], 256);
|
||||
textinputbuffer_recalculate_length(&gTextInput);
|
||||
gTextInput.selection_offset = strlen(_consoleCurrentLine);
|
||||
_consoleTextInputSession->Size = strlen(_consoleTextInputSession->Buffer);
|
||||
_consoleTextInputSession->Length = utf8_length(_consoleTextInputSession->Buffer);
|
||||
_consoleTextInputSession->SelectionStart = strlen(_consoleCurrentLine);
|
||||
} else {
|
||||
_consoleHistoryIndex = _consoleHistoryCount;
|
||||
console_clear_input();
|
||||
|
@ -1006,7 +1009,7 @@ static sint32 cc_set(const utf8 **argv, sint32 argc)
|
|||
gConfigGeneral.window_scale = clamp(newScale, 0.5f, 5.0f);
|
||||
config_save_default();
|
||||
gfx_invalidate_screen();
|
||||
platform_trigger_resize();
|
||||
context_trigger_resize();
|
||||
console_execute_silent("get window_scale");
|
||||
}
|
||||
else if (strcmp(argv[0], "window_limit") == 0 && invalidArguments(&invalidArgs, int_valid[0])) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "../platform/platform.h"
|
||||
#include "../localisation/localisation.h"
|
||||
#include "../util/util.h"
|
||||
#include "../Context.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
@ -1104,15 +1105,15 @@ static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widg
|
|||
|
||||
// Make a copy of the string for measuring the width.
|
||||
char temp_string[TEXT_INPUT_SIZE] = { 0 };
|
||||
memcpy(temp_string, wrapped_string, min(string_length, gTextInput.selection_offset));
|
||||
memcpy(temp_string, wrapped_string, min(string_length, gTextInput->SelectionStart));
|
||||
sint32 cur_x = l + gfx_get_string_width(temp_string) + 3;
|
||||
|
||||
sint32 width = 6;
|
||||
if ((uint32)gTextInput.selection_offset < strlen(gTextBoxInput)){
|
||||
if ((uint32)gTextInput->SelectionStart < strlen(gTextBoxInput)){
|
||||
// Make a new 1 character wide string for measuring the width
|
||||
// of the character that the cursor is under.
|
||||
temp_string[1] = '\0';
|
||||
temp_string[0] = gTextBoxInput[gTextInput.selection_offset];
|
||||
temp_string[0] = gTextBoxInput[gTextInput->SelectionStart];
|
||||
width = max(gfx_get_string_width(temp_string) - 2, 4);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ char gTextBoxInput[TEXT_INPUT_SIZE] = { 0 };
|
|||
sint32 gMaxTextBoxInputLength = 0;
|
||||
sint32 gTextBoxFrameNo = 0;
|
||||
bool gUsingWidgetTextBox = 0;
|
||||
TextInputSession * gTextInput;
|
||||
|
||||
uint16 gWindowUpdateTicks;
|
||||
uint8 gToolbarDirtyFlags;
|
||||
|
|
|
@ -33,6 +33,7 @@ struct rct_window;
|
|||
union rct_window_event;
|
||||
struct track_design_file_ref;
|
||||
struct TitleSequence;
|
||||
struct TextInputSession;
|
||||
|
||||
#define TEXT_INPUT_SIZE 1024
|
||||
|
||||
|
@ -41,6 +42,7 @@ extern char gTextBoxInput[TEXT_INPUT_SIZE];
|
|||
extern sint32 gMaxTextBoxInputLength;
|
||||
extern sint32 gTextBoxFrameNo;
|
||||
extern bool gUsingWidgetTextBox;
|
||||
extern struct TextInputSession * gTextInput;
|
||||
|
||||
typedef void wndproc(struct rct_window*, union rct_window_event*);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "../audio/audio.h"
|
||||
#include "../audio/AudioMixer.h"
|
||||
#include "../config/Config.h"
|
||||
#include "../Context.h"
|
||||
#include "../drawing/drawing.h"
|
||||
#include "../drawing/IDrawingEngine.h"
|
||||
#include "../drawing/lightfx.h"
|
||||
|
@ -134,8 +135,8 @@ void platform_update_palette(const uint8* colours, sint32 start_index, sint32 nu
|
|||
|
||||
void platform_init()
|
||||
{
|
||||
gKeysPressed = malloc(sizeof(uint8) * 256);
|
||||
memset(gKeysPressed, 0, sizeof(uint8) * 256);
|
||||
// gKeysPressed = malloc(sizeof(uint8) * 256);
|
||||
// memset(gKeysPressed, 0, sizeof(uint8) * 256);
|
||||
|
||||
// Set the highest palette entry to white.
|
||||
// This fixes a bug with the TT:rainbow road due to the
|
||||
|
@ -161,13 +162,13 @@ sint32 platform_scancode_to_rct_keycode(sint32 sdl_key)
|
|||
|
||||
void platform_free()
|
||||
{
|
||||
free(gKeysPressed);
|
||||
// free(gKeysPressed);
|
||||
}
|
||||
|
||||
void platform_toggle_windowed_mode()
|
||||
{
|
||||
sint32 targetMode = gConfigGeneral.fullscreen_mode == 0 ? 2 : 0;
|
||||
platform_set_fullscreen_mode(targetMode);
|
||||
context_set_fullscreen_mode(targetMode);
|
||||
gConfigGeneral.fullscreen_mode = targetMode;
|
||||
config_save_default();
|
||||
}
|
||||
|
|
|
@ -18,10 +18,9 @@
|
|||
|
||||
#include <vector>
|
||||
#include "../common.h"
|
||||
#include "../Context.h"
|
||||
#include "../interface/Cursors.h"
|
||||
|
||||
struct CursorState;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
namespace Drawing
|
||||
|
@ -39,22 +38,6 @@ namespace OpenRCT2
|
|||
FULLSCREEN_DESKTOP,
|
||||
};
|
||||
|
||||
struct TextInputSession
|
||||
{
|
||||
const utf8 * Buffer; // UTF-8 stream
|
||||
size_t BufferSize; // Maximum number of bytes (excluding null terminator)
|
||||
size_t Size; // Number of bytes (excluding null terminator)
|
||||
size_t Length; // Number of codepoints
|
||||
size_t SelectionStart; // Selection start, in bytes
|
||||
size_t SelectionSize; // Selection length in bytes
|
||||
};
|
||||
|
||||
struct Resolution
|
||||
{
|
||||
sint32 Width;
|
||||
sint32 Height;
|
||||
};
|
||||
|
||||
inline bool operator <(const Resolution& lhs, const Resolution& rhs)
|
||||
{
|
||||
sint32 areaA = lhs.Width * lhs.Height;
|
||||
|
@ -92,6 +75,7 @@ namespace OpenRCT2
|
|||
virtual std::vector<Resolution> GetFullscreenResolutions() abstract;
|
||||
virtual bool IsSteamOverlayActive() abstract;
|
||||
virtual void ProcessMessages() abstract;
|
||||
virtual void TriggerResize() abstract;
|
||||
|
||||
// Input
|
||||
virtual const CursorState * GetCursorState() abstract;
|
||||
|
@ -107,9 +91,9 @@ namespace OpenRCT2
|
|||
virtual Drawing::IDrawingEngine * CreateDrawingEngine(Drawing::DRAWING_ENGINE_TYPE type) abstract;
|
||||
|
||||
// Text input
|
||||
virtual bool IsTextInputActive() abstract;
|
||||
virtual const TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) abstract;
|
||||
virtual void StopTextInput() abstract;
|
||||
virtual bool IsTextInputActive() abstract;
|
||||
virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) abstract;
|
||||
virtual void StopTextInput() abstract;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "../audio/audio.h"
|
||||
#include "../config/Config.h"
|
||||
#include "../Context.h"
|
||||
#include "../game.h"
|
||||
#include "../editor.h"
|
||||
#include "../interface/widget.h"
|
||||
|
@ -1002,7 +1003,8 @@ static void window_editor_object_selection_scroll_mousedown(rct_window *w, sint3
|
|||
|
||||
window_invalidate(w);
|
||||
|
||||
audio_play_sound_panned(SOUND_CLICK_1, gCursorState.x, 0, 0, 0);
|
||||
const CursorState * state = context_get_cursor_state();
|
||||
audio_play_sound_panned(SOUND_CLICK_1, state->x, 0, 0, 0);
|
||||
|
||||
|
||||
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#pragma endregion
|
||||
|
||||
#include "../audio/audio.h"
|
||||
#include "../Context.h"
|
||||
#include "../interface/widget.h"
|
||||
#include "../interface/window.h"
|
||||
#include "../localisation/localisation.h"
|
||||
|
@ -120,10 +121,11 @@ void window_error_open(rct_string_id title, rct_string_id message)
|
|||
window_error_widgets[WIDX_BACKGROUND].right = width;
|
||||
window_error_widgets[WIDX_BACKGROUND].bottom = height;
|
||||
|
||||
x = gCursorState.x - (width / 2);
|
||||
const CursorState * state = context_get_cursor_state();
|
||||
x = state->x - (width / 2);
|
||||
x = clamp(0, x, gScreenWidth);
|
||||
|
||||
y = gCursorState.y + 26;
|
||||
y = state->y + 26;
|
||||
y = max(22, y);
|
||||
maxY = gScreenHeight - height;
|
||||
if (y > maxY) {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include "../Context.h"
|
||||
#include "../input.h"
|
||||
#include "../interface/widget.h"
|
||||
#include "../interface/window.h"
|
||||
|
@ -75,8 +76,9 @@ void window_map_tooltip_update_visibility()
|
|||
{
|
||||
sint32 cursorX, cursorY;
|
||||
|
||||
cursorX = gCursorState.x;
|
||||
cursorY = gCursorState.y;
|
||||
const CursorState * state = context_get_cursor_state();
|
||||
cursorX = state->x;
|
||||
cursorY = state->y;
|
||||
|
||||
// Check for cursor movement
|
||||
_cursorHoldDuration++;
|
||||
|
@ -112,8 +114,9 @@ static void window_map_tooltip_open()
|
|||
|
||||
width = 200;
|
||||
height = 44;
|
||||
x = gCursorState.x - (width / 2);
|
||||
y = gCursorState.y + 15;
|
||||
const CursorState * state = context_get_cursor_state();
|
||||
x = state->x - (width / 2);
|
||||
y = state->y + 15;
|
||||
|
||||
w = window_find_by_class(WC_MAP_TOOLTIP);
|
||||
if (w == NULL) {
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "../audio/audio.h"
|
||||
#include "../audio/AudioMixer.h"
|
||||
#include "../config/Config.h"
|
||||
#include "../Context.h"
|
||||
#include "../drawing/drawing.h"
|
||||
#include "../drawing/IDrawingEngine.h"
|
||||
#include "../interface/themes.h"
|
||||
|
@ -402,6 +403,7 @@ static void window_options_update_height_markers();
|
|||
|
||||
#pragma region Events
|
||||
|
||||
static void window_options_close(rct_window *w);
|
||||
static void window_options_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
||||
static void window_options_mousedown(rct_widgetindex widgetIndex, rct_window*w, rct_widget* widget);
|
||||
static void window_options_dropdown(rct_window *w, rct_widgetindex widgetIndex, sint32 dropdownIndex);
|
||||
|
@ -413,7 +415,7 @@ static void window_options_text_input(rct_window *w, rct_widgetindex widgetIndex
|
|||
static void window_options_tooltip(rct_window *w, rct_widgetindex widgetIndex, rct_string_id *stringid);
|
||||
|
||||
static rct_window_event_list window_options_events = {
|
||||
NULL,
|
||||
window_options_close,
|
||||
window_options_mouseup,
|
||||
NULL,
|
||||
window_options_mousedown,
|
||||
|
@ -565,6 +567,9 @@ static uint64 window_options_page_enabled_widgets[] = {
|
|||
|
||||
#pragma endregion
|
||||
|
||||
static struct Resolution * _resolutions = NULL;
|
||||
static sint32 _numResolutions = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006BAC5B
|
||||
|
@ -586,6 +591,12 @@ void window_options_open()
|
|||
window_init_scroll_widgets(w);
|
||||
}
|
||||
|
||||
static void window_options_close(rct_window *w)
|
||||
{
|
||||
free(_resolutions);
|
||||
_resolutions = NULL;
|
||||
_numResolutions = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -637,7 +648,7 @@ static void window_options_mouseup(rct_window *w, rct_widgetindex widgetIndex)
|
|||
gConfigGeneral.use_nn_at_integer_scales ^= 1;
|
||||
config_save_default();
|
||||
gfx_invalidate_screen();
|
||||
platform_trigger_resize();
|
||||
context_trigger_resize();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -931,24 +942,24 @@ static void window_options_mousedown(rct_widgetindex widgetIndex, rct_window*w,
|
|||
switch (widgetIndex) {
|
||||
case WIDX_RESOLUTION_DROPDOWN:
|
||||
{
|
||||
platform_update_fullscreen_resolutions();
|
||||
_numResolutions = context_get_resolutions(&_resolutions);
|
||||
|
||||
sint32 selectedResolution = -1;
|
||||
for (sint32 i = 0; i < gNumResolutions; i++) {
|
||||
resolution_t *resolution = &gResolutions[i];
|
||||
for (sint32 i = 0; i < _numResolutions; i++) {
|
||||
struct Resolution *resolution = &_resolutions[i];
|
||||
|
||||
gDropdownItemsFormat[i] = STR_DROPDOWN_MENU_LABEL;
|
||||
|
||||
uint16 *args = (uint16*)&gDropdownItemsArgs[i];
|
||||
args[0] = STR_RESOLUTION_X_BY_Y;
|
||||
args[1] = resolution->width;
|
||||
args[2] = resolution->height;
|
||||
args[1] = resolution->Width;
|
||||
args[2] = resolution->Height;
|
||||
|
||||
if (resolution->width == gConfigGeneral.fullscreen_width && resolution->height == gConfigGeneral.fullscreen_height)
|
||||
if (resolution->Width == gConfigGeneral.fullscreen_width && resolution->Height == gConfigGeneral.fullscreen_height)
|
||||
selectedResolution = i;
|
||||
}
|
||||
|
||||
window_options_show_dropdown(w, widget, gNumResolutions);
|
||||
window_options_show_dropdown(w, widget, _numResolutions);
|
||||
|
||||
if (selectedResolution != -1 && selectedResolution < 32) {
|
||||
dropdown_set_checked(selectedResolution, true);
|
||||
|
@ -987,14 +998,14 @@ static void window_options_mousedown(rct_widgetindex widgetIndex, rct_window*w,
|
|||
gConfigGeneral.window_scale += 0.25f;
|
||||
config_save_default();
|
||||
gfx_invalidate_screen();
|
||||
platform_trigger_resize();
|
||||
context_trigger_resize();
|
||||
break;
|
||||
case WIDX_SCALE_DOWN:
|
||||
gConfigGeneral.window_scale -= 0.25f;
|
||||
gConfigGeneral.window_scale = max(0.5f, gConfigGeneral.window_scale);
|
||||
config_save_default();
|
||||
gfx_invalidate_screen();
|
||||
platform_trigger_resize();
|
||||
context_trigger_resize();
|
||||
break;
|
||||
case WIDX_SCALE_QUALITY_DROPDOWN:
|
||||
gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL;
|
||||
|
@ -1259,13 +1270,13 @@ static void window_options_dropdown(rct_window *w, rct_widgetindex widgetIndex,
|
|||
switch (widgetIndex) {
|
||||
case WIDX_RESOLUTION_DROPDOWN:
|
||||
{
|
||||
resolution_t *resolution = &gResolutions[dropdownIndex];
|
||||
if (resolution->width != gConfigGeneral.fullscreen_width || resolution->height != gConfigGeneral.fullscreen_height) {
|
||||
gConfigGeneral.fullscreen_width = resolution->width;
|
||||
gConfigGeneral.fullscreen_height = resolution->height;
|
||||
struct Resolution *resolution = &_resolutions[dropdownIndex];
|
||||
if (resolution->Width != gConfigGeneral.fullscreen_width || resolution->Height != gConfigGeneral.fullscreen_height) {
|
||||
gConfigGeneral.fullscreen_width = resolution->Width;
|
||||
gConfigGeneral.fullscreen_height = resolution->Height;
|
||||
|
||||
if (gConfigGeneral.fullscreen_mode == SDL_WINDOW_FULLSCREEN)
|
||||
platform_set_fullscreen_mode(SDL_WINDOW_FULLSCREEN);
|
||||
context_set_fullscreen_mode(SDL_WINDOW_FULLSCREEN);
|
||||
|
||||
config_save_default();
|
||||
gfx_invalidate_screen();
|
||||
|
@ -1274,7 +1285,7 @@ static void window_options_dropdown(rct_window *w, rct_widgetindex widgetIndex,
|
|||
break;
|
||||
case WIDX_FULLSCREEN_DROPDOWN:
|
||||
if (dropdownIndex != gConfigGeneral.fullscreen_mode){
|
||||
platform_set_fullscreen_mode(dropdownIndex);
|
||||
context_set_fullscreen_mode(dropdownIndex);
|
||||
|
||||
gConfigGeneral.fullscreen_mode = (uint8)dropdownIndex;
|
||||
config_save_default();
|
||||
|
@ -1301,7 +1312,7 @@ static void window_options_dropdown(rct_window *w, rct_widgetindex widgetIndex,
|
|||
gConfigGeneral.scale_quality = (uint8)dropdownIndex;
|
||||
config_save_default();
|
||||
gfx_invalidate_screen();
|
||||
platform_trigger_resize();
|
||||
context_trigger_resize();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "../audio/audio.h"
|
||||
#include "../cheats.h"
|
||||
#include "../config/Config.h"
|
||||
#include "../Context.h"
|
||||
#include "../drawing/drawing.h"
|
||||
#include "../game.h"
|
||||
#include "../input.h"
|
||||
|
@ -3826,6 +3827,7 @@ void ride_construction_toolupdate_entrance_exit(sint32 screenX, sint32 screenY)
|
|||
*/
|
||||
void ride_construction_tooldown_construct(sint32 screenX, sint32 screenY)
|
||||
{
|
||||
const CursorState * state = context_get_cursor_state();
|
||||
sint32 trackType, trackDirection, rideIndex, edxRS16, x, y, z, properties, highestZ;
|
||||
rct_window *w;
|
||||
|
||||
|
@ -3923,7 +3925,7 @@ void ride_construction_tooldown_construct(sint32 screenX, sint32 screenY)
|
|||
zAttempts == 0 ||
|
||||
z < 0
|
||||
) {
|
||||
audio_play_sound_panned(SOUND_ERROR, gCursorState.x, x, y, z);
|
||||
audio_play_sound_panned(SOUND_ERROR, state->x, x, y, z);
|
||||
w = window_find_by_class(WC_RIDE_CONSTRUCTION);
|
||||
if (w != NULL){
|
||||
tool_set(w, WIDX_CONSTRUCT, TOOL_CROSSHAIR);
|
||||
|
@ -3995,7 +3997,7 @@ void ride_construction_tooldown_construct(sint32 screenX, sint32 screenY)
|
|||
_currentTrackAlternative = saveCurrentTrackAlternative;
|
||||
_currentTrackLiftHill = saveCurrentTrackLiftHill;
|
||||
|
||||
audio_play_sound_panned(SOUND_ERROR, gCursorState.x, x, y, z);
|
||||
audio_play_sound_panned(SOUND_ERROR, state->x, x, y, z);
|
||||
break;
|
||||
} else if (zAttempts >= 0) {
|
||||
z += 16;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#pragma endregion
|
||||
|
||||
#include "../audio/audio.h"
|
||||
#include "../Context.h"
|
||||
#include "../drawing/drawing.h"
|
||||
#include "../game.h"
|
||||
#include "../input.h"
|
||||
|
@ -728,13 +729,14 @@ static void window_scenery_event_07(rct_window *w)
|
|||
*/
|
||||
static void window_scenery_update(rct_window *w)
|
||||
{
|
||||
rct_window *other = window_find_from_point(gCursorState.x, gCursorState.y);
|
||||
const CursorState * state = context_get_cursor_state();
|
||||
rct_window *other = window_find_from_point(state->x, state->y);
|
||||
if (other == w) {
|
||||
sint32 window_x = gCursorState.x - w->x + 26;
|
||||
sint32 window_y = gCursorState.y - w->y;
|
||||
sint32 window_x = state->x - w->x + 26;
|
||||
sint32 window_y = state->y - w->y;
|
||||
|
||||
if (window_y < 44 || window_x <= w->width) {
|
||||
rct_widgetindex widgetIndex = window_find_widget_from_point(w, gCursorState.x, gCursorState.y);
|
||||
rct_widgetindex widgetIndex = window_find_widget_from_point(w, state->x, state->y);
|
||||
if (widgetIndex >= WIDX_SCENERY_TAB_CONTENT_PANEL) {
|
||||
w->scenery.hover_counter++;
|
||||
if (w->scenery.hover_counter < 8) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include "../config/Config.h"
|
||||
#include "../Context.h"
|
||||
#include "../platform/platform.h"
|
||||
#include "../interface/window.h"
|
||||
#include "../interface/widget.h"
|
||||
|
@ -147,7 +148,7 @@ void window_text_input_open(rct_window* call_w, rct_widgetindex call_widget, rct
|
|||
calling_number = call_w->number;
|
||||
calling_widget = call_widget;
|
||||
|
||||
platform_start_text_input(text_input, maxLength);
|
||||
gTextInput = context_start_text_input(text_input, maxLength);
|
||||
|
||||
window_init_scroll_widgets(w);
|
||||
w->colours[0] = call_w->colours[0];
|
||||
|
@ -208,7 +209,7 @@ void window_text_input_raw_open(rct_window* call_w, rct_widgetindex call_widget,
|
|||
calling_number = call_w->number;
|
||||
calling_widget = call_widget;
|
||||
|
||||
platform_start_text_input(text_input, maxLength);
|
||||
gTextInput = context_start_text_input(text_input, maxLength);
|
||||
|
||||
window_init_scroll_widgets(w);
|
||||
w->colours[0] = call_w->colours[0];
|
||||
|
@ -227,7 +228,7 @@ static void window_text_input_mouseup(rct_window *w, rct_widgetindex widgetIndex
|
|||
switch (widgetIndex){
|
||||
case WIDX_CANCEL:
|
||||
case WIDX_CLOSE:
|
||||
platform_stop_text_input();
|
||||
context_stop_text_input();
|
||||
// Pass back the text that has been entered.
|
||||
// ecx when zero means text input failed
|
||||
if (calling_w != NULL)
|
||||
|
@ -235,7 +236,7 @@ static void window_text_input_mouseup(rct_window *w, rct_widgetindex widgetIndex
|
|||
window_close(w);
|
||||
break;
|
||||
case WIDX_OKAY:
|
||||
platform_stop_text_input();
|
||||
context_stop_text_input();
|
||||
// Pass back the text that has been entered.
|
||||
// ecx when none zero means text input success
|
||||
if (calling_w != NULL)
|
||||
|
@ -285,19 +286,19 @@ static void window_text_input_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
|||
|
||||
size_t string_length = get_string_size(wrap_pointer) - 1;
|
||||
|
||||
if (!cur_drawn && (gTextInput.selection_offset <= char_count + string_length)) {
|
||||
if (!cur_drawn && (gTextInput->SelectionStart <= char_count + string_length)) {
|
||||
// Make a copy of the string for measuring the width.
|
||||
char temp_string[TEXT_INPUT_SIZE] = { 0 };
|
||||
memcpy(temp_string, wrap_pointer, gTextInput.selection_offset - char_count);
|
||||
memcpy(temp_string, wrap_pointer, gTextInput->SelectionStart - char_count);
|
||||
cursorX = w->x + 13 + gfx_get_string_width(temp_string);
|
||||
cursorY = y;
|
||||
|
||||
sint32 width = 6;
|
||||
if (gTextInput.selection_offset < strlen(text_input)){
|
||||
if (gTextInput->SelectionStart < strlen(text_input)){
|
||||
// Make a 1 utf8-character wide string for measuring the width
|
||||
// of the currently selected character.
|
||||
utf8 tmp[5] = { 0 }; // This is easier than setting temp_string[0..5]
|
||||
uint32 codepoint = utf8_get_next(text_input + gTextInput.selection_offset, NULL);
|
||||
uint32 codepoint = utf8_get_next(text_input + gTextInput->SelectionStart, NULL);
|
||||
utf8_write_codepoint(tmp, codepoint);
|
||||
width = max(gfx_get_string_width(tmp) - 2, 4);
|
||||
}
|
||||
|
@ -325,9 +326,9 @@ static void window_text_input_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
|||
}
|
||||
|
||||
// IME composition
|
||||
if (gTextInputCompositionActive) {
|
||||
draw_ime_composition(dpi, cursorX, cursorY);
|
||||
}
|
||||
// if (gTextInputCompositionActive) {
|
||||
// draw_ime_composition(dpi, cursorX, cursorY);
|
||||
// }
|
||||
}
|
||||
|
||||
void window_text_input_key(rct_window* w, sint32 key)
|
||||
|
@ -336,7 +337,7 @@ void window_text_input_key(rct_window* w, sint32 key)
|
|||
|
||||
// If the return button is pressed stop text input
|
||||
if (new_char == '\r'){
|
||||
platform_stop_text_input();
|
||||
context_stop_text_input();
|
||||
window_close(w);
|
||||
rct_window* calling_w = window_find_by_number(calling_class, calling_number);
|
||||
// Pass back the text that has been entered.
|
||||
|
@ -367,7 +368,7 @@ static void window_text_input_close(rct_window *w)
|
|||
{
|
||||
// Make sure that we take it out of the text input
|
||||
// mode otherwise problems may occur.
|
||||
platform_stop_text_input();
|
||||
context_stop_text_input();
|
||||
}
|
||||
|
||||
static void window_text_input_invalidate(rct_window *w)
|
||||
|
@ -401,13 +402,13 @@ static void window_text_input_invalidate(rct_window *w)
|
|||
|
||||
static void draw_ime_composition(rct_drawpixelinfo * dpi, int cursorX, int cursorY)
|
||||
{
|
||||
int compositionWidth = gfx_get_string_width(gTextInputComposition);
|
||||
int x = cursorX - (compositionWidth / 2);
|
||||
int y = cursorY + 13;
|
||||
int width = compositionWidth;
|
||||
int height = 10;
|
||||
// int compositionWidth = gfx_get_string_width(gTextInputComposition);
|
||||
// int x = cursorX - (compositionWidth / 2);
|
||||
// int y = cursorY + 13;
|
||||
// int width = compositionWidth;
|
||||
// int height = 10;
|
||||
|
||||
gfx_fill_rect(dpi, x - 1, y - 1, x + width + 1, y + height + 1, PALETTE_INDEX_12);
|
||||
gfx_fill_rect(dpi, x, y, x + width, y + height, PALETTE_INDEX_0);
|
||||
gfx_draw_string(dpi, gTextInputComposition, COLOUR_DARK_GREEN, x, y);
|
||||
// gfx_fill_rect(dpi, x - 1, y - 1, x + width + 1, y + height + 1, PALETTE_INDEX_12);
|
||||
// gfx_fill_rect(dpi, x, y, x + width, y + height, PALETTE_INDEX_0);
|
||||
// gfx_draw_string(dpi, gTextInputComposition, COLOUR_DARK_GREEN, x, y);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue