[934] | 1 | package org.expeditee.items.MagneticConstraint.Utilities;
|
---|
| 2 |
|
---|
[1102] | 3 | import org.expeditee.gio.EcosystemManager;
|
---|
| 4 | import org.expeditee.gui.DisplayController;
|
---|
[934] | 5 | import org.expeditee.items.Text;
|
---|
| 6 |
|
---|
| 7 | public class TextLogic {
|
---|
| 8 |
|
---|
| 9 | public static boolean XIsTowardsRight(final int x, final Text text) {
|
---|
| 10 | if(text.getPixelBoundsUnion() == null) return false;
|
---|
[1102] | 11 | final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX();
|
---|
[962] | 12 | return /*text.getText().length() == 1 ||*/ distanceThroughText > (text.getPixelBoundsUnion().getWidth() / 2);
|
---|
[934] | 13 | }
|
---|
| 14 |
|
---|
| 15 | public static boolean XIsTowardsLeft(final Text text, final int x) {
|
---|
| 16 | if(text.getPixelBoundsUnion() == null) return false;
|
---|
[1102] | 17 | final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX();
|
---|
[934] | 18 | return distanceThroughText < (text.getPixelBoundsUnion().getWidth() / 2);
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | public static boolean XIsBeforeCharacters(final Text text, final int x) {
|
---|
| 22 | try {
|
---|
[1102] | 23 | final int firstLetterWidth = EcosystemManager.getTextLayoutManager().getStringWidth(null, text.getText().substring(0, 1));
|
---|
| 24 | final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX();
|
---|
[934] | 25 | return firstLetterWidth > distanceThroughText;
|
---|
| 26 | } catch (NullPointerException e) {
|
---|
| 27 | return false;
|
---|
| 28 | } catch (StringIndexOutOfBoundsException e) {
|
---|
| 29 | return false;
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | public static boolean XIsAfterCharacters(final Text text, final int x) {
|
---|
| 34 | try {
|
---|
[1102] | 35 | final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX();
|
---|
[934] | 36 | return distanceThroughText > text.getPixelBoundsUnion().getWidth();
|
---|
| 37 | } catch (NullPointerException e) {
|
---|
| 38 | return false;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[963] | 42 | public static int GetInsertionIndexSelected(final Text text) {
|
---|
[1102] | 43 | return text.getCharPosition(0, DisplayController.getMouseX()).getInsertionIndex();
|
---|
[934] | 44 | }
|
---|
| 45 | }
|
---|