1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #if !defined(__has_feature) || !__has_feature(objc_arc) 6 #error "This file requires ARC support." 7 #endif 8 9 #import "Utility.h" 10 11 @implementation Utility 12 13 + (BOOL)isPad { 14 return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); 15 } 16 17 + (BOOL)isInLandscapeMode { 18 UIInterfaceOrientation orientation = 19 [UIApplication sharedApplication].statusBarOrientation; 20 21 if ((orientation == UIInterfaceOrientationLandscapeLeft) || 22 (orientation == UIInterfaceOrientationLandscapeRight)) { 23 return YES; 24 } 25 return NO; 26 } 27 28 + (CGSize)getOrientatedSize:(CGSize)size 29 shouldWidthBeLongestSide:(BOOL)shouldWidthBeLongestSide { 30 if (shouldWidthBeLongestSide && (size.height > size.width)) { 31 return CGSizeMake(size.height, size.width); 32 } 33 return size; 34 } 35 36 + (void)showAlert:(NSString*)title message:(NSString*)message { 37 UIAlertView* alert; 38 alert = [[UIAlertView alloc] init]; 39 alert.title = title; 40 alert.message = message; 41 alert.delegate = nil; 42 [alert addButtonWithTitle:@"OK"]; 43 [alert show]; 44 } 45 46 + (NSString*)appVersionNumberDisplayString { 47 NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary]; 48 49 NSString* majorVersion = 50 [infoDictionary objectForKey:@"CFBundleShortVersionString"]; 51 NSString* minorVersion = [infoDictionary objectForKey:@"CFBundleVersion"]; 52 53 return [NSString 54 stringWithFormat:@"Version %@ (%@)", majorVersion, minorVersion]; 55 } 56 57 + (void)bindTextureForIOS:(GLuint)glName { 58 glBindTexture(GL_TEXTURE_2D, glName); 59 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 61 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 63 } 64 65 + (void)logGLErrorCode:(NSString*)funcName { 66 GLenum errorCode = 1; 67 68 while (errorCode != 0) { 69 errorCode = glGetError(); // I don't know why this is returning an error 70 // on the first call to this function, but if I 71 // don't read it, then stuff doesn't work... 72 #if DEBUG 73 if (errorCode != 0) { 74 NSLog(@"glerror in %@: %X", funcName, errorCode); 75 } 76 #endif // DEBUG 77 } 78 } 79 80 + (void)drawSubRectToGLFromRectOfSize:(const webrtc::DesktopSize&)rectSize 81 subRect:(const webrtc::DesktopRect&)subRect 82 data:(const uint8_t*)data { 83 DCHECK(rectSize.width() >= subRect.width()); 84 DCHECK(rectSize.height() >= subRect.height()); 85 DCHECK(rectSize.width() >= (subRect.left() + subRect.width())); 86 DCHECK(rectSize.height() >= (subRect.top() + subRect.height())); 87 DCHECK(data); 88 89 glTexSubImage2D(GL_TEXTURE_2D, 90 0, 91 subRect.left(), 92 subRect.top(), 93 subRect.width(), 94 subRect.height(), 95 GL_RGBA, 96 GL_UNSIGNED_BYTE, 97 data); 98 } 99 100 + (void)moveMouse:(HostProxy*)controller 101 at:(const webrtc::DesktopVector&)point { 102 [controller mouseAction:point 103 wheelDelta:webrtc::DesktopVector(0, 0) 104 whichButton:0 105 buttonDown:NO]; 106 } 107 108 + (void)leftClickOn:(HostProxy*)controller 109 at:(const webrtc::DesktopVector&)point { 110 [controller mouseAction:point 111 wheelDelta:webrtc::DesktopVector(0, 0) 112 whichButton:1 113 buttonDown:YES]; 114 [controller mouseAction:point 115 wheelDelta:webrtc::DesktopVector(0, 0) 116 whichButton:1 117 buttonDown:NO]; 118 } 119 120 + (void)middleClickOn:(HostProxy*)controller 121 at:(const webrtc::DesktopVector&)point { 122 [controller mouseAction:point 123 wheelDelta:webrtc::DesktopVector(0, 0) 124 whichButton:2 125 buttonDown:YES]; 126 [controller mouseAction:point 127 wheelDelta:webrtc::DesktopVector(0, 0) 128 whichButton:2 129 buttonDown:NO]; 130 } 131 132 + (void)rightClickOn:(HostProxy*)controller 133 at:(const webrtc::DesktopVector&)point { 134 [controller mouseAction:point 135 wheelDelta:webrtc::DesktopVector(0, 0) 136 whichButton:3 137 buttonDown:YES]; 138 [controller mouseAction:point 139 wheelDelta:webrtc::DesktopVector(0, 0) 140 whichButton:3 141 buttonDown:NO]; 142 } 143 144 + (void)mouseScroll:(HostProxy*)controller 145 at:(const webrtc::DesktopVector&)point 146 delta:(const webrtc::DesktopVector&)delta { 147 [controller mouseAction:point wheelDelta:delta whichButton:0 buttonDown:NO]; 148 } 149 150 @end