diff --git a/Makefile b/Makefile index 207e275ea..2d3fa0e18 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,12 @@ else ifeq ($(SYSNAME),Darwin) OS:=macos GPERF:=/usr/bin/gperf + + CC:=$(shell xcrun -f clang) + ARCHS:=$(shell uname -m) + MINVER:=10.8 + SDKROOT:=$(shell xcrun --show-sdk-path) + HOSTROOT:=/opt/local else ifeq ($(SYSNAME),BeOS) OS:=beos @@ -59,16 +65,67 @@ else endif endif +# CROSS COMPILATION OVERRIDES +# +# Usage: +# make HOST= HOSTROOT= [EXTRA_ARGS] +# +# may be one of: +# iphoneos Build for the iphoneos, presumably on macOS. +# iphonesimulator Build for the iphonesimulator, presumably on macOS. +# +# is the directory containing support files for building for : +# /include Header files. +# /lib Library files. +# /lib/pkgconfig *.pc files. +# +ifdef HOST + ifndef HOSTROOT + $(error Must set HOSTROOT to cross compile) + endif + ifeq ($(wildcard $(HOSTROOT)/.),) + $(error Invalid HOSTROOT: $(HOSTROOT)) + endif + + ifeq ($(HOST),iphoneos) + OS:=iphoneos + CC:=$(shell xcrun --sdk iphoneos -f clang) + ARCHS:=arm64 armv7s armv7 + MINVER:=9.0 + SDKROOT:=$(shell xcrun --sdk iphoneos --show-sdk-path) + else ifeq ($(HOST),iphonesimulator) + OS:=iphonesimulator + CC:=$(shell xcrun --sdk iphonesimulator -f clang) + ARCHS:=$(shell uname -m) + MINVER:=9.0 + SDKROOT:=$(shell xcrun --sdk iphonesimulator --show-sdk-path) + else + $(error Invalid HOST: $(HOST)) + endif + + # We set PKG_CONFIG_LIBDIR instead of PKG_CONFIG_PATH because we want to + # *change* where pkg-config looks for .pc files instead of adding to the + # default path which may have libraries that aren't for HOST. + export PKG_CONFIG_LIBDIR:=$(HOSTROOT)/lib/pkgconfig +endif + # change to sdl-console to build a console version on Windows SDL_PCNAME:=sdl2 WINDRES:=windres PKG_CONFIG:=pkg-config +ifdef PKG_CONFIG_LIBDIR + # Cross compilation override + PKG_CONFIG:=PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR) $(PKG_CONFIG) +endif -# test if a library can be linked -linktest = $(shell if $(CC) $(CPPFLAGS) $(CFLAGS) -o dummy.o dummy.c $(LDFLAGS) $(1) $(2) > /dev/null 2>&1; \ +# test if a pkg-config library exists or can be linked manually +linktest = $(shell [ -n "$(1)" ] \ + && $(PKG_CONFIG) --exists $(1) \ + && $(PKG_CONFIG) --libs $(1) \ + || if $(CC) $(CPPFLAGS) $(CFLAGS) -o dummy.o dummy.c $(LDFLAGS) $(2) $(3) > /dev/null 2>&1; \ then \ - echo "$(1)"; \ + echo "$(2)"; \ fi ;) # test compiler options @@ -88,50 +145,59 @@ RAD_CMD:=$($(OS)_RAD_CMD) windows_SO_TYPE:=dll macos_SO_TYPE:=dylib +iphoneos_SO_TYPE:=dylib +iphonesimulator_SO_TYPE:=dylib beos_SO_TYPE:=so linux_SO_TYPE:=so SO_TYPE:=$($(OS)_SO_TYPE) -windows_LIBMINGW:=-lmingw32 +windows_LIBMINGW:=-L/usr/local/lib -lmingw32 LIBMINGW:=$($(OS)_LIBMINGW) windows_EXE_EXT:=.exe EXE_EXT:=$($(OS)_EXE_EXT) -windows_BUNDLE:= -macos_BUNDLE=./TuxPaint.app -beos_BUNDLE:= -linux_BUNDLE:= +macos_BUNDLE:=./TuxPaint.app +iphoneos_BUNDLE:=./TuxPaint-iphoneos.app +iphonesimulator_BUNDLE:=./TuxPaint-iphonesimulator.app BUNDLE:=$($(OS)_BUNDLE) windows_ARCH_LIBS:=obj/win32_print.o obj/resource.o macos_ARCH_LIBS:=src/macos_print.m obj/macos.o +iphoneos_ARCH_LIBS:=src/ios_print.m obj/ios.o +iphonesimulator_ARCH_LIBS:=src/ios_print.m obj/ios.o beos_ARCH_LIBS:=obj/BeOS_print.o linux_ARCH_LIBS:=obj/postscript_print.o ARCH_LIBS:=$($(OS)_ARCH_LIBS) windows_ARCH_CFLAGS:= -macos_ARCH_CFLAGS:=-mmacosx-version-min=10.8 -isystem /opt/local/include -DHAVE_STRCASESTR -w -headerpad_max_install_names +macos_ARCH_CFLAGS:=-isysroot $(SDKROOT) -I$(SDKROOT)/usr/include -I$(HOSTROOT)/include -mmacosx-version-min=$(MINVER) -arch $(subst $() $(), -arch ,$(ARCHS)) -w -headerpad_max_install_names -DHAVE_STRCASESTR +iphoneos_ARCH_CFLAGS:=-isysroot $(SDKROOT) -I$(SDKROOT)/usr/include -I$(HOSTROOT)/include -miphoneos-version-min=$(MINVER) -arch $(subst $() $(), -arch ,$(ARCHS)) -w -fPIC -DHAVE_STRCASESTR -DUNLINK_ONLY +iphonesimulator_ARCH_CFLAGS:=-isysroot $(SDKROOT) -I$(SDKROOT)/usr/include -I$(HOSTROOT)/include -mios-simulator-version-min=$(MINVER) -arch $(subst $() $(), -arch ,$(ARCHS)) -w -fPIC -DHAVE_STRCASESTR -DUNLINK_ONLY beos_ARCH_CFLAGS:= linux_ARCH_CFLAGS:= ARCH_CFLAGS:=$($(OS)_ARCH_CFLAGS) windows_ARCH_LDFLAGS:= -macos_ARCH_LDFLAGS:=-L/opt/local/lib +macos_ARCH_LDFLAGS:=-isysroot $(SDKROOT) -L$(HOSTROOT)/lib -mmacosx-version-min=$(MINVER) -arch $(subst $() $(), -arch ,$(ARCHS)) +iphoneos_ARCH_LDFLAGS:=-isysroot $(SDKROOT) -L$(HOSTROOT)/lib -miphoneos-version-min=$(MINVER) -arch $(subst $() $(), -arch ,$(ARCHS)) +iphonesimulator_ARCH_LDFLAGS:=-isysroot $(SDKROOT) -L$(HOSTROOT)/lib -mios-simulator-version-min=$(MINVER) -arch $(subst $() $(), -arch ,$(ARCHS)) beos_ARCH_LDFLAGS:= linux_ARCH_LDFLAGS:= ARCH_LDFLAGS:=$($(OS)_ARCH_LDFLAGS) LDFLAGS:=$(ARCH_LDFLAGS) -PAPER_LIB:=$(call linktest,-lpaper,) -PNG:=$(call linktest,-lpng,) -PNG:=$(if $(PNG),$(PNG),$(call linktest,-lpng12,)) +PAPER_LIB:=$(call linktest,,-lpaper,) +PNG:=$(call linktest,libpng,-lpng,) +PNG:=$(if $(PNG),$(PNG),$(call linktest,,-lpng12,)) FRIBIDI_LIB:=$(shell $(PKG_CONFIG) --libs fribidi) FRIBIDI_CFLAGS:=$(shell $(PKG_CONFIG) --cflags fribidi) windows_ARCH_LINKS:=-lgdi32 -lcomdlg32 $(PNG) -lz -lwinspool -lshlwapi $(FRIBIDI_LIB) -liconv -limagequant macos_ARCH_LINKS:=$(FRIBIDI_LIB) -limagequant -lSDLmain -Wl,-framework,AppKit -Wl,-framework,Cocoa +iphoneos_ARCH_LINKS:=$(FRIBIDI_LIB) -limagequant -ljpeg -lbz2 $(shell $(PKG_CONFIG) --libs freetype2 libtiff-4 libwebp libffi harfbuzz libmpg123 ogg vorbisenc vorbisidec libxml-2.0 pangoft2 libpcre) +iphonesimulator_ARCH_LINKS:=$(FRIBIDI_LIB) -limagequant -ljpeg -lbz2 $(shell $(PKG_CONFIG) --libs freetype2 libtiff-4 libwebp libffi harfbuzz libmpg123 ogg vorbisenc vorbisidec libxml-2.0 pangoft2 libpcre) beos_ARCH_LINKS:=-lintl $(PNG) -lz -lbe -lnetwork -liconv $(FRIBIDI_LIB) $(PAPER_LIB) $(STDC_LIB) -limagequant linux_ARCH_LINKS:=$(PAPER_LIB) $(FRIBIDI_LIB) -limagequant ARCH_LINKS:=$($(OS)_ARCH_LINKS) @@ -143,18 +209,24 @@ linux_ARCH_HEADERS:= ARCH_HEADERS:=$($(OS)_ARCH_HEADERS) # Where things will go when ultimately installed: -# For macOS, the prefix is relative to DESTDIR. +# For macOS and iOS, the prefix is relative to DESTDIR. windows_PREFIX:=/usr/local macos_PREFIX:=Resources +iphoneos_PREFIX:=Resources +iphonesimulator_PREFIX:=Resources linux_PREFIX:=/usr/local PREFIX:=$($(OS)_PREFIX) # Root directory to place files when creating packages. # PKG_ROOT is the old name for this, and should be undefined. -# macOS is set up as a bundle, with all files under 'Contents'. +# macOS and iOS are set up as bundles, with all files under the bundle. # "TuxPaint-1" is the OLPC XO name. Installing to ./ is bad! ifeq ($(OS),macos) DESTDIR:=$(BUNDLE)/Contents/ +else ifeq ($(OS),iphoneos) + DESTDIR:=$(BUNDLE)/ +else ifeq ($(OS),iphonesimulator) + DESTDIR:=$(BUNDLE)/ else ifeq ($(PREFIX),./) DESTDIR:=TuxPaint-1 else @@ -216,14 +288,18 @@ CURSOR_SHAPES:=LARGE # CURSOR_SHAPES:=SMALL # Libraries, paths, and flags: -SDL_LIBS:=$(shell $(PKG_CONFIG) $(SDL_PCNAME) --libs) -lSDL2_image -lSDL2_ttf -lz $(PNG) +SDL_LIBS:=$(shell $(PKG_CONFIG) $(SDL_PCNAME) --libs) +SDL_LIBS+=$(call linktest,SDL2_image,-lSDL2_image,$(SDL_LIBS)) +SDL_LIBS+=$(call linktest,SDL2_ttf,-lSDL2_ttf,$(SDL_LIBS)) +SDL_LIBS+=$(call linktest,zlib,-lz,) +SDL_LIBS+=$(call linktest,libpng,$(PNG),) # Sound support -SDL_MIXER_LIB:=$(call linktest,-lSDL2_mixer,$(SDL_LIBS)) +SDL_MIXER_LIB:=$(call linktest,SDL2_mixer,-lSDL2_mixer,$(SDL_LIBS)) NOSOUNDFLAG:=$(if $(SDL_MIXER_LIB),,-DNOSOUND$(warning -lSDL2_Mixer failed, no sound for you!)) # SDL Pango is needed to render complex scripts like Thai and Arabic -SDL2_PANGO_LIB:=$(call linktest,-lSDL2_Pango,$(SDL_LIBS)) +SDL2_PANGO_LIB:=$(call linktest,SDL2_Pango,-lSDL2_Pango,$(SDL_LIBS)) NOPANGOFLAG:=$(if $(SDL2_PANGO_LIB),,-DNO_SDLPANGO$(warning -lSDL2_Pango failed, no scripts for you!)) SDL_LIBS+=$(SDL_MIXER_LIB) $(SDL2_PANGO_LIB) @@ -478,6 +554,8 @@ trans: windows_ARCH_INSTALL:= macos_ARCH_INSTALL:=install-macbundle TuxPaint.dmg +iphoneos_ARCH_INSTALL:=install-iosbundle +iphonesimulator_ARCH_INSTALL:=install-iosbundle linux_ARCH_INSTALL:=install-xdg ARCH_INSTALL:=$($(OS)_ARCH_INSTALL) @@ -1025,7 +1103,7 @@ install-man: .PHONY: install-macbundle install-macbundle: @echo - @echo "...Installing App Bundle Support Files..." + @echo "...Installing macOS App Bundle Support Files..." @install -d -m 755 $(BUNDLE)/Contents/MacOS @install -d -m 755 $(BUNDLE)/Contents/Resources @install -d -m 755 $(BUNDLE)/Contents/lib @@ -1035,6 +1113,20 @@ install-macbundle: @install -m 644 macos/tuxpaint.icns $(BUNDLE)/Contents/Resources @macos/build-app.sh +# Install the support files for iOS application bundle +.PHONY: install-iosbundle +install-iosbundle: + @echo + @echo "...Installing iOS App Bundle Support Files..." + install -m 755 tuxpaint $(BUNDLE) + install -m 644 ios/PkgInfo $(BUNDLE) + install -m 644 ios/Info.plist $(BUNDLE) + install -m 644 ios/Info.plist $(BUNDLE)/Resources + install -m 644 ios/tuxpaint.icns $(BUNDLE) + install -m 644 ios/tuxpaint.cfg $(BUNDLE) + install -m 644 ios/Splash.png $(BUNDLE) + ibtool --compile $(BUNDLE)/Splash.storyboardc ios/Splash.storyboard + # Create DMG for macOS TuxPaint.dmg: @@ -1071,7 +1163,7 @@ obj/tuxpaint.o: src/tuxpaint.c \ src/tools.h src/titles.h src/colors.h src/shapes.h \ src/sounds.h src/tip_tux.h src/great.h \ src/tp_magic_api.h src/parse.h src/onscreen_keyboard.h \ - src/gifenc.h \ + src/gifenc.h src/platform.h \ src/$(MOUSEDIR)/arrow.xbm src/$(MOUSEDIR)/arrow-mask.xbm \ src/$(MOUSEDIR)/hand.xbm src/$(MOUSEDIR)/hand-mask.xbm \ src/$(MOUSEDIR)/insertion.xbm \ @@ -1211,12 +1303,18 @@ obj/postscript_print.o: src/postscript_print.c \ @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \ -c src/postscript_print.c -o obj/postscript_print.o -obj/macos.o: src/macos.c src/macos.h src/debug.h +obj/macos.o: src/macos.c src/macos.h src/platform.h src/debug.h @echo @echo "...Compiling macOS support..." @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \ -c src/macos.c -o obj/macos.o +obj/ios.o: src/ios.c src/ios.h src/platform.h src/debug.h + @echo + @echo "...Compiling iOS support..." + @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \ + -c src/ios.c -o obj/ios.o + obj/resource.o: win32/resources.rc win32/resource.h @echo @echo "...Compiling win32 resources..." @@ -1256,11 +1354,20 @@ obj: ###### MAGIC_SDL_CPPFLAGS:=$(shell $(PKG_CONFIG) $(SDL_PCNAME) --cflags) -MAGIC_SDL_LIBS:=-L/usr/local/lib $(LIBMINGW) $(shell $(PKG_CONFIG) $(SDL_PCNAME) --libs) -lSDL2_image -lSDL2_ttf $(SDL_MIXER_LIB) -MAGIC_ARCH_LINKS:=-lintl $(PNG) +MAGIC_SDL_LIBS:=$(LIBMINGW) $(shell $(PKG_CONFIG) $(SDL_PCNAME) --libs) -lSDL2_image -lSDL2_ttf $(SDL_MIXER_LIB) +windows_MAGIC_ARCH_LINKS:=-lintl $(PNG) +macos_MAGIC_ARCH_LINKS:=-lintl $(PNG) +iphoneos_MAGIC_ARCH_LINKS:=-lintl -ljpeg $(PNG) $(shell $(PKG_CONFIG) --libs libtiff-4 libwebp libmpg123 ogg vorbisenc vorbisidec) +iphonesimulator_MAGIC_ARCH_LINKS:=-lintl -ljpeg $(PNG) $(shell $(PKG_CONFIG) --libs libtiff-4 libwebp libmpg123 ogg vorbisenc vorbisidec) +beos_MAGIC_ARCH_LINKS:=-lintl $(PNG) +linux_MAGIC_ARCH_LINKS:=-lintl $(PNG) +MAGIC_ARCH_LINKS:=$($(OS)_MAGIC_ARCH_LINKS) + windows_PLUGIN_LIBS:=$(MAGIC_SDL_LIBS) $(MAGIC_ARCH_LINKS) macos_PLUGIN_LIBS:=$(MAGIC_SDL_LIBS) $(MAGIC_ARCH_LINKS) +iphoneos_PLUGIN_LIBS:=$(MAGIC_SDL_LIBS) $(MAGIC_ARCH_LINKS) +iphonesimulator_PLUGIN_LIBS:=$(MAGIC_SDL_LIBS) $(MAGIC_ARCH_LINKS) beos_PLUGIN_LIBS:="$(MAGIC_SDL_LIBS) $(MAGIC_ARCH_LINKS) $(MAGIC_SDL_CPPFLAGS)" linux_PLUGIN_LIBS:= PLUGIN_LIBS:=$($(OS)_PLUGIN_LIBS) diff --git a/ios/Info.plist b/ios/Info.plist new file mode 100644 index 000000000..9ef560077 --- /dev/null +++ b/ios/Info.plist @@ -0,0 +1,39 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + tuxpaint + CFBundleGetInfoString + 0.9.26, Copyright 2009-2020, Tux Paint Development Team + CFBundleIconFile + tuxpaint.icns + CFBundleIdentifier + com.newbreedsoftware.tuxpaint + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Tux Paint + CFBundlePackageType + APPL + CFBundleShortVersionString + 0.9.26 + CFBundleSignature + TXPT + CFBundleVersion + 2020-12-27 + UISupportedInterfaceOrientations + + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIStatusBarHidden + + UIViewControllerBasedStatusBarAppearance + + UILaunchStoryboardName + Splash + + diff --git a/ios/PkgInfo b/ios/PkgInfo new file mode 100644 index 000000000..c00b87013 --- /dev/null +++ b/ios/PkgInfo @@ -0,0 +1 @@ +APPLTXPT \ No newline at end of file diff --git a/ios/Splash.png b/ios/Splash.png new file mode 100644 index 000000000..9db41423a Binary files /dev/null and b/ios/Splash.png differ diff --git a/ios/Splash.storyboard b/ios/Splash.storyboard new file mode 100644 index 000000000..b82fbac8b --- /dev/null +++ b/ios/Splash.storyboard @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ios/tuxpaint.cfg b/ios/tuxpaint.cfg new file mode 100644 index 000000000..75173e917 --- /dev/null +++ b/ios/tuxpaint.cfg @@ -0,0 +1,4 @@ +# Default iOS tuxpaint.cfg + +fullscreen=native +noprint=yes diff --git a/ios/tuxpaint.icns b/ios/tuxpaint.icns new file mode 100644 index 000000000..8df6a921a Binary files /dev/null and b/ios/tuxpaint.icns differ diff --git a/src/fonts.c b/src/fonts.c index 8e5430adb..eff5628fa 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -56,6 +56,7 @@ The renaming ends here. */ +#include "platform.h" #include "fonts.h" #include "i18n.h" #include "progressbar.h" @@ -67,8 +68,10 @@ #include "win32_print.h" #endif -#ifdef __APPLE__ +#if defined(__MACOS__) #include "macos.h" +#elif defined(__IOS__) +#include "ios.h" #endif #ifdef __HAIKU__ @@ -193,7 +196,7 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size) if (!ret) { - snprintf(str, sizeof(str), "%s/%s.ttf", macos_fontsPath(), lang_prefix); + snprintf(str, sizeof(str), "%s/%s.ttf", apple_fontsPath(), lang_prefix); ret = TuxPaint_Font_OpenFont("", str, size); } #endif @@ -981,7 +984,7 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer #elif defined(__APPLE__) loadfonts(screen, texture, renderer, "/System/Library/Fonts"); loadfonts(screen, texture, renderer, "/Library/Fonts"); - loadfonts(screen, texture, renderer, macos_fontsPath()); + loadfonts(screen, texture, renderer, apple_fontsPath()); loadfonts(screen, texture, renderer, "/usr/share/fonts"); loadfonts(screen, texture, renderer, "/usr/X11R6/lib/X11/fonts"); #elif defined(__ANDROID__) diff --git a/src/ios.c b/src/ios.c new file mode 100644 index 000000000..1c7a682f5 --- /dev/null +++ b/src/ios.c @@ -0,0 +1,46 @@ +/* + ios.c + + Copyright (c) 2021 + http://www.tuxpaint.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + (See COPYING.txt) +*/ +#include +#include +#include +#include "ios.h" + +#define IOS_FONTS_PATH "../Library/Fonts" +#define IOS_PREFERENCES_PATH "../Library/Application Support/TuxPaint" + + +const char *apple_fontsPath(void) +{ + return IOS_FONTS_PATH; +} + + +const char *apple_preferencesPath(void) +{ + return IOS_PREFERENCES_PATH; +} + + +const char *apple_globalPreferencesPath(void) +{ + return IOS_PREFERENCES_PATH; +} diff --git a/src/ios.h b/src/ios.h new file mode 100644 index 000000000..bef4f72c7 --- /dev/null +++ b/src/ios.h @@ -0,0 +1,30 @@ +/* + ios.h + + Copyright (c) 2021 + http://www.tuxpaint.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + (See COPYING.txt) +*/ +#ifndef __IOS_H__ +#define __IOS_H__ + +const char *apple_fontsPath(void); +const char *apple_preferencesPath(void); +const char *apple_globalPreferencesPath(void); + + +#endif /* __IOS_H__ */ diff --git a/src/ios_print.h b/src/ios_print.h new file mode 100644 index 000000000..340679cf4 --- /dev/null +++ b/src/ios_print.h @@ -0,0 +1,32 @@ +/* + ios_print.h + + Copyright (c) 2021 + http://www.tuxpaint.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + (See COPYING.txt) +*/ +#ifndef __IOS_PRINT_H__ +#define __IOS_PRINT_H__ + +#include "SDL.h" + + +int DisplayPageSetup(const SDL_Surface* surface); +const char* SurfacePrint(const SDL_Surface* surface, int showDialog); + + +#endif /* __IOS_PRINT_H__ */ diff --git a/src/ios_print.m b/src/ios_print.m new file mode 100644 index 000000000..71adab9ec --- /dev/null +++ b/src/ios_print.m @@ -0,0 +1,39 @@ +/* + ios_print.m + + Copyright (c) 2021 + http://www.tuxpaint.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + (See COPYING.txt) +*/ +#import "ios_print.h" + + +int DisplayPageSetup(const SDL_Surface* surface) +{ + /* TODO */ + + return 0; +} + + +const char* SurfacePrint(const SDL_Surface* surface, int showDialog) +{ + /* TODO */ + + return NULL; +} + diff --git a/src/macos.c b/src/macos.c index 148661f5b..4f311adc6 100644 --- a/src/macos.c +++ b/src/macos.c @@ -1,6 +1,24 @@ /* - * FIXME - */ + macos.c + + Copyright (c) 2021 + http://www.tuxpaint.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + (See COPYING.txt) +*/ #include #include #include @@ -14,7 +32,7 @@ /** * FIXME */ -const char *macos_fontsPath(void) +const char *apple_fontsPath(void) { static char *p = NULL; @@ -27,7 +45,7 @@ const char *macos_fontsPath(void) if (p) sprintf(p, MACOS_FONTS_PATH, getenv("HOME")); else - perror("macos_fontsPath"); + perror("apple_fontsPath"); } return p; @@ -37,7 +55,7 @@ const char *macos_fontsPath(void) /** * FIXME */ -const char *macos_preferencesPath(void) +const char *apple_preferencesPath(void) { static char *p = NULL; @@ -50,7 +68,7 @@ const char *macos_preferencesPath(void) if (p) sprintf(p, MACOS_PREFERENCES_PATH, getenv("HOME")); else - perror("macos_preferencesPath"); + perror("apple_preferencesPath"); } return p; @@ -60,7 +78,7 @@ const char *macos_preferencesPath(void) /** * FIXME */ -const char *macos_globalPreferencesPath(void) +const char *apple_globalPreferencesPath(void) { return MACOS_GLOBAL_PREFERENCES_PATH; } diff --git a/src/macos.h b/src/macos.h index db965d61b..a4170a091 100644 --- a/src/macos.h +++ b/src/macos.h @@ -1,9 +1,30 @@ +/* + macos.h + + Copyright (c) 2021 + http://www.tuxpaint.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + (See COPYING.txt) +*/ #ifndef __MACOS_H__ #define __MACOS_H__ -const char *macos_fontsPath(void); -const char *macos_preferencesPath(void); -const char *macos_globalPreferencesPath(void); +const char *apple_fontsPath(void); +const char *apple_preferencesPath(void); +const char *apple_globalPreferencesPath(void); #endif /* __MACOS_H__ */ diff --git a/src/platform.h b/src/platform.h new file mode 100644 index 000000000..92e445b10 --- /dev/null +++ b/src/platform.h @@ -0,0 +1,45 @@ +/* + platform.h + + Copyright (c) 2021 + http://www.tuxpaint.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + (See COPYING.txt) +*/ +#ifndef __PLATFORM_H__ +#define __PLATFORM_H__ + + +#if defined(__APPLE__) + #include + + /* + * MAC test must be last because it tests true even on iOS / tvOS / watchOS. + */ + + #if TARGET_OS_IOS || TARGET_OS_IPHONE || TARGET_OS_SIMULATOR || TARGET_IPHONE_SIMULATOR || TARGET_OS_EMBEDDED + #define __IOS__ 1 + #elif TARGET_OS_OSX || TARGET_OS_MAC + #define __MACOS__ 1 + #else + #define __OTHER_APPLE__ 1 + + #warning "Unsupported Apple platform, will build on a best-effort basis" + #endif +#endif /* __APPLE__ */ + + +#endif /* __PLATFORM_H__ */ diff --git a/src/tuxpaint.c b/src/tuxpaint.c index f39f6d266..fe7ff3c3b 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -25,6 +25,7 @@ June 14, 2002 - March 8, 2021 */ +#include "platform.h" /* (Note: VER_VERSION and VER_DATE are now handled by Makefile) */ @@ -303,15 +304,21 @@ typedef struct safer_dirent /* Not BeOS */ -#ifdef __APPLE__ +#if defined(__MACOS__) -/* Apple */ +/* macOS */ #include "macos_print.h" -#else /* __APPLE__ */ +#elif defined(__IOS__) -/* Not Windows, not BeOS, not Apple */ +/* iOS */ + +#include "ios_print.h" + +#else /* __MACOS__, __IOS__ */ + +/* Not Windows, not BeOS, not macOS, not iOS */ #ifdef __ANDROID__ #define AUTOSAVE_GOING_BACKGROUND @@ -326,7 +333,7 @@ typedef struct safer_dirent #endif /* __ANDROID__ */ -#endif /* __APPLE__ */ +#endif /* __MACOS__, __IOS__ */ #endif /* __BEOS__ */ @@ -373,8 +380,10 @@ static void mtw(wchar_t * wtok, char *tok) #endif /* WIN32 */ -#ifdef __APPLE__ +#if defined(__MACOS__) #include "macos.h" +#elif defined(__IOS__) +#include "ios.h" #endif #include @@ -17718,7 +17727,7 @@ void do_print(void) SurfacePrint(save_canvas); #elif defined(__APPLE__) - /* Mac OS X */ + /* macOS, iOS */ int show = (want_alt_printcommand && !fullscreen); const char *error = SurfacePrint(save_canvas, show); @@ -23925,7 +23934,7 @@ static void setup_config(char *argv[]) result = find_directory(B_USER_SETTINGS_DIRECTORY, volume, false, buffer, sizeof(buffer)); asprintf((char **)&savedir, "%s/%s", buffer, "TuxPaint"); #elif __APPLE__ - savedir = strdup(macos_preferencesPath()); + savedir = strdup(apple_preferencesPath()); #elif __ANDROID__ savedir = SDL_AndroidGetExternalStoragePath(); #else @@ -23969,8 +23978,8 @@ static void setup_config(char *argv[]) /* BeOS: Use a "tuxpaint.cfg" file: */ strcpy(str, "tuxpaint.cfg"); /* safe; sufficient size */ #elif defined(__APPLE__) - /* Mac OS X: Use a "tuxpaint.cfg" file in the Tux Paint application support folder */ - safe_snprintf(str, sizeof(str), "%s/tuxpaint.cfg", macos_preferencesPath()); + /* macOS, iOS: Use a "tuxpaint.cfg" file in the Tux Paint application support folder */ + safe_snprintf(str, sizeof(str), "%s/tuxpaint.cfg", apple_preferencesPath()); #elif defined(__ANDROID__) /* Try to find the user's config file */ /* This file is writed by the tuxpaint config activity when the user runs it */ @@ -24004,9 +24013,9 @@ static void setup_config(char *argv[]) #elif defined(__APPLE__) /* EP added this conditional section for Mac to fix folder & extension inconsistency with Tux Paint Config application) */ - /* Mac OS X: Use a "tuxpaint.cfg" file in the *global* Tux Paint + /* macOS, iOS: Use a "tuxpaint.cfg" file in the *global* Tux Paint application support folder */ - safe_snprintf(str, sizeof(str), "%s/tuxpaint.cfg", macos_globalPreferencesPath()); + safe_snprintf(str, sizeof(str), "%s/tuxpaint.cfg", apple_globalPreferencesPath()); parse_file_options(&tmpcfg_sys, str); #elif defined(__ANDROID__) /* Load the config file we provide in assets/etc/tuxpaint.cfg */ @@ -24500,7 +24509,7 @@ static void chdir_to_binary(char *argv0) char *app_path = strdup(argv0); char *slash = strrchr(app_path, '/'); -#if defined(__APPLE__) +#if defined(__MACOS__) // On macOS, execution is deep inside the app bundle. // E.g., "/Applications/TuxPaint.app/Contents/MacOS/tuxpaint" // But we want to point somewhere higher up, say to "Contents", so we can access