Search in sources :

Example 1 with Swatch

use of org.telegram.ui.Components.Paint.Swatch in project Telegram-FOSS by Telegram-FOSS-Team.

the class CropView method editBitmap.

public static void editBitmap(Context context, String path, Bitmap b, Canvas canvas, Bitmap canvasBitmap, Bitmap.CompressFormat format, Matrix stateMatrix, int contentWidth, int contentHeight, float stateScale, float rotation, float orientationOnly, float scale, boolean mirror, ArrayList<VideoEditedInfo.MediaEntity> entities, boolean clear) {
    try {
        if (clear) {
            canvasBitmap.eraseColor(0);
        }
        if (b == null) {
            b = BitmapFactory.decodeFile(path);
        }
        float sc = Math.max(b.getWidth(), b.getHeight()) / (float) Math.max(contentWidth, contentHeight);
        Matrix matrix = new Matrix();
        matrix.postTranslate(-b.getWidth() / 2, -b.getHeight() / 2);
        if (mirror) {
            matrix.postScale(-1, 1);
        }
        matrix.postScale(1.0f / sc, 1.0f / sc);
        matrix.postRotate(orientationOnly);
        matrix.postConcat(stateMatrix);
        matrix.postScale(scale, scale);
        matrix.postTranslate(canvasBitmap.getWidth() / 2, canvasBitmap.getHeight() / 2);
        canvas.drawBitmap(b, matrix, new Paint(Paint.FILTER_BITMAP_FLAG));
        FileOutputStream stream = new FileOutputStream(new File(path));
        canvasBitmap.compress(format, 87, stream);
        stream.close();
        if (entities != null && !entities.isEmpty()) {
            float[] point = new float[4];
            float newScale = 1.0f / sc * scale * stateScale;
            float widthScale = b.getWidth() / (float) canvasBitmap.getWidth();
            newScale *= widthScale;
            TextPaintView textPaintView = null;
            for (int a = 0, N = entities.size(); a < N; a++) {
                VideoEditedInfo.MediaEntity entity = entities.get(a);
                point[0] = entity.x * b.getWidth() + entity.viewWidth * entity.scale / 2;
                point[1] = entity.y * b.getHeight() + entity.viewHeight * entity.scale / 2;
                point[2] = entity.textViewX * b.getWidth();
                point[3] = entity.textViewY * b.getHeight();
                matrix.mapPoints(point);
                if (entity.type == 0) {
                    entity.viewWidth = entity.viewHeight = canvasBitmap.getWidth() / 2;
                } else if (entity.type == 1) {
                    entity.fontSize = canvasBitmap.getWidth() / 9;
                    if (textPaintView == null) {
                        textPaintView = new TextPaintView(context, new Point(0, 0), entity.fontSize, "", new Swatch(Color.BLACK, 0.85f, 0.1f), 0);
                        textPaintView.setMaxWidth(canvasBitmap.getWidth() - 20);
                    }
                    int type;
                    if ((entity.subType & 1) != 0) {
                        type = 0;
                    } else if ((entity.subType & 4) != 0) {
                        type = 2;
                    } else {
                        type = 1;
                    }
                    textPaintView.setType(type);
                    textPaintView.setText(entity.text);
                    textPaintView.measure(MeasureSpec.makeMeasureSpec(canvasBitmap.getWidth(), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(canvasBitmap.getHeight(), MeasureSpec.AT_MOST));
                    entity.viewWidth = textPaintView.getMeasuredWidth();
                    entity.viewHeight = textPaintView.getMeasuredHeight();
                }
                entity.scale *= newScale;
                entity.x = (point[0] - entity.viewWidth * entity.scale / 2) / canvasBitmap.getWidth();
                entity.y = (point[1] - entity.viewHeight * entity.scale / 2) / canvasBitmap.getHeight();
                entity.textViewX = point[2] / canvasBitmap.getWidth();
                entity.textViewY = point[3] / canvasBitmap.getHeight();
                entity.width = entity.viewWidth * entity.scale / canvasBitmap.getWidth();
                entity.height = entity.viewHeight * entity.scale / canvasBitmap.getHeight();
                entity.textViewWidth = entity.viewWidth / (float) canvasBitmap.getWidth();
                entity.textViewHeight = entity.viewHeight / (float) canvasBitmap.getHeight();
                entity.rotation -= (rotation + orientationOnly) * (Math.PI / 180);
            }
        }
        b.recycle();
    } catch (Throwable e) {
        FileLog.e(e);
    }
}
Also used : Swatch(org.telegram.ui.Components.Paint.Swatch) TextPaintView(org.telegram.ui.Components.Paint.Views.TextPaintView) Paint(android.graphics.Paint) Point(org.telegram.ui.Components.Point) Point(org.telegram.ui.Components.Point) Paint(android.graphics.Paint) Matrix(android.graphics.Matrix) FileOutputStream(java.io.FileOutputStream) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) File(java.io.File)

Example 2 with Swatch

use of org.telegram.ui.Components.Paint.Swatch in project Telegram-FOSS by Telegram-FOSS-Team.

the class PhotoPaintView method setType.

private void setType(int type) {
    selectedTextType = type;
    if (currentEntityView instanceof TextPaintView) {
        Swatch currentSwatch = colorPicker.getSwatch();
        if (type == 0 && currentSwatch.color == Color.WHITE) {
            Swatch blackSwatch = new Swatch(Color.BLACK, 0.85f, currentSwatch.brushWeight);
            setCurrentSwatch(blackSwatch, true);
        } else if ((type == 1 || type == 2) && currentSwatch.color == Color.BLACK) {
            Swatch blackSwatch = new Swatch(Color.WHITE, 1.0f, currentSwatch.brushWeight);
            setCurrentSwatch(blackSwatch, true);
        }
        ((TextPaintView) currentEntityView).setType(type);
    }
}
Also used : Swatch(org.telegram.ui.Components.Paint.Swatch) TextPaintView(org.telegram.ui.Components.Paint.Views.TextPaintView)

Example 3 with Swatch

use of org.telegram.ui.Components.Paint.Swatch in project Telegram-FOSS by Telegram-FOSS-Team.

the class PhotoPaintView method createText.

private TextPaintView createText(boolean select) {
    onTextAdd();
    Swatch currentSwatch = colorPicker.getSwatch();
    Swatch swatch;
    if (selectedTextType == 0) {
        swatch = new Swatch(Color.BLACK, 0.85f, currentSwatch.brushWeight);
    } else if (selectedTextType == 1) {
        swatch = new Swatch(Color.WHITE, 1.0f, currentSwatch.brushWeight);
    } else {
        swatch = new Swatch(Color.WHITE, 1.0f, currentSwatch.brushWeight);
    }
    Size paintingSize = getPaintingSize();
    TextPaintView view = new TextPaintView(getContext(), startPositionRelativeToEntity(null), (int) (paintingSize.width / 9), "", swatch, selectedTextType);
    view.setDelegate(this);
    view.setMaxWidth((int) (paintingSize.width - 20));
    entitiesView.addView(view, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
    if (currentCropState != null) {
        view.scale(1.0f / currentCropState.cropScale);
        view.rotate(-(currentCropState.transformRotation + currentCropState.cropRotate));
    }
    if (select) {
        registerRemovalUndo(view);
        selectEntity(view);
        editSelectedTextEntity();
    }
    setCurrentSwatch(swatch, true);
    return view;
}
Also used : Swatch(org.telegram.ui.Components.Paint.Swatch) TextPaintView(org.telegram.ui.Components.Paint.Views.TextPaintView)

Aggregations

Swatch (org.telegram.ui.Components.Paint.Swatch)3 TextPaintView (org.telegram.ui.Components.Paint.Views.TextPaintView)3 Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 VideoEditedInfo (org.telegram.messenger.VideoEditedInfo)1 Point (org.telegram.ui.Components.Point)1