src/events/SDL_mouse.c
author Szymon Wilczek
Tue, 05 Aug 2008 14:10:11 +0000
branchgsoc2008_manymouse
changeset 3774 8b5b67000dc0
parent 3771 8cc36a399a12
child 3776 a9c2a7071874
permissions -rw-r--r--
Cursor support added
     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()
   178 {
   179     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   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(SDL_bool enabled, int index)
   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()
   228 {
   229     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   230 
   231     if (!mouse) {
   232         return SDL_FALSE;
   233     }
   234     return mouse->relative_mode;
   235 }
   236 
   237 Uint8
   238 SDL_GetMouseState(int *x, int *y)
   239 {
   240     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   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 *x, int *y)
   263 {
   264     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   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         //if (!(mouse->buttonstate & SDL_BUTTON(button))) {
   498         //    /* Ignore this event, no state change */
   499         //    return 0;
   500         //}*/
   501         type = SDL_MOUSEBUTTONUP;
   502         mouse->buttonstate &= ~SDL_BUTTON(button);
   503         break;
   504     default:
   505         /* Invalid state -- bail */
   506         return 0;
   507     }
   508 
   509     /* Post the event, if desired */
   510     posted = 0;
   511     if (SDL_ProcessEvents[type] == SDL_ENABLE) {
   512         SDL_Event event;
   513         event.type = type;
   514         event.button.which = (Uint8) index;
   515         event.button.state = state;
   516         event.button.button = button;
   517         event.button.x = mouse->x;
   518         event.button.y = mouse->y;
   519         event.button.windowID = mouse->focus;
   520         posted = (SDL_PushEvent(&event) > 0);
   521     }
   522     return posted;
   523 }
   524 
   525 int
   526 SDL_SendMouseWheel(int index, int x, int y)
   527 {
   528     SDL_Mouse *mouse = SDL_GetMouse(index);
   529     int posted;
   530 
   531     if (!mouse || (!x && !y)) {
   532         return 0;
   533     }
   534 
   535     /* Post the event, if desired */
   536     posted = 0;
   537     if (SDL_ProcessEvents[SDL_MOUSEWHEEL] == SDL_ENABLE) {
   538         SDL_Event event;
   539         event.type = SDL_MOUSEWHEEL;
   540         event.wheel.which = (Uint8) index;
   541         event.wheel.x = x;
   542         event.wheel.y = y;
   543         event.wheel.windowID = mouse->focus;
   544         posted = (SDL_PushEvent(&event) > 0);
   545     }
   546     return posted;
   547 }
   548 
   549 void
   550 SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
   551 {
   552     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   553 
   554     if (!mouse) {
   555         return;
   556     }
   557 
   558     if (mouse->WarpMouse) {
   559         mouse->WarpMouse(mouse, windowID, x, y);
   560     } else {
   561         SDL_SetMouseFocus(SDL_current_mouse, windowID);
   562         SDL_SendMouseMotion(SDL_current_mouse, 0, x, y,0);
   563     }
   564 }
   565 
   566 SDL_Cursor *
   567 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
   568                  int w, int h, int hot_x, int hot_y)
   569 {
   570     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   571     SDL_Surface *surface;
   572     SDL_Cursor *cursor;
   573     int x, y;
   574     Uint32 *pixel;
   575     Uint8 datab, maskb;
   576     const Uint32 black = 0xFF000000;
   577     const Uint32 white = 0xFFFFFFFF;
   578     const Uint32 transparent = 0x00000000;
   579 
   580     if (!mouse) {
   581         SDL_SetError("No mice are initialized");
   582         return NULL;
   583     }
   584 
   585     if (!mouse->CreateCursor) {
   586         SDL_SetError("Current mouse doesn't have cursor support");
   587         return NULL;
   588     }
   589 
   590     /* Sanity check the hot spot */
   591     if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) {
   592         SDL_SetError("Cursor hot spot doesn't lie within cursor");
   593         return NULL;
   594     }
   595 
   596     /* Make sure the width is a multiple of 8 */
   597     w = ((w + 7) & ~7);
   598 
   599     /* Create the surface from a bitmap*/
   600     surface =
   601         SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
   602                              0xFF000000);
   603     if (!surface) {
   604         return NULL;
   605     }
   606     for (y = 0; y < h; ++y) {
   607         pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
   608         for (x = 0; x < w; ++x) {
   609             if ((x % 8) == 0) {
   610                 datab = *data++;
   611                 maskb = *mask++;
   612             }
   613             if (maskb & 0x80) {
   614                 *pixel++ = (datab & 0x80) ? black : white;
   615             } else {
   616                 *pixel++ = (datab & 0x80) ? black : transparent;
   617             }
   618             datab <<= 1;
   619             maskb <<= 1;
   620         }
   621     }
   622 
   623     cursor = mouse->CreateCursor(surface, hot_x, hot_y);
   624     if (cursor) {
   625         cursor->mouse = mouse;
   626         cursor->next = mouse->cursors;
   627         mouse->cursors = cursor;
   628     }
   629 
   630     SDL_FreeSurface(surface);
   631 
   632     return cursor;
   633 }
   634 
   635 /* SDL_SetCursor(NULL) can be used to force the cursor redraw,
   636    if this is desired for any reason.  This is used when setting
   637    the video mode and when the SDL window gains the mouse focus.
   638  */
   639 void
   640 SDL_SetCursor(SDL_Cursor * cursor)
   641 {
   642     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   643 
   644     if (!mouse) {
   645         SDL_SetError("No mice are initialized");
   646         return;
   647     }
   648 
   649     /* Set the new cursor */
   650     if (cursor) {
   651         /* Make sure the cursor is still valid for this mouse */
   652         SDL_Cursor *found;
   653         for (found = mouse->cursors; found; found = found->next) {
   654             if (found == cursor) {
   655                 break;
   656             }
   657         }
   658         if (!found) {
   659             SDL_SetError("Cursor not associated with the current mouse");
   660             return;
   661         }
   662         mouse->cur_cursor = cursor;
   663     } else {
   664         cursor = mouse->cur_cursor;
   665     }
   666 
   667     if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
   668         if (mouse->ShowCursor) {
   669             mouse->ShowCursor(cursor);
   670         }
   671     } else {
   672         if (mouse->ShowCursor) {
   673             mouse->ShowCursor(NULL);
   674         }
   675     }
   676 }
   677 
   678 SDL_Cursor *
   679 SDL_GetCursor(void)
   680 {
   681     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   682 
   683     if (!mouse) {
   684         return NULL;
   685     }
   686     return mouse->cur_cursor;
   687 }
   688 
   689 void
   690 SDL_FreeCursor(SDL_Cursor * cursor)
   691 {
   692     SDL_Mouse *mouse;
   693     SDL_Cursor *curr, *prev;
   694 
   695     if (!cursor) {
   696         return;
   697     }
   698     mouse = cursor->mouse;
   699 
   700     if (cursor == mouse->def_cursor) {
   701         return;
   702     }
   703     if (cursor == mouse->cur_cursor) {
   704         SDL_SetCursor(mouse->def_cursor);
   705     }
   706 
   707     for (prev = NULL, curr = mouse->cursors; curr;
   708          prev = curr, curr = curr->next) {
   709         if (curr == cursor) {
   710             if (prev) {
   711                 prev->next = curr->next;
   712             } else {
   713                 mouse->cursors = curr->next;
   714             }
   715 
   716             if (mouse->FreeCursor) {
   717                 mouse->FreeCursor(curr);
   718             }
   719             return;
   720         }
   721     }
   722 }
   723 
   724 int
   725 SDL_ShowCursor(int toggle)
   726 {
   727     SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   728     SDL_bool shown;
   729 
   730     if (!mouse) {
   731         return 0;
   732     }
   733 
   734     shown = mouse->cursor_shown;
   735     if (toggle >= 0) {
   736         if (toggle) {
   737             mouse->cursor_shown = SDL_TRUE;
   738         } else {
   739             mouse->cursor_shown = SDL_FALSE;
   740         }
   741         if (mouse->cursor_shown != shown) {
   742             SDL_SetCursor(NULL);
   743         }
   744     }
   745     return shown;
   746 }
   747 
   748 int SDL_SetIndexId(int id, int index)
   749 {
   750     if(id>SDL_highestId)
   751     {
   752         int *indexes;
   753         indexes =
   754             (int*) SDL_realloc(SDL_IdIndex,
   755                                        (id + 1) * sizeof(int));
   756         if (!indexes) {
   757             SDL_OutOfMemory();
   758             return -1;
   759         }
   760         SDL_IdIndex=indexes;
   761         SDL_IdIndex[id]=index;
   762         SDL_highestId=id;
   763     }
   764     else
   765     {
   766         SDL_IdIndex[id]=index;
   767     }
   768 	return 1;
   769 }
   770 
   771 int SDL_GetIndexById(int id)
   772 {
   773     if(id>SDL_highestId)
   774     {
   775         return -1;
   776     }
   777     else
   778     {
   779         return SDL_IdIndex[id];
   780     }
   781 }
   782 
   783 int SDL_GetNumOfMice(void)
   784 {
   785     return SDL_num_mice;
   786 }
   787 
   788 char* SDL_GetMouseName(int index)
   789 {
   790     SDL_Mouse* mouse = SDL_GetMouse(index);
   791     if(!mouse)
   792     {
   793         return NULL;
   794     }
   795     return mouse->name;
   796 }
   797 
   798 void SDL_UpdateCoordinates(int x, int y)
   799 {
   800     x_max=x;
   801     y_max=y;
   802 }
   803 
   804 void SDL_ChangeEnd(int id, int end)
   805 {
   806 	int index=SDL_GetIndexById(id);
   807 	SDL_mice[index]->current_end=end;
   808 }
   809 
   810 int SDL_GetCursorsNumber(int index)
   811 {
   812 	if(index>=SDL_num_mice)
   813 	{
   814 		return -1;
   815 	}
   816 	if(SDL_mice[index]==NULL)
   817 	{
   818 		return -1;
   819 	}
   820 	return SDL_mice[index]->total_ends;
   821 }
   822 /* vi: set ts=4 sw=4 expandtab: */
   823