Files
mcpe/platforms/sdl/AppPlatform_sdlbase.hpp
Brent Da Mage d5ee7bfc08 Cleaned Up AppPlatform & Input Classes
* Cleaned up AppPlatform classes
* Documented & improved Keyboard & Mouse classes
* Improved input-handling code in the Windows & SDL main.cpp files
2023-08-19 15:57:50 +03:00

63 lines
1.7 KiB
C++

#pragma once
#include <string>
#include <SDL2/SDL.h>
#include "AppPlatform.hpp"
#include "client/player/input/Mouse.hpp"
#include "client/player/input/Keyboard.hpp"
class AppPlatform_sdlbase : public AppPlatform
{
public:
void _init(std::string storageDir, SDL_Window *window);
void _init(std::string storageDir, SDL_Window *window, const Texture& icon);
AppPlatform_sdlbase(std::string storageDir, SDL_Window *window)
{
_init(storageDir, window);
}
AppPlatform_sdlbase(std::string storageDir, SDL_Window *window, const Texture& icon)
{
_init(storageDir, window, icon);
}
~AppPlatform_sdlbase();
int checkLicense() override;
const char* const getWindowTitle() const;
int getScreenWidth() const override;
int getScreenHeight() const override;
Texture loadTexture(const std::string& path, bool b = false) override = 0;
int getUserInputStatus() override;
// Also add these to allow proper turning within the game.
void setMouseGrabbed(bool b) override;
void setMouseDiff(int x, int y);
void getMouseDiff(int& x, int& y) override;
void clearDiff() override;
// Also add these to allow proper text input within the game.
bool shiftPressed() override;
void setShiftPressed(bool b, bool isLeft);
static Mouse::ButtonType GetMouseButtonType(SDL_Event event);
static Mouse::ButtonState GetMouseButtonState(SDL_Event event);
static Keyboard::KeyState GetKeyState(SDL_Event event);
private:
SDL_Window *_window;
const Texture *_iconTexture;
SDL_Surface *_icon;
bool m_bShiftPressed[2];
int xrel;
int yrel;
static SDL_Surface* getSurfaceForTexture(const Texture* const texture);
protected:
std::string _storageDir;
virtual void ensureDirectoryExists(const char* path) { }
};