src/video/cocoa/SDL_cocoawindow.m
changeset 1959 25d6537feea4
parent 1958 5fc6fb0fb605
child 1962 c92e5f3e68d9
equal deleted inserted replaced
1958:5fc6fb0fb605 1959:25d6537feea4
   146 }
   146 }
   147 
   147 
   148 - (void)mouseDown:(NSEvent *)theEvent
   148 - (void)mouseDown:(NSEvent *)theEvent
   149 {
   149 {
   150     int index;
   150     int index;
       
   151     int button;
   151 
   152 
   152     index = _data->videodata->mouse;
   153     index = _data->videodata->mouse;
   153     SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_LEFT);
   154     switch ([theEvent buttonNumber]) {
       
   155     case 0:
       
   156         button = SDL_BUTTON_LEFT;
       
   157         break;
       
   158     case 1:
       
   159         button = SDL_BUTTON_RIGHT;
       
   160         break;
       
   161     case 2:
       
   162         button = SDL_BUTTON_MIDDLE;
       
   163         break;
       
   164     default:
       
   165         button = [theEvent buttonNumber];
       
   166         break;
       
   167     }
       
   168     SDL_SendMouseButton(index, SDL_PRESSED, button);
   154 }
   169 }
   155 
   170 
   156 - (void)rightMouseDown:(NSEvent *)theEvent
   171 - (void)rightMouseDown:(NSEvent *)theEvent
   157 {
   172 {
       
   173     [self mouseDown:theEvent];
       
   174 }
       
   175 
       
   176 - (void)otherMouseDown:(NSEvent *)theEvent
       
   177 {
       
   178     [self mouseDown:theEvent];
       
   179 }
       
   180 
       
   181 - (void)mouseUp:(NSEvent *)theEvent
       
   182 {
   158     int index;
   183     int index;
       
   184     int button;
   159 
   185 
   160     index = _data->videodata->mouse;
   186     index = _data->videodata->mouse;
   161     SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_RIGHT);
   187     switch ([theEvent buttonNumber]) {
   162 }
   188     case 0:
   163 
   189         button = SDL_BUTTON_LEFT;
   164 - (void)otherMouseDown:(NSEvent *)theEvent
   190         break;
   165 {
   191     case 1:
   166     int index;
   192         button = SDL_BUTTON_RIGHT;
   167 
   193         break;
   168     index = _data->videodata->mouse;
   194     case 2:
   169     SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_MIDDLE);
   195         button = SDL_BUTTON_MIDDLE;
   170 }
   196         break;
   171 
   197     default:
   172 - (void)mouseUp:(NSEvent *)theEvent
   198         button = [theEvent buttonNumber];
   173 {
   199         break;
   174     int index;
   200     }
   175 
   201     SDL_SendMouseButton(index, SDL_RELEASED, button);
   176     index = _data->videodata->mouse;
       
   177     SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_LEFT);
       
   178 }
   202 }
   179 
   203 
   180 - (void)rightMouseUp:(NSEvent *)theEvent
   204 - (void)rightMouseUp:(NSEvent *)theEvent
   181 {
   205 {
   182     int index;
   206     [self mouseUp:theEvent];
   183 
       
   184     index = _data->videodata->mouse;
       
   185     SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_RIGHT);
       
   186 }
   207 }
   187 
   208 
   188 - (void)otherMouseUp:(NSEvent *)theEvent
   209 - (void)otherMouseUp:(NSEvent *)theEvent
   189 {
   210 {
   190     int index;
   211     [self mouseUp:theEvent];
   191 
       
   192     index = _data->videodata->mouse;
       
   193     SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_MIDDLE);
       
   194 }
   212 }
   195 
   213 
   196 - (void)mouseMoved:(NSEvent *)theEvent
   214 - (void)mouseMoved:(NSEvent *)theEvent
   197 {
   215 {
   198     SDL_Window *window = SDL_GetWindowFromID(_data->windowID);
   216     SDL_Window *window = SDL_GetWindowFromID(_data->windowID);
   236     SDL_SendMouseWheel(index, (int)([theEvent deltaY]+0.9f));
   254     SDL_SendMouseWheel(index, (int)([theEvent deltaY]+0.9f));
   237 }
   255 }
   238 
   256 
   239 - (void)keyDown:(NSEvent *)theEvent
   257 - (void)keyDown:(NSEvent *)theEvent
   240 {
   258 {
       
   259     int index;
       
   260 
       
   261     index = _data->videodata->keyboard;
   241 fprintf(stderr, "keyDown\n");
   262 fprintf(stderr, "keyDown\n");
       
   263     const char *text = [[theEvent characters] UTF8String];
       
   264     if(text && *text) {
       
   265         SDL_SendKeyboardText(index, text);
       
   266     }
   242 }
   267 }
   243 
   268 
   244 - (void)keyUp:(NSEvent *)theEvent
   269 - (void)keyUp:(NSEvent *)theEvent
   245 {
   270 {
       
   271     int index;
       
   272 
       
   273     index = _data->videodata->keyboard;
   246 fprintf(stderr, "keyUp\n");
   274 fprintf(stderr, "keyUp\n");
   247 }
   275 }
   248 
   276 
   249 @end
   277 @end
   250 
   278