正在显示
1 个修改的文件
包含
795 行增加
和
0 行删除
pen_demo.html
0 → 100644
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
| 2 | +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
| 3 | +<!-- saved from url=(0014)about:internet --> | ||
| 4 | +<html xmlns="http://www.w3.org/1999/xhtml"> | ||
| 5 | + | ||
| 6 | +<head> | ||
| 7 | + <title>Pen Demo</title> | ||
| 8 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
| 9 | + <link rel="stylesheet" href="./jqx/styles/jquery-ui.css"/> | ||
| 10 | + <script type="text/javascript" src="./jqx/jquery-1.11.1.min.js"></script> | ||
| 11 | + <script type="text/javascript" src="./jqx/jquery-ui.min.js"></script> | ||
| 12 | + | ||
| 13 | + <style type="text/css"> | ||
| 14 | + body { | ||
| 15 | + margin:0px; | ||
| 16 | + width:100%; | ||
| 17 | + height:100%; | ||
| 18 | + overflow:hidden; | ||
| 19 | + font-family:Arial; | ||
| 20 | + /* prevent text selection on ui */ | ||
| 21 | + user-select: none; | ||
| 22 | + -webkit-user-select: none; | ||
| 23 | + -moz-user-select: none; | ||
| 24 | + -ms-user-select: none; | ||
| 25 | + /* prevent scrolling in windows phone */ | ||
| 26 | + -ms-touch-action: none; | ||
| 27 | + /* prevent selection highlight */ | ||
| 28 | + -webkit-tap-highlight-color: rgba(0,0,0,0); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + .header, .footer{ | ||
| 32 | + position: absolute; | ||
| 33 | + background-color: #222; | ||
| 34 | + text-align: center; | ||
| 35 | + } | ||
| 36 | + .header { | ||
| 37 | + top: 0px; | ||
| 38 | + left: 0px; | ||
| 39 | + right: 0px; | ||
| 40 | + height: 228px; | ||
| 41 | + padding:6px; | ||
| 42 | + } | ||
| 43 | + .footer { | ||
| 44 | + bottom: 0px; | ||
| 45 | + left: 0px; | ||
| 46 | + right: 0px; | ||
| 47 | + height: 42px; | ||
| 48 | + padding:2px; | ||
| 49 | + } | ||
| 50 | + .title { | ||
| 51 | + width: auto; | ||
| 52 | + line-height: 32px; | ||
| 53 | + font-size: 20px; | ||
| 54 | + font-weight: bold; | ||
| 55 | + color: #eee; | ||
| 56 | + text-shadow: 0px -1px #000; | ||
| 57 | + padding:0 60px; | ||
| 58 | + } | ||
| 59 | + .navbtn { | ||
| 60 | + cursor: pointer; | ||
| 61 | + float:left; | ||
| 62 | + padding: 6px 10px; | ||
| 63 | + font-weight: bold; | ||
| 64 | + line-height: 18px; | ||
| 65 | + font-size: 14px; | ||
| 66 | + color: #eee; | ||
| 67 | + text-shadow: 0px -1px #000; | ||
| 68 | + border: solid 1px #111; | ||
| 69 | + border-radius: 4px; | ||
| 70 | + background-color: #404040; | ||
| 71 | + box-shadow: 0 0 1px 1px #555,inset 0 1px 0 0 #666; | ||
| 72 | + } | ||
| 73 | + .navbtn-hover, .navbtn:active { | ||
| 74 | + color: #222; | ||
| 75 | + text-shadow: 0px 1px #aaa; | ||
| 76 | + background-color: #aaa; | ||
| 77 | + box-shadow: 0 0 1px 1px #444,inset 0 1px 0 0 #ccc; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + #content{ | ||
| 81 | + position: absolute; | ||
| 82 | + top: 160px; | ||
| 83 | + left: 0px; | ||
| 84 | + right: 0px; | ||
| 85 | + bottom: 0px; | ||
| 86 | + overflow:hidden; | ||
| 87 | + background-color:#ddd; | ||
| 88 | + } | ||
| 89 | + #canvas{ | ||
| 90 | + cursor:crosshair ; | ||
| 91 | + background-color:#fff; | ||
| 92 | + } | ||
| 93 | + .palette-case { | ||
| 94 | + width:260px; | ||
| 95 | + margin:auto; | ||
| 96 | + text-align:center; | ||
| 97 | + } | ||
| 98 | + .palette-box { | ||
| 99 | + float:left; | ||
| 100 | + padding:2px 6px 2px 6px; | ||
| 101 | + } | ||
| 102 | + .palette { | ||
| 103 | + border:2px solid #777; | ||
| 104 | + height:36px; | ||
| 105 | + width:36px; | ||
| 106 | + } | ||
| 107 | + .red{ | ||
| 108 | + background-color:#c22; | ||
| 109 | + } | ||
| 110 | + .blue{ | ||
| 111 | + background-color:#22c; | ||
| 112 | + } | ||
| 113 | + .green{ | ||
| 114 | + background-color:#2c2; | ||
| 115 | + } | ||
| 116 | + .white{ | ||
| 117 | + background-color:#fff; | ||
| 118 | + } | ||
| 119 | + .black{ | ||
| 120 | + background-color:#000; | ||
| 121 | + border:2px dashed #fff; | ||
| 122 | + } | ||
| 123 | + </style> | ||
| 124 | + <style type="text/css"> | ||
| 125 | + td img { | ||
| 126 | + display: block; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + body { | ||
| 130 | + background-color: #191919; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + a:link { | ||
| 134 | + text-decoration: none; | ||
| 135 | + color: #F00; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + a:hover { | ||
| 139 | + text-decoration: underline; | ||
| 140 | + color: #F00; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + a:visited { | ||
| 144 | + text-decoration: none; | ||
| 145 | + color: #F00; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + a:active { | ||
| 149 | + text-decoration: none; | ||
| 150 | + color: #F00; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + .style22 { | ||
| 154 | + color: #666666; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + .style23 { | ||
| 158 | + font-family: Arial, Helvetica, sans-serif; | ||
| 159 | + font-size: 12px; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + .style31 { | ||
| 163 | + font-family: "Arial"; | ||
| 164 | + color: #999999; | ||
| 165 | + font-size: 12px; | ||
| 166 | + font-weight: bold; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + .style34 { | ||
| 170 | + font-family: "Arial"; | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + .style24 { | ||
| 174 | + font-size: 11px; | ||
| 175 | + color: #999999; | ||
| 176 | + font-family: Arial, Helvetica, sans-serif; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + .style62 { | ||
| 180 | + font-size: 12px; | ||
| 181 | + color: #999999; | ||
| 182 | + font-family: "myriad Pro"; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + .style67 { | ||
| 186 | + font-family: "myriad Pro"; | ||
| 187 | + color: #999999; | ||
| 188 | + font-size: 12px; | ||
| 189 | + font-weight: bold; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + .style69 { | ||
| 193 | + font-family: "Arial"; | ||
| 194 | + color: #999999; | ||
| 195 | + font-weight: bold; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + .style1 { | ||
| 199 | + font-family: Arial, Helvetica, sans-serif; | ||
| 200 | + color: #999999; | ||
| 201 | + font-size: 14px; | ||
| 202 | + font-weight: bold; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + .style3 { | ||
| 206 | + font-family: "Arial"; | ||
| 207 | + font-size: 12px; | ||
| 208 | + line-height: normal; | ||
| 209 | + height: 10px; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + .style71 { | ||
| 213 | + font-family: "myriad Pro"; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + .style73 { | ||
| 217 | + font-family: Arial; | ||
| 218 | + color: #999999; | ||
| 219 | + font-size: 12px; | ||
| 220 | + font-weight: bold; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + .style74 { | ||
| 224 | + font-size: 12px; | ||
| 225 | + color: #999999; | ||
| 226 | + font-family: Arial; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + .style75 { | ||
| 230 | + font-family: Arial; | ||
| 231 | + color: #CCC; | ||
| 232 | + font-size: 12px; | ||
| 233 | + font-weight: bold; | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + .style76 { | ||
| 237 | + font-size: 12px; | ||
| 238 | + font-family: Arial; | ||
| 239 | + color: #FF0000; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + .style81 { | ||
| 243 | + font-family: Arial; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + .style82 { | ||
| 247 | + color: #999999; | ||
| 248 | + font-size: 12px; | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + .style83 { | ||
| 252 | + font-size: 12px; | ||
| 253 | + font-weight: bold; | ||
| 254 | + color: #999999; | ||
| 255 | + } | ||
| 256 | + </style> | ||
| 257 | + | ||
| 258 | + | ||
| 259 | + <script language="javascript"> | ||
| 260 | + var initload = true; | ||
| 261 | + var ctx, color = "#000"; | ||
| 262 | + var voffset = 160; | ||
| 263 | + var footerheight = 50; | ||
| 264 | + var canvas_width,canvas_height; | ||
| 265 | + var ext_input_panel_width,ext_input_panel_height; | ||
| 266 | + var ratio_x,ratio_y; | ||
| 267 | + var ext_input_open = false; | ||
| 268 | + var cur_pen_type = 0; | ||
| 269 | + | ||
| 270 | + | ||
| 271 | + // function to setup a new canvas for drawing | ||
| 272 | + function newCanvas() { | ||
| 273 | + //define and resize canvas | ||
| 274 | + canvas_width = window.innerWidth-100; | ||
| 275 | + canvas_height = window.innerHeight - voffset - footerheight ; | ||
| 276 | + document.getElementById("content").style.height = canvas_height; | ||
| 277 | + var canvas = '<canvas id="canvas" width="' + window.innerWidth + '" height="' + canvas_height + '"></canvas>'; | ||
| 278 | + document.getElementById("content").innerHTML = canvas; | ||
| 279 | + | ||
| 280 | + // setup canvas | ||
| 281 | + ctx = document.getElementById("canvas").getContext("2d"); | ||
| 282 | + ctx.strokeStyle = color; | ||
| 283 | + ctx.lineWidth = 0.2; | ||
| 284 | + ctx.translate(0.5, 0.5); | ||
| 285 | + | ||
| 286 | + // setup to trigger drawing on mouse or touch | ||
| 287 | + drawTouch(); | ||
| 288 | + drawPointer(); | ||
| 289 | + drawMouse(); | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + | ||
| 293 | + function Point(x , y, p) { | ||
| 294 | + this.x = x; | ||
| 295 | + this.y = y; | ||
| 296 | + this.p = p; | ||
| 297 | + } | ||
| 298 | + | ||
| 299 | + var previousPoint = new Point(0, 0, 0), currentPoint = new Point(0, 0, 0); | ||
| 300 | + var previousWidth = 0; | ||
| 301 | + var kWIDTH_MIN = 0.2; | ||
| 302 | + var kWIDTH_MAX = 3.0; | ||
| 303 | + //current width | ||
| 304 | + var strokeWidth = 3.0; | ||
| 305 | + var rotate_degree = 0; | ||
| 306 | + var pressure_level = 2048.0 - 1; | ||
| 307 | + var draw_method = 0; | ||
| 308 | + | ||
| 309 | + function draw_method_change(){ | ||
| 310 | + draw_method = document.getElementById("draw_method").selectedIndex; | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + function draw_ext_input(px,py,p) { | ||
| 314 | + if(p > pressure_level) { | ||
| 315 | + //something maybe wrong | ||
| 316 | + return ; | ||
| 317 | + } | ||
| 318 | + if(draw_method == 0) { | ||
| 319 | + draw_ext_input_dda(px,py,p); | ||
| 320 | + } | ||
| 321 | + else if(draw_method == 1) { | ||
| 322 | + draw_ext_input_line(px,py,p); | ||
| 323 | + } | ||
| 324 | + } | ||
| 325 | + | ||
| 326 | + | ||
| 327 | + | ||
| 328 | + function draw_ext_input_line(px,py,p) { | ||
| 329 | + if(currentPoint.p == 0){ | ||
| 330 | + if (p != 0) { | ||
| 331 | + currentPoint.x = px * ratio_x; | ||
| 332 | + currentPoint.y = py * ratio_y; | ||
| 333 | + currentPoint.p = p; | ||
| 334 | + draw_point(currentPoint); | ||
| 335 | + } | ||
| 336 | + } | ||
| 337 | + else if(p != 0) { | ||
| 338 | + ctx.beginPath(); | ||
| 339 | + ctx.moveTo(currentPoint.x, currentPoint.y); | ||
| 340 | + ctx.lineWidth = previousWidth; | ||
| 341 | + currentPoint.x = px * ratio_x; | ||
| 342 | + currentPoint.y = py * ratio_y; | ||
| 343 | + ctx.lineTo(currentPoint.x, currentPoint.y); | ||
| 344 | + ctx.stroke(); | ||
| 345 | + | ||
| 346 | + currentPoint.p = p; | ||
| 347 | + draw_point(currentPoint); | ||
| 348 | + } | ||
| 349 | + else { | ||
| 350 | + currentPoint.p = p; | ||
| 351 | + } | ||
| 352 | + } | ||
| 353 | + | ||
| 354 | + | ||
| 355 | + function draw_ext_input_dda(px, py, p) { | ||
| 356 | + if(p == 0) { | ||
| 357 | + previousPoint.p = 0; | ||
| 358 | + } | ||
| 359 | + else { | ||
| 360 | + //currentPoint.x = Math.round( px * ratio_x); | ||
| 361 | + //currentPoint.y = Math.round( py * ratio_y); | ||
| 362 | + | ||
| 363 | + currentPoint.x = px * ratio_x; | ||
| 364 | + currentPoint.y = py * ratio_y; | ||
| 365 | + | ||
| 366 | + currentPoint.p = p; | ||
| 367 | + | ||
| 368 | + if(previousPoint.p == 0) { | ||
| 369 | + draw_point(currentPoint); | ||
| 370 | + } | ||
| 371 | + else { | ||
| 372 | + draw_line(currentPoint); | ||
| 373 | + } | ||
| 374 | + | ||
| 375 | + previousPoint.x = currentPoint.x; | ||
| 376 | + previousPoint.y = currentPoint.y; | ||
| 377 | + previousPoint.p = currentPoint.p; | ||
| 378 | + } | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + $( function() { | ||
| 382 | + $( "#line_width_slider" ).slider({ | ||
| 383 | + range: true, | ||
| 384 | + min: 1, | ||
| 385 | + max: 100, | ||
| 386 | + values: [ 2, 32 ], | ||
| 387 | + slide: function( event, ui ) { | ||
| 388 | + $( "#line_width" ).val( ui.values[ 0 ] /10.0+ " - " + ui.values[ 1 ] /10.0); | ||
| 389 | + kWIDTH_MIN = ui.values[ 0 ] /10.0; | ||
| 390 | + kWIDTH_MAX = ui.values[ 1 ] /10.0; | ||
| 391 | + } | ||
| 392 | + }); | ||
| 393 | + $( "#line_width" ).val( $( "#line_width_slider" ).slider( "values", 0 )/10.0 + | ||
| 394 | + " - " + $( "#line_width_slider" ).slider( "values", 1 )/10.0 ); | ||
| 395 | + } ); | ||
| 396 | + | ||
| 397 | + | ||
| 398 | + function setStrokeWidth(strokeWidth) { | ||
| 399 | + strokeWidth = strokeWidth; | ||
| 400 | + kWIDTH_MAX = strokeWidth; | ||
| 401 | + kWIDTH_MIN = strokeWidth / 3; | ||
| 402 | + } | ||
| 403 | + | ||
| 404 | + | ||
| 405 | + function draw_point(pt){ | ||
| 406 | + var line_width = (kWIDTH_MAX - kWIDTH_MIN)/pressure_level * pt.p + kWIDTH_MIN; | ||
| 407 | + ctx.beginPath(); //Start path | ||
| 408 | + ctx.lineWidth = 0.1; | ||
| 409 | + ctx.arc(pt.x, pt.y, line_width/2, 0, Math.PI * 2, true); // Draw a point using the arc function of the canvas with a point structure. | ||
| 410 | + ctx.fill(); | ||
| 411 | + previousWidth = line_width; | ||
| 412 | + } | ||
| 413 | + | ||
| 414 | + function draw_line(pt) { | ||
| 415 | + var dy = pt.y - previousPoint.y; | ||
| 416 | + var dx = pt.x - previousPoint.x; | ||
| 417 | + | ||
| 418 | + var abs_dy = Math.abs(dy); | ||
| 419 | + var abs_dx = Math.abs(dx); | ||
| 420 | + | ||
| 421 | + if(abs_dy < 0.1 && abs_dx < 0.1) { | ||
| 422 | + if(pt.p > previousPoint.p) { | ||
| 423 | + draw_point(pt); | ||
| 424 | + } | ||
| 425 | + return; | ||
| 426 | + } | ||
| 427 | + else if(abs_dy <= 1 && abs_dx <=1) { | ||
| 428 | + draw_point(pt); | ||
| 429 | + return; | ||
| 430 | + } | ||
| 431 | + | ||
| 432 | + | ||
| 433 | + var stepx, stepy ,stepw; | ||
| 434 | + var times = 0; | ||
| 435 | + var w0 = previousWidth; | ||
| 436 | + var w1 = (kWIDTH_MAX - kWIDTH_MIN)/pressure_level * pt.p + kWIDTH_MIN; | ||
| 437 | + var dw = w1 - w0; | ||
| 438 | + | ||
| 439 | + | ||
| 440 | + if (abs_dy >= abs_dx) { | ||
| 441 | + times += abs_dy; | ||
| 442 | + stepx = dx * 1.0 / abs_dy; | ||
| 443 | + stepy = dy / abs_dy; | ||
| 444 | + stepw = dw * 1.0 / abs_dy; | ||
| 445 | + } | ||
| 446 | + else | ||
| 447 | + { | ||
| 448 | + times += abs_dx; | ||
| 449 | + stepx = dx / abs_dx; | ||
| 450 | + stepy = dy * 1.0 / abs_dx; | ||
| 451 | + stepw = dw * 1.0 / abs_dx; | ||
| 452 | + } | ||
| 453 | + | ||
| 454 | + var x = previousPoint.x + stepx; | ||
| 455 | + var y = previousPoint.y + stepy; | ||
| 456 | + var w = w0 + stepw; | ||
| 457 | + | ||
| 458 | + while (times > 0) { | ||
| 459 | + times = times - 1; | ||
| 460 | + ctx.beginPath(); //Start path | ||
| 461 | + if(w < kWIDTH_MIN) { | ||
| 462 | + w = kWIDTH_MIN; | ||
| 463 | + } | ||
| 464 | + ctx.arc(x, y, w /2, 0, Math.PI * 2, true); // Draw a point using the arc function of the canvas with a point structure. | ||
| 465 | + ctx.fill(); | ||
| 466 | + x += stepx; | ||
| 467 | + y += stepy; | ||
| 468 | + w += stepw; | ||
| 469 | + } | ||
| 470 | + | ||
| 471 | + ctx.beginPath(); //Start path | ||
| 472 | + ctx.arc(pt.x, pt.y, w1 /2, 0, Math.PI * 2, true); // Draw a point using the arc function of the canvas with a point structure. | ||
| 473 | + ctx.fill(); | ||
| 474 | + | ||
| 475 | + previousWidth = w1; | ||
| 476 | + } | ||
| 477 | + | ||
| 478 | + | ||
| 479 | + function onTouchDownEvent(x, y, p) { | ||
| 480 | + previousPoint = null; | ||
| 481 | + currentPoint = null; | ||
| 482 | + currentPoint = new Point(x, y, 0); | ||
| 483 | + previousPoint = currentPoint; | ||
| 484 | + } | ||
| 485 | + | ||
| 486 | + function onTouchMoveEvent(x, y, p) { | ||
| 487 | + if (previousPoint == null) { | ||
| 488 | + return; | ||
| 489 | + } | ||
| 490 | + | ||
| 491 | + previousPoint = currentPoint; | ||
| 492 | + currentPoint = new Point(x, y, p); | ||
| 493 | + draw_line(currentPoint); | ||
| 494 | + } | ||
| 495 | + | ||
| 496 | + function onTouchUpEvent(x, y, p) { | ||
| 497 | + if (previousPoint == null) { | ||
| 498 | + return; | ||
| 499 | + } | ||
| 500 | + previousPoint = currentPoint; | ||
| 501 | + currentPoint = new Point(x, y, 0); | ||
| 502 | + | ||
| 503 | + draw_line(currentPoint); | ||
| 504 | + } | ||
| 505 | + | ||
| 506 | + //------end | ||
| 507 | + | ||
| 508 | + function selectColor(el) { | ||
| 509 | + for (var i = 0; i < document.getElementsByClassName("palette").length; i++) { | ||
| 510 | + document.getElementsByClassName("palette")[i].style.borderColor = "#777"; | ||
| 511 | + document.getElementsByClassName("palette")[i].style.borderStyle = "solid"; | ||
| 512 | + } | ||
| 513 | + el.style.borderColor = "#fff"; | ||
| 514 | + el.style.borderStyle = "dashed"; | ||
| 515 | + color = window.getComputedStyle(el).backgroundColor; | ||
| 516 | + ctx.beginPath(); | ||
| 517 | + ctx.strokeStyle = color; | ||
| 518 | + } | ||
| 519 | + | ||
| 520 | + // prototype to start drawing on touch using canvas moveTo and lineTo | ||
| 521 | + var drawTouch = function () { | ||
| 522 | + var start = function (e) { | ||
| 523 | + ctx.beginPath(); | ||
| 524 | + ctx.lineWidth = kWIDTH_MIN; | ||
| 525 | + x = e.changedTouches[0].pageX; | ||
| 526 | + y = e.changedTouches[0].pageY - voffset; | ||
| 527 | + ctx.moveTo(x, y); | ||
| 528 | + }; | ||
| 529 | + var move = function (e) { | ||
| 530 | + e.preventDefault(); | ||
| 531 | + x = e.changedTouches[0].pageX; | ||
| 532 | + y = e.changedTouches[0].pageY -voffset; | ||
| 533 | + ctx.lineTo(x, y); | ||
| 534 | + ctx.stroke(); | ||
| 535 | + }; | ||
| 536 | + document.getElementById("canvas").addEventListener("touchstart", start, false); | ||
| 537 | + document.getElementById("canvas").addEventListener("touchmove", move, false); | ||
| 538 | + }; | ||
| 539 | + | ||
| 540 | + // prototype to start drawing on pointer(microsoft ie) using canvas moveTo and lineTo | ||
| 541 | + var drawPointer = function () { | ||
| 542 | + var start = function (e) { | ||
| 543 | + e = e.originalEvent; | ||
| 544 | + ctx.beginPath(); | ||
| 545 | + x = e.pageX; | ||
| 546 | + y = e.pageY - voffset; | ||
| 547 | + ctx.moveTo(x, y); | ||
| 548 | + }; | ||
| 549 | + var move = function (e) { | ||
| 550 | + e.preventDefault(); | ||
| 551 | + e = e.originalEvent; | ||
| 552 | + x = e.pageX; | ||
| 553 | + y = e.pageY - voffset; | ||
| 554 | + ctx.lineTo(x, y); | ||
| 555 | + ctx.stroke(); | ||
| 556 | + }; | ||
| 557 | + document.getElementById("canvas").addEventListener("MSPointerDown", start, false); | ||
| 558 | + document.getElementById("canvas").addEventListener("MSPointerMove", move, false); | ||
| 559 | + }; | ||
| 560 | + | ||
| 561 | + // prototype to start drawing on mouse using canvas moveTo and lineTo | ||
| 562 | + var drawMouse = function () { | ||
| 563 | + var clicked = 0; | ||
| 564 | + var start = function (e) { | ||
| 565 | + clicked = 1; | ||
| 566 | + ctx.beginPath(); | ||
| 567 | + ctx.lineWidth = kWIDTH_MIN; | ||
| 568 | + x = e.pageX; | ||
| 569 | + y = e.pageY - voffset; | ||
| 570 | + ctx.moveTo(x, y); | ||
| 571 | + }; | ||
| 572 | + var move = function (e) { | ||
| 573 | + if (clicked) { | ||
| 574 | + x = e.pageX; | ||
| 575 | + y = e.pageY - voffset; | ||
| 576 | + ctx.lineTo(x, y); | ||
| 577 | + ctx.stroke(); | ||
| 578 | + } | ||
| 579 | + }; | ||
| 580 | + var stop = function (e) { | ||
| 581 | + clicked = 0; | ||
| 582 | + }; | ||
| 583 | + document.getElementById("canvas").addEventListener("mousedown", start, false); | ||
| 584 | + document.getElementById("canvas").addEventListener("mousemove", move, false); | ||
| 585 | + document.addEventListener("mouseup", stop, false); | ||
| 586 | + }; | ||
| 587 | + | ||
| 588 | + function dummy(){ | ||
| 589 | + var nPress = dv.getUint16(9, true); | ||
| 590 | + var x = dv.getUint16(11, true); | ||
| 591 | + var y = dv.getUint16(13, true); | ||
| 592 | + if(14 == type) { | ||
| 593 | + if(rotate_degree == 0) { | ||
| 594 | + draw_ext_input(x,y,nPress); | ||
| 595 | + } | ||
| 596 | + else if(rotate_degree == 90) { | ||
| 597 | + draw_ext_input(y, ext_input_panel_width - x ,nPress); | ||
| 598 | + } | ||
| 599 | + else if(rotate_degree == 180) { | ||
| 600 | + draw_ext_input(ext_input_panel_width - x, ext_input_panel_height - y, nPress); | ||
| 601 | + } | ||
| 602 | + else { | ||
| 603 | + draw_ext_input(ext_input_panel_height - y, x, nPress); | ||
| 604 | + } | ||
| 605 | + } | ||
| 606 | + else { | ||
| 607 | + draw_ext_input(x,y,nPress); | ||
| 608 | + } | ||
| 609 | + if(4 == type || 16 == type){ | ||
| 610 | + var nPoint = dv.getUint16(9,true); | ||
| 611 | + for (var i = 0; i < nPoint; i++) { | ||
| 612 | + var nPress = dv.getUint16(11 + i * 6, true); | ||
| 613 | + var x = dv.getUint16(13 + i * 6, true); | ||
| 614 | + var y = dv.getUint16(15 + i * 6, true); | ||
| 615 | + if (14 == type) { | ||
| 616 | + if (rotate_degree == 0) { | ||
| 617 | + draw_ext_input(x, y, nPress); | ||
| 618 | + } | ||
| 619 | + else if (rotate_degree == 90) { | ||
| 620 | + draw_ext_input(y, ext_input_panel_width - x, nPress); | ||
| 621 | + } | ||
| 622 | + else if (rotate_degree == 180) { | ||
| 623 | + draw_ext_input(ext_input_panel_width - x, ext_input_panel_height - y, nPress); | ||
| 624 | + } | ||
| 625 | + else { | ||
| 626 | + draw_ext_input(ext_input_panel_height - y, x, nPress); | ||
| 627 | + } | ||
| 628 | + } | ||
| 629 | + else { | ||
| 630 | + draw_ext_input(x, y, nPress); | ||
| 631 | + } | ||
| 632 | + } | ||
| 633 | + } | ||
| 634 | + } | ||
| 635 | + function writeToScreen(message) { | ||
| 636 | + var pre = document.createElement("p"); | ||
| 637 | + pre.style.wordWrap = "break-word"; | ||
| 638 | + pre.className = "style75"; | ||
| 639 | + pre.innerHTML = message; | ||
| 640 | + output.appendChild(pre); | ||
| 641 | + } | ||
| 642 | + | ||
| 643 | + function getExplorerTitle() { | ||
| 644 | + var explorer = window.navigator.userAgent.toLowerCase(); | ||
| 645 | + //ie | ||
| 646 | + if (explorer.indexOf("msie") >= 0 || explorer.indexOf("trident") > 0) { | ||
| 647 | + return "Internet Explorer"; | ||
| 648 | + } | ||
| 649 | + //firefox | ||
| 650 | + else if (explorer.indexOf("firefox") >= 0) { | ||
| 651 | + return "Mozilla Firefox"; | ||
| 652 | + } | ||
| 653 | + //Chrome | ||
| 654 | + else if (explorer.indexOf("chrome") >= 0) { | ||
| 655 | + return "Google Chrome"; | ||
| 656 | + } | ||
| 657 | + //Opera | ||
| 658 | + else if (explorer.indexOf("opera") >= 0) { | ||
| 659 | + return "Opera"; | ||
| 660 | + } | ||
| 661 | + //Safari | ||
| 662 | + else if (explorer.indexOf("Safari") >= 0) { | ||
| 663 | + return ""; | ||
| 664 | + } | ||
| 665 | + return ""; | ||
| 666 | + } | ||
| 667 | + | ||
| 668 | + | ||
| 669 | + window.onload = function () { | ||
| 670 | + | ||
| 671 | + newCanvas(); | ||
| 672 | + | ||
| 673 | + | ||
| 674 | + ext_input_panel_width = 21000; | ||
| 675 | + ext_input_panel_height = 29800; | ||
| 676 | + pressure_level = 2048.0 - 1; | ||
| 677 | + var w = ext_input_panel_width * 1.0; | ||
| 678 | + var h = ext_input_panel_height * 1.0; | ||
| 679 | + var canvasw = w / h * canvas_height; | ||
| 680 | + ratio_x = (canvasw + 0.0) / ext_input_panel_width; | ||
| 681 | + ratio_y = (canvas_height + 0.0) / ext_input_panel_height; | ||
| 682 | + rotate_degree = 0; | ||
| 683 | + } | ||
| 684 | + | ||
| 685 | + function onTestClick(obj) { | ||
| 686 | + send_pen_cmd(obj.id); | ||
| 687 | + } | ||
| 688 | + | ||
| 689 | + function rotateExtInput() { | ||
| 690 | + if(cur_pen_type == 0) { | ||
| 691 | + rotate_degree = rotate_degree + 90; | ||
| 692 | + if( rotate_degree == 360) { | ||
| 693 | + rotate_degree = 0; | ||
| 694 | + } | ||
| 695 | + | ||
| 696 | + if (rotate_degree == 0 || rotate_degree == 180) { | ||
| 697 | + var w = ext_input_panel_width * 1.0; | ||
| 698 | + var h = ext_input_panel_height * 1.0; | ||
| 699 | + var canvasw = w / h * canvas_height; | ||
| 700 | + ratio_x = (canvasw + 0.0) / w; | ||
| 701 | + ratio_y = (canvas_height + 0.0) / h; | ||
| 702 | + } | ||
| 703 | + else { | ||
| 704 | + var w = ext_input_panel_height * 1.0; | ||
| 705 | + var h = ext_input_panel_width * 1.0; | ||
| 706 | + var canvasw = w / h * canvas_height; | ||
| 707 | + ratio_x = (canvasw + 0.0) / w; | ||
| 708 | + ratio_y = (canvas_height + 0.0) / h; | ||
| 709 | + } | ||
| 710 | + } | ||
| 711 | + } | ||
| 712 | + | ||
| 713 | + | ||
| 714 | + function send_pen_cmd(cmd){ | ||
| 715 | + window.Native.pen_cmd(cmd); | ||
| 716 | + } | ||
| 717 | + | ||
| 718 | + function on_pen_cmd_result(cmd,result){ | ||
| 719 | + | ||
| 720 | + } | ||
| 721 | + | ||
| 722 | + function on_pen_point(x,y,nPress){ | ||
| 723 | + | ||
| 724 | + if (rotate_degree == 0) { | ||
| 725 | + draw_ext_input(x, y, nPress); | ||
| 726 | + } | ||
| 727 | + else if (rotate_degree == 90) { | ||
| 728 | + draw_ext_input(y, ext_input_panel_width - x, nPress); | ||
| 729 | + } | ||
| 730 | + else if (rotate_degree == 180) { | ||
| 731 | + draw_ext_input(ext_input_panel_width - x, ext_input_panel_height - y, nPress); | ||
| 732 | + } | ||
| 733 | + else { | ||
| 734 | + draw_ext_input(ext_input_panel_height - y, x, nPress); | ||
| 735 | + } | ||
| 736 | + } | ||
| 737 | + | ||
| 738 | + | ||
| 739 | + </script> | ||
| 740 | +</head> | ||
| 741 | +<body> | ||
| 742 | + <div > | ||
| 743 | + <a id="new" class="navbtn" onclick="newCanvas()">Clear</a> | ||
| 744 | + <a id="open" class="navbtn" onclick="onTestClick(this)">open</a> | ||
| 745 | + <a id="close" class="navbtn" onclick="onTestClick(this)">close</a> | ||
| 746 | + <a id="rotate_ext_input" class="navbtn" onclick="rotateExtInput()">Rotate</a> | ||
| 747 | + | ||
| 748 | + </div > | ||
| 749 | + | ||
| 750 | + <table > | ||
| 751 | + <tr> | ||
| 752 | + <td> | ||
| 753 | + <div class="palette white" onclick="selectColor(this)"></div> | ||
| 754 | + </td> | ||
| 755 | + <td> | ||
| 756 | + <div class="palette red" onclick="selectColor(this)"></div> | ||
| 757 | + </td> | ||
| 758 | + <td> | ||
| 759 | + | ||
| 760 | + <div class="palette blue" onclick="selectColor(this)"></div> | ||
| 761 | + </td> | ||
| 762 | + <td> | ||
| 763 | + <div class="palette green" onclick="selectColor(this)"></div> | ||
| 764 | + </td> | ||
| 765 | + <td> | ||
| 766 | + | ||
| 767 | + <div class="palette black" onclick="selectColor(this)"></div> | ||
| 768 | + </td> | ||
| 769 | + </tr> | ||
| 770 | + </table > | ||
| 771 | + <table> | ||
| 772 | + <tr> | ||
| 773 | + <td> | ||
| 774 | + <table width = "150"> | ||
| 775 | + <tr> | ||
| 776 | + <td id="line_width_slider"></td> | ||
| 777 | + </tr> | ||
| 778 | + </table> | ||
| 779 | + </td> | ||
| 780 | + <td> | ||
| 781 | + <input type="text" id="line_width" size="4" readonly style="border:0; color:#f6931f; font-weight:bold;"/> | ||
| 782 | + </td> | ||
| 783 | + <td> | ||
| 784 | + <div colspan="2"><select id="draw_method" name="draw_method" onchange='javascript:draw_method_change();'><option value ="use_arc">use dda</option><option value ="use_line">use line</option></select> | ||
| 785 | + </td> | ||
| 786 | + </tr> | ||
| 787 | + | ||
| 788 | + <div id="content"> | ||
| 789 | + <p style="text-align:center">Loading Canvas...</p> | ||
| 790 | + </div> | ||
| 791 | + | ||
| 792 | + <p id="info"></p> | ||
| 793 | +</body> | ||
| 794 | + | ||
| 795 | +</html> |
-
请 注册 或 登录 后发表评论