JavaScriptを色々あれこれしようとするがひたすら失敗を繰り返している
| Revision | 26 (tree) |
|---|---|
| Time | 2016-11-24 08:59:35 |
| Author | |
マウスイベントハンドラ担当を変更
パレットグループを移動できるように
| @@ -30,8 +30,17 @@ | ||
| 30 | 30 | [data-objid] { |
| 31 | 31 | transition: transform 2s linear 0s; |
| 32 | 32 | } |
| 33 | -*/ | |
| 33 | +*/ | |
| 34 | 34 | |
| 35 | + | |
| 36 | + #apparea{ | |
| 37 | + display: block; | |
| 38 | + width: 100%; height: 100%; | |
| 39 | + border: none; | |
| 40 | + margin: 0; padding: 0; | |
| 41 | + background-color: gainsboro; | |
| 42 | + } | |
| 43 | + | |
| 35 | 44 | /* キャンバス要素の定義 */ |
| 36 | 45 | #DispField{ |
| 37 | 46 | display:block; |
| @@ -38,6 +47,7 @@ | ||
| 38 | 47 | width:400px; height:300px; |
| 39 | 48 | border:1px solid black; |
| 40 | 49 | margin: 10px; |
| 50 | + background-color: white; | |
| 41 | 51 | } |
| 42 | 52 | |
| 43 | 53 |
| @@ -8,102 +8,198 @@ | ||
| 8 | 8 | <link href="css/default.css" rel="stylesheet" /> |
| 9 | 9 | </head> |
| 10 | 10 | <body> |
| 11 | - <!-- 編集領域 --> | |
| 12 | - <div id="DispField" data-objid="DisplayField" data-focus="true"> | |
| 13 | - </div> | |
| 14 | - <!-- 固定ボタン (選択要素の削除, 保存, …) --> | |
| 15 | - <button type=button class="pal" data-objid="pal" data-palid="0" data-value="0xff000001">削除</button> | |
| 16 | - <button type=button class="pal" data-objid="pal" data-palid="1" data-value="0x00ff0001">設定保存</button> | |
| 17 | - <button type=button class="pal" data-objid="pal" data-palid="2" data-value="0x0000ff01">設定Drop</button> | |
| 18 | - <button type=button class="pal" data-objid="pal" data-palid="3" data-value="0xffffff01">アニメ停止</button> | |
| 19 | - <button type=button class="pal" data-objid="pal" data-palid="4" data-value="0x00000000">button5</button> | |
| 20 | - <a href="#" id="save" download="savefilename.txt">画像保存</a><br /> | |
| 21 | 11 | |
| 22 | - <!-- Palette --> | |
| 23 | - <style id="stylepalbg"> | |
| 24 | - .palbg0 { background-image: url(dummy.png); } | |
| 25 | - .palbg1 { background-image: url(dummy.png); } | |
| 26 | - .palbg2 { background-image: url(dummy.png); } | |
| 27 | - .palbg3 { background-image: url(dummy.png); } | |
| 28 | - .palbg4 { background-image: url(dummy.png); } | |
| 29 | - </style> | |
| 30 | - <style id="stylepaltxtcol"> | |
| 31 | - .paltxtcol0 { color: black; } | |
| 32 | - .paltxtcol1 { color: red; } | |
| 33 | - .paltxtcol2 { color: blue; } | |
| 34 | - .paltxtcol3 { color: green; } | |
| 35 | - .paltxtcol4 { color: brown; } | |
| 36 | - </style> | |
| 37 | - <style id="stylepalact"> | |
| 38 | - /* animation指定,keyframe指定, … と交互に設定されている想定 */ | |
| 39 | - /* palette css と keyframe は必ず1対1.例えkeyframeが使いまわせたとしても。 */ | |
| 40 | - .palact0 { animation: animeY1 0.5s ease-in 0.3s 1 normal; } | |
| 41 | - @keyframes animeY1 { | |
| 42 | - 0% {transform: translateY(-60px) translateX(-30px);} | |
| 43 | - 10% {transform: translateY(20px) translateX(30px);} | |
| 44 | - 20% {transform: translateY(-40px) translateX(-20px);} | |
| 45 | - 30% {transform: translateY(50px) translateX(-10px);} | |
| 46 | - 40% {transform: translateY(-40px) translateX(20px);} | |
| 47 | - 50% {transform: translateY(30px) translateX(-15px);} | |
| 48 | - 60% {transform: translateY(-25px) translateX(0px);} | |
| 49 | - 70% {transform: translateY(15px) translateX(-15px);} | |
| 50 | - 80% {transform: translateY(-10px) translateX(10px);} | |
| 51 | - 90% {transform: translateY(0px) translateX(-5px);} | |
| 52 | - 100% {transform: translateY(0px) translateX(0px);} | |
| 53 | - } | |
| 12 | + <div id="apparea" data-objid="apparea"> | |
| 13 | + <!-- 編集領域 --> | |
| 14 | + <div id="DispField" data-objid="DisplayField" data-focus="true"> | |
| 15 | + </div> | |
| 16 | + <!-- 固定ボタン (選択要素の削除, 保存, …) --> | |
| 17 | + <button type=button class="pal" data-objid="pal" data-palid="0" data-value="0xff000001">削除</button> | |
| 18 | + <button type=button class="pal" data-objid="pal" data-palid="1" data-value="0x00ff0001">設定保存</button> | |
| 19 | + <button type=button class="pal" data-objid="pal" data-palid="2" data-value="0x0000ff01">設定Drop</button> | |
| 20 | + <button type=button class="pal" data-objid="pal" data-palid="3" data-value="0xffffff01">アニメ停止</button> | |
| 21 | + <button type=button class="pal" data-objid="pal" data-palid="4" data-value="0x00000000">button5</button> | |
| 22 | + <a href="#" id="save" download="savefilename.txt">画像保存</a><br /> | |
| 54 | 23 | |
| 55 | - .palact1 { animation: animeact1 2s ease-in 0.3s 1 normal; } | |
| 56 | - @keyframes animeact1 { to {color:black;} } | |
| 24 | + <!-- Palette --> | |
| 25 | + <style id="stylepalbg"> | |
| 26 | + .palbg0 { | |
| 27 | + background-image: url(dummy.png); | |
| 28 | + } | |
| 57 | 29 | |
| 58 | - .palact2 { animation: animeact2 2s ease-in 0.3s 1 normal; } | |
| 59 | - @keyframes animeact2 { to {color:black;} } | |
| 30 | + .palbg1 { | |
| 31 | + background-image: url(dummy.png); | |
| 32 | + } | |
| 60 | 33 | |
| 61 | - .palact3 { animation: animeact3 2s ease-in 0.3s 1 normal; } | |
| 62 | - @keyframes animeact3 { to {color:black;} } | |
| 34 | + .palbg2 { | |
| 35 | + background-image: url(dummy.png); | |
| 36 | + } | |
| 63 | 37 | |
| 64 | - .palact4 { animation: animeact4 2s ease-in 0.3s 1 normal; } | |
| 65 | - @keyframes animeact4 { to {color:black;} } | |
| 66 | - </style> | |
| 38 | + .palbg3 { | |
| 39 | + background-image: url(dummy.png); | |
| 40 | + } | |
| 67 | 41 | |
| 68 | - <fieldset class="palgroup palgrouphorizon" data-objid="palgroup0"> | |
| 69 | - <legend class="pallegend"> Background <button>横</button> </legend> | |
| 70 | - <div class="palbg palbg0" data-objid="palbg0" data-palid="0"></div> | |
| 71 | - <div class="palbg palbg1" data-objid="palbg1" data-palid="1"></div> | |
| 72 | - <div class="palbg palbg2" data-objid="palbg2" data-palid="2"></div> | |
| 73 | - <div class="palbg palbg3" data-objid="palbg3" data-palid="3"></div> | |
| 74 | - <div class="palbg palbg4" data-objid="palbg4" data-palid="4"></div> | |
| 75 | - </fieldset> | |
| 76 | - <br /> | |
| 42 | + .palbg4 { | |
| 43 | + background-image: url(dummy.png); | |
| 44 | + } | |
| 45 | + </style> | |
| 46 | + <style id="stylepaltxtcol"> | |
| 47 | + .paltxtcol0 { | |
| 48 | + color: black; | |
| 49 | + } | |
| 77 | 50 | |
| 78 | - <fieldset class="palgroup palgrouphorizon" data-objid="palgroup1"> | |
| 79 | - <legend class="pallegend"> Text Color <button>横</button> </legend> | |
| 80 | - <div class="paltxtcol paltxtcol0" data-objid="paltxtcol0" data-palid="0">あ</div> | |
| 81 | - <div class="paltxtcol paltxtcol1" data-objid="paltxtcol1" data-palid="1">あ</div> | |
| 82 | - <div class="paltxtcol paltxtcol2" data-objid="paltxtcol2" data-palid="2">あ</div> | |
| 83 | - <div class="paltxtcol paltxtcol3" data-objid="paltxtcol3" data-palid="3">あ</div> | |
| 84 | - <div class="paltxtcol paltxtcol4" data-objid="paltxtcol4" data-palid="4">あ</div> | |
| 85 | - </fieldset> | |
| 51 | + .paltxtcol1 { | |
| 52 | + color: red; | |
| 53 | + } | |
| 86 | 54 | |
| 55 | + .paltxtcol2 { | |
| 56 | + color: blue; | |
| 57 | + } | |
| 58 | + | |
| 59 | + .paltxtcol3 { | |
| 60 | + color: green; | |
| 61 | + } | |
| 62 | + | |
| 63 | + .paltxtcol4 { | |
| 64 | + color: brown; | |
| 65 | + } | |
| 66 | + </style> | |
| 67 | + <style id="stylepalact"> | |
| 68 | + /* animation指定,keyframe指定, … と交互に設定されている想定 */ | |
| 69 | + /* palette css と keyframe は必ず1対1.例えkeyframeが使いまわせたとしても。 */ | |
| 70 | + .palact0 { | |
| 71 | + animation: animeY1 0.5s ease-in 0.3s 1 normal; | |
| 72 | + } | |
| 73 | + | |
| 74 | + @keyframes animeY1 { | |
| 75 | + 0% { | |
| 76 | + transform: translateY(-60px) translateX(-30px); | |
| 77 | + } | |
| 78 | + | |
| 79 | + 10% { | |
| 80 | + transform: translateY(20px) translateX(30px); | |
| 81 | + } | |
| 82 | + | |
| 83 | + 20% { | |
| 84 | + transform: translateY(-40px) translateX(-20px); | |
| 85 | + } | |
| 86 | + | |
| 87 | + 30% { | |
| 88 | + transform: translateY(50px) translateX(-10px); | |
| 89 | + } | |
| 90 | + | |
| 91 | + 40% { | |
| 92 | + transform: translateY(-40px) translateX(20px); | |
| 93 | + } | |
| 94 | + | |
| 95 | + 50% { | |
| 96 | + transform: translateY(30px) translateX(-15px); | |
| 97 | + } | |
| 98 | + | |
| 99 | + 60% { | |
| 100 | + transform: translateY(-25px) translateX(0px); | |
| 101 | + } | |
| 102 | + | |
| 103 | + 70% { | |
| 104 | + transform: translateY(15px) translateX(-15px); | |
| 105 | + } | |
| 106 | + | |
| 107 | + 80% { | |
| 108 | + transform: translateY(-10px) translateX(10px); | |
| 109 | + } | |
| 110 | + | |
| 111 | + 90% { | |
| 112 | + transform: translateY(0px) translateX(-5px); | |
| 113 | + } | |
| 114 | + | |
| 115 | + 100% { | |
| 116 | + transform: translateY(0px) translateX(0px); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + | |
| 120 | + .palact1 { | |
| 121 | + animation: animeact1 2s ease-in 0.3s 1 normal; | |
| 122 | + } | |
| 123 | + | |
| 124 | + @keyframes animeact1 { | |
| 125 | + to { | |
| 126 | + color: black; | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + .palact2 { | |
| 131 | + animation: animeact2 2s ease-in 0.3s 1 normal; | |
| 132 | + } | |
| 133 | + | |
| 134 | + @keyframes animeact2 { | |
| 135 | + to { | |
| 136 | + color: black; | |
| 137 | + } | |
| 138 | + } | |
| 139 | + | |
| 140 | + .palact3 { | |
| 141 | + animation: animeact3 2s ease-in 0.3s 1 normal; | |
| 142 | + } | |
| 143 | + | |
| 144 | + @keyframes animeact3 { | |
| 145 | + to { | |
| 146 | + color: black; | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + .palact4 { | |
| 151 | + animation: animeact4 2s ease-in 0.3s 1 normal; | |
| 152 | + } | |
| 153 | + | |
| 154 | + @keyframes animeact4 { | |
| 155 | + to { | |
| 156 | + color: black; | |
| 157 | + } | |
| 158 | + } | |
| 159 | + </style> | |
| 160 | + | |
| 161 | + <fieldset class="palgroup palgrouphorizon" data-objid="palgroup0"> | |
| 162 | + <legend class="pallegend"> Background <button>横</button> </legend> | |
| 163 | + <div class="palbg palbg0" data-objid="palbg0" data-palid="0"></div> | |
| 164 | + <div class="palbg palbg1" data-objid="palbg1" data-palid="1"></div> | |
| 165 | + <div class="palbg palbg2" data-objid="palbg2" data-palid="2"></div> | |
| 166 | + <div class="palbg palbg3" data-objid="palbg3" data-palid="3"></div> | |
| 167 | + <div class="palbg palbg4" data-objid="palbg4" data-palid="4"></div> | |
| 168 | + </fieldset> | |
| 87 | 169 | <br /> |
| 88 | 170 | |
| 89 | - <fieldset class="palgroup palgrouphorizon" data-objid="palgroup2"> | |
| 90 | - <legend class="pallegend"> Action <span class="buttonstyle">horizon</span> </legend> | |
| 91 | - <div class="palact palact0" data-objid="palact0" data-palid="0"></div> | |
| 92 | - <div class="palact palact1" data-objid="palact1" data-palid="1"></div> | |
| 93 | - <div class="palact palact2" data-objid="palact2" data-palid="2"></div> | |
| 94 | - <div class="palact palact3" data-objid="palact3" data-palid="3"></div> | |
| 95 | - <div class="palact palact4" data-objid="palact4" data-palid="4"></div> | |
| 96 | - </fieldset> | |
| 171 | + <fieldset class="palgroup palgrouphorizon" data-objid="palgroup1"> | |
| 172 | + <legend class="pallegend"> Text Color <button>横</button> </legend> | |
| 173 | + <div class="paltxtcol paltxtcol0" data-objid="paltxtcol0" data-palid="0">あ</div> | |
| 174 | + <div class="paltxtcol paltxtcol1" data-objid="paltxtcol1" data-palid="1">あ</div> | |
| 175 | + <div class="paltxtcol paltxtcol2" data-objid="paltxtcol2" data-palid="2">あ</div> | |
| 176 | + <div class="paltxtcol paltxtcol3" data-objid="paltxtcol3" data-palid="3">あ</div> | |
| 177 | + <div class="paltxtcol paltxtcol4" data-objid="paltxtcol4" data-palid="4">あ</div> | |
| 178 | + </fieldset> | |
| 97 | 179 | |
| 180 | + <br /> | |
| 181 | + | |
| 182 | + <fieldset class="palgroup palgrouphorizon" data-objid="palgroup2"> | |
| 183 | + <legend class="pallegend"> Action <span class="buttonstyle">horizon</span> </legend> | |
| 184 | + <div class="palact palact0" data-objid="palact0" data-palid="0"></div> | |
| 185 | + <div class="palact palact1" data-objid="palact1" data-palid="1"></div> | |
| 186 | + <div class="palact palact2" data-objid="palact2" data-palid="2"></div> | |
| 187 | + <div class="palact palact3" data-objid="palact3" data-palid="3"></div> | |
| 188 | + <div class="palact palact4" data-objid="palact4" data-palid="4"></div> | |
| 189 | + </fieldset> | |
| 190 | + </div> | |
| 191 | + | |
| 98 | 192 | <script type="text/javascript" src="js/Common.js"></script> |
| 99 | 193 | <script type="text/javascript" src="js/Queue.js"></script> |
| 100 | 194 | <script type="text/javascript" src="js/CommandObj.js"></script> |
| 101 | 195 | <script type="text/javascript" src="js/UI_parts.js"></script> |
| 196 | + <script type="text/javascript" src="js/palgroup.js"></script> | |
| 102 | 197 | <script type="text/javascript" src="js/palette.js"></script> |
| 103 | 198 | <script type="text/javascript" src="js/DispObj.js"></script> |
| 104 | 199 | <script type="text/javascript" src="js/ObjIDMgr.js"></script> |
| 105 | 200 | <script type="text/javascript" src="js/ThreadMessage.js"></script> |
| 106 | 201 | <script type="text/javascript" src="js/DisplayField.js"></script> |
| 202 | + <script type="text/javascript" src="js/apparea.js"></script> | |
| 107 | 203 | <script type="text/javascript" src="js/main.js"></script> |
| 108 | 204 | </body> |
| 109 | 205 | </html> |
| @@ -1,5 +1,7 @@ | ||
| 1 | -// Worker thread | |
| 2 | -// Command処理を実行する | |
| 1 | +// CommandMgr.js | |
| 2 | +// Worker thread上で動作 | |
| 3 | +// Worker thread側でcommand処理を実行することはない(今のところ。commandが表示に関する操作ばかりのため) | |
| 4 | +// 主な機能 | |
| 3 | 5 | // ・Queuing command. |
| 4 | 6 | // ・To process the command sequentially. |
| 5 | 7 | // ・And stack to undo list. |
| @@ -1,3 +1,10 @@ | ||
| 1 | +// CommandObj.js | |
| 2 | +// 処理commandの実体 | |
| 3 | +// 主な機能 | |
| 4 | +// ・command作成 | |
| 5 | +// ・不正内容チェック | |
| 6 | +// ・Thread間 通信電文も兼ねている | |
| 7 | + | |
| 1 | 8 | const cmdType = { |
| 2 | 9 | request: 0, |
| 3 | 10 | response: 1, |
| @@ -1,3 +1,10 @@ | ||
| 1 | +// DispObj.js | |
| 2 | +// Canvas上に配置される要素 | |
| 3 | +// 主な機能 | |
| 4 | +// ・外部からのfile dropによる要素作成 | |
| 5 | +// ・Dropされたtext, imageの読み込み | |
| 6 | +// ・Drag&Dropによる要素の移動 | |
| 7 | +// ・要素の拡大縮小, 回転 | |
| 1 | 8 | |
| 2 | 9 | class CDispObj { |
| 3 | 10 | constructor() { |
| @@ -239,8 +246,8 @@ | ||
| 239 | 246 | if (0 == (evt.buttons & 0x0001)) { // 左クリックチェック |
| 240 | 247 | return; |
| 241 | 248 | } |
| 242 | - // Mouse eventをDisplayFieldからScalerに渡してもらうように設定 | |
| 243 | - window.displayField.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 249 | + // Mouse eventをappAreaからScalerに渡してもらうように設定 | |
| 250 | + window.appArea.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 244 | 251 | |
| 245 | 252 | |
| 246 | 253 | // Focus設定 |
| @@ -274,7 +281,7 @@ | ||
| 274 | 281 | mouseUp(evt) { |
| 275 | 282 | this.debuglog("mouseUp"); |
| 276 | 283 | // Mouse event処理対象をクリア |
| 277 | - window.displayField.setMouseEventObj(null, null); | |
| 284 | + window.appArea.setMouseEventObj(null, null); | |
| 278 | 285 | |
| 279 | 286 | |
| 280 | 287 | // 移動元として座標を保持 |
| @@ -1,3 +1,8 @@ | ||
| 1 | +// DisplayField.js | |
| 2 | +// Canvas部分 | |
| 3 | +// 主な機能 | |
| 4 | +// ・マウスイベント処理 (mousemove, mouseup) | |
| 5 | +// ・外部からのtext, image drop処理 (DispObj要素作成要求) | |
| 1 | 6 | |
| 2 | 7 | |
| 3 | 8 | class CDisplayField { |
| @@ -15,13 +20,13 @@ | ||
| 15 | 20 | // ■ 初期化 |
| 16 | 21 | initialize() { |
| 17 | 22 | if (null == this.DOMobject) { |
| 18 | - console.log("【DisplayField】 initialize() DOMobject is null."); | |
| 23 | + console.error("【DisplayField】 initialize() DOMobject is null."); | |
| 19 | 24 | return false; |
| 20 | 25 | } |
| 21 | 26 | this.debuglog("initialize"); |
| 22 | - this.DOMobject.addEventListener('mousemove', this.onMouseMove.bind(this), false); | |
| 23 | - this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 24 | - this.DOMobject.addEventListener('mouseup', this.onMouseUp.bind(this), false); | |
| 27 | +// this.DOMobject.addEventListener('mousemove', this.onMouseMove.bind(this), false); | |
| 28 | +// this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 29 | +// this.DOMobject.addEventListener('mouseup', this.onMouseUp.bind(this), false); | |
| 25 | 30 | this.DOMobject.addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 26 | 31 | this.DOMobject.addEventListener('dragover', this.onDragover.bind(this), false); |
| 27 | 32 | this.DOMobject.addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -29,7 +34,7 @@ | ||
| 29 | 34 | |
| 30 | 35 | |
| 31 | 36 | // 操作関数 ----------------------------------- |
| 32 | - | |
| 37 | +/* | |
| 33 | 38 | // Mouse eventを処理するObj |
| 34 | 39 | setMouseEventObj(mouseMove, mouseUp) { |
| 35 | 40 | this.debuglog('setMouseEventObj'); |
| @@ -37,9 +42,9 @@ | ||
| 37 | 42 | this.mouseMoveFunc = mouseMove; |
| 38 | 43 | this.mouseUpFunc = mouseUp; |
| 39 | 44 | } |
| 45 | +*/ | |
| 40 | 46 | |
| 41 | 47 | |
| 42 | - | |
| 43 | 48 | // ブラウザ上への描画 ------------------------- |
| 44 | 49 | render() { |
| 45 | 50 | while (0 < this.renderFunc.size()) { |
| @@ -52,7 +57,7 @@ | ||
| 52 | 57 | |
| 53 | 58 | |
| 54 | 59 | // Event handler ------------------- |
| 55 | - | |
| 60 | + /* | |
| 56 | 61 | // ■マウス左ボタン押下 (Drag処理) |
| 57 | 62 | onMouseDown(evt) { |
| 58 | 63 | } |
| @@ -76,7 +81,7 @@ | ||
| 76 | 81 | return; |
| 77 | 82 | } |
| 78 | 83 | } |
| 79 | - | |
| 84 | + */ | |
| 80 | 85 | // 表示要素の drag & drop禁止 |
| 81 | 86 | onDragStart(evt) { |
| 82 | 87 | evt.preventDefault(); |
| @@ -1,3 +1,12 @@ | ||
| 1 | +// ObjIDMgr.js | |
| 2 | +// Canvas上の表示要素 (DispObj) を管理する | |
| 3 | +// 主な機能 | |
| 4 | +// ・DispObjのリスト保持と管理 | |
| 5 | +// ・DispObjへのobjid割り当て | |
| 6 | +// ・objidから実体への変換 | |
| 7 | +// ・DispObjへのcommand処理要求 (振り分け) | |
| 8 | +// ・DispObjの描画関数呼び出し | |
| 9 | + | |
| 1 | 10 | class CObjIDMgr { |
| 2 | 11 | constructor() { |
| 3 | 12 | this.ObjIDLen = 0; |
| @@ -1,8 +1,11 @@ | ||
| 1 | -// importScripts()での読み込みは、先に定義がないとエラーになるためこのファイルを作成 | |
| 2 | -// (JavaScriptは実行時 型チェックのため定義が前後しても基本的には問題ないが | |
| 3 | -// worker thread用 import関数は読み込みと同時に実行も行うため) | |
| 1 | +// ThreadMessage.js | |
| 2 | +// Worker threadの作成、messageの送信 ★ここで受信したほうがいいのでは? | |
| 3 | +// 実体はUI thread上で動作 | |
| 4 | +// 主な機能 | |
| 5 | +// ・Worker threadへの要求はこの実体を通す (処理を追いやすく) | |
| 6 | +// ・要求commandのlog出力 (漏れなく出力するため) | |
| 7 | +// ・(将来)command構成変更が発生したときにこのclassで対応できないか検討 (影響範囲の縮小) | |
| 4 | 8 | |
| 5 | - | |
| 6 | 9 | // UI thread用 定義 |
| 7 | 10 | // Worker thead起動, post message |
| 8 | 11 | function postToWorker() { |
| @@ -1,3 +1,9 @@ | ||
| 1 | +// UI_parts.js | |
| 2 | +// Canvas上の要素選択で表示される、focusを表示 | |
| 3 | +// 主な機能 | |
| 4 | +// ・要素の周囲にfocus表示 (機能はない) | |
| 5 | +// ・Focus line上に 拡大縮小, 回転用要素表示 | |
| 6 | +// ・拡大縮小, 回転の実行 | |
| 1 | 7 | |
| 2 | 8 | // [data-focus="true"] の場合のみ CSSで borderを変更したかったが |
| 3 | 9 | // DOMに直接 style指定するとその指定が最優先となるため CSSで上書きできない |
| @@ -252,8 +258,8 @@ | ||
| 252 | 258 | onMouseDownScale(evt) { |
| 253 | 259 | this.debuglog('onMouseDownScale'); |
| 254 | 260 | |
| 255 | - // Mouse eventをDisplayFieldからScalerに渡してもらうように設定 | |
| 256 | - window.displayField.setMouseEventObj(this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 261 | + // Mouse eventをappAreaからScalerに渡してもらうように設定 | |
| 262 | + window.appArea.setMouseEventObj(this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 257 | 263 | |
| 258 | 264 | // 移動元として座標を保持 |
| 259 | 265 | this.scaleStartWidth = parseInt(this.clingingPartner.style.width); |
| @@ -301,7 +307,7 @@ | ||
| 301 | 307 | mouseUpScale(evt) { |
| 302 | 308 | this.debuglog('mouseUpScale'); |
| 303 | 309 | // Mouse event callback設定をクリア |
| 304 | - window.displayField.setMouseEventObj(null, null); | |
| 310 | + window.appArea.setMouseEventObj(null, null); | |
| 305 | 311 | |
| 306 | 312 | // 画像の仮変形 |
| 307 | 313 | this.endDragX = evt.pageX; |
| @@ -338,8 +344,8 @@ | ||
| 338 | 344 | onMouseDownRoll(evt) { |
| 339 | 345 | this.debuglog('onMouseDownRoll'); |
| 340 | 346 | |
| 341 | - // Mouse eventをDisplayFieldからRollerに渡してもらうように設定 | |
| 342 | - window.displayField.setMouseEventObj(this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 347 | + // Mouse eventをappAreaからRollerに渡してもらうように設定 | |
| 348 | + window.appArea.setMouseEventObj(this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 343 | 349 | } |
| 344 | 350 | mouseMoveRoll(evt) { |
| 345 | 351 | let x1 = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; |
| @@ -356,7 +362,7 @@ | ||
| 356 | 362 | mouseUpRoll(evt) { |
| 357 | 363 | this.debuglog('mouseUpRoll'); |
| 358 | 364 | // Mouse event callback設定をクリア |
| 359 | - window.displayField.setMouseEventObj(null, null); | |
| 365 | + window.appArea.setMouseEventObj(null, null); | |
| 360 | 366 | |
| 361 | 367 | let x1 = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; |
| 362 | 368 | let y1 = parseInt(this.clingingPartner.style.top) + parseInt(this.clingingPartner.style.height) / 2; |
| @@ -0,0 +1,65 @@ | ||
| 1 | +// apparea.js | |
| 2 | +// マウスイベントハンドリング | |
| 3 | + | |
| 4 | +class appArea { | |
| 5 | + constructor(dom) { | |
| 6 | + this.DOMobject = dom; | |
| 7 | + this.mouseMoveFunc = null; | |
| 8 | + this.mouseUpFunc = null; | |
| 9 | + } | |
| 10 | + debuglog(str) { | |
| 11 | + debuglog("【appArea】" + str); | |
| 12 | + } | |
| 13 | + | |
| 14 | + initialize() { | |
| 15 | + if (null == this.DOMobject) { | |
| 16 | + console.error("【appArea】 initialize() DOMobject is null."); | |
| 17 | + return false; | |
| 18 | + } | |
| 19 | + this.debuglog("initialize"); | |
| 20 | + this.DOMobject.addEventListener('mousemove', this.onMouseMove.bind(this), false); | |
| 21 | + this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 22 | + this.DOMobject.addEventListener('mouseup', this.onMouseUp.bind(this), false); | |
| 23 | + } | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + // 操作関数 ----------------------------------- | |
| 28 | + | |
| 29 | + // Mouse eventを処理するObj | |
| 30 | + setMouseEventObj(mouseMove, mouseUp) { | |
| 31 | + this.debuglog('setMouseEventObj'); | |
| 32 | + | |
| 33 | + this.mouseMoveFunc = mouseMove; | |
| 34 | + this.mouseUpFunc = mouseUp; | |
| 35 | + } | |
| 36 | + | |
| 37 | + // Event handler ------------------- | |
| 38 | + | |
| 39 | + // ■マウス左ボタン押下 (Drag処理) | |
| 40 | + onMouseDown(evt) { | |
| 41 | + } | |
| 42 | + // ■ マウス移動 (ドラッグ中) | |
| 43 | + onMouseMove(evt) { | |
| 44 | + // ★ evt.targetが期待するelementかチェックする必要がある | |
| 45 | + // ★ 期待するelementではない場合、DOM treeを辿って親elementから該当elementを探す必要がある | |
| 46 | + | |
| 47 | + if (null != this.mouseMoveFunc) { | |
| 48 | + this.mouseMoveFunc(evt); | |
| 49 | + return; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + // ■ ドロップ処理 | |
| 53 | + onMouseUp(evt) { | |
| 54 | + // ★ evt.targetが期待するelementかチェックする必要がある | |
| 55 | + // ★ 期待するelementではない場合、DOM treeを辿って親elementから該当elementを探す必要がある | |
| 56 | + | |
| 57 | + if (null != this.mouseUpFunc) { | |
| 58 | + this.mouseUpFunc(evt); | |
| 59 | + return; | |
| 60 | + } | |
| 61 | + } | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | +} |
| @@ -1,4 +1,12 @@ | ||
| 1 | -class CSSPalette { | |
| 1 | +// palette.js | |
| 2 | +// Canvas上の要素を変更するための内容を保持するpalette | |
| 3 | +// Background用, Text color用, Action用 の3種類ある | |
| 4 | +// 主な機能 | |
| 5 | +// ・Drag&Dropによる移動 | |
| 6 | +// ・Target要素に自objidと同名のCSS class追加 | |
| 7 | +// ・外部からのDropによる text, image, css 読み込み | |
| 8 | + | |
| 9 | +class CSSPalette { | |
| 2 | 10 | constructor() { |
| 3 | 11 | this.DOMobject = []; |
| 4 | 12 | this.draggingDOM = null; |
| @@ -22,6 +30,7 @@ | ||
| 22 | 30 | this.DOMpalbg[cnt].style.left = 5 + (25 + 10) * cnt + 'px'; |
| 23 | 31 | this.DOMpalbg[cnt].style.top = 10 + 'px'; |
| 24 | 32 | this.DOMpalbg[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 33 | + this.DOMpalbg[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); | |
| 25 | 34 | this.DOMpalbg[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 26 | 35 | this.DOMpalbg[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 27 | 36 | this.DOMpalbg[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -32,6 +41,7 @@ | ||
| 32 | 41 | this.DOMpaltxtcol[cnt].style.left = 5 + (25 + 10) * cnt + 'px'; |
| 33 | 42 | this.DOMpaltxtcol[cnt].style.top = 10 + 'px'; |
| 34 | 43 | this.DOMpaltxtcol[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 44 | + this.DOMpaltxtcol[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); | |
| 35 | 45 | this.DOMpaltxtcol[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 36 | 46 | this.DOMpaltxtcol[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 37 | 47 | this.DOMpaltxtcol[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -167,8 +177,8 @@ | ||
| 167 | 177 | // Mouse event |
| 168 | 178 | // 自elementをDragし、Drop時にTarget elementに自分のCSS classを適用する |
| 169 | 179 | onMouseDown(evt) { |
| 170 | - // Mouse eventをDisplayFieldからCSSPalに渡してもらうように設定 | |
| 171 | - window.displayField.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 180 | + // Mouse eventをappAreaからCSSPalに渡してもらうように設定 | |
| 181 | + window.appArea.setMouseEventObj(this.mouseMove.bind(this), null); | |
| 172 | 182 | |
| 173 | 183 | // Drag対象を保持 |
| 174 | 184 | this.draggingDOM = evt.target; |
| @@ -198,7 +208,8 @@ | ||
| 198 | 208 | renderMoveDragging(x, y) { |
| 199 | 209 | this.draggingDOM.style.left = x + "px"; |
| 200 | 210 | this.draggingDOM.style.top = y + "px"; |
| 201 | - this.draggingDOM.style.opacity = 0.4; | |
| 211 | + if( 1.0 == this.draggingDOM.style.opacity ) | |
| 212 | + this.draggingDOM.style.opacity = 0.4; | |
| 202 | 213 | } |
| 203 | 214 | mouseUp(evt) { |
| 204 | 215 | let palobjid = this.draggingDOM.dataset.objid; |
| @@ -212,7 +223,7 @@ | ||
| 212 | 223 | // Drag中 element情報をクリア |
| 213 | 224 | this.draggingDOM = null; |
| 214 | 225 | // Mouse event callback設定をクリア |
| 215 | - window.displayField.setMouseEventObj(null, null); | |
| 226 | + window.appArea.setMouseEventObj(null, null); | |
| 216 | 227 | |
| 217 | 228 | // マウス座標直下にある要素を検索 |
| 218 | 229 | // (evt.targetは自分を指してしまうため) |
| @@ -0,0 +1,88 @@ | ||
| 1 | +// palgroup.js | |
| 2 | +// Paletteの各要素をまとめるもの | |
| 3 | +// 主な機能 | |
| 4 | +// ・グループバーのDrag&Dropによる移動 | |
| 5 | +// ・グループバーの表示方向 vertical/horizon 切り替え | |
| 6 | +// ・Palette設定状態の Save/Load | |
| 7 | +// ・(将来)5 Palette単位で次のPalette, 前のPalette表示 | |
| 8 | +// ・(将来)バー表示を半透明,短く表示 | |
| 9 | + | |
| 10 | +class PalGroup { | |
| 11 | + constructor() { | |
| 12 | + this.DOMobject = []; // bg,text,action | |
| 13 | + this.renderFunc = new Queue(); | |
| 14 | + } | |
| 15 | + debuglog(str) { | |
| 16 | + debuglog('【PalGroup】 ' + str); | |
| 17 | + } | |
| 18 | + | |
| 19 | + initialize() { | |
| 20 | + this.DOMobject = document.getElementsByClassName('palgroup'); | |
| 21 | + for (let cnt = 0; cnt < this.DOMobject.length; cnt++) { | |
| 22 | + this.DOMobject[cnt].style.left = 0 + 'px'; | |
| 23 | + this.DOMobject[cnt].style.top = 30 * cnt + 'px'; | |
| 24 | + this.DOMobject[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 25 | + this.DOMobject[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + // 操作関数 ---------------------------- | |
| 30 | + | |
| 31 | + | |
| 32 | + // 描画関数 --------------------- | |
| 33 | + | |
| 34 | + render() { | |
| 35 | + while (0 < this.renderFunc.size()) { | |
| 36 | + let renderFunction = this.renderFunc.dequeue(); | |
| 37 | + renderFunction(); | |
| 38 | + } | |
| 39 | + } | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + // Event handler ----------------------- | |
| 44 | + | |
| 45 | + onMouseDown(evt) { | |
| 46 | + // Mouse eventをappAreaからCSSPalに渡してもらうように設定 | |
| 47 | + window.appArea.setMouseEventObj(this.mouseMove.bind(this), null); | |
| 48 | + | |
| 49 | + // Drag対象を保持 | |
| 50 | + this.draggingDOM = evt.target; | |
| 51 | + // ElementのDrag開始位置を保持 | |
| 52 | + this.startElementX = parseInt(this.draggingDOM.style.left); | |
| 53 | + this.startElementY = parseInt(this.draggingDOM.style.top); | |
| 54 | + // MouseのDrag開始位置を保持 | |
| 55 | + this.startDragX = evt.pageX; | |
| 56 | + this.startDragY = evt.pageY; | |
| 57 | + } | |
| 58 | + mouseMove(evt) { | |
| 59 | + if (null == this.draggingDOM) return; | |
| 60 | + | |
| 61 | + // 画像の仮移動 | |
| 62 | + this.endDragX = evt.pageX; | |
| 63 | + this.endDragY = evt.pageY; | |
| 64 | + // 移動量取得 | |
| 65 | + let moveX = this.endDragX - this.startDragX; | |
| 66 | + let moveY = this.endDragY - this.startDragY; | |
| 67 | + // dispObjがあった位置からマウス移動分移動させた後の位置取得 | |
| 68 | + moveX = this.startElementX + moveX; | |
| 69 | + moveY = this.startElementY + moveY; | |
| 70 | + | |
| 71 | + this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 72 | + //this.renderMoveDragging(moveX, moveY); | |
| 73 | + } | |
| 74 | + renderMoveDragging(x, y) { | |
| 75 | + // 非同期のためmouseupの後に入ることがある | |
| 76 | + if (null == this.draggingDOM) return; | |
| 77 | + | |
| 78 | + this.draggingDOM.style.left = x + "px"; | |
| 79 | + this.draggingDOM.style.top = y + "px"; | |
| 80 | + } | |
| 81 | + mouseUp(evt) { | |
| 82 | + // Drag中 element情報をクリア | |
| 83 | + this.draggingDOM = null; | |
| 84 | + // Mouse event callback設定をクリア | |
| 85 | + window.appArea.setMouseEventObj(null, null); | |
| 86 | + } | |
| 87 | + | |
| 88 | +} |
| @@ -1,3 +1,8 @@ | ||
| 1 | +// worker_thread.js | |
| 2 | +// UI threadからの要求Commandを受け付ける | |
| 3 | +// 主な機能 | |
| 4 | +// ・Message受信 | |
| 5 | +// ・CommandMgrに受信commandを渡す | |
| 1 | 6 | |
| 2 | 7 | // worker threadでのcommand処理に必要な class fileの読み込みと実行 |
| 3 | 8 | // (引数のjs内容の実行も行われる) |
| @@ -30,8 +30,17 @@ | ||
| 30 | 30 | [data-objid] { |
| 31 | 31 | transition: transform 2s linear 0s; |
| 32 | 32 | } |
| 33 | -*/ | |
| 33 | +*/ | |
| 34 | 34 | |
| 35 | + | |
| 36 | + #apparea{ | |
| 37 | + display: block; | |
| 38 | + width: 100%; height: 100%; | |
| 39 | + border: none; | |
| 40 | + margin: 0; padding: 0; | |
| 41 | + background-color: gainsboro; | |
| 42 | + } | |
| 43 | + | |
| 35 | 44 | /* キャンバス要素の定義 */ |
| 36 | 45 | #DispField{ |
| 37 | 46 | display:block; |
| @@ -38,6 +47,7 @@ | ||
| 38 | 47 | width:400px; height:300px; |
| 39 | 48 | border:1px solid black; |
| 40 | 49 | margin: 10px; |
| 50 | + background-color: white; | |
| 41 | 51 | } |
| 42 | 52 | |
| 43 | 53 |
| @@ -8,102 +8,198 @@ | ||
| 8 | 8 | <link href="css/default.css" rel="stylesheet" /> |
| 9 | 9 | </head> |
| 10 | 10 | <body> |
| 11 | - <!-- 編集領域 --> | |
| 12 | - <div id="DispField" data-objid="DisplayField" data-focus="true"> | |
| 13 | - </div> | |
| 14 | - <!-- 固定ボタン (選択要素の削除, 保存, …) --> | |
| 15 | - <button type=button class="pal" data-objid="pal" data-palid="0" data-value="0xff000001">削除</button> | |
| 16 | - <button type=button class="pal" data-objid="pal" data-palid="1" data-value="0x00ff0001">設定保存</button> | |
| 17 | - <button type=button class="pal" data-objid="pal" data-palid="2" data-value="0x0000ff01">設定Drop</button> | |
| 18 | - <button type=button class="pal" data-objid="pal" data-palid="3" data-value="0xffffff01">アニメ停止</button> | |
| 19 | - <button type=button class="pal" data-objid="pal" data-palid="4" data-value="0x00000000">button5</button> | |
| 20 | - <a href="#" id="save" download="savefilename.txt">画像保存</a><br /> | |
| 21 | 11 | |
| 22 | - <!-- Palette --> | |
| 23 | - <style id="stylepalbg"> | |
| 24 | - .palbg0 { background-image: url(dummy.png); } | |
| 25 | - .palbg1 { background-image: url(dummy.png); } | |
| 26 | - .palbg2 { background-image: url(dummy.png); } | |
| 27 | - .palbg3 { background-image: url(dummy.png); } | |
| 28 | - .palbg4 { background-image: url(dummy.png); } | |
| 29 | - </style> | |
| 30 | - <style id="stylepaltxtcol"> | |
| 31 | - .paltxtcol0 { color: black; } | |
| 32 | - .paltxtcol1 { color: red; } | |
| 33 | - .paltxtcol2 { color: blue; } | |
| 34 | - .paltxtcol3 { color: green; } | |
| 35 | - .paltxtcol4 { color: brown; } | |
| 36 | - </style> | |
| 37 | - <style id="stylepalact"> | |
| 38 | - /* animation指定,keyframe指定, … と交互に設定されている想定 */ | |
| 39 | - /* palette css と keyframe は必ず1対1.例えkeyframeが使いまわせたとしても。 */ | |
| 40 | - .palact0 { animation: animeY1 0.5s ease-in 0.3s 1 normal; } | |
| 41 | - @keyframes animeY1 { | |
| 42 | - 0% {transform: translateY(-60px) translateX(-30px);} | |
| 43 | - 10% {transform: translateY(20px) translateX(30px);} | |
| 44 | - 20% {transform: translateY(-40px) translateX(-20px);} | |
| 45 | - 30% {transform: translateY(50px) translateX(-10px);} | |
| 46 | - 40% {transform: translateY(-40px) translateX(20px);} | |
| 47 | - 50% {transform: translateY(30px) translateX(-15px);} | |
| 48 | - 60% {transform: translateY(-25px) translateX(0px);} | |
| 49 | - 70% {transform: translateY(15px) translateX(-15px);} | |
| 50 | - 80% {transform: translateY(-10px) translateX(10px);} | |
| 51 | - 90% {transform: translateY(0px) translateX(-5px);} | |
| 52 | - 100% {transform: translateY(0px) translateX(0px);} | |
| 53 | - } | |
| 12 | + <div id="apparea" data-objid="apparea"> | |
| 13 | + <!-- 編集領域 --> | |
| 14 | + <div id="DispField" data-objid="DisplayField" data-focus="true"> | |
| 15 | + </div> | |
| 16 | + <!-- 固定ボタン (選択要素の削除, 保存, …) --> | |
| 17 | + <button type=button class="pal" data-objid="pal" data-palid="0" data-value="0xff000001">削除</button> | |
| 18 | + <button type=button class="pal" data-objid="pal" data-palid="1" data-value="0x00ff0001">設定保存</button> | |
| 19 | + <button type=button class="pal" data-objid="pal" data-palid="2" data-value="0x0000ff01">設定Drop</button> | |
| 20 | + <button type=button class="pal" data-objid="pal" data-palid="3" data-value="0xffffff01">アニメ停止</button> | |
| 21 | + <button type=button class="pal" data-objid="pal" data-palid="4" data-value="0x00000000">button5</button> | |
| 22 | + <a href="#" id="save" download="savefilename.txt">画像保存</a><br /> | |
| 54 | 23 | |
| 55 | - .palact1 { animation: animeact1 2s ease-in 0.3s 1 normal; } | |
| 56 | - @keyframes animeact1 { to {color:black;} } | |
| 24 | + <!-- Palette --> | |
| 25 | + <style id="stylepalbg"> | |
| 26 | + .palbg0 { | |
| 27 | + background-image: url(dummy.png); | |
| 28 | + } | |
| 57 | 29 | |
| 58 | - .palact2 { animation: animeact2 2s ease-in 0.3s 1 normal; } | |
| 59 | - @keyframes animeact2 { to {color:black;} } | |
| 30 | + .palbg1 { | |
| 31 | + background-image: url(dummy.png); | |
| 32 | + } | |
| 60 | 33 | |
| 61 | - .palact3 { animation: animeact3 2s ease-in 0.3s 1 normal; } | |
| 62 | - @keyframes animeact3 { to {color:black;} } | |
| 34 | + .palbg2 { | |
| 35 | + background-image: url(dummy.png); | |
| 36 | + } | |
| 63 | 37 | |
| 64 | - .palact4 { animation: animeact4 2s ease-in 0.3s 1 normal; } | |
| 65 | - @keyframes animeact4 { to {color:black;} } | |
| 66 | - </style> | |
| 38 | + .palbg3 { | |
| 39 | + background-image: url(dummy.png); | |
| 40 | + } | |
| 67 | 41 | |
| 68 | - <fieldset class="palgroup palgrouphorizon" data-objid="palgroup0"> | |
| 69 | - <legend class="pallegend"> Background <button>横</button> </legend> | |
| 70 | - <div class="palbg palbg0" data-objid="palbg0" data-palid="0"></div> | |
| 71 | - <div class="palbg palbg1" data-objid="palbg1" data-palid="1"></div> | |
| 72 | - <div class="palbg palbg2" data-objid="palbg2" data-palid="2"></div> | |
| 73 | - <div class="palbg palbg3" data-objid="palbg3" data-palid="3"></div> | |
| 74 | - <div class="palbg palbg4" data-objid="palbg4" data-palid="4"></div> | |
| 75 | - </fieldset> | |
| 76 | - <br /> | |
| 42 | + .palbg4 { | |
| 43 | + background-image: url(dummy.png); | |
| 44 | + } | |
| 45 | + </style> | |
| 46 | + <style id="stylepaltxtcol"> | |
| 47 | + .paltxtcol0 { | |
| 48 | + color: black; | |
| 49 | + } | |
| 77 | 50 | |
| 78 | - <fieldset class="palgroup palgrouphorizon" data-objid="palgroup1"> | |
| 79 | - <legend class="pallegend"> Text Color <button>横</button> </legend> | |
| 80 | - <div class="paltxtcol paltxtcol0" data-objid="paltxtcol0" data-palid="0">あ</div> | |
| 81 | - <div class="paltxtcol paltxtcol1" data-objid="paltxtcol1" data-palid="1">あ</div> | |
| 82 | - <div class="paltxtcol paltxtcol2" data-objid="paltxtcol2" data-palid="2">あ</div> | |
| 83 | - <div class="paltxtcol paltxtcol3" data-objid="paltxtcol3" data-palid="3">あ</div> | |
| 84 | - <div class="paltxtcol paltxtcol4" data-objid="paltxtcol4" data-palid="4">あ</div> | |
| 85 | - </fieldset> | |
| 51 | + .paltxtcol1 { | |
| 52 | + color: red; | |
| 53 | + } | |
| 86 | 54 | |
| 55 | + .paltxtcol2 { | |
| 56 | + color: blue; | |
| 57 | + } | |
| 58 | + | |
| 59 | + .paltxtcol3 { | |
| 60 | + color: green; | |
| 61 | + } | |
| 62 | + | |
| 63 | + .paltxtcol4 { | |
| 64 | + color: brown; | |
| 65 | + } | |
| 66 | + </style> | |
| 67 | + <style id="stylepalact"> | |
| 68 | + /* animation指定,keyframe指定, … と交互に設定されている想定 */ | |
| 69 | + /* palette css と keyframe は必ず1対1.例えkeyframeが使いまわせたとしても。 */ | |
| 70 | + .palact0 { | |
| 71 | + animation: animeY1 0.5s ease-in 0.3s 1 normal; | |
| 72 | + } | |
| 73 | + | |
| 74 | + @keyframes animeY1 { | |
| 75 | + 0% { | |
| 76 | + transform: translateY(-60px) translateX(-30px); | |
| 77 | + } | |
| 78 | + | |
| 79 | + 10% { | |
| 80 | + transform: translateY(20px) translateX(30px); | |
| 81 | + } | |
| 82 | + | |
| 83 | + 20% { | |
| 84 | + transform: translateY(-40px) translateX(-20px); | |
| 85 | + } | |
| 86 | + | |
| 87 | + 30% { | |
| 88 | + transform: translateY(50px) translateX(-10px); | |
| 89 | + } | |
| 90 | + | |
| 91 | + 40% { | |
| 92 | + transform: translateY(-40px) translateX(20px); | |
| 93 | + } | |
| 94 | + | |
| 95 | + 50% { | |
| 96 | + transform: translateY(30px) translateX(-15px); | |
| 97 | + } | |
| 98 | + | |
| 99 | + 60% { | |
| 100 | + transform: translateY(-25px) translateX(0px); | |
| 101 | + } | |
| 102 | + | |
| 103 | + 70% { | |
| 104 | + transform: translateY(15px) translateX(-15px); | |
| 105 | + } | |
| 106 | + | |
| 107 | + 80% { | |
| 108 | + transform: translateY(-10px) translateX(10px); | |
| 109 | + } | |
| 110 | + | |
| 111 | + 90% { | |
| 112 | + transform: translateY(0px) translateX(-5px); | |
| 113 | + } | |
| 114 | + | |
| 115 | + 100% { | |
| 116 | + transform: translateY(0px) translateX(0px); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + | |
| 120 | + .palact1 { | |
| 121 | + animation: animeact1 2s ease-in 0.3s 1 normal; | |
| 122 | + } | |
| 123 | + | |
| 124 | + @keyframes animeact1 { | |
| 125 | + to { | |
| 126 | + color: black; | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + .palact2 { | |
| 131 | + animation: animeact2 2s ease-in 0.3s 1 normal; | |
| 132 | + } | |
| 133 | + | |
| 134 | + @keyframes animeact2 { | |
| 135 | + to { | |
| 136 | + color: black; | |
| 137 | + } | |
| 138 | + } | |
| 139 | + | |
| 140 | + .palact3 { | |
| 141 | + animation: animeact3 2s ease-in 0.3s 1 normal; | |
| 142 | + } | |
| 143 | + | |
| 144 | + @keyframes animeact3 { | |
| 145 | + to { | |
| 146 | + color: black; | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + .palact4 { | |
| 151 | + animation: animeact4 2s ease-in 0.3s 1 normal; | |
| 152 | + } | |
| 153 | + | |
| 154 | + @keyframes animeact4 { | |
| 155 | + to { | |
| 156 | + color: black; | |
| 157 | + } | |
| 158 | + } | |
| 159 | + </style> | |
| 160 | + | |
| 161 | + <fieldset class="palgroup palgrouphorizon" data-objid="palgroup0"> | |
| 162 | + <legend class="pallegend"> Background <button>横</button> </legend> | |
| 163 | + <div class="palbg palbg0" data-objid="palbg0" data-palid="0"></div> | |
| 164 | + <div class="palbg palbg1" data-objid="palbg1" data-palid="1"></div> | |
| 165 | + <div class="palbg palbg2" data-objid="palbg2" data-palid="2"></div> | |
| 166 | + <div class="palbg palbg3" data-objid="palbg3" data-palid="3"></div> | |
| 167 | + <div class="palbg palbg4" data-objid="palbg4" data-palid="4"></div> | |
| 168 | + </fieldset> | |
| 87 | 169 | <br /> |
| 88 | 170 | |
| 89 | - <fieldset class="palgroup palgrouphorizon" data-objid="palgroup2"> | |
| 90 | - <legend class="pallegend"> Action <span class="buttonstyle">horizon</span> </legend> | |
| 91 | - <div class="palact palact0" data-objid="palact0" data-palid="0"></div> | |
| 92 | - <div class="palact palact1" data-objid="palact1" data-palid="1"></div> | |
| 93 | - <div class="palact palact2" data-objid="palact2" data-palid="2"></div> | |
| 94 | - <div class="palact palact3" data-objid="palact3" data-palid="3"></div> | |
| 95 | - <div class="palact palact4" data-objid="palact4" data-palid="4"></div> | |
| 96 | - </fieldset> | |
| 171 | + <fieldset class="palgroup palgrouphorizon" data-objid="palgroup1"> | |
| 172 | + <legend class="pallegend"> Text Color <button>横</button> </legend> | |
| 173 | + <div class="paltxtcol paltxtcol0" data-objid="paltxtcol0" data-palid="0">あ</div> | |
| 174 | + <div class="paltxtcol paltxtcol1" data-objid="paltxtcol1" data-palid="1">あ</div> | |
| 175 | + <div class="paltxtcol paltxtcol2" data-objid="paltxtcol2" data-palid="2">あ</div> | |
| 176 | + <div class="paltxtcol paltxtcol3" data-objid="paltxtcol3" data-palid="3">あ</div> | |
| 177 | + <div class="paltxtcol paltxtcol4" data-objid="paltxtcol4" data-palid="4">あ</div> | |
| 178 | + </fieldset> | |
| 97 | 179 | |
| 180 | + <br /> | |
| 181 | + | |
| 182 | + <fieldset class="palgroup palgrouphorizon" data-objid="palgroup2"> | |
| 183 | + <legend class="pallegend"> Action <span class="buttonstyle">horizon</span> </legend> | |
| 184 | + <div class="palact palact0" data-objid="palact0" data-palid="0"></div> | |
| 185 | + <div class="palact palact1" data-objid="palact1" data-palid="1"></div> | |
| 186 | + <div class="palact palact2" data-objid="palact2" data-palid="2"></div> | |
| 187 | + <div class="palact palact3" data-objid="palact3" data-palid="3"></div> | |
| 188 | + <div class="palact palact4" data-objid="palact4" data-palid="4"></div> | |
| 189 | + </fieldset> | |
| 190 | + </div> | |
| 191 | + | |
| 98 | 192 | <script type="text/javascript" src="js/Common.js"></script> |
| 99 | 193 | <script type="text/javascript" src="js/Queue.js"></script> |
| 100 | 194 | <script type="text/javascript" src="js/CommandObj.js"></script> |
| 101 | 195 | <script type="text/javascript" src="js/UI_parts.js"></script> |
| 196 | + <script type="text/javascript" src="js/palgroup.js"></script> | |
| 102 | 197 | <script type="text/javascript" src="js/palette.js"></script> |
| 103 | 198 | <script type="text/javascript" src="js/DispObj.js"></script> |
| 104 | 199 | <script type="text/javascript" src="js/ObjIDMgr.js"></script> |
| 105 | 200 | <script type="text/javascript" src="js/ThreadMessage.js"></script> |
| 106 | 201 | <script type="text/javascript" src="js/DisplayField.js"></script> |
| 202 | + <script type="text/javascript" src="js/apparea.js"></script> | |
| 107 | 203 | <script type="text/javascript" src="js/main.js"></script> |
| 108 | 204 | </body> |
| 109 | 205 | </html> |
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | // CommandMgr.js |
| 2 | -// Worker thread | |
| 3 | -// UI threadからの要求Commandを受け付ける | |
| 2 | +// Worker thread上で動作 | |
| 4 | 3 | // Worker thread側でcommand処理を実行することはない(今のところ。commandが表示に関する操作ばかりのため) |
| 5 | 4 | // 主な機能 |
| 6 | 5 | // ・Queuing command. |
| @@ -246,8 +246,8 @@ | ||
| 246 | 246 | if (0 == (evt.buttons & 0x0001)) { // 左クリックチェック |
| 247 | 247 | return; |
| 248 | 248 | } |
| 249 | - // Mouse eventをDisplayFieldからScalerに渡してもらうように設定 | |
| 250 | - window.displayField.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 249 | + // Mouse eventをappAreaからScalerに渡してもらうように設定 | |
| 250 | + window.appArea.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 251 | 251 | |
| 252 | 252 | |
| 253 | 253 | // Focus設定 |
| @@ -281,7 +281,7 @@ | ||
| 281 | 281 | mouseUp(evt) { |
| 282 | 282 | this.debuglog("mouseUp"); |
| 283 | 283 | // Mouse event処理対象をクリア |
| 284 | - window.displayField.setMouseEventObj(null, null); | |
| 284 | + window.appArea.setMouseEventObj(null, null); | |
| 285 | 285 | |
| 286 | 286 | |
| 287 | 287 | // 移動元として座標を保持 |
| @@ -20,13 +20,13 @@ | ||
| 20 | 20 | // ■ 初期化 |
| 21 | 21 | initialize() { |
| 22 | 22 | if (null == this.DOMobject) { |
| 23 | - console.log("【DisplayField】 initialize() DOMobject is null."); | |
| 23 | + console.error("【DisplayField】 initialize() DOMobject is null."); | |
| 24 | 24 | return false; |
| 25 | 25 | } |
| 26 | 26 | this.debuglog("initialize"); |
| 27 | - this.DOMobject.addEventListener('mousemove', this.onMouseMove.bind(this), false); | |
| 28 | - this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 29 | - this.DOMobject.addEventListener('mouseup', this.onMouseUp.bind(this), false); | |
| 27 | +// this.DOMobject.addEventListener('mousemove', this.onMouseMove.bind(this), false); | |
| 28 | +// this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 29 | +// this.DOMobject.addEventListener('mouseup', this.onMouseUp.bind(this), false); | |
| 30 | 30 | this.DOMobject.addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 31 | 31 | this.DOMobject.addEventListener('dragover', this.onDragover.bind(this), false); |
| 32 | 32 | this.DOMobject.addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | // 操作関数 ----------------------------------- |
| 37 | - | |
| 37 | +/* | |
| 38 | 38 | // Mouse eventを処理するObj |
| 39 | 39 | setMouseEventObj(mouseMove, mouseUp) { |
| 40 | 40 | this.debuglog('setMouseEventObj'); |
| @@ -42,9 +42,9 @@ | ||
| 42 | 42 | this.mouseMoveFunc = mouseMove; |
| 43 | 43 | this.mouseUpFunc = mouseUp; |
| 44 | 44 | } |
| 45 | +*/ | |
| 45 | 46 | |
| 46 | 47 | |
| 47 | - | |
| 48 | 48 | // ブラウザ上への描画 ------------------------- |
| 49 | 49 | render() { |
| 50 | 50 | while (0 < this.renderFunc.size()) { |
| @@ -57,7 +57,7 @@ | ||
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | // Event handler ------------------- |
| 60 | - | |
| 60 | + /* | |
| 61 | 61 | // ■マウス左ボタン押下 (Drag処理) |
| 62 | 62 | onMouseDown(evt) { |
| 63 | 63 | } |
| @@ -81,7 +81,7 @@ | ||
| 81 | 81 | return; |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | - | |
| 84 | + */ | |
| 85 | 85 | // 表示要素の drag & drop禁止 |
| 86 | 86 | onDragStart(evt) { |
| 87 | 87 | evt.preventDefault(); |
| @@ -258,8 +258,8 @@ | ||
| 258 | 258 | onMouseDownScale(evt) { |
| 259 | 259 | this.debuglog('onMouseDownScale'); |
| 260 | 260 | |
| 261 | - // Mouse eventをDisplayFieldからScalerに渡してもらうように設定 | |
| 262 | - window.displayField.setMouseEventObj(this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 261 | + // Mouse eventをappAreaからScalerに渡してもらうように設定 | |
| 262 | + window.appArea.setMouseEventObj(this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 263 | 263 | |
| 264 | 264 | // 移動元として座標を保持 |
| 265 | 265 | this.scaleStartWidth = parseInt(this.clingingPartner.style.width); |
| @@ -307,7 +307,7 @@ | ||
| 307 | 307 | mouseUpScale(evt) { |
| 308 | 308 | this.debuglog('mouseUpScale'); |
| 309 | 309 | // Mouse event callback設定をクリア |
| 310 | - window.displayField.setMouseEventObj(null, null); | |
| 310 | + window.appArea.setMouseEventObj(null, null); | |
| 311 | 311 | |
| 312 | 312 | // 画像の仮変形 |
| 313 | 313 | this.endDragX = evt.pageX; |
| @@ -344,8 +344,8 @@ | ||
| 344 | 344 | onMouseDownRoll(evt) { |
| 345 | 345 | this.debuglog('onMouseDownRoll'); |
| 346 | 346 | |
| 347 | - // Mouse eventをDisplayFieldからRollerに渡してもらうように設定 | |
| 348 | - window.displayField.setMouseEventObj(this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 347 | + // Mouse eventをappAreaからRollerに渡してもらうように設定 | |
| 348 | + window.appArea.setMouseEventObj(this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 349 | 349 | } |
| 350 | 350 | mouseMoveRoll(evt) { |
| 351 | 351 | let x1 = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; |
| @@ -362,7 +362,7 @@ | ||
| 362 | 362 | mouseUpRoll(evt) { |
| 363 | 363 | this.debuglog('mouseUpRoll'); |
| 364 | 364 | // Mouse event callback設定をクリア |
| 365 | - window.displayField.setMouseEventObj(null, null); | |
| 365 | + window.appArea.setMouseEventObj(null, null); | |
| 366 | 366 | |
| 367 | 367 | let x1 = parseInt(this.clingingPartner.style.left) + parseInt(this.clingingPartner.style.width) / 2; |
| 368 | 368 | let y1 = parseInt(this.clingingPartner.style.top) + parseInt(this.clingingPartner.style.height) / 2; |
| @@ -0,0 +1,65 @@ | ||
| 1 | +// apparea.js | |
| 2 | +// マウスイベントハンドリング | |
| 3 | + | |
| 4 | +class appArea { | |
| 5 | + constructor(dom) { | |
| 6 | + this.DOMobject = dom; | |
| 7 | + this.mouseMoveFunc = null; | |
| 8 | + this.mouseUpFunc = null; | |
| 9 | + } | |
| 10 | + debuglog(str) { | |
| 11 | + debuglog("【appArea】" + str); | |
| 12 | + } | |
| 13 | + | |
| 14 | + initialize() { | |
| 15 | + if (null == this.DOMobject) { | |
| 16 | + console.error("【appArea】 initialize() DOMobject is null."); | |
| 17 | + return false; | |
| 18 | + } | |
| 19 | + this.debuglog("initialize"); | |
| 20 | + this.DOMobject.addEventListener('mousemove', this.onMouseMove.bind(this), false); | |
| 21 | + this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 22 | + this.DOMobject.addEventListener('mouseup', this.onMouseUp.bind(this), false); | |
| 23 | + } | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + // 操作関数 ----------------------------------- | |
| 28 | + | |
| 29 | + // Mouse eventを処理するObj | |
| 30 | + setMouseEventObj(mouseMove, mouseUp) { | |
| 31 | + this.debuglog('setMouseEventObj'); | |
| 32 | + | |
| 33 | + this.mouseMoveFunc = mouseMove; | |
| 34 | + this.mouseUpFunc = mouseUp; | |
| 35 | + } | |
| 36 | + | |
| 37 | + // Event handler ------------------- | |
| 38 | + | |
| 39 | + // ■マウス左ボタン押下 (Drag処理) | |
| 40 | + onMouseDown(evt) { | |
| 41 | + } | |
| 42 | + // ■ マウス移動 (ドラッグ中) | |
| 43 | + onMouseMove(evt) { | |
| 44 | + // ★ evt.targetが期待するelementかチェックする必要がある | |
| 45 | + // ★ 期待するelementではない場合、DOM treeを辿って親elementから該当elementを探す必要がある | |
| 46 | + | |
| 47 | + if (null != this.mouseMoveFunc) { | |
| 48 | + this.mouseMoveFunc(evt); | |
| 49 | + return; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + // ■ ドロップ処理 | |
| 53 | + onMouseUp(evt) { | |
| 54 | + // ★ evt.targetが期待するelementかチェックする必要がある | |
| 55 | + // ★ 期待するelementではない場合、DOM treeを辿って親elementから該当elementを探す必要がある | |
| 56 | + | |
| 57 | + if (null != this.mouseUpFunc) { | |
| 58 | + this.mouseUpFunc(evt); | |
| 59 | + return; | |
| 60 | + } | |
| 61 | + } | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | +} |
| @@ -27,7 +27,11 @@ | ||
| 27 | 27 | |
| 28 | 28 | // Mgr obj生成 |
| 29 | 29 | // Create Mgr--- |
| 30 | - var dom = document.getElementById( "DispField" ); | |
| 30 | + let dom = document.getElementById("apparea"); | |
| 31 | + window.appArea = new appArea(dom); | |
| 32 | + window.appArea.initialize(); | |
| 33 | + | |
| 34 | + dom = document.getElementById("DispField"); | |
| 31 | 35 | window.displayField = new CDisplayField(dom); |
| 32 | 36 | window.displayField.initialize(); |
| 33 | 37 | window.ObjIDMgr = new CObjIDMgr(); |
| @@ -45,6 +49,9 @@ | ||
| 45 | 49 | let savelink = document.getElementById('save'); |
| 46 | 50 | savelink.addEventListener('click', onClickSaveLink, false); |
| 47 | 51 | |
| 52 | + // パレットグループ作成 | |
| 53 | + window.CSSPalGroup = new PalGroup(); | |
| 54 | + window.CSSPalGroup.initialize(); | |
| 48 | 55 | // パレット作成 |
| 49 | 56 | window.CSSPalette = new CSSPalette(); |
| 50 | 57 | window.CSSPalette.initialize(); |
| @@ -91,6 +98,7 @@ | ||
| 91 | 98 | // Focus枠, scale, rotate obj描画 |
| 92 | 99 | window.partsFocus.render(); |
| 93 | 100 | // palette描画 |
| 101 | + window.CSSPalGroup.render(); | |
| 94 | 102 | window.CSSPalette.render(); |
| 95 | 103 | |
| 96 | 104 | requestAnimationFrame( renderLoop ); |
| @@ -30,6 +30,7 @@ | ||
| 30 | 30 | this.DOMpalbg[cnt].style.left = 5 + (25 + 10) * cnt + 'px'; |
| 31 | 31 | this.DOMpalbg[cnt].style.top = 10 + 'px'; |
| 32 | 32 | this.DOMpalbg[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 33 | + this.DOMpalbg[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); | |
| 33 | 34 | this.DOMpalbg[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 34 | 35 | this.DOMpalbg[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 35 | 36 | this.DOMpalbg[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -40,6 +41,7 @@ | ||
| 40 | 41 | this.DOMpaltxtcol[cnt].style.left = 5 + (25 + 10) * cnt + 'px'; |
| 41 | 42 | this.DOMpaltxtcol[cnt].style.top = 10 + 'px'; |
| 42 | 43 | this.DOMpaltxtcol[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 44 | + this.DOMpaltxtcol[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); | |
| 43 | 45 | this.DOMpaltxtcol[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 44 | 46 | this.DOMpaltxtcol[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 45 | 47 | this.DOMpaltxtcol[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -175,8 +177,8 @@ | ||
| 175 | 177 | // Mouse event |
| 176 | 178 | // 自elementをDragし、Drop時にTarget elementに自分のCSS classを適用する |
| 177 | 179 | onMouseDown(evt) { |
| 178 | - // Mouse eventをDisplayFieldからCSSPalに渡してもらうように設定 | |
| 179 | - window.displayField.setMouseEventObj(this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 180 | + // Mouse eventをappAreaからCSSPalに渡してもらうように設定 | |
| 181 | + window.appArea.setMouseEventObj(this.mouseMove.bind(this), null); | |
| 180 | 182 | |
| 181 | 183 | // Drag対象を保持 |
| 182 | 184 | this.draggingDOM = evt.target; |
| @@ -206,7 +208,8 @@ | ||
| 206 | 208 | renderMoveDragging(x, y) { |
| 207 | 209 | this.draggingDOM.style.left = x + "px"; |
| 208 | 210 | this.draggingDOM.style.top = y + "px"; |
| 209 | - this.draggingDOM.style.opacity = 0.4; | |
| 211 | + if( 1.0 == this.draggingDOM.style.opacity ) | |
| 212 | + this.draggingDOM.style.opacity = 0.4; | |
| 210 | 213 | } |
| 211 | 214 | mouseUp(evt) { |
| 212 | 215 | let palobjid = this.draggingDOM.dataset.objid; |
| @@ -220,7 +223,7 @@ | ||
| 220 | 223 | // Drag中 element情報をクリア |
| 221 | 224 | this.draggingDOM = null; |
| 222 | 225 | // Mouse event callback設定をクリア |
| 223 | - window.displayField.setMouseEventObj(null, null); | |
| 226 | + window.appArea.setMouseEventObj(null, null); | |
| 224 | 227 | |
| 225 | 228 | // マウス座標直下にある要素を検索 |
| 226 | 229 | // (evt.targetは自分を指してしまうため) |
| @@ -7,3 +7,82 @@ | ||
| 7 | 7 | // ・(将来)5 Palette単位で次のPalette, 前のPalette表示 |
| 8 | 8 | // ・(将来)バー表示を半透明,短く表示 |
| 9 | 9 | |
| 10 | +class PalGroup { | |
| 11 | + constructor() { | |
| 12 | + this.DOMobject = []; // bg,text,action | |
| 13 | + this.renderFunc = new Queue(); | |
| 14 | + } | |
| 15 | + debuglog(str) { | |
| 16 | + debuglog('【PalGroup】 ' + str); | |
| 17 | + } | |
| 18 | + | |
| 19 | + initialize() { | |
| 20 | + this.DOMobject = document.getElementsByClassName('palgroup'); | |
| 21 | + for (let cnt = 0; cnt < this.DOMobject.length; cnt++) { | |
| 22 | + this.DOMobject[cnt].style.left = 0 + 'px'; | |
| 23 | + this.DOMobject[cnt].style.top = 30 * cnt + 'px'; | |
| 24 | + this.DOMobject[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); | |
| 25 | + this.DOMobject[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + // 操作関数 ---------------------------- | |
| 30 | + | |
| 31 | + | |
| 32 | + // 描画関数 --------------------- | |
| 33 | + | |
| 34 | + render() { | |
| 35 | + while (0 < this.renderFunc.size()) { | |
| 36 | + let renderFunction = this.renderFunc.dequeue(); | |
| 37 | + renderFunction(); | |
| 38 | + } | |
| 39 | + } | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + // Event handler ----------------------- | |
| 44 | + | |
| 45 | + onMouseDown(evt) { | |
| 46 | + // Mouse eventをappAreaからCSSPalに渡してもらうように設定 | |
| 47 | + window.appArea.setMouseEventObj(this.mouseMove.bind(this), null); | |
| 48 | + | |
| 49 | + // Drag対象を保持 | |
| 50 | + this.draggingDOM = evt.target; | |
| 51 | + // ElementのDrag開始位置を保持 | |
| 52 | + this.startElementX = parseInt(this.draggingDOM.style.left); | |
| 53 | + this.startElementY = parseInt(this.draggingDOM.style.top); | |
| 54 | + // MouseのDrag開始位置を保持 | |
| 55 | + this.startDragX = evt.pageX; | |
| 56 | + this.startDragY = evt.pageY; | |
| 57 | + } | |
| 58 | + mouseMove(evt) { | |
| 59 | + if (null == this.draggingDOM) return; | |
| 60 | + | |
| 61 | + // 画像の仮移動 | |
| 62 | + this.endDragX = evt.pageX; | |
| 63 | + this.endDragY = evt.pageY; | |
| 64 | + // 移動量取得 | |
| 65 | + let moveX = this.endDragX - this.startDragX; | |
| 66 | + let moveY = this.endDragY - this.startDragY; | |
| 67 | + // dispObjがあった位置からマウス移動分移動させた後の位置取得 | |
| 68 | + moveX = this.startElementX + moveX; | |
| 69 | + moveY = this.startElementY + moveY; | |
| 70 | + | |
| 71 | + this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); | |
| 72 | + //this.renderMoveDragging(moveX, moveY); | |
| 73 | + } | |
| 74 | + renderMoveDragging(x, y) { | |
| 75 | + // 非同期のためmouseupの後に入ることがある | |
| 76 | + if (null == this.draggingDOM) return; | |
| 77 | + | |
| 78 | + this.draggingDOM.style.left = x + "px"; | |
| 79 | + this.draggingDOM.style.top = y + "px"; | |
| 80 | + } | |
| 81 | + mouseUp(evt) { | |
| 82 | + // Drag中 element情報をクリア | |
| 83 | + this.draggingDOM = null; | |
| 84 | + // Mouse event callback設定をクリア | |
| 85 | + window.appArea.setMouseEventObj(null, null); | |
| 86 | + } | |
| 87 | + | |
| 88 | +} |