33d6d868e05219070a908e953bde210e54f92e26.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, size, view, screen, ResolutionPolicy, _dec, _class, _crd, ccclass, property, CHECK_INTERVAL, ResolutionAutoFit;
  4. return {
  5. setters: [function (_cc) {
  6. _cclegacy = _cc.cclegacy;
  7. __checkObsolete__ = _cc.__checkObsolete__;
  8. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  9. _decorator = _cc._decorator;
  10. Component = _cc.Component;
  11. size = _cc.size;
  12. view = _cc.view;
  13. screen = _cc.screen;
  14. ResolutionPolicy = _cc.ResolutionPolicy;
  15. }],
  16. execute: function () {
  17. _crd = true;
  18. _cclegacy._RF.push({}, "c7d72SJqEtIhpLiAo3HdgLR", "ui_ResolutionAutoFit", undefined);
  19. __checkObsolete__(['_decorator', 'Component', 'Node', 'size', 'Size', 'view', 'screen', 'ResolutionPolicy']);
  20. ({
  21. ccclass,
  22. property
  23. } = _decorator);
  24. CHECK_INTERVAL = 0.1;
  25. _export("ResolutionAutoFit", ResolutionAutoFit = (_dec = ccclass('ch.ResolutionAutoFit'), _dec(_class = class ResolutionAutoFit extends Component {
  26. constructor() {
  27. super(...arguments);
  28. this._oldSize = size();
  29. this.lastCheckTime = 0;
  30. }
  31. start() {
  32. this.adjustResolutionPolicy();
  33. }
  34. update(deltaTime) {
  35. this.lastCheckTime += deltaTime;
  36. if (this.lastCheckTime < CHECK_INTERVAL) {
  37. return;
  38. }
  39. this.lastCheckTime = 0;
  40. this.adjustResolutionPolicy();
  41. }
  42. adjustResolutionPolicy() {
  43. var winSize = screen.windowSize;
  44. if (!this._oldSize.equals(winSize)) {
  45. var ratio = winSize.width / winSize.height;
  46. var drs = view.getDesignResolutionSize();
  47. var drsRatio = drs.width / drs.height;
  48. if (ratio > drsRatio) {
  49. //wider than desgin. fixed height
  50. view.setResolutionPolicy(ResolutionPolicy.FIXED_HEIGHT);
  51. } else {
  52. //
  53. view.setResolutionPolicy(ResolutionPolicy.FIXED_WIDTH);
  54. }
  55. this._oldSize.set(winSize);
  56. }
  57. }
  58. }) || _class));
  59. _cclegacy._RF.pop();
  60. _crd = false;
  61. }
  62. };
  63. });
  64. //# sourceMappingURL=33d6d868e05219070a908e953bde210e54f92e26.js.map