Skip to content

Commit 0399023

Browse files
authored
Merge pull request #173 from NTUT-FUCK-PTSD/seticon
Set the window icon with sdl2
2 parents b891a72 + f09e269 commit 0399023

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
77
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
88

9+
# Ignore .DS_Store file from a git repository
10+
11+
.DS_Store
12+
913
# User-specific stuff
1014
.idea/**/workspace.xml
1115
.idea/**/tasks.xml

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ if (${PTSD_ENABLE_PCH})
128128
include/pch.hpp
129129
)
130130
endif()
131+
131132
target_compile_options(PTSD PRIVATE
132133
${TARGET_COMPILE_OPTIONS}
133134
)
@@ -146,6 +147,8 @@ target_include_directories(Example PRIVATE
146147
${EXAMPLE_DIR}/include
147148
)
148149

150+
target_compile_definitions(Example PRIVATE ASSETS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/assets")
151+
149152
enable_testing()
150153

151154
add_executable(Tests EXCLUDE_FROM_ALL

assets/icon.jpg

4.43 KB
Loading

example/src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ int main(int, char **) {
88
auto context = Core::Context::GetInstance();
99
App app;
1010

11+
// set icon in window.
12+
context->SetWindowIcon(ASSETS_DIR "/icon.jpg");
13+
1114
while (!context->GetExit()) {
1215
context->Setup();
1316

include/Core/Context.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Context {
2929
void SetExit(bool exit) { m_Exit = exit; }
3030
void SetWindowWidth(unsigned int width) { m_WindowWidth = width; }
3131
void SetWindowHeight(unsigned int height) { m_WindowHeight = height; }
32+
void SetWindowIcon(const std::string &path);
3233

3334
void Setup();
3435
void Update();

src/Core/Context.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,9 @@ std::shared_ptr<Context> Context::GetInstance() {
134134
}
135135
return s_Instance;
136136
}
137+
138+
void Context::SetWindowIcon(const std::string &path) {
139+
SDL_Surface *image = IMG_Load(path.c_str());
140+
SDL_SetWindowIcon(m_Window, image);
141+
}
137142
} // namespace Core

0 commit comments

Comments
 (0)