src/video/uikit/SDL_uikitview.m
changeset 6079 d7135957b216
parent 6054 effedf4d675c
child 6138 4c64952a58fb
equal deleted inserted replaced
6078:718b49ec039e 6079:d7135957b216
     1 /*
     1  /*
     2   Simple DirectMedia Layer
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     3   Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     4 
     4 
     5   This software is provided 'as-is', without any express or implied
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     6   warranty.  In no event will the authors be held liable for any damages
    58 
    58 
    59     //touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    59     //touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    60     //EventTouchData* data = (EventTouchData*)(touch.driverdata);
    60     //EventTouchData* data = (EventTouchData*)(touch.driverdata);
    61 
    61 
    62     touch.x_min = 0;
    62     touch.x_min = 0;
    63     touch.x_max = frame.size.width;
    63     touch.x_max = 1;
    64     touch.native_xres = touch.x_max - touch.x_min;
    64     touch.native_xres = touch.x_max - touch.x_min;
    65     touch.y_min = 0;
    65     touch.y_min = 0;
    66     touch.y_max = frame.size.height;
    66     touch.y_max = 1;
    67     touch.native_yres = touch.y_max - touch.y_min;
    67     touch.native_yres = touch.y_max - touch.y_min;
    68     touch.pressure_min = 0;
    68     touch.pressure_min = 0;
    69     touch.pressure_max = 1;
    69     touch.pressure_max = 1;
    70     touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    70     touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    71 
    71 
    75 
    75 
    76     return self;
    76     return self;
    77 
    77 
    78 }
    78 }
    79 
    79 
       
    80 - (CGPoint)touchLocation:(UITouch *)touch
       
    81 {
       
    82     CGPoint point = [touch locationInView: self];
       
    83     CGRect frame = [self frame];
       
    84 
       
    85     frame = CGRectApplyAffineTransform(frame, [self transform]);
       
    86     point.x /= frame.size.width;
       
    87     point.y /= frame.size.height;
       
    88     return point;
       
    89 }
       
    90 
    80 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    91 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    81 {
    92 {
    82     NSEnumerator *enumerator = [touches objectEnumerator];
    93     NSEnumerator *enumerator = [touches objectEnumerator];
    83     UITouch *touch = (UITouch*)[enumerator nextObject];
    94     UITouch *touch = (UITouch*)[enumerator nextObject];
    84 
    95 
    92         SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
   103         SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
    93     }
   104     }
    94 
   105 
    95 #ifdef FIXED_MULTITOUCH
   106 #ifdef FIXED_MULTITOUCH
    96     while(touch) {
   107     while(touch) {
    97         CGPoint locationInView = [touch locationInView: self];
   108         CGPoint locationInView = [self touchLocation:touch];
    98 
   109 
    99 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   110 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   100         //FIXME: TODO: Using touch as the fingerId is potentially dangerous
   111         //FIXME: TODO: Using touch as the fingerId is potentially dangerous
   101         //It is also much more efficient than storing the UITouch pointer
   112         //It is also much more efficient than storing the UITouch pointer
   102         //and comparing it to the incoming event.
   113         //and comparing it to the incoming event.
   131         SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
   142         SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
   132     }
   143     }
   133 
   144 
   134 #ifdef FIXED_MULTITOUCH
   145 #ifdef FIXED_MULTITOUCH
   135     while(touch) {
   146     while(touch) {
   136         CGPoint locationInView = [touch locationInView: self];
   147         CGPoint locationInView = [self touchLocation:touch];
   137 
   148 
   138 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   149 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   139         SDL_SendFingerDown(touchId, (long)touch,
   150         SDL_SendFingerDown(touchId, (long)touch,
   140                            SDL_FALSE, locationInView.x, locationInView.y,
   151                            SDL_FALSE, locationInView.x, locationInView.y,
   141                            1);
   152                            1);
   179         SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   190         SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   180     }
   191     }
   181 
   192 
   182 #ifdef FIXED_MULTITOUCH
   193 #ifdef FIXED_MULTITOUCH
   183     while(touch) {
   194     while(touch) {
   184         CGPoint locationInView = [touch locationInView: self];
   195         CGPoint locationInView = [self touchLocation:touch];
   185 
   196 
   186 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   197 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   187         SDL_SendTouchMotion(touchId, (long)touch,
   198         SDL_SendTouchMotion(touchId, (long)touch,
   188                             SDL_FALSE, locationInView.x, locationInView.y,
   199                             SDL_FALSE, locationInView.x, locationInView.y,
   189                             1);
   200                             1);