Changeset 107 for trunk/src/org/expeditee/items/Text.java
- Timestamp:
- 06/20/08 16:48:33 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Text.java
r106 r107 8 8 import java.awt.Point; 9 9 import java.awt.Polygon; 10 import java.awt.Rectangle;11 10 import java.awt.Stroke; 12 11 import java.awt.event.KeyEvent; … … 396 395 float y = getLineDrop(last) * line; 397 396 398 int x = (Math.round(getX() + caret[0]) + getJustOffset(last));397 float x = getX() + caret[0] + getJustOffset(last); 399 398 x = Math 400 399 .min( 401 400 x, 402 401 (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth())); 403 return new Point( x, Math.round(getY() + y + caret[1]));402 return new Point(Math.round(x), Math.round(getY() + y + caret[1])); 404 403 } 405 404 … … 617 616 float y = getLineDrop(current) * line; 618 617 619 int x = Math.round(getX() + caret[0])+ getJustOffset(current);618 float x = getX() + caret[0] + getJustOffset(current); 620 619 x = Math 621 620 .min( 622 621 x, 623 622 (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth())); 624 return new Point( x, Math.round(getY() + y + caret[1]));623 return new Point(Math.round(x), Math.round(getY() + y + caret[1])); 625 624 } 626 625 … … 701 700 float y = getLineDrop(current) * line; 702 701 703 return new Point(Math.round(getX() + caret[0]) 704 + getJustOffset(current), Math.round(getY() + y + caret[1])); 702 return new Point( 703 Math.round(getX() + caret[0]) + getJustOffset(current), Math 704 .round(getY() + y + caret[1])); 705 705 } 706 706 … … 715 715 * @return The position in the string of the character being pointed at. 716 716 */ 717 p rivateTextHitInfo getCharPosition(int line, int mouseX) {717 public TextHitInfo getCharPosition(int line, int mouseX) { 718 718 if (line < 0 || line >= _textLayouts.size()) 719 719 return null; … … 726 726 } 727 727 728 p rivateint getLinePosition(int mouseY) {728 public int getLinePosition(int mouseY) { 729 729 mouseY += getOffset().y; 730 730 731 int y = getY();731 float y = getY(); 732 732 733 733 for (TextLayout text : _textLayouts) { 734 734 // calculate X to ensure it is in the shape 735 Rectangle bounds = text.getLogicalHighlightShape(0,736 text.getCharacterCount()).getBounds ();735 Rectangle2D bounds = text.getLogicalHighlightShape(0, 736 text.getCharacterCount()).getBounds2D(); 737 737 738 738 if (bounds.getWidth() < 1) 739 bounds = new Rectangle((int) bounds.getMinX(), (int)bounds740 .getMinY(), 10, (int)bounds.getHeight());739 bounds.setRect(bounds.getMinX(), bounds 740 .getMinY(), 10, bounds.getHeight()); 741 741 742 742 double x = bounds.getCenterX(); 743 743 744 // if(text.getLogicalHighlightShape(0,745 // text.getCharacterCount()).contains(text.getBounds().getMinX()746 // + 10, mouseY - getY() - (y - getY())))747 744 if (bounds.contains(x, mouseY - getY() - (y - getY()))) 748 745 return _textLayouts.indexOf(text); … … 973 970 public boolean intersects(Polygon p) { 974 971 if (super.intersects(p)) { 975 int textY = getY();972 float textY = getY(); 976 973 977 974 for (TextLayout text : _textLayouts) { 978 975 // check left and right of each box 979 Rectangle textOutline = text.getLogicalHighlightShape(0, 980 text.getCharacterCount()).getBounds(); 981 textOutline.width += 2; 982 textOutline.height += 2; 983 984 textOutline.translate(getX() - 1, textY - 1); 976 Rectangle2D textOutline = text.getLogicalHighlightShape(0, 977 text.getCharacterCount()).getBounds2D(); 978 textOutline 979 .setRect(textOutline.getX() + getX() - 1, textOutline 980 .getY() 981 + textY - 1, textOutline.getWidth() + 2, 982 textOutline.getHeight() + 2); 985 983 if (p.intersects(textOutline)) 986 984 return true; … … 1000 998 mouseY += getOffset().y; 1001 999 1002 int textY = getY();1003 int textX = getX();1004 1005 Rectangle outline = getPolygon().getBounds();1000 float textY = getY(); 1001 float textX = getX(); 1002 1003 Rectangle2D outline = getPolygon().getBounds2D(); 1006 1004 1007 1005 // Check if its outside the top and left and bottom bounds 1008 if (outline.x - mouseX > gravity || outline.y - mouseY > gravity 1009 || mouseY - (outline.y + outline.height) > gravity 1010 || mouseX - (outline.x + outline.width) > gravity) { 1006 if (outline.getX() - mouseX > gravity 1007 || outline.getY() - mouseY > gravity 1008 || mouseY - (outline.getY() + outline.getHeight()) > gravity 1009 || mouseX - (outline.getX() + outline.getWidth()) > gravity) { 1011 1010 return false; 1012 1011 } … … 1014 1013 for (TextLayout text : _textLayouts) { 1015 1014 // check left and right of each box 1016 Rectangle textOutline = text.getLogicalHighlightShape(0,1017 text.getCharacterCount()).getBounds ();1015 Rectangle2D textOutline = text.getLogicalHighlightShape(0, 1016 text.getCharacterCount()).getBounds2D(); 1018 1017 1019 1018 // check if the cursor is within the top, bottom and within the 1020 1019 // gravity of right 1021 if (mouseY - textY > textOutline.y 1022 && mouseY - textY < textOutline.y + textOutline.height 1023 && mouseX - textX < textOutline.width + gravity 1020 if (mouseY - textY > textOutline.getY() 1021 && mouseY - textY < textOutline.getY() 1022 + textOutline.getHeight() 1023 && mouseX - textX < textOutline.getWidth() + gravity 1024 1024 + Item.MARGIN_RIGHT) 1025 1025 return true; … … 1353 1353 g.setColor(getPaintHighlightColor()); 1354 1354 Stroke _highlightStroke = new BasicStroke( 1355 (float) _highlightThickness, BasicStroke.CAP_BUTT, 1356 BasicStroke.JOIN_ROUND); 1355 (float) _highlightThickness, CAP, JOIN); 1357 1356 g.setStroke(_highlightStroke); 1358 1357 g.drawPolygon(getPolygon()); … … 1621 1620 // bottom of text lines... so the cursor must be between two text 1622 1621 // lines 1623 int textY = getY();1624 int textX = getX();1622 float textY = getY(); 1623 float textX = getX(); 1625 1624 1626 1625 for (TextLayout text : _textLayouts) { 1627 1626 // check left and right of each box 1628 Rectangle textOutline = text.getLogicalHighlightShape(0,1629 text.getCharacterCount()).getBounds ();1627 Rectangle2D textOutline = text.getLogicalHighlightShape(0, 1628 text.getCharacterCount()).getBounds2D(); 1630 1629 1631 1630 // check if the cursor is within the top, bottom and within the 1632 1631 // gravity of right 1633 if (y - textY > textOutline. y- NEAR_DISTANCE1634 && y - textY < textOutline. y + textOutline.height1635 + NEAR_DISTANCE1636 && x - textX < textOutline. width+ NEAR_DISTANCE)1632 if (y - textY > textOutline.getY() - NEAR_DISTANCE 1633 && y - textY < textOutline.getY() 1634 + textOutline.getHeight() + NEAR_DISTANCE 1635 && x - textX < textOutline.getWidth() + NEAR_DISTANCE) 1637 1636 return true; 1638 1637 textY += getLineDrop(text);
Note:
See TracChangeset
for help on using the changeset viewer.