canvas.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. //------------------------------------------------------------------------------
  23. // initializeCanvas
  24. // Constructs and initializes the default canvas window.
  25. //------------------------------------------------------------------------------
  26. function AppCore::initializeCanvas(%this, %windowName)
  27. {
  28. // Don't duplicate the canvas.
  29. if(%this.canvasCreated)
  30. {
  31. error("Cannot instantiate more than one canvas!");
  32. return;
  33. }
  34. videoSetGammaCorrection($pref::OpenGL::gammaCorrection);
  35. if ( !createCanvas(%windowName) )
  36. {
  37. error("Canvas creation failed. Shutting down.");
  38. quit();
  39. }
  40. $pref::iOS::ScreenDepth = 32;
  41. if ($platform $= "iOS")
  42. {
  43. %resolution = $pref::iOS::Width SPC $pref::iOS::Height SPC 32;
  44. }
  45. else if ($platform $= "Android")
  46. {
  47. %resolution = GetAndroidResolution();
  48. }
  49. else
  50. {
  51. if ( $pref::Video::windowedRes !$= "" )
  52. %resolution = $pref::Video::windowedRes;
  53. else
  54. %resolution = $pref::Video::defaultResolution;
  55. }
  56. if ($platform $= "windows" || $platform $= "macos")
  57. {
  58. setScreenMode( %resolution._0, %resolution._1, %resolution._2, $pref::Video::fullScreen );
  59. }
  60. else
  61. {
  62. setScreenMode( %resolution._0, %resolution._1, %resolution._2, false );
  63. }
  64. $canvasCreated = true;
  65. }
  66. //------------------------------------------------------------------------------
  67. // resetCanvas
  68. // Forces the canvas to redraw itself.
  69. //------------------------------------------------------------------------------
  70. function AppCore::resetCanvas(%this)
  71. {
  72. if (isObject(Canvas))
  73. Canvas.repaint();
  74. }
  75. //------------------------------------------------------------------------------
  76. // iOSResolutionFromSetting
  77. // Helper function that grabs resolution strings based on device type
  78. //------------------------------------------------------------------------------
  79. function AppCore::iOSResolutionFromSetting( %this, %deviceType, %deviceScreenOrientation )
  80. {
  81. // A helper function to get a string based resolution from the settings given.
  82. %x = 0;
  83. %y = 0;
  84. %scaleFactor = $pref::iOS::RetinaEnabled ? 2 : 1;
  85. switch(%deviceType)
  86. {
  87. case $iOS::constant::iPhone:
  88. if(%deviceScreenOrientation == $iOS::constant::Landscape)
  89. {
  90. %x = $iOS::constant::iPhoneWidth * %scaleFactor;
  91. %y = $iOS::constant::iPhoneHeight * %scaleFactor;
  92. }
  93. else
  94. {
  95. %x = $iOS::constant::iPhoneHeight * %scaleFactor;
  96. %y = $iOS::constant::iPhoneWidth * %scaleFactor;
  97. }
  98. case $iOS::constant::iPad:
  99. if(%deviceScreenOrientation == $iOS::constant::Landscape)
  100. {
  101. %x = $iOS::constant::iPadWidth * %scaleFactor;
  102. %y = $iOS::constant::iPadHeight * %scaleFactor;
  103. }
  104. else
  105. {
  106. %x = $iOS::constant::iPadHeight * %scaleFactor;
  107. %y = $iOS::constant::iPadWidth * %scaleFactor;
  108. }
  109. case $iOS::constant::iPhone5:
  110. if(%deviceScreenOrientation == $iOS::constant::Landscape)
  111. {
  112. %x = $iOS::constant::iPhone5Width;
  113. %y = $iOS::constant::iPhone5Height;
  114. }
  115. else
  116. {
  117. %x = $iOS::constant::iPhone5Height;
  118. %y = $iOS::constant::iPhone5Width;
  119. }
  120. }
  121. return %x @ " " @ %y;
  122. }