| 526 | } |
| 527 | |
| 528 | bool wxShape::HitTest(double x, double y, int *attachment, double *distance) |
| 529 | { |
| 530 | // if (!sensitive) |
| 531 | // return false; |
| 532 | |
| 533 | double width = 0.0, height = 0.0; |
| 534 | GetBoundingBoxMin(&width, &height); |
| 535 | if (fabs(width) < 4.0) width = 4.0; |
| 536 | if (fabs(height) < 4.0) height = 4.0; |
| 537 | |
| 538 | width += (double)4.0; height += (double)4.0; // Allowance for inaccurate mousing |
| 539 | |
| 540 | double left = (double)(m_xpos - (width/2.0)); |
| 541 | double top = (double)(m_ypos - (height/2.0)); |
| 542 | double right = (double)(m_xpos + (width/2.0)); |
| 543 | double bottom = (double)(m_ypos + (height/2.0)); |
| 544 | |
| 545 | int nearest_attachment = 0; |
| 546 | |
| 547 | // If within the bounding box, check the attachment points |
| 548 | // within the object. |
| 549 | |
| 550 | if (x >= left && x <= right && y >= top && y <= bottom) |
| 551 | { |
| 552 | int n = GetNumberOfAttachments(); |
| 553 | double nearest = 999999.0; |
| 554 | |
| 555 | // GetAttachmentPosition[Edge] takes a logical attachment position, |
| 556 | // i.e. if it's rotated through 90%, position 0 is East-facing. |
| 557 | |
| 558 | for (int i = 0; i < n; i++) |
| 559 | { |
| 560 | double xp, yp; |
| 561 | if (GetAttachmentPositionEdge(i, &xp, &yp)) |
| 562 | { |
| 563 | double l = (double)sqrt(((xp - x) * (xp - x)) + |
| 564 | ((yp - y) * (yp - y))); |
| 565 | |
| 566 | if (l < nearest) |
| 567 | { |
| 568 | nearest = l; |
| 569 | nearest_attachment = i; |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | *attachment = nearest_attachment; |
| 574 | *distance = nearest; |
| 575 | return true; |
| 576 | } |
| 577 | else return false; |
| 578 | } |
| 579 | |
| 580 | // Format a text string according to the region size, adding |
| 581 | // strings with positions to region text list |
no outgoing calls
no test coverage detected