2017-03-24 03:47:43 +01:00
|
|
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
|
|
|
/*****************************************************************************
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
|
|
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
|
|
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* A full copy of the GNU General Public License can be found in licence.txt
|
|
|
|
*****************************************************************************/
|
|
|
|
#pragma endregion
|
|
|
|
|
2017-03-25 04:16:40 +01:00
|
|
|
#include <exception>
|
2017-03-26 04:36:22 +02:00
|
|
|
#include "core/Memory.hpp"
|
2017-03-25 18:42:14 +01:00
|
|
|
#include "config/Config.h"
|
2017-03-24 03:47:43 +01:00
|
|
|
#include "Context.h"
|
|
|
|
#include "OpenRCT2.h"
|
2017-03-25 15:57:02 +01:00
|
|
|
#include "ui/UiContext.h"
|
2017-03-24 03:47:43 +01:00
|
|
|
|
|
|
|
using namespace OpenRCT2;
|
2017-03-25 04:16:40 +01:00
|
|
|
using namespace OpenRCT2::Ui;
|
2017-03-24 03:47:43 +01:00
|
|
|
|
2017-03-25 04:16:40 +01:00
|
|
|
namespace OpenRCT2
|
2017-03-24 03:47:43 +01:00
|
|
|
{
|
2017-03-25 04:16:40 +01:00
|
|
|
class Context : public IContext
|
2017-03-24 03:47:43 +01:00
|
|
|
{
|
2017-03-25 04:16:40 +01:00
|
|
|
private:
|
|
|
|
IUiContext * const _uiContext;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Singleton of Context.
|
|
|
|
// Remove this when GetContext() is no longer called so that
|
|
|
|
// multiple instances can be created in parallel
|
|
|
|
static Context * Instance;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Context(IUiContext * uiContext)
|
|
|
|
: _uiContext(uiContext)
|
|
|
|
{
|
|
|
|
Instance = this;
|
|
|
|
}
|
2017-03-24 03:47:43 +01:00
|
|
|
|
2017-03-25 04:16:40 +01:00
|
|
|
~Context() override
|
|
|
|
{
|
|
|
|
Instance = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUiContext * GetUiContext() override
|
|
|
|
{
|
|
|
|
return _uiContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
sint32 RunOpenRCT2(int argc, char * * argv) override
|
|
|
|
{
|
|
|
|
core_init();
|
|
|
|
int runGame = cmdline_run((const char * *)argv, argc);
|
|
|
|
if (runGame == 1)
|
|
|
|
{
|
|
|
|
openrct2_launch();
|
|
|
|
}
|
|
|
|
return gExitCode;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Context * Context::Instance = nullptr;
|
|
|
|
|
|
|
|
IContext * CreateContext()
|
2017-03-24 03:47:43 +01:00
|
|
|
{
|
2017-03-25 04:16:40 +01:00
|
|
|
return new Context(nullptr);
|
2017-03-24 03:47:43 +01:00
|
|
|
}
|
|
|
|
|
2017-03-25 04:16:40 +01:00
|
|
|
IContext * CreateContext(IUiContext * uiContext)
|
2017-03-24 17:26:43 +01:00
|
|
|
{
|
2017-03-25 04:16:40 +01:00
|
|
|
return new Context(uiContext);
|
2017-03-24 17:26:43 +01:00
|
|
|
}
|
|
|
|
|
2017-03-25 04:16:40 +01:00
|
|
|
IContext * GetContext()
|
2017-03-24 03:47:43 +01:00
|
|
|
{
|
2017-03-25 04:16:40 +01:00
|
|
|
return Context::Instance;
|
2017-03-24 03:47:43 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-25 15:57:02 +01:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
void context_setcurrentcursor(sint32 cursor)
|
|
|
|
{
|
|
|
|
GetContext()->GetUiContext()->SetCursor((CURSOR_ID)cursor);
|
|
|
|
}
|
2017-03-25 18:42:14 +01:00
|
|
|
|
|
|
|
void context_hide_cursor()
|
|
|
|
{
|
|
|
|
GetContext()->GetUiContext()->SetCursorVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_show_cursor()
|
|
|
|
{
|
|
|
|
GetContext()->GetUiContext()->SetCursorVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_get_cursor_position(sint32 * x, sint32 * y)
|
|
|
|
{
|
|
|
|
GetContext()->GetUiContext()->GetCursorPosition(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_get_cursor_position_scaled(sint32 * x, sint32 * y)
|
|
|
|
{
|
|
|
|
context_get_cursor_position(x, y);
|
|
|
|
|
|
|
|
// Compensate for window scaling.
|
|
|
|
*x = (sint32)ceilf(*x / gConfigGeneral.window_scale);
|
|
|
|
*y = (sint32)ceilf(*y / gConfigGeneral.window_scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_set_cursor_position(sint32 x, sint32 y)
|
|
|
|
{
|
|
|
|
GetContext()->GetUiContext()->SetCursorPosition(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
const CursorState * context_get_cursor_state()
|
|
|
|
{
|
|
|
|
return GetContext()->GetUiContext()->GetCursorState();
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8 * context_get_keys_state()
|
|
|
|
{
|
|
|
|
return GetContext()->GetUiContext()->GetKeysState();
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8 * context_get_keys_pressed()
|
|
|
|
{
|
|
|
|
return GetContext()->GetUiContext()->GetKeysPressed();
|
|
|
|
}
|
|
|
|
|
2017-03-26 04:36:22 +02:00
|
|
|
TextInputSession * context_start_text_input(utf8 * buffer, size_t maxLength)
|
2017-03-25 18:42:14 +01:00
|
|
|
{
|
2017-03-26 04:36:22 +02:00
|
|
|
return GetContext()->GetUiContext()->StartTextInput(buffer, maxLength);
|
2017-03-25 18:42:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void context_stop_text_input()
|
|
|
|
{
|
|
|
|
GetContext()->GetUiContext()->StopTextInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool context_is_input_active()
|
|
|
|
{
|
|
|
|
return GetContext()->GetUiContext()->IsTextInputActive();
|
|
|
|
}
|
2017-03-26 04:36:22 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-03-25 15:57:02 +01:00
|
|
|
}
|