T2DView.cpp 5.9 KB

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