canvas.cs 4.8 KB

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