Esempio n. 1
0
int
Android_AddJoystick(int device_id, const char *name, const char *desc, SDL_bool is_accelerometer, int nbuttons, int naxes, int nhats, int nballs)
{
    SDL_JoystickGUID guid;
    SDL_joylist_item *item;
    
    if(JoystickByDeviceId(device_id) != NULL || name == NULL) {
        return -1;
    }
    
    /* the GUID is just the first 16 chars of the name for now */
    SDL_zero( guid );
    SDL_memcpy( &guid, desc, SDL_min( sizeof(guid), SDL_strlen( desc) ) );

    item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
    if (item == NULL) {
        return -1;
    }

    SDL_zerop(item);
    item->guid = guid;
    item->device_id = device_id;
    item->name = SDL_strdup(name);
    if ( item->name == NULL ) {
         SDL_free(item);
         return -1;
    }
    
    item->is_accelerometer = is_accelerometer;
    if (nbuttons > -1) {
        item->nbuttons = nbuttons;
    }
    else {
        item->nbuttons = ANDROID_MAX_NBUTTONS;
    }
    item->naxes = naxes;
    item->nhats = nhats;
    item->nballs = nballs;
    item->device_instance = instance_counter++;
    if (SDL_joylist_tail == NULL) {
        SDL_joylist = SDL_joylist_tail = item;
    } else {
        SDL_joylist_tail->next = item;
        SDL_joylist_tail = item;
    }

    /* Need to increment the joystick count before we post the event */
    ++numjoysticks;

    SDL_PrivateJoystickAdded(numjoysticks - 1);

#ifdef DEBUG_JOYSTICK
    SDL_Log("Added joystick %s with device_id %d", name, device_id);
#endif

    return numjoysticks;
}
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
    SDL_JoystickGUID guid;
    /* the GUID is just the first 16 chars of the name for now */
    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
    SDL_zero( guid );
    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
    return guid;
}
Esempio n. 3
0
/* The CoreAudio callback */
static OSStatus     audioCallback (void                            *inRefCon,
                                   AudioUnitRenderActionFlags      *ioActionFlags,
                                   const AudioTimeStamp            *inTimeStamp,
                                   UInt32                          inBusNumber,
                                   UInt32                          inNumberFrames,
                                   AudioBufferList                 *ioData)
{
    SDL_AudioDevice *this = (SDL_AudioDevice *)inRefCon;
    UInt32 remaining, len;
    AudioBuffer *abuf;
    void *ptr;
    UInt32 i;

    /* Only do anything if audio is enabled and not paused */
    if ( ! this->enabled || this->paused ) {
        for (i = 0; i < ioData->mNumberBuffers; i++) {
            abuf = &ioData->mBuffers[i];
            SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize);
        }
        return 0;
    }
    
    /* No SDL conversion should be needed here, ever, since we accept
       any input format in OpenAudio, and leave the conversion to CoreAudio.
     */
    /*
    assert(!this->convert.needed);
    assert(this->spec.channels == ioData->mNumberChannels);
     */

    for (i = 0; i < ioData->mNumberBuffers; i++) {
        abuf = &ioData->mBuffers[i];
        remaining = abuf->mDataByteSize;
        ptr = abuf->mData;
        while (remaining > 0) {
            if (bufferOffset >= bufferSize) {
                /* Generate the data */
                SDL_memset(buffer, this->spec.silence, bufferSize);
                SDL_mutexP(this->mixer_lock);
                (*this->spec.callback)(this->spec.userdata,
                            buffer, bufferSize);
                SDL_mutexV(this->mixer_lock);
                bufferOffset = 0;
            }
        
            len = bufferSize - bufferOffset;
            if (len > remaining)
                len = remaining;
            SDL_memcpy(ptr, (char *)buffer + bufferOffset, len);
            ptr = (char *)ptr + len;
            remaining -= len;
            bufferOffset += len;
        }
    }

    return 0;
}
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
    SDL_JoystickGUID guid;
    /* the GUID is just the first 16 chars of the name for now */
    const char *name = joystick->name;
    SDL_zero( guid );
    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
    return guid;
}
Esempio n. 5
0
void Mac_SetCaption(_THIS, const char *title, const char *icon)
{
	
	Str255		ptitle; 
	ptitle[0] = strlen (title);
	SDL_memcpy(ptitle+1, title, ptitle[0]); 
	if (SDL_Window)
		SetWTitle(SDL_Window, ptitle); 
}
Esempio n. 6
0
static int SDLCALL mem_write(SDL_RWops *context, const void *ptr, int size, int num)
{
	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
	}
	SDL_memcpy(context->hidden.mem.here, ptr, num*size);
	context->hidden.mem.here += num*size;
	return(num);
}
Esempio n. 7
0
static int
GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
                   const SDL_Rect * rect, const void *pixels, int pitch)
{
    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
    Uint8 *blob = NULL;
    Uint8 *src;
    int srcPitch;
    int y;

    GLES_ActivateRenderer(renderer);

    /* Bail out if we're supposed to update an empty rectangle */
    if (rect->w <= 0 || rect->h <= 0) {
        return 0;
    }

    /* Reformat the texture data into a tightly packed array */
    srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format);
    src = (Uint8 *)pixels;
    if (pitch != srcPitch) {
        blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
        if (!blob) {
            return SDL_OutOfMemory();
        }
        src = blob;
        for (y = 0; y < rect->h; ++y) {
            SDL_memcpy(src, pixels, srcPitch);
            src += srcPitch;
            pixels = (Uint8 *)pixels + pitch;
        }
        src = blob;
    }

    /* Create a texture subimage with the supplied data */
    renderdata->glGetError();
    renderdata->glEnable(data->type);
    renderdata->glBindTexture(data->type, data->texture);
    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    renderdata->glTexSubImage2D(data->type,
                    0,
                    rect->x,
                    rect->y,
                    rect->w,
                    rect->h,
                    data->format,
                    data->formattype,
                    src);
    renderdata->glDisable(data->type);
    SDL_free(blob);

    if (renderdata->glGetError() != GL_NO_ERROR) {
        return SDL_SetError("Failed to update texture");
    }
    return 0;
}
Esempio n. 8
0
void Mac_SetCaption(_THIS, const char *title, const char *icon)
{
	/* Don't convert C to P string in place, because it may be read-only */
	Str255		ptitle; /* MJS */
	ptitle[0] = strlen (title);
	SDL_memcpy(ptitle+1, title, ptitle[0]); /* MJS */
	if (SDL_Window)
		SetWTitle(SDL_Window, ptitle); /* MJS */
}
Esempio n. 9
0
/*
 * Copy a block of pixels of one format to another format
 */
int SDL_ConvertPixels(int width, int height,
                      Uint32 src_format, const void * src, int src_pitch,
                      Uint32 dst_format, void * dst, int dst_pitch)
{
    SDL_Surface src_surface, dst_surface;
    SDL_PixelFormat src_fmt, dst_fmt;
    SDL_BlitMap src_blitmap, dst_blitmap;
    SDL_Rect rect;
    void *nonconst_src = (void *) src;

    /* Check to make sure we are blitting somewhere, so we don't crash */
    if (!dst) {
        return SDL_InvalidParamError("dst");
    }
    if (!dst_pitch) {
        return SDL_InvalidParamError("dst_pitch");
    }

    if (SDL_ISPIXELFORMAT_FOURCC(src_format) && SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
        return SDL_ConvertPixels_YUV_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
    } else if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
        return SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
    } else if (SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
        return SDL_ConvertPixels_RGB_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
    }

    /* Fast path for same format copy */
    if (src_format == dst_format) {
        int i;
        const int bpp = SDL_BYTESPERPIXEL(src_format);
        width *= bpp;
        for (i = height; i--;) {
            SDL_memcpy(dst, src, width);
            src = (const Uint8*)src + src_pitch;
            dst = (Uint8*)dst + dst_pitch;
        }
        return 0;
    }

    if (!SDL_CreateSurfaceOnStack(width, height, src_format, nonconst_src,
                                  src_pitch,
                                  &src_surface, &src_fmt, &src_blitmap)) {
        return -1;
    }
    if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
                                  &dst_surface, &dst_fmt, &dst_blitmap)) {
        return -1;
    }

    /* Set up the rect and go! */
    rect.x = 0;
    rect.y = 0;
    rect.w = width;
    rect.h = height;
    return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
}
int
SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue)
{
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    int succeeded;

    if (!_this) {
        SDL_UninitializedVideo();
        return -1;
    }

    /* Lazily allocate the gamma tables */
    if (!display->gamma) {
        if (SDL_GetGammaRampForDisplay(display, NULL, NULL, NULL) < 0) {
            return -1;
        }
    }

    /* Fill the gamma table with the new values */
    if (red) {
        SDL_memcpy(&display->gamma[0 * 256], red, 256 * sizeof(*display->gamma));
    }
    if (green) {
        SDL_memcpy(&display->gamma[1 * 256], green, 256 * sizeof(*display->gamma));
    }
    if (blue) {
        SDL_memcpy(&display->gamma[2 * 256], blue, 256 * sizeof(*display->gamma));
    }

    /* Try to set the gamma ramp in the driver */
    succeeded = -1;
    if (_this && _this->SetDisplayGammaRamp) {
        if (SDL_GetFocusWindow()) {
            succeeded =
                _this->SetDisplayGammaRamp(_this, display, display->gamma);
        } else {
            succeeded = 0;
        }
    } else {
        SDL_SetError("Gamma ramp manipulation not supported");
    }
    return succeeded;
}
Esempio n. 11
0
int PL_Handle_SwapHandleIDs(int handleAID, int handleBID) {
    HandleData *handleA, *handleB;
    HandleData tempHandle;
    
    if (handleAID < 0 || handleAID >= s_handleCount
        || handleBID < 0 || handleBID >= s_handleCount
    ) {
        return -1;
    }
    
    handleA = &s_handleTable[handleAID];
    handleB = &s_handleTable[handleBID];
    
    SDL_memcpy(&tempHandle, handleA, sizeof(HandleData));
    SDL_memcpy(handleA, handleB, sizeof(HandleData));
    SDL_memcpy(handleB, &tempHandle, sizeof(HandleData));
    
    return 0;
}
Esempio n. 12
0
size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen)
{
    size_t srclen = SDL_strlen(src);
    if ( maxlen > 0 ) {
        size_t len = SDL_min(srclen, maxlen-1);
        SDL_memcpy(dst, src, len);
        dst[len] = '\0';
    }
    return srclen;
}
Esempio n. 13
0
static void UMS_PlayAudio(_THIS)
{
    UMSAudioDevice_ReturnCode rc;
    long                      samplesToWrite;
    long                      samplesWritten;
    UMSAudioTypes_Buffer      swpbuf;

#ifdef DEBUG_AUDIO
    fprintf(stderr, "enter UMS_PlayAudio\n");
#endif
    samplesToWrite = this->hidden->playbuf._length/this->hidden->bytesPerSample;
    do
    {
        rc = UADWrite(this,  &this->hidden->playbuf,
		       samplesToWrite,
	               &samplesWritten );
	samplesToWrite -= samplesWritten;

	/* rc values: UMSAudioDevice_Success
	 *            UMSAudioDevice_Failure
	 *            UMSAudioDevice_Preempted
	 *            UMSAudioDevice_Interrupted
	 *            UMSAudioDevice_DeviceError
	 */
	if ( rc == UMSAudioDevice_DeviceError ) {
#ifdef DEBUG_AUDIO
	    fprintf(stderr, "Returning from PlayAudio with devices error\n");
#endif
	    return;
	}
    }
    while(samplesToWrite>0);

    SDL_LockAudio();
    SDL_memcpy( &swpbuf,                &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer) );
    SDL_memcpy( &this->hidden->playbuf, &this->hidden->fillbuf, sizeof(UMSAudioTypes_Buffer) );
    SDL_memcpy( &this->hidden->fillbuf, &swpbuf,                sizeof(UMSAudioTypes_Buffer) );
    SDL_UnlockAudio();

#ifdef DEBUG_AUDIO
    fprintf(stderr, "Wrote audio data and swapped buffer\n");
#endif
}
Esempio n. 14
0
static SDL_Cursor *
WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
{
    SDL_Cursor *cursor;
    HICON hicon;
    HDC hdc;
    BITMAPV4HEADER bmh;
    LPVOID pixels;
    ICONINFO ii;

    SDL_zero(bmh);
    bmh.bV4Size = sizeof(bmh);
    bmh.bV4Width = surface->w;
    bmh.bV4Height = -surface->h; /* Invert the image */
    bmh.bV4Planes = 1;
    bmh.bV4BitCount = 32;
    bmh.bV4V4Compression = BI_BITFIELDS;
    bmh.bV4AlphaMask = 0xFF000000;
    bmh.bV4RedMask   = 0x00FF0000;
    bmh.bV4GreenMask = 0x0000FF00;
    bmh.bV4BlueMask  = 0x000000FF;

    hdc = GetDC(NULL);
    SDL_zero(ii);
    ii.fIcon = FALSE;
    ii.xHotspot = (DWORD)hot_x;
    ii.yHotspot = (DWORD)hot_y;
    ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0);
    ii.hbmMask = CreateBitmap(surface->w, surface->h, 1, 1, NULL);
    ReleaseDC(NULL, hdc);

    SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
    SDL_assert(surface->pitch == surface->w * 4);
    SDL_memcpy(pixels, surface->pixels, surface->h * surface->pitch);

    hicon = CreateIconIndirect(&ii);

    DeleteObject(ii.hbmColor);
    DeleteObject(ii.hbmMask);

    if (!hicon) {
        WIN_SetError("CreateIconIndirect()");
        return NULL;
    }

    cursor = SDL_calloc(1, sizeof(*cursor));
    if (cursor) {
        cursor->driverdata = hicon;
    } else {
        DestroyIcon(hicon);
        SDL_OutOfMemory();
    }

    return cursor;
}
Esempio n. 15
0
/*
 * Copy a block of pixels of one format to another format
 */
int SDL_ConvertPixels(int width, int height,
                      Uint32 src_format, const void * src, int src_pitch,
                      Uint32 dst_format, void * dst, int dst_pitch)
{
    SDL_Surface src_surface, dst_surface;
    SDL_PixelFormat src_fmt, dst_fmt;
    SDL_BlitMap src_blitmap, dst_blitmap;
    SDL_Rect rect;

    /* Fast path for same format copy */
    if (src_format == dst_format) {
        int bpp;

        if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
            switch (src_format) {
            case SDL_PIXELFORMAT_YV12:
            case SDL_PIXELFORMAT_IYUV:
            case SDL_PIXELFORMAT_YUY2:
            case SDL_PIXELFORMAT_UYVY:
            case SDL_PIXELFORMAT_YVYU:
                bpp = 2;
            default:
                SDL_SetError("Unknown FOURCC pixel format");
                return -1;
            }
        } else {
            bpp = SDL_BYTESPERPIXEL(src_format);
        }
        width *= bpp;

        while (height-- > 0) {
            SDL_memcpy(dst, src, width);
            src = (Uint8*)src + src_pitch;
            dst = (Uint8*)dst + dst_pitch;
        }
        return 0;
    }

    if (!SDL_CreateSurfaceOnStack(width, height, src_format, (void*)src,
                                  src_pitch,
                                  &src_surface, &src_fmt, &src_blitmap)) {
        return -1;
    }
    if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
                                  &dst_surface, &dst_fmt, &dst_blitmap)) {
        return -1;
    }

    /* Set up the rect and go! */
    rect.x = 0;
    rect.y = 0;
    rect.w = width;
    rect.h = height;
    return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
}
Esempio n. 16
0
void SDL_MoSync_AudioBufferFill() {
	int startTime;
	if ( sDevice->convert.needed ) {
		(*sDevice->spec.callback)(sDevice->spec.userdata, (Uint8 *)sDevice->convert.buf,sDevice->convert.len);
		SDL_ConvertAudio(&sDevice->convert);
		SDL_memcpy(sDevice->hidden->info.buffer,sDevice->convert.buf,sDevice->convert.len_cvt);
	} else {
		(*sDevice->spec.callback)(sDevice->spec.userdata, (Uint8 *)sDevice->hidden->info.buffer, sDevice->hidden->info.bufferSize);
	}
	maAudioBufferReady();
}
Esempio n. 17
0
void AtlasLayer_ctor_Ex(AtlasLayer* ptr, int atlasColumnCount, AtlasColumn** atlasColumns)
{
    SDL_assert(ptr);

    DestructibleObject_ctor(&ptr->destructible, &AtlasLayer_destructionSteps);

    ptr->atlasColumnCount = atlasColumnCount;
    ptr->atlasColumns = SDL_calloc(atlasColumnCount, sizeof(AtlasColumn*));

    SDL_memcpy(ptr->atlasColumns, atlasColumns, sizeof(Board*) * atlasColumnCount);
}
Esempio n. 18
0
static SDL_bool AddDialogData(WIN_DialogData *dialog, const void *data, size_t size)
{
    if (!ExpandDialogSpace(dialog, size)) {
        return SDL_FALSE;
    }

    SDL_memcpy(dialog->data+dialog->used, data, size);
    dialog->used += size;

    return SDL_TRUE;
}
Esempio n. 19
0
size_t
SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
{
    size_t srclen = SDL_wcslen(src);
    if (maxlen > 0) {
        size_t len = SDL_min(srclen, maxlen - 1);
        SDL_memcpy(dst, src, len * sizeof(wchar_t));
        dst[len] = '\0';
    }
    return srclen;
}
Esempio n. 20
0
static BOOL CALLBACK
EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
{
    SDL_memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
               sizeof(DIDEVICEINSTANCE));
    SYS_NumJoysticks++;

    if (SYS_NumJoysticks >= MAX_JOYSTICKS)
        return DIENUM_STOP;

    return DIENUM_CONTINUE;
}
Esempio n. 21
0
int
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
{
    HRESULT ret;
    DWORD flags;
    DIEFFECT temp;

    /* Get the effect. */
    SDL_memset(&temp, 0, sizeof(DIEFFECT));
    if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) {
        goto err_update;
    }

    /* Set the flags.  Might be worthwhile to diff temp with loaded effect and
    *  only change those parameters. */
    flags = DIEP_DIRECTION |
        DIEP_DURATION |
        DIEP_ENVELOPE |
        DIEP_STARTDELAY |
        DIEP_TRIGGERBUTTON |
        DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;

    /* Create the actual effect. */
    ret =
        IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
    if (ret == DIERR_NOTEXCLUSIVEACQUIRED) {
        IDirectInputDevice8_Unacquire(haptic->hwdata->device);
        ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device, SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND);
        if (SUCCEEDED(ret)) {
            ret = DIERR_NOTACQUIRED;
        }
    }
    if (ret == DIERR_INPUTLOST || ret == DIERR_NOTACQUIRED) {
        ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
        if (SUCCEEDED(ret)) {
            ret = IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
        }
    }
    if (FAILED(ret)) {
        DI_SetError("Unable to update effect", ret);
        goto err_update;
    }

    /* Copy it over. */
    SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, data->type);
    SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(DIEFFECT));

    return 0;

err_update:
    SDL_SYS_HapticFreeDIEFFECT(&temp, data->type);
    return -1;
}
Esempio n. 22
0
void SDLCALL fillerup(void *unused, Uint8 *stream, int len)
{
	Uint8 *waveptr;
	int    waveleft;

	/* Set up the pointers */
	waveptr = wave.sound + wave.soundpos;
	waveleft = wave.soundlen - wave.soundpos;

	/* Go! */
	while ( waveleft <= len ) {
		SDL_memcpy(stream, waveptr, waveleft);
		stream += waveleft;
		len -= waveleft;
		waveptr = wave.sound;
		waveleft = wave.soundlen;
		wave.soundpos = 0;
	}
	SDL_memcpy(stream, waveptr, len);
	wave.soundpos += len;
}
Esempio n. 23
0
void my_audio_callback(void *userdata, Uint8 *stream, int len) {
	
	if (audio_len ==0)
		return;
	
	len = ( len > audio_len ? audio_len : len );
	SDL_memcpy (stream, audio_pos, len); 					// simply copy from one buffer into the other
	//SDL_MixAudio(stream, audio_pos, len, 32);// mix from one buffer into another
	
	audio_pos += len;
	audio_len -= len;
}
Esempio n. 24
0
SDL_Surface *Surface::createSurfaceWithFormatFrom(void *pixels,
        int width, int height, int depth, int pitch, uint32_t format)
{
#if SDL_VERSION_ATLEAST(2, 0, 5)
    return SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height,
            depth, pitch, format);
#else
    SDL_Surface *surface = Surface::createSurfaceWithFormat(width, height, depth, format);
    SDL_memcpy(surface->pixels, pixels, height * pitch);
    return surface;
#endif
}
Esempio n. 25
0
int
SDL_AddTouch(const SDL_Touch * touch, char *name)
{
    SDL_Touch **touchPads;
    int index;
    size_t length;

    if (SDL_GetTouchIndexId(touch->id) != -1) {
        SDL_SetError("Touch ID already in use");
    }

    /* Add the touch to the list of touch */
    touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads,
                                      (SDL_num_touch + 1) * sizeof(*touch));
    if (!touchPads) {
        SDL_OutOfMemory();
        return -1;
    }

    SDL_touchPads = touchPads;
    index = SDL_num_touch++;

    SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index]));
    if (!SDL_touchPads[index]) {
        SDL_OutOfMemory();
        return -1;
    }
    SDL_memcpy(SDL_touchPads[index], touch, sizeof(*touch));

    /* we're setting the touch properties */
    length = 0;
    length = SDL_strlen(name);
    SDL_touchPads[index]->focus = 0;
    SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char));
    SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);   

    SDL_touchPads[index]->num_fingers = 0;
    SDL_touchPads[index]->max_fingers = 1;
    SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*));
    SDL_touchPads[index]->fingers[0] = NULL;
    SDL_touchPads[index]->buttonstate = 0;
    SDL_touchPads[index]->relative_mode = SDL_FALSE;
    SDL_touchPads[index]->flush_motion = SDL_FALSE;
    
    SDL_touchPads[index]->xres = (1<<(16-1));
    SDL_touchPads[index]->yres = (1<<(16-1));
    SDL_touchPads[index]->pressureres = (1<<(16-1));
    //Do I want this here? Probably
    SDL_GestureAddTouch(SDL_touchPads[index]);

    return index;
}
Esempio n. 26
0
static void LRSetPalette_logical(SDL_Surface *screen, SDL_Color *colors,
			       int firstcolor, int ncolors)
{
	SDL_Palette *pal = screen->format->palette;
	SDL_Palette *vidpal;

	if ( colors != (pal->colors + firstcolor) ) {
		SDL_memcpy(pal->colors + firstcolor, colors,
		       ncolors * sizeof(*colors));
	}

	LRSDL_FormatChanged(screen);
}
Esempio n. 27
0
int SDL_GetGammaRamp(Uint16 *red, Uint16 *green, Uint16 *blue)
{
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;	

	/* Lazily allocate the gamma table */
	if ( ! video->gamma ) {
		video->gamma = SDL_malloc(3*256*sizeof(*video->gamma));
		if ( ! video->gamma ) {
			SDL_OutOfMemory();
			return -1;
		}
		if ( video->GetGammaRamp ) {
			/* Get the real hardware gamma */
			video->GetGammaRamp(this, video->gamma);
		} else {
			/* Assume an identity gamma */
			int i;
			for ( i=0; i<256; ++i ) {
				video->gamma[0*256+i] = (i << 8) | i;
				video->gamma[1*256+i] = (i << 8) | i;
				video->gamma[2*256+i] = (i << 8) | i;
			}
		}
	}

	/* Just copy from our internal table */
	if ( red ) {
		SDL_memcpy(red, &video->gamma[0*256], 256*sizeof(*red));
	}
	if ( green ) {
		SDL_memcpy(green, &video->gamma[1*256], 256*sizeof(*green));
	}
	if ( blue ) {
		SDL_memcpy(blue, &video->gamma[2*256], 256*sizeof(*blue));
	}
	return 0;
}
Esempio n. 28
0
//string mythVirtualServer::GetLocalAddress(){
//	unsigned char iphost[4] = { 0 };
//	IPaddress serverip;
//	SDLNet_GetLocalAddress(&serverip);
//	SDL_memcpy(iphost, &serverip.host, 4);
//	char tmpstr[100] = { 0 };
//	sprintf(tmpstr, "%d.%d.%d.%d", iphost[0], iphost[1], iphost[2], iphost[3]);
//	return tmpstr;
//}
int mythVirtualServer::initalsocket(int port){
	
    IPaddress serverIP;
	int i;
	unsigned char iphost[4] = {0};

        /* Initialize SDL */
    if ( SDL_Init(0) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
        exit(1);
    }

    /* Initialize the network */
    if ( SDLNet_Init() < 0 ) {
        fprintf(stderr, "Couldn't initialize net: %s\n",
                        SDLNet_GetError());
        SDL_Quit();
        exit(1);
    }
#pragma omp parallel for
    /* Initialize the channels */
    for ( i=0; i<CHAT_MAXPEOPLE; ++i ) {
		people[i] = PEOPLE::CreateNew();
		people[i]->addtionaldata = NULL;
		people[i]->active = 0;
		people[i]->sock = NULL;
    }

    /* Allocate the socket set */
    socketset = SDLNet_AllocSocketSet(CHAT_MAXPEOPLE+1);
    if ( socketset == NULL ) {
        fprintf(stderr, "Couldn't create socket set: %s\n",
                        SDLNet_GetError());
        cleanup(2);
    }

    /* Create the server socket */
	SDLNet_ResolveHost(&serverIP, NULL, port);
	//iphost[0] = &serverIP.host;
	SDL_memcpy(iphost, &serverIP.host, 4);
	printf("Server IP: %d.%d.%d.%d ---  %d\n", iphost[0], iphost[1], iphost[2], iphost[3], port);
    servsock = SDLNet_TCP_Open(&serverIP);
    if ( servsock == NULL ) {
        fprintf(stderr, "Couldn't create server socket: %s\n",
                        SDLNet_GetError());
        cleanup(2);
    }
    SDLNet_TCP_AddSocket(socketset, servsock);
	return 0;
}
Esempio n. 29
0
/*
 * Close a joystick previously opened with SDL_JoystickOpen()
 */
void
SDL_JoystickClose(SDL_Joystick * joystick)
{
    int i;

    if (!SDL_PrivateJoystickValid(&joystick)) {
        return;
    }

    /* First decrement ref count */
    if (--joystick->ref_count > 0) {
        return;
    }

    /* Lock the event queue - prevent joystick polling */
    SDL_Lock_EventThread();

    if (joystick == default_joystick) {
        default_joystick = NULL;
    }
    SDL_SYS_JoystickClose(joystick);

    /* Remove joystick from list */
    for (i = 0; SDL_joysticks[i]; ++i) {
        if (joystick == SDL_joysticks[i]) {
            SDL_memcpy(&SDL_joysticks[i], &SDL_joysticks[i + 1],
                       (SDL_numjoysticks - i) * sizeof(joystick));
            break;
        }
    }

    /* Let the event thread keep running */
    SDL_Unlock_EventThread();

    /* Free the data associated with this joystick */
    if (joystick->axes) {
        SDL_free(joystick->axes);
    }
    if (joystick->hats) {
        SDL_free(joystick->hats);
    }
    if (joystick->balls) {
        SDL_free(joystick->balls);
    }
    if (joystick->buttons) {
        SDL_free(joystick->buttons);
    }
    SDL_free(joystick);
}
Esempio n. 30
0
/*	eloGetPacket
*/
int
eloGetPacket(unsigned char *buffer, int *buffer_p, int *checksum, int fd)
{
    int num_bytes;
    int ok;

    if (fd == 0) {
        num_bytes = ELO_PACKET_SIZE;
    } else {
        num_bytes = read(fd,
                         (char *) (buffer + *buffer_p),
                         ELO_PACKET_SIZE - *buffer_p);
    }

    if (num_bytes < 0) {
#ifdef DEBUG_MOUSE
        fprintf(stderr,
                "System error while reading from Elographics touchscreen.\n");
#endif
        return 0;
    }

    while (num_bytes) {
        if ((*buffer_p == 0) && (buffer[0] != ELO_START_BYTE)) {
            SDL_memcpy(&buffer[0], &buffer[1], num_bytes - 1);
        } else {
            if (*buffer_p < ELO_PACKET_SIZE - 1) {
                *checksum = *checksum + buffer[*buffer_p];
                *checksum = *checksum % 256;
            }
            (*buffer_p)++;
        }
        num_bytes--;
    }

    if (*buffer_p == ELO_PACKET_SIZE) {
        ok = (*checksum == buffer[ELO_PACKET_SIZE - 1]);
        *checksum = ELO_INIT_CHECKSUM;
        *buffer_p = 0;

        if (!ok) {
            return 0;
        }

        return 1;
    } else {
        return 0;
    }
}