First step of SFML migration.

This commit is contained in:
Quentin Bazin 2020-05-11 17:30:54 +02:00
parent dc1b7147c8
commit 333222e2a7
60 changed files with 243 additions and 306 deletions

4
.gitmodules vendored
View File

@ -2,10 +2,6 @@
path = external/entt
url = git://github.com/skypjack/entt.git
ignore = dirty
[submodule "external/SFML"]
path = external/SFML
url = git://github.com/SFML/SFML.git
ignore = dirty
[submodule "external/gamekit"]
path = external/gamekit
url = git://github.com/Unarelith/GameKit.git

View File

@ -7,7 +7,7 @@ project(openminer)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if (WIN32)
set(WIN_LIBRARIES_PATH "C:/Libraries")
@ -98,47 +98,6 @@ endif(NOT GLM_FOUND)
include_directories(${GLM_INCLUDE_DIRS})
#------------------------------------------------------------------------------
# - SDL2, SDL2_image, SDL2_mixer
#------------------------------------------------------------------------------
if (MSVC)
set(SDL2_PATH ${WIN_LIBRARIES_PATH}/SDL2 CACHE BOOL "" FORCE)
set(SDL2_IMAGE_PATH ${WIN_LIBRARIES_PATH}/SDL2_image CACHE BOOL "" FORCE)
set(SDL2_MIXER_PATH ${WIN_LIBRARIES_PATH}/SDL2_mixer CACHE BOOL "" FORCE)
set(SDL2_TTF_PATH ${WIN_LIBRARIES_PATH}/SDL2_ttf CACHE BOOL "" FORCE)
elseif (WIN32)
set(SDL2_PATH ${WIN_LIBRARIES_PATH}/SDL2/i686-w64-mingw32 CACHE BOOL "" FORCE)
set(SDL2_IMAGE_PATH ${WIN_LIBRARIES_PATH}/SDL2_image/i686-w64-mingw32 CACHE BOOL "" FORCE)
set(SDL2_MIXER_PATH ${WIN_LIBRARIES_PATH}/SDL2_mixer/i686-w64-mingw32 CACHE BOOL "" FORCE)
set(SDL2_TTF_PATH ${WIN_LIBRARIES_PATH}/SDL2_ttf/i686-w64-mingw32 CACHE BOOL "" FORCE)
endif ()
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(SDL2_ttf REQUIRED)
if(NOT SDL2_FOUND)
message(FATAL_ERROR "SDL2 not found!")
endif(NOT SDL2_FOUND)
if(NOT SDL2_IMAGE_FOUND)
message(FATAL_ERROR "SDL2_image not found!")
endif(NOT SDL2_IMAGE_FOUND)
if(NOT SDL2_MIXER_FOUND)
message(FATAL_ERROR "SDL2_mixer not found!")
endif(NOT SDL2_MIXER_FOUND)
if(NOT SDL2_TTF_FOUND)
message(FATAL_ERROR "SDL2_ttf not found!")
endif(NOT SDL2_TTF_FOUND)
include_directories(${SDL2_INCLUDE_DIRS}
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_MIXER_INCLUDE_DIRS}
${SDL2_TTF_INCLUDE_DIRS})
#------------------------------------------------------------------------------
# - GLEW
#------------------------------------------------------------------------------
@ -189,18 +148,6 @@ include_directories(external/entt/single_include)
add_subdirectory(external/gamekit)
include_directories(external/gamekit/include)
#------------------------------------------------------------------------------
# - SFML network
#------------------------------------------------------------------------------
set(SFML_BUILD_AUDIO FALSE)
set(SFML_BUILD_GRAPHICS FALSE)
set(SFML_BUILD_WINDOW FALSE)
set(SFML_STATIC TRUE)
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(external/SFML)
#------------------------------------------------------------------------------
# - zlib
#------------------------------------------------------------------------------

1
external/SFML vendored

@ -1 +0,0 @@
Subproject commit 50e173e403ef8912e3d8ac3c7ab3e27e32243339

2
external/gamekit vendored

@ -1 +1 @@
Subproject commit d39510fa3920197ddff588aacf5a15175e67887a
Subproject commit 4459bb5cb5b99c5265930fde9276b763b0969fa5

View File

@ -52,15 +52,14 @@ target_link_libraries(${PROJECT_NAME}
${CMAKE_PROJECT_NAME}_common
gamekit
${OPENGL_LIBRARIES}
${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${TINYXML2_LIBRARIES}
${GLEW_LIBRARIES}
${LUA_LIBRARIES}
sfml-system
sfml-window
sfml-network
sfml-graphics
sfml-audio
zlib
${UNIX_LIBS})

View File

@ -104,21 +104,22 @@ void ClientApplication::init() {
void ClientApplication::handleEvents() {
gk::CoreApplication::handleEvents();
if ((Config::isFullscreenModeEnabled && m_window.getWindowMode() != gk::Window::Mode::Fullscreen)
|| (!Config::isFullscreenModeEnabled && m_window.getWindowMode() != gk::Window::Mode::Windowed)) {
m_window.setWindowMode(Config::isFullscreenModeEnabled ? gk::Window::Mode::Fullscreen : gk::Window::Mode::Windowed);
}
if (Config::screenWidth != m_window.getSize().x || Config::screenHeight != m_window.getSize().y) {
m_window.resize(Config::screenWidth, Config::screenHeight);
}
if (Config::isVerticalSyncEnabled != m_window.isVerticalSyncEnabled())
m_window.setVerticalSyncEnabled(Config::isVerticalSyncEnabled);
// FIXME: SFML
// if ((Config::isFullscreenModeEnabled && m_window.getWindowMode() != gk::Window::Mode::Fullscreen)
// || (!Config::isFullscreenModeEnabled && m_window.getWindowMode() != gk::Window::Mode::Windowed)) {
// m_window.setWindowMode(Config::isFullscreenModeEnabled ? gk::Window::Mode::Fullscreen : gk::Window::Mode::Windowed);
// }
//
// if (Config::screenWidth != m_window.getSize().x || Config::screenHeight != m_window.getSize().y) {
// m_window.resize(Config::screenWidth, Config::screenHeight);
// }
//
// if (Config::isVerticalSyncEnabled != m_window.isVerticalSyncEnabled())
// m_window.setVerticalSyncEnabled(Config::isVerticalSyncEnabled);
}
void ClientApplication::onEvent(const SDL_Event &event) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F11)
void ClientApplication::onEvent(const sf::Event &event) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F11)
Config::isFullscreenModeEnabled ^= 1;
}

View File

@ -41,7 +41,7 @@ class ClientApplication : public gk::CoreApplication {
private:
void handleEvents() override;
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void initOpenGL();

View File

@ -248,7 +248,7 @@ static constexpr float modelCoords[NUM_QUADS * NUM_VERTICES_PER_QUAD][NUM_VERTEX
PlayerBox::PlayerBox(const gk::Camera &camera)
: m_camera(camera),
m_texture(gk::ResourceHandler::getInstance().get<gk::Texture>("texture-player"))
m_texture(gk::ResourceHandler::getInstance().get<sf::Texture>("texture-player"))
{
updateVertexBuffer();
}

View File

@ -27,11 +27,12 @@
#ifndef PLAYERBOX_HPP_
#define PLAYERBOX_HPP_
#include <SFML/Graphics/Texture.hpp>
#include <gk/gl/Camera.hpp>
#include <gk/gl/Drawable.hpp>
#include <gk/gl/VertexBuffer.hpp>
#include <gk/gl/Transformable.hpp>
#include <gk/gl/Texture.hpp>
#include "Player.hpp"
@ -52,7 +53,7 @@ class PlayerBox : public gk::Drawable, public gk::Transformable, public Player {
const gk::Camera &m_camera;
gk::Texture &m_texture;
sf::Texture &m_texture;
};
#endif // PLAYERBOX_HPP_

View File

@ -26,6 +26,7 @@
*/
#include <gk/core/Exception.hpp>
#include <gk/core/Filesystem.hpp>
#include <gk/gl/OpenGL.hpp>
#include "Registry.hpp"
#include "TextureAtlas.hpp"
@ -37,75 +38,78 @@ void TextureAtlas::addFile(const std::string &path, const std::string &filename)
if (it != m_textureMap.end())
return;
SurfacePtr surface{IMG_Load((path + filename).c_str()), &SDL_FreeSurface};
if(!surface) {
gkWarning() << "Failed to load texture:" << path + filename;
return;
}
if (!m_tileSize)
m_tileSize = surface->w;
if (m_tileSize != surface->w || m_tileSize != surface->h)
throw EXCEPTION("Texture size unexpected for", path + filename + ". Got", surface->w, surface->h, "instead of", m_tileSize, m_tileSize);
m_textureMap.emplace(filename, m_textures.size());
m_textures.emplace_back(std::move(surface));
// FIXME: SFML
// SurfacePtr surface{IMG_Load((path + filename).c_str()), &SDL_FreeSurface};
// if(!surface) {
// gkWarning() << "Failed to load texture:" << path + filename;
// return;
// }
//
// if (!m_tileSize)
// m_tileSize = surface->w;
//
// if (m_tileSize != surface->w || m_tileSize != surface->h)
// throw EXCEPTION("Texture size unexpected for", path + filename + ". Got", surface->w, surface->h, "instead of", m_tileSize, m_tileSize);
//
// m_textureMap.emplace(filename, m_textures.size());
// m_textures.emplace_back(std::move(surface));
}
void TextureAtlas::packTextures() {
if (!m_tileSize)
throw EXCEPTION("Cannot pack zero-sized textures!");
SurfacePtr atlas{nullptr, &SDL_FreeSurface};
// Max amount of textures on one line
const u16 atlasWidth = 16;
// Max amount of textures on one column
const u16 atlasHeight = std::ceil((float)m_textures.size() / atlasWidth);
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
atlas.reset(SDL_CreateRGBSurface(0, atlasWidth * m_tileSize, atlasHeight * m_tileSize, 32, rmask, gmask, bmask, amask));
if (!atlas) {
throw EXCEPTION("Failed to create surface:", SDL_GetError());
}
u16 i = 0;
for (auto &it : m_textures) {
SDL_Rect outRect;
outRect.x = (i % atlasWidth) * m_tileSize;
outRect.y = (i / atlasWidth) * m_tileSize;
outRect.w = m_tileSize;
outRect.h = m_tileSize;
SDL_BlitSurface(it.get(), nullptr, atlas.get(), &outRect);
++i;
}
m_textures.clear();
// FIXME: SFML
// SurfacePtr atlas{nullptr, &SDL_FreeSurface};
//
// // Max amount of textures on one line
// const u16 atlasWidth = 16;
//
// // Max amount of textures on one column
// const u16 atlasHeight = std::ceil((float)m_textures.size() / atlasWidth);
//
// Uint32 rmask, gmask, bmask, amask;
// #if SDL_BYTEORDER == SDL_BIG_ENDIAN
// rmask = 0xff000000;
// gmask = 0x00ff0000;
// bmask = 0x0000ff00;
// amask = 0x000000ff;
// #else
// rmask = 0x000000ff;
// gmask = 0x0000ff00;
// bmask = 0x00ff0000;
// amask = 0xff000000;
// #endif
//
// atlas.reset(SDL_CreateRGBSurface(0, atlasWidth * m_tileSize, atlasHeight * m_tileSize, 32, rmask, gmask, bmask, amask));
// if (!atlas) {
// throw EXCEPTION("Failed to create surface:", SDL_GetError());
// }
//
// u16 i = 0;
// for (auto &it : m_textures) {
// SDL_Rect outRect;
// outRect.x = (i % atlasWidth) * m_tileSize;
// outRect.y = (i / atlasWidth) * m_tileSize;
// outRect.w = m_tileSize;
// outRect.h = m_tileSize;
//
// SDL_BlitSurface(it.get(), nullptr, atlas.get(), &outRect);
//
// ++i;
// }
//
// m_textures.clear();
m_isReady = true;
if (IMG_SavePNG(atlas.get(), "test_atlas.png") < 0)
throw EXCEPTION("Failed to save texture to: test_atlas.png. Reason:", IMG_GetError());
// FIXME: SFML
// if (IMG_SavePNG(atlas.get(), "test_atlas.png") < 0)
// throw EXCEPTION("Failed to save texture to: test_atlas.png. Reason:", IMG_GetError());
//
// m_texture.loadFromSurface(atlas.get());
m_texture.loadFromSurface(atlas.get());
gk::Texture::bind(&m_texture);
sf::Texture::bind(&m_texture);
glGenerateMipmap(GL_TEXTURE_2D);
@ -115,7 +119,7 @@ void TextureAtlas::packTextures() {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gk::Texture::bind(nullptr);
sf::Texture::bind(nullptr);
}
void TextureAtlas::loadFromRegistry(const std::string &texturePack) {

View File

@ -32,10 +32,10 @@
#include <unordered_map>
#include <vector>
#include <SFML/Graphics/Texture.hpp>
#include <gk/core/IntTypes.hpp>
#include <gk/core/SDLHeaders.hpp>
#include <gk/core/Rect.hpp>
#include <gk/gl/Texture.hpp>
class TextureAtlas {
public:
@ -49,7 +49,7 @@ class TextureAtlas {
u16 getTextureID(const std::string &filename) const;
gk::FloatRect getTexCoords(const std::string &filename, bool normalized = true) const;
const gk::Texture &texture() const { return m_texture; }
const sf::Texture &texture() const { return m_texture; }
bool isReady() const { return m_isReady; }
@ -60,12 +60,8 @@ class TextureAtlas {
// Mapping between filename and internal texture ID
std::unordered_map<std::string, u16> m_textureMap;
// Textures to pack together
using SurfacePtr = std::unique_ptr<SDL_Surface, decltype(&SDL_FreeSurface)>;
std::vector<SurfacePtr> m_textures;
// Packed texture
gk::Texture m_texture;
sf::Texture m_texture;
// Is the texture atlas ready to use?
bool m_isReady = false;

View File

@ -43,7 +43,7 @@ void CraftingWidget::init(unsigned int offset, unsigned int size) {
m_craftingResultInventoryWidget.setShiftDestination(m_shiftDestination);
}
void CraftingWidget::onEvent(const SDL_Event &event) {
void CraftingWidget::onEvent(const sf::Event &event) {
m_craftingInventoryWidget.onEvent(event);
m_craftingResultInventoryWidget.onEvent(event);

View File

@ -37,7 +37,7 @@ class CraftingWidget : public AbstractInventoryWidget {
void init(unsigned int offset = 0, unsigned int size = 3);
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void update() override;

View File

@ -26,13 +26,14 @@
*/
#include <fstream>
#include <gk/gl/Texture.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <gk/resource/ResourceHandler.hpp>
#include "Font.hpp"
Font::Font(const std::string &textureName, const std::string &configPath)
: m_texture(gk::ResourceHandler::getInstance().get<gk::Texture>(textureName))
: m_texture(gk::ResourceHandler::getInstance().get<sf::Texture>(textureName))
{
std::memset(m_charWidth, 0, sizeof(u8) * 256);

View File

@ -31,7 +31,7 @@
#include <gk/core/Vector2.hpp>
namespace gk {
namespace sf {
class Texture;
}
@ -44,12 +44,12 @@ class Font {
u8 getCharWidth(u8 c) const { return m_charWidth[c]; }
gk::Vector2i getTileSize() const { return {m_width, m_height}; }
const gk::Texture &texture() const { return m_texture; }
const sf::Texture &texture() const { return m_texture; }
private:
void parseConfig(const std::string &configPath);
gk::Texture &m_texture;
sf::Texture &m_texture;
u8 m_charWidth[256];
u8 m_width = 8; // FIXME: Hardcoded value

View File

@ -52,11 +52,11 @@ void InventoryWidget::scroll(float scrolling) {
loadItemWidgets(offset, size);
}
void InventoryWidget::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEMOTION) {
void InventoryWidget::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseMoved) {
m_currentItemWidget = nullptr;
for (std::size_t i = 0 ; i < m_itemWidgets.size() ; ++i) {
if (m_itemWidgets[i].isPointInWidget(event.motion.x, event.motion.y)) {
if (m_itemWidgets[i].isPointInWidget(event.mouseMove.x, event.mouseMove.y)) {
m_currentItemWidget = &m_itemWidgets[i];
m_selectedItemBackground.setPosition(1 + (i % m_inventoryWidth) * 18, 1 + (i / m_inventoryWidth) * 18, 0);

View File

@ -43,7 +43,7 @@ class InventoryWidget : public AbstractInventoryWidget {
void scroll(float scrolling);
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void update() override;

View File

@ -40,11 +40,11 @@ void MenuWidget::reset(u16 width, u16 height) {
m_buttons.reserve(m_width * m_height);
}
void MenuWidget::onEvent(const SDL_Event &event) {
void MenuWidget::onEvent(const sf::Event &event) {
for (std::size_t i = 0 ; i < m_buttons.size() ; ++i) {
m_buttons.at(i).onEvent(event);
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event.type == sf::Event::Resized) {
int x = i % m_width;
int y = i / m_width;

View File

@ -38,7 +38,7 @@ class MenuWidget : public Widget {
void reset(u16 width, u16 height);
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void onGuiScaleChanged(const GuiScaleChangedEvent &event);

View File

@ -37,35 +37,35 @@ MouseItemWidget::MouseItemWidget(Widget *parent) : ItemWidget(m_inventory, 0, 0,
m_tooltipInfoText.setColor({180, 180, 180});
}
void MouseItemWidget::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEMOTION) {
updatePosition(event.motion.x, event.motion.y);
void MouseItemWidget::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseMoved) {
updatePosition(event.mouseMove.x, event.mouseMove.y);
}
else if (event.type == SDL_MOUSEBUTTONDOWN) {
updatePosition(event.button.x, event.button.y);
else if (event.type == sf::Event::MouseButtonPressed) {
updatePosition(event.mouseButton.x, event.mouseButton.y);
if (getStack().amount() == 0) {
if (event.button.button == SDL_BUTTON_LEFT) {
if (event.mouseButton.button == sf::Mouse::Left) {
leftClickBehaviour();
}
else if (event.button.button == SDL_BUTTON_RIGHT) {
else if (event.mouseButton.button == sf::Mouse::Right) {
rightClickBehaviour();
}
m_isDragging = false;
}
else if (event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT) {
startDragging(event.button.button == SDL_BUTTON_LEFT);
else if (event.mouseButton.button == sf::Mouse::Left || event.mouseButton.button == sf::Mouse::Right) {
startDragging(event.mouseButton.button == sf::Mouse::Left);
}
}
else if (event.type == SDL_MOUSEBUTTONUP) {
updatePosition(event.button.x, event.button.y);
else if (event.type == sf::Event::MouseButtonReleased) {
updatePosition(event.mouseButton.x, event.mouseButton.y);
if (m_isDragging && m_draggedSlots.size() <= 1) {
if (event.button.button == SDL_BUTTON_LEFT) {
if (event.mouseButton.button == sf::Mouse::Left) {
leftClickBehaviour();
}
else if (event.button.button == SDL_BUTTON_RIGHT) {
else if (event.mouseButton.button == sf::Mouse::Right) {
rightClickBehaviour();
}
}

View File

@ -38,7 +38,7 @@ class MouseItemWidget : public ItemWidget {
public:
MouseItemWidget(Widget *parent);
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void leftClickBehaviour();
void rightClickBehaviour();

View File

@ -26,7 +26,7 @@
*/
#include "ProgressBarWidget.hpp"
ProgressBarWidget::ProgressBarWidget(const gk::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent)
ProgressBarWidget::ProgressBarWidget(const sf::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent)
: Widget(parent), m_blockData(blockData), m_image(texture)
{
m_type = type;

View File

@ -40,7 +40,7 @@ enum class ProgressBarType : u8 {
class ProgressBarWidget : public Widget {
public:
ProgressBarWidget(const gk::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent = nullptr);
ProgressBarWidget(const sf::Texture &texture, BlockData &blockData, ProgressBarType type, Widget *parent = nullptr);
void init(const gk::FloatRect &clipRect, const gk::Vector2i &position, const std::string &meta, unsigned int maxMetaValue);
void init(const gk::FloatRect &clipRect, const gk::Vector2i &position, const std::string &meta, const std::string &maxMeta);

View File

@ -29,7 +29,7 @@
#include "Config.hpp"
#include "ScrollBarWidget.hpp"
void ScrollBarWidget::init(const gk::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget) {
void ScrollBarWidget::init(const sf::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget) {
m_clipRect = clipRect;
m_minY = minY;
@ -44,19 +44,19 @@ void ScrollBarWidget::init(const gk::Texture &texture, const gk::FloatRect &clip
m_image.setClipRect(m_clipRect.x, m_clipRect.y, m_clipRect.sizeX, m_clipRect.sizeY);
}
void ScrollBarWidget::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
if (isPointInWidget(event.button.x, event.button.y)) {
void ScrollBarWidget::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left) {
if (isPointInWidget(event.mouseButton.x, event.mouseButton.y)) {
m_isDragging = true;
updateScrolling(event.button.y);
updateScrolling(event.mouseButton.y);
}
}
else if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT) {
else if (event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left) {
m_isDragging = false;
}
else if (event.type == SDL_MOUSEMOTION && m_isDragging) {
updateScrolling(event.motion.y);
else if (event.type == sf::Event::MouseMoved && m_isDragging) {
updateScrolling(event.mouseMove.y);
}
}

View File

@ -35,9 +35,9 @@ class ScrollBarWidget : public Widget {
public:
ScrollBarWidget(Widget *parent = nullptr) : Widget(12, 15, parent) {}
void init(const gk::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget);
void init(const sf::Texture &texture, const gk::FloatRect &clipRect, u16 minY, u16 maxY, InventoryWidget &widget);
void onEvent(const SDL_Event &event);
void onEvent(const sf::Event &event);
private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const;

View File

@ -24,7 +24,6 @@
*
* =====================================================================================
*/
#include <gk/gl/Texture.hpp>
#include <gk/resource/ResourceHandler.hpp>
#include "Color.hpp"

View File

@ -36,16 +36,16 @@ TextButton::TextButton(const CppCallback &callback, Widget *parent) : TextButton
m_cppCallback = callback;
}
void TextButton::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEMOTION) {
m_isHovered = isPointInWidget(event.motion.x, event.motion.y);
void TextButton::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseMoved) {
m_isHovered = isPointInWidget(event.mouseMove.x, event.mouseMove.y);
if (m_isEnabled && m_isHovered && m_text.color() == gk::Color::White)
m_text.setColor({255, 255, 160});
else if (!m_isHovered && m_text.color() != gk::Color::White)
m_text.setColor(gk::Color::White);
}
else if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT && m_isHovered && m_isEnabled) {
else if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left && m_isHovered && m_isEnabled) {
if (m_cppCallback)
m_cppCallback(*this);
else if (m_luaCallback)

View File

@ -44,7 +44,7 @@ class TextButton : public Widget {
TextButton(Widget *parent = nullptr);
TextButton(const CppCallback &callback, Widget *parent = nullptr);
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
const std::string &text() const { return m_text.text(); }
void setText(const std::string &text);

View File

@ -32,22 +32,20 @@ TextInput::TextInput() {
m_text.setText(std::string{m_cursor});
}
void TextInput::onEvent(const SDL_Event &event) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_BACKSPACE && !m_content.empty()) {
void TextInput::onEvent(const sf::Event &event) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Backspace && !m_content.empty()) {
m_content.erase(m_content.begin() + m_content.length() - 1);
m_text.setText(m_content + m_cursor);
}
if (event.type == SDL_TEXTINPUT) {
std::string text = event.text.text;
for (char c : text) {
if (isprint(c) && (!m_characterLimit || m_content.size() < m_characterLimit)) {
m_content += c;
}
m_text.setText(m_content + m_cursor);
if (event.type == sf::Event::TextEntered) {
u32 c = event.text.unicode;
if (isprint(c) && (!m_characterLimit || m_content.size() < m_characterLimit)) {
m_content += c;
}
m_text.setText(m_content + m_cursor);
}
}

View File

@ -27,7 +27,7 @@
#ifndef TEXTINPUT_HPP_
#define TEXTINPUT_HPP_
#include <gk/core/SDLHeaders.hpp>
#include <SFML/Window/Event.hpp>
#include "Text.hpp"
@ -35,7 +35,7 @@ class TextInput : public gk::Drawable, public gk::Transformable {
public:
TextInput();
void onEvent(const SDL_Event &event);
void onEvent(const sf::Event &event);
const std::string &text() const { return m_content; }
void setText(const std::string &text) { m_content = text; m_text.setText(m_content + m_cursor); }

View File

@ -27,8 +27,9 @@
#ifndef WIDGET_HPP_
#define WIDGET_HPP_
#include <SFML/Window/Event.hpp>
#include <gk/core/Rect.hpp>
#include <gk/core/SDLHeaders.hpp>
#include <gk/gl/Drawable.hpp>
#include <gk/gl/Transformable.hpp>
@ -38,7 +39,7 @@ class Widget : public gk::Drawable, public gk::Transformable {
Widget(unsigned int width, unsigned int height, Widget *parent = nullptr)
: m_parent(parent), m_width(width), m_height(height) {}
virtual void onEvent(const SDL_Event &) {}
virtual void onEvent(const sf::Event &) {}
virtual void update() {}
bool isPointInWidget(float x, float y);

View File

@ -44,16 +44,16 @@
BlockCursor::BlockCursor(ClientPlayer &player, ClientWorld &world, ClientCommandHandler &client)
: m_player(player), m_world(world), m_client(client)
{
m_blockDestroyTexture = &gk::ResourceHandler::getInstance().get<gk::Texture>("texture-block_destroy");
m_blockDestroyTexture = &gk::ResourceHandler::getInstance().get<sf::Texture>("texture-block_destroy");
}
void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) {
if (event.type == SDL_MOUSEBUTTONDOWN && m_selectedBlock.w != -1) {
if (event.button.button == SDL_BUTTON_LEFT) {
void BlockCursor::onEvent(const sf::Event &event, const Hotbar &hotbar) {
if (event.type == sf::Event::MouseButtonPressed && m_selectedBlock.w != -1) {
if (event.mouseButton.button == sf::Mouse::Left) {
m_animationStart = gk::GameClock::getInstance().getTicks();
m_currentTool = &m_player.inventory().getStack(hotbar.cursorPos(), 0);
}
else if (event.button.button == SDL_BUTTON_RIGHT) {
else if (event.mouseButton.button == sf::Mouse::Right) {
if (m_animationStart != 0)
m_animationStart = 0;
@ -112,8 +112,8 @@ void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) {
}
}
}
else if (event.type == SDL_MOUSEBUTTONUP) {
if (event.button.button == SDL_BUTTON_LEFT) {
else if (event.type == sf::Event::MouseButtonReleased) {
if (event.mouseButton.button == sf::Mouse::Left) {
m_animationStart = 0;
}
}

View File

@ -27,7 +27,7 @@
#ifndef BLOCKCURSOR_HPP_
#define BLOCKCURSOR_HPP_
#include <gk/core/SDLHeaders.hpp>
#include <SFML/Window/Event.hpp>
#include "ClientWorld.hpp"
#include "Inventory.hpp"
@ -41,7 +41,7 @@ class BlockCursor : public gk::Drawable {
public:
BlockCursor(ClientPlayer &player, ClientWorld &world, ClientCommandHandler &client);
void onEvent(const SDL_Event &event, const Hotbar &hotbar);
void onEvent(const sf::Event &event, const Hotbar &hotbar);
void update(const Hotbar &hotbar);
@ -69,7 +69,7 @@ class BlockCursor : public gk::Drawable {
const Block *m_currentBlock = nullptr;
const ItemStack *m_currentTool = nullptr;
gk::Texture *m_blockDestroyTexture = nullptr;
sf::Texture *m_blockDestroyTexture = nullptr;
};
#endif // BLOCKCURSOR_HPP_

View File

@ -62,8 +62,8 @@ void HUD::setup() {
m_crosshair.setup();
}
void HUD::onEvent(const SDL_Event &event) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F3)
void HUD::onEvent(const sf::Event &event) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F3)
m_isDebugOverlayVisible ^= 1;
if (Config::isHotbarVisible)

View File

@ -44,7 +44,7 @@ class HUD : public gk::Transformable, public gk::Drawable {
void setup();
void onEvent(const SDL_Event &event);
void onEvent(const sf::Event &event);
void onGuiScaleChanged(const GuiScaleChangedEvent &event);
void update();

View File

@ -37,11 +37,11 @@ Hotbar::Hotbar(Inventory &inventory, Widget *parent) : Widget(182, 22, parent),
m_cursor.setPosition(-1, -1, 0);
}
void Hotbar::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEWHEEL) {
if (event.wheel.y < 0)
void Hotbar::onEvent(const sf::Event &event) {
if (event.type == sf::Event::MouseWheelScrolled) {
if (event.mouseWheelScroll.y < 0)
m_cursorPos = (m_cursorPos + 1) % 9;
else if (event.wheel.y > 0)
else if (event.mouseWheelScroll.y > 0)
m_cursorPos = (m_cursorPos == 0) ? 8 : m_cursorPos - 1;
m_cursor.setPosition(-1 + 20 * m_cursorPos, -1, 0);

View File

@ -36,7 +36,7 @@ class Hotbar : public Widget {
public:
Hotbar(Inventory &inventory, Widget *parent = nullptr);
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void update() override;

View File

@ -58,16 +58,16 @@ void ChatState::updateTextInputGeometry() {
m_textInput.setBackgroundSize(Config::screenWidth / Config::guiScale - 4, 10);
}
void ChatState::onEvent(const SDL_Event &event) {
void ChatState::onEvent(const sf::Event &event) {
InterfaceState::onEvent(event);
m_textInput.onEvent(event);
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event.type == sf::Event::Resized) {
updateTextInputGeometry();
}
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Escape) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
gk::Mouse::resetToWindowCenter();
@ -78,7 +78,7 @@ void ChatState::onEvent(const SDL_Event &event) {
m_stateStack->pop();
}
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return) {
if (!m_textInput.text().empty())
m_clientCommandHandler.sendChatMessage(m_textInput.text());

View File

@ -39,7 +39,7 @@ class ChatState : public InterfaceState {
void updateTextInputGeometry();
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;

View File

@ -71,8 +71,8 @@ void GameState::connect(const std::string &host, int port) {
gk::Mouse::setCursorGrabbed(true);
}
void GameState::onEvent(const SDL_Event &event) {
if (event.type == SDL_QUIT) {
void GameState::onEvent(const sf::Event &event) {
if (event.type == sf::Event::Closed) {
m_client.disconnect();
m_stateStack->clear();
@ -81,42 +81,41 @@ void GameState::onEvent(const SDL_Event &event) {
if (!m_stateStack->empty() && &m_stateStack->top() == this) {
gk::KeyboardHandler *keyboardHandler = (gk::KeyboardHandler *)gk::GamePad::getInputHandler();
if (event.type == SDL_MOUSEMOTION) {
if(Config::screenWidth / 2.0f != event.motion.x || Config::screenHeight / 2.0f != event.motion.y) {
m_player.turnH(event.motion.xrel * -0.01 * Config::mouseSensitivity);
m_player.turnViewV(event.motion.yrel * -0.01 * Config::mouseSensitivity);
if (event.type == sf::Event::MouseMoved) {
if(Config::screenWidth / 2.0f != event.mouseMove.x || Config::screenHeight / 2.0f != event.mouseMove.y) {
// FIXME: SFML
// m_player.turnH(event.mouseMove.xrel * -0.01 * Config::mouseSensitivity);
// m_player.turnViewV(event.mouseMove.yrel * -0.01 * Config::mouseSensitivity);
gk::Mouse::resetToWindowCenter();
}
}
else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
m_stateStack->push<PauseMenuState>(m_client, this);
}
else if (event.type == SDL_KEYDOWN
&& (event.key.keysym.sym == keyboardHandler->getKeycode(GameKey::Chat)
|| event.key.keysym.sym == keyboardHandler->getKeycode(GameKey::Command)))
else if (event.type == sf::Event::KeyPressed
&& (event.key.code == keyboardHandler->getKeycode(GameKey::Chat)
|| event.key.code == keyboardHandler->getKeycode(GameKey::Command)))
{
m_stateStack->push<ChatState>(m_clientCommandHandler, m_hud.chat(), event.key.keysym.sym == keyboardHandler->getKeycode(GameKey::Command), this);
m_stateStack->push<ChatState>(m_clientCommandHandler, m_hud.chat(), event.key.code == keyboardHandler->getKeycode(GameKey::Command), this);
}
else if (event.type == SDL_WINDOWEVENT) {
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
m_stateStack->push<PauseMenuState>(m_client, this);
else if (event.type == sf::Event::LostFocus) {
m_stateStack->push<PauseMenuState>(m_client, this);
gk::Mouse::setCursorGrabbed(false);
gk::Mouse::setCursorVisible(true);
}
else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
}
gk::Mouse::setCursorGrabbed(false);
gk::Mouse::setCursorVisible(true);
}
else if (event.type == sf::Event::GainedFocus) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
}
m_hud.onEvent(event);
}
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
Config::screenWidth = event.window.data1;
Config::screenHeight = event.window.data2;
if (event.type == sf::Event::Resized) {
Config::screenWidth = event.size.width;
Config::screenHeight = event.size.height;
m_camera.setAspectRatio((float)Config::screenWidth / Config::screenHeight);
m_hud.setup();

View File

@ -51,7 +51,7 @@ class GameState : public gk::ApplicationState {
void connect(const std::string &host, int port);
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void update() override;

View File

@ -52,18 +52,18 @@ void InterfaceState::setup() {
// m_view.setCenter(Config::screenWidth / 2.0f, Config::screenHeight / 2.0f);
}
void InterfaceState::onEvent(const SDL_Event &event) {
void InterfaceState::onEvent(const sf::Event &event) {
if (m_parent) {
m_parent->onEvent(event);
}
else if (event.type == SDL_QUIT) {
else if (event.type == sf::Event::Closed) {
m_stateStack->clear();
}
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event.type == sf::Event::Resized) {
if (!m_parent) {
Config::screenWidth = event.window.data1;
Config::screenHeight = event.window.data2;
Config::screenWidth = event.size.width;
Config::screenHeight = event.size.height;
}
setup();

View File

@ -37,7 +37,7 @@ class InterfaceState : public gk::ApplicationState {
protected:
void setup();
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void update() override;

View File

@ -64,13 +64,13 @@ LuaGUIState::LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, Cli
loadGUI(packet);
}
void LuaGUIState::onEvent(const SDL_Event &event) {
void LuaGUIState::onEvent(const sf::Event &event) {
InterfaceState::onEvent(event);
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED && m_isCentered)
if (event.type == sf::Event::Resized && m_isCentered)
centerMainWidget();
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
gk::Mouse::resetToWindowCenter();
@ -81,7 +81,7 @@ void LuaGUIState::onEvent(const SDL_Event &event) {
for (auto &it : m_widgets)
it->onEvent(event);
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT
if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left
&& m_currentInventoryWidget && !m_currentInventoryWidget->shiftDestination().empty()
&& m_mouseItemWidget.currentItemWidget() && gk::GamePad::isKeyPressed(GameKey::Shift)) {
for (const std::string &shiftDestination : m_currentInventoryWidget->shiftDestination()) {
@ -202,7 +202,7 @@ void LuaGUIState::loadImage(const std::string &, s32 x, s32 y, sf::Packet &packe
gk::FloatRect clipRect;
packet >> textureFilename >> clipRect.x >> clipRect.y >> clipRect.sizeX >> clipRect.sizeY;
gk::Texture &texture = loadTexture(textureFilename);
sf::Texture &texture = loadTexture(textureFilename);
auto *image = new gk::Image(texture);
image->setPosition(x, y);
@ -335,7 +335,7 @@ void LuaGUIState::loadProgressBarWidget(const std::string &, s32 x, s32 y, sf::P
return;
}
gk::Texture &texture = loadTexture(textureFilename);
sf::Texture &texture = loadTexture(textureFilename);
ProgressBarWidget *widget = new ProgressBarWidget(texture, *data, ProgressBarType(type));
if (!maxMeta.empty())
@ -353,7 +353,7 @@ void LuaGUIState::loadScrollBarWidget(const std::string &, s32 x, s32 y, sf::Pac
std::string widget;
packet >> textureFilename >> clipRect >> minY >> maxY >> widget;
gk::Texture &texture = loadTexture(textureFilename);
sf::Texture &texture = loadTexture(textureFilename);
ScrollBarWidget *scrollBarWidget = new ScrollBarWidget(&m_mainWidget);
scrollBarWidget->setPosition(x, y);
@ -368,10 +368,10 @@ void LuaGUIState::loadInventory(const std::string &name, sf::Packet &packet) {
packet >> m_inventories.at(name);
}
gk::Texture &LuaGUIState::loadTexture(const std::string &textureFilename) {
sf::Texture &LuaGUIState::loadTexture(const std::string &textureFilename) {
auto it = m_textures.find(textureFilename);
if (it == m_textures.end()) {
m_textures.emplace(textureFilename, gk::Texture{textureFilename});
m_textures.emplace(textureFilename, sf::Texture{}).first->second.loadFromFile(textureFilename);
return m_textures.at(textureFilename);
}
else {

View File

@ -44,7 +44,7 @@ class LuaGUIState : public InterfaceState {
public:
LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, ClientWorld &world, sf::Packet &packet, gk::ApplicationState *parent = nullptr);
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void update() override;
@ -60,7 +60,7 @@ class LuaGUIState : public InterfaceState {
void loadScrollBarWidget(const std::string &name, s32 x, s32 y, sf::Packet &packet);
void loadInventory(const std::string &name, sf::Packet &packet);
gk::Texture &loadTexture(const std::string &textureFilename);
sf::Texture &loadTexture(const std::string &textureFilename);
void centerMainWidget();
@ -76,7 +76,7 @@ class LuaGUIState : public InterfaceState {
std::vector<std::unique_ptr<Widget>> m_widgets;
std::vector<std::unique_ptr<gk::Drawable>> m_drawables;
std::unordered_map<std::string, Inventory> m_inventories;
std::unordered_map<std::string, gk::Texture> m_textures;
std::unordered_map<std::string, sf::Texture> m_textures;
ClientPlayer &m_player;
ClientWorld &m_world;

View File

@ -75,10 +75,10 @@ void PauseMenuState::init() {
m_eventHandler->addListener<GuiScaleChangedEvent>(&PauseMenuState::onGuiScaleChanged, this);
}
void PauseMenuState::onEvent(const SDL_Event &event) {
void PauseMenuState::onEvent(const sf::Event &event) {
InterfaceState::onEvent(event);
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event.type == sf::Event::Resized) {
if (!m_stateStack->empty() && &m_stateStack->top() != this)
m_menuWidget.onEvent(event);
}
@ -86,7 +86,7 @@ void PauseMenuState::onEvent(const SDL_Event &event) {
if (!m_stateStack->empty() && &m_stateStack->top() == this) {
m_menuWidget.onEvent(event);
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
gk::Mouse::setCursorGrabbed(true);
gk::Mouse::setCursorVisible(false);
gk::Mouse::resetToWindowCenter();

View File

@ -41,7 +41,7 @@ class PauseMenuState : public InterfaceState {
void init() override;
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
private:
void onGuiScaleChanged(const GuiScaleChangedEvent &event);

View File

@ -89,10 +89,10 @@ ServerConnectState::ServerConnectState(gk::ApplicationState *parent) : Interface
m_errorText.setScale(Config::guiScale, Config::guiScale);
}
void ServerConnectState::onEvent(const SDL_Event &event) {
void ServerConnectState::onEvent(const sf::Event &event) {
InterfaceState::onEvent(event);
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event.type == sf::Event::Resized) {
m_textInput.setPosition(Config::screenWidth / 2.0f - m_textInput.getBackgroundSize().x * Config::guiScale / 2.0f,
Config::screenHeight / 2.0f - m_textInput.getBackgroundSize().y * Config::guiScale / 2.0f);

View File

@ -35,7 +35,7 @@ class ServerConnectState : public InterfaceState {
public:
ServerConnectState(gk::ApplicationState *parent = nullptr);
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void update() override;

View File

@ -54,10 +54,10 @@ void ServerLoadingState::centerText() {
Config::screenHeight / 2 - m_text.getSize().y * Config::guiScale * 2 / 2);
}
void ServerLoadingState::onEvent(const SDL_Event &event) {
void ServerLoadingState::onEvent(const sf::Event &event) {
InterfaceState::onEvent(event);
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event.type == sf::Event::Resized) {
centerText();
}
}

View File

@ -38,7 +38,7 @@ class ServerLoadingState : public InterfaceState {
void centerText();
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void update() override;

View File

@ -59,10 +59,10 @@ void SettingsMenuState::init() {
m_eventHandler->addListener<GuiScaleChangedEvent>(&SettingsMenuState::onGuiScaleChanged, this);
}
void SettingsMenuState::onEvent(const SDL_Event &event) {
void SettingsMenuState::onEvent(const sf::Event &event) {
InterfaceState::onEvent(event);
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event.type == sf::Event::Resized) {
updateDoneButtonPosition();
if (&m_stateStack->top() != this)
@ -73,12 +73,12 @@ void SettingsMenuState::onEvent(const SDL_Event &event) {
m_menuWidget.onEvent(event);
m_doneButton.onEvent(event);
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
doneButtonAction();
}
else if (m_currentKeyButton && event.type == SDL_KEYDOWN) {
else if (m_currentKeyButton && event.type == sf::Event::KeyPressed) {
gk::KeyboardHandler *keyboardHandler = (gk::KeyboardHandler *)gk::GamePad::getInputHandler();
keyboardHandler->setKeycode(m_currentKey, event.key.keysym.sym);
keyboardHandler->setKeycode(m_currentKey, event.key.code);
m_currentKeyButton->setText(m_currentKeyButton->text() + keyboardHandler->getKeyName(m_currentKey));
m_currentKeyButton = nullptr;

View File

@ -41,7 +41,7 @@ class SettingsMenuState : public InterfaceState {
void init() override;
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
private:
void onGuiScaleChanged(const GuiScaleChangedEvent &event);

View File

@ -74,10 +74,10 @@ void TitleScreenState::init() {
m_eventHandler->addListener<ServerOnlineEvent>(&TitleScreenState::onServerOnlineEvent, this);
}
void TitleScreenState::onEvent(const SDL_Event &event) {
void TitleScreenState::onEvent(const sf::Event &event) {
InterfaceState::onEvent(event);
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (event.type == sf::Event::Resized) {
centerBackground();
if (!m_stateStack->empty() && &m_stateStack->top() != this)

View File

@ -44,7 +44,7 @@ class TitleScreenState : public InterfaceState {
void init() override;
void onEvent(const SDL_Event &event) override;
void onEvent(const sf::Event &event) override;
void update() override;

View File

@ -48,9 +48,9 @@ void ClientChunk::drawLayer(gk::RenderTarget &target, gk::RenderStates states, u
else
glCheck(glEnable(GL_CULL_FACE));
gk::Texture::bind(states.texture);
sf::Texture::bind(states.texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, (layer == ChunkBuilder::Layer::NoMipMap || layer == ChunkBuilder::Layer::Flora) ? 0 : Config::mipmapLevels);
gk::Texture::bind(nullptr);
sf::Texture::bind(nullptr);
glCheck(glEnable(GL_DEPTH_TEST));

View File

@ -28,7 +28,6 @@
#define CLIENTCHUNK_HPP_
#include <gk/gl/Drawable.hpp>
#include <gk/gl/Texture.hpp>
#include "Chunk.hpp"
#include "ChunkBuilder.hpp"

View File

@ -18,7 +18,7 @@ endforeach(HEADER_FILE)
# Add library
#------------------------------------------------------------------------------
add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
add_dependencies(${PROJECT_NAME} zlib EnTT sfml-network gamekit)
add_dependencies(${PROJECT_NAME} zlib EnTT gamekit)
#------------------------------------------------------------------------------
# Compiler flags

View File

@ -24,9 +24,10 @@
*
* =====================================================================================
*/
#include <SFML/Graphics/Texture.hpp>
#include <gk/core/XMLFile.hpp>
#include <gk/gl/OpenGL.hpp>
#include <gk/gl/Texture.hpp>
#include <gk/resource/ResourceHandler.hpp>
#include "TextureLoader.hpp"
@ -39,14 +40,14 @@ void TextureLoader::load(const char *xmlFilename, gk::ResourceHandler &handler)
std::string name = textureElement->Attribute("name");
std::string path = textureElement->Attribute("path");
auto &texture = handler.add<gk::Texture>("texture-" + name);
auto &texture = handler.add<sf::Texture>("texture-" + name);
texture.loadFromFile(path);
// gk::Texture::bind(&texture);
// sf::Texture::bind(&texture);
// glGenerateMipmap(GL_TEXTURE_2D);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);
// gk::Texture::bind(nullptr);
// sf::Texture::bind(nullptr);
textureElement = textureElement->NextSiblingElement("texture");
}

View File

@ -71,10 +71,6 @@ target_link_libraries(${PROJECT_NAME}
${CMAKE_PROJECT_NAME}_common
gamekit
${OPENGL_LIBRARIES}
${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${TINYXML2_LIBRARIES}
${GLEW_LIBRARIES}
${LUA_LIBRARIES}