src/events/SDL_mouse.c
author Szymon Wilczek
Wed, 06 Aug 2008 11:49:28 +0000
branchgsoc2008_manymouse
changeset 3778 a9370b995ded
parent 3777 54d08ecec1cb
permissions -rw-r--r--
proximity events bug fix
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /* General mouse handling code for SDL */
    25 
    26 #include "SDL_events.h"
    27 #include "SDL_events_c.h"
    28 #include "default_cursor.h"
    29 
    30 
    31 static int SDL_num_mice=0;
    32 static int SDL_current_mouse=-1;
    33 static SDL_Mouse **SDL_mice=NULL;
    34 static int *SDL_IdIndex=NULL;
    35 static int SDL_highestId=-1;
    36 static int last_x, last_y;/*the last reported x and y coordinates by the system cursor*/
    37 int x_max, y_max; /*current window width and height*/
    38 /* Public functions */
    39 int
    40 SDL_MouseInit(void)
    41 {
    42     return (0);
    43 }
    44 
    45 SDL_Mouse *
    46 SDL_GetMouse(int index)
    47 {
    48     if (index < 0 || index >= SDL_num_mice) {
    49         return NULL;
    50     }
    51     return SDL_mice[index];
    52 }
    53 
    54 int
    55 SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name,int pressure_max,\
    56 int pressure_min, int ends)
    57 {
    58     SDL_Mouse **mice;
    59     int selected_mouse;
    60 	int length;
    61 
    62     /* Add the mouse to the list of mice */
    63     if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) {
    64         mice =
    65             (SDL_Mouse **) SDL_realloc(SDL_mice,
    66                                        (SDL_num_mice + 1) * sizeof(*mice));
    67         if (!mice) {
    68             SDL_OutOfMemory();
    69             return -1;
    70         }
    71 
    72         SDL_mice = mice;
    73         index = SDL_num_mice++;
    74     }
    75     SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index]));
    76     if (!SDL_mice[index]) {
    77         SDL_OutOfMemory();
    78         return -1;
    79     }
    80     *SDL_mice[index] = *mouse;
    81 
    82 	/*we're setting the mouse properties*/
    83 	length=0;
    84 	length=SDL_strlen(name);
    85     SDL_mice[index]->name=SDL_malloc((length+1)*sizeof(char));
    86     SDL_strlcpy(SDL_mice[index]->name,name,length);
    87     SDL_mice[index]->pressure_max=pressure_max;
    88     SDL_mice[index]->pressure_min=pressure_min;
    89     SDL_mice[index]->cursor_shown = SDL_TRUE;
    90     selected_mouse = SDL_SelectMouse(index);
    91     SDL_mice[index]->cur_cursor = NULL;
    92     SDL_mice[index]->def_cursor =
    93         SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
    94                          DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
    95     SDL_SetCursor(SDL_mice[index]->def_cursor);
    96 	/*we're assuming that all mouses are in the computer sensing zone*/
    97     SDL_mice[index]->proximity=SDL_TRUE;
    98 	/*we're assuming that all mouses are working in the absolute position mode
    99 	thanx to that, the users that don't want to use many mouses don't have to
   100 	worry about anything*/
   101     SDL_mice[index]->relative_mode=SDL_FALSE;
   102     SDL_mice[index]->current_end=0;
   103     SDL_mice[index]->total_ends=ends;
   104     SDL_SelectMouse(selected_mouse);
   105 
   106     return index;
   107 }
   108 
   109 void
   110 SDL_DelMouse(int index)
   111 {
   112     SDL_Mouse *mouse = SDL_GetMouse(index);
   113 
   114     if (!mouse) {
   115         return;
   116     }
   117 
   118     mouse->def_cursor = NULL;
   119     SDL_free(mouse->name);
   120     while (mouse->cursors) {
   121         SDL_FreeCursor(mouse->cursors);
   122     }
   123 
   124     if (mouse->FreeMouse) {
   125         mouse->FreeMouse(mouse);
   126     }
   127     SDL_free(mouse);
   128 
   129     SDL_mice[index] = NULL;
   130 }
   131 
   132 void
   133 SDL_ResetMouse(int index)
   134 {
   135     SDL_Mouse *mouse = SDL_GetMouse(index);
   136 
   137     if (!mouse) {
   138         return;
   139     }
   140 
   141     /* FIXME */
   142 }
   143 
   144 void
   145 SDL_MouseQuit(void)
   146 {
   147     int i;
   148 
   149     for (i = 0; i < SDL_num_mice; ++i) {
   150         SDL_DelMouse(i);
   151     }
   152     SDL_num_mice = 0;
   153     SDL_current_mouse = 0;
   154 
   155     if (SDL_mice) {
   156         SDL_free(SDL_mice);
   157         SDL_mice = NULL;
   158     }
   159 }
   160 
   161 int
   162 SDL_GetNumMice(void)
   163 {
   164     return SDL_num_mice;
   165 }
   166 
   167 int
   168 SDL_SelectMouse(int index)
   169 {
   170     if (index >= 0 && index < SDL_num_mice) {
   171         SDL_current_mouse = index;
   172     }
   173     return SDL_current_mouse;
   174 }
   175 
   176 SDL_WindowID
   177 SDL_GetMouseFocusWindow(int index)
   178 {
   179     SDL_Mouse *mouse = SDL_GetMouse(index);
   180 
   181     if (!mouse) {
   182         return 0;
   183     }
   184     return mouse->focus;
   185 }
   186 
   187 static int SDLCALL
   188 FlushMouseMotion(void *param, SDL_Event * event)
   189 {
   190     if (event->type == SDL_MOUSEMOTION
   191         && event->motion.which == (Uint8) SDL_current_mouse) {
   192         return 0;
   193     } else {
   194         return 1;
   195     }
   196 }
   197 
   198 int
   199 SDL_SetRelativeMouseMode(int index, SDL_bool enabled)
   200 {
   201     SDL_Mouse *mouse = SDL_GetMouse(index);
   202 
   203     if (!mouse) {
   204         return -1;
   205     }
   206 
   207     /* Flush pending mouse motion */
   208     mouse->flush_motion = SDL_TRUE;
   209     SDL_PumpEvents();
   210     mouse->flush_motion = SDL_FALSE;
   211     SDL_FilterEvents(FlushMouseMotion, mouse);
   212 
   213     /* Set the relative mode */
   214     mouse->relative_mode = enabled;
   215 
   216     /* Update cursor visibility */
   217     SDL_SetCursor(NULL);
   218 
   219     if (!enabled) {
   220         /* Restore the expected mouse position */
   221         SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
   222     }
   223     return 0;
   224 }
   225 
   226 SDL_bool
   227 SDL_GetRelativeMouseMode(int index)
   228 {
   229     SDL_Mouse *mouse = SDL_GetMouse(index);
   230 
   231     if (!mouse) {
   232         return SDL_FALSE;
   233     }
   234     return mouse->relative_mode;
   235 }
   236 
   237 Uint8
   238 SDL_GetMouseState(int index, int *x, int *y)
   239 {
   240     SDL_Mouse *mouse = SDL_GetMouse(index);
   241 
   242     if (!mouse) {
   243         if (x) {
   244             *x = 0;
   245         }
   246         if (y) {
   247             *y = 0;
   248         }
   249         return 0;
   250     }
   251 
   252     if (x) {
   253         *x = mouse->x;
   254     }
   255     if (y) {
   256         *y = mouse->y;
   257     }
   258     return mouse->buttonstate;
   259 }
   260 
   261 Uint8
   262 SDL_GetRelativeMouseState(int index, int *x, int *y)
   263 {
   264     SDL_Mouse *mouse = SDL_GetMouse(index);
   265 
   266     if (!mouse) {
   267         if (x) {
   268             *x = 0;
   269         }
   270         if (y) {
   271             *y = 0;
   272         }
   273         return 0;
   274     }
   275 
   276     if (x) {
   277         *x = mouse->xdelta;
   278     }
   279     if (y) {
   280         *y = mouse->ydelta;
   281     }
   282     mouse->xdelta = 0;
   283     mouse->ydelta = 0;
   284     return mouse->buttonstate;
   285 }
   286 
   287 void
   288 SDL_SetMouseFocus(int id, SDL_WindowID windowID)
   289 {
   290     int index = SDL_GetIndexById(id);
   291     SDL_Mouse *mouse = SDL_GetMouse(index);
   292     int i;
   293     SDL_bool focus;
   294 
   295     if (!mouse || (mouse->focus == windowID)) {
   296         return;
   297     }
   298 
   299     /* See if the current window has lost focus */
   300     if (mouse->focus) {
   301         focus = SDL_FALSE;
   302         for (i = 0; i < SDL_num_mice; ++i) {
   303             SDL_Mouse *check;
   304             if (i != index) {
   305                 check = SDL_GetMouse(i);
   306                 if (check && check->focus == mouse->focus) {
   307                     focus = SDL_TRUE;
   308                     break;
   309                 }
   310             }
   311         }
   312         if (!focus) {
   313             SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
   314         }
   315     }
   316 
   317     mouse->focus = windowID;
   318 
   319     if (mouse->focus) {
   320         focus = SDL_FALSE;
   321         for (i = 0; i < SDL_num_mice; ++i) {
   322             SDL_Mouse *check;
   323             if (i != index) {
   324                 check = SDL_GetMouse(i);
   325                 if (check && check->focus == mouse->focus) {
   326                     focus = SDL_TRUE;
   327                     break;
   328                 }
   329             }
   330         }
   331         if (!focus) {
   332             SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
   333         }
   334     }
   335 }
   336 
   337 int
   338 SDL_SendProximity(int id, int x, int y, int type)
   339 {
   340     int index=SDL_GetIndexById(id);
   341     SDL_Mouse* mouse=SDL_GetMouse(index);
   342     int posted=0;
   343 	last_x=x;
   344 	last_y=y;
   345     if(SDL_ProcessEvents[type]==SDL_ENABLE)
   346     {
   347         SDL_Event event;
   348         event.proximity.which=(Uint8)index;
   349         event.proximity.x=x;
   350         event.proximity.y=y;
   351         event.proximity.cursor=mouse->current_end;
   352         event.proximity.type=type;
   353         posted = (SDL_PushEvent(&event) > 0);
   354         if(type==SDL_PROXIMITYIN)
   355         {
   356             mouse->proximity=SDL_TRUE;
   357         }
   358         else
   359         {
   360             mouse->proximity=SDL_FALSE;
   361         }
   362     }
   363     return posted;
   364 }
   365 
   366 int
   367 SDL_SendMouseMotion(int id, int relative, int x, int y,int pressure)
   368 {
   369     int index=SDL_GetIndexById(id);
   370     SDL_Mouse *mouse = SDL_GetMouse(index);
   371     int posted;
   372     int xrel;
   373     int yrel;
   374 	/*while using the relative mode and many windows, we have to be sure,
   375 	that the pointers find themselves inside the windows*/
   376 	if(x>x_max)
   377 	{
   378 		x=x_max;
   379 	}
   380 	if(y>y_max)
   381 	{
   382 		y=y_max;
   383 	}
   384 
   385     if (!mouse || mouse->flush_motion) {
   386         return 0;
   387     }
   388 
   389 	/*if the mouse is out of proximity we don't to want to have any motion from it*/
   390     if(mouse->proximity==SDL_FALSE)
   391     {
   392         last_x=x;
   393         last_y=y;
   394         return 0;
   395     }
   396 
   397 	/*the relative motion is calculated regarding the system cursor last position*/
   398 
   399     xrel = x - last_x;
   400     yrel = y - last_y;
   401 
   402     /* Drop events that don't change state */
   403     if (!xrel && !yrel) {
   404 #if 0
   405         printf("Mouse event didn't change state - dropped!\n");
   406 #endif
   407         return 0;
   408     }
   409 
   410     /* Update internal mouse coordinates */
   411     if (mouse->relative_mode==SDL_FALSE) {
   412         mouse->x = x;
   413         mouse->y = y;
   414     }
   415     else
   416     {
   417         if(mouse->x+xrel>x_max)
   418         {
   419             mouse->x=x_max;
   420         }
   421         else if(mouse->x+xrel<0)
   422         {
   423             mouse->x=0;
   424         }
   425         else
   426         {
   427             mouse->x+=xrel;
   428         }
   429         if(mouse->y+yrel>y_max)
   430         {
   431             mouse->y=y_max;
   432         }
   433         else if(mouse->y+yrel<0)
   434         {
   435             mouse->y=0;
   436         }
   437         else
   438         {
   439             mouse->y+=yrel;
   440         }
   441     }
   442     mouse->xdelta += xrel;
   443     mouse->ydelta += yrel;
   444     mouse->pressure=pressure;
   445 
   446     /* Move the mouse cursor, if needed */
   447     if (mouse->cursor_shown && !mouse->relative_mode &&
   448         mouse->MoveCursor && mouse->cur_cursor) {
   449         mouse->MoveCursor(mouse->cur_cursor);
   450     }
   451 
   452     /* Post the event, if desired */
   453     posted = 0;
   454     if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE && \
   455             mouse->proximity==SDL_TRUE) {
   456         SDL_Event event;
   457         event.motion.type = SDL_MOUSEMOTION;
   458 		event.motion.which = (Uint8) index;
   459         event.motion.state = mouse->buttonstate;
   460         event.motion.x = mouse->x;
   461         event.motion.y = mouse->y;
   462         event.motion.pressure= mouse->pressure;
   463         event.motion.xrel = xrel;
   464         event.motion.yrel = yrel;
   465         event.motion.windowID = mouse->focus;
   466         event.motion.pressure_max=mouse->pressure_max;
   467         event.motion.pressure_min=mouse->pressure_min;
   468 		event.motion.cursor=SDL_mice[index]->current_end;
   469         posted = (SDL_PushEvent(&event) > 0);
   470     }
   471     last_x=x;
   472     last_y=y;
   473     return posted;
   474 }
   475 
   476 int
   477 SDL_SendMouseButton(int id, Uint8 state, Uint8 button)
   478 {
   479     int index=SDL_GetIndexById(id);
   480     SDL_Mouse *mouse = SDL_GetMouse(index);
   481     int posted;
   482     Uint8 type;
   483 
   484     if (!mouse) {
   485         return 0;
   486     }
   487 
   488     /* Figure out which event to perform */
   489     switch (state) {
   490     case SDL_PRESSED:
   491         if (mouse->buttonstate & SDL_BUTTON(button)) {
   492             /* Ignore this event, no state change */
   493             return 0;
   494         }
   495         type = SDL_MOUSEBUTTONDOWN;
   496         mouse->buttonstate |= SDL_BUTTON(button);
   497         break;
   498     case SDL_RELEASED:
   499         type = SDL_MOUSEBUTTONUP;
   500         mouse->buttonstate &= ~SDL_BUTTON(button);
   501         break;
   502     default:
   503         /* Invalid state -- bail */
   504         return 0;
   505     }
   506 
   507     /* Post the event, if desired */
   508     posted = 0;
   509     if (SDL_ProcessEvents[type] == SDL_ENABLE) {
   510         SDL_Event event;
   511         event.type = type;
   512         event.button.which = (Uint8) index;
   513         event.button.state = state;
   514         event.button.button = button;
   515         event.button.x = mouse->x;
   516         event.button.y = mouse->y;
   517         event.button.windowID = mouse->focus;
   518         posted = (SDL_PushEvent(&event) > 0);
   519     }
   520     return posted;
   521 }
   522 
   523 int
   524 SDL_SendMouseWheel(int index, int x, int y)
   525 {
   526     SDL_Mouse *mouse = SDL_GetMouse(index);
   527     int posted;
   528 
   529     if (!mouse || (!x && !y)) {
   530         return 0;
   531     }
   532 
   533     /* Post the event, if desired */
   534     posted = 0;
   535     if (SDL_ProcessEvents[SDL_MOUSEWHEEL] == SDL_ENABLE) {
   536         SDL_Event event;
   537         event.type = SDL_MOUSEWHEEL;
   538         event.wheel.which = (Uint8) index;
   539         event.wheel.x = x;
   540         event.wheel.y = y;
   541         event.wheel.windowID = mouse->focus;
   542         posted = (SDL_PushEvent(&event) > 0);
   543     }
   544     return posted;
   545 }
   546 
   547 void
   548 SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
   549 {
   550     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   551 
   552     if (!mouse) {
   553         return;
   554     }
   555 
   556     if (mouse->WarpMouse) {
   557         mouse->WarpMouse(mouse, windowID, x, y);
   558     } else {
   559         SDL_SetMouseFocus(SDL_current_mouse, windowID);
   560         SDL_SendMouseMotion(SDL_current_mouse, 0, x, y,0);
   561     }
   562 }
   563 
   564 SDL_Cursor *
   565 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
   566                  int w, int h, int hot_x, int hot_y)
   567 {
   568     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   569     SDL_Surface *surface;
   570     SDL_Cursor *cursor;
   571     int x, y;
   572     Uint32 *pixel;
   573     Uint8 datab, maskb;
   574     const Uint32 black = 0xFF000000;
   575     const Uint32 white = 0xFFFFFFFF;
   576     const Uint32 transparent = 0x00000000;
   577 
   578     if (!mouse) {
   579         SDL_SetError("No mice are initialized");
   580         return NULL;
   581     }
   582 
   583     if (!mouse->CreateCursor) {
   584         SDL_SetError("Current mouse doesn't have cursor support");
   585         return NULL;
   586     }
   587 
   588     /* Sanity check the hot spot */
   589     if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) {
   590         SDL_SetError("Cursor hot spot doesn't lie within cursor");
   591         return NULL;
   592     }
   593 
   594     /* Make sure the width is a multiple of 8 */
   595     w = ((w + 7) & ~7);
   596 
   597     /* Create the surface from a bitmap*/
   598     surface =
   599         SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
   600                              0xFF000000);
   601     if (!surface) {
   602         return NULL;
   603     }
   604     for (y = 0; y < h; ++y) {
   605         pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
   606         for (x = 0; x < w; ++x) {
   607             if ((x % 8) == 0) {
   608                 datab = *data++;
   609                 maskb = *mask++;
   610             }
   611             if (maskb & 0x80) {
   612                 *pixel++ = (datab & 0x80) ? black : white;
   613             } else {
   614                 *pixel++ = (datab & 0x80) ? black : transparent;
   615             }
   616             datab <<= 1;
   617             maskb <<= 1;
   618         }
   619     }
   620 
   621     cursor = mouse->CreateCursor(surface, hot_x, hot_y);
   622     if (cursor) {
   623         cursor->mouse = mouse;
   624         cursor->next = mouse->cursors;
   625         mouse->cursors = cursor;
   626     }
   627 
   628     SDL_FreeSurface(surface);
   629 
   630     return cursor;
   631 }
   632 
   633 /* SDL_SetCursor(NULL) can be used to force the cursor redraw,
   634    if this is desired for any reason.  This is used when setting
   635    the video mode and when the SDL window gains the mouse focus.
   636  */
   637 void
   638 SDL_SetCursor(SDL_Cursor * cursor)
   639 {
   640     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   641 
   642     if (!mouse) {
   643         SDL_SetError("No mice are initialized");
   644         return;
   645     }
   646 
   647     /* Set the new cursor */
   648     if (cursor) {
   649         /* Make sure the cursor is still valid for this mouse */
   650         SDL_Cursor *found;
   651         for (found = mouse->cursors; found; found = found->next) {
   652             if (found == cursor) {
   653                 break;
   654             }
   655         }
   656         if (!found) {
   657             SDL_SetError("Cursor not associated with the current mouse");
   658             return;
   659         }
   660         mouse->cur_cursor = cursor;
   661     } else {
   662         cursor = mouse->cur_cursor;
   663     }
   664 
   665     if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
   666         if (mouse->ShowCursor) {
   667             mouse->ShowCursor(cursor);
   668         }
   669     } else {
   670         if (mouse->ShowCursor) {
   671             mouse->ShowCursor(NULL);
   672         }
   673     }
   674 }
   675 
   676 SDL_Cursor *
   677 SDL_GetCursor(void)
   678 {
   679     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   680 
   681     if (!mouse) {
   682         return NULL;
   683     }
   684     return mouse->cur_cursor;
   685 }
   686 
   687 void
   688 SDL_FreeCursor(SDL_Cursor * cursor)
   689 {
   690     SDL_Mouse *mouse;
   691     SDL_Cursor *curr, *prev;
   692 
   693     if (!cursor) {
   694         return;
   695     }
   696     mouse = cursor->mouse;
   697 
   698     if (cursor == mouse->def_cursor) {
   699         return;
   700     }
   701     if (cursor == mouse->cur_cursor) {
   702         SDL_SetCursor(mouse->def_cursor);
   703     }
   704 
   705     for (prev = NULL, curr = mouse->cursors; curr;
   706          prev = curr, curr = curr->next) {
   707         if (curr == cursor) {
   708             if (prev) {
   709                 prev->next = curr->next;
   710             } else {
   711                 mouse->cursors = curr->next;
   712             }
   713 
   714             if (mouse->FreeCursor) {
   715                 mouse->FreeCursor(curr);
   716             }
   717             return;
   718         }
   719     }
   720 }
   721 
   722 int
   723 SDL_ShowCursor(int toggle)
   724 {
   725     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   726     SDL_bool shown;
   727 
   728     if (!mouse) {
   729         return 0;
   730     }
   731 
   732     shown = mouse->cursor_shown;
   733     if (toggle >= 0) {
   734         if (toggle) {
   735             mouse->cursor_shown = SDL_TRUE;
   736         } else {
   737             mouse->cursor_shown = SDL_FALSE;
   738         }
   739         if (mouse->cursor_shown != shown) {
   740             SDL_SetCursor(NULL);
   741         }
   742     }
   743     return shown;
   744 }
   745 
   746 int SDL_SetIndexId(int id, int index)
   747 {
   748     if(id>SDL_highestId)
   749     {
   750         int *indexes;
   751         indexes =
   752             (int*) SDL_realloc(SDL_IdIndex,
   753                                        (id + 1) * sizeof(int));
   754         if (!indexes) {
   755             SDL_OutOfMemory();
   756             return -1;
   757         }
   758         SDL_IdIndex=indexes;
   759         SDL_IdIndex[id]=index;
   760         SDL_highestId=id;
   761     }
   762     else
   763     {
   764         SDL_IdIndex[id]=index;
   765     }
   766 	return 1;
   767 }
   768 
   769 int SDL_GetIndexById(int id)
   770 {
   771     if(id>SDL_highestId)
   772     {
   773         return -1;
   774     }
   775     else
   776     {
   777         return SDL_IdIndex[id];
   778     }
   779 }
   780 
   781 int SDL_GetNumOfMice(void)
   782 {
   783     return SDL_num_mice;
   784 }
   785 
   786 char* SDL_GetMouseName(int index)
   787 {
   788     SDL_Mouse* mouse = SDL_GetMouse(index);
   789     if(!mouse)
   790     {
   791         return NULL;
   792     }
   793     return mouse->name;
   794 }
   795 
   796 void SDL_UpdateCoordinates(int x, int y)
   797 {
   798     x_max=x;
   799     y_max=y;
   800 }
   801 
   802 void SDL_ChangeEnd(int id, int end)
   803 {
   804 	int index=SDL_GetIndexById(id);
   805 	SDL_mice[index]->current_end=end;
   806 }
   807 
   808 int SDL_GetCursorsNumber(int index)
   809 {
   810 	SDL_Mouse* mouse = SDL_GetMouse(index);
   811     if(!mouse)
   812     {
   813         return -1;
   814     }
   815 	return mouse->total_ends;
   816 }
   817 
   818 int SDL_GetCurrentCursor(int index)
   819 {
   820     SDL_Mouse* mouse = SDL_GetMouse(index);
   821     if(!mouse)
   822     {
   823         return -1;
   824     }
   825     return mouse->current_end;
   826 }
   827 /* vi: set ts=4 sw=4 expandtab: */
   828