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