Skip to content

Commit

Permalink
feat: Initial impl of GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
JJL772 committed Jul 18, 2022
1 parent a180e9a commit 9524013
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "external/vtflib"]
path = external/vtflib
url = https://github.com/JJL772/VTFLib
[submodule "external/fmtlib"]
path = external/fmtlib
url = https://github.com/fmtlib/fmt
61 changes: 43 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,66 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)

# Project settings

# Set to enable Qt for this project
set(USING_QT OFF)
option(BUILD_GUI "Build the VTFViewer GUI" ON)

# Global flags, mainly for UNIX. Use $ORIGIN rpath & -fPIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)

# Build vtflib as static lib
set(VTFLIB_STATIC ON)
add_subdirectory(external/vtflib)
add_subdirectory(external/fmtlib)

##############################
# Common code
##############################
set(COMMON_SRC
src/common/image.cpp
src/common/enums.cpp)

add_library(libcom STATIC ${COMMON_SRC})

##############################
# CLI
##############################

# Sources
set(CLI_SRC
src/cli/main.cpp
src/cli/action_extract.cpp
src/cli/action_info.cpp
src/common/enums.cpp
src/common/image.cpp)
src/cli/action_info.cpp)

add_executable(vtex2 ${CLI_SRC})

# Qt support
if (USING_QT)
##############################
# GUI
##############################

if (BUILD_GUI)
include(cmake_scripts/Qt.cmake)
find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui)
target_link_libraries(${PROJECTNAME} PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui)
target_include_directories(${PROJECTNAME} PRIVATE ${QT_INCLUDE} ${QT_INCLUDE}/QtWidgets ${QT_INCLUDE}/QtGui ${QT_INCLUDE}/QtCore)
endif()

set(VIEWER_SRC
src/gui/main.cpp
src/gui/viewer.cpp)

add_executable(vtfview ${VIEWER_SRC})
endif()

# Set up the debugger so it can run the program without copying a million dlls
if(WIN32)
set_target_properties(vtex2 PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=%PATH%;${QT_BASEDIR}/bin;")
set_target_properties(vtfview PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=%PATH%;${QT_BASEDIR}/bin;")
endif()

# Build vtflib as static lib
set(VTFLIB_STATIC ON)
add_subdirectory(external/vtflib)

target_link_libraries(vtex2 vtflib)
target_link_libraries(vtex2 PRIVATE vtflib libcom fmt::fmt)
target_include_directories(vtex2 PRIVATE src external)
target_include_directories(libcom PRIVATE src external external/vtflib/lib)

if (BUILD_GUI)
target_link_libraries(vtfview PRIVATE vtflib libcom fmt::fmt)
target_include_directories(vtfview PRIVATE src external)

find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui)
target_link_libraries(vtfview PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui)
target_include_directories(vtfview PRIVATE ${QT_INCLUDE} ${QT_INCLUDE}/QtWidgets ${QT_INCLUDE}/QtGui ${QT_INCLUDE}/QtCore)
endif()
1 change: 1 addition & 0 deletions external/fmtlib
Submodule fmtlib added at 91abfc
2 changes: 1 addition & 1 deletion external/vtflib
13 changes: 13 additions & 0 deletions src/common/enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,16 @@ std::vector<std::string> TextureFlagsToStringVector(std::uint32_t flags) {

return ret;
}

const char* GetResourceName(vlUInt resource) {
switch(resource) {
case VTF_LEGACY_RSRC_LOW_RES_IMAGE: return "Low-res Image (Legacy";
case VTF_LEGACY_RSRC_IMAGE: return "Image (Legacy)";
case VTF_RSRC_SHEET: return "Sheet";
case VTF_RSRC_CRC: return "CRC";
case VTF_RSRC_TEXTURE_LOD_SETTINGS: return "Texture LOD Settings";
case VTF_RSRC_TEXTURE_SETTINGS_EX: return "Texture Settings Extended";
case VTF_RSRC_KEY_VALUE_DATA: return "KeyValue Data";
default: return "";
}
}
5 changes: 5 additions & 0 deletions src/common/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ VTFImageFormat ImageFormatFromString(const char* arg);
* Convert VTF flags to a user friendly list of strings
*/
std::vector<std::string> TextureFlagsToStringVector(std::uint32_t flags);

/**
* Get a human readable name for the resource
*/
const char* GetResourceName(vlUInt resource);
5 changes: 5 additions & 0 deletions src/common/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ namespace util {
private:
T m_func;
};

template<class T, std::size_t N>
constexpr std::size_t ArraySize(T(&arr)[N]) {
return N;
}
}
26 changes: 26 additions & 0 deletions src/gui/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#include <QApplication>

#include <cstdlib>
#include <cstring>

#include "viewer.hpp"
#include "VTFLib.h"

int main(int argc, char** argv) {
QApplication app(argc, argv);

std::string file;
if (argc > 1) {
file = argv[1];
}

auto* pMainWindow = new vtfview::ViewerMainWindow(nullptr);
if (file.length() && !pMainWindow->load_file(file.c_str())) {
fprintf(stderr, "Could not open vtf '%s'!\n", file.c_str());
return 1;
}
pMainWindow->show();

return app.exec();
}
Loading

0 comments on commit 9524013

Please sign in to comment.