T2DView.mm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #import "platformiOS/T2DView.h"
  23. //#import <QuartzCore/QuartzCore.h>
  24. //#include "platformiPhone/iPhoneEvents.h"
  25. #import "platformiOS/platformiOS.h"
  26. #import "platformiOS/platformGL.h"
  27. #import "platformiOS/iOSOGLVideo.h"
  28. #include "console/console.h"
  29. #include "math/mPoint.h"
  30. #include "platform/event.h"
  31. #include "game/gameInterface.h"
  32. #include "console/consoleInternal.h"
  33. #include "console/ast.h"
  34. #include "io/fileStream.h"
  35. #include "platformiOS/iOSUtil.h"
  36. #include "platformiOS/iOSEvents.h"
  37. #include "graphics/dgl.h"
  38. #include "debug/profiler.h"
  39. #define USE_DEPTH_BUFFER 0
  40. extern bool createMouseMoveEvent(S32 i, S32 x, S32 y, S32 lastX, S32 lastY);
  41. extern bool createMouseDownEvent(S32 touchNumber, S32 x, S32 y, U32 numTouches);
  42. extern bool createMouseUpEvent(S32 touchNumber, S32 x, S32 y, S32 lastX, S32 lastY, U32 numTouches); //EFM
  43. extern void createMouseTapEvent( S32 nbrTaps, S32 x, S32 y );
  44. bool retinaEnabled;
  45. void ConvertToRetina(CGPoint *p)
  46. {
  47. CGFloat screenScale = [[UIScreen mainScreen] scale];
  48. p->x *= screenScale;
  49. p->y *= screenScale;
  50. }
  51. @implementation T2DView
  52. @synthesize context = _context;
  53. @synthesize currentAngle;
  54. @synthesize isLayedOut;
  55. -(void)swapBuffers {
  56. if( self.isLayedOut == true ) {
  57. [self.context presentRenderbuffer:GL_RENDERBUFFER_OES];
  58. }
  59. }
  60. - (void)layoutSubviews {
  61. }
  62. -(void)rotateByAngle:(CGFloat)angle {
  63. CGAffineTransform transform = self.transform;
  64. transform = CGAffineTransformRotate(transform, angle);
  65. self.transform = transform;
  66. }
  67. -(void)rotateToAngle:(CGFloat)angle {
  68. CGFloat rotateAmount = (angle - currentAngle);//need to make this work better
  69. if( rotateAmount == 0 ) {
  70. return;
  71. }
  72. currentAngle = angle;
  73. [self rotateByAngle:rotateAmount];
  74. }
  75. -(void)centerOnPoint:(CGPoint)point {
  76. self.center = point;
  77. }
  78. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  79. {
  80. NSUInteger touchCount = 0;
  81. // Enumerates through all touch objects
  82. for (UITouch *touch in touches)
  83. {
  84. CGPoint point = [touch locationInView:self];
  85. if (retinaEnabled)
  86. {
  87. ConvertToRetina(&point);
  88. }
  89. S32 orientation = _iOSGameGetOrientation();
  90. if (UIDeviceOrientationIsPortrait((UIDeviceOrientation)orientation))
  91. {
  92. point.y -= _iOSGetPortraitTouchoffset();
  93. }
  94. int numTouches = [touch tapCount];
  95. createMouseDownEvent(touchCount, point.x, point.y, numTouches);
  96. touchCount++;
  97. }
  98. }
  99. extern Vector<Event *> TouchMoveEvents;
  100. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  101. {
  102. NSUInteger touchCount = 0;
  103. // Enumerates through all touch objects
  104. for (UITouch *touch in touches)
  105. {
  106. CGPoint point = [touch locationInView:self];
  107. CGPoint prevPoint = [touch previousLocationInView:self]; //EFM
  108. if (retinaEnabled)
  109. {
  110. ConvertToRetina(&point);
  111. ConvertToRetina(&prevPoint);
  112. }
  113. S32 orientation = _iOSGameGetOrientation();
  114. if (UIDeviceOrientationIsPortrait((UIDeviceOrientation)orientation))
  115. {
  116. point.y -= _iOSGetPortraitTouchoffset();
  117. prevPoint.y -= _iOSGetPortraitTouchoffset();
  118. }
  119. createMouseMoveEvent(touchCount, point.x, point.y, prevPoint.x, prevPoint.y);
  120. touchCount++;
  121. }
  122. }
  123. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  124. {
  125. NSUInteger touchCount = 0;
  126. // Enumerates through all touch objects
  127. for (UITouch *touch in touches)
  128. {
  129. CGPoint point = [touch locationInView:self];
  130. CGPoint prevPoint = [touch previousLocationInView:self]; //EFM
  131. if (retinaEnabled)
  132. {
  133. ConvertToRetina(&point);
  134. ConvertToRetina(&prevPoint);
  135. }
  136. S32 orientation = _iOSGameGetOrientation();
  137. if (UIDeviceOrientationIsPortrait((UIDeviceOrientation)orientation))
  138. {
  139. point.y -= _iOSGetPortraitTouchoffset();
  140. prevPoint.y -= _iOSGetPortraitTouchoffset();
  141. }
  142. int tc = [touch tapCount];
  143. createMouseUpEvent(touchCount, point.x, point.y, prevPoint.x, prevPoint.y, tc);
  144. touchCount++;
  145. //Luma: Tap support
  146. if (tc > 0)
  147. {
  148. // this was a tap, so create a tap event
  149. createMouseTapEvent(tc, (int) point.x, (int) point.y);
  150. }
  151. }
  152. }
  153. - (void)touchesChangedWithEvent:(UIEvent *)event
  154. {
  155. Con::printf("Touches Changed with Event");
  156. }
  157. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
  158. {
  159. [self touchesEnded:touches withEvent:event];
  160. }
  161. bool gScreenAutoRotate = false;
  162. int currentRotate = 0;
  163. #define ROTATE_LEFT 0
  164. #define ROTATE_RIGHT 1
  165. #define ROTATE_UP 2
  166. @end