src/events/SDL_mouse.c
author Szymon Wilczek <kazeuser@gmail.com>
Wed, 06 Aug 2008 08:48:43 +0000
branchgsoc2008_manymouse
changeset 3776 a9c2a7071874
parent 3774 8b5b67000dc0
child 3777 54d08ecec1cb
permissions -rw-r--r--
upgraded functions
     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     int posted=0;
   342 	last_x=x;
   343 	last_y=y;
   344     if(SDL_ProcessEvents[type]==SDL_ENABLE)
   345     {
   346         SDL_Event event;
   347         event.proximity.which=(Uint8)index;
   348         event.proximity.x=x;
   349         event.proximity.y=y;
   350         event.type=type;
   351         event.proximity.type=type;
   352         posted = (SDL_PushEvent(&event) > 0);
   353         if(type==SDL_PROXIMITYIN)
   354         {
   355             SDL_mice[index]->proximity=SDL_TRUE;
   356         }
   357         else
   358         {
   359             SDL_mice[index]->proximity=SDL_FALSE;
   360         }
   361     }
   362     return posted;
   363 }
   364 
   365 int
   366 SDL_SendMouseMotion(int id, int relative, int x, int y,int z)
   367 {
   368     int index=SDL_GetIndexById(id);
   369     SDL_Mouse *mouse = SDL_GetMouse(index);
   370     int posted;
   371     int xrel;
   372     int yrel;
   373 	/*while using the relative mode and many windows, we have to be sure,
   374 	that the pointers find themselves inside the windows*/
   375 	if(x>x_max)
   376 	{
   377 		x=x_max;
   378 	}
   379 	if(y>y_max)
   380 	{
   381 		y=y_max;
   382 	}
   383 
   384     if (!mouse || mouse->flush_motion) {
   385         return 0;
   386     }
   387 
   388 	/*if the mouse is out of proximity we don't to want to have any motion from it*/
   389     if(mouse->proximity==SDL_FALSE)
   390     {
   391         last_x=x;
   392         last_y=y;
   393         return 0;
   394     }
   395 
   396 	/*the relative motion is calculated regarding the system cursor last position*/
   397 
   398     xrel = x - last_x;
   399     yrel = y - last_y;
   400 
   401     /* Drop events that don't change state */
   402     if (!xrel && !yrel) {
   403 #if 0
   404         printf("Mouse event didn't change state - dropped!\n");
   405 #endif
   406         return 0;
   407     }
   408 
   409     /* Update internal mouse coordinates */
   410     if (mouse->relative_mode==SDL_FALSE) {
   411         mouse->x = x;
   412         mouse->y = y;
   413     }
   414     else
   415     {
   416         if(mouse->x+xrel>x_max)
   417         {
   418             mouse->x=x_max;
   419         }
   420         else if(mouse->x+xrel<0)
   421         {
   422             mouse->x=0;
   423         }
   424         else
   425         {
   426             mouse->x+=xrel;
   427         }
   428         if(mouse->y+yrel>y_max)
   429         {
   430             mouse->y=y_max;
   431         }
   432         else if(mouse->y+yrel<0)
   433         {
   434             mouse->y=0;
   435         }
   436         else
   437         {
   438             mouse->y+=yrel;
   439         }
   440     }
   441     mouse->xdelta += xrel;
   442     mouse->ydelta += yrel;
   443     mouse->pressure=z;
   444 
   445     /* Move the mouse cursor, if needed */
   446     if (mouse->cursor_shown && !mouse->relative_mode &&
   447         mouse->MoveCursor && mouse->cur_cursor) {
   448         mouse->MoveCursor(mouse->cur_cursor);
   449     }
   450 
   451     /* Post the event, if desired */
   452     posted = 0;
   453     if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE && SDL_mice[index]->proximity==SDL_TRUE) {
   454         SDL_Event event;
   455         event.motion.type = SDL_MOUSEMOTION;
   456 		event.motion.which = (Uint8) index;
   457         event.motion.state = mouse->buttonstate;
   458         event.motion.x = mouse->x;
   459         event.motion.y = mouse->y;
   460         event.motion.pressure= mouse->pressure;
   461         event.motion.xrel = xrel;
   462         event.motion.yrel = yrel;
   463         event.motion.windowID = mouse->focus;
   464         event.motion.pressure_max=mouse->pressure_max;
   465         event.motion.pressure_min=mouse->pressure_min;
   466 		event.motion.cursor=SDL_mice[index]->current_end;
   467         posted = (SDL_PushEvent(&event) > 0);
   468     }
   469     last_x=x;
   470     last_y=y;
   471     return posted;
   472 }
   473 
   474 int
   475 SDL_SendMouseButton(int id, Uint8 state, Uint8 button)
   476 {
   477     int index=SDL_GetIndexById(id);
   478     SDL_Mouse *mouse = SDL_GetMouse(index);
   479     int posted;
   480     Uint8 type;
   481 
   482     if (!mouse) {
   483         return 0;
   484     }
   485 
   486     /* Figure out which event to perform */
   487     switch (state) {
   488     case SDL_PRESSED:
   489         if (mouse->buttonstate & SDL_BUTTON(button)) {
   490             /* Ignore this event, no state change */
   491             return 0;
   492         }
   493         type = SDL_MOUSEBUTTONDOWN;
   494         mouse->buttonstate |= SDL_BUTTON(button);
   495         break;
   496     case SDL_RELEASED:
   497         type = SDL_MOUSEBUTTONUP;
   498         mouse->buttonstate &= ~SDL_BUTTON(button);
   499         break;
   500     default:
   501         /* Invalid state -- bail */
   502         return 0;
   503     }
   504 
   505     /* Post the event, if desired */
   506     posted = 0;
   507     if (SDL_ProcessEvents[type] == SDL_ENABLE) {
   508         SDL_Event event;
   509         event.type = type;
   510         event.button.which = (Uint8) index;
   511         event.button.state = state;
   512         event.button.button = button;
   513         event.button.x = mouse->x;
   514         event.button.y = mouse->y;
   515         event.button.windowID = mouse->focus;
   516         posted = (SDL_PushEvent(&event) > 0);
   517     }
   518     return posted;
   519 }
   520 
   521 int
   522 SDL_SendMouseWheel(int index, int x, int y)
   523 {
   524     SDL_Mouse *mouse = SDL_GetMouse(index);
   525     int posted;
   526 
   527     if (!mouse || (!x && !y)) {
   528         return 0;
   529     }
   530 
   531     /* Post the event, if desired */
   532     posted = 0;
   533     if (SDL_ProcessEvents[SDL_MOUSEWHEEL] == SDL_ENABLE) {
   534         SDL_Event event;
   535         event.type = SDL_MOUSEWHEEL;
   536         event.wheel.which = (Uint8) index;
   537         event.wheel.x = x;
   538         event.wheel.y = y;
   539         event.wheel.windowID = mouse->focus;
   540         posted = (SDL_PushEvent(&event) > 0);
   541     }
   542     return posted;
   543 }
   544 
   545 void
   546 SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
   547 {
   548     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   549 
   550     if (!mouse) {
   551         return;
   552     }
   553 
   554     if (mouse->WarpMouse) {
   555         mouse->WarpMouse(mouse, windowID, x, y);
   556     } else {
   557         SDL_SetMouseFocus(SDL_current_mouse, windowID);
   558         SDL_SendMouseMotion(SDL_current_mouse, 0, x, y,0);
   559     }
   560 }
   561 
   562 SDL_Cursor *
   563 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
   564                  int w, int h, int hot_x, int hot_y)
   565 {
   566     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   567     SDL_Surface *surface;
   568     SDL_Cursor *cursor;
   569     int x, y;
   570     Uint32 *pixel;
   571     Uint8 datab, maskb;
   572     const Uint32 black = 0xFF000000;
   573     const Uint32 white = 0xFFFFFFFF;
   574     const Uint32 transparent = 0x00000000;
   575 
   576     if (!mouse) {
   577         SDL_SetError("No mice are initialized");
   578         return NULL;
   579     }
   580 
   581     if (!mouse->CreateCursor) {
   582         SDL_SetError("Current mouse doesn't have cursor support");
   583         return NULL;
   584     }
   585 
   586     /* Sanity check the hot spot */
   587     if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) {
   588         SDL_SetError("Cursor hot spot doesn't lie within cursor");
   589         return NULL;
   590     }
   591 
   592     /* Make sure the width is a multiple of 8 */
   593     w = ((w + 7) & ~7);
   594 
   595     /* Create the surface from a bitmap*/
   596     surface =
   597         SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
   598                              0xFF000000);
   599     if (!surface) {
   600         return NULL;
   601     }
   602     for (y = 0; y < h; ++y) {
   603         pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
   604         for (x = 0; x < w; ++x) {
   605             if ((x % 8) == 0) {
   606                 datab = *data++;
   607                 maskb = *mask++;
   608             }
   609             if (maskb & 0x80) {
   610                 *pixel++ = (datab & 0x80) ? black : white;
   611             } else {
   612                 *pixel++ = (datab & 0x80) ? black : transparent;
   613             }
   614             datab <<= 1;
   615             maskb <<= 1;
   616         }
   617     }
   618 
   619     cursor = mouse->CreateCursor(surface, hot_x, hot_y);
   620     if (cursor) {
   621         cursor->mouse = mouse;
   622         cursor->next = mouse->cursors;
   623         mouse->cursors = cursor;
   624     }
   625 
   626     SDL_FreeSurface(surface);
   627 
   628     return cursor;
   629 }
   630 
   631 /* SDL_SetCursor(NULL) can be used to force the cursor redraw,
   632    if this is desired for any reason.  This is used when setting
   633    the video mode and when the SDL window gains the mouse focus.
   634  */
   635 void
   636 SDL_SetCursor(SDL_Cursor * cursor)
   637 {
   638     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   639 
   640     if (!mouse) {
   641         SDL_SetError("No mice are initialized");
   642         return;
   643     }
   644 
   645     /* Set the new cursor */
   646     if (cursor) {
   647         /* Make sure the cursor is still valid for this mouse */
   648         SDL_Cursor *found;
   649         for (found = mouse->cursors; found; found = found->next) {
   650             if (found == cursor) {
   651                 break;
   652             }
   653         }
   654         if (!found) {
   655             SDL_SetError("Cursor not associated with the current mouse");
   656             return;
   657         }
   658         mouse->cur_cursor = cursor;
   659     } else {
   660         cursor = mouse->cur_cursor;
   661     }
   662 
   663     if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
   664         if (mouse->ShowCursor) {
   665             mouse->ShowCursor(cursor);
   666         }
   667     } else {
   668         if (mouse->ShowCursor) {
   669             mouse->ShowCursor(NULL);
   670         }
   671     }
   672 }
   673 
   674 SDL_Cursor *
   675 SDL_GetCursor(void)
   676 {
   677     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   678 
   679     if (!mouse) {
   680         return NULL;
   681     }
   682     return mouse->cur_cursor;
   683 }
   684 
   685 void
   686 SDL_FreeCursor(SDL_Cursor * cursor)
   687 {
   688     SDL_Mouse *mouse;
   689     SDL_Cursor *curr, *prev;
   690 
   691     if (!cursor) {
   692         return;
   693     }
   694     mouse = cursor->mouse;
   695 
   696     if (cursor == mouse->def_cursor) {
   697         return;
   698     }
   699     if (cursor == mouse->cur_cursor) {
   700         SDL_SetCursor(mouse->def_cursor);
   701     }
   702 
   703     for (prev = NULL, curr = mouse->cursors; curr;
   704          prev = curr, curr = curr->next) {
   705         if (curr == cursor) {
   706             if (prev) {
   707                 prev->next = curr->next;
   708             } else {
   709                 mouse->cursors = curr->next;
   710             }
   711 
   712             if (mouse->FreeCursor) {
   713                 mouse->FreeCursor(curr);
   714             }
   715             return;
   716         }
   717     }
   718 }
   719 
   720 int
   721 SDL_ShowCursor(int toggle)
   722 {
   723     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   724     SDL_bool shown;
   725 
   726     if (!mouse) {
   727         return 0;
   728     }
   729 
   730     shown = mouse->cursor_shown;
   731     if (toggle >= 0) {
   732         if (toggle) {
   733             mouse->cursor_shown = SDL_TRUE;
   734         } else {
   735             mouse->cursor_shown = SDL_FALSE;
   736         }
   737         if (mouse->cursor_shown != shown) {
   738             SDL_SetCursor(NULL);
   739         }
   740     }
   741     return shown;
   742 }
   743 
   744 int SDL_SetIndexId(int id, int index)
   745 {
   746     if(id>SDL_highestId)
   747     {
   748         int *indexes;
   749         indexes =
   750             (int*) SDL_realloc(SDL_IdIndex,
   751                                        (id + 1) * sizeof(int));
   752         if (!indexes) {
   753             SDL_OutOfMemory();
   754             return -1;
   755         }
   756         SDL_IdIndex=indexes;
   757         SDL_IdIndex[id]=index;
   758         SDL_highestId=id;
   759     }
   760     else
   761     {
   762         SDL_IdIndex[id]=index;
   763     }
   764 	return 1;
   765 }
   766 
   767 int SDL_GetIndexById(int id)
   768 {
   769     if(id>SDL_highestId)
   770     {
   771         return -1;
   772     }
   773     else
   774     {
   775         return SDL_IdIndex[id];
   776     }
   777 }
   778 
   779 int SDL_GetNumOfMice(void)
   780 {
   781     return SDL_num_mice;
   782 }
   783 
   784 char* SDL_GetMouseName(int index)
   785 {
   786     SDL_Mouse* mouse = SDL_GetMouse(index);
   787     if(!mouse)
   788     {
   789         return NULL;
   790     }
   791     return mouse->name;
   792 }
   793 
   794 void SDL_UpdateCoordinates(int x, int y)
   795 {
   796     x_max=x;
   797     y_max=y;
   798 }
   799 
   800 void SDL_ChangeEnd(int id, int end)
   801 {
   802 	int index=SDL_GetIndexById(id);
   803 	SDL_mice[index]->current_end=end;
   804 }
   805 
   806 int SDL_GetCursorsNumber(int index)
   807 {
   808 	SDL_Mouse* mouse = SDL_GetMouse(index);
   809     if(!mouse)
   810     {
   811         return -1;
   812     }
   813 	return mouse->total_ends;
   814 }
   815 
   816 int SDL_GetCurrentCursor(int index)
   817 {
   818     SDL_Mouse* mouse = SDL_GetMouse(index);
   819     if(!mouse)
   820     {
   821         return -1;
   822     }
   823     return mouse->current_end;
   824 }
   825 /* vi: set ts=4 sw=4 expandtab: */
   826