src/events/SDL_mouse.c
author Szymon Wilczek
Sat, 02 Aug 2008 14:02:28 +0000
branchgsoc2008_manymouse
changeset 3771 8cc36a399a12
parent 3770 81b649bad6d2
child 3774 8b5b67000dc0
permissions -rw-r--r--
comments added and improved code look(windows part)
     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,int pressure_min)
    56 {
    57     SDL_Mouse **mice;
    58     int selected_mouse;
    59 	int length;
    60 
    61     /* Add the mouse to the list of mice */
    62     if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) {
    63         mice =
    64             (SDL_Mouse **) SDL_realloc(SDL_mice,
    65                                        (SDL_num_mice + 1) * sizeof(*mice));
    66         if (!mice) {
    67             SDL_OutOfMemory();
    68             return -1;
    69         }
    70 
    71         SDL_mice = mice;
    72         index = SDL_num_mice++;
    73     }
    74     SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index]));
    75     if (!SDL_mice[index]) {
    76         SDL_OutOfMemory();
    77         return -1;
    78     }
    79     *SDL_mice[index] = *mouse;
    80 
    81 	/*we're setting the mouse properties*/
    82 	length=0;
    83 	length=SDL_strlen(name);
    84     SDL_mice[index]->name=SDL_malloc((length+1)*sizeof(char));
    85     SDL_strlcpy(SDL_mice[index]->name,name,length);
    86     SDL_mice[index]->pressure_max=pressure_max;
    87     SDL_mice[index]->pressure_min=pressure_min;
    88     SDL_mice[index]->cursor_shown = SDL_TRUE;
    89     selected_mouse = SDL_SelectMouse(index);
    90     SDL_mice[index]->cur_cursor = NULL;
    91     SDL_mice[index]->def_cursor =
    92         SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
    93                          DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
    94     SDL_SetCursor(SDL_mice[index]->def_cursor);
    95 	/*we're assuming that all mouses are in the computer sensing zone*/
    96     SDL_mice[index]->proximity=SDL_TRUE;
    97 	/*we're assuming that all mouses are working in the absolute position mode
    98 	thanx to that, the users that don't want to use many mouses don't have to
    99 	worry about anything*/
   100     SDL_mice[index]->relative_mode=SDL_FALSE;
   101     SDL_SelectMouse(selected_mouse);
   102 
   103     return index;
   104 }
   105 
   106 void
   107 SDL_DelMouse(int index)
   108 {
   109     SDL_Mouse *mouse = SDL_GetMouse(index);
   110 
   111     if (!mouse) {
   112         return;
   113     }
   114 
   115     mouse->def_cursor = NULL;
   116     SDL_free(mouse->name);
   117     while (mouse->cursors) {
   118         SDL_FreeCursor(mouse->cursors);
   119     }
   120 
   121     if (mouse->FreeMouse) {
   122         mouse->FreeMouse(mouse);
   123     }
   124     SDL_free(mouse);
   125 
   126     SDL_mice[index] = NULL;
   127 }
   128 
   129 void
   130 SDL_ResetMouse(int index)
   131 {
   132     SDL_Mouse *mouse = SDL_GetMouse(index);
   133 
   134     if (!mouse) {
   135         return;
   136     }
   137 
   138     /* FIXME */
   139 }
   140 
   141 void
   142 SDL_MouseQuit(void)
   143 {
   144     int i;
   145 
   146     for (i = 0; i < SDL_num_mice; ++i) {
   147         SDL_DelMouse(i);
   148     }
   149     SDL_num_mice = 0;
   150     SDL_current_mouse = 0;
   151 
   152     if (SDL_mice) {
   153         SDL_free(SDL_mice);
   154         SDL_mice = NULL;
   155     }
   156 }
   157 
   158 int
   159 SDL_GetNumMice(void)
   160 {
   161     return SDL_num_mice;
   162 }
   163 
   164 int
   165 SDL_SelectMouse(int index)
   166 {
   167     if (index >= 0 && index < SDL_num_mice) {
   168         SDL_current_mouse = index;
   169     }
   170     return SDL_current_mouse;
   171 }
   172 
   173 SDL_WindowID
   174 SDL_GetMouseFocusWindow()
   175 {
   176     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   177 
   178     if (!mouse) {
   179         return 0;
   180     }
   181     return mouse->focus;
   182 }
   183 
   184 static int SDLCALL
   185 FlushMouseMotion(void *param, SDL_Event * event)
   186 {
   187     if (event->type == SDL_MOUSEMOTION
   188         && event->motion.which == (Uint8) SDL_current_mouse) {
   189         return 0;
   190     } else {
   191         return 1;
   192     }
   193 }
   194 
   195 int
   196 SDL_SetRelativeMouseMode(SDL_bool enabled, int index)
   197 {
   198     SDL_Mouse *mouse = SDL_GetMouse(index);
   199 
   200     if (!mouse) {
   201         return -1;
   202     }
   203 
   204     /* Flush pending mouse motion */
   205     mouse->flush_motion = SDL_TRUE;
   206     SDL_PumpEvents();
   207     mouse->flush_motion = SDL_FALSE;
   208     SDL_FilterEvents(FlushMouseMotion, mouse);
   209 
   210     /* Set the relative mode */
   211     mouse->relative_mode = enabled;
   212 
   213     /* Update cursor visibility */
   214     SDL_SetCursor(NULL);
   215 
   216     if (!enabled) {
   217         /* Restore the expected mouse position */
   218         SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
   219     }
   220     return 0;
   221 }
   222 
   223 SDL_bool
   224 SDL_GetRelativeMouseMode()
   225 {
   226     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   227 
   228     if (!mouse) {
   229         return SDL_FALSE;
   230     }
   231     return mouse->relative_mode;
   232 }
   233 
   234 Uint8
   235 SDL_GetMouseState(int *x, int *y)
   236 {
   237     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   238 
   239     if (!mouse) {
   240         if (x) {
   241             *x = 0;
   242         }
   243         if (y) {
   244             *y = 0;
   245         }
   246         return 0;
   247     }
   248 
   249     if (x) {
   250         *x = mouse->x;
   251     }
   252     if (y) {
   253         *y = mouse->y;
   254     }
   255     return mouse->buttonstate;
   256 }
   257 
   258 Uint8
   259 SDL_GetRelativeMouseState(int *x, int *y)
   260 {
   261     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   262 
   263     if (!mouse) {
   264         if (x) {
   265             *x = 0;
   266         }
   267         if (y) {
   268             *y = 0;
   269         }
   270         return 0;
   271     }
   272 
   273     if (x) {
   274         *x = mouse->xdelta;
   275     }
   276     if (y) {
   277         *y = mouse->ydelta;
   278     }
   279     mouse->xdelta = 0;
   280     mouse->ydelta = 0;
   281     return mouse->buttonstate;
   282 }
   283 
   284 void
   285 SDL_SetMouseFocus(int id, SDL_WindowID windowID)
   286 {
   287     int index = SDL_GetIndexById(id);
   288     SDL_Mouse *mouse = SDL_GetMouse(index);
   289     int i;
   290     SDL_bool focus;
   291 
   292     if (!mouse || (mouse->focus == windowID)) {
   293         return;
   294     }
   295 
   296     /* See if the current window has lost focus */
   297     if (mouse->focus) {
   298         focus = SDL_FALSE;
   299         for (i = 0; i < SDL_num_mice; ++i) {
   300             SDL_Mouse *check;
   301             if (i != index) {
   302                 check = SDL_GetMouse(i);
   303                 if (check && check->focus == mouse->focus) {
   304                     focus = SDL_TRUE;
   305                     break;
   306                 }
   307             }
   308         }
   309         if (!focus) {
   310             SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
   311         }
   312     }
   313 
   314     mouse->focus = windowID;
   315 
   316     if (mouse->focus) {
   317         focus = SDL_FALSE;
   318         for (i = 0; i < SDL_num_mice; ++i) {
   319             SDL_Mouse *check;
   320             if (i != index) {
   321                 check = SDL_GetMouse(i);
   322                 if (check && check->focus == mouse->focus) {
   323                     focus = SDL_TRUE;
   324                     break;
   325                 }
   326             }
   327         }
   328         if (!focus) {
   329             SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
   330         }
   331     }
   332 }
   333 
   334 int
   335 SDL_SendProximity(int id, int x, int y, int type)
   336 {
   337     int index=SDL_GetIndexById(id);
   338     int posted=0;
   339 	last_x=x;
   340 	last_y=y;
   341     if(SDL_ProcessEvents[type]==SDL_ENABLE)
   342     {
   343         SDL_Event event;
   344         event.proximity.which=(Uint8)index;
   345         event.proximity.x=x;
   346         event.proximity.y=y;
   347         event.type=type;
   348         event.proximity.type=type;
   349         posted = (SDL_PushEvent(&event) > 0);
   350         if(type==SDL_PROXIMITYIN)
   351         {
   352             SDL_mice[index]->proximity=SDL_TRUE;
   353         }
   354         else
   355         {
   356             SDL_mice[index]->proximity=SDL_FALSE;
   357         }
   358     }
   359     return posted;
   360 }
   361 
   362 int
   363 SDL_SendMouseMotion(int id, int relative, int x, int y,int z)
   364 {
   365     int index=SDL_GetIndexById(id);
   366     SDL_Mouse *mouse = SDL_GetMouse(index);
   367     int posted;
   368     int xrel;
   369     int yrel;
   370 	/*while using the relative mode and many windows, we have to be sure,
   371 	that the pointers find themselves inside the windows*/
   372 	if(x>x_max)
   373 	{
   374 		x=x_max;
   375 	}
   376 	if(y>y_max)
   377 	{
   378 		y=y_max;
   379 	}
   380 
   381     if (!mouse || mouse->flush_motion) {
   382         return 0;
   383     }
   384 
   385 	/*if the mouse is out of proximity we don't to want to have any motion from it*/
   386     if(mouse->proximity==SDL_FALSE)
   387     {
   388         last_x=x;
   389         last_y=y;
   390         return 0;
   391     }
   392 
   393 	/*the relative motion is calculated regarding the system cursor last position*/
   394 
   395     xrel = x - last_x;
   396     yrel = y - last_y;
   397 
   398     /* Drop events that don't change state */
   399     if (!xrel && !yrel) {
   400 #if 0
   401         printf("Mouse event didn't change state - dropped!\n");
   402 #endif
   403         return 0;
   404     }
   405 
   406     /* Update internal mouse coordinates */
   407     if (mouse->relative_mode==SDL_FALSE) {
   408         mouse->x = x;
   409         mouse->y = y;
   410     }
   411     else
   412     {
   413         if(mouse->x+xrel>x_max)
   414         {
   415             mouse->x=x_max;
   416         }
   417         else if(mouse->x+xrel<0)
   418         {
   419             mouse->x=0;
   420         }
   421         else
   422         {
   423             mouse->x+=xrel;
   424         }
   425         if(mouse->y+yrel>y_max)
   426         {
   427             mouse->y=y_max;
   428         }
   429         else if(mouse->y+yrel<0)
   430         {
   431             mouse->y=0;
   432         }
   433         else
   434         {
   435             mouse->y+=yrel;
   436         }
   437     }
   438     mouse->xdelta += xrel;
   439     mouse->ydelta += yrel;
   440     mouse->pressure=z;
   441 
   442     /* Move the mouse cursor, if needed */
   443     if (mouse->cursor_shown && !mouse->relative_mode &&
   444         mouse->MoveCursor && mouse->cur_cursor) {
   445         mouse->MoveCursor(mouse->cur_cursor);
   446     }
   447 
   448     /* Post the event, if desired */
   449     posted = 0;
   450     if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE && SDL_mice[index]->proximity==SDL_TRUE) {
   451         SDL_Event event;
   452         event.motion.type = SDL_MOUSEMOTION;
   453 		event.motion.which = (Uint8) index;
   454         event.motion.state = mouse->buttonstate;
   455         event.motion.x = mouse->x;
   456         event.motion.y = mouse->y;
   457         event.motion.pressure= mouse->pressure;
   458         event.motion.xrel = xrel;
   459         event.motion.yrel = yrel;
   460         event.motion.windowID = mouse->focus;
   461         event.motion.pressure_max=mouse->pressure_max;
   462         event.motion.pressure_min=mouse->pressure_min;
   463         posted = (SDL_PushEvent(&event) > 0);
   464     }
   465     last_x=x;
   466     last_y=y;
   467     return posted;
   468 }
   469 
   470 int
   471 SDL_SendMouseButton(int id, Uint8 state, Uint8 button)
   472 {
   473     int index=SDL_GetIndexById(id);
   474     SDL_Mouse *mouse = SDL_GetMouse(index);
   475     int posted;
   476     Uint8 type;
   477 
   478     if (!mouse) {
   479         return 0;
   480     }
   481 
   482     /* Figure out which event to perform */
   483     switch (state) {
   484     case SDL_PRESSED:
   485         if (mouse->buttonstate & SDL_BUTTON(button)) {
   486             /* Ignore this event, no state change */
   487             return 0;
   488         }
   489         type = SDL_MOUSEBUTTONDOWN;
   490         mouse->buttonstate |= SDL_BUTTON(button);
   491         break;
   492     case SDL_RELEASED:
   493         //if (!(mouse->buttonstate & SDL_BUTTON(button))) {
   494         //    /* Ignore this event, no state change */
   495         //    return 0;
   496         //}*/
   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 /* vi: set ts=4 sw=4 expandtab: */
   800