RSS

(root)/iphone/tappity : 62 : source/TappityServer.m

« back to all changes in this revision

Viewing changes to source/TappityServer.m

Dömötör Gulyás
2010-01-28 20:58:38
Revision ID: dognotdog@gmail.com-20100128195838-a4lz0bri0lflx6qm
adds rescaling touches for iphone->ipad events

Show diffs side-by-side

added added

removed removed

352
352
                eventPlaybackBusy = NO;
353
353
}
354
354
 
 
355
- (NSDictionary*) rescaleTouches: (NSDictionary*) event
 
356
{
 
357
        
 
358
        /*
 
359
                in "Data"
 
360
                +33             num touches
 
361
                +48             x-loc 1st touch
 
362
                +52             y-loc 1st touch
 
363
                +72             x-loc 2nd touch
 
364
                +76             y-loc 2nd touch
 
365
                
 
366
                presumably touches at offsets +24 per touch
 
367
        */
 
368
 
 
369
        
 
370
        long type = [[event objectForKey: @"Type"] integerValue];
 
371
                
 
372
        if (type == 3001) // touch event
 
373
        {
 
374
                NSMutableDictionary* mdict = [event mutableCopy];
 
375
 
 
376
                CGRect targetScreen = [[UIScreen mainScreen] bounds];
 
377
                CGRect sourceScreen = CGRectFromString([mdict objectForKey: @"UIScreen bounds"]);
 
378
                
 
379
                float xoff0 = sourceScreen.origin.x;
 
380
                float xoff1 = targetScreen.origin.x;
 
381
                float yoff0 = sourceScreen.origin.y;
 
382
                float yoff1 = targetScreen.origin.y;
 
383
                float xs0 = sourceScreen.size.width;
 
384
                float xs1 = targetScreen.size.width;
 
385
                float ys0 = sourceScreen.size.height;
 
386
                float ys1 = targetScreen.size.height;
 
387
                
 
388
                CGPoint wloc = CGPointMake([[[mdict objectForKey: @"WindowLocation"] objectForKey: @"X"] floatValue], [[[mdict objectForKey: @"WindowLocation"] objectForKey: @"Y"] floatValue]);
 
389
                CGPoint loc = CGPointMake([[[mdict objectForKey: @"Location"] objectForKey: @"X"] floatValue], [[[mdict objectForKey: @"Location"] objectForKey: @"Y"] floatValue]);
 
390
                
 
391
                wloc.x = (wloc.x - xoff0)*(xs1/xs0) + xoff1;
 
392
                wloc.y = (wloc.y - yoff0)*(ys1/ys0) + yoff1;
 
393
                loc.x = (loc.x - xoff0)*(xs1/xs0) + xoff1;
 
394
                loc.y = (loc.y - yoff0)*(ys1/ys0) + yoff1;
 
395
                
 
396
                [mdict setObject: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithFloat: wloc.x], @"X", [NSNumber numberWithFloat: wloc.y], @"Y", nil] forKey: @"WindowLocation"];
 
397
                [mdict setObject: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithFloat: loc.x], @"X", [NSNumber numberWithFloat: loc.y], @"Y", nil] forKey: @"Location"];
 
398
                
 
399
                NSMutableData* data = [[event objectForKey: @"Data"] mutableCopy];
 
400
                void* bytes = [data mutableBytes];
 
401
                
 
402
                uint8_t ntouches = ((uint8_t*)bytes)[33];
 
403
                
 
404
                for (size_t i = 0; i < ntouches; ++i)
 
405
                {
 
406
                        size_t ii = 48 + i*24;
 
407
                        float x = *((float*)(bytes + ii));
 
408
                        float y = *((float*)(bytes + ii+4));
 
409
                        
 
410
                        x = (x - xoff0)*(xs1/xs0) + xoff1;
 
411
                        y = (y - yoff0)*(ys1/ys0) + yoff1;
 
412
                        
 
413
                        *((float*)(bytes + ii)) = x;
 
414
                        *((float*)(bytes + ii+4)) = y;
 
415
 
 
416
                }
 
417
                
 
418
                [mdict setObject: data forKey: @"Data"];
 
419
                
 
420
                [mdict removeObjectForKey: @"UIScreen bounds"];
 
421
                event = mdict;
 
422
        }
 
423
        
 
424
        return event;
 
425
 
 
426
}
 
427
 
355
428
- (void) dataReceived: (NSDictionary*) dataDict
356
429
{
357
430
        uint32_t messageId = [[dataDict objectForKey: SocketMessageIdKey] intValue];
406
479
                        if (!queuedEvents)
407
480
                                queuedEvents = [[NSMutableArray alloc] init];
408
481
 
 
482
                        eventDict = [self rescaleTouches: eventDict];
 
483
 
409
484
                        [queuedEvents addObject: eventDict];
410
485
                        
411
486
                        if (!eventPlaybackBusy)

Loggerhead 1.17 is a web-based interface for Bazaar branches