Skip to content

Commit

Permalink
Paintroid 433: Zoom window position, comments removed, tool compatibi…
Browse files Browse the repository at this point in the history
…lity with zoom window updated
  • Loading branch information
saat-sy committed Dec 11, 2022
1 parent 24f3f5b commit f696c1f
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 100 deletions.
1 change: 0 additions & 1 deletion Paintroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ dependencies {
implementation 'androidx.exifinterface:exifinterface:1.3.2'
implementation 'com.esotericsoftware:kryo:5.1.1'
implementation 'id.zelory:compressor:2.1.1'
androidTestImplementation project(path: ':Paintroid')
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

debugImplementation 'androidx.multidex:multidex:2.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ class ZoomWindowIntegrationTest {
onZoomWindow()
.checkAlignment(RelativeLayout.ALIGN_PARENT_RIGHT)
} else {
// Layout params rules for ALIGN_PARENT_LEFT and ALIGN_PARENT_RIGHT from
// https://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams#getRules()
// for API level less than M
onZoomWindow()
.checkAlignmentBelowM(11)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public final class ZoomWindowInteraction extends CustomViewInteraction {
private ZoomWindowInteraction() {
super(onView(withId(R.id.pocketpaint_zoom_window)));
super(onView(withId(R.id.pocketpaint_zoom_window_image)));
}

public static ZoomWindowInteraction onZoomWindow() {
Expand All @@ -29,7 +29,7 @@ public ZoomWindowInteraction checkAlignment(final int verb) {
protected boolean matchesSafely(View view) {
MainActivity activity = getMainActivityFromView(view);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
activity.findViewById(R.id.pocketpaint_zoom_window).getLayoutParams();
activity.findViewById(R.id.pocketpaint_zoom_window_image).getLayoutParams();

int rulesFromLayout = layoutParams.getRule(verb);

Expand All @@ -50,7 +50,7 @@ public ZoomWindowInteraction checkAlignmentBelowM(final int index) {
protected boolean matchesSafely(View view) {
MainActivity activity = getMainActivityFromView(view);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
activity.findViewById(R.id.pocketpaint_zoom_window).getLayoutParams();
activity.findViewById(R.id.pocketpaint_zoom_window_image).getLayoutParams();

int[] rulesFromLayout = layoutParams.getRules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ open class BrushTool(
}
}

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

override fun resetInternalState() {
pathToDraw.rewind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ class FillTool(
return true
}

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

public override fun resetInternalState() = Unit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ class HandTool(

override fun handleUp(coordinate: PointF?): Boolean = true

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

override fun handToolMode(): Boolean = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class ImportTool(
override val toolType: ToolType
get() = ToolType.IMPORTPNG

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

init {
rotationEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,7 @@ class LineTool(
return true
}

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

override fun resetInternalState() {
initialEventCoordinate = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ class PipetteTool(

override fun handleUp(coordinate: PointF?): Boolean = setColor(coordinate)

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

override fun resetInternalState() {
updateSurfaceBitmap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ class ShapeTool(
override val toolType: ToolType
get() = ToolType.SHAPE

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

init {
rotationEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ class SmudgeTool(
}
}

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

override fun draw(canvas: Canvas) {
if (pointArray.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ class SprayTool(
return true
}

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

override fun handleMove(coordinate: PointF?): Boolean {
currentCoordinate = coordinate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ class StampTool(
override val toolType: ToolType
get() = ToolType.STAMP

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

init {
rotationEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ class TextTool(
override val toolType: ToolType
get() = ToolType.TEXT

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

init {
rotationEnabled = ROTATION_ENABLED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ class TransformTool(
override val toolType: ToolType
get() = ToolType.TRANSFORM

override fun toolPositionCoordinates(coordinate: PointF): PointF =
// The tool coordinate is same as the touch coordinate
coordinate
override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate

init {
rotationEnabled = ROTATION_ENABLED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import org.catrobat.paintroid.tools.ToolType
import org.catrobat.paintroid.tools.options.ToolOptionsViewController
import org.catrobat.paintroid.ui.zoomwindow.ZoomWindowController
import org.catrobat.paintroid.ui.viewholder.DrawerLayoutViewHolder
import org.catrobat.paintroid.ui.zoomwindow.DefaultZoomWindowController

open class DrawingSurface : SurfaceView, SurfaceHolder.Callback {
private val canvasRect = Rect()
Expand Down Expand Up @@ -174,18 +175,11 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback {
}

val tool = toolReference.tool

// Will create the zoom window only if the tool is a compatible tool
when (checkCurrentTool(tool)) {
0 -> {
// NON-COMPATIBLE TOOLS
when (zoomController.checkIfToolCompatibleWithZoomWindow(tool)) {
DefaultZoomWindowController.Constants.NOT_COMPATIBLE -> {
tool?.draw(surfaceViewCanvas)
}
1 -> {
// LINE TOOL OR CURSOR TOOL
// Does not return the contents of the current layer
// But only the new lines drawn

DefaultZoomWindowController.Constants.COMPATIBLE_NEW -> {
val bitmapOfDrawingBoard = Bitmap.createBitmap(
layerModel.width, layerModel.height, Bitmap.Config.ARGB_8888)

Expand All @@ -200,8 +194,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback {
}
)
}
2 -> {
// OTHER COMPATIBLE TOOLS
DefaultZoomWindowController.Constants.COMPATIBLE_ALL -> {
val bitmapOfDrawingBoard = layerModel.currentLayer?.bitmap
surfaceViewCanvas.setBitmap(bitmapOfDrawingBoard)

Expand Down Expand Up @@ -245,30 +238,6 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback {
drawingSurfaceListener.disableAutoScroll()
}

private fun checkCurrentTool(tool: Tool?): Int {
if (
tool?.toolType?.name.equals(ToolType.HAND.name) ||
tool?.toolType?.name.equals(ToolType.FILL.name) ||
tool?.toolType?.name.equals(ToolType.STAMP.name) ||
tool?.toolType?.name.equals(ToolType.TRANSFORM.name)
) {
return 0
} else if (
tool?.toolType?.name.equals(ToolType.IMPORTPNG.name) ||
tool?.toolType?.name.equals(ToolType.SHAPE.name) ||
tool?.toolType?.name.equals(ToolType.TEXT.name)
) {
return 0
} else if (
tool?.toolType?.name.equals(ToolType.LINE.name) ||
tool?.toolType?.name.equals(ToolType.CURSOR.name)
) {
return 1
} else {
return 2
}
}

fun isPointOnCanvas(pointX: Int, pointY: Int): Boolean =
pointX > 0 && pointX < layerModel.width && pointY > 0 && pointY < layerModel.height

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,14 @@ class DefaultZoomWindowController
private val checkeredPattern = Paint()
private val framePaint = Paint()

// Getting the dimensions of the zoom window
private val windowHeight =
activity.resources.getDimensionPixelSize(R.dimen.pocketpaint_zoom_window_height)
private val windowWidth =
activity.resources.getDimensionPixelSize(R.dimen.pocketpaint_zoom_window_width)

// CHEQUERED
private val chequeredBackgroundBitmap =
Bitmap.createBitmap(layerModel.width, layerModel.height, Bitmap.Config.ARGB_8888)

// GREY BACKGROUND
private val greyBackgroundBitmap =
Bitmap.createBitmap(
layerModel.width + windowWidth,
Expand Down Expand Up @@ -97,8 +94,7 @@ class DefaultZoomWindowController
private var coordinates: PointF? = null

override fun show(coordinates: PointF) {
// Check if the tool is a compatible tool
if (checkCurrentTool(toolReference.tool) &&
if (checkIfToolCompatibleWithZoomWindow(toolReference.tool) != Constants.NOT_COMPATIBLE &&
isPointOnCanvas(coordinates.x, coordinates.y)) {
if (shouldBeInTheRight(coordinates = coordinates)) {
setLayoutAlignment(right = true)
Expand Down Expand Up @@ -150,25 +146,21 @@ class DefaultZoomWindowController

private fun setLayoutAlignment(right: Boolean) {
val params: RelativeLayout.LayoutParams =
zoomWindow.layoutParams as RelativeLayout.LayoutParams
zoomWindowImage.layoutParams as RelativeLayout.LayoutParams
if (right) {
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
params.removeRule(RelativeLayout.ALIGN_PARENT_LEFT)
} else {
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT)
params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT)
}
zoomWindow.layoutParams = params
zoomWindowImage.layoutParams = params
}

private fun cropBitmap(bitmap: Bitmap?, coordinates: PointF): Bitmap? {

val bitmapWithBackground: Bitmap? = mergeBackground(bitmap)

// StartX and StartY coordinates
// StartX and StartY - windowWidth / 2, without the grey background
// But since we are adding the grey background, windowWidth / 2 should be added
// So they get cancelled
val startX: Int = coordinates.x.roundToInt()
val startY: Int = coordinates.y.roundToInt()

Expand Down Expand Up @@ -199,18 +191,16 @@ class DefaultZoomWindowController

private fun mergeBackground(bitmap: Bitmap?): Bitmap? {

// Adding the extra width and height for the grey background
val bmOverlay =
val bitmapOverlay =
Bitmap.createBitmap(
layerModel.width + windowWidth,
layerModel.height + windowHeight,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bmOverlay)
val canvas = Canvas(bitmapOverlay)

canvas.drawBitmap(backgroundBitmap, Matrix(), null)

// Add the current layer if the tool is line or cursor tool
if (toolReference.tool?.toolType?.name.equals(ToolType.LINE.name) ||
toolReference.tool?.toolType?.name.equals(ToolType.CURSOR.name)) {
layerModel.currentLayer?.bitmap?.let {
Expand All @@ -220,25 +210,36 @@ class DefaultZoomWindowController

bitmap?.let { canvas.drawBitmap(it, windowWidth / 2f, windowHeight / 2f, null) }

return bmOverlay
return bitmapOverlay
}

private fun checkCurrentTool(tool: Tool?): Boolean {
override fun checkIfToolCompatibleWithZoomWindow(tool: Tool?): Constants {
if (
tool?.toolType?.name.equals(ToolType.HAND.name) ||
tool?.toolType?.name.equals(ToolType.FILL.name) ||
tool?.toolType?.name.equals(ToolType.STAMP.name) ||
tool?.toolType?.name.equals(ToolType.TRANSFORM.name)
) {
return false
return Constants.NOT_COMPATIBLE
} else if (
tool?.toolType?.name.equals(ToolType.IMPORTPNG.name) ||
tool?.toolType?.name.equals(ToolType.SHAPE.name) ||
tool?.toolType?.name.equals(ToolType.TEXT.name)
) {
return false
return Constants.NOT_COMPATIBLE
} else if (
tool?.toolType?.name.equals(ToolType.LINE.name) ||
tool?.toolType?.name.equals(ToolType.CURSOR.name)
) {
return Constants.COMPATIBLE_NEW
} else {
return true
return Constants.COMPATIBLE_ALL
}
}

enum class Constants {
NOT_COMPATIBLE,
COMPATIBLE_NEW,
COMPATIBLE_ALL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.catrobat.paintroid.ui.zoomwindow

import android.graphics.Bitmap
import android.graphics.PointF
import org.catrobat.paintroid.tools.Tool

interface ZoomWindowController {
fun show(coordinates: PointF)
Expand All @@ -13,4 +14,6 @@ interface ZoomWindowController {
fun onMove(coordinates: PointF)

fun getBitmap(bitmap: Bitmap?)

fun checkIfToolCompatibleWithZoomWindow(tool: Tool?): DefaultZoomWindowController.Constants
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<stroke android:width="3dp" android:color="@color/pocketpaint_colorAccent"/>
</shape>
</shape>

0 comments on commit f696c1f

Please sign in to comment.