正在显示
1 个修改的文件
包含
43 行增加
和
48 行删除
| @@ -371,76 +371,71 @@ | @@ -371,76 +371,71 @@ | ||
| 371 | drawMouse(); | 371 | drawMouse(); |
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | - var draw_method = 0; | 374 | + |
| 375 | + function Point(x , y, p) { | ||
| 376 | + this.x = x; | ||
| 377 | + this.y = y; | ||
| 378 | + this.p = p; | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + var previousPoint = new Point(0, 0, 0), currentPoint = new Point(0, 0, 0); | ||
| 382 | + var previousWidth = 0; | ||
| 383 | + var kWIDTH_MIN = 0.2; | ||
| 384 | + var kWIDTH_MAX = 3.0; | ||
| 385 | + //current width | ||
| 386 | + var strokeWidth = 3.0; | ||
| 387 | + var rotate_degree = 0; | ||
| 388 | + var pressure_level = 2048.0 - 1; | ||
| 389 | + var draw_method = 0; | ||
| 375 | 390 | ||
| 376 | function draw_method_change(){ | 391 | function draw_method_change(){ |
| 377 | draw_method = document.getElementById("draw_method").selectedIndex; | 392 | draw_method = document.getElementById("draw_method").selectedIndex; |
| 378 | } | 393 | } |
| 379 | 394 | ||
| 380 | function draw_ext_input(px,py,p) { | 395 | function draw_ext_input(px,py,p) { |
| 396 | + if(p > pressure_level) { | ||
| 397 | + //something maybe wrong | ||
| 398 | + return ; | ||
| 399 | + } | ||
| 381 | if(draw_method == 0) { | 400 | if(draw_method == 0) { |
| 382 | - draw_ext_input_arc(px,py,p); | 401 | + draw_ext_input_dda(px,py,p); |
| 383 | } | 402 | } |
| 384 | else if(draw_method == 1) { | 403 | else if(draw_method == 1) { |
| 385 | draw_ext_input_line(px,py,p); | 404 | draw_ext_input_line(px,py,p); |
| 386 | } | 405 | } |
| 387 | } | 406 | } |
| 388 | 407 | ||
| 389 | - var last_ext_press = 0; | ||
| 390 | - var last_x = 0; | ||
| 391 | - var last_y = 0; | ||
| 392 | - function draw_ext_input_line(px,py,p) { | ||
| 393 | - x = px * ratio_x; | ||
| 394 | - y = py * ratio_y; | ||
| 395 | - if(last_ext_press == 0){ | 408 | + |
| 409 | + | ||
| 410 | + function draw_ext_input_line(px,py,p) { | ||
| 411 | + if(currentPoint.p == 0){ | ||
| 396 | if (p != 0) { | 412 | if (p != 0) { |
| 397 | - ctx.beginPath(); | ||
| 398 | - ctx.lineWidth = (kWIDTH_MAX - kWIDTH_MIN) / pressure_level * p + kWIDTH_MIN; | ||
| 399 | - ctx.moveTo(x, y); | ||
| 400 | - ctx.lineTo(x, y); | ||
| 401 | - ctx.stroke(); | ||
| 402 | - last_x = x; | ||
| 403 | - last_y = y; | 413 | + currentPoint.x = px * ratio_x; |
| 414 | + currentPoint.y = py * ratio_y; | ||
| 415 | + currentPoint.p = p; | ||
| 416 | + draw_point(currentPoint); | ||
| 404 | } | 417 | } |
| 405 | } | 418 | } |
| 406 | else if(p != 0) { | 419 | else if(p != 0) { |
| 407 | ctx.beginPath(); | 420 | ctx.beginPath(); |
| 408 | - ctx.lineWidth = (kWIDTH_MAX - kWIDTH_MIN)/pressure_level * p + kWIDTH_MIN; | ||
| 409 | - ctx.moveTo(last_x, last_y); | ||
| 410 | - ctx.lineTo(x, y); | 421 | + ctx.moveTo(currentPoint.x, currentPoint.y); |
| 422 | + ctx.lineWidth = previousWidth; | ||
| 423 | + currentPoint.x = px * ratio_x; | ||
| 424 | + currentPoint.y = py * ratio_y; | ||
| 425 | + ctx.lineTo(currentPoint.x, currentPoint.y); | ||
| 411 | ctx.stroke(); | 426 | ctx.stroke(); |
| 412 | - last_x = x; | ||
| 413 | - last_y = y; | 427 | + |
| 428 | + currentPoint.p = p; | ||
| 429 | + draw_point(currentPoint); | ||
| 414 | } | 430 | } |
| 415 | else { | 431 | else { |
| 416 | - ctx.beginPath(); | ||
| 417 | - ctx.lineWidth = (kWIDTH_MAX - kWIDTH_MIN)/pressure_level * last_ext_press + kWIDTH_MIN; | ||
| 418 | - ctx.moveTo(last_x, last_y); | ||
| 419 | - ctx.lineTo(x, y); | ||
| 420 | - ctx.stroke(); | 432 | + currentPoint.p = p; |
| 421 | } | 433 | } |
| 422 | - | ||
| 423 | - last_ext_press = p; | ||
| 424 | } | 434 | } |
| 425 | 435 | ||
| 426 | - function Point(x , y, p) { | ||
| 427 | - this.x = x; | ||
| 428 | - this.y = y; | ||
| 429 | - this.p = p; | ||
| 430 | - } | ||
| 431 | - | ||
| 432 | - | ||
| 433 | - var previousPoint = new Point(0,0,0), currentPoint= new Point(0,0,0); | ||
| 434 | - var previousWidth = 0; | ||
| 435 | - var kWIDTH_MIN = 0.2; | ||
| 436 | - var kWIDTH_MAX = 3.0; | ||
| 437 | - //current width | ||
| 438 | - var strokeWidth = 3.0; | ||
| 439 | - var rotate_degree = 0; | ||
| 440 | - var pressure_level = 2048.0 - 1; | ||
| 441 | 436 | ||
| 442 | - function draw_ext_input_arc(px, py, press) { | ||
| 443 | - if(press == 0) { | 437 | + function draw_ext_input_dda(px, py, p) { |
| 438 | + if(p == 0) { | ||
| 444 | previousPoint.p = 0; | 439 | previousPoint.p = 0; |
| 445 | } | 440 | } |
| 446 | else { | 441 | else { |
| @@ -450,7 +445,7 @@ | @@ -450,7 +445,7 @@ | ||
| 450 | currentPoint.x = px * ratio_x; | 445 | currentPoint.x = px * ratio_x; |
| 451 | currentPoint.y = py * ratio_y; | 446 | currentPoint.y = py * ratio_y; |
| 452 | 447 | ||
| 453 | - currentPoint.p = press; | 448 | + currentPoint.p = p; |
| 454 | 449 | ||
| 455 | if(previousPoint.p == 0) { | 450 | if(previousPoint.p == 0) { |
| 456 | draw_point(currentPoint); | 451 | draw_point(currentPoint); |
| @@ -469,7 +464,7 @@ | @@ -469,7 +464,7 @@ | ||
| 469 | $( "#line_width_slider" ).slider({ | 464 | $( "#line_width_slider" ).slider({ |
| 470 | range: true, | 465 | range: true, |
| 471 | min: 1, | 466 | min: 1, |
| 472 | - max: 50, | 467 | + max: 100, |
| 473 | values: [ 2, 32 ], | 468 | values: [ 2, 32 ], |
| 474 | slide: function( event, ui ) { | 469 | slide: function( event, ui ) { |
| 475 | $( "#line_width" ).val( ui.values[ 0 ] /10.0+ " - " + ui.values[ 1 ] /10.0); | 470 | $( "#line_width" ).val( ui.values[ 0 ] /10.0+ " - " + ui.values[ 1 ] /10.0); |
| @@ -2073,7 +2068,7 @@ | @@ -2073,7 +2068,7 @@ | ||
| 2073 | <td><input type="text" id="line_width" size="10" readonly style="border:0; color:#f6931f; font-weight:bold;"/></td>> | 2068 | <td><input type="text" id="line_width" size="10" readonly style="border:0; color:#f6931f; font-weight:bold;"/></td>> |
| 2074 | 2069 | ||
| 2075 | <td colspan="2"><select id="pen_type" name="pen_type"><option value ="PendoTech">PendoTech PH-1820-A</option><option value ="robot">Nebula T7</option></select></td> | 2070 | <td colspan="2"><select id="pen_type" name="pen_type"><option value ="PendoTech">PendoTech PH-1820-A</option><option value ="robot">Nebula T7</option></select></td> |
| 2076 | - <td colspan="2"><select id="draw_method" name="draw_method" onchange='javascript:draw_method_change();'><option value ="use_arc">use arc</option><option value ="use_line">use line</option></select></td> | 2071 | + <td 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></td> |
| 2077 | </tr> | 2072 | </tr> |
| 2078 | </table> | 2073 | </table> |
| 2079 | </div> | 2074 | </div> |
-
请 注册 或 登录 后发表评论