int SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float xin, float yin, float pressurein) { int posted; Uint16 x; Uint16 y; Uint16 pressure; SDL_Finger *finger; SDL_Touch* touch = SDL_GetTouch(id); if(!touch) { return SDL_TouchNotFoundError(id); } //scale to Integer coordinates x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres)); y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres)); pressure = (Uint16)((yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres)); finger = SDL_GetFinger(touch,fingerid); if(down) { if(finger == NULL) { SDL_Finger nf; nf.id = fingerid; nf.x = x; nf.y = y; nf.pressure = pressure; nf.xdelta = 0; nf.ydelta = 0; nf.last_x = x; nf.last_y = y; nf.last_pressure = pressure; nf.down = SDL_FALSE; if(SDL_AddFinger(touch,&nf) < 0) return 0; finger = SDL_GetFinger(touch,fingerid); } else if(finger->down) return 0; if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input posted = 0; if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { SDL_Event event; event.tfinger.type = SDL_FINGERDOWN; event.tfinger.touchId = id; event.tfinger.x = x; event.tfinger.y = y; event.tfinger.pressure = pressure; event.tfinger.state = touch->buttonstate; event.tfinger.windowID = touch->focus ? touch->focus->id : 0; event.tfinger.fingerId = fingerid; posted = (SDL_PushEvent(&event) > 0); } if(posted) finger->down = SDL_TRUE; return posted; } else { if(finger == NULL) { SDL_SetError("Finger not found."); return 0; } posted = 0; if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { SDL_Event event; event.tfinger.type = SDL_FINGERUP; event.tfinger.touchId = id; event.tfinger.state = touch->buttonstate; event.tfinger.windowID = touch->focus ? touch->focus->id : 0; event.tfinger.fingerId = fingerid; //I don't trust the coordinates passed on fingerUp event.tfinger.x = finger->x; event.tfinger.y = finger->y; event.tfinger.dx = 0; event.tfinger.dy = 0; if(SDL_DelFinger(touch,fingerid) < 0) return 0; posted = (SDL_PushEvent(&event) > 0); } return posted; } }
static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) { CDCntrlParam cdpb; if ( SDL_SYS_CDPause(cdrom) < 0 ) { return(-1); } SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kSetPlayMode; cdpb.csParam.bytes[0] = false; cdpb.csParam.bytes[1] = kPlayModeSequential; PBControlSync((ParmBlkPtr) &cdpb); #if 1 SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kAudioStop; cdpb.csParam.words[0] = kBlockPosition; *(long *) (cdpb.csParam.words + 1) = start+length-1; if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { SDL_SetError("PBControlSync() failed"); return(-1); } SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kAudioPlay; cdpb.csParam.words[0] = kBlockPosition; *(long *) (cdpb.csParam.words + 1) = start+1; cdpb.csParam.words[3] = false; cdpb.csParam.words[4] = kStereoPlayMode; if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { SDL_SetError("PBControlSync() failed"); return(-1); } #else FRAMES_TO_MSF(start+length, &m, &s, &f); SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kAudioStop; cdpb.csParam.words[0] = kTrackPosition; cdpb.csParam.words[1] = 0; cdpb.csParam.words[2] = SDL_SYS_ShortToBCD(cdrom->numtracks); if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { SDL_SetError("PBControlSync() failed"); return(-1); } FRAMES_TO_MSF(start, &m, &s, &f); SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kAudioPlay; cdpb.csParam.words[0] = kTrackPosition; cdpb.csParam.words[1] = 0; cdpb.csParam.words[2] = SDL_SYS_ShortToBCD(1); cdpb.csParam.words[3] = false; cdpb.csParam.words[4] = kStereoPlayMode; if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { SDL_SetError("PBControlSync() failed"); return(-1); } #endif return(0); }
/* * Open a joystick for use - the index passed as an argument refers to * the N'th joystick on the system. This index is the value which will * identify this joystick in future joystick events. * * This function returns a joystick identifier, or NULL if an error occurred. */ SDL_Joystick * SDL_JoystickOpen(int device_index) { int i; SDL_Joystick *joystick; if ((device_index < 0) || (device_index >= SDL_numjoysticks)) { SDL_SetError("There are %d joysticks available", SDL_numjoysticks); return (NULL); } /* If the joystick is already open, return it */ for (i = 0; SDL_joysticks[i]; ++i) { if (device_index == SDL_joysticks[i]->index) { joystick = SDL_joysticks[i]; ++joystick->ref_count; return (joystick); } } /* Create and initialize the joystick */ joystick = (SDL_Joystick *) SDL_malloc((sizeof *joystick)); if (joystick != NULL) { SDL_memset(joystick, 0, (sizeof *joystick)); joystick->index = device_index; if (SDL_SYS_JoystickOpen(joystick) < 0) { SDL_free(joystick); joystick = NULL; } else { if (joystick->naxes > 0) { joystick->axes = (Sint16 *) SDL_malloc (joystick->naxes * sizeof(Sint16)); } if (joystick->nhats > 0) { joystick->hats = (Uint8 *) SDL_malloc (joystick->nhats * sizeof(Uint8)); } if (joystick->nballs > 0) { joystick->balls = (struct balldelta *) SDL_malloc (joystick->nballs * sizeof(*joystick->balls)); } if (joystick->nbuttons > 0) { joystick->buttons = (Uint8 *) SDL_malloc (joystick->nbuttons * sizeof(Uint8)); } if (((joystick->naxes > 0) && !joystick->axes) || ((joystick->nhats > 0) && !joystick->hats) || ((joystick->nballs > 0) && !joystick->balls) || ((joystick->nbuttons > 0) && !joystick->buttons)) { SDL_OutOfMemory(); SDL_JoystickClose(joystick); joystick = NULL; } if (joystick->axes) { SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16)); } if (joystick->hats) { SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8)); } if (joystick->balls) { SDL_memset(joystick->balls, 0, joystick->nballs * sizeof(*joystick->balls)); } if (joystick->buttons) { SDL_memset(joystick->buttons, 0, joystick->nbuttons * sizeof(Uint8)); } } } if (joystick) { /* Add joystick to list */ ++joystick->ref_count; SDL_Lock_EventThread(); for (i = 0; SDL_joysticks[i]; ++i) /* Skip to next joystick */ ; SDL_joysticks[i] = joystick; SDL_Unlock_EventThread(); } return (joystick); }
static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) { CDCntrlParam cdpb; CDstatus status = CD_ERROR; Boolean spinning = false; if (position) *position = 0; if ( ! get_drivenum(cdrom->id) ) { return(CD_TRAYEMPTY); } SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kReadTOC; cdpb.csParam.words[0] = kGetTrackRange; if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { SDL_SetError("PBControlSync() failed"); return(CD_ERROR); } cdrom->numtracks = SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) - SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1; if ( cdrom->numtracks > SDL_MAX_TRACKS ) cdrom->numtracks = SDL_MAX_TRACKS; cdrom->cur_track = 0; cdrom->cur_frame = 0; if (1 || SDL_cdlist[cdrom->id].hasAudio) { SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kAudioStatus; if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { SDL_SetError("PBControlSync() failed"); return(-1); } switch(cdpb.csParam.cd.status) { case kStatusPlaying: status = CD_PLAYING; spinning = true; break; case kStatusPaused: status = CD_PAUSED; spinning = true; break; case kStatusMuted: status = CD_PLAYING; spinning = true; break; case kStatusDone: status = CD_STOPPED; spinning = true; break; case kStatusStopped: status = CD_STOPPED; spinning = false; break; case kStatusError: default: status = CD_ERROR; spinning = false; break; } if (spinning && position) *position = MSF_TO_FRAMES( SDL_SYS_BCDToShort(cdpb.csParam.cd.minute), SDL_SYS_BCDToShort(cdpb.csParam.cd.second), SDL_SYS_BCDToShort(cdpb.csParam.cd.frame)); } else status = CD_ERROR; return(status); }
static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) { CDCntrlParam cdpb; CDTrackData tracks[SDL_MAX_TRACKS]; long i, leadout; SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kReadTOC; cdpb.csParam.words[0] = kGetTrackRange; if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { SDL_SetError("PBControlSync() failed"); return(-1); } cdrom->numtracks = SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) - SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1; if ( cdrom->numtracks > SDL_MAX_TRACKS ) cdrom->numtracks = SDL_MAX_TRACKS; cdrom->status = CD_STOPPED; cdrom->cur_track = 0; cdrom->cur_frame = 0; SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kReadTOC; cdpb.csParam.words[0] = kGetLeadOutArea; if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { SDL_SetError("PBControlSync() failed"); return(-1); } leadout = MSF_TO_FRAMES( SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]), SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]), SDL_SYS_BCDToShort(cdpb.csParam.bytes[2])); SDL_memset(tracks, 0, sizeof(tracks)); SDL_memset(&cdpb, 0, sizeof(cdpb)); cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum; cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum; cdpb.csCode = kReadTOC; cdpb.csParam.words[0] = kGetTrackEntries; * ((long *) (cdpb.csParam.words+1)) = (long) tracks; cdpb.csParam.words[3] = cdrom->numtracks * sizeof(tracks[0]); * ((char *) (cdpb.csParam.words+4)) = 1; if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) { SDL_SetError("PBControlSync() failed"); return(-1); } SDL_cdlist[cdrom->id].hasAudio = false; for ( i=0; i<cdrom->numtracks; ++i ) { cdrom->track[i].id = i+1; if (tracks[i].entry.control & kDataTrackMask) cdrom->track[i].type = SDL_DATA_TRACK; else { cdrom->track[i].type = SDL_AUDIO_TRACK; SDL_cdlist[SDL_numcds].hasAudio = true; } cdrom->track[i].offset = MSF_TO_FRAMES( SDL_SYS_BCDToShort(tracks[i].entry.min), SDL_SYS_BCDToShort(tracks[i].entry.min), SDL_SYS_BCDToShort(tracks[i].entry.frame)); cdrom->track[i].length = MSF_TO_FRAMES( SDL_SYS_BCDToShort(tracks[i+1].entry.min), SDL_SYS_BCDToShort(tracks[i+1].entry.min), SDL_SYS_BCDToShort(tracks[i+1].entry.frame)) - cdrom->track[i].offset; } cdrom->track[i].offset = leadout; cdrom->track[i].length = 0; return(0); }
static int DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { SDL_Window *window = SDL_GetWindowFromID(renderer->window); SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); SDL_DFB_DEVICEDATA(display->device); DirectFB_TextureData *data; DFBResult ret; DFBSurfaceDescription dsc; SDL_DFB_CALLOC(data, 1, sizeof(*data)); texture->driverdata = data; data->format = texture->format; data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format)); if (DirectFB_AcquireVidLayer(renderer, texture) != 0) { /* fill surface description */ dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; dsc.width = texture->w; dsc.height = texture->h; /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance * No DSCAPS_SYSTEMONLY either - let dfb decide * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8 * Depends on other settings as well. Let dfb decide. */ dsc.caps = DSCAPS_PREMULTIPLIED; #if 0 if (texture->access == SDL_TEXTUREACCESS_STREAMING) dsc.caps |= DSCAPS_SYSTEMONLY; else dsc.caps |= DSCAPS_VIDEOONLY; #endif /* find the right pixelformat */ dsc.pixelformat = SDLToDFBPixelFormat(data->format); if (dsc.pixelformat == DSPF_UNKNOWN) { SDL_SetError("Unknown pixel format %d\n", data->format); goto error; } data->pixels = NULL; /* Create the surface */ SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, &data->surface)); if (SDL_ISPIXELFORMAT_INDEXED(data->format) && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &data->palette)); } } #if (DFB_VERSION_ATLEAST(1,2,0)) data->render_options = DSRO_NONE; #endif if (texture->access == SDL_TEXTUREACCESS_STREAMING) { data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch); } return 0; error: SDL_DFB_RELEASE(data->palette); SDL_DFB_RELEASE(data->surface); SDL_DFB_FREE(texture->driverdata); return -1; }
/* Create auxiliary (toplevel) windows with the current visual */ static void create_aux_windows(_THIS) { int x = 0, y = 0; char classname[1024]; XSetWindowAttributes xattr; XWMHints *hints; unsigned long app_event_mask; int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen)); /* Look up some useful Atoms */ WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False); /* Don't create any extra windows if we are being managed */ if ( SDL_windowid ) { FSwindow = 0; WMwindow = SDL_strtol(SDL_windowid, NULL, 0); return; } if(FSwindow) XDestroyWindow(SDL_Display, FSwindow); #if SDL_VIDEO_DRIVER_X11_XINERAMA if ( use_xinerama ) { x = xinerama_info.x_org; y = xinerama_info.y_org; } #endif xattr.override_redirect = True; xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0; xattr.border_pixel = 0; xattr.colormap = SDL_XColorMap; FSwindow = XCreateWindow(SDL_Display, SDL_Root, x, y, 32, 32, 0, this->hidden->depth, InputOutput, SDL_Visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap, &xattr); XSelectInput(SDL_Display, FSwindow, StructureNotifyMask); /* Tell KDE to keep the fullscreen window on top */ { XEvent ev; long mask; SDL_memset(&ev, 0, sizeof(ev)); ev.xclient.type = ClientMessage; ev.xclient.window = SDL_Root; ev.xclient.message_type = XInternAtom(SDL_Display, "KWM_KEEP_ON_TOP", False); ev.xclient.format = 32; ev.xclient.data.l[0] = FSwindow; ev.xclient.data.l[1] = CurrentTime; mask = SubstructureRedirectMask; XSendEvent(SDL_Display, SDL_Root, False, mask, &ev); } hints = NULL; if(WMwindow) { /* All window attributes must survive the recreation */ hints = XGetWMHints(SDL_Display, WMwindow); XDestroyWindow(SDL_Display, WMwindow); } /* Create the window for windowed management */ /* (reusing the xattr structure above) */ WMwindow = XCreateWindow(SDL_Display, SDL_Root, x, y, 32, 32, 0, this->hidden->depth, InputOutput, SDL_Visual, CWBackPixel | CWBorderPixel | CWColormap, &xattr); /* Set the input hints so we get keyboard input */ if(!hints) { hints = XAllocWMHints(); hints->input = True; hints->flags = InputHint; } XSetWMHints(SDL_Display, WMwindow, hints); XFree(hints); X11_SetCaptionNoLock(this, this->wm_title, this->wm_icon); app_event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask | PropertyChangeMask | StructureNotifyMask | KeymapStateMask; XSelectInput(SDL_Display, WMwindow, app_event_mask); /* Set the class hints so we can get an icon (AfterStep) */ get_classname(classname, sizeof(classname)); { XClassHint *classhints; classhints = XAllocClassHint(); if(classhints != NULL) { classhints->res_name = classname; classhints->res_class = classname; XSetClassHint(SDL_Display, WMwindow, classhints); XFree(classhints); } } /* Setup the communication with the IM server */ /* create_aux_windows may be called several times against the same Display. We should reuse the SDL_IM if one has been opened for the Display, so we should not simply reset SDL_IM here. */ #ifdef X_HAVE_UTF8_STRING if (SDL_X11_HAVE_UTF8) { /* Discard obsolete resources if any. */ if (SDL_IM != NULL && SDL_Display != XDisplayOfIM(SDL_IM)) { /* Just a double check. I don't think this code is ever executed. */ SDL_SetError("display has changed while an IM is kept"); if (SDL_IC) { XUnsetICFocus(SDL_IC); XDestroyIC(SDL_IC); SDL_IC = NULL; } XCloseIM(SDL_IM); SDL_IM = NULL; } /* Open an input method. */ if (SDL_IM == NULL) { char *old_locale = NULL, *old_modifiers = NULL; const char *p; size_t n; /* I'm not comfortable to do locale setup here. However, we need C library locale (and xlib modifiers) to be set based on the user's preference to use XIM, and many existing game programs doesn't take care of users' locale preferences, so someone other than the game program should do it. Moreover, ones say that some game programs heavily rely on the C locale behaviour, e.g., strcol()'s, and we can't change the C library locale. Given the situation, I couldn't find better place to do the job... */ /* Save the current (application program's) locale settings. */ p = setlocale(LC_ALL, NULL); if ( p ) { n = SDL_strlen(p)+1; old_locale = SDL_stack_alloc(char, n); if ( old_locale ) { SDL_strlcpy(old_locale, p, n); } } p = XSetLocaleModifiers(NULL); if ( p ) { n = SDL_strlen(p)+1; old_modifiers = SDL_stack_alloc(char, n); if ( old_modifiers ) { SDL_strlcpy(old_modifiers, p, n); } } /* Fetch the user's preferences and open the input method with them. */ setlocale(LC_ALL, ""); XSetLocaleModifiers(""); SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname); /* Restore the application's locale settings so that we don't break the application's expected behaviour. */ if ( old_locale ) { /* We need to restore the C library locale first, since the interpretation of the X modifier may depend on it. */ setlocale(LC_ALL, old_locale); SDL_stack_free(old_locale); } if ( old_modifiers ) { XSetLocaleModifiers(old_modifiers); SDL_stack_free(old_modifiers); } } /* Create a new input context for the new window just created. */ if (SDL_IM == NULL) { SDL_SetError("no input method could be opened"); } else { if (SDL_IC != NULL) { /* Discard the old IC before creating new one. */ XUnsetICFocus(SDL_IC); XDestroyIC(SDL_IC); } /* Theoretically we should check the current IM supports PreeditNothing+StatusNothing style (i.e., root window method) before creating the IC. However, it is the bottom line method, and we supports any other options. If the IM didn't support root window method, the following call fails, and SDL falls back to pre-XIM keyboard handling. */ SDL_IC = pXCreateIC(SDL_IM, XNClientWindow, WMwindow, XNFocusWindow, WMwindow, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNResourceName, classname, XNResourceClass, classname, NULL); if (SDL_IC == NULL) { SDL_SetError("no input context could be created"); XCloseIM(SDL_IM); SDL_IM = NULL; } else { /* We need to receive X events that an IM wants and to pass them to the IM through XFilterEvent. The set of events may vary depending on the IM implementation and the options specified through various routes. Although unlikely, the xlib specification allows IM to change the event requirement with its own circumstances, it is safe to call SelectInput whenever we re-create an IC. */ unsigned long mask = 0; char *ret = pXGetICValues(SDL_IC, XNFilterEvents, &mask, NULL); if (ret != NULL) { XUnsetICFocus(SDL_IC); XDestroyIC(SDL_IC); SDL_IC = NULL; SDL_SetError("no input context could be created"); XCloseIM(SDL_IM); SDL_IM = NULL; } else { XSelectInput(SDL_Display, WMwindow, app_event_mask | mask); XSetICFocus(SDL_IC); } } } }
static int SDL_SYS_LogicError(void) { return SDL_SetError("Logic error: No haptic devices available."); }