JavaScriptを色々あれこれしようとするがひたすら失敗を繰り返している
| Revision | 32 (tree) |
|---|---|
| Time | 2016-11-29 18:45:50 |
| Author | |
・フォーカス表示方法の見直し
・画面表示ループを1ヵ所にまとめた
・アクション適用すると回転状態がキャンセルされる問題の修正
・表示要素をDIV2段構成またはDIV-IMGの2段構成に変更
・マウス入力取得要素から期待する要素まで DOM treeを辿って探すように修正
未対応
・コメントコードの削除
・ファイル保存,読み込み
| @@ -51,12 +51,18 @@ | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
| 54 | + .DispBase, | |
| 54 | 55 | .DispObj { |
| 55 | 56 | display: inline-block; |
| 56 | - position:absolute; | |
| 57 | + position: absolute; | |
| 57 | 58 | marginj:0; padding:0; |
| 58 | 59 | } |
| 60 | + .DispObj { | |
| 61 | + left:0; top:0; | |
| 62 | + width: 100%; height: 100%; | |
| 63 | + } | |
| 59 | 64 | |
| 65 | + | |
| 60 | 66 | /* パレットグループ要素の定義 */ |
| 61 | 67 | .palgroup { |
| 62 | 68 | display: inline-block; |
| @@ -106,14 +112,22 @@ | ||
| 106 | 112 | |
| 107 | 113 | |
| 108 | 114 | /* フォーカス枠と拡大縮小・回転用マーカー定義 */ |
| 109 | - .scaler { | |
| 115 | + .scaler, | |
| 116 | + .roller { | |
| 117 | + position: absolute; | |
| 118 | + width: 15px; height: 15px; | |
| 119 | + padding: 0; margin: 0; | |
| 110 | 120 | border: 2px solid black; |
| 111 | 121 | border-radius: 50%; |
| 122 | + } | |
| 123 | + .scaler { | |
| 124 | + left: 100%; top: 100%; | |
| 125 | + transform: translateX(-50%) translateY(-50%); | |
| 112 | 126 | background-color: orange; |
| 113 | 127 | } |
| 114 | 128 | .roller { |
| 115 | - border: 2px solid black; | |
| 116 | - border-radius: 50%; | |
| 129 | + left: 50%; top: 0%; | |
| 130 | + transform: translateX(-50%) translateY(-50%); | |
| 117 | 131 | background-color: green; |
| 118 | 132 | } |
| 119 | 133 |
| @@ -131,10 +145,37 @@ | ||
| 131 | 145 | ); |
| 132 | 146 | background-size: 8px 8px; |
| 133 | 147 | } |
| 134 | - .focusleft { animation: animForcus1 3s linear infinite; } | |
| 135 | - .focusright { animation: animForcus2 3s linear infinite; } | |
| 136 | - .focustop { animation: animForcus2 3s linear infinite; } | |
| 137 | - .focusbottom { animation: animForcus1 3s linear infinite; } | |
| 148 | + .focusleft, | |
| 149 | + .focustop, | |
| 150 | + .focusright, | |
| 151 | + .focusbottom{ | |
| 152 | + position: absolute; | |
| 153 | + padding: 0; margin: 0; | |
| 154 | + } | |
| 155 | + .focusleft { | |
| 156 | + left: 0%; top: 0%; | |
| 157 | + width: 2px; height: 100%; | |
| 158 | + transform: translateX(-50%) translateY(0%); | |
| 159 | + animation: animForcus1 3s linear infinite; | |
| 160 | + } | |
| 161 | + .focustop { | |
| 162 | + left: 0%; top: 0%; | |
| 163 | + width: 100%; height: 2px; | |
| 164 | + transform: translateX(0%) translateY(-50%); | |
| 165 | + animation: animForcus2 3s linear infinite; | |
| 166 | + } | |
| 167 | + .focusright { | |
| 168 | + left: 100%; top: 0%; | |
| 169 | + width: 2px; height: 100%; | |
| 170 | + transform: translateX(-50%) translateY(0%); | |
| 171 | + animation: animForcus2 3s linear infinite; | |
| 172 | + } | |
| 173 | + .focusbottom { | |
| 174 | + left: 0%; top: 100%; | |
| 175 | + width: 100%; height: 2px; | |
| 176 | + transform: translateX(0%) translateY(-50%); | |
| 177 | + animation: animForcus1 3s linear infinite; | |
| 178 | + } | |
| 138 | 179 | @keyframes animForcus1 { |
| 139 | 180 | 0% { background-position:0% 0%} |
| 140 | 181 | 100% {background-position:100% 100%} |
| @@ -151,11 +192,6 @@ | ||
| 151 | 192 | animation: none; |
| 152 | 193 | } |
| 153 | 194 | |
| 154 | - #apparea:target img, | |
| 155 | - #apparea:target div { | |
| 156 | - animation: none; | |
| 157 | - background-color:red; | |
| 158 | - } | |
| 159 | 195 | |
| 160 | 196 | |
| 161 | 197 |
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | var DEBUGLOG = true; |
| 5 | 5 | debuglog = (true==DEBUGLOG)? debugLog : logQuiet; |
| 6 | 6 | |
| 7 | -function debugLog(str) { | |
| 7 | +function debugLog(str,callerargs) { | |
| 8 | 8 | console.log(str); |
| 9 | 9 | }; |
| 10 | 10 | function logQuiet(str) { |
| @@ -195,14 +195,45 @@ | ||
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | return null; |
| 198 | -} | |
| 198 | +}; | |
| 199 | 199 | |
| 200 | 200 | |
| 201 | 201 | |
| 202 | 202 | |
| 203 | +// elementを起点に classNameを持った要素を遡って検索 | |
| 204 | +// 見つからなければ nullを返す | |
| 205 | +function findClassNameParent( | |
| 206 | + className, // 検索対象 CSS class name | |
| 207 | + element // 検索起点 element | |
| 208 | +) { | |
| 209 | + let e = element; | |
| 210 | + if (null != className && null != element) { | |
| 211 | + let result = false; | |
| 212 | + do { | |
| 213 | + result = e.classList.contains(className); | |
| 214 | + if (true == result) break; | |
| 203 | 215 | |
| 216 | + e = e.parent; | |
| 217 | + } while (null != e); | |
| 218 | + } | |
| 219 | + return e; | |
| 220 | +}; | |
| 204 | 221 | |
| 205 | 222 | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 206 | 237 | // Drop fileから file objectを取得 (同期処理) |
| 207 | 238 | // 複数file 非対応。text or image がヒットした時点でcallbackを呼び出す |
| 208 | 239 | // callback書式(text,image): function(blob) |
| @@ -314,3 +345,34 @@ | ||
| 314 | 345 | if (null != this.callbackError) this.callbackError(err.message); |
| 315 | 346 | }; |
| 316 | 347 | } // class SaveFile |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | +class RenderLoop { | |
| 352 | + constructor() { | |
| 353 | + this.renderQue = new Queue(); | |
| 354 | + this.rendering = null; // loop処理呼び出し済み判定用 | |
| 355 | + } | |
| 356 | + | |
| 357 | + | |
| 358 | + // 描画用callback関数登録要求 | |
| 359 | + // 引数のcallbackを1回呼び出します | |
| 360 | + // callback: function callback(time) | |
| 361 | + requestRenderFunc(callback) { | |
| 362 | + console.log('Request render function = ' + (callback ? callback.name : 'null')); | |
| 363 | + if (null != callback){ | |
| 364 | + this.renderQue.enqueue(callback); | |
| 365 | + | |
| 366 | + // 描画loop | |
| 367 | + (function renderloop(time) { | |
| 368 | + if (0 < this.renderQue.size()) { | |
| 369 | + this.renderQue.dequeue()(time); | |
| 370 | + console.log('render func size=' + this.renderQue.size()); | |
| 371 | + requestAnimationFrame(renderloop.bind(this)); | |
| 372 | + } | |
| 373 | + }.call(this,window.performance.now())); | |
| 374 | + } | |
| 375 | + } | |
| 376 | +} | |
| 377 | + | |
| 378 | + |
| @@ -13,23 +13,24 @@ | ||
| 13 | 13 | init() { |
| 14 | 14 | this.debuglog('init()'); |
| 15 | 15 | this.ObjID = 0; |
| 16 | - this.GroupID = 0; | |
| 17 | 16 | this.type = 0; |
| 18 | 17 | this.x = 0.0; |
| 19 | 18 | this.y = 0.0; |
| 20 | 19 | this.width = 0.0; |
| 21 | 20 | this.height = 0.0; |
| 21 | + this.originalWidth = 0.0; | |
| 22 | + this.originalHeight = 0.0; | |
| 22 | 23 | this.opacity = 1.0; |
| 23 | 24 | this.degree = 0; |
| 24 | 25 | this.text = null; |
| 25 | 26 | this.transformStr = null; |
| 26 | - this.initDOMobj(); // DOMをクリア | |
| 27 | - this.renderFunc = new Queue(); | |
| 28 | 27 | |
| 29 | - this.originalWidth = 0; | |
| 30 | - this.originalHeight = 0; | |
| 28 | + // DOMをクリア | |
| 29 | + this.initDOMobj(); | |
| 30 | +// this.renderFunc = new Queue(); | |
| 31 | 31 | |
| 32 | - this.dropinitsize = 100.0; | |
| 32 | + | |
| 33 | + this.dropinitsize = 100.0; // File dropで作成する Elementの長辺の長さ | |
| 33 | 34 | } |
| 34 | 35 | initDOMobj() { |
| 35 | 36 | if (null != this.DOMobject) { |
| @@ -47,6 +48,7 @@ | ||
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | |
| 51 | + | |
| 50 | 52 | // 操作関数 ------------------------------------ |
| 51 | 53 | |
| 52 | 54 | // 破棄 |
| @@ -73,7 +75,7 @@ | ||
| 73 | 75 | |
| 74 | 76 | |
| 75 | 77 | |
| 76 | - | |
| 78 | + /* | |
| 77 | 79 | // ブラウザ上への描画 ------------------------- |
| 78 | 80 | |
| 79 | 81 | // コマンド要求実行後の描画共通処理 |
| @@ -84,6 +86,7 @@ | ||
| 84 | 86 | renderFunction(); |
| 85 | 87 | } |
| 86 | 88 | } |
| 89 | + */ | |
| 87 | 90 | |
| 88 | 91 | // コマンド実行処理 ----------------------------- |
| 89 | 92 |
| @@ -113,14 +116,20 @@ | ||
| 113 | 116 | this.originalHeight = this.height; |
| 114 | 117 | |
| 115 | 118 | // 画面に影響しない範囲で作成できるところまで Dom objectを作成する |
| 119 | + // DispBase作成 | |
| 120 | + this.DOMbase = document.createElement('div'); | |
| 121 | + this.DOMbase.classList.add('DispBase'); | |
| 122 | + this.DOMbase.dataset.objid = this.ObjID; | |
| 123 | + this.DOMbase.dataset.degree = 0; | |
| 124 | + this.DOMbase.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 125 | + // DispObj作成 | |
| 116 | 126 | let elType = (null != type.match(/imagebox/)) ? 'img' : 'div'; |
| 117 | 127 | this.DOMobject = document.createElement(elType); |
| 128 | + this.DOMbase.appendChild(this.DOMobject); // ひとまず連結 | |
| 118 | 129 | this.DOMobject.classList.add('DispObj'); |
| 119 | 130 | this.DOMobject.dataset.objid = this.ObjID; |
| 120 | 131 | this.DOMobject.dataset.orgwidth = this.originalWidth; // transform: scaleの基準サイズ |
| 121 | - this.DOMobject.dataset.orgheight = this.originalHeight; | |
| 122 | - this.DOMobject.dataset.degree = 0; | |
| 123 | - this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 132 | + this.DOMobject.dataset.orgheight = this.originalHeight; // 画像original sizeなのでこちらで管理 | |
| 124 | 133 | if (null != type.match(/imagebox/)) { |
| 125 | 134 | // imageの場合、画像読み込み完了後に描画する必要がある |
| 126 | 135 | this.loadImage(opt1); |
| @@ -131,7 +140,8 @@ | ||
| 131 | 140 | } |
| 132 | 141 | else { |
| 133 | 142 | // 描画呼び出し時に呼び出す関数を登録 |
| 134 | - this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 143 | +// this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 144 | + window.renderLoop.requestRenderFunc(this.renderCreate.bind(this)); | |
| 135 | 145 | } |
| 136 | 146 | } |
| 137 | 147 | return true; |
| @@ -143,7 +153,8 @@ | ||
| 143 | 153 | reader.onload = function (evt) { |
| 144 | 154 | this.text = evt.target.result; |
| 145 | 155 | // 描画呼び出し時に呼び出す関数を登録 |
| 146 | - this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 156 | +// this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 157 | + window.renderLoop.requestRenderFunc(this.renderCreate.bind(this)); | |
| 147 | 158 | }.bind(this); |
| 148 | 159 | } |
| 149 | 160 | loadImage(file) { |
| @@ -162,9 +173,10 @@ | ||
| 162 | 173 | this.originalWidth = this.width; |
| 163 | 174 | this.originalHeight = this.height; |
| 164 | 175 | this.DOMobject.dataset.orgwidth = this.originalWidth; // transform: scaleの基準サイズ |
| 165 | - this.DOMobject.dataset.orgheight = this.originalHeight; | |
| 176 | + this.DOMobject.dataset.orgheight = this.originalHeight; // 画像original sizeなのでこちらで管理 | |
| 166 | 177 | // 表示サイズ取得完了したので画面に表示 |
| 167 | - this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 178 | +// this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 179 | + window.renderLoop.requestRenderFunc(this.renderCreate.bind(this)); | |
| 168 | 180 | }.bind(this); |
| 169 | 181 | }.bind(this); |
| 170 | 182 | } |
| @@ -185,27 +197,27 @@ | ||
| 185 | 197 | return new rectData(0, 0, destW, destH); |
| 186 | 198 | } |
| 187 | 199 | renderCreate() { |
| 188 | -// this.DOMobject.style.position = "absolute"; // DispObj CSS classで指定 | |
| 189 | - this.DOMobject.style.left = this.x.toString() + "px"; | |
| 190 | - this.DOMobject.style.top = this.y.toString() + "px"; | |
| 191 | - this.DOMobject.style.width = this.width.toString() + "px"; | |
| 192 | - this.DOMobject.style.height = this.height.toString() + "px"; | |
| 193 | 200 | this.DOMobject.style.border = "1px solid black"; // 指定するI/Fが必要 |
| 194 | 201 | if (null != this.text) this.DOMobject.innerHTML = this.text; |
| 202 | +// this.DOMobject.style.position = "absolute"; // DispObj CSS classで指定 | |
| 195 | 203 | |
| 196 | - document.getElementById('DispField').appendChild(this.DOMobject); | |
| 204 | + this.DOMbase.style.left = this.x.toString() + "px"; | |
| 205 | + this.DOMbase.style.top = this.y.toString() + "px"; | |
| 206 | + this.DOMbase.style.width = this.width.toString() + "px"; | |
| 207 | + this.DOMbase.style.height = this.height.toString() + "px"; | |
| 208 | + document.getElementById('DispField').appendChild(this.DOMbase); | |
| 197 | 209 | |
| 198 | - this.debuglog("renderCreate() left=" + this.DOMobject.style.left | |
| 199 | - + ", top=" + this.DOMobject.style.top | |
| 200 | - + ", width=" + this.DOMobject.style.width | |
| 201 | - + ", height=" + this.DOMobject.style.height | |
| 202 | - + ", border=" + this.DOMobject.style.border); | |
| 210 | + this.debuglog("renderCreate() left=" + this.DOMbase.style.left | |
| 211 | + + ", top=" + this.DOMbase.style.top | |
| 212 | + + ", width=" + this.DOMbase.style.width | |
| 213 | + + ", height=" + this.DOMbase.style.height | |
| 214 | + + ", innerHTML=" + this.DOMobject.innerHTML); | |
| 203 | 215 | } |
| 204 | 216 | |
| 205 | 217 | createFromElement(ele) { |
| 206 | 218 | this.debuglog('createFromElement() ele=' + ele); |
| 207 | 219 | |
| 208 | - this.DOMobject = ele; | |
| 220 | + this.DOMbase = ele; | |
| 209 | 221 | this.type = (null != ele.nodeName.match(/IMG/)) ? 'imagebox' : 'textbox'; |
| 210 | 222 | this.x = parseInt(ele.style.left); |
| 211 | 223 | this.y = parseInt(ele.style.top); |
| @@ -215,7 +227,7 @@ | ||
| 215 | 227 | this.originalHeight = ele.dataset.orgheight; |
| 216 | 228 | this.ObjID = ele.dataset.objid; |
| 217 | 229 | this.degree = ele.dataset.degree; |
| 218 | - this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 230 | + this.DOMbase.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 219 | 231 | |
| 220 | 232 | // 画像・テキストは既にelementに読み込み済み |
| 221 | 233 | // treeにも入っており、更新する必要もないのでこれで完了 |
| @@ -229,20 +241,21 @@ | ||
| 229 | 241 | movebox(x, y) { |
| 230 | 242 | this.x = x; |
| 231 | 243 | this.y = y; |
| 232 | - this.renderFunc.enqueue(this.rendermove.bind(this)); | |
| 244 | +// this.renderFunc.enqueue(this.rendermove.bind(this)); | |
| 245 | + window.renderLoop.requestRenderFunc(this.rendermove.bind(this)); | |
| 233 | 246 | |
| 234 | - this.debuglog("movebox() x=" + this.x + ", y=" + this.y + ", renderFunc size=" + this.renderFunc.size()); | |
| 247 | + this.debuglog("movebox() x=" + this.x + ", y=" + this.y); | |
| 235 | 248 | } |
| 236 | 249 | rendermove() { |
| 237 | - this.DOMobject.style.left = this.x.toString() + "px"; | |
| 238 | - this.DOMobject.style.top = this.y.toString() + "px"; | |
| 250 | + this.DOMbase.style.left = this.x.toString() + "px"; | |
| 251 | + this.DOMbase.style.top = this.y.toString() + "px"; | |
| 239 | 252 | this.DOMobject.style.opacity = this.opacity.toString(); |
| 240 | 253 | |
| 241 | - this.debuglog("rendermove() left=" + this.DOMobject.style.left | |
| 242 | - + ", top=" + this.DOMobject.style.top | |
| 243 | - + ", width=" + this.DOMobject.style.width | |
| 244 | - + ", height=" + this.DOMobject.style.height | |
| 245 | - + ", border=" + this.DOMobject.style.border); | |
| 254 | + this.debuglog("rendermove() left=" + this.DOMbase.style.left | |
| 255 | + + ", top=" + this.DOMbase.style.top | |
| 256 | + + ", width=" + this.DOMbase.style.width | |
| 257 | + + ", height=" + this.DOMbase.style.height | |
| 258 | + + ", opacity=" + this.DOMobject.opacity); | |
| 246 | 259 | } |
| 247 | 260 | |
| 248 | 261 | scalebox(rect, fontscale) { |
| @@ -250,14 +263,15 @@ | ||
| 250 | 263 | this.y = rect.top; |
| 251 | 264 | this.width = rect.right - rect.left; |
| 252 | 265 | this.height = rect.bottom - rect.top; |
| 253 | - this.renderFunc.enqueue(this.renderscalebox.bind(this)); | |
| 266 | +// this.renderFunc.enqueue(this.renderscalebox.bind(this)); | |
| 267 | + window.renderLoop.requestRenderFunc(this.renderscalebox.bind(this)); | |
| 254 | 268 | this.fontsize = fontscale; |
| 255 | 269 | } |
| 256 | 270 | renderscalebox() { |
| 257 | - this.DOMobject.style.left = this.x.toString() + "px"; | |
| 258 | - this.DOMobject.style.top = this.y.toString() + "px"; | |
| 259 | - this.DOMobject.style.width = this.width.toString() + "px"; | |
| 260 | - this.DOMobject.style.height = this.height.toString() + "px"; | |
| 271 | + this.DOMbase.style.left = this.x.toString() + "px"; | |
| 272 | + this.DOMbase.style.top = this.y.toString() + "px"; | |
| 273 | + this.DOMbase.style.width = this.width.toString() + "px"; | |
| 274 | + this.DOMbase.style.height = this.height.toString() + "px"; | |
| 261 | 275 | this.DOMobject.style.opacity = this.opacity.toString(); |
| 262 | 276 | this.DOMobject.style.fontSize = this.fontsize + '%'; |
| 263 | 277 | } |
| @@ -264,11 +278,12 @@ | ||
| 264 | 278 | |
| 265 | 279 | rollbox(degree) { |
| 266 | 280 | this.degree = degree; |
| 267 | - this.DOMobject.dataset.degree = degree; | |
| 268 | - this.renderFunc.enqueue(this.renderrollbox.bind(this)); | |
| 281 | + this.DOMbase.dataset.degree = degree; | |
| 282 | +// this.renderFunc.enqueue(this.renderrollbox.bind(this)); | |
| 283 | + window.renderLoop.requestRenderFunc(this.renderrollbox.bind(this)); | |
| 269 | 284 | } |
| 270 | 285 | renderrollbox() { |
| 271 | - this.DOMobject.style.transform = 'rotateZ(' + this.degree + 'deg);'; | |
| 286 | + this.DOMbase.style.transform = 'rotateZ(' + this.degree + 'deg);'; | |
| 272 | 287 | } |
| 273 | 288 | |
| 274 | 289 |
| @@ -288,22 +303,19 @@ | ||
| 288 | 303 | return; |
| 289 | 304 | } |
| 290 | 305 | // Mouse eventをappAreaからScalerに渡してもらうように設定 |
| 291 | - window.appArea.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 306 | + window.appArea.setMouseEventObj('DispBase',this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 292 | 307 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 293 | 308 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 294 | 309 | |
| 295 | - | |
| 296 | - // Focus設定 | |
| 297 | - evt.target.dataset.focus = "true"; | |
| 298 | 310 | // 移動元として座標を保持 |
| 299 | 311 | this.startDragX = evt.pageX; |
| 300 | 312 | this.startDragY = evt.pageY; |
| 301 | 313 | |
| 302 | 314 | // Focus表示 |
| 303 | - window.partsFocus.setClingingPartner(this.DOMobject); | |
| 315 | + window.partsFocus.setClingingPartner(this.DOMbase); | |
| 304 | 316 | |
| 305 | 317 | } |
| 306 | - mouseMove(evt) { | |
| 318 | + mouseMove(evt, target) { | |
| 307 | 319 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 308 | 320 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 309 | 321 |
| @@ -317,17 +329,18 @@ | ||
| 317 | 329 | moveX = this.x + moveX; |
| 318 | 330 | moveY = this.y + moveY; |
| 319 | 331 | |
| 320 | - this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 332 | +// this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 333 | + window.renderLoop.requestRenderFunc(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 321 | 334 | } |
| 322 | 335 | renderMoveDragging(x, y) { |
| 323 | - this.DOMobject.style.left = x + "px"; | |
| 324 | - this.DOMobject.style.top = y + "px"; | |
| 336 | + this.DOMbase.style.left = x + "px"; | |
| 337 | + this.DOMbase.style.top = y + "px"; | |
| 325 | 338 | this.DOMobject.style.opacity = 0.4; |
| 326 | 339 | } |
| 327 | - mouseUp(evt) { | |
| 340 | + mouseUp(evt, target) { | |
| 328 | 341 | this.debuglog("mouseUp"); |
| 329 | 342 | // Mouse event処理対象をクリア |
| 330 | - window.appArea.setMouseEventObj(null, null); | |
| 343 | + window.appArea.setMouseEventObj(null, null, null); | |
| 331 | 344 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 332 | 345 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 333 | 346 |
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | class CDisplayField { |
| 8 | 8 | constructor(dom) { |
| 9 | 9 | this.DOMobject = dom; |
| 10 | - this.renderFunc = new Queue(); | |
| 10 | +// this.renderFunc = new Queue(); | |
| 11 | 11 | this.mouseMoveFunc = null; |
| 12 | 12 | this.mouseUpFunc = null; |
| 13 | 13 | } |
| @@ -39,7 +39,7 @@ | ||
| 39 | 39 | let styleaction = document.getElementById('stylepalact'); |
| 40 | 40 | let cssbg = stylebg.sheet.cssText; |
| 41 | 41 | let csstextcol = styletextcol.sheet.cssText; |
| 42 | - let cssaction = getAnimationCssFromElement(styleaction); | |
| 42 | + let cssaction = getAnimationCssFromElement(styleaction); // keyframe情報を取得するため、専用関数になっている | |
| 43 | 43 | |
| 44 | 44 | // 最終出力 |
| 45 | 45 | let savestr = '<style id="stylepalbg">' + cssbg + '</style><style id="stylepaltxtcol">' + csstextcol + '</style><style id="stylepalact">' + cssaction + '</style>' + displayInfo; |
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
| 54 | - | |
| 54 | + /* | |
| 55 | 55 | // ブラウザ上への描画 ------------------------- |
| 56 | 56 | render() { |
| 57 | 57 | while (0 < this.renderFunc.size()) { |
| @@ -59,9 +59,9 @@ | ||
| 59 | 59 | renderFunction(); |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | + */ | |
| 62 | 63 | |
| 63 | 64 | |
| 64 | - | |
| 65 | 65 | // Event handler ------------------- |
| 66 | 66 | // 表示要素の drag & drop禁止 |
| 67 | 67 | onDragStart(evt) { |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | // ・DispObjへのobjid割り当て |
| 6 | 6 | // ・objidから実体への変換 |
| 7 | 7 | // ・DispObjへのcommand処理要求 (振り分け) |
| 8 | -// ・DispObjの描画関数呼び出し | |
| 8 | +// ×【やめ】DispObjの描画関数呼び出し | |
| 9 | 9 | |
| 10 | 10 | class CObjIDMgr { |
| 11 | 11 | constructor() { |
| @@ -46,6 +46,7 @@ | ||
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | + /* ★ObjIDMgrは描画には関与しないように変更★ | |
| 49 | 50 | // 管理Elementの描画関数呼び出し |
| 50 | 51 | // requestAnimationFrame loop内から呼び出される |
| 51 | 52 | renderAll() { |
| @@ -53,6 +54,7 @@ | ||
| 53 | 54 | this.ObjIDarray[i].render(); |
| 54 | 55 | } |
| 55 | 56 | } |
| 57 | + */ | |
| 56 | 58 | |
| 57 | 59 | // 指定されたIDの実体(への参照)を返す |
| 58 | 60 | getIDtoDispObj(id) { |
| @@ -11,14 +11,12 @@ | ||
| 11 | 11 | // そのため Focus図形を描く専用の DOMを用意する |
| 12 | 12 | class CPartsFocus { |
| 13 | 13 | constructor() { |
| 14 | - this.lineWidth = 2; | |
| 15 | - this.markWidth = 20; | |
| 16 | 14 | this.num2str = ['focusleft', 'focustop', 'focusright', 'focusbottom']; |
| 17 | 15 | this.clingingPartner = null; |
| 18 | 16 | this.DOM = [null, null, null, null]; // focus表示用 |
| 19 | 17 | this.domScaler = null; |
| 20 | 18 | this.domRoller = null; |
| 21 | - this.renderFunc = new Queue(); | |
| 19 | +// this.renderFunc = new Queue(); | |
| 22 | 20 | } |
| 23 | 21 | |
| 24 | 22 | debuglog(str) { |
| @@ -26,7 +24,7 @@ | ||
| 26 | 24 | debuglog("【PartsFocus】 focused objid=" + focused + ", " + str); |
| 27 | 25 | } |
| 28 | 26 | |
| 29 | - | |
| 27 | +/* | |
| 30 | 28 | // ブラウザ上への描画 ------------------------- |
| 31 | 29 | |
| 32 | 30 | // domの淵を囲むように Focus lineを表示する |
| @@ -36,102 +34,20 @@ | ||
| 36 | 34 | let renderFunction = this.renderFunc.dequeue(); |
| 37 | 35 | renderFunction(); |
| 38 | 36 | } |
| 39 | - | |
| 40 | - // Drag & Dropを追いかけるための処理 | |
| 41 | - this.renderClinging(); | |
| 42 | 37 | } |
| 43 | - renderClinging() { | |
| 44 | - if (null == this.clingingPartner) return; | |
| 38 | +*/ | |
| 45 | 39 | |
| 46 | - let originX = parseInt(this.clingingPartner.style.width) / 2; | |
| 47 | - let originY = parseInt(this.clingingPartner.style.height) / 2; | |
| 48 | - // DOM 描画先rect 回転の中心位置 | |
| 49 | - this.renderClingingSetPosition(this.DOM[0], this.getRectLeft(), (originX + this.lineWidth / 2) + 'px', '50%'); | |
| 50 | - this.renderClingingSetPosition(this.DOM[1], this.getRectTop(), '50%', (originY + this.lineWidth / 2) + 'px'); | |
| 51 | - this.renderClingingSetPosition(this.DOM[2], this.getRectRight(), (originX - this.lineWidth / 2) * -1 + 'px', '50%'); | |
| 52 | - this.renderClingingSetPosition(this.DOM[3], this.getRectBottom(), '50%', (originY - this.lineWidth / 2) * -1 + 'px'); | |
| 53 | - this.renderClingingSetPosition(this.domScaler, this.getRectScaler(), (originX - this.markWidth / 2) * -1 + 'px', (originY - this.markWidth / 2) * -1 + 'px'); | |
| 54 | - // this.renderClingingSetPosition( this.domRoller, this.getRectRoller(), (originX - this.markWidth / 2) * -1 + 'px', (originY + this.markWidth / 2) + 'px'); | |
| 55 | - this.renderClingingSetPosition(this.domRoller, this.getRectRoller(), '50%', (originY + this.markWidth / 2) + 'px'); | |
| 56 | - } | |
| 57 | - renderClingingSetPosition(dom, rect, ox, oy) { | |
| 58 | - dom.style.left = rect.left.toString() + "px"; | |
| 59 | - dom.style.top = rect.top.toString() + "px"; | |
| 60 | - dom.style.width = (rect.right - rect.left).toString() + "px"; | |
| 61 | - dom.style.height = (rect.bottom - rect.top).toString() + "px"; | |
| 62 | - // dom.style.border = "1px solid blue"; | |
| 63 | - dom.style.transform = this.clingingPartner.style.transform; | |
| 64 | - dom.style.transformOrigin = ox + ' ' + oy + ';'; // 回転の中心を focus対象の中心点に合わせる | |
| 65 | - } | |
| 66 | 40 | |
| 67 | - | |
| 68 | - | |
| 69 | - // Elementの描画 size取得関数 ------------------------- | |
| 70 | - | |
| 71 | - // Focusとして描画する4つのbar それぞれの サイズ取得 | |
| 72 | - getRectLeft() { | |
| 73 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 74 | - let rect = new rectData(); | |
| 75 | - rect.setLTWH(this.clingingPartner.style.left, this.clingingPartner.style.top, this.clingingPartner.style.width, this.clingingPartner.style.height); | |
| 76 | - rect.left -= this.lineWidth / 2; rect.top -= this.lineWidth / 2; | |
| 77 | - rect.right = rect.left + this.lineWidth; rect.bottom += this.lineWidth / 2; | |
| 78 | - return rect; | |
| 79 | - } | |
| 80 | - getRectTop() { | |
| 81 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 82 | - let rect = new rectData(); | |
| 83 | - rect.setLTWH(this.clingingPartner.style.left, this.clingingPartner.style.top, this.clingingPartner.style.width, this.clingingPartner.style.height); | |
| 84 | - rect.left += this.lineWidth / 2; rect.top -= this.lineWidth / 2; | |
| 85 | - rect.right -= this.lineWidth / 2; rect.bottom = rect.top + this.lineWidth; | |
| 86 | - return rect; | |
| 87 | - } | |
| 88 | - getRectRight() { | |
| 89 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 90 | - let rect = new rectData(); | |
| 91 | - rect.setLTWH(this.clingingPartner.style.left, this.clingingPartner.style.top, this.clingingPartner.style.width, this.clingingPartner.style.height); | |
| 92 | - rect.right += this.lineWidth / 2; rect.bottom += this.lineWidth / 2; | |
| 93 | - rect.left = rect.right - this.lineWidth; rect.top -= this.lineWidth / 2; | |
| 94 | - return rect; | |
| 95 | - } | |
| 96 | - getRectBottom() { | |
| 97 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 98 | - let rect = new rectData(); | |
| 99 | - rect.setLTWH(this.clingingPartner.style.left, this.clingingPartner.style.top, this.clingingPartner.style.width, this.clingingPartner.style.height); | |
| 100 | - rect.right -= this.lineWidth / 2; rect.bottom += this.lineWidth / 2; | |
| 101 | - rect.left += this.lineWidth / 2; rect.top = rect.bottom - this.lineWidth; | |
| 102 | - return rect; | |
| 103 | - } | |
| 104 | - // 拡大縮小用 右下マーカーの rect取得 | |
| 105 | - getRectScaler() { | |
| 106 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 107 | - let centerX = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width); | |
| 108 | - let centerY = parseInt(this.clingingPartner.style.top) + parseInt(this.clingingPartner.style.height); | |
| 109 | - let rect = new rectData(); | |
| 110 | - rect.left = centerX - this.markWidth / 2; rect.top = centerY - this.markWidth / 2; | |
| 111 | - rect.right = centerX + this.markWidth / 2; rect.bottom = centerY + this.markWidth / 2; | |
| 112 | - return rect; | |
| 113 | - } | |
| 114 | - // 回転用 上辺中心部 マーカーの rect取得 | |
| 115 | - getRectRoller() { | |
| 116 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 117 | - let centerX = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; | |
| 118 | - let centerY = parseInt(this.clingingPartner.style.top); | |
| 119 | - let rect = new rectData(); | |
| 120 | - rect.left = centerX - this.markWidth / 2; rect.top = centerY - this.markWidth / 2; | |
| 121 | - rect.right = centerX + this.markWidth / 2; rect.bottom = centerY + this.markWidth / 2; | |
| 122 | - return rect; | |
| 123 | - } | |
| 124 | - | |
| 125 | 41 | // 表示関数----------------------------------- |
| 126 | 42 | // Focus作成 |
| 127 | 43 | create() { |
| 128 | - let getRectProperty = [this.getRectLeft.bind(this), this.getRectTop.bind(this), this.getRectRight.bind(this), this.getRectBottom.bind(this)]; | |
| 129 | 44 | for (let cnt = 0; cnt < this.num2str.length; cnt++) { |
| 130 | 45 | this.DOM[cnt] = document.createElement('div'); |
| 131 | 46 | this.DOM[cnt].dataset.objid = this.num2str[cnt]; |
| 132 | 47 | this.DOM[cnt].classList.add('focusimage'); |
| 133 | 48 | this.DOM[cnt].classList.add(this.num2str[cnt]); |
| 134 | - this.renderFunc.enqueue(this.renderCreateOneFocusbar.bind(this, this.DOM[cnt], getRectProperty[cnt]())); | |
| 49 | +// this.renderFunc.enqueue(this.renderCreateOneFocusbar.bind(this, this.DOM[cnt], null)); | |
| 50 | + window.renderLoop.requestRenderFunc(this.renderCreateOneFocusbar.bind(this, this.DOM[cnt], null)); | |
| 135 | 51 | } |
| 136 | 52 | // this.debuglog("create() renderFunc size=" + this.renderFunc.size()); |
| 137 | 53 |
| @@ -140,13 +56,7 @@ | ||
| 140 | 56 | } |
| 141 | 57 | renderCreateOneFocusbar(dom, rect) { |
| 142 | 58 | dom.style.display = (null == this.clingingPartner) ? "none" : "block"; |
| 143 | - dom.style.position = "absolute"; | |
| 144 | - dom.style.left = rect.left.toString() + "px"; | |
| 145 | - dom.style.top = rect.top.toString() + "px"; | |
| 146 | - dom.style.width = (rect.right - rect.left).toString() + "px"; | |
| 147 | - dom.style.height = (rect.bottom - rect.top).toString() + "px"; | |
| 148 | - // dom.style.border = "1px solid blue"; | |
| 149 | - document.getElementById('DispField').appendChild(dom); | |
| 59 | + this.clingingPartner.appendChild(dom); | |
| 150 | 60 | } |
| 151 | 61 | |
| 152 | 62 |
| @@ -156,17 +66,12 @@ | ||
| 156 | 66 | this.domScaler.dataset.objid = 'scaler'; |
| 157 | 67 | this.domScaler.classList.add('scaler'); |
| 158 | 68 | this.domScaler.addEventListener('mousedown', this.onMouseDownScale.bind(this), false); |
| 159 | - this.renderFunc.enqueue(this.renderScaler.bind(this, this.getRectScaler())); | |
| 69 | +// this.renderFunc.enqueue(this.renderScaler.bind(this, null)); | |
| 70 | + window.renderLoop.requestRenderFunc(this.renderScaler.bind(this, null)); | |
| 160 | 71 | } |
| 161 | 72 | renderScaler(rect) { |
| 162 | 73 | this.domScaler.style.display = (null == this.clingingPartner) ? "none" : "block"; |
| 163 | - this.domScaler.style.position = 'absolute'; | |
| 164 | - this.domScaler.style.left = rect.left.toString() + "px"; | |
| 165 | - this.domScaler.style.top = rect.top.toString() + "px"; | |
| 166 | - this.domScaler.style.width = (rect.right - rect.left).toString() + "px"; | |
| 167 | - this.domScaler.style.height = (rect.bottom - rect.top).toString() + "px"; | |
| 168 | - // this.domScaler.style.border = "1px solid blue"; | |
| 169 | - document.getElementById('DispField').appendChild(this.domScaler); | |
| 74 | + this.clingingPartner.appendChild(this.domScaler); | |
| 170 | 75 | } |
| 171 | 76 | |
| 172 | 77 | // 回転操作マーカー作成 |
| @@ -175,17 +80,12 @@ | ||
| 175 | 80 | this.domRoller.dataset.objid = 'roller'; |
| 176 | 81 | this.domRoller.classList.add('roller'); |
| 177 | 82 | this.domRoller.addEventListener('mousedown', this.onMouseDownRoll.bind(this), false); |
| 178 | - this.renderFunc.enqueue(this.renderRoller.bind(this, this.getRectRoller())); | |
| 83 | +// this.renderFunc.enqueue(this.renderRoller.bind(this, null)); | |
| 84 | + window.renderLoop.requestRenderFunc(this.renderRoller.bind(this, null)); | |
| 179 | 85 | } |
| 180 | 86 | renderRoller(rect) { |
| 181 | 87 | this.domRoller.style.display = (null == this.clingingPartner) ? "none" : "block"; |
| 182 | - this.domRoller.style.position = 'absolute'; | |
| 183 | - this.domRoller.style.left = rect.left.toString() + "px"; | |
| 184 | - this.domRoller.style.top = rect.top.toString() + "px"; | |
| 185 | - this.domRoller.style.width = (rect.right - rect.left).toString() + "px"; | |
| 186 | - this.domRoller.style.height = (rect.bottom - rect.top).toString() + "px"; | |
| 187 | - // this.domRoller.style.border = "1px solid blue"; | |
| 188 | - document.getElementById('DispField').appendChild(this.domRoller); | |
| 88 | + this.clingingPartner.appendChild(this.domRoller); | |
| 189 | 89 | } |
| 190 | 90 | |
| 191 | 91 | // 操作関数----------------------------------- |
| @@ -193,11 +93,10 @@ | ||
| 193 | 93 | // 非選択: nullを返す |
| 194 | 94 | getFocusedObjid() { |
| 195 | 95 | this.debuglog("getFocusedObjid()."); |
| 196 | - let ret = null; | |
| 197 | - if (null != this.clingingPartner) { | |
| 198 | - ret = this.clingingPartner.dataset.objid; | |
| 199 | - } | |
| 200 | - return ret; | |
| 96 | + let eleFocus = this.getFocusdElements(); | |
| 97 | + if (eleFocus < 2) return null; | |
| 98 | + | |
| 99 | + return eleFocus[0].dataset.objid; | |
| 201 | 100 | } |
| 202 | 101 | |
| 203 | 102 | // Forcus先 クリア (focus 非表示) |
| @@ -207,7 +106,7 @@ | ||
| 207 | 106 | // requestAnimationFrameでの描画タイミング中は DOM.outerHTMLを変更できないため |
| 208 | 107 | // 処理ロジック上のまま削除処理を実行する |
| 209 | 108 | // this.renderFunc.enqueue( this.renderClearClingingPartner.bind(this) ); |
| 210 | - this.debuglog("clearClingingPartner() renderFunc size=" + this.renderFunc.size()); | |
| 109 | + this.debuglog("clearClingingPartner()"); | |
| 211 | 110 | |
| 212 | 111 | this.renderClearClingingPartner(); |
| 213 | 112 | } |
| @@ -242,8 +141,23 @@ | ||
| 242 | 141 | this.clearClingingPartner(); |
| 243 | 142 | return; |
| 244 | 143 | } |
| 245 | - // Focus先 変更 | |
| 246 | - else if (this.clingingPartner != dom) { | |
| 144 | + | |
| 145 | + // Focus対象チェック | |
| 146 | + let result = dom.classList.contains('DispBase'); | |
| 147 | + if (false == result) { | |
| 148 | + console.error('フォーカス先要素 誤り objid=' + dom.dataset.objid + ', className=' + dom.className); | |
| 149 | + // 誤って子要素が指定されている可能性があるため、treeを遡って検索 | |
| 150 | + dom = findClassNameParent('DispBase', dom); | |
| 151 | + if (null == dom) { | |
| 152 | + console.error('フォーカス先要素 誤り (フォーカス先検索も失敗)'); | |
| 153 | + this.clearClingingPartner(); | |
| 154 | + return; | |
| 155 | + } | |
| 156 | + } | |
| 157 | + | |
| 158 | + | |
| 159 | + // Focus先 変更 | |
| 160 | + if (this.clingingPartner != dom) { | |
| 247 | 161 | // 現在の情報をクリア |
| 248 | 162 | this.clearClingingPartner(); |
| 249 | 163 | // 新しいFocus先に変更 |
| @@ -256,17 +170,26 @@ | ||
| 256 | 170 | // Event handler ------------------------- |
| 257 | 171 | onMouseDownScale(evt) { |
| 258 | 172 | this.debuglog('onMouseDownScale'); |
| 173 | + let eleFocus = this.getFocusdElements(); | |
| 174 | + if (eleFocus < 2) return; | |
| 175 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 176 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 259 | 177 | |
| 260 | 178 | // Mouse eventをappAreaからScalerに渡してもらうように設定 |
| 261 | - window.appArea.setMouseEventObj(this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 179 | + window.appArea.setMouseEventObj(null, this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 262 | 180 | |
| 263 | 181 | // 移動元として座標を保持 |
| 264 | - this.scaleStartWidth = parseInt(this.clingingPartner.style.width); | |
| 265 | - this.scaleStartHeight = parseInt(this.clingingPartner.style.height); | |
| 182 | + this.scaleStartWidth = parseInt(eleFocus[0].style.width); | |
| 183 | + this.scaleStartHeight = parseInt(eleFocus[0].style.height); | |
| 266 | 184 | this.startDragX = evt.pageX; |
| 267 | 185 | this.startDragY = evt.pageY; |
| 268 | 186 | } |
| 269 | 187 | mouseMoveScale(evt) { |
| 188 | + let eleFocus = this.getFocusdElements(); | |
| 189 | + if (eleFocus < 2) return; | |
| 190 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 191 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 192 | + | |
| 270 | 193 | // 画像の仮変形 |
| 271 | 194 | this.endDragX = evt.pageX; |
| 272 | 195 | this.endDragY = evt.pageY; |
| @@ -276,30 +199,33 @@ | ||
| 276 | 199 | |
| 277 | 200 | switch(1){ |
| 278 | 201 | case 0: // 領域サイズ変更のみ |
| 279 | - this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 202 | +// this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 203 | + window.renderLoop.requestRenderFunc(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 280 | 204 | break; |
| 281 | 205 | case 1: // 縦倍率に合わせfont sizeも変更 |
| 282 | 206 | { |
| 283 | - let orgwidth = parseInt(this.clingingPartner.dataset.orgwidth); | |
| 284 | - let orgheight = parseInt(this.clingingPartner.dataset.orgheight); | |
| 207 | + let orgheight = parseInt(eleFocus[1].dataset.orgheight); | |
| 285 | 208 | let scaleY = (this.scaleStartHeight + moveY) / orgheight * 100; // ★さらに初期倍率設定値を掛ける必要がある |
| 286 | - this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY, scaleY)); | |
| 209 | +// this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY, scaleY)); | |
| 210 | + window.renderLoop.requestRenderFunc(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY, scaleY)); | |
| 287 | 211 | } |
| 288 | 212 | break; |
| 289 | 213 | } |
| 290 | 214 | } |
| 291 | 215 | renderMouseMoveScale(width, height, scalefont) { |
| 292 | - this.clingingPartner.style.opacity = 0.4; | |
| 216 | + let eleFocus = this.getFocusdElements(); | |
| 217 | + if (eleFocus < 2) return; | |
| 218 | + eleFocus[1].style.opacity = 0.4; | |
| 293 | 219 | |
| 294 | 220 | switch(1){ |
| 295 | 221 | case 0: |
| 296 | - this.clingingPartner.style.width = width + "px"; | |
| 297 | - this.clingingPartner.style.height = height + "px"; | |
| 222 | + eleFocus[0].style.width = width + "px"; | |
| 223 | + eleFocus[0].style.height = height + "px"; | |
| 298 | 224 | break; |
| 299 | 225 | case 1: |
| 300 | - this.clingingPartner.style.width = width + "px"; | |
| 301 | - this.clingingPartner.style.height = height + "px"; | |
| 302 | - this.clingingPartner.style.fontSize = scalefont + '%'; | |
| 226 | + eleFocus[0].style.width = width + "px"; | |
| 227 | + eleFocus[0].style.height = height + "px"; | |
| 228 | + eleFocus[1].style.fontSize = scalefont + '%'; | |
| 303 | 229 | break; |
| 304 | 230 | } |
| 305 | 231 | } |
| @@ -306,8 +232,13 @@ | ||
| 306 | 232 | mouseUpScale(evt) { |
| 307 | 233 | this.debuglog('mouseUpScale'); |
| 308 | 234 | // Mouse event callback設定をクリア |
| 309 | - window.appArea.setMouseEventObj(null, null); | |
| 235 | + window.appArea.setMouseEventObj(null, null, null); | |
| 310 | 236 | |
| 237 | + let eleFocus = this.getFocusdElements(); | |
| 238 | + if (eleFocus < 2) return; | |
| 239 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 240 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 241 | + | |
| 311 | 242 | // 画像の仮変形 |
| 312 | 243 | this.endDragX = evt.pageX; |
| 313 | 244 | this.endDragY = evt.pageY; |
| @@ -317,7 +248,7 @@ | ||
| 317 | 248 | |
| 318 | 249 | let rectFrom = new rectData(); |
| 319 | 250 | let rectTo = new rectData(); |
| 320 | - rectFrom.setLTWH(parseInt(this.clingingPartner.style.left), parseInt(this.clingingPartner.style.top), this.scaleStartWidth, this.scaleStartHeight); | |
| 251 | + rectFrom.setLTWH(parseInt(eleFocus[0].style.left), parseInt(eleFocus[0].style.top), this.scaleStartWidth, this.scaleStartHeight); | |
| 321 | 252 | rectTo.setLTWH(rectFrom.left, rectFrom.top, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY); |
| 322 | 253 | |
| 323 | 254 | let scaleY = 1.0; |
| @@ -326,8 +257,8 @@ | ||
| 326 | 257 | break; |
| 327 | 258 | case 1: // 縦倍率に合わせfont sizeも変更 |
| 328 | 259 | { |
| 329 | - let orgwidth = parseInt(this.clingingPartner.dataset.orgwidth); | |
| 330 | - let orgheight = parseInt(this.clingingPartner.dataset.orgheight); | |
| 260 | + let orgwidth = parseInt(eleFocus[1].dataset.orgwidth); | |
| 261 | + let orgheight = parseInt(eleFocus[1].dataset.orgheight); | |
| 331 | 262 | scaleY = (this.scaleStartHeight + moveY) / orgheight * 100; // ★さらに初期倍率設定値を掛ける必要がある |
| 332 | 263 | } |
| 333 | 264 | break; |
| @@ -335,7 +266,7 @@ | ||
| 335 | 266 | |
| 336 | 267 | // Scale Command発行 |
| 337 | 268 | let cmd = new CCommandObj(); |
| 338 | - cmd.createCommand(cmdType.request, cmdAddress.Focus, cmdAddress.ObjIDMgr, cmdCmd.scalebox, this.clingingPartner.dataset.objid, rectFrom, rectTo, scaleY, 5); | |
| 269 | + cmd.createCommand(cmdType.request, cmdAddress.Focus, cmdAddress.ObjIDMgr, cmdCmd.scalebox, eleFocus[0].dataset.objid, rectFrom, rectTo, scaleY, 5); | |
| 339 | 270 | this.debuglog("postToWorker"); |
| 340 | 271 | window.postToWorker.post(cmd); |
| 341 | 272 | } |
| @@ -342,40 +273,75 @@ | ||
| 342 | 273 | |
| 343 | 274 | onMouseDownRoll(evt) { |
| 344 | 275 | this.debuglog('onMouseDownRoll'); |
| 276 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 277 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 345 | 278 | |
| 346 | 279 | // Mouse eventをappAreaからRollerに渡してもらうように設定 |
| 347 | - window.appArea.setMouseEventObj(this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 280 | + window.appArea.setMouseEventObj(null, this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 348 | 281 | } |
| 349 | 282 | mouseMoveRoll(evt) { |
| 350 | - let x1 = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; | |
| 351 | - let y1 = parseInt(this.clingingPartner.style.top) + parseInt(this.clingingPartner.style.height) / 2; | |
| 283 | + let eleFocus = this.getFocusdElements(); | |
| 284 | + if (eleFocus < 2) return; | |
| 285 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 286 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 287 | + | |
| 288 | + let x1 = parseInt(eleFocus[0].style.left) + parseInt(eleFocus[0].style.width) / 2; | |
| 289 | + let y1 = parseInt(eleFocus[0].style.top) + parseInt(eleFocus[0].style.height) / 2; | |
| 352 | 290 | let x2 = evt.pageX; |
| 353 | 291 | let y2 = evt.pageY; |
| 354 | 292 | let degree = angle(x2, y2, x1, y1); |
| 355 | 293 | |
| 356 | - this.renderFunc.enqueue(this.renderMouseMoveRoll.bind(this, degree)); | |
| 294 | +// this.renderFunc.enqueue(this.renderMouseMoveRoll.bind(this, degree)); | |
| 295 | + window.renderLoop.requestRenderFunc(this.renderMouseMoveRoll.bind(this, degree)); | |
| 357 | 296 | } |
| 358 | 297 | renderMouseMoveRoll(degree) { |
| 359 | - this.clingingPartner.style.transform = 'rotateZ(' + degree + 'deg);'; | |
| 298 | + let eleFocus = this.getFocusdElements(); | |
| 299 | + if (eleFocus < 2) return; | |
| 300 | + | |
| 301 | + eleFocus[0].style.transform = 'rotateZ(' + degree + 'deg);'; | |
| 360 | 302 | } |
| 361 | 303 | mouseUpRoll(evt) { |
| 362 | 304 | this.debuglog('mouseUpRoll'); |
| 363 | 305 | // Mouse event callback設定をクリア |
| 364 | - window.appArea.setMouseEventObj(null, null); | |
| 306 | + window.appArea.setMouseEventObj(null, null, null); | |
| 307 | + let eleFocus = this.getFocusdElements(); | |
| 308 | + if (eleFocus < 2) return; | |
| 309 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 310 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 365 | 311 | |
| 366 | - let x1 = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; | |
| 367 | - let y1 = parseInt(this.clingingPartner.style.top) + parseInt(this.clingingPartner.style.height) / 2; | |
| 312 | + let x1 = parseInt(eleFocus[0].style.left) + parseInt(eleFocus[0].style.width) / 2; | |
| 313 | + let y1 = parseInt(eleFocus[0].style.top) + parseInt(eleFocus[0].style.height) / 2; | |
| 368 | 314 | let x2 = evt.pageX; |
| 369 | 315 | let y2 = evt.pageY; |
| 370 | 316 | let degree = angle(x2, y2, x1, y1); |
| 371 | 317 | // this.debuglog('■■ x1=' + x1 + ', y1=' + y1 + ',\nx2=' + x2 + ', y2=' + y2 + '\nangle=' + degree); |
| 372 | - // window.ObjIDMgr.rollbox( this.clingingPartner.dataset.objid, degree ); // debug用 設定情報で直接表示 | |
| 318 | + // window.ObjIDMgr.rollbox( eleFocus[0].dataset.objid, degree ); // debug用 設定情報で直接表示 | |
| 373 | 319 | |
| 374 | 320 | // Rotate command発行 |
| 375 | 321 | let cmd = new CCommandObj(); |
| 376 | - cmd.createCommand(cmdType.request, cmdAddress.Focus, cmdAddress.ObjIDMgr, cmdCmd.rollbox, this.clingingPartner.dataset.objid, degree, null, null, 6); | |
| 322 | + cmd.createCommand(cmdType.request, cmdAddress.Focus, cmdAddress.ObjIDMgr, cmdCmd.rollbox, eleFocus[0].dataset.objid, degree, null, null, 6); | |
| 377 | 323 | this.debuglog("postToWorker"); |
| 378 | 324 | window.postToWorker.post(cmd); |
| 379 | 325 | } |
| 380 | 326 | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + getFocusdElements() { | |
| 334 | + let eleBase = this.clingingPartner; | |
| 335 | + if (null == eleBase) { | |
| 336 | + console.error('変形処理失敗 操作対象要素が見つからない PartsFocus'); | |
| 337 | + return []; | |
| 338 | + } | |
| 339 | + if (eleBase.children.length < 1) { | |
| 340 | + console.error('変形処理失敗 表示要素が見つからない PartsFocus base element objid=' + eleBalse.dataset.objid + ', className=' + eleBase.className); | |
| 341 | + return []; | |
| 342 | + } | |
| 343 | + let eleDisp = eleBase.children[0]; | |
| 344 | + | |
| 345 | + return [eleBase, eleDisp]; | |
| 346 | + } | |
| 381 | 347 | } // class CPartsFocus |
| @@ -26,10 +26,27 @@ | ||
| 26 | 26 | |
| 27 | 27 | // 操作関数 ----------------------------------- |
| 28 | 28 | |
| 29 | - // Mouse eventを処理するObj | |
| 30 | - setMouseEventObj(mouseMove, mouseUp) { | |
| 31 | - this.debuglog('setMouseEventObj callbackMove=' + ((null != mouseMove)? mouseMove.name: 'null') + ', callbackUp=' + ((null != mouseUp)? mouseUp.name: 'null')); | |
| 29 | + // Mouse eventを拾ったときに通知してほしいときにセット | |
| 30 | + // 上書きすると前に設定されていた callbackが消えます | |
| 31 | + // callback: function mouseMove( evt ) move eventの evt.targetは目的のelementでない場合が多いため検索しない | |
| 32 | + // callback: function mouseUp( evt, strclassElement ) elementが見つからなければ null | |
| 33 | + setMouseEventObj( | |
| 34 | + strclass, // mouse up callback 第2引数 targetとして返してほしいelementが持つ css class名 | |
| 35 | + mouseMove, // mouse moveで呼んでほしい関数 or null | |
| 36 | + mouseUp // mouse upで呼んでほしい関数 or null | |
| 37 | + ) { | |
| 38 | + this.debuglog('setMouseEventObj strclass=' + strclass + ', callbackMove=' + ((null != mouseMove)? mouseMove.name: 'null') + ', callbackUp=' + ((null != mouseUp)? mouseUp.name: 'null')); | |
| 32 | 39 | |
| 40 | + // Callbackを上書きしてしまう場合はエラー出力し、ひとまず処理を継続 | |
| 41 | + if (null != mouseMove || null != mouseUp) { | |
| 42 | + if (null != this.mouseMoveFunc || null != this.mouseUpFunc) { | |
| 43 | + console.error('マウスイベント callback設定上書き \n\ | |
| 44 | +Before strclass=' + this.strclass + 'callbackMove=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', callbackUp=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null') + '\n\ | |
| 45 | +After strclass=' + strclass + 'callbackMove=' + ((null != mouseMove) ? mouseMove.name : 'null') + ', callbackUp=' + ((null != mouseUp) ? mouseUp.name : 'null')); | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 49 | + this.strclass = strclass; | |
| 33 | 50 | this.mouseMoveFunc = mouseMove; |
| 34 | 51 | this.mouseUpFunc = mouseUp; |
| 35 | 52 | } |
| @@ -38,25 +55,27 @@ | ||
| 38 | 55 | |
| 39 | 56 | // ■マウス左ボタン押下 (Drag処理) |
| 40 | 57 | onMouseDown(evt) { |
| 58 | + this.debuglog('マウスクリック onMouseDown()'); | |
| 41 | 59 | } |
| 42 | 60 | // ■ マウス移動 (ドラッグ中) |
| 43 | 61 | onMouseMove(evt) { |
| 44 | - // ★ evt.targetが期待するelementかチェックする必要がある | |
| 45 | - // ★ 期待するelementではない場合、DOM treeを辿って親elementから該当elementを探す必要がある | |
| 46 | 62 | |
| 47 | 63 | if (null != this.mouseMoveFunc) { |
| 48 | 64 | this.mouseMoveFunc(evt); |
| 49 | - return; | |
| 50 | 65 | } |
| 51 | 66 | } |
| 67 | + | |
| 52 | 68 | // ■ ドロップ処理 |
| 53 | 69 | onMouseUp(evt) { |
| 54 | - // ★ evt.targetが期待するelementかチェックする必要がある | |
| 55 | - // ★ 期待するelementではない場合、DOM treeを辿って親elementから該当elementを探す必要がある | |
| 70 | + this.debuglog('マウスアップ onMouseUp() findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); | |
| 71 | + let e = findClassNameParent(this.strclass, evt.target); | |
| 72 | + if (null == e) { | |
| 73 | + console.error('マウスアップ 指定要素が見つからない findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); | |
| 74 | + // ひとまず処理を継続する | |
| 75 | + } | |
| 56 | 76 | |
| 57 | 77 | if (null != this.mouseUpFunc) { |
| 58 | - this.mouseUpFunc(evt); | |
| 59 | - return; | |
| 78 | + this.mouseUpFunc(evt, e); | |
| 60 | 79 | } |
| 61 | 80 | } |
| 62 | 81 |
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | constructor() { |
| 11 | 11 | this.DOMobject = []; |
| 12 | 12 | this.draggingDOM = null; |
| 13 | - this.renderFunc = new Queue(); | |
| 13 | +// this.renderFunc = new Queue(); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | debuglog(str) { |
| @@ -146,7 +146,7 @@ | ||
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - | |
| 149 | + /* | |
| 150 | 150 | // 描画関数 --------------------- |
| 151 | 151 | |
| 152 | 152 | render() { |
| @@ -155,6 +155,7 @@ | ||
| 155 | 155 | renderFunction(); |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | + */ | |
| 158 | 159 | |
| 159 | 160 | // Event handler ----------------------- |
| 160 | 161 |
| @@ -202,8 +203,8 @@ | ||
| 202 | 203 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 203 | 204 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 204 | 205 | |
| 205 | - // Mouse eventをappAreaからCSSPalに渡してもらうように設定 | |
| 206 | - window.appArea.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 206 | + // Mouse eventをappAreaからCSSPalに渡してもらうように設定 (evt.targetは必ずpalette要素である前提。子要素なし。) | |
| 207 | + window.appArea.setMouseEventObj(evt.target.dataset.objid, this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 207 | 208 | |
| 208 | 209 | // Drag対象を保持 |
| 209 | 210 | this.draggingDOM = evt.target; |
| @@ -229,7 +230,8 @@ | ||
| 229 | 230 | moveX = this.startElementX + moveX; |
| 230 | 231 | moveY = this.startElementY + moveY; |
| 231 | 232 | |
| 232 | - this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 233 | +// this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 234 | + window.renderLoop.requestRenderFunc(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 233 | 235 | //this.renderMoveDragging(moveX, moveY); |
| 234 | 236 | } |
| 235 | 237 | renderMoveDragging(x, y) { |
| @@ -256,7 +258,7 @@ | ||
| 256 | 258 | // Drag中 element情報をクリア |
| 257 | 259 | this.draggingDOM = null; |
| 258 | 260 | // Mouse event callback設定をクリア |
| 259 | - window.appArea.setMouseEventObj(null, null); | |
| 261 | + window.appArea.setMouseEventObj(null, null, null); | |
| 260 | 262 | |
| 261 | 263 | // マウス座標直下にある要素を検索 |
| 262 | 264 | // (evt.targetは自分を指してしまうため) |
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | this.typeAction = 2; |
| 17 | 17 | |
| 18 | 18 | this.DOMobject = []; // bg,text,action |
| 19 | - this.renderFunc = new Queue(); | |
| 19 | +// this.renderFunc = new Queue(); | |
| 20 | 20 | } |
| 21 | 21 | debuglog(str) { |
| 22 | 22 | debuglog('【PalGroup】 ' + str); |
| @@ -44,7 +44,7 @@ | ||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - | |
| 47 | + /* | |
| 48 | 48 | // 描画関数 --------------------- |
| 49 | 49 | |
| 50 | 50 | render() { |
| @@ -53,14 +53,14 @@ | ||
| 53 | 53 | renderFunction(); |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | + */ | |
| 56 | 57 | |
| 57 | 58 | |
| 58 | - | |
| 59 | 59 | // Event handler ----------------------- |
| 60 | 60 | |
| 61 | 61 | onMouseDown(evt) { |
| 62 | 62 | // Mouse eventをappAreaからCSSPalに渡してもらうように設定 |
| 63 | - window.appArea.setMouseEventObj(this.mouseMove.bind(this), null); | |
| 63 | + window.appArea.setMouseEventObj(null, this.mouseMove.bind(this), null); | |
| 64 | 64 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 65 | 65 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 66 | 66 |
| @@ -88,7 +88,8 @@ | ||
| 88 | 88 | moveX = this.startElementX + moveX; |
| 89 | 89 | moveY = this.startElementY + moveY; |
| 90 | 90 | |
| 91 | - this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 91 | +// this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 92 | + window.renderLoop.requestRenderFunc(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 92 | 93 | //this.renderMoveDragging(moveX, moveY); |
| 93 | 94 | } |
| 94 | 95 | renderMoveDragging(x, y) { |
| @@ -106,7 +107,7 @@ | ||
| 106 | 107 | // Drag中 element情報をクリア |
| 107 | 108 | this.draggingDOM = null; |
| 108 | 109 | // Mouse event callback設定をクリア |
| 109 | - window.appArea.setMouseEventObj(null, null); | |
| 110 | + window.appArea.setMouseEventObj(null, null, null); | |
| 110 | 111 | } |
| 111 | 112 | |
| 112 | 113 |
| @@ -51,12 +51,18 @@ | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
| 54 | + .DispBase, | |
| 54 | 55 | .DispObj { |
| 55 | 56 | display: inline-block; |
| 56 | - position:absolute; | |
| 57 | + position: absolute; | |
| 57 | 58 | marginj:0; padding:0; |
| 58 | 59 | } |
| 60 | + .DispObj { | |
| 61 | + left:0; top:0; | |
| 62 | + width: 100%; height: 100%; | |
| 63 | + } | |
| 59 | 64 | |
| 65 | + | |
| 60 | 66 | /* パレットグループ要素の定義 */ |
| 61 | 67 | .palgroup { |
| 62 | 68 | display: inline-block; |
| @@ -106,14 +112,22 @@ | ||
| 106 | 112 | |
| 107 | 113 | |
| 108 | 114 | /* フォーカス枠と拡大縮小・回転用マーカー定義 */ |
| 109 | - .scaler { | |
| 115 | + .scaler, | |
| 116 | + .roller { | |
| 117 | + position: absolute; | |
| 118 | + width: 15px; height: 15px; | |
| 119 | + padding: 0; margin: 0; | |
| 110 | 120 | border: 2px solid black; |
| 111 | 121 | border-radius: 50%; |
| 122 | + } | |
| 123 | + .scaler { | |
| 124 | + left: 100%; top: 100%; | |
| 125 | + transform: translateX(-50%) translateY(-50%); | |
| 112 | 126 | background-color: orange; |
| 113 | 127 | } |
| 114 | 128 | .roller { |
| 115 | - border: 2px solid black; | |
| 116 | - border-radius: 50%; | |
| 129 | + left: 50%; top: 0%; | |
| 130 | + transform: translateX(-50%) translateY(-50%); | |
| 117 | 131 | background-color: green; |
| 118 | 132 | } |
| 119 | 133 |
| @@ -131,10 +145,37 @@ | ||
| 131 | 145 | ); |
| 132 | 146 | background-size: 8px 8px; |
| 133 | 147 | } |
| 134 | - .focusleft { animation: animForcus1 3s linear infinite; } | |
| 135 | - .focusright { animation: animForcus2 3s linear infinite; } | |
| 136 | - .focustop { animation: animForcus2 3s linear infinite; } | |
| 137 | - .focusbottom { animation: animForcus1 3s linear infinite; } | |
| 148 | + .focusleft, | |
| 149 | + .focustop, | |
| 150 | + .focusright, | |
| 151 | + .focusbottom{ | |
| 152 | + position: absolute; | |
| 153 | + padding: 0; margin: 0; | |
| 154 | + } | |
| 155 | + .focusleft { | |
| 156 | + left: 0%; top: 0%; | |
| 157 | + width: 2px; height: 100%; | |
| 158 | + transform: translateX(-50%) translateY(0%); | |
| 159 | + animation: animForcus1 3s linear infinite; | |
| 160 | + } | |
| 161 | + .focustop { | |
| 162 | + left: 0%; top: 0%; | |
| 163 | + width: 100%; height: 2px; | |
| 164 | + transform: translateX(0%) translateY(-50%); | |
| 165 | + animation: animForcus2 3s linear infinite; | |
| 166 | + } | |
| 167 | + .focusright { | |
| 168 | + left: 100%; top: 0%; | |
| 169 | + width: 2px; height: 100%; | |
| 170 | + transform: translateX(-50%) translateY(0%); | |
| 171 | + animation: animForcus2 3s linear infinite; | |
| 172 | + } | |
| 173 | + .focusbottom { | |
| 174 | + left: 0%; top: 100%; | |
| 175 | + width: 100%; height: 2px; | |
| 176 | + transform: translateX(0%) translateY(-50%); | |
| 177 | + animation: animForcus1 3s linear infinite; | |
| 178 | + } | |
| 138 | 179 | @keyframes animForcus1 { |
| 139 | 180 | 0% { background-position:0% 0%} |
| 140 | 181 | 100% {background-position:100% 100%} |
| @@ -151,11 +192,6 @@ | ||
| 151 | 192 | animation: none; |
| 152 | 193 | } |
| 153 | 194 | |
| 154 | - #apparea:target img, | |
| 155 | - #apparea:target div { | |
| 156 | - animation: none; | |
| 157 | - background-color:red; | |
| 158 | - } | |
| 159 | 195 | |
| 160 | 196 | |
| 161 | 197 |
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | var DEBUGLOG = true; |
| 5 | 5 | debuglog = (true==DEBUGLOG)? debugLog : logQuiet; |
| 6 | 6 | |
| 7 | -function debugLog(str) { | |
| 7 | +function debugLog(str,callerargs) { | |
| 8 | 8 | console.log(str); |
| 9 | 9 | }; |
| 10 | 10 | function logQuiet(str) { |
| @@ -195,14 +195,45 @@ | ||
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | return null; |
| 198 | -} | |
| 198 | +}; | |
| 199 | 199 | |
| 200 | 200 | |
| 201 | 201 | |
| 202 | 202 | |
| 203 | +// elementを起点に classNameを持った要素を遡って検索 | |
| 204 | +// 見つからなければ nullを返す | |
| 205 | +function findClassNameParent( | |
| 206 | + className, // 検索対象 CSS class name | |
| 207 | + element // 検索起点 element | |
| 208 | +) { | |
| 209 | + let e = element; | |
| 210 | + if (null != className && null != element) { | |
| 211 | + let result = false; | |
| 212 | + do { | |
| 213 | + result = e.classList.contains(className); | |
| 214 | + if (true == result) break; | |
| 203 | 215 | |
| 216 | + e = e.parent; | |
| 217 | + } while (null != e); | |
| 218 | + } | |
| 219 | + return e; | |
| 220 | +}; | |
| 204 | 221 | |
| 205 | 222 | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 206 | 237 | // Drop fileから file objectを取得 (同期処理) |
| 207 | 238 | // 複数file 非対応。text or image がヒットした時点でcallbackを呼び出す |
| 208 | 239 | // callback書式(text,image): function(blob) |
| @@ -314,3 +345,34 @@ | ||
| 314 | 345 | if (null != this.callbackError) this.callbackError(err.message); |
| 315 | 346 | }; |
| 316 | 347 | } // class SaveFile |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | +class RenderLoop { | |
| 352 | + constructor() { | |
| 353 | + this.renderQue = new Queue(); | |
| 354 | + this.rendering = null; // loop処理呼び出し済み判定用 | |
| 355 | + } | |
| 356 | + | |
| 357 | + | |
| 358 | + // 描画用callback関数登録要求 | |
| 359 | + // 引数のcallbackを1回呼び出します | |
| 360 | + // callback: function callback(time) | |
| 361 | + requestRenderFunc(callback) { | |
| 362 | + console.log('Request render function = ' + (callback ? callback.name : 'null')); | |
| 363 | + if (null != callback){ | |
| 364 | + this.renderQue.enqueue(callback); | |
| 365 | + | |
| 366 | + // 描画loop | |
| 367 | + (function renderloop(time) { | |
| 368 | + if (0 < this.renderQue.size()) { | |
| 369 | + this.renderQue.dequeue()(time); | |
| 370 | + console.log('render func size=' + this.renderQue.size()); | |
| 371 | + requestAnimationFrame(renderloop.bind(this)); | |
| 372 | + } | |
| 373 | + }.call(this,window.performance.now())); | |
| 374 | + } | |
| 375 | + } | |
| 376 | +} | |
| 377 | + | |
| 378 | + |
| @@ -13,23 +13,24 @@ | ||
| 13 | 13 | init() { |
| 14 | 14 | this.debuglog('init()'); |
| 15 | 15 | this.ObjID = 0; |
| 16 | - this.GroupID = 0; | |
| 17 | 16 | this.type = 0; |
| 18 | 17 | this.x = 0.0; |
| 19 | 18 | this.y = 0.0; |
| 20 | 19 | this.width = 0.0; |
| 21 | 20 | this.height = 0.0; |
| 21 | + this.originalWidth = 0.0; | |
| 22 | + this.originalHeight = 0.0; | |
| 22 | 23 | this.opacity = 1.0; |
| 23 | 24 | this.degree = 0; |
| 24 | 25 | this.text = null; |
| 25 | 26 | this.transformStr = null; |
| 26 | - this.initDOMobj(); // DOMをクリア | |
| 27 | - this.renderFunc = new Queue(); | |
| 28 | 27 | |
| 29 | - this.originalWidth = 0; | |
| 30 | - this.originalHeight = 0; | |
| 28 | + // DOMをクリア | |
| 29 | + this.initDOMobj(); | |
| 30 | +// this.renderFunc = new Queue(); | |
| 31 | 31 | |
| 32 | - this.dropinitsize = 100.0; | |
| 32 | + | |
| 33 | + this.dropinitsize = 100.0; // File dropで作成する Elementの長辺の長さ | |
| 33 | 34 | } |
| 34 | 35 | initDOMobj() { |
| 35 | 36 | if (null != this.DOMobject) { |
| @@ -47,6 +48,7 @@ | ||
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | |
| 51 | + | |
| 50 | 52 | // 操作関数 ------------------------------------ |
| 51 | 53 | |
| 52 | 54 | // 破棄 |
| @@ -73,7 +75,7 @@ | ||
| 73 | 75 | |
| 74 | 76 | |
| 75 | 77 | |
| 76 | - | |
| 78 | + /* | |
| 77 | 79 | // ブラウザ上への描画 ------------------------- |
| 78 | 80 | |
| 79 | 81 | // コマンド要求実行後の描画共通処理 |
| @@ -84,6 +86,7 @@ | ||
| 84 | 86 | renderFunction(); |
| 85 | 87 | } |
| 86 | 88 | } |
| 89 | + */ | |
| 87 | 90 | |
| 88 | 91 | // コマンド実行処理 ----------------------------- |
| 89 | 92 |
| @@ -113,14 +116,20 @@ | ||
| 113 | 116 | this.originalHeight = this.height; |
| 114 | 117 | |
| 115 | 118 | // 画面に影響しない範囲で作成できるところまで Dom objectを作成する |
| 119 | + // DispBase作成 | |
| 120 | + this.DOMbase = document.createElement('div'); | |
| 121 | + this.DOMbase.classList.add('DispBase'); | |
| 122 | + this.DOMbase.dataset.objid = this.ObjID; | |
| 123 | + this.DOMbase.dataset.degree = 0; | |
| 124 | + this.DOMbase.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 125 | + // DispObj作成 | |
| 116 | 126 | let elType = (null != type.match(/imagebox/)) ? 'img' : 'div'; |
| 117 | 127 | this.DOMobject = document.createElement(elType); |
| 128 | + this.DOMbase.appendChild(this.DOMobject); // ひとまず連結 | |
| 118 | 129 | this.DOMobject.classList.add('DispObj'); |
| 119 | 130 | this.DOMobject.dataset.objid = this.ObjID; |
| 120 | 131 | this.DOMobject.dataset.orgwidth = this.originalWidth; // transform: scaleの基準サイズ |
| 121 | - this.DOMobject.dataset.orgheight = this.originalHeight; | |
| 122 | - this.DOMobject.dataset.degree = 0; | |
| 123 | - this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 132 | + this.DOMobject.dataset.orgheight = this.originalHeight; // 画像original sizeなのでこちらで管理 | |
| 124 | 133 | if (null != type.match(/imagebox/)) { |
| 125 | 134 | // imageの場合、画像読み込み完了後に描画する必要がある |
| 126 | 135 | this.loadImage(opt1); |
| @@ -131,7 +140,8 @@ | ||
| 131 | 140 | } |
| 132 | 141 | else { |
| 133 | 142 | // 描画呼び出し時に呼び出す関数を登録 |
| 134 | - this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 143 | +// this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 144 | + window.renderLoop.requestRenderFunc(this.renderCreate.bind(this)); | |
| 135 | 145 | } |
| 136 | 146 | } |
| 137 | 147 | return true; |
| @@ -143,7 +153,8 @@ | ||
| 143 | 153 | reader.onload = function (evt) { |
| 144 | 154 | this.text = evt.target.result; |
| 145 | 155 | // 描画呼び出し時に呼び出す関数を登録 |
| 146 | - this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 156 | +// this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 157 | + window.renderLoop.requestRenderFunc(this.renderCreate.bind(this)); | |
| 147 | 158 | }.bind(this); |
| 148 | 159 | } |
| 149 | 160 | loadImage(file) { |
| @@ -162,9 +173,10 @@ | ||
| 162 | 173 | this.originalWidth = this.width; |
| 163 | 174 | this.originalHeight = this.height; |
| 164 | 175 | this.DOMobject.dataset.orgwidth = this.originalWidth; // transform: scaleの基準サイズ |
| 165 | - this.DOMobject.dataset.orgheight = this.originalHeight; | |
| 176 | + this.DOMobject.dataset.orgheight = this.originalHeight; // 画像original sizeなのでこちらで管理 | |
| 166 | 177 | // 表示サイズ取得完了したので画面に表示 |
| 167 | - this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 178 | +// this.renderFunc.enqueue(this.renderCreate.bind(this)); | |
| 179 | + window.renderLoop.requestRenderFunc(this.renderCreate.bind(this)); | |
| 168 | 180 | }.bind(this); |
| 169 | 181 | }.bind(this); |
| 170 | 182 | } |
| @@ -185,27 +197,27 @@ | ||
| 185 | 197 | return new rectData(0, 0, destW, destH); |
| 186 | 198 | } |
| 187 | 199 | renderCreate() { |
| 188 | -// this.DOMobject.style.position = "absolute"; // DispObj CSS classで指定 | |
| 189 | - this.DOMobject.style.left = this.x.toString() + "px"; | |
| 190 | - this.DOMobject.style.top = this.y.toString() + "px"; | |
| 191 | - this.DOMobject.style.width = this.width.toString() + "px"; | |
| 192 | - this.DOMobject.style.height = this.height.toString() + "px"; | |
| 193 | 200 | this.DOMobject.style.border = "1px solid black"; // 指定するI/Fが必要 |
| 194 | 201 | if (null != this.text) this.DOMobject.innerHTML = this.text; |
| 202 | +// this.DOMobject.style.position = "absolute"; // DispObj CSS classで指定 | |
| 195 | 203 | |
| 196 | - document.getElementById('DispField').appendChild(this.DOMobject); | |
| 204 | + this.DOMbase.style.left = this.x.toString() + "px"; | |
| 205 | + this.DOMbase.style.top = this.y.toString() + "px"; | |
| 206 | + this.DOMbase.style.width = this.width.toString() + "px"; | |
| 207 | + this.DOMbase.style.height = this.height.toString() + "px"; | |
| 208 | + document.getElementById('DispField').appendChild(this.DOMbase); | |
| 197 | 209 | |
| 198 | - this.debuglog("renderCreate() left=" + this.DOMobject.style.left | |
| 199 | - + ", top=" + this.DOMobject.style.top | |
| 200 | - + ", width=" + this.DOMobject.style.width | |
| 201 | - + ", height=" + this.DOMobject.style.height | |
| 202 | - + ", border=" + this.DOMobject.style.border); | |
| 210 | + this.debuglog("renderCreate() left=" + this.DOMbase.style.left | |
| 211 | + + ", top=" + this.DOMbase.style.top | |
| 212 | + + ", width=" + this.DOMbase.style.width | |
| 213 | + + ", height=" + this.DOMbase.style.height | |
| 214 | + + ", innerHTML=" + this.DOMobject.innerHTML); | |
| 203 | 215 | } |
| 204 | 216 | |
| 205 | 217 | createFromElement(ele) { |
| 206 | 218 | this.debuglog('createFromElement() ele=' + ele); |
| 207 | 219 | |
| 208 | - this.DOMobject = ele; | |
| 220 | + this.DOMbase = ele; | |
| 209 | 221 | this.type = (null != ele.nodeName.match(/IMG/)) ? 'imagebox' : 'textbox'; |
| 210 | 222 | this.x = parseInt(ele.style.left); |
| 211 | 223 | this.y = parseInt(ele.style.top); |
| @@ -215,7 +227,7 @@ | ||
| 215 | 227 | this.originalHeight = ele.dataset.orgheight; |
| 216 | 228 | this.ObjID = ele.dataset.objid; |
| 217 | 229 | this.degree = ele.dataset.degree; |
| 218 | - this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 230 | + this.DOMbase.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 219 | 231 | |
| 220 | 232 | // 画像・テキストは既にelementに読み込み済み |
| 221 | 233 | // treeにも入っており、更新する必要もないのでこれで完了 |
| @@ -229,20 +241,21 @@ | ||
| 229 | 241 | movebox(x, y) { |
| 230 | 242 | this.x = x; |
| 231 | 243 | this.y = y; |
| 232 | - this.renderFunc.enqueue(this.rendermove.bind(this)); | |
| 244 | +// this.renderFunc.enqueue(this.rendermove.bind(this)); | |
| 245 | + window.renderLoop.requestRenderFunc(this.rendermove.bind(this)); | |
| 233 | 246 | |
| 234 | - this.debuglog("movebox() x=" + this.x + ", y=" + this.y + ", renderFunc size=" + this.renderFunc.size()); | |
| 247 | + this.debuglog("movebox() x=" + this.x + ", y=" + this.y); | |
| 235 | 248 | } |
| 236 | 249 | rendermove() { |
| 237 | - this.DOMobject.style.left = this.x.toString() + "px"; | |
| 238 | - this.DOMobject.style.top = this.y.toString() + "px"; | |
| 250 | + this.DOMbase.style.left = this.x.toString() + "px"; | |
| 251 | + this.DOMbase.style.top = this.y.toString() + "px"; | |
| 239 | 252 | this.DOMobject.style.opacity = this.opacity.toString(); |
| 240 | 253 | |
| 241 | - this.debuglog("rendermove() left=" + this.DOMobject.style.left | |
| 242 | - + ", top=" + this.DOMobject.style.top | |
| 243 | - + ", width=" + this.DOMobject.style.width | |
| 244 | - + ", height=" + this.DOMobject.style.height | |
| 245 | - + ", border=" + this.DOMobject.style.border); | |
| 254 | + this.debuglog("rendermove() left=" + this.DOMbase.style.left | |
| 255 | + + ", top=" + this.DOMbase.style.top | |
| 256 | + + ", width=" + this.DOMbase.style.width | |
| 257 | + + ", height=" + this.DOMbase.style.height | |
| 258 | + + ", opacity=" + this.DOMobject.opacity); | |
| 246 | 259 | } |
| 247 | 260 | |
| 248 | 261 | scalebox(rect, fontscale) { |
| @@ -250,14 +263,15 @@ | ||
| 250 | 263 | this.y = rect.top; |
| 251 | 264 | this.width = rect.right - rect.left; |
| 252 | 265 | this.height = rect.bottom - rect.top; |
| 253 | - this.renderFunc.enqueue(this.renderscalebox.bind(this)); | |
| 266 | +// this.renderFunc.enqueue(this.renderscalebox.bind(this)); | |
| 267 | + window.renderLoop.requestRenderFunc(this.renderscalebox.bind(this)); | |
| 254 | 268 | this.fontsize = fontscale; |
| 255 | 269 | } |
| 256 | 270 | renderscalebox() { |
| 257 | - this.DOMobject.style.left = this.x.toString() + "px"; | |
| 258 | - this.DOMobject.style.top = this.y.toString() + "px"; | |
| 259 | - this.DOMobject.style.width = this.width.toString() + "px"; | |
| 260 | - this.DOMobject.style.height = this.height.toString() + "px"; | |
| 271 | + this.DOMbase.style.left = this.x.toString() + "px"; | |
| 272 | + this.DOMbase.style.top = this.y.toString() + "px"; | |
| 273 | + this.DOMbase.style.width = this.width.toString() + "px"; | |
| 274 | + this.DOMbase.style.height = this.height.toString() + "px"; | |
| 261 | 275 | this.DOMobject.style.opacity = this.opacity.toString(); |
| 262 | 276 | this.DOMobject.style.fontSize = this.fontsize + '%'; |
| 263 | 277 | } |
| @@ -264,11 +278,12 @@ | ||
| 264 | 278 | |
| 265 | 279 | rollbox(degree) { |
| 266 | 280 | this.degree = degree; |
| 267 | - this.DOMobject.dataset.degree = degree; | |
| 268 | - this.renderFunc.enqueue(this.renderrollbox.bind(this)); | |
| 281 | + this.DOMbase.dataset.degree = degree; | |
| 282 | +// this.renderFunc.enqueue(this.renderrollbox.bind(this)); | |
| 283 | + window.renderLoop.requestRenderFunc(this.renderrollbox.bind(this)); | |
| 269 | 284 | } |
| 270 | 285 | renderrollbox() { |
| 271 | - this.DOMobject.style.transform = 'rotateZ(' + this.degree + 'deg);'; | |
| 286 | + this.DOMbase.style.transform = 'rotateZ(' + this.degree + 'deg);'; | |
| 272 | 287 | } |
| 273 | 288 | |
| 274 | 289 |
| @@ -288,22 +303,19 @@ | ||
| 288 | 303 | return; |
| 289 | 304 | } |
| 290 | 305 | // Mouse eventをappAreaからScalerに渡してもらうように設定 |
| 291 | - window.appArea.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 306 | + window.appArea.setMouseEventObj('DispBase',this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 292 | 307 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 293 | 308 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 294 | 309 | |
| 295 | - | |
| 296 | - // Focus設定 | |
| 297 | - evt.target.dataset.focus = "true"; | |
| 298 | 310 | // 移動元として座標を保持 |
| 299 | 311 | this.startDragX = evt.pageX; |
| 300 | 312 | this.startDragY = evt.pageY; |
| 301 | 313 | |
| 302 | 314 | // Focus表示 |
| 303 | - window.partsFocus.setClingingPartner(this.DOMobject); | |
| 315 | + window.partsFocus.setClingingPartner(this.DOMbase); | |
| 304 | 316 | |
| 305 | 317 | } |
| 306 | - mouseMove(evt) { | |
| 318 | + mouseMove(evt, target) { | |
| 307 | 319 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 308 | 320 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 309 | 321 |
| @@ -317,17 +329,18 @@ | ||
| 317 | 329 | moveX = this.x + moveX; |
| 318 | 330 | moveY = this.y + moveY; |
| 319 | 331 | |
| 320 | - this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 332 | +// this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 333 | + window.renderLoop.requestRenderFunc(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 321 | 334 | } |
| 322 | 335 | renderMoveDragging(x, y) { |
| 323 | - this.DOMobject.style.left = x + "px"; | |
| 324 | - this.DOMobject.style.top = y + "px"; | |
| 336 | + this.DOMbase.style.left = x + "px"; | |
| 337 | + this.DOMbase.style.top = y + "px"; | |
| 325 | 338 | this.DOMobject.style.opacity = 0.4; |
| 326 | 339 | } |
| 327 | - mouseUp(evt) { | |
| 340 | + mouseUp(evt, target) { | |
| 328 | 341 | this.debuglog("mouseUp"); |
| 329 | 342 | // Mouse event処理対象をクリア |
| 330 | - window.appArea.setMouseEventObj(null, null); | |
| 343 | + window.appArea.setMouseEventObj(null, null, null); | |
| 331 | 344 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 332 | 345 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 333 | 346 |
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | class CDisplayField { |
| 8 | 8 | constructor(dom) { |
| 9 | 9 | this.DOMobject = dom; |
| 10 | - this.renderFunc = new Queue(); | |
| 10 | +// this.renderFunc = new Queue(); | |
| 11 | 11 | this.mouseMoveFunc = null; |
| 12 | 12 | this.mouseUpFunc = null; |
| 13 | 13 | } |
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
| 54 | - | |
| 54 | + /* | |
| 55 | 55 | // ブラウザ上への描画 ------------------------- |
| 56 | 56 | render() { |
| 57 | 57 | while (0 < this.renderFunc.size()) { |
| @@ -59,9 +59,9 @@ | ||
| 59 | 59 | renderFunction(); |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | + */ | |
| 62 | 63 | |
| 63 | 64 | |
| 64 | - | |
| 65 | 65 | // Event handler ------------------- |
| 66 | 66 | // 表示要素の drag & drop禁止 |
| 67 | 67 | onDragStart(evt) { |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | // ・DispObjへのobjid割り当て |
| 6 | 6 | // ・objidから実体への変換 |
| 7 | 7 | // ・DispObjへのcommand処理要求 (振り分け) |
| 8 | -// ・DispObjの描画関数呼び出し | |
| 8 | +// ×【やめ】DispObjの描画関数呼び出し | |
| 9 | 9 | |
| 10 | 10 | class CObjIDMgr { |
| 11 | 11 | constructor() { |
| @@ -46,6 +46,7 @@ | ||
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | + /* ★ObjIDMgrは描画には関与しないように変更★ | |
| 49 | 50 | // 管理Elementの描画関数呼び出し |
| 50 | 51 | // requestAnimationFrame loop内から呼び出される |
| 51 | 52 | renderAll() { |
| @@ -53,6 +54,7 @@ | ||
| 53 | 54 | this.ObjIDarray[i].render(); |
| 54 | 55 | } |
| 55 | 56 | } |
| 57 | + */ | |
| 56 | 58 | |
| 57 | 59 | // 指定されたIDの実体(への参照)を返す |
| 58 | 60 | getIDtoDispObj(id) { |
| @@ -11,14 +11,12 @@ | ||
| 11 | 11 | // そのため Focus図形を描く専用の DOMを用意する |
| 12 | 12 | class CPartsFocus { |
| 13 | 13 | constructor() { |
| 14 | - this.lineWidth = 2; | |
| 15 | - this.markWidth = 20; | |
| 16 | 14 | this.num2str = ['focusleft', 'focustop', 'focusright', 'focusbottom']; |
| 17 | 15 | this.clingingPartner = null; |
| 18 | 16 | this.DOM = [null, null, null, null]; // focus表示用 |
| 19 | 17 | this.domScaler = null; |
| 20 | 18 | this.domRoller = null; |
| 21 | - this.renderFunc = new Queue(); | |
| 19 | +// this.renderFunc = new Queue(); | |
| 22 | 20 | } |
| 23 | 21 | |
| 24 | 22 | debuglog(str) { |
| @@ -26,7 +24,7 @@ | ||
| 26 | 24 | debuglog("【PartsFocus】 focused objid=" + focused + ", " + str); |
| 27 | 25 | } |
| 28 | 26 | |
| 29 | - | |
| 27 | +/* | |
| 30 | 28 | // ブラウザ上への描画 ------------------------- |
| 31 | 29 | |
| 32 | 30 | // domの淵を囲むように Focus lineを表示する |
| @@ -36,102 +34,20 @@ | ||
| 36 | 34 | let renderFunction = this.renderFunc.dequeue(); |
| 37 | 35 | renderFunction(); |
| 38 | 36 | } |
| 39 | - | |
| 40 | - // Drag & Dropを追いかけるための処理 | |
| 41 | - this.renderClinging(); | |
| 42 | 37 | } |
| 43 | - renderClinging() { | |
| 44 | - if (null == this.clingingPartner) return; | |
| 38 | +*/ | |
| 45 | 39 | |
| 46 | - let originX = parseInt(this.clingingPartner.style.width) / 2; | |
| 47 | - let originY = parseInt(this.clingingPartner.style.height) / 2; | |
| 48 | - // DOM 描画先rect 回転の中心位置 | |
| 49 | - this.renderClingingSetPosition(this.DOM[0], this.getRectLeft(), (originX + this.lineWidth / 2) + 'px', '50%'); | |
| 50 | - this.renderClingingSetPosition(this.DOM[1], this.getRectTop(), '50%', (originY + this.lineWidth / 2) + 'px'); | |
| 51 | - this.renderClingingSetPosition(this.DOM[2], this.getRectRight(), (originX - this.lineWidth / 2) * -1 + 'px', '50%'); | |
| 52 | - this.renderClingingSetPosition(this.DOM[3], this.getRectBottom(), '50%', (originY - this.lineWidth / 2) * -1 + 'px'); | |
| 53 | - this.renderClingingSetPosition(this.domScaler, this.getRectScaler(), (originX - this.markWidth / 2) * -1 + 'px', (originY - this.markWidth / 2) * -1 + 'px'); | |
| 54 | - // this.renderClingingSetPosition( this.domRoller, this.getRectRoller(), (originX - this.markWidth / 2) * -1 + 'px', (originY + this.markWidth / 2) + 'px'); | |
| 55 | - this.renderClingingSetPosition(this.domRoller, this.getRectRoller(), '50%', (originY + this.markWidth / 2) + 'px'); | |
| 56 | - } | |
| 57 | - renderClingingSetPosition(dom, rect, ox, oy) { | |
| 58 | - dom.style.left = rect.left.toString() + "px"; | |
| 59 | - dom.style.top = rect.top.toString() + "px"; | |
| 60 | - dom.style.width = (rect.right - rect.left).toString() + "px"; | |
| 61 | - dom.style.height = (rect.bottom - rect.top).toString() + "px"; | |
| 62 | - // dom.style.border = "1px solid blue"; | |
| 63 | - dom.style.transform = this.clingingPartner.style.transform; | |
| 64 | - dom.style.transformOrigin = ox + ' ' + oy + ';'; // 回転の中心を focus対象の中心点に合わせる | |
| 65 | - } | |
| 66 | 40 | |
| 67 | - | |
| 68 | - | |
| 69 | - // Elementの描画 size取得関数 ------------------------- | |
| 70 | - | |
| 71 | - // Focusとして描画する4つのbar それぞれの サイズ取得 | |
| 72 | - getRectLeft() { | |
| 73 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 74 | - let rect = new rectData(); | |
| 75 | - rect.setLTWH(this.clingingPartner.style.left, this.clingingPartner.style.top, this.clingingPartner.style.width, this.clingingPartner.style.height); | |
| 76 | - rect.left -= this.lineWidth / 2; rect.top -= this.lineWidth / 2; | |
| 77 | - rect.right = rect.left + this.lineWidth; rect.bottom += this.lineWidth / 2; | |
| 78 | - return rect; | |
| 79 | - } | |
| 80 | - getRectTop() { | |
| 81 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 82 | - let rect = new rectData(); | |
| 83 | - rect.setLTWH(this.clingingPartner.style.left, this.clingingPartner.style.top, this.clingingPartner.style.width, this.clingingPartner.style.height); | |
| 84 | - rect.left += this.lineWidth / 2; rect.top -= this.lineWidth / 2; | |
| 85 | - rect.right -= this.lineWidth / 2; rect.bottom = rect.top + this.lineWidth; | |
| 86 | - return rect; | |
| 87 | - } | |
| 88 | - getRectRight() { | |
| 89 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 90 | - let rect = new rectData(); | |
| 91 | - rect.setLTWH(this.clingingPartner.style.left, this.clingingPartner.style.top, this.clingingPartner.style.width, this.clingingPartner.style.height); | |
| 92 | - rect.right += this.lineWidth / 2; rect.bottom += this.lineWidth / 2; | |
| 93 | - rect.left = rect.right - this.lineWidth; rect.top -= this.lineWidth / 2; | |
| 94 | - return rect; | |
| 95 | - } | |
| 96 | - getRectBottom() { | |
| 97 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 98 | - let rect = new rectData(); | |
| 99 | - rect.setLTWH(this.clingingPartner.style.left, this.clingingPartner.style.top, this.clingingPartner.style.width, this.clingingPartner.style.height); | |
| 100 | - rect.right -= this.lineWidth / 2; rect.bottom += this.lineWidth / 2; | |
| 101 | - rect.left += this.lineWidth / 2; rect.top = rect.bottom - this.lineWidth; | |
| 102 | - return rect; | |
| 103 | - } | |
| 104 | - // 拡大縮小用 右下マーカーの rect取得 | |
| 105 | - getRectScaler() { | |
| 106 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 107 | - let centerX = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width); | |
| 108 | - let centerY = parseInt(this.clingingPartner.style.top) + parseInt(this.clingingPartner.style.height); | |
| 109 | - let rect = new rectData(); | |
| 110 | - rect.left = centerX - this.markWidth / 2; rect.top = centerY - this.markWidth / 2; | |
| 111 | - rect.right = centerX + this.markWidth / 2; rect.bottom = centerY + this.markWidth / 2; | |
| 112 | - return rect; | |
| 113 | - } | |
| 114 | - // 回転用 上辺中心部 マーカーの rect取得 | |
| 115 | - getRectRoller() { | |
| 116 | - if (null == this.clingingPartner) return new rectData(0, 0, 0, 0); | |
| 117 | - let centerX = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; | |
| 118 | - let centerY = parseInt(this.clingingPartner.style.top); | |
| 119 | - let rect = new rectData(); | |
| 120 | - rect.left = centerX - this.markWidth / 2; rect.top = centerY - this.markWidth / 2; | |
| 121 | - rect.right = centerX + this.markWidth / 2; rect.bottom = centerY + this.markWidth / 2; | |
| 122 | - return rect; | |
| 123 | - } | |
| 124 | - | |
| 125 | 41 | // 表示関数----------------------------------- |
| 126 | 42 | // Focus作成 |
| 127 | 43 | create() { |
| 128 | - let getRectProperty = [this.getRectLeft.bind(this), this.getRectTop.bind(this), this.getRectRight.bind(this), this.getRectBottom.bind(this)]; | |
| 129 | 44 | for (let cnt = 0; cnt < this.num2str.length; cnt++) { |
| 130 | 45 | this.DOM[cnt] = document.createElement('div'); |
| 131 | 46 | this.DOM[cnt].dataset.objid = this.num2str[cnt]; |
| 132 | 47 | this.DOM[cnt].classList.add('focusimage'); |
| 133 | 48 | this.DOM[cnt].classList.add(this.num2str[cnt]); |
| 134 | - this.renderFunc.enqueue(this.renderCreateOneFocusbar.bind(this, this.DOM[cnt], getRectProperty[cnt]())); | |
| 49 | +// this.renderFunc.enqueue(this.renderCreateOneFocusbar.bind(this, this.DOM[cnt], null)); | |
| 50 | + window.renderLoop.requestRenderFunc(this.renderCreateOneFocusbar.bind(this, this.DOM[cnt], null)); | |
| 135 | 51 | } |
| 136 | 52 | // this.debuglog("create() renderFunc size=" + this.renderFunc.size()); |
| 137 | 53 |
| @@ -140,13 +56,7 @@ | ||
| 140 | 56 | } |
| 141 | 57 | renderCreateOneFocusbar(dom, rect) { |
| 142 | 58 | dom.style.display = (null == this.clingingPartner) ? "none" : "block"; |
| 143 | - dom.style.position = "absolute"; | |
| 144 | - dom.style.left = rect.left.toString() + "px"; | |
| 145 | - dom.style.top = rect.top.toString() + "px"; | |
| 146 | - dom.style.width = (rect.right - rect.left).toString() + "px"; | |
| 147 | - dom.style.height = (rect.bottom - rect.top).toString() + "px"; | |
| 148 | - // dom.style.border = "1px solid blue"; | |
| 149 | - document.getElementById('DispField').appendChild(dom); | |
| 59 | + this.clingingPartner.appendChild(dom); | |
| 150 | 60 | } |
| 151 | 61 | |
| 152 | 62 |
| @@ -156,17 +66,12 @@ | ||
| 156 | 66 | this.domScaler.dataset.objid = 'scaler'; |
| 157 | 67 | this.domScaler.classList.add('scaler'); |
| 158 | 68 | this.domScaler.addEventListener('mousedown', this.onMouseDownScale.bind(this), false); |
| 159 | - this.renderFunc.enqueue(this.renderScaler.bind(this, this.getRectScaler())); | |
| 69 | +// this.renderFunc.enqueue(this.renderScaler.bind(this, null)); | |
| 70 | + window.renderLoop.requestRenderFunc(this.renderScaler.bind(this, null)); | |
| 160 | 71 | } |
| 161 | 72 | renderScaler(rect) { |
| 162 | 73 | this.domScaler.style.display = (null == this.clingingPartner) ? "none" : "block"; |
| 163 | - this.domScaler.style.position = 'absolute'; | |
| 164 | - this.domScaler.style.left = rect.left.toString() + "px"; | |
| 165 | - this.domScaler.style.top = rect.top.toString() + "px"; | |
| 166 | - this.domScaler.style.width = (rect.right - rect.left).toString() + "px"; | |
| 167 | - this.domScaler.style.height = (rect.bottom - rect.top).toString() + "px"; | |
| 168 | - // this.domScaler.style.border = "1px solid blue"; | |
| 169 | - document.getElementById('DispField').appendChild(this.domScaler); | |
| 74 | + this.clingingPartner.appendChild(this.domScaler); | |
| 170 | 75 | } |
| 171 | 76 | |
| 172 | 77 | // 回転操作マーカー作成 |
| @@ -175,17 +80,12 @@ | ||
| 175 | 80 | this.domRoller.dataset.objid = 'roller'; |
| 176 | 81 | this.domRoller.classList.add('roller'); |
| 177 | 82 | this.domRoller.addEventListener('mousedown', this.onMouseDownRoll.bind(this), false); |
| 178 | - this.renderFunc.enqueue(this.renderRoller.bind(this, this.getRectRoller())); | |
| 83 | +// this.renderFunc.enqueue(this.renderRoller.bind(this, null)); | |
| 84 | + window.renderLoop.requestRenderFunc(this.renderRoller.bind(this, null)); | |
| 179 | 85 | } |
| 180 | 86 | renderRoller(rect) { |
| 181 | 87 | this.domRoller.style.display = (null == this.clingingPartner) ? "none" : "block"; |
| 182 | - this.domRoller.style.position = 'absolute'; | |
| 183 | - this.domRoller.style.left = rect.left.toString() + "px"; | |
| 184 | - this.domRoller.style.top = rect.top.toString() + "px"; | |
| 185 | - this.domRoller.style.width = (rect.right - rect.left).toString() + "px"; | |
| 186 | - this.domRoller.style.height = (rect.bottom - rect.top).toString() + "px"; | |
| 187 | - // this.domRoller.style.border = "1px solid blue"; | |
| 188 | - document.getElementById('DispField').appendChild(this.domRoller); | |
| 88 | + this.clingingPartner.appendChild(this.domRoller); | |
| 189 | 89 | } |
| 190 | 90 | |
| 191 | 91 | // 操作関数----------------------------------- |
| @@ -193,11 +93,10 @@ | ||
| 193 | 93 | // 非選択: nullを返す |
| 194 | 94 | getFocusedObjid() { |
| 195 | 95 | this.debuglog("getFocusedObjid()."); |
| 196 | - let ret = null; | |
| 197 | - if (null != this.clingingPartner) { | |
| 198 | - ret = this.clingingPartner.dataset.objid; | |
| 199 | - } | |
| 200 | - return ret; | |
| 96 | + let eleFocus = this.getFocusdElements(); | |
| 97 | + if (eleFocus < 2) return null; | |
| 98 | + | |
| 99 | + return eleFocus[0].dataset.objid; | |
| 201 | 100 | } |
| 202 | 101 | |
| 203 | 102 | // Forcus先 クリア (focus 非表示) |
| @@ -207,7 +106,7 @@ | ||
| 207 | 106 | // requestAnimationFrameでの描画タイミング中は DOM.outerHTMLを変更できないため |
| 208 | 107 | // 処理ロジック上のまま削除処理を実行する |
| 209 | 108 | // this.renderFunc.enqueue( this.renderClearClingingPartner.bind(this) ); |
| 210 | - this.debuglog("clearClingingPartner() renderFunc size=" + this.renderFunc.size()); | |
| 109 | + this.debuglog("clearClingingPartner()"); | |
| 211 | 110 | |
| 212 | 111 | this.renderClearClingingPartner(); |
| 213 | 112 | } |
| @@ -242,8 +141,23 @@ | ||
| 242 | 141 | this.clearClingingPartner(); |
| 243 | 142 | return; |
| 244 | 143 | } |
| 245 | - // Focus先 変更 | |
| 246 | - else if (this.clingingPartner != dom) { | |
| 144 | + | |
| 145 | + // Focus対象チェック | |
| 146 | + let result = dom.classList.contains('DispBase'); | |
| 147 | + if (false == result) { | |
| 148 | + console.error('フォーカス先要素 誤り objid=' + dom.dataset.objid + ', className=' + dom.className); | |
| 149 | + // 誤って子要素が指定されている可能性があるため、treeを遡って検索 | |
| 150 | + dom = findClassNameParent('DispBase', dom); | |
| 151 | + if (null == dom) { | |
| 152 | + console.error('フォーカス先要素 誤り (フォーカス先検索も失敗)'); | |
| 153 | + this.clearClingingPartner(); | |
| 154 | + return; | |
| 155 | + } | |
| 156 | + } | |
| 157 | + | |
| 158 | + | |
| 159 | + // Focus先 変更 | |
| 160 | + if (this.clingingPartner != dom) { | |
| 247 | 161 | // 現在の情報をクリア |
| 248 | 162 | this.clearClingingPartner(); |
| 249 | 163 | // 新しいFocus先に変更 |
| @@ -256,17 +170,26 @@ | ||
| 256 | 170 | // Event handler ------------------------- |
| 257 | 171 | onMouseDownScale(evt) { |
| 258 | 172 | this.debuglog('onMouseDownScale'); |
| 173 | + let eleFocus = this.getFocusdElements(); | |
| 174 | + if (eleFocus < 2) return; | |
| 175 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 176 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 259 | 177 | |
| 260 | 178 | // Mouse eventをappAreaからScalerに渡してもらうように設定 |
| 261 | - window.appArea.setMouseEventObj(this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 179 | + window.appArea.setMouseEventObj(null, this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 262 | 180 | |
| 263 | 181 | // 移動元として座標を保持 |
| 264 | - this.scaleStartWidth = parseInt(this.clingingPartner.style.width); | |
| 265 | - this.scaleStartHeight = parseInt(this.clingingPartner.style.height); | |
| 182 | + this.scaleStartWidth = parseInt(eleFocus[0].style.width); | |
| 183 | + this.scaleStartHeight = parseInt(eleFocus[0].style.height); | |
| 266 | 184 | this.startDragX = evt.pageX; |
| 267 | 185 | this.startDragY = evt.pageY; |
| 268 | 186 | } |
| 269 | 187 | mouseMoveScale(evt) { |
| 188 | + let eleFocus = this.getFocusdElements(); | |
| 189 | + if (eleFocus < 2) return; | |
| 190 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 191 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 192 | + | |
| 270 | 193 | // 画像の仮変形 |
| 271 | 194 | this.endDragX = evt.pageX; |
| 272 | 195 | this.endDragY = evt.pageY; |
| @@ -276,30 +199,33 @@ | ||
| 276 | 199 | |
| 277 | 200 | switch(1){ |
| 278 | 201 | case 0: // 領域サイズ変更のみ |
| 279 | - this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 202 | +// this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 203 | + window.renderLoop.requestRenderFunc(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 280 | 204 | break; |
| 281 | 205 | case 1: // 縦倍率に合わせfont sizeも変更 |
| 282 | 206 | { |
| 283 | - let orgwidth = parseInt(this.clingingPartner.dataset.orgwidth); | |
| 284 | - let orgheight = parseInt(this.clingingPartner.dataset.orgheight); | |
| 207 | + let orgheight = parseInt(eleFocus[1].dataset.orgheight); | |
| 285 | 208 | let scaleY = (this.scaleStartHeight + moveY) / orgheight * 100; // ★さらに初期倍率設定値を掛ける必要がある |
| 286 | - this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY, scaleY)); | |
| 209 | +// this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY, scaleY)); | |
| 210 | + window.renderLoop.requestRenderFunc(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY, scaleY)); | |
| 287 | 211 | } |
| 288 | 212 | break; |
| 289 | 213 | } |
| 290 | 214 | } |
| 291 | 215 | renderMouseMoveScale(width, height, scalefont) { |
| 292 | - this.clingingPartner.style.opacity = 0.4; | |
| 216 | + let eleFocus = this.getFocusdElements(); | |
| 217 | + if (eleFocus < 2) return; | |
| 218 | + eleFocus[1].style.opacity = 0.4; | |
| 293 | 219 | |
| 294 | 220 | switch(1){ |
| 295 | 221 | case 0: |
| 296 | - this.clingingPartner.style.width = width + "px"; | |
| 297 | - this.clingingPartner.style.height = height + "px"; | |
| 222 | + eleFocus[0].style.width = width + "px"; | |
| 223 | + eleFocus[0].style.height = height + "px"; | |
| 298 | 224 | break; |
| 299 | 225 | case 1: |
| 300 | - this.clingingPartner.style.width = width + "px"; | |
| 301 | - this.clingingPartner.style.height = height + "px"; | |
| 302 | - this.clingingPartner.style.fontSize = scalefont + '%'; | |
| 226 | + eleFocus[0].style.width = width + "px"; | |
| 227 | + eleFocus[0].style.height = height + "px"; | |
| 228 | + eleFocus[1].style.fontSize = scalefont + '%'; | |
| 303 | 229 | break; |
| 304 | 230 | } |
| 305 | 231 | } |
| @@ -306,8 +232,13 @@ | ||
| 306 | 232 | mouseUpScale(evt) { |
| 307 | 233 | this.debuglog('mouseUpScale'); |
| 308 | 234 | // Mouse event callback設定をクリア |
| 309 | - window.appArea.setMouseEventObj(null, null); | |
| 235 | + window.appArea.setMouseEventObj(null, null, null); | |
| 310 | 236 | |
| 237 | + let eleFocus = this.getFocusdElements(); | |
| 238 | + if (eleFocus < 2) return; | |
| 239 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 240 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 241 | + | |
| 311 | 242 | // 画像の仮変形 |
| 312 | 243 | this.endDragX = evt.pageX; |
| 313 | 244 | this.endDragY = evt.pageY; |
| @@ -317,7 +248,7 @@ | ||
| 317 | 248 | |
| 318 | 249 | let rectFrom = new rectData(); |
| 319 | 250 | let rectTo = new rectData(); |
| 320 | - rectFrom.setLTWH(parseInt(this.clingingPartner.style.left), parseInt(this.clingingPartner.style.top), this.scaleStartWidth, this.scaleStartHeight); | |
| 251 | + rectFrom.setLTWH(parseInt(eleFocus[0].style.left), parseInt(eleFocus[0].style.top), this.scaleStartWidth, this.scaleStartHeight); | |
| 321 | 252 | rectTo.setLTWH(rectFrom.left, rectFrom.top, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY); |
| 322 | 253 | |
| 323 | 254 | let scaleY = 1.0; |
| @@ -326,8 +257,8 @@ | ||
| 326 | 257 | break; |
| 327 | 258 | case 1: // 縦倍率に合わせfont sizeも変更 |
| 328 | 259 | { |
| 329 | - let orgwidth = parseInt(this.clingingPartner.dataset.orgwidth); | |
| 330 | - let orgheight = parseInt(this.clingingPartner.dataset.orgheight); | |
| 260 | + let orgwidth = parseInt(eleFocus[1].dataset.orgwidth); | |
| 261 | + let orgheight = parseInt(eleFocus[1].dataset.orgheight); | |
| 331 | 262 | scaleY = (this.scaleStartHeight + moveY) / orgheight * 100; // ★さらに初期倍率設定値を掛ける必要がある |
| 332 | 263 | } |
| 333 | 264 | break; |
| @@ -335,7 +266,7 @@ | ||
| 335 | 266 | |
| 336 | 267 | // Scale Command発行 |
| 337 | 268 | let cmd = new CCommandObj(); |
| 338 | - cmd.createCommand(cmdType.request, cmdAddress.Focus, cmdAddress.ObjIDMgr, cmdCmd.scalebox, this.clingingPartner.dataset.objid, rectFrom, rectTo, scaleY, 5); | |
| 269 | + cmd.createCommand(cmdType.request, cmdAddress.Focus, cmdAddress.ObjIDMgr, cmdCmd.scalebox, eleFocus[0].dataset.objid, rectFrom, rectTo, scaleY, 5); | |
| 339 | 270 | this.debuglog("postToWorker"); |
| 340 | 271 | window.postToWorker.post(cmd); |
| 341 | 272 | } |
| @@ -342,40 +273,75 @@ | ||
| 342 | 273 | |
| 343 | 274 | onMouseDownRoll(evt) { |
| 344 | 275 | this.debuglog('onMouseDownRoll'); |
| 276 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 277 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 345 | 278 | |
| 346 | 279 | // Mouse eventをappAreaからRollerに渡してもらうように設定 |
| 347 | - window.appArea.setMouseEventObj(this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 280 | + window.appArea.setMouseEventObj(null, this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 348 | 281 | } |
| 349 | 282 | mouseMoveRoll(evt) { |
| 350 | - let x1 = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; | |
| 351 | - let y1 = parseInt(this.clingingPartner.style.top) + parseInt(this.clingingPartner.style.height) / 2; | |
| 283 | + let eleFocus = this.getFocusdElements(); | |
| 284 | + if (eleFocus < 2) return; | |
| 285 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 286 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 287 | + | |
| 288 | + let x1 = parseInt(eleFocus[0].style.left) + parseInt(eleFocus[0].style.width) / 2; | |
| 289 | + let y1 = parseInt(eleFocus[0].style.top) + parseInt(eleFocus[0].style.height) / 2; | |
| 352 | 290 | let x2 = evt.pageX; |
| 353 | 291 | let y2 = evt.pageY; |
| 354 | 292 | let degree = angle(x2, y2, x1, y1); |
| 355 | 293 | |
| 356 | - this.renderFunc.enqueue(this.renderMouseMoveRoll.bind(this, degree)); | |
| 294 | +// this.renderFunc.enqueue(this.renderMouseMoveRoll.bind(this, degree)); | |
| 295 | + window.renderLoop.requestRenderFunc(this.renderMouseMoveRoll.bind(this, degree)); | |
| 357 | 296 | } |
| 358 | 297 | renderMouseMoveRoll(degree) { |
| 359 | - this.clingingPartner.style.transform = 'rotateZ(' + degree + 'deg);'; | |
| 298 | + let eleFocus = this.getFocusdElements(); | |
| 299 | + if (eleFocus < 2) return; | |
| 300 | + | |
| 301 | + eleFocus[0].style.transform = 'rotateZ(' + degree + 'deg);'; | |
| 360 | 302 | } |
| 361 | 303 | mouseUpRoll(evt) { |
| 362 | 304 | this.debuglog('mouseUpRoll'); |
| 363 | 305 | // Mouse event callback設定をクリア |
| 364 | - window.appArea.setMouseEventObj(null, null); | |
| 306 | + window.appArea.setMouseEventObj(null, null, null); | |
| 307 | + let eleFocus = this.getFocusdElements(); | |
| 308 | + if (eleFocus < 2) return; | |
| 309 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 310 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 365 | 311 | |
| 366 | - let x1 = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; | |
| 367 | - let y1 = parseInt(this.clingingPartner.style.top) + parseInt(this.clingingPartner.style.height) / 2; | |
| 312 | + let x1 = parseInt(eleFocus[0].style.left) + parseInt(eleFocus[0].style.width) / 2; | |
| 313 | + let y1 = parseInt(eleFocus[0].style.top) + parseInt(eleFocus[0].style.height) / 2; | |
| 368 | 314 | let x2 = evt.pageX; |
| 369 | 315 | let y2 = evt.pageY; |
| 370 | 316 | let degree = angle(x2, y2, x1, y1); |
| 371 | 317 | // this.debuglog('■■ x1=' + x1 + ', y1=' + y1 + ',\nx2=' + x2 + ', y2=' + y2 + '\nangle=' + degree); |
| 372 | - // window.ObjIDMgr.rollbox( this.clingingPartner.dataset.objid, degree ); // debug用 設定情報で直接表示 | |
| 318 | + // window.ObjIDMgr.rollbox( eleFocus[0].dataset.objid, degree ); // debug用 設定情報で直接表示 | |
| 373 | 319 | |
| 374 | 320 | // Rotate command発行 |
| 375 | 321 | let cmd = new CCommandObj(); |
| 376 | - cmd.createCommand(cmdType.request, cmdAddress.Focus, cmdAddress.ObjIDMgr, cmdCmd.rollbox, this.clingingPartner.dataset.objid, degree, null, null, 6); | |
| 322 | + cmd.createCommand(cmdType.request, cmdAddress.Focus, cmdAddress.ObjIDMgr, cmdCmd.rollbox, eleFocus[0].dataset.objid, degree, null, null, 6); | |
| 377 | 323 | this.debuglog("postToWorker"); |
| 378 | 324 | window.postToWorker.post(cmd); |
| 379 | 325 | } |
| 380 | 326 | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + getFocusdElements() { | |
| 334 | + let eleBase = this.clingingPartner; | |
| 335 | + if (null == eleBase) { | |
| 336 | + console.error('変形処理失敗 操作対象要素が見つからない PartsFocus'); | |
| 337 | + return []; | |
| 338 | + } | |
| 339 | + if (eleBase.children.length < 1) { | |
| 340 | + console.error('変形処理失敗 表示要素が見つからない PartsFocus base element objid=' + eleBalse.dataset.objid + ', className=' + eleBase.className); | |
| 341 | + return []; | |
| 342 | + } | |
| 343 | + let eleDisp = eleBase.children[0]; | |
| 344 | + | |
| 345 | + return [eleBase, eleDisp]; | |
| 346 | + } | |
| 381 | 347 | } // class CPartsFocus |
| @@ -26,10 +26,27 @@ | ||
| 26 | 26 | |
| 27 | 27 | // 操作関数 ----------------------------------- |
| 28 | 28 | |
| 29 | - // Mouse eventを処理するObj | |
| 30 | - setMouseEventObj(mouseMove, mouseUp) { | |
| 31 | - this.debuglog('setMouseEventObj callbackMove=' + ((null != mouseMove)? mouseMove.name: 'null') + ', callbackUp=' + ((null != mouseUp)? mouseUp.name: 'null')); | |
| 29 | + // Mouse eventを拾ったときに通知してほしいときにセット | |
| 30 | + // 上書きすると前に設定されていた callbackが消えます | |
| 31 | + // callback: function mouseMove( evt ) move eventの evt.targetは目的のelementでない場合が多いため検索しない | |
| 32 | + // callback: function mouseUp( evt, strclassElement ) elementが見つからなければ null | |
| 33 | + setMouseEventObj( | |
| 34 | + strclass, // mouse up callback 第2引数 targetとして返してほしいelementが持つ css class名 | |
| 35 | + mouseMove, // mouse moveで呼んでほしい関数 or null | |
| 36 | + mouseUp // mouse upで呼んでほしい関数 or null | |
| 37 | + ) { | |
| 38 | + this.debuglog('setMouseEventObj strclass=' + strclass + ', callbackMove=' + ((null != mouseMove)? mouseMove.name: 'null') + ', callbackUp=' + ((null != mouseUp)? mouseUp.name: 'null')); | |
| 32 | 39 | |
| 40 | + // Callbackを上書きしてしまう場合はエラー出力し、ひとまず処理を継続 | |
| 41 | + if (null != mouseMove || null != mouseUp) { | |
| 42 | + if (null != this.mouseMoveFunc || null != this.mouseUpFunc) { | |
| 43 | + console.error('マウスイベント callback設定上書き \n\ | |
| 44 | +Before strclass=' + this.strclass + 'callbackMove=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', callbackUp=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null') + '\n\ | |
| 45 | +After strclass=' + strclass + 'callbackMove=' + ((null != mouseMove) ? mouseMove.name : 'null') + ', callbackUp=' + ((null != mouseUp) ? mouseUp.name : 'null')); | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 49 | + this.strclass = strclass; | |
| 33 | 50 | this.mouseMoveFunc = mouseMove; |
| 34 | 51 | this.mouseUpFunc = mouseUp; |
| 35 | 52 | } |
| @@ -38,25 +55,27 @@ | ||
| 38 | 55 | |
| 39 | 56 | // ■マウス左ボタン押下 (Drag処理) |
| 40 | 57 | onMouseDown(evt) { |
| 58 | + this.debuglog('マウスクリック onMouseDown()'); | |
| 41 | 59 | } |
| 42 | 60 | // ■ マウス移動 (ドラッグ中) |
| 43 | 61 | onMouseMove(evt) { |
| 44 | - // ★ evt.targetが期待するelementかチェックする必要がある | |
| 45 | - // ★ 期待するelementではない場合、DOM treeを辿って親elementから該当elementを探す必要がある | |
| 46 | 62 | |
| 47 | 63 | if (null != this.mouseMoveFunc) { |
| 48 | 64 | this.mouseMoveFunc(evt); |
| 49 | - return; | |
| 50 | 65 | } |
| 51 | 66 | } |
| 67 | + | |
| 52 | 68 | // ■ ドロップ処理 |
| 53 | 69 | onMouseUp(evt) { |
| 54 | - // ★ evt.targetが期待するelementかチェックする必要がある | |
| 55 | - // ★ 期待するelementではない場合、DOM treeを辿って親elementから該当elementを探す必要がある | |
| 70 | + this.debuglog('マウスアップ onMouseUp() findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); | |
| 71 | + let e = findClassNameParent(this.strclass, evt.target); | |
| 72 | + if (null == e) { | |
| 73 | + console.error('マウスアップ 指定要素が見つからない findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); | |
| 74 | + // ひとまず処理を継続する | |
| 75 | + } | |
| 56 | 76 | |
| 57 | 77 | if (null != this.mouseUpFunc) { |
| 58 | - this.mouseUpFunc(evt); | |
| 59 | - return; | |
| 78 | + this.mouseUpFunc(evt, e); | |
| 60 | 79 | } |
| 61 | 80 | } |
| 62 | 81 |
| @@ -78,10 +78,10 @@ | ||
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | |
| 81 | + // 描画ループ | |
| 82 | + window.renderLoop = new RenderLoop(); | |
| 81 | 83 | |
| 82 | - | |
| 83 | - | |
| 84 | - | |
| 84 | + /* | |
| 85 | 85 | // 画像読み込み等は待たずに実行開始 |
| 86 | 86 | window.startTime = window.performance.now(); |
| 87 | 87 | window.frameLength = 6.0; |
| @@ -91,7 +91,7 @@ | ||
| 91 | 91 | // let frame = Math.floor((nowTime - window.startTime) / (1000.0 / 60.0) % window.frameLength); |
| 92 | 92 | |
| 93 | 93 | // Canvas area描画 (div tag) |
| 94 | - window.displayField.render(); | |
| 94 | +// window.displayField.render(); | |
| 95 | 95 | // 各表示要素の描画 (div, img tag) |
| 96 | 96 | window.ObjIDMgr.renderAll(); |
| 97 | 97 |
| @@ -103,10 +103,10 @@ | ||
| 103 | 103 | |
| 104 | 104 | requestAnimationFrame( renderLoop ); |
| 105 | 105 | })(); |
| 106 | + */ | |
| 106 | 107 | |
| 107 | 108 | |
| 108 | 109 | |
| 109 | - | |
| 110 | 110 | // worker threadからの Message受信関数 |
| 111 | 111 | // UI threadで処理が必要な commandが送られてくる |
| 112 | 112 | function receiveWorkerMessage(evt) { |
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | constructor() { |
| 11 | 11 | this.DOMobject = []; |
| 12 | 12 | this.draggingDOM = null; |
| 13 | - this.renderFunc = new Queue(); | |
| 13 | +// this.renderFunc = new Queue(); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | debuglog(str) { |
| @@ -146,7 +146,7 @@ | ||
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - | |
| 149 | + /* | |
| 150 | 150 | // 描画関数 --------------------- |
| 151 | 151 | |
| 152 | 152 | render() { |
| @@ -155,6 +155,7 @@ | ||
| 155 | 155 | renderFunction(); |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | + */ | |
| 158 | 159 | |
| 159 | 160 | // Event handler ----------------------- |
| 160 | 161 |
| @@ -202,8 +203,8 @@ | ||
| 202 | 203 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 203 | 204 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 204 | 205 | |
| 205 | - // Mouse eventをappAreaからCSSPalに渡してもらうように設定 | |
| 206 | - window.appArea.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 206 | + // Mouse eventをappAreaからCSSPalに渡してもらうように設定 (evt.targetは必ずpalette要素である前提。子要素なし。) | |
| 207 | + window.appArea.setMouseEventObj(evt.target.dataset.objid, this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 207 | 208 | |
| 208 | 209 | // Drag対象を保持 |
| 209 | 210 | this.draggingDOM = evt.target; |
| @@ -229,7 +230,8 @@ | ||
| 229 | 230 | moveX = this.startElementX + moveX; |
| 230 | 231 | moveY = this.startElementY + moveY; |
| 231 | 232 | |
| 232 | - this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 233 | +// this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 234 | + window.renderLoop.requestRenderFunc(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 233 | 235 | //this.renderMoveDragging(moveX, moveY); |
| 234 | 236 | } |
| 235 | 237 | renderMoveDragging(x, y) { |
| @@ -256,7 +258,7 @@ | ||
| 256 | 258 | // Drag中 element情報をクリア |
| 257 | 259 | this.draggingDOM = null; |
| 258 | 260 | // Mouse event callback設定をクリア |
| 259 | - window.appArea.setMouseEventObj(null, null); | |
| 261 | + window.appArea.setMouseEventObj(null, null, null); | |
| 260 | 262 | |
| 261 | 263 | // マウス座標直下にある要素を検索 |
| 262 | 264 | // (evt.targetは自分を指してしまうため) |
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | this.typeAction = 2; |
| 17 | 17 | |
| 18 | 18 | this.DOMobject = []; // bg,text,action |
| 19 | - this.renderFunc = new Queue(); | |
| 19 | +// this.renderFunc = new Queue(); | |
| 20 | 20 | } |
| 21 | 21 | debuglog(str) { |
| 22 | 22 | debuglog('【PalGroup】 ' + str); |
| @@ -44,7 +44,7 @@ | ||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - | |
| 47 | + /* | |
| 48 | 48 | // 描画関数 --------------------- |
| 49 | 49 | |
| 50 | 50 | render() { |
| @@ -53,14 +53,14 @@ | ||
| 53 | 53 | renderFunction(); |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | + */ | |
| 56 | 57 | |
| 57 | 58 | |
| 58 | - | |
| 59 | 59 | // Event handler ----------------------- |
| 60 | 60 | |
| 61 | 61 | onMouseDown(evt) { |
| 62 | 62 | // Mouse eventをappAreaからCSSPalに渡してもらうように設定 |
| 63 | - window.appArea.setMouseEventObj(this.mouseMove.bind(this), null); | |
| 63 | + window.appArea.setMouseEventObj(null, this.mouseMove.bind(this), null); | |
| 64 | 64 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 65 | 65 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 66 | 66 |
| @@ -88,7 +88,8 @@ | ||
| 88 | 88 | moveX = this.startElementX + moveX; |
| 89 | 89 | moveY = this.startElementY + moveY; |
| 90 | 90 | |
| 91 | - this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 91 | +// this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 92 | + window.renderLoop.requestRenderFunc(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 92 | 93 | //this.renderMoveDragging(moveX, moveY); |
| 93 | 94 | } |
| 94 | 95 | renderMoveDragging(x, y) { |
| @@ -106,7 +107,7 @@ | ||
| 106 | 107 | // Drag中 element情報をクリア |
| 107 | 108 | this.draggingDOM = null; |
| 108 | 109 | // Mouse event callback設定をクリア |
| 109 | - window.appArea.setMouseEventObj(null, null); | |
| 110 | + window.appArea.setMouseEventObj(null, null, null); | |
| 110 | 111 | } |
| 111 | 112 | |
| 112 | 113 |