diff --git a/.gitignore b/.gitignore index 6afae90..53b12f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +build/* release/* libgui.cbp \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 0370289..5077e58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,14 +6,14 @@ dist: trusty env: global: - - DEVKITPRO=/opt/devkitpro + - DEVKITPRO=/opt/devkitpro + - WUT_ROOT=/opt/devkitpro/wut - DEVKITPPC=/opt/devkitpro/devkitPPC - PORTLIBREPOS=$HOME/portlibrepos cache: directories: - "$HOME/.local" - - "$PORTLIBREPOS" - "$DEVKITPRO" addons: @@ -27,17 +27,23 @@ before_install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget https://github.com/devkitPro/pacman/releases/download/devkitpro-pacman-1.0.1/devkitpro-pacman.deb -O /tmp/devkitpro-pacman.deb; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo dpkg -i /tmp/devkitpro-pacman.deb; fi - yes | sudo dkp-pacman -Syu devkitPPC --needed + - wget $(curl -s https://api.github.com/repos/decaf-emu/wut/releases/latest | grep 'browser_' | grep 'linux' | cut -d\" -f4) install: + - 7z x -y $(ls | grep "linux") -o${WUT_ROOT} - 7z x -y ./libs/portlibs.zip -o${DEVKITPRO} - cd $PORTLIBREPOS - - ((git clone https://github.com/Maschell/dynamic_libs.git -b lib && (7z x -y ./dynamic_libs/libs/portlibs.zip -o${DEVKITPRO})) || (cd dynamic_libs && git pull)) - - (git clone https://github.com/Maschell/libutils.git || (cd libutils && git pull)) - - (cd dynamic_libs && ((make -j8 | grep -c "built ... ") && make install && echo "installed" ) || (echo "no need for make install" && make)) - - (cd libutils && ((make -j8 | grep -c "built ... ") && make install && echo "installed" ) || (echo "no need for make install" && make)) + - git clone https://github.com/Maschell/libutils.git -b wut + - cd libutils + - mkdir build && cd build + - cmake -DCMAKE_TOOLCHAIN_FILE=$WUT_ROOT/share/wut.toolchain.cmake -DCMAKE_INSTALL_PREFIX=$WUT_ROOT ../ + - make install + - cd $PORTLIBREPOS before_script: - cd $TRAVIS_BUILD_DIR/ script: - - make && make install \ No newline at end of file + - mkdir build && cd build + - cmake -DCMAKE_TOOLCHAIN_FILE=$WUT_ROOT/share/wut.toolchain.cmake -DCMAKE_INSTALL_PREFIX=$WUT_ROOT ../ + - make install \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9c8d753 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.2) +project(gui) +include("${WUT_ROOT}/share/wut.cmake" REQUIRED) + +file(GLOB_RECURSE SOURCE_FILES *.c *.cpp) +file(GLOB_RECURSE HEADER_FILES *.h*) + +add_library(gui STATIC ${SOURCE_FILES} ${HEADER_FILES}) + +target_link_libraries(gui + utilswut) + + +include_directories("$ENV{WUT_ROOT}/include/libutils" REQUIRED) +include_directories("$ENV{DEVKITPRO}/portlibs/ppc/include" REQUIRED) +include_directories("$ENV{DEVKITPRO}/portlibs/ppc/include/freetype2" REQUIRED) + +target_include_directories(gui PUBLIC "include") +target_include_directories(gui PRIVATE "src") + +wut_enable_stdcpp(gui) +wut_default_malloc(gui) + +target_include_directories(gui PUBLIC "include") +target_compile_options(gui PUBLIC "-D__LOGGING__") + +install(TARGETS gui + ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ + DESTINATION "${CMAKE_INSTALL_PREFIX}/include/libgui" + FILES_MATCHING PATTERN "*.h*") \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 4a84f10..0000000 --- a/Makefile +++ /dev/null @@ -1,151 +0,0 @@ -DO_LOGGING := 0 - -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- -ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC) -endif - -export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH) -export PORTLIBS := $(DEVKITPRO)/portlibs/ppc - -PREFIX := powerpc-eabi- - -export AS := $(PREFIX)as -export CC := $(PREFIX)gcc -export CXX := $(PREFIX)g++ -export AR := $(PREFIX)ar -export OBJCOPY := $(PREFIX)objcopy - -include $(DEVKITPPC)/base_rules - -#--------------------------------------------------------------------------------- -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -# DATA is a list of directories containing binary files -# LIBDIR is where the built library will be placed -# all directories are relative to this makefile -#--------------------------------------------------------------------------------- -BUILD ?= release -SOURCES := source \ - source/gui \ - source/resources \ - source/sounds \ - source/video \ - source/video/shaders -INCLUDES := source \ - include -DATA := -LIB := lib - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -CFLAGS = -g -Os -Wall -D__wiiu__ -D_GNU_SOURCE $(MACHDEP) $(INCLUDE) -CXXFLAGS = $(CFLAGS) - -ifeq ($(DO_LOGGING), 1) - CFLAGS += -D__LOGGING__ - CXXFLAGS += -D__LOGGING__ -endif - -ASFLAGS := -mregnames - -export WIIUBIN := $(LIB)/libgui.a - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project -#--------------------------------------------------------------------------------- -LIBS := -lutils -ldynamiclibs -lfreetype -lgd -lpng -ljpeg -lz -lmad -lvorbisidec - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export TOPDIR ?= $(CURDIR)/.. -export DEPSDIR := $(CURDIR)/$(BUILD) - -export INCLUDEDIR := $(PORTLIBS)/include/libgui - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) $(sFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) -I$(LIBOGC_INC) \ - -I$(CURDIR)/$(BUILD) -I$(PORTLIBS)/include \ - -I$(PORTLIBS)/include/freetype2 -I$(PORTLIBS)/include/libutils - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) $(PORTLIBS)/lib - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr debug release $(LIB) include - -all: $(WIIUBIN) - -install: - @cp $(BUILD)/lib/libgui.a $(PORTLIBS)/lib - @mkdir -p $(INCLUDEDIR)/gui/ - @mkdir -p $(INCLUDEDIR)/resources/ - @mkdir -p $(INCLUDEDIR)/sounds/ - @mkdir -p $(INCLUDEDIR)/video/shaders - @cp source/gui/*.h $(INCLUDEDIR)/gui/ - @cp source/resources/*.h $(INCLUDEDIR)/resources/ - @cp source/sounds/*.h $(INCLUDEDIR)/sounds/ - @cp source/sounds/*.hpp $(INCLUDEDIR)/sounds/ - @cp source/video/*.h $(INCLUDEDIR)/video/ - @cp source/video/shaders/*.h $(INCLUDEDIR)/video/shaders/ - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(WIIUBIN) : $(OFILES) $(LIB) - @rm -f "$(WIIUBIN)" - @$(AR) rcs "$(WIIUBIN)" $(OFILES) - @echo built ... $(notdir $@) - - -$(LIB): - mkdir $(LIB) - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- - diff --git a/README.md b/README.md index 14fca0d..07addaa 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,26 @@ # libgui -[![Build Status](https://travis-ci.org/Maschell/libgui.svg?branch=master)](https://travis-ci.org/Maschell/libgui) +[![Build Status](https://travis-ci.org/Maschell/libgui.svg?branch=wut)](https://travis-ci.org/Maschell/libgui/tree/wut) ## Usage Following steps are required for initialization: ```C -InitOSFunctionPointers(); // Load OS functions -InitPadScoreFunctionPointers(); -InitVPadFunctionPointers(); // Input functions for GUI control -InitFSFunctionPointers(); // To load file from the SD Card -InitGX2FunctionPointers(); // For rendering -InitAXFunctionPointers(); // For sound - -mount_sd_fat("sd"); // Mounting the SD Card memoryInitialize(); // Initialize memory management //DO GUI STUFF HERE! memoryRelease(); -unmount_sd_fat("sd"); ``` Link the application with: ```Makefile --lgui -lutils -ldynamiclibs -lfreetype -lgd -lpng -ljpeg -lz -lmad -lvorbisidec +-lgui -lutilswut -lfreetype -lgd -lpng -ljpeg -lz -lmad -lvorbisidec ``` You also need to add the include path to your Makefile. Example: ```Makefile export INCLUDE := [...] -I$(PORTLIBS)/include/freetype2 \ - -I$(PORTLIBS)/include/libgui \ + -I$(WUT_ROOT)/include/libgui \ -I$(PORTLIBS)/include ``` @@ -39,10 +30,11 @@ TODO: provide more information To be able to use libgui, you need to install the following dependencies: - Application needs to be loaded from the [homebrew_launcher](https://github.com/dimok789/homebrew_launcher) -- [libutils](https://github.com/Maschell/libutils) for common functions. -- [dynamic_libs](https://github.com/Maschell/dynamic_libs/tree/lib) for access to the functions. +- [libutils](https://github.com/Maschell/libutils/tree/wut) (WUT branch) for common functions. +- [wut](https://github.com/decaf-emu/wut) -And other portable libraries that can be found in the "libs" folder of this repository. Extract the "portlibs.zip" into your devkitPro directory. +And other portable libraries that can be found in the "libs" folder of this repository. Extract the "portlibs.zip" into your devkitPro directory. +`7z x -y ./libs/portlibs.zip -o${DEVKITPRO}` This package includes: - freetype2 diff --git a/source/gui/FreeTypeGX.h b/include/gui/FreeTypeGX.h similarity index 59% rename from source/gui/FreeTypeGX.h rename to include/gui/FreeTypeGX.h index b93341d..49170d3 100644 --- a/source/gui/FreeTypeGX.h +++ b/include/gui/FreeTypeGX.h @@ -34,17 +34,20 @@ #include #include + +#include + +#include +#include + #include #include -#include - /*! \struct ftgxCharData_ * * Font face character glyph relevant data structure. */ -typedef struct ftgxCharData_ -{ +typedef struct ftgxCharData_ { int16_t renderOffsetX; /**< Texture X axis bearing offset. */ uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */ uint16_t glyphAdvanceY; /**< Character glyph Y coordinate advance in pixels. */ @@ -61,8 +64,7 @@ typedef struct ftgxCharData_ * * Offset structure which hold both a maximum and minimum value. */ -typedef struct ftgxDataOffset_ -{ +typedef struct ftgxDataOffset_ { int16_t ascender; /**< Maximum data offset. */ int16_t descender; /**< Minimum data offset. */ int16_t max; /**< Maximum data offset. */ @@ -93,7 +95,9 @@ typedef struct ftgxDataOffset_ ftgxDataOffset; #define FTGX_STYLE_MASK 0xf000 /**< Constant color value used only to sanitize Doxygen documentation. */ -static const GX2ColorF32 ftgxWhite = (GX2ColorF32){ 1.0f, 1.0f, 1.0f, 1.0f }; +static const GX2ColorF32 ftgxWhite = (GX2ColorF32) { + 1.0f, 1.0f, 1.0f, 1.0f +}; //! forward declaration @@ -108,48 +112,46 @@ class CVideo; * a specified texture format. Rendering of the data to the EFB is accomplished through the application of high performance * GX texture functions resulting in high throughput of string rendering. */ -class FreeTypeGX -{ - private: - FT_Library ftLibrary; /**< FreeType FT_Library instance. */ - FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */ - int16_t ftPointSize; /**< Current set size of the rendered font. */ - bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */ - uint8_t vertexIndex; /**< Vertex format descriptor index. */ - GX2Sampler ftSampler; +class FreeTypeGX { +private: + FT_Library ftLibrary; /**< FreeType FT_Library instance. */ + FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */ + int16_t ftPointSize; /**< Current set size of the rendered font. */ + bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */ + uint8_t vertexIndex; /**< Vertex format descriptor index. */ + GX2Sampler ftSampler; - typedef struct _ftGX2Data - { - ftgxDataOffset ftgxAlign; - std::map ftgxCharMap; - } ftGX2Data; + typedef struct _ftGX2Data { + ftgxDataOffset ftgxAlign; + std::map ftgxCharMap; + } ftGX2Data; - std::map fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */ + std::map fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */ - int16_t getStyleOffsetWidth(uint16_t width, uint16_t format); - int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize); + int16_t getStyleOffsetWidth(uint16_t width, uint16_t format); + int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize); - void unloadFont(); - ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize); - uint16_t cacheGlyphDataComplete(int16_t pixelSize); - void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData); + void unloadFont(); + ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize); + uint16_t cacheGlyphDataComplete(int16_t pixelSize); + void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData); - void copyTextureToFramebuffer(CVideo * pVideo, GX2Texture *tex, int16_t screenX, int16_t screenY, int16_t screenZ, const glm::vec4 & color, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 & blurColor, const float & internalRenderingScale); + void copyTextureToFramebuffer(CVideo * pVideo, GX2Texture *tex, int16_t screenX, int16_t screenY, int16_t screenZ, const glm::vec4 & color, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 & blurColor, const float & internalRenderingScale); - public: - FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace = false); - ~FreeTypeGX(); +public: + FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace = false); + ~FreeTypeGX(); - uint16_t drawText(CVideo * pVideo, int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, const glm::vec4 & color, - uint16_t textStyling, uint16_t textWidth, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 & blurColor, const float & internalRenderingScale); + uint16_t drawText(CVideo * pVideo, int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, const glm::vec4 & color, + uint16_t textStyling, uint16_t textWidth, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 & blurColor, const float & internalRenderingScale); - uint16_t getWidth(const wchar_t *text, int16_t pixelSize); - uint16_t getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000); - uint16_t getHeight(const wchar_t *text, int16_t pixelSize); - void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0); + uint16_t getWidth(const wchar_t *text, int16_t pixelSize); + uint16_t getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000); + uint16_t getHeight(const wchar_t *text, int16_t pixelSize); + void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0); - static wchar_t* charToWideChar(const char* p); - static char* wideCharToUTF8(const wchar_t* strChar); + static wchar_t* charToWideChar(const char* p); + static char* wideCharToUTF8(const wchar_t* strChar); }; #endif /* FREETYPEGX_H_ */ diff --git a/source/gui/GameBgImage.h b/include/gui/GameBgImage.h similarity index 77% rename from source/gui/GameBgImage.h rename to include/gui/GameBgImage.h index a78b715..f778d1a 100644 --- a/source/gui/GameBgImage.h +++ b/include/gui/GameBgImage.h @@ -1,11 +1,10 @@ #ifndef _GAME_BG_IMAGE_H_ #define _GAME_BG_IMAGE_H_ -#include "GuiImageAsync.h" -#include "video/shaders/Shader3D.h" +#include +#include