Skip to content

Commit 9404be3

Browse files
committed
Restructured files, started refactoring main.cpp
1 parent 21d40ee commit 9404be3

File tree

10 files changed

+580
-191
lines changed

10 files changed

+580
-191
lines changed

CMakeLists.txt

+38-22
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,66 @@ project(RePiskel)
99
# Set CMake variables
1010
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1111
set(CMAKE_CXX_EXTENSIONS OFF)
12-
set(CMAKE_CXX_STANDARD 23)
12+
set(CMAKE_CXX_STANDARD 26)
1313
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1414

1515

1616
# Main executable
17+
string(APPEND CMAKE_CXX_FLAGS " -Wno-narrowing")
1718
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
18-
add_executable(RePiskel MACOSX_BUNDLE main.cpp buildfiles/icon.icns)
19-
else(CMAKE_SYSTEM_NAME STREQUAL "Windows")
20-
add_executable(RePiskel WIN32 main.cpp buildfiles/wicon.rc)
19+
add_executable(RePiskel MACOSX_BUNDLE src/main.cpp buildfiles/icon.icns)
20+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
21+
add_executable(RePiskel src/main.cpp buildfiles/wicon.rc) # WIN32
22+
else(CMAKE_SYSTEM_NAME STREQUAL "Linux")
23+
add_executable(RePiskel src/main.cpp)
2124
endif()
2225

2326

24-
target_compile_options(RePiskel PRIVATE -fpermissive)
25-
26-
2727
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
2828
# Set macos executable rpath and result path
2929
set_target_properties(RePiskel PROPERTIES INSTALL_RPATH "@executable_path/../Resources" BUILD_WITH_INSTALL_RPATH TRUE)
3030
set_target_properties(RePiskel PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
3131

3232

3333
# Link libraries and include directories
34-
target_link_libraries(RePiskel PRIVATE ${CMAKE_SOURCE_DIR}/../Cached/libSDL3.0.dylib)
35-
target_link_libraries(RePiskel PRIVATE ${CMAKE_SOURCE_DIR}/../Cached/libSDL3_ttf.0.0.0.dylib)
36-
# target_link_libraries(RePiskel PRIVATE ${CMAKE_SOURCE_DIR}/../Cached/libgtk-4.1.dylib)
37-
target_include_directories(RePiskel PRIVATE /usr/local/include)
38-
34+
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-shared)
35+
find_package(SDL3_ttf REQUIRED CONFIG COMPONENTS SDL3_ttf-shared)
36+
target_link_libraries(RePiskel PRIVATE SDL3::SDL3)
37+
target_link_libraries(RePiskel PRIVATE SDL3_ttf::SDL3_ttf)
3938

4039
# Make directories for macos app
41-
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents/MacOS)
42-
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents/Resources)
40+
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents/MacOS")
41+
file(COPY "${CMAKE_SOURCE_DIR}/buildfiles/Resources" DESTINATION "${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents")
4342

4443

4544
# Add basic files to macos app
46-
file(COPY ${CMAKE_SOURCE_DIR}/buildfiles/info.plist DESTINATION ${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents)
47-
file(COPY ${CMAKE_SOURCE_DIR}/buildfiles/icon.icns DESTINATION ${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents/Resources)
48-
file(COPY ${CMAKE_SOURCE_DIR}/buildfiles/Font.ttf DESTINATION ${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents/Resources)
49-
file(COPY ${CMAKE_SOURCE_DIR}/buildfiles/tools.bmp DESTINATION ${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents/Resources)
45+
file(COPY ${CMAKE_SOURCE_DIR}/buildfiles/info.plist DESTINATION "${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents")
46+
file(COPY ${CMAKE_SOURCE_DIR}/buildfiles/icon.icns DESTINATION "${CMAKE_SOURCE_DIR}/build/RePiskel.app/Contents/Resources")
5047

5148

5249
# Add resources to macos app
53-
file(COPY ${CMAKE_SOURCE_DIR}/../Cached/libSDL3.0.dylib DESTINATION ${CMAKE_SOURCE_DIR}/build/RePiskel.app/contents/Resources)
54-
configure_file(${CMAKE_SOURCE_DIR}/../Cached/libSDL3_ttf.0.0.0.dylib ${CMAKE_SOURCE_DIR}/build/RePiskel.app/contents/Resources/libSDL3_ttf.0.dylib COPYONLY)
50+
add_custom_command(TARGET CanvasView POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:SDL3::SDL3-shared> $<TARGET_FILE_DIR:CanvasView>/../Resources)
51+
add_custom_command(TARGET CanvasView POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:SDL3_ttf::SDL3_ttf-shared> $<TARGET_FILE_DIR:CanvasView>/../Resources)
52+
add_custom_command(TARGET CanvasView POST_BUILD COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE_DIR:CanvasView>/../Resources/libSDL3_ttf.0.0.0.dylib $<TARGET_FILE_DIR:CanvasView>/../Resources/libSDL3_ttf.0.dylib)
53+
54+
55+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
56+
# Set linux result path
57+
set_target_properties(RePiskel PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/RePiskel)
58+
set_target_properties(RePiskel PROPERTIES INSTALL_RPATH "$ORIGIN/Resources" BUILD_WITH_INSTALL_RPATH TRUE)
59+
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-shared)
60+
find_package(SDL3_ttf REQUIRED CONFIG COMPONENTS SDL3_ttf-shared)
61+
target_link_libraries(RePiskel PRIVATE SDL3::SDL3)
62+
target_link_libraries(RePiskel PRIVATE SDL3_ttf::SDL3_ttf)
63+
64+
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/build/RePiskel")
65+
file(COPY "${CMAKE_SOURCE_DIR}/buildfiles/Resources" DESTINATION "${CMAKE_SOURCE_DIR}/build/RePiskel")
66+
67+
add_custom_command(TARGET RePiskel POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:SDL3::SDL3-shared> $<TARGET_FILE_DIR:RePiskel>/Resources)
68+
add_custom_command(TARGET RePiskel POST_BUILD COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE_DIR:RePiskel>/Resources/libSDL3.so.0.2.5 $<TARGET_FILE_DIR:RePiskel>/Resources/libSDL3.so.0)
69+
add_custom_command(TARGET RePiskel POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:SDL3_ttf::SDL3_ttf-shared> $<TARGET_FILE_DIR:RePiskel>/Resources)
70+
add_custom_command(TARGET RePiskel POST_BUILD COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE_DIR:RePiskel>/Resources/libSDL3_ttf.so.0.1.2 $<TARGET_FILE_DIR:RePiskel>/Resources/libSDL3_ttf.so.0)
71+
5572

5673

5774
else(CMAKE_SYSTEM_NAME STREQUAL "Windows")
@@ -66,8 +83,7 @@ else(CMAKE_SYSTEM_NAME STREQUAL "Windows")
6683

6784

6885
# Add basic files to windows app
69-
file(COPY ${CMAKE_SOURCE_DIR}/buildfiles/tools.bmp DESTINATION ${CMAKE_SOURCE_DIR}/build/RePiskel)
70-
file(COPY ${CMAKE_SOURCE_DIR}/buildfiles/Font.ttf DESTINATION ${CMAKE_SOURCE_DIR}/build/RePiskel)
86+
file(COPY ${CMAKE_SOURCE_DIR}/buildfiles/Resources DESTINATION "${CMAKE_SOURCE_DIR}/build/RePiskel")
7187

7288

7389
# Add resources to windows app

Vector2.h

-72
This file was deleted.
File renamed without changes.
File renamed without changes.

MoreMaths.h src/MoreMaths.h

File renamed without changes.

src/StringFix.h

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <string>
2+
#include <vector>
3+
#include <SDL3/SDL.h>
4+
#define elif else if
5+
6+
inline std::string SDL_GetBasePathNOS(){
7+
std::string data = SDL_GetBasePath();
8+
#ifdef _WIN32
9+
std::string returnv;
10+
for (int i = 0; i < data.length(); i++){
11+
if (data[i] == '\\'){
12+
returnv += "/";
13+
}
14+
else{
15+
returnv += data[i];
16+
}
17+
}
18+
return returnv;
19+
#else
20+
return data;
21+
#endif
22+
}
23+
24+
inline std::string ParsePath(std::string path) {
25+
std::string returnv;
26+
27+
28+
for (int i = 0; i < path.length(); i++) {
29+
bool Append = true;
30+
if (path[i] == '\\') {
31+
returnv += "/";
32+
Append = false;
33+
} elif (path[i] == '~') {
34+
returnv += SDL_GetBasePathNOS();
35+
Append = false;
36+
} elif (i > 0) {
37+
if (std::string(path[i-1], path[i]) != "\\\\") {
38+
Append = false;
39+
}
40+
}
41+
returnv += path[i];
42+
}
43+
44+
return returnv;
45+
}
46+
47+
48+
inline std::vector<std::string> SplitString(std::string str, char delimiter) {
49+
std::vector<std::string> returnv;
50+
std::string part;
51+
for (int i = 0; i < str.length(); i++) {
52+
if (str[i] == delimiter) {
53+
returnv.push_back(part);
54+
part.clear();
55+
} else {
56+
part += str[i];
57+
}
58+
}
59+
return returnv;
60+
}

0 commit comments

Comments
 (0)