XSDL: fixed help message

This commit is contained in:
Sergii Pylypenko
2019-10-08 18:39:36 +03:00
parent 1e71441946
commit a967016781
8 changed files with 90 additions and 34 deletions

View File

@@ -262,19 +262,19 @@ AppMinimumRAM=0
NDK_TOOLCHAIN_VERSION=clang
# Android platform version.
# android-16 = Android 4.1, the earliest supported version for NDK r18.
# android-16 = Android 4.1, the earliest supported version in NDK r18.
# android-18 = Android 4.3, the first version supporting GLES3.
# android-21 = Android 5.1, the first version with SO_REUSEPORT defined.
APP_PLATFORM=
# Specify architectures to compile, 'all' or 'y' to compile for all architectures.
# Available architectures: armeabi-v7a x86 arm64-v8a x86_64
MultiABI='arm64-v8a' # armeabi-v7a x86 x86_64
# Available architectures: armeabi-v7a arm64-v8a x86 x86_64
MultiABI='arm64-v8a'
# Optional shared libraries to compile - removing some of them will save space
# MP3 support by libMAD is encumbered by patents and libMAD is GPL-ed
# MP3 patents are expired, but libmad license is GPL, not LGPL
# Available libraries: mad (GPL-ed!) sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx sdl_sound intl xml2 lua jpeg png ogg flac tremor vorbis freetype xerces curl theora fluidsynth lzma lzo2 mikmod openal timidity zzip bzip2 yaml-cpp python boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread glu avcodec avdevice avfilter avformat avresample avutil swscale swresample bzip2
CompiledLibraries="sdl_image icui18n iculx icu-le-hb harfbuzz icudata icuuc iconv charset"
CompiledLibraries="sdl_image c++_shared"
# Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n)
CustomBuildScript=n
@@ -283,7 +283,7 @@ CustomBuildScript=n
AppCflags=''
# Aditional C++-specific compiler flags for application, added after AppCflags
AppCppflags='-fexceptions'
AppCppflags=''
# Additional LDFLAGS for application
AppLdflags=''

View File

@@ -14,7 +14,6 @@
#include <math.h>
#include <android/log.h>
#include <wchar.h>
#include <stdexcept>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
@@ -24,6 +23,9 @@
#define fprintf(X, ...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__)
#define printf(...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__)
extern int create_server_socket(int portno);
/*----------------------------------------------------------
Definitions...
----------------------------------------------------------*/
@@ -411,16 +413,6 @@ void tiled_back(SDL_Surface *back, SDL_Surface *screen, int xo, int yo)
SDL_BlitSurface(back, NULL, screen, &r);
}
void throw_something_more()
{
throw std::runtime_error("Exception: whoops");
}
void throw_something()
{
throw_something_more();
}
/*----------------------------------------------------------
main()
----------------------------------------------------------*/
@@ -594,6 +586,8 @@ int main(int argc, char* argv[])
}
//SDL_ANDROID_SetScreenKeyboardButtonGenerateTouchEvents(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, 1);
//SDL_ANDROID_SetScreenKeyboardButtonGenerateTouchEvents(SDL_ANDROID_SCREENKEYBOARD_BUTTON_3, 1);
create_server_socket(6000);
while(1)
{
@@ -700,11 +694,6 @@ int main(int argc, char* argv[])
{
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, 1);
SDL_ANDROID_SetMouseEmulationMode(0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
try {
throw_something();
} catch (const std::exception & e) {
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Got exception: %s", e.what());
}
}
if(evt.key.keysym.sym == SDLK_1)
{

View File

@@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <android/log.h>
#define fprintf(X, ...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__)
#define printf(...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__)
void error(const char *msg)
{
perror(msg);
__android_log_print(ANDROID_LOG_ERROR, "Ballfield", "%s", msg);
exit(1);
}
int create_server_socket(int portno)
{
int sockfd, newsockfd;
socklen_t clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) error("ERROR opening socket");
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
if (bind(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0) error("ERROR on binding");
listen(sockfd,5);
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Opened TCP socket %d port %d", sockfd, portno);
return 0;
/*
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd,
(struct sockaddr *) &cli_addr,
&clilen);
if (newsockfd < 0)
error("ERROR on accept");
bzero(buffer,256);
n = read(newsockfd,buffer,255);
if (n < 0) error("ERROR reading from socket");
printf("Here is the message: %s\n",buffer);
n = write(newsockfd,"I got your message",18);
if (n < 0) error("ERROR writing to socket");
close(newsockfd);
close(sockfd);
return 0;
*/
}

View File

@@ -275,7 +275,7 @@ MultiABI='arm64-v8a'
# Optional shared libraries to compile - removing some of them will save space
# MP3 patents are expired, but libmad license is GPL, not LGPL
# Available libraries: mad (GPL-ed!) sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx sdl_sound intl xml2 lua jpeg png ogg flac tremor vorbis freetype xerces curl theora fluidsynth lzma lzo2 mikmod openal timidity zzip bzip2 yaml-cpp python boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread glu avcodec avdevice avfilter avformat avresample avutil swscale swresample bzip2
CompiledLibraries="jpeg png freetype sdl_ttf crypto"
CompiledLibraries="freetype sdl_ttf crypto sdl_savepng jpeg png"
# Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n)
CustomBuildScript=y

View File

@@ -70,7 +70,7 @@ xkb/.libs/libxkbstubs.a \
composite/.libs/libcomposite.a \
os/.libs/libos.a \
-L$CURDIR/../../../libs/'"$1"' \
-lpixman-1 -lXfont2 -lXau -lxshmfence -lXdmcp -lfontenc -lfreetype \
-lpixman-1 -lXfont2 -lXau -lxshmfence -lXdmcp -lfontenc -lfreetype -lsdl_savepng -lpng \
-llog -lsdl-1.2 -lsdl_native_helpers -lGLESv1_CM -landroid-shmem -l:libcrypto.so.sdl.1.so -lz -lm -ldl' \
|| exit 1

View File

@@ -15,6 +15,7 @@
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_screenkeyboard.h>
#include <SDL/SDL_android.h>
#include <savepng.h>
#include <android/log.h>
#include "gfx.h"
@@ -767,13 +768,13 @@ void XSDL_generateBackground(const char * port, int showHelp, int resolutionW, i
{
surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 16, 16, 24, 0x0000ff, 0x00ff00, 0xff0000, 0);
SDL_FillRect(surf, NULL, 0x00002f);
SDL_SaveBMP(surf, "background.bmp");
SDL_SavePNG(surf, "background.png");
SDL_FreeSurface(surf);
return;
}
surf = SDL_CreateRGBSurface(SDL_SWSURFACE, resolutionW, resolutionH, 24, 0x0000ff, 0x00ff00, 0xff0000, 0);
SDL_FillRect(surf, NULL, 0x00002f);
SDL_FillRect(surf, NULL, 0x7f0000);
renderStringScaled("Launch these commands on your Linux PC:", 12 * resolutionH / VID_Y, resolutionW/2, y, 255, 255, 255, surf);
y += resolutionH * 30 / VID_Y;
@@ -810,7 +811,7 @@ void XSDL_generateBackground(const char * port, int showHelp, int resolutionW, i
sprintf (msg, "export PULSE_SERVER=tcp:%s:4712", saddr);
renderStringScaled(msg, 12 * resolutionH / VID_Y, resolutionW/2, y, 255, 255, 255, surf);
y += resolutionH * 15 / VID_Y;
sprintf (msg, "gnome-session & gimp");
sprintf (msg, "x-window-manager & gimp");
renderStringScaled(msg, 12 * resolutionH / VID_Y, resolutionW/2, y, 255, 255, 255, surf);
y += resolutionH * 20 / VID_Y;
}
@@ -833,7 +834,7 @@ void XSDL_generateBackground(const char * port, int showHelp, int resolutionW, i
sprintf (msg, "export DISPLAY=:0 PULSE_SERVER=tcp:127.0.0.1:4712");
renderStringScaled(msg, 12 * resolutionH / VID_Y, resolutionW/2, y, 255, 255, 255, surf);
SDL_SaveBMP(surf, "background.bmp");
SDL_SavePNG(surf, "background.png");
SDL_FreeSurface(surf);
}
@@ -928,11 +929,14 @@ void renderString(const char *c, int x, int y)
void renderStringScaled(const char *c, int size, int x, int y, int r, int g, int b, SDL_Surface * surf)
{
char fontpath[PATH_MAX];
if (!c || !c[0])
return;
SDL_Color fColor = {r, g, b};
SDL_Rect fontRect = {0, 0, 0, 0};
TTF_Font* font = TTF_OpenFont("DroidSansMono.ttf", size);
strcpy( fontpath, getenv("UNSECURE_STORAGE_DIR") );
strcat( fontpath, "/DroidSansMono.ttf" );
TTF_Font* font = TTF_OpenFont(fontpath, size);
SDL_Surface* fontSurface = TTF_RenderUTF8_Solid(font, c, fColor);
TTF_CloseFont(font);
fontRect.w = fontSurface->w;

View File

@@ -34,7 +34,11 @@ int main( int argc, char* argv[] )
port,
"-nolock",
"-noreset",
"-pn",
"-nopn",
"-listen",
"inet",
"-listen",
"inet6",
"-nolisten",
"unix",
"-fp",
@@ -42,7 +46,7 @@ int main( int argc, char* argv[] )
"-screen",
screenres,
};
int argnum = 11;
int argnum = 15;
char * envp[] = { NULL };
int printHelp = 1;
int screenResOverride = 0;
@@ -123,14 +127,15 @@ int main( int argc, char* argv[] )
sprintf( screenres, "%d/%dx%d/%dx%d", resolutionW, displayW, resolutionH, displayH, SDL_GetVideoInfo()->vfmt->BitsPerPixel );
}
XSDL_generateBackground( port, printHelp, 800, 600 );
XSDL_generateBackground( port, printHelp, 600 * resolutionW / resolutionH, 600 );
XSDL_deinitSDL();
if( printHelp )
{
sprintf( clientcmd, "%s/usr/bin/xhost + ; %s/usr/bin/xloadimage -onroot -fullscreen %s/background.bmp",
sprintf( clientcmd, "%s/usr/bin/xhost + ; %s/usr/bin/xloadimage -onroot -fullscreen %s/background.png",
getenv("SECURE_STORAGE_DIR"), getenv("SECURE_STORAGE_DIR"), getenv("UNSECURE_STORAGE_DIR") );
args[argnum] = "-exec";
args[argnum+1] = clientcmd;
argnum += 2;