Core.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. require('Polycode/EventDispatcher')
  2. function Core() {
  3. Object.defineProperties(this, {
  4. 'eventMutex': { enumerable: true, configurable: true, get: Core.prototype.__get_eventMutex, set: Core.prototype.__set_eventMutex},
  5. 'paused': { enumerable: true, configurable: true, get: Core.prototype.__get_paused, set: Core.prototype.__set_paused},
  6. 'pauseOnLoseFocus': { enumerable: true, configurable: true, get: Core.prototype.__get_pauseOnLoseFocus, set: Core.prototype.__set_pauseOnLoseFocus},
  7. 'defaultScreenWidth': { enumerable: true, configurable: true, get: Core.prototype.__get_defaultScreenWidth, set: Core.prototype.__set_defaultScreenWidth},
  8. 'defaultScreenHeight': { enumerable: true, configurable: true, get: Core.prototype.__get_defaultScreenHeight, set: Core.prototype.__set_defaultScreenHeight},
  9. 'deviceAttitude': { enumerable: true, configurable: true, get: Core.prototype.__get_deviceAttitude, set: Core.prototype.__set_deviceAttitude}
  10. })
  11. }
  12. Core.EVENTBASE_CORE = 0x200
  13. Core.EVENT_CORE_RESIZE = EVENTBASE_CORE + 0
  14. Core.EVENT_LOST_FOCUS = EVENTBASE_CORE + 1
  15. Core.EVENT_GAINED_FOCUS = EVENTBASE_CORE + 2
  16. Core.EVENT_UNDO = EVENTBASE_CORE + 3
  17. Core.EVENT_REDO = EVENTBASE_CORE + 4
  18. Core.EVENT_COPY = EVENTBASE_CORE + 5
  19. Core.EVENT_CUT = EVENTBASE_CORE + 6
  20. Core.EVENT_SELECT_ALL = EVENTBASE_CORE + 7
  21. Core.EVENT_PASTE = EVENTBASE_CORE + 8
  22. Core.EVENT_GYRO_ROTATION = EVENTBASE_CORE + 9
  23. Core.EVENT_ACCELEROMETER_MOTION = EVENTBASE_CORE + 10
  24. Core.CURSOR_ARROW = 0
  25. Core.CURSOR_TEXT = 1
  26. Core.CURSOR_POINTER = 2
  27. Core.CURSOR_CROSSHAIR = 3
  28. Core.CURSOR_RESIZE_LEFT_RIGHT = 4
  29. Core.CURSOR_RESIZE_UP_DOWN = 5
  30. Core.CURSOR_OPEN_HAND = 6
  31. Core.prototype = Object.create(EventDispatcher.prototype)
  32. Core.prototype.__get_eventMutex = function() {
  33. var retVal = new CoreMutex()
  34. retVal.__ptr = Polycode.Core__get_eventMutex(this.__ptr)
  35. return retVal
  36. }
  37. Core.prototype.__set_eventMutex = function(val) {
  38. Polycode.Core__set_eventMutex(this.__ptr, val.__ptr)
  39. }
  40. Core.prototype.__get_paused = function() {
  41. return Polycode.Core__get_paused(this.__ptr)
  42. }
  43. Core.prototype.__set_paused = function(val) {
  44. Polycode.Core__set_paused(this.__ptr, val)
  45. }
  46. Core.prototype.__get_pauseOnLoseFocus = function() {
  47. return Polycode.Core__get_pauseOnLoseFocus(this.__ptr)
  48. }
  49. Core.prototype.__set_pauseOnLoseFocus = function(val) {
  50. Polycode.Core__set_pauseOnLoseFocus(this.__ptr, val)
  51. }
  52. Core.prototype.__get_defaultScreenWidth = function() {
  53. return Polycode.Core__get_defaultScreenWidth(this.__ptr)
  54. }
  55. Core.prototype.__set_defaultScreenWidth = function(val) {
  56. Polycode.Core__set_defaultScreenWidth(this.__ptr, val)
  57. }
  58. Core.prototype.__get_defaultScreenHeight = function() {
  59. return Polycode.Core__get_defaultScreenHeight(this.__ptr)
  60. }
  61. Core.prototype.__set_defaultScreenHeight = function(val) {
  62. Polycode.Core__set_defaultScreenHeight(this.__ptr, val)
  63. }
  64. Core.prototype.__get_deviceAttitude = function() {
  65. var retVal = new Quaternion()
  66. retVal.__ptr = Polycode.Core__get_deviceAttitude(this.__ptr)
  67. return retVal
  68. }
  69. Core.prototype.__set_deviceAttitude = function(val) {
  70. Polycode.Core__set_deviceAttitude(this.__ptr, val.__ptr)
  71. }
  72. Duktape.fin(Core.prototype, function (x) {
  73. if (x === Core.prototype) {
  74. return;
  75. }
  76. Polycode.Core__delete(x.__ptr)
  77. })
  78. Core.prototype.Update = function() {
  79. return Polycode.Core_Update(this.__ptr)
  80. }
  81. Core.prototype.Render = function() {
  82. Polycode.Core_Render(this.__ptr)
  83. }
  84. Core.prototype.fixedUpdate = function() {
  85. return Polycode.Core_fixedUpdate(this.__ptr)
  86. }
  87. Core.prototype.systemUpdate = function() {
  88. return Polycode.Core_systemUpdate(this.__ptr)
  89. }
  90. Core.prototype.updateAndRender = function() {
  91. return Polycode.Core_updateAndRender(this.__ptr)
  92. }
  93. Core.prototype.enableMouse = function(newval) {
  94. Polycode.Core_enableMouse(this.__ptr, newval)
  95. }
  96. Core.prototype.captureMouse = function(newval) {
  97. Polycode.Core_captureMouse(this.__ptr, newval)
  98. }
  99. Core.prototype.setCursor = function(cursorType) {
  100. Polycode.Core_setCursor(this.__ptr, cursorType)
  101. }
  102. Core.prototype.warpCursor = function(x,y) {
  103. Polycode.Core_warpCursor(this.__ptr, x, y)
  104. }
  105. Core.prototype.openOnScreenKeyboard = function(open) {
  106. Polycode.Core_openOnScreenKeyboard(this.__ptr, open)
  107. }
  108. Core.prototype.createThread = function(target) {
  109. Polycode.Core_createThread(this.__ptr, target.__ptr)
  110. }
  111. Core.prototype.lockMutex = function(mutex) {
  112. Polycode.Core_lockMutex(this.__ptr, mutex.__ptr)
  113. }
  114. Core.prototype.unlockMutex = function(mutex) {
  115. Polycode.Core_unlockMutex(this.__ptr, mutex.__ptr)
  116. }
  117. Core.prototype.createMutex = function() {
  118. var retVal = new CoreMutex()
  119. retVal.__ptr = Polycode.Core_createMutex(this.__ptr)
  120. return retVal
  121. }
  122. Core.prototype.copyStringToClipboard = function(str) {
  123. Polycode.Core_copyStringToClipboard(this.__ptr, str)
  124. }
  125. Core.prototype.getClipboardString = function() {
  126. return Polycode.Core_getClipboardString(this.__ptr)
  127. }
  128. Core.prototype.getServices = function() {
  129. var retVal = new CoreServices()
  130. retVal.__ptr = Polycode.Core_getServices(this.__ptr)
  131. return retVal
  132. }
  133. Core.prototype.getFPS = function() {
  134. return Polycode.Core_getFPS(this.__ptr)
  135. }
  136. Core.prototype.Shutdown = function() {
  137. Polycode.Core_Shutdown(this.__ptr)
  138. }
  139. Core.prototype.isFullscreen = function() {
  140. return Polycode.Core_isFullscreen(this.__ptr)
  141. }
  142. Core.prototype.getAALevel = function() {
  143. return Polycode.Core_getAALevel(this.__ptr)
  144. }
  145. Core.prototype.getInput = function() {
  146. var retVal = new CoreInput()
  147. retVal.__ptr = Polycode.Core_getInput(this.__ptr)
  148. return retVal
  149. }
  150. Core.prototype.getXRes = function() {
  151. return Polycode.Core_getXRes(this.__ptr)
  152. }
  153. Core.prototype.getYRes = function() {
  154. return Polycode.Core_getYRes(this.__ptr)
  155. }
  156. Core.prototype.getBackingXRes = function() {
  157. return Polycode.Core_getBackingXRes(this.__ptr)
  158. }
  159. Core.prototype.getBackingYRes = function() {
  160. return Polycode.Core_getBackingYRes(this.__ptr)
  161. }
  162. Core.prototype.getScreenInfo = function(width,height,hz) {
  163. Polycode.Core_getScreenInfo(width.__ptr, height.__ptr, hz.__ptr)
  164. }
  165. Core.prototype.getScreenWidth = function() {
  166. return Polycode.Core_getScreenWidth(this.__ptr)
  167. }
  168. Core.prototype.getScreenHeight = function() {
  169. return Polycode.Core_getScreenHeight(this.__ptr)
  170. }
  171. Core.prototype.createFolder = function(folderPath) {
  172. Polycode.Core_createFolder(this.__ptr, folderPath)
  173. }
  174. Core.prototype.copyDiskItem = function(itemPath,destItemPath) {
  175. Polycode.Core_copyDiskItem(this.__ptr, itemPath, destItemPath)
  176. }
  177. Core.prototype.moveDiskItem = function(itemPath,destItemPath) {
  178. Polycode.Core_moveDiskItem(this.__ptr, itemPath, destItemPath)
  179. }
  180. Core.prototype.removeDiskItem = function(itemPath) {
  181. Polycode.Core_removeDiskItem(this.__ptr, itemPath)
  182. }
  183. Core.prototype.openFolderPicker = function() {
  184. return Polycode.Core_openFolderPicker(this.__ptr)
  185. }
  186. Core.prototype.setFramerate = function(frameRate,maxFixedCycles) {
  187. Polycode.Core_setFramerate(this.__ptr, frameRate, maxFixedCycles)
  188. }
  189. Core.prototype.openFilePicker = function(extensions,allowMultiple) {
  190. Polycode.Core_openFilePicker(this.__ptr, extensions, allowMultiple)
  191. }
  192. Core.prototype.saveFilePicker = function(extensions) {
  193. return Polycode.Core_saveFilePicker(this.__ptr, extensions)
  194. }
  195. Core.prototype.handleVideoModeChange = function(modeInfo) {
  196. Polycode.Core_handleVideoModeChange(this.__ptr, modeInfo.__ptr)
  197. }
  198. Core.prototype.flushRenderContext = function() {
  199. Polycode.Core_flushRenderContext(this.__ptr)
  200. }
  201. Core.prototype.prepareRenderContext = function() {
  202. Polycode.Core_prepareRenderContext(this.__ptr)
  203. }
  204. Core.prototype.isWindowInitialized = function() {
  205. return Polycode.Core_isWindowInitialized(this.__ptr)
  206. }
  207. Core.prototype.openFile = function(fileName,opts) {
  208. var retVal = new CoreFile()
  209. retVal.__ptr = Polycode.Core_openFile(this.__ptr, fileName, opts)
  210. return retVal
  211. }
  212. Core.prototype.closeFile = function(file) {
  213. Polycode.Core_closeFile(this.__ptr, file.__ptr)
  214. }
  215. Core.prototype.addFileSource = function(type,source) {
  216. Polycode.Core_addFileSource(this.__ptr, type, source)
  217. }
  218. Core.prototype.removeFileSource = function(type,source) {
  219. Polycode.Core_removeFileSource(this.__ptr, type, source)
  220. }
  221. Core.prototype.parseFolder = function(pathString,showHidden) {
  222. Polycode.Core_parseFolder(this.__ptr, pathString, showHidden)
  223. }
  224. Core.prototype.systemParseFolder = function(pathString,showHidden,targetVector) {
  225. return Polycode.Core_systemParseFolder(this.__ptr, pathString, showHidden, targetVector)
  226. }
  227. Core.prototype.getResourcePathForFile = function(fileName) {
  228. return Polycode.Core_getResourcePathForFile(this.__ptr, fileName)
  229. }
  230. Core.prototype.setVideoMode = function(xRes,yRes,fullScreen,vSync,aaLevel,anisotropyLevel,retinaSupport) {
  231. Polycode.Core_setVideoMode(this.__ptr, xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, retinaSupport)
  232. }
  233. Core.prototype.resizeTo = function(xRes,yRes) {
  234. Polycode.Core_resizeTo(this.__ptr, xRes, yRes)
  235. }
  236. Core.prototype.doSleep = function() {
  237. Polycode.Core_doSleep(this.__ptr)
  238. }
  239. Core.prototype.openURL = function(url) {
  240. Polycode.Core_openURL(this.__ptr, url)
  241. }
  242. Core.prototype.getElapsed = function() {
  243. return Polycode.Core_getElapsed(this.__ptr)
  244. }
  245. Core.prototype.getTicks = function() {
  246. return Polycode.Core_getTicks(this.__ptr)
  247. }
  248. Core.prototype.getRefreshIntervalMs = function() {
  249. return Polycode.Core_getRefreshIntervalMs(this.__ptr)
  250. }
  251. Core.prototype.getTimeSleptMs = function() {
  252. return Polycode.Core_getTimeSleptMs(this.__ptr)
  253. }
  254. Core.prototype.getFixedTimestep = function() {
  255. return Polycode.Core_getFixedTimestep(this.__ptr)
  256. }
  257. Core.prototype.getTicksFloat = function() {
  258. return Polycode.Core_getTicksFloat(this.__ptr)
  259. }
  260. Core.prototype.setUserPointer = function(ptr) {
  261. Polycode.Core_setUserPointer(this.__ptr, ptr.__ptr)
  262. }
  263. Core.prototype.getUserPointer = function() {
  264. Polycode.Core_getUserPointer(this.__ptr)
  265. }
  266. Core.prototype.executeExternalCommand = function(command,args,inDirectory) {
  267. return Polycode.Core_executeExternalCommand(this.__ptr, command, args, inDirectory)
  268. }
  269. Core.prototype.getDefaultWorkingDirectory = function() {
  270. return Polycode.Core_getDefaultWorkingDirectory(this.__ptr)
  271. }
  272. Core.prototype.getUserHomeDirectory = function() {
  273. return Polycode.Core_getUserHomeDirectory(this.__ptr)
  274. }
  275. Core.prototype.makeApplicationMain = function() {
  276. Polycode.Core_makeApplicationMain(this.__ptr)
  277. }
  278. Core.prototype.getEventMutex = function() {
  279. var retVal = new CoreMutex()
  280. retVal.__ptr = Polycode.Core_getEventMutex(this.__ptr)
  281. return retVal
  282. }
  283. Core.prototype.removeThread = function(thread) {
  284. Polycode.Core_removeThread(this.__ptr, thread.__ptr)
  285. }