canvas.cs 4.3 KB

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