mirror of
https://github.com/love2d/love-android.git
synced 2026-08-20 12:40:28 +02:00
Updated SDL2 to changeset 69a5f3a540af (dev version of 2.0.4)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -15,12 +15,12 @@
|
||||
* l to load all touches from "./gestureSave"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_touch.h"
|
||||
#include "SDL_gesture.h"
|
||||
#include <stdlib.h> /* for exit() */
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#define WIDTH 640
|
||||
#define HEIGHT 480
|
||||
@@ -33,13 +33,16 @@
|
||||
|
||||
#define VERBOSE 0
|
||||
|
||||
static SDL_Window *window;
|
||||
static SDL_Event events[EVENT_BUF_SIZE];
|
||||
static int eventWrite;
|
||||
|
||||
|
||||
static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
|
||||
|
||||
SDL_Surface *screen;
|
||||
SDL_Window *window;
|
||||
SDL_bool quitting = SDL_FALSE;
|
||||
|
||||
typedef struct {
|
||||
float x,y;
|
||||
} Point;
|
||||
@@ -51,18 +54,6 @@ typedef struct {
|
||||
|
||||
static Knob knob;
|
||||
|
||||
void handler (int sig)
|
||||
{
|
||||
SDL_Log ("exiting...(%d)", sig);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
void perror_exit (char *error)
|
||||
{
|
||||
perror (error);
|
||||
handler (9);
|
||||
}
|
||||
|
||||
void setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
|
||||
{
|
||||
Uint32 *pixmem32;
|
||||
@@ -104,7 +95,7 @@ void drawCircle(SDL_Surface* screen,float x,float y,float r,unsigned int c)
|
||||
float tx,ty;
|
||||
float xr;
|
||||
for(ty = (float)-SDL_fabs(r);ty <= (float)SDL_fabs((int)r);ty++) {
|
||||
xr = (float)sqrt(r*r - ty*ty);
|
||||
xr = (float)SDL_sqrt(r*r - ty*ty);
|
||||
if(r > 0) { /* r > 0 ==> filled circle */
|
||||
for(tx=-xr+.5f;tx<=xr-.5;tx++) {
|
||||
setpix(screen,x+tx,y+ty,c);
|
||||
@@ -123,7 +114,7 @@ void drawKnob(SDL_Surface* screen,Knob k) {
|
||||
(k.p.y+k.r/2*SDL_sinf(k.ang))*screen->h,k.r/4*screen->w,0);
|
||||
}
|
||||
|
||||
void DrawScreen(SDL_Surface* screen)
|
||||
void DrawScreen(SDL_Surface* screen, SDL_Window* window)
|
||||
{
|
||||
int i;
|
||||
#if 1
|
||||
@@ -165,44 +156,24 @@ void DrawScreen(SDL_Surface* screen)
|
||||
SDL_UpdateWindowSurface(window);
|
||||
}
|
||||
|
||||
SDL_Surface* initScreen(int width,int height)
|
||||
/* Returns a new SDL_Window if window is NULL or window if not. */
|
||||
SDL_Window* initWindow(SDL_Window *window, int width,int height)
|
||||
{
|
||||
if (!window) {
|
||||
window = SDL_CreateWindow("Gesture Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
width, height, SDL_WINDOW_RESIZABLE);
|
||||
}
|
||||
if (!window) {
|
||||
return NULL;
|
||||
}
|
||||
return SDL_GetWindowSurface(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
void loop()
|
||||
{
|
||||
SDL_Surface *screen;
|
||||
SDL_Event event;
|
||||
SDL_bool quitting = SDL_FALSE;
|
||||
SDL_RWops *stream;
|
||||
SDL_Event event;
|
||||
SDL_RWops *stream;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* gesture variables */
|
||||
knob.r = .1f;
|
||||
knob.ang = 0;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
|
||||
|
||||
if (!(screen = initScreen(WIDTH,HEIGHT)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
while(!quitting) {
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
{
|
||||
/* Record _all_ events */
|
||||
events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
|
||||
eventWrite++;
|
||||
@@ -215,6 +186,15 @@ int main(int argc, char* argv[])
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_i:
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < SDL_GetNumTouchDevices(); ++i) {
|
||||
SDL_TouchID id = SDL_GetTouchDevice(i);
|
||||
SDL_Log("Fingers Down on device %"SDL_PRIs64": %d", id, SDL_GetNumTouchFingers(id));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDLK_SPACE:
|
||||
SDL_RecordGesture(-1);
|
||||
break;
|
||||
@@ -235,10 +215,11 @@ int main(int argc, char* argv[])
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
if (!(screen = initScreen(event.window.data1, event.window.data2)))
|
||||
if (!(window = initWindow(window, event.window.data1, event.window.data2)) ||
|
||||
!(screen = SDL_GetWindowSurface(window)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -283,9 +264,46 @@ int main(int argc, char* argv[])
|
||||
SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
DrawScreen(screen);
|
||||
}
|
||||
DrawScreen(screen, window);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (quitting) {
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
window = NULL;
|
||||
screen = NULL;
|
||||
quitting = SDL_FALSE;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* gesture variables */
|
||||
knob.r = .1f;
|
||||
knob.ang = 0;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
|
||||
|
||||
if (!(window = initWindow(window, WIDTH, HEIGHT)) ||
|
||||
!(screen = SDL_GetWindowSurface(window)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while(!quitting) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user