Changeset 107


Ignore:
Timestamp:
06/20/08 16:48:33 (16 years ago)
Author:
ra33
Message:

Fixed rounding errors in Text class...
They caused a whole bunch of problems with small fonts and text items with several lines!

Location:
trunk/src/org/expeditee
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Misc.java

    r105 r107  
    318318                        fontsList.append(s).append('\n');
    319319                }
     320                fontsList.deleteCharAt(fontsList.length()-1);
    320321
    321322                Text text = DisplayIO.getCurrentFrame().createNewText();
  • trunk/src/org/expeditee/actions/Simple.java

    r106 r107  
    11331133                                                context.getPrimitives().setValue(tokens[2],
    11341134                                                                new SString(currentFrame.getName()));
     1135                                        }
     1136                                } else if (tokens[0].equals("getcurrentitem")) {
     1137                                        assertMinParametreCount(tokens, 1);
     1138                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     1139
     1140                                        Item currentItem = FrameUtils.getCurrentItem();
     1141
     1142                                        context.getPointers().setObject(tokens[1], currentItem);
     1143
     1144                                        // check if the user is also after line position
     1145                                        if (currentItem != null && currentItem instanceof Text
     1146                                                        && tokens.length > 2) {
     1147                                                Text text = (Text) currentItem;
     1148                                                int cursorLinePos = text
     1149                                                                .getLinePosition(FrameMouseActions.getY());
     1150                                                context.getPrimitives().setValue(tokens[2],
     1151                                                                new SInteger(cursorLinePos + 1));
     1152                                                if (tokens.length > 3) {
     1153                                                        int cursorCharPos = text.getCharPosition(
     1154                                                                        cursorLinePos, DisplayIO.getMouseX())
     1155                                                                        .getCharIndex();
     1156                                                        context.getPrimitives().setValue(tokens[3],
     1157                                                                        new SInteger(cursorCharPos + 1));
     1158                                                }
    11351159                                        }
    11361160                                }
     
    17241748                        boolean success = fileContents != null;
    17251749                        if (!success)
    1726                                 FrameGraphics.WarningMessage("Error copying " + frameToCopy.getName());
     1750                                FrameGraphics.WarningMessage("Error copying "
     1751                                                + frameToCopy.getName());
    17271752                        FrameIO.ResumeCache();
    17281753                        if (tokens.length > 4) {
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r105 r107  
    10991099         */
    11001100        public static Item onItem(Frame toCheck, float floatX, float floatY) {
     1101                //System.out.println("MouseX: " + floatX + " MouseY: " + floatY);
     1102               
    11011103                int x = Math.round(floatX);
    11021104                int y = Math.round(floatY);
     
    11501152                                if (!(FrameGraphics.isAudienceMode() && i.isAnnotation())) {
    11511153                                        if (i.contains(x, y) && !Frame.FreeItems.contains(i)) {
    1152                                                 // names have copy permissions only
    1153                                                 if (i == toCheck.getNameItem()) {
    1154                                                         // i.Permission = Item.PERMISSION_TDFC;
    1155                                                         possibles.add(i);
    1156                                                 } else {
    1157                                                         // i.Permission = Item.PERMISSION_FULL;
    1158                                                         possibles.add(i);
    1159                                                 }
     1154                                                possibles.add(i);
    11601155                                        }
    11611156                                }
     
    12141209        }
    12151210
    1216         public static Item getCurrentItem() {
     1211        public synchronized static Item getCurrentItem() {
    12171212                return onItem(DisplayIO.getCurrentFrame(), DisplayIO.getMouseX(),
    12181213                                FrameMouseActions.getY());
  • trunk/src/org/expeditee/items/Item.java

    r106 r107  
    11package org.expeditee.items;
    22
     3import java.awt.BasicStroke;
    34import java.awt.Color;
    45import java.awt.Cursor;
     
    3839public abstract class Item implements Comparable<Item>, Runnable {
    3940
     41        protected final int JOIN = BasicStroke.JOIN_ROUND;
     42
     43        protected final int CAP = BasicStroke.CAP_BUTT;
     44       
    4045        // contains all dots (including this one) that form an enclosure
    4146        // if this dot is part of an enclosing shape
  • trunk/src/org/expeditee/items/Line.java

    r105 r107  
    5757
    5858        private boolean _isCircle = false;
    59 
    60         // TODO find out why bevel is not working
    61         private final int JOIN = BasicStroke.JOIN_ROUND;
    62 
    63         private final int CAP = BasicStroke.CAP_BUTT;
    6459
    6560        // brush strokes used for painting this line and highlighting
  • trunk/src/org/expeditee/items/Text.java

    r106 r107  
    88import java.awt.Point;
    99import java.awt.Polygon;
    10 import java.awt.Rectangle;
    1110import java.awt.Stroke;
    1211import java.awt.event.KeyEvent;
     
    396395                float y = getLineDrop(last) * line;
    397396
    398                 int x = (Math.round(getX() + caret[0]) + getJustOffset(last));
     397                float x = getX() + caret[0] + getJustOffset(last);
    399398                x = Math
    400399                                .min(
    401400                                                x,
    402401                                                (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]));
    404403        }
    405404
     
    617616                float y = getLineDrop(current) * line;
    618617
    619                 int x = Math.round(getX() + caret[0]) + getJustOffset(current);
     618                float x = getX() + caret[0] + getJustOffset(current);
    620619                x = Math
    621620                                .min(
    622621                                                x,
    623622                                                (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]));
    625624        }
    626625
     
    701700                float y = getLineDrop(current) * line;
    702701
    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]));
    705705        }
    706706
     
    715715         * @return The position in the string of the character being pointed at.
    716716         */
    717         private TextHitInfo getCharPosition(int line, int mouseX) {
     717        public TextHitInfo getCharPosition(int line, int mouseX) {
    718718                if (line < 0 || line >= _textLayouts.size())
    719719                        return null;
     
    726726        }
    727727
    728         private int getLinePosition(int mouseY) {
     728        public int getLinePosition(int mouseY) {
    729729                mouseY += getOffset().y;
    730730
    731                 int y = getY();
     731                float y = getY();
    732732
    733733                for (TextLayout text : _textLayouts) {
    734734                        // 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();
    737737
    738738                        if (bounds.getWidth() < 1)
    739                                 bounds = new Rectangle((int) bounds.getMinX(), (int) bounds
    740                                                 .getMinY(), 10, (int) bounds.getHeight());
     739                                bounds.setRect(bounds.getMinX(), bounds
     740                                                .getMinY(), 10, bounds.getHeight());
    741741
    742742                        double x = bounds.getCenterX();
    743743
    744                         // if(text.getLogicalHighlightShape(0,
    745                         // text.getCharacterCount()).contains(text.getBounds().getMinX()
    746                         // + 10, mouseY - getY() - (y - getY())))
    747744                        if (bounds.contains(x, mouseY - getY() - (y - getY())))
    748745                                return _textLayouts.indexOf(text);
     
    973970        public boolean intersects(Polygon p) {
    974971                if (super.intersects(p)) {
    975                         int textY = getY();
     972                        float textY = getY();
    976973
    977974                        for (TextLayout text : _textLayouts) {
    978975                                // 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);
    985983                                if (p.intersects(textOutline))
    986984                                        return true;
     
    1000998                mouseY += getOffset().y;
    1001999
    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();
    10061004
    10071005                // 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) {
    10111010                        return false;
    10121011                }
     
    10141013                for (TextLayout text : _textLayouts) {
    10151014                        // 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();
    10181017
    10191018                        // check if the cursor is within the top, bottom and within the
    10201019                        // 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
    10241024                                                        + Item.MARGIN_RIGHT)
    10251025                                return true;
     
    13531353                        g.setColor(getPaintHighlightColor());
    13541354                        Stroke _highlightStroke = new BasicStroke(
    1355                                         (float) _highlightThickness, BasicStroke.CAP_BUTT,
    1356                                         BasicStroke.JOIN_ROUND);
     1355                                        (float) _highlightThickness, CAP, JOIN);
    13571356                        g.setStroke(_highlightStroke);
    13581357                        g.drawPolygon(getPolygon());
     
    16211620                        // bottom of text lines... so the cursor must be between two text
    16221621                        // lines
    1623                         int textY = getY();
    1624                         int textX = getX();
     1622                        float textY = getY();
     1623                        float textX = getX();
    16251624
    16261625                        for (TextLayout text : _textLayouts) {
    16271626                                // 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();
    16301629
    16311630                                // check if the cursor is within the top, bottom and within the
    16321631                                // gravity of right
    1633                                 if (y - textY > textOutline.y - NEAR_DISTANCE
    1634                                                 && y - textY < textOutline.y + textOutline.height
    1635                                                                 + NEAR_DISTANCE
    1636                                                 && 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)
    16371636                                        return true;
    16381637                                textY += getLineDrop(text);
Note: See TracChangeset for help on using the changeset viewer.