Skip to content

Commit

Permalink
implement icon setter
Browse files Browse the repository at this point in the history
  • Loading branch information
durkisneer1 committed Nov 11, 2024
1 parent 875aa7e commit 12abde9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ subprojects/**/
*.gz
*.tar
.vs/
.cache/

# Wrap files that meson is scared of for some reason
subprojects/libpng.wrap
subprojects/zlib.wrap
subprojects/zlib.wrap
Binary file added example/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions example/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <KrakenEngine.hpp>
#include <vector>

#include "include/Player.hpp"

int main()
{
kn::window::init({320, 180}, "Kraken", 4);
kn::window::setIcon("../example/assets/icon.png");
kn::time::Clock clock;
kn::camera = {-32, -26};

Expand All @@ -26,7 +26,7 @@ int main()
done = true;
}

kn::window::clear();
kn::window::clear({21, 18, 37});
tileMap.drawLayer("Background");
tileMap.drawLayer("Wall");

Expand Down
6 changes: 6 additions & 0 deletions include/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,11 @@ void setFullscreen(bool fullscreen);
* @brief Quit SDL and destroy the window.
*/
void quit();

/**
* @brief Set the window icon.
*/
void setIcon(const std::string& path);

} // namespace window
} // namespace kn
6 changes: 3 additions & 3 deletions src/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Texture::~Texture()
SDL_DestroyTexture(texture);
}

bool Texture::loadFromFile(const std::string& path)
bool Texture::loadFromFile(const std::string& filePath)
{
texture = IMG_LoadTexture(window::getRenderer(), path.c_str());
texture = IMG_LoadTexture(window::getRenderer(), filePath.c_str());
if (!texture)
{
WARN("Failed to create texture from: " + path);
WARN("Failed to create texture from: " + filePath);
return false;
}

Expand Down
17 changes: 17 additions & 0 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,21 @@ math::Vec2 getSize()

return {w, h};
}

void setIcon(const std::string& path)
{
if (!_window)
WARN("Cannot set icon before creating the window")

SDL_Surface* icon = IMG_Load(path.c_str());
if (!icon)
{
WARN("IMG_Load Error: " + std::string(IMG_GetError()))
return;
}

SDL_SetWindowIcon(_window, icon);
SDL_FreeSurface(icon);
}

} // namespace kn::window

0 comments on commit 12abde9

Please sign in to comment.