Java Code Examples for org.telegram.tgnet.TLRPC#TL_maskCoords

The following examples show how to use org.telegram.tgnet.TLRPC#TL_maskCoords . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhotoPaintView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private PhotoFace getRandomFaceWithVacantAnchor(int anchor, long documentId, TLRPC.TL_maskCoords maskCoords) {
    if (anchor < 0 || anchor > 3 || faces.isEmpty()) {
        return null;
    }

    int count = faces.size();
    int randomIndex = Utilities.random.nextInt(count);
    int remaining = count;

    PhotoFace selectedFace = null;
    for (int i = randomIndex; remaining > 0; i = (i + 1) % count, remaining--) {
        PhotoFace face = faces.get(i);
        if (!isFaceAnchorOccupied(face, anchor, documentId, maskCoords)) {
            return face;
        }
    }

    return selectedFace;
}
 
Example 2
Source File: PhotoPaintView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private PhotoFace getRandomFaceWithVacantAnchor(int anchor, long documentId, TLRPC.TL_maskCoords maskCoords) {
    if (anchor < 0 || anchor > 3 || faces.isEmpty()) {
        return null;
    }

    int count = faces.size();
    int randomIndex = Utilities.random.nextInt(count);
    int remaining = count;

    PhotoFace selectedFace = null;
    for (int i = randomIndex; remaining > 0; i = (i + 1) % count, remaining--) {
        PhotoFace face = faces.get(i);
        if (!isFaceAnchorOccupied(face, anchor, documentId, maskCoords)) {
            return face;
        }
    }

    return selectedFace;
}
 
Example 3
Source File: PhotoPaintView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private StickerPosition calculateStickerPosition(TLRPC.Document document) {
TLRPC.TL_maskCoords maskCoords = null;

for (int a = 0; a < document.attributes.size(); a++) {
    TLRPC.DocumentAttribute attribute = document.attributes.get(a);
    if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
        maskCoords = attribute.mask_coords;
        break;
    }
}

StickerPosition defaultPosition = new StickerPosition(centerPositionForEntity(), 0.75f, 0.0f);
/*
if (maskCoords == null || faces == null || faces.size() == 0) {
    return defaultPosition;
} else {
    int anchor = maskCoords.n;

    PhotoFace face = getRandomFaceWithVacantAnchor(anchor, document.id, maskCoords);
    if (face == null) {*/
        return defaultPosition;
    }
 
Example 4
Source File: PhotoPaintView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private PhotoFace getRandomFaceWithVacantAnchor(int anchor, long documentId, TLRPC.TL_maskCoords maskCoords) {
    if (anchor < 0 || anchor > 3 || faces.isEmpty()) {
        return null;
    }

    int count = faces.size();
    int randomIndex = Utilities.random.nextInt(count);
    int remaining = count;

    PhotoFace selectedFace = null;
    for (int i = randomIndex; remaining > 0; i = (i + 1) % count, remaining--) {
        PhotoFace face = faces.get(i);
        if (!isFaceAnchorOccupied(face, anchor, documentId, maskCoords)) {
            return face;
        }
    }

    return selectedFace;
}
 
Example 5
Source File: PhotoPaintView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean isFaceAnchorOccupied(PhotoFace face, int anchor, long documentId, TLRPC.TL_maskCoords maskCoords) {
    Point anchorPoint = face.getPointForAnchor(anchor);
    if (anchorPoint == null) {
        return true;
    }

    float minDistance = face.getWidthForAnchor(0) * 1.1f;

    for (int index = 0; index < entitiesView.getChildCount(); index++) {
        View view = entitiesView.getChildAt(index);
        if (!(view instanceof StickerView)) {
            continue;
        }

        StickerView stickerView = (StickerView) view;
        if (stickerView.getAnchor() != anchor) {
            continue;
        }

        Point location = stickerView.getPosition();
        float distance = (float)Math.hypot(location.x - anchorPoint.x, location.y - anchorPoint.y);
        if ((documentId == stickerView.getSticker().id || faces.size() > 1) && distance < minDistance) {
            return true;
        }
    }

    return false;
}
 
Example 6
Source File: PhotoPaintView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean isFaceAnchorOccupied(PhotoFace face, int anchor, long documentId, TLRPC.TL_maskCoords maskCoords) {
    Point anchorPoint = face.getPointForAnchor(anchor);
    if (anchorPoint == null) {
        return true;
    }

    float minDistance = face.getWidthForAnchor(0) * 1.1f;

    for (int index = 0; index < entitiesView.getChildCount(); index++) {
        View view = entitiesView.getChildAt(index);
        if (!(view instanceof StickerView)) {
            continue;
        }

        StickerView stickerView = (StickerView) view;
        if (stickerView.getAnchor() != anchor) {
            continue;
        }

        Point location = stickerView.getPosition();
        float distance = (float)Math.hypot(location.x - anchorPoint.x, location.y - anchorPoint.y);
        if ((documentId == stickerView.getSticker().id || faces.size() > 1) && distance < minDistance) {
            return true;
        }
    }

    return false;
}
 
Example 7
Source File: PhotoPaintView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private boolean isFaceAnchorOccupied(PhotoFace face, int anchor, long documentId, TLRPC.TL_maskCoords maskCoords) {
    Point anchorPoint = face.getPointForAnchor(anchor);
    if (anchorPoint == null) {
        return true;
    }

    float minDistance = face.getWidthForAnchor(0) * 1.1f;

    for (int index = 0; index < entitiesView.getChildCount(); index++) {
        View view = entitiesView.getChildAt(index);
        if (!(view instanceof StickerView)) {
            continue;
        }

        StickerView stickerView = (StickerView) view;
        if (stickerView.getAnchor() != anchor) {
            continue;
        }

        Point location = stickerView.getPosition();
        float distance = (float)Math.hypot(location.x - anchorPoint.x, location.y - anchorPoint.y);
        if ((documentId == stickerView.getSticker().id || faces.size() > 1) && distance < minDistance) {
            return true;
        }
    }

    return false;
}