canvas.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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(!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. Canvas.UseBackgroundColor = true;
  67. Canvas.BackgroundColor = "Black";
  68. }
  69. //------------------------------------------------------------------------------
  70. // iOSResolutionFromSetting
  71. // Helper function that grabs resolution strings based on device type
  72. //------------------------------------------------------------------------------
  73. function AppCore::iOSResolutionFromSetting( %this, %deviceType, %deviceScreenOrientation )
  74. {
  75. // A helper function to get a string based resolution from the settings given.
  76. %x = 0;
  77. %y = 0;
  78. %scaleFactor = $pref::iOS::RetinaEnabled ? 2 : 1;
  79. switch(%deviceType)
  80. {
  81. case $iOS::constant::iPhone:
  82. if(%deviceScreenOrientation == $iOS::constant::Landscape)
  83. {
  84. %x = $iOS::constant::iPhoneWidth * %scaleFactor;
  85. %y = $iOS::constant::iPhoneHeight * %scaleFactor;
  86. }
  87. else
  88. {
  89. %x = $iOS::constant::iPhoneHeight * %scaleFactor;
  90. %y = $iOS::constant::iPhoneWidth * %scaleFactor;
  91. }
  92. case $iOS::constant::iPad:
  93. if(%deviceScreenOrientation == $iOS::constant::Landscape)
  94. {
  95. %x = $iOS::constant::iPadWidth * %scaleFactor;
  96. %y = $iOS::constant::iPadHeight * %scaleFactor;
  97. }
  98. else
  99. {
  100. %x = $iOS::constant::iPadHeight * %scaleFactor;
  101. %y = $iOS::constant::iPadWidth * %scaleFactor;
  102. }
  103. case $iOS::constant::iPhone5:
  104. if(%deviceScreenOrientation == $iOS::constant::Landscape)
  105. {
  106. %x = $iOS::constant::iPhone5Width;
  107. %y = $iOS::constant::iPhone5Height;
  108. }
  109. else
  110. {
  111. %x = $iOS::constant::iPhone5Height;
  112. %y = $iOS::constant::iPhone5Width;
  113. }
  114. }
  115. return %x @ " " @ %y;
  116. }