smoothretro1982

w.changeZoom (Slow Zoom in/out Update)

Apr 9th, 2026 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. /**
  2. * ZoomControl98-TitleBarControls (V4 - Expanded Range)
  3. * Flat Windows 98 layout with Max Zoom increased to 5.0
  4. */
  5. class ZoomControl98Flat {
  6. constructor() {
  7. this.zoomInterval = null;
  8. this.zoomStep = 0.005; // Increased slightly for higher range
  9. this.currentValue = 1.0;
  10. this.maxZoom = 5.0; // Added as a variable for easy maintenance
  11. this.minZoom = 0.06;
  12.  
  13. const oldHud = document.getElementById("zoom-hud-root");
  14. if (oldHud) oldHud.remove();
  15.  
  16. this.initHUD();
  17. }
  18.  
  19. initHUD() {
  20. this.injectStyles();
  21. this.hud = document.createElement("div");
  22. this.hud.id = "zoom-hud-root";
  23. this.hud.style.cssText = `
  24. position:fixed; top:120px; left:20px; background:#c0c0c0;
  25. width:210px; z-index:999999; border:1px solid #000;
  26. font-family: 'Tahoma', sans-serif; font-size:11px; padding:2px;
  27. user-select: none; box-shadow: 2px 2px 0 #000;
  28. `;
  29.  
  30. this.hud.innerHTML = `
  31. <div id="z-title" style="background:#000080; color:white; padding:3px 5px; font-weight:bold; cursor:move; display:flex; justify-content:space-between; align-items:center;">
  32. <span>Zoom Properties</span>
  33. <div style="display:flex; gap:2px;">
  34. <button id="zReverse" class="win98-flat-btn title-btn" title="Slow Out">-</button>
  35. <button id="zForward" class="win98-flat-btn title-btn" title="Slow In">+</button>
  36. <button id="z-close" class="win98-flat-btn title-btn" style="font-weight:bold; margin-left:4px;">x</button>
  37. </div>
  38. </div>
  39. <div style="padding:15px 10px;">
  40. <div style="margin-bottom:4px; color:#000;">Direct Value:</div>
  41. <div style="display:flex; gap:4px; margin-bottom:12px;">
  42. <input type="text" id="zInput" class="win98-flat-inset" style="flex-grow:1; width:0; padding:4px;" value="1.000">
  43. <button id="zApply" class="win98-flat-btn" style="padding:0 8px;">Apply</button>
  44. </div>
  45.  
  46. <input type="range" id="zSlider" class="win98-flat-slider" min="${this.minZoom}" max="${this.maxZoom}" step="0.001" value="1">
  47.  
  48. <div style="display:flex; justify-content:space-between; font-size:9px; color:#000; margin-top:2px; margin-bottom:15px;">
  49. <span>${this.minZoom}</span>
  50. <span>${this.maxZoom.toFixed(2)}</span>
  51. </div>
  52.  
  53. <button id="zReset" class="win98-flat-btn" style="width:100%; height:25px;">Reset to Default</button>
  54. </div>
  55. `;
  56.  
  57. document.body.appendChild(this.hud);
  58. this.setupEvents();
  59. }
  60.  
  61. stopAuto() {
  62. if (this.zoomInterval) {
  63. clearInterval(this.zoomInterval);
  64. this.zoomInterval = null;
  65. }
  66. this.hud.querySelector('#zForward').classList.remove('active');
  67. this.hud.querySelector('#zReverse').classList.remove('active');
  68. }
  69.  
  70. updateZoom(val, syncUI = true) {
  71. let num = parseFloat(val);
  72. if (isNaN(num)) return;
  73.  
  74. // Updated clamp range to 5.0
  75. this.currentValue = Math.min(Math.max(num, this.minZoom), this.maxZoom);
  76.  
  77. if (syncUI) {
  78. this.hud.querySelector('#zSlider').value = this.currentValue;
  79. this.hud.querySelector('#zInput').value = this.currentValue.toFixed(3);
  80. }
  81.  
  82. if (window.w && typeof w.changeZoom === 'function') {
  83. w.changeZoom(this.currentValue);
  84. }
  85. }
  86.  
  87. setupEvents() {
  88. const slider = this.hud.querySelector('#zSlider');
  89. const input = this.hud.querySelector('#zInput');
  90. const fwdBtn = this.hud.querySelector('#zForward');
  91. const revBtn = this.hud.querySelector('#zReverse');
  92.  
  93. slider.oninput = (e) => {
  94. this.stopAuto();
  95. this.updateZoom(e.target.value, true);
  96. };
  97.  
  98. const toggleAuto = (dir, btn) => {
  99. const isRunning = btn.classList.contains('active');
  100. this.stopAuto();
  101.  
  102. if (!isRunning) {
  103. btn.classList.add('active');
  104. this.zoomInterval = setInterval(() => {
  105. let next = this.currentValue + (this.zoomStep * dir);
  106. // Updated auto-stop logic for 5.0
  107. if (next <= this.minZoom || next >= this.maxZoom) {
  108. this.updateZoom(next);
  109. this.stopAuto();
  110. } else {
  111. this.updateZoom(next);
  112. }
  113. }, 16);
  114. }
  115. };
  116.  
  117. fwdBtn.onclick = () => toggleAuto(1, fwdBtn);
  118. revBtn.onclick = () => toggleAuto(-1, revBtn);
  119. this.hud.querySelector('#zApply').onclick = () => { this.stopAuto(); this.updateZoom(input.value); };
  120. this.hud.querySelector('#zReset').onclick = () => { this.stopAuto(); this.updateZoom(1.0); };
  121. this.hud.querySelector('#z-close').onclick = () => { this.stopAuto(); this.hud.remove(); };
  122.  
  123. const title = this.hud.querySelector('#z-title');
  124. let drag = false, ox, oy;
  125. title.onmousedown = (e) => {
  126. if(e.target.tagName === 'BUTTON' || e.target.tagName === 'INPUT') return;
  127. drag = true; ox = e.clientX - this.hud.offsetLeft; oy = e.clientY - this.hud.offsetTop;
  128. };
  129. window.addEventListener('mousemove', (e) => {
  130. if(drag) {
  131. this.hud.style.left = (e.clientX - ox) + 'px';
  132. this.hud.style.top = (e.clientY - oy) + 'px';
  133. }
  134. });
  135. window.addEventListener('mouseup', () => drag = false);
  136. }
  137.  
  138. injectStyles() {
  139. if (document.getElementById('win98-flat-v3')) return;
  140. const s = document.createElement('style');
  141. s.id = 'win98-flat-v3';
  142. s.innerText = `
  143. .win98-flat-btn { background:#c0c0c0; border:1px solid #000; color:#000; cursor:pointer; outline:none; }
  144. .win98-flat-btn:active, .win98-flat-btn.active { background:#000080; color:#fff; }
  145. .title-btn { width:16px; height:14px; font-size:10px; padding:0; line-height:10px; }
  146. .win98-flat-inset { border:1px solid #000; background:#fff; font-family: 'Courier New', monospace; font-weight: bold; outline: none; color: #000; }
  147. .win98-flat-slider { -webkit-appearance: none; width: 100%; background: transparent; outline: none; }
  148. .win98-flat-slider::-webkit-slider-runnable-track { width: 100%; height: 2px; background: #000; }
  149. .win98-flat-slider::-webkit-slider-thumb { -webkit-appearance: none; height: 18px; width: 8px; background: #c0c0c0; border: 1px solid #000; margin-top: -8px; cursor: pointer; }
  150. `;
  151. document.head.appendChild(s);
  152. }
  153. }
  154.  
  155. new ZoomControl98Flat();
Advertisement
Add Comment
Please, Sign In to add comment