T2DView.mm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. p->x *= 2;
  48. p->y *= 2;
  49. }
  50. @implementation T2DView
  51. @synthesize context = _context;
  52. @synthesize currentAngle;
  53. @synthesize isLayedOut;
  54. -(void)swapBuffers {
  55. if( self.isLayedOut == true ) {
  56. [self.context presentRenderbuffer:GL_RENDERBUFFER_OES];
  57. }
  58. }
  59. - (void)layoutSubviews {
  60. }
  61. -(void)rotateByAngle:(CGFloat)angle {
  62. CGAffineTransform transform = self.transform;
  63. transform = CGAffineTransformRotate(transform, angle);
  64. self.transform = transform;
  65. }
  66. -(void)rotateToAngle:(CGFloat)angle {
  67. CGFloat rotateAmount = (angle - currentAngle);//need to make this work better
  68. if( rotateAmount == 0 ) {
  69. return;
  70. }
  71. currentAngle = angle;
  72. [self rotateByAngle:rotateAmount];
  73. }
  74. -(void)centerOnPoint:(CGPoint)point {
  75. self.center = point;
  76. }
  77. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  78. {
  79. NSUInteger touchCount = 0;
  80. // Enumerates through all touch objects
  81. for (UITouch *touch in touches)
  82. {
  83. CGPoint point = [touch locationInView:self];
  84. if (retinaEnabled)
  85. {
  86. ConvertToRetina(&point);
  87. }
  88. S32 orientation = _iOSGameGetOrientation();
  89. if (UIDeviceOrientationIsPortrait((UIDeviceOrientation)orientation))
  90. {
  91. point.y -= _iOSGetPortraitTouchoffset();
  92. }
  93. int numTouches = [touch tapCount];
  94. createMouseDownEvent(touchCount, point.x, point.y, numTouches);
  95. touchCount++;
  96. }
  97. }
  98. extern Vector<Event *> TouchMoveEvents;
  99. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  100. {
  101. NSUInteger touchCount = 0;
  102. // Enumerates through all touch objects
  103. for (UITouch *touch in touches)
  104. {
  105. CGPoint point = [touch locationInView:self];
  106. CGPoint prevPoint = [touch previousLocationInView:self]; //EFM
  107. if (retinaEnabled)
  108. {
  109. ConvertToRetina(&point);
  110. ConvertToRetina(&prevPoint);
  111. }
  112. S32 orientation = _iOSGameGetOrientation();
  113. if (UIDeviceOrientationIsPortrait((UIDeviceOrientation)orientation))
  114. {
  115. point.y -= _iOSGetPortraitTouchoffset();
  116. prevPoint.y -= _iOSGetPortraitTouchoffset();
  117. }
  118. createMouseMoveEvent(touchCount, point.x, point.y, prevPoint.x, prevPoint.y);
  119. touchCount++;
  120. }
  121. }
  122. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  123. {
  124. NSUInteger touchCount = 0;
  125. // Enumerates through all touch objects
  126. for (UITouch *touch in touches)
  127. {
  128. CGPoint point = [touch locationInView:self];
  129. CGPoint prevPoint = [touch previousLocationInView:self]; //EFM
  130. if (retinaEnabled)
  131. {
  132. ConvertToRetina(&point);
  133. ConvertToRetina(&prevPoint);
  134. }
  135. S32 orientation = _iOSGameGetOrientation();
  136. if (UIDeviceOrientationIsPortrait((UIDeviceOrientation)orientation))
  137. {
  138. point.y -= _iOSGetPortraitTouchoffset();
  139. prevPoint.y -= _iOSGetPortraitTouchoffset();
  140. }
  141. int tc = [touch tapCount];
  142. createMouseUpEvent(touchCount, point.x, point.y, prevPoint.x, prevPoint.y, tc);
  143. touchCount++;
  144. //Luma: Tap support
  145. if (tc > 0)
  146. {
  147. // this was a tap, so create a tap event
  148. createMouseTapEvent(tc, (int) point.x, (int) point.y);
  149. }
  150. }
  151. }
  152. - (void)touchesChangedWithEvent:(UIEvent *)event
  153. {
  154. Con::printf("Touches Changed with Event");
  155. }
  156. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
  157. {
  158. [self touchesEnded:touches withEvent:event];
  159. }
  160. bool gScreenAutoRotate = false;
  161. int currentRotate = 0;
  162. #define ROTATE_LEFT 0
  163. #define ROTATE_RIGHT 1
  164. #define ROTATE_UP 2
  165. @end