mirror of
https://github.com/celisej567/mcpe.git
synced 2025-12-31 17:49:17 +03:00
Merge pull request #91 into master
This commit is contained in:
@@ -16,17 +16,17 @@
|
||||
|
||||
void AppPlatform_sdl_base::_init(std::string storageDir, SDL_Window *window)
|
||||
{
|
||||
_storageDir = storageDir;
|
||||
_window = window;
|
||||
|
||||
_iconTexture = nullptr;
|
||||
_icon = nullptr;
|
||||
|
||||
m_bShiftPressed[0] = false;
|
||||
m_bShiftPressed[1] = false;
|
||||
_storageDir = storageDir;
|
||||
_window = window;
|
||||
|
||||
_iconTexture = nullptr;
|
||||
_icon = nullptr;
|
||||
|
||||
m_bShiftPressed[0] = false;
|
||||
m_bShiftPressed[1] = false;
|
||||
|
||||
ensureDirectoryExists(_storageDir.c_str());
|
||||
|
||||
ensureDirectoryExists(_storageDir.c_str());
|
||||
|
||||
m_pLogger = new Logger;
|
||||
m_pSoundSystem = nullptr;
|
||||
}
|
||||
@@ -52,11 +52,11 @@ void AppPlatform_sdl_base::setIcon(const Texture& icon)
|
||||
SAFE_DELETE(_iconTexture);
|
||||
if (_icon) SDL_FreeSurface(_icon);
|
||||
|
||||
_iconTexture = new Texture(icon);
|
||||
_icon = getSurfaceForTexture(_iconTexture);
|
||||
|
||||
if (_icon)
|
||||
SDL_SetWindowIcon(_window, _icon);
|
||||
_iconTexture = new Texture(icon);
|
||||
_icon = getSurfaceForTexture(_iconTexture);
|
||||
|
||||
if (_icon)
|
||||
SDL_SetWindowIcon(_window, _icon);
|
||||
}
|
||||
|
||||
AppPlatform_sdl_base::~AppPlatform_sdl_base()
|
||||
@@ -65,29 +65,29 @@ AppPlatform_sdl_base::~AppPlatform_sdl_base()
|
||||
SAFE_DELETE(_iconTexture);
|
||||
|
||||
SAFE_DELETE(m_pSoundSystem);
|
||||
|
||||
|
||||
// DELETE THIS LAST
|
||||
SAFE_DELETE(m_pLogger);
|
||||
}
|
||||
|
||||
SDL_Surface* AppPlatform_sdl_base::getSurfaceForTexture(const Texture* const texture)
|
||||
{
|
||||
if (!texture) return nullptr;
|
||||
|
||||
void * const pixels = texture->m_pixels;
|
||||
const int width = texture->m_width;
|
||||
const int height = texture->m_height;
|
||||
const int depth = 32; // Color depth (32-bit by default)
|
||||
SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(
|
||||
pixels, width, height, depth,
|
||||
width * 4, // Pitch
|
||||
0x000000FF, 0x0000FF00, 0x00FF0000,
|
||||
0xFF000000
|
||||
);
|
||||
if (!surface)
|
||||
LOG_E("Failed loading SDL_Surface from Texture: %s", SDL_GetError());
|
||||
|
||||
return surface;
|
||||
if (!texture) return nullptr;
|
||||
|
||||
void * const pixels = texture->m_pixels;
|
||||
const int width = texture->m_width;
|
||||
const int height = texture->m_height;
|
||||
const int depth = 32; // Color depth (32-bit by default)
|
||||
SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(
|
||||
pixels, width, height, depth,
|
||||
width * 4, // Pitch
|
||||
0x000000FF, 0x0000FF00, 0x00FF0000,
|
||||
0xFF000000
|
||||
);
|
||||
if (!surface)
|
||||
LOG_E("Failed loading SDL_Surface from Texture: %s", SDL_GetError());
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
int AppPlatform_sdl_base::checkLicense()
|
||||
@@ -98,7 +98,7 @@ int AppPlatform_sdl_base::checkLicense()
|
||||
|
||||
const char* const AppPlatform_sdl_base::getWindowTitle() const
|
||||
{
|
||||
return SDL_GetWindowTitle(_window);
|
||||
return SDL_GetWindowTitle(_window);
|
||||
}
|
||||
|
||||
int AppPlatform_sdl_base::getScreenWidth() const
|
||||
@@ -185,11 +185,15 @@ bool AppPlatform_sdl_base::GetMouseButtonState(SDL_Event event)
|
||||
{
|
||||
short wheelDelta = event.wheel.y;
|
||||
if (wheelDelta > 0)
|
||||
{
|
||||
// "A positive value indicates that the wheel was rotated forward, away from the user."
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// "A negative value indicates that the wheel was rotated backward, toward the user."
|
||||
result = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -46,23 +46,23 @@ public:
|
||||
static Keyboard::KeyState GetKeyState(SDL_Event event);
|
||||
private:
|
||||
SDL_Window *_window;
|
||||
|
||||
const Texture *_iconTexture;
|
||||
SDL_Surface *_icon;
|
||||
|
||||
const Texture *_iconTexture;
|
||||
SDL_Surface *_icon;
|
||||
|
||||
bool m_bShiftPressed[2];
|
||||
|
||||
int xrel;
|
||||
int yrel;
|
||||
|
||||
|
||||
Logger* m_pLogger;
|
||||
SoundSystem* m_pSoundSystem;
|
||||
|
||||
static SDL_Surface* getSurfaceForTexture(const Texture* const texture);
|
||||
|
||||
static SDL_Surface* getSurfaceForTexture(const Texture* const texture);
|
||||
protected:
|
||||
std::string _storageDir;
|
||||
std::string _storageDir;
|
||||
|
||||
virtual void ensureDirectoryExists(const char* path) { }
|
||||
|
||||
|
||||
void setIcon(const Texture& icon); // note: this takes ownership of the texture, so no memory leaks!
|
||||
};
|
||||
|
||||
@@ -43,6 +43,60 @@ static int TranslateSDLKeyCodeToVirtual(int sdlCode)
|
||||
return SDLVK_UNKNOWN;
|
||||
}
|
||||
|
||||
// Touch
|
||||
#define TOUCH_IDS_SIZE (MAX_TOUCHES - 1) // ID 0 Is Reserved For The Mouse
|
||||
struct touch_id_data {
|
||||
bool active = false;
|
||||
int id;
|
||||
};
|
||||
static touch_id_data touch_ids[TOUCH_IDS_SIZE];
|
||||
static char get_touch_id(int device, int finger) {
|
||||
int real_id = (device * 100) + finger;
|
||||
for (int i = 0; i < TOUCH_IDS_SIZE; i++) {
|
||||
touch_id_data &data = touch_ids[i];
|
||||
if (data.active && data.id == real_id) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
// Not Found
|
||||
for (int i = 0; i < TOUCH_IDS_SIZE; i++) {
|
||||
// Find First Inactive ID, And Activate It
|
||||
touch_id_data &data = touch_ids[i];
|
||||
if (!data.active) {
|
||||
data.active = true;
|
||||
data.id = real_id;
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
// Fail
|
||||
return 0;
|
||||
}
|
||||
static void drop_touch_id(int id) {
|
||||
touch_ids[id - 1].active = false;
|
||||
}
|
||||
static void handle_touch(int x, int y, int type, char id) {
|
||||
if (id == 0) {
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_FINGERUP: {
|
||||
bool data = type == SDL_FINGERUP ? 0 : 1;
|
||||
Mouse::feed(BUTTON_LEFT, data, x, y);
|
||||
Multitouch::feed(BUTTON_LEFT, data, x, y, id);
|
||||
if (type == SDL_FINGERUP) {
|
||||
drop_touch_id(id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_FINGERMOTION: {
|
||||
Mouse::feed(BUTTON_NONE, 0, x, y);
|
||||
Multitouch::feed(BUTTON_NONE, 0, x, y, id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resize From JS
|
||||
#ifdef __EMSCRIPTEN__
|
||||
extern "C" void resize_from_js(int new_width, int new_height)
|
||||
@@ -87,24 +141,42 @@ static void handle_events()
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
const float scale = g_fPointToPixelScale;
|
||||
Mouse::feed(AppPlatform_sdl_base::GetMouseButtonType(event), AppPlatform_sdl_base::GetMouseButtonState(event), event.button.x * scale, event.button.y * scale);
|
||||
Multitouch::feed(AppPlatform_sdl_base::GetMouseButtonType(event), AppPlatform_sdl_base::GetMouseButtonState(event), event.button.x * scale, event.button.y * scale, 0);
|
||||
if (event.button.which != SDL_TOUCH_MOUSEID) {
|
||||
const float scale = g_fPointToPixelScale;
|
||||
MouseButtonType type = AppPlatform_sdl_base::GetMouseButtonType(event);
|
||||
bool state = AppPlatform_sdl_base::GetMouseButtonState(event);
|
||||
float x = event.button.x * scale;
|
||||
float y = event.button.y * scale;
|
||||
Mouse::feed(type, state, x, y);
|
||||
Multitouch::feed(type, state, x, y, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
float scale = g_fPointToPixelScale;
|
||||
float x = event.motion.x * scale;
|
||||
float y = event.motion.y * scale;
|
||||
Mouse::feed(BUTTON_NONE, false, x, y);
|
||||
Multitouch::feed(BUTTON_NONE, false, x, y, 0);
|
||||
g_pAppPlatform->setMouseDiff(event.motion.xrel * scale, event.motion.yrel * scale);
|
||||
if (event.button.which != SDL_TOUCH_MOUSEID) {
|
||||
float scale = g_fPointToPixelScale;
|
||||
float x = event.motion.x * scale;
|
||||
float y = event.motion.y * scale;
|
||||
Multitouch::feed(BUTTON_NONE, 0, x, y, 0);
|
||||
Mouse::feed(BUTTON_NONE, false, x, y);
|
||||
g_pAppPlatform->setMouseDiff(event.motion.xrel * scale, event.motion.yrel * scale);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEWHEEL:
|
||||
{
|
||||
Mouse::feed(BUTTON_SCROLLWHEEL, AppPlatform_sdl_base::GetMouseButtonState(event), Mouse::getX(), Mouse::getY());
|
||||
if (event.button.which != SDL_TOUCH_MOUSEID) {
|
||||
Mouse::feed(BUTTON_SCROLLWHEEL, AppPlatform_sdl_base::GetMouseButtonState(event), Mouse::getX(), Mouse::getY());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_FINGERUP:
|
||||
case SDL_FINGERMOTION: {
|
||||
float x = event.tfinger.x * Minecraft::width;
|
||||
float y = event.tfinger.y * Minecraft::height;
|
||||
handle_touch(x, y, event.type, get_touch_id(event.tfinger.touchId, event.tfinger.fingerId));
|
||||
break;
|
||||
}
|
||||
case SDL_TEXTINPUT:
|
||||
|
||||
@@ -90,21 +90,21 @@ add_library(reminecraftpe-core STATIC
|
||||
client/player/input/MouseTurnInput.cpp
|
||||
client/player/input/KeyboardInput.cpp
|
||||
client/player/input/ITurnInput.cpp
|
||||
client/player/input/IBuildInput.cpp
|
||||
client/player/input/IncludeExcludeArea.cpp
|
||||
client/player/input/MouseHandler.cpp
|
||||
client/player/input/PolygonArea.cpp
|
||||
client/player/input/RectangleArea.cpp
|
||||
client/player/input/MouseDevice.cpp
|
||||
client/player/input/Multitouch.cpp
|
||||
client/player/input/CustomInputHolder.cpp
|
||||
client/player/input/IInputHolder.cpp
|
||||
client/player/input/IMoveInput.cpp
|
||||
client/player/input/ITouchScreenModel.cpp
|
||||
client/player/input/TouchAreaModel.cpp
|
||||
client/player/input/TouchInputHolder.cpp
|
||||
client/player/input/TouchscreenInput_TestFps.cpp
|
||||
client/player/input/UnifiedTurnBuild.cpp
|
||||
client/player/input/IBuildInput.cpp
|
||||
client/player/input/IncludeExcludeArea.cpp
|
||||
client/player/input/MouseHandler.cpp
|
||||
client/player/input/PolygonArea.cpp
|
||||
client/player/input/RectangleArea.cpp
|
||||
client/player/input/MouseDevice.cpp
|
||||
client/player/input/Multitouch.cpp
|
||||
client/player/input/CustomInputHolder.cpp
|
||||
client/player/input/IInputHolder.cpp
|
||||
client/player/input/IMoveInput.cpp
|
||||
client/player/input/ITouchScreenModel.cpp
|
||||
client/player/input/TouchAreaModel.cpp
|
||||
client/player/input/TouchInputHolder.cpp
|
||||
client/player/input/TouchscreenInput_TestFps.cpp
|
||||
client/player/input/UnifiedTurnBuild.cpp
|
||||
client/network/ClientSideNetworkHandler.cpp
|
||||
network/packets/UpdateBlockPacket.cpp
|
||||
network/packets/RequestChunkPacket.cpp
|
||||
|
||||
Reference in New Issue
Block a user