-
Notifications
You must be signed in to change notification settings - Fork 818
CATROID-1647 Feat: Resize and rotate object when placing in stage #5189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
harshsomankar123-tech
wants to merge
17
commits into
Catrobat:develop
Choose a base branch
from
harshsomankar123-tech:feature/IDE-217-resize-rotate-object-in-stage
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c8149fc
[RED] IDE-217: Add tests and boilerplate for resize/rotate visual pla…
harshsomankar123-tech 7125602
[GREEN] IDE-217: Implement resize/rotate logic and visual overlay in …
harshsomankar123-tech 1cddac9
Fix: SonarCloud reliability and Android Lint issues in Resize and rot…
harshsomankar123-tech 2aabacc
Fix: detekt unused imports, missing braces and SonarCloud reliability…
harshsomankar123-tech 85cdf69
Fix: All SonarCloud reliability and detekt issues in Visual Placement…
harshsomankar123-tech 9d954a9
Refactor: Final SonarCloud reliability and maintainability fixes (IDE…
harshsomankar123-tech e881f71
Fix: Rename rotation field in VisualPlacementActivity to resolve Sona…
harshsomankar123-tech 4fdde17
Fix bugs in ProjectActivity.kt, SpriteActivity.java, and VisualPlacem…
harshsomankar123-tech abfe6d3
Address PR #5189 review comments: fix angle normalization, touch base…
harshsomankar123-tech 32292e8
Fix detekt bot warning and SonarQube code smell
harshsomankar123-tech bf8eeee
Fix touch interaction jumps and cleanup ProjectActivity constants
harshsomankar123-tech d0ae7e5
Remove unused local variable in VisualPlacementTouchListener
harshsomankar123-tech 170bec1
Add regression unit tests for visual placement in ProjectActivity (ID…
harshsomankar123-tech 57d5096
Fix visual placement rotation bug, add panning/snapping and reset but…
harshsomankar123-tech c59065d
Add Rotate 90° toolbar button and update tests (IDE-217)
harshsomankar123-tech a0fd2f4
Fix: Prevent resize from changing position and orientation (IDE-217)
harshsomankar123-tech e152f09
Refactor: Reduce cognitive complexity of onCreate in VisualPlacementA…
harshsomankar123-tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
catroid/src/main/java/org/catrobat/catroid/visualplacement/BoundingBoxOverlay.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /* | ||
| * Catroid: An on-device visual programming system for Android devices | ||
| * Copyright (C) 2010-2026 The Catrobat Team | ||
| * (<http://developer.catrobat.org/credits>) | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * An additional term exception under section 7 of the GNU Affero | ||
| * General Public License, version 3, is available at | ||
| * http://developer.catrobat.org/license_additional_term | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package org.catrobat.catroid.visualplacement | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.Canvas | ||
| import android.graphics.Paint | ||
| import android.graphics.RectF | ||
| import android.view.View | ||
| import android.widget.ImageView | ||
| import androidx.core.content.ContextCompat | ||
| import androidx.core.graphics.toColorInt | ||
| import androidx.core.graphics.withRotation | ||
| import androidx.core.graphics.withTranslation | ||
| import org.catrobat.catroid.R | ||
|
|
||
| class BoundingBoxOverlay(context: Context) : View(context) { | ||
|
|
||
| private val boundingBoxPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { | ||
| color = BOUNDING_BOX_COLOR | ||
| style = Paint.Style.STROKE | ||
| strokeWidth = BOUNDING_BOX_STROKE_WIDTH | ||
| } | ||
|
|
||
| private val cornerHandleDrawable = ContextCompat.getDrawable(context, R.drawable.ic_corner_handle) | ||
|
|
||
| private val handleSizePx: Int = | ||
| (HANDLE_SIZE_DP * context.resources.displayMetrics.density).toInt() | ||
|
|
||
| private val rect = RectF() | ||
|
|
||
| var trackedImageView: ImageView? = null | ||
|
|
||
| fun updateOverlay() { | ||
| invalidate() | ||
| } | ||
|
|
||
| override fun onDraw(canvas: Canvas) { | ||
| super.onDraw(canvas) | ||
|
|
||
| val imageView = trackedImageView ?: return | ||
| val drawable = imageView.drawable ?: return | ||
|
|
||
| val imgWidth = drawable.intrinsicWidth.toFloat() | ||
| val imgHeight = drawable.intrinsicHeight.toFloat() | ||
|
|
||
| val scaleX = imageView.scaleX | ||
| val scaleY = imageView.scaleY | ||
|
|
||
| val scaledWidth = imgWidth * scaleX | ||
| val scaledHeight = imgHeight * scaleY | ||
|
|
||
| val viewCenterX = imageView.x + imageView.width / 2f | ||
| val viewCenterY = imageView.y + imageView.height / 2f | ||
|
|
||
| val left = viewCenterX - scaledWidth / 2f | ||
| val top = viewCenterY - scaledHeight / 2f | ||
| val right = viewCenterX + scaledWidth / 2f | ||
| val bottom = viewCenterY + scaledHeight / 2f | ||
|
|
||
| rect.left = left | ||
| rect.top = top | ||
| rect.right = right | ||
| rect.bottom = bottom | ||
|
|
||
| canvas.withRotation(imageView.rotation, viewCenterX, viewCenterY) { | ||
| drawRect(rect, boundingBoxPaint) | ||
|
|
||
| drawCornerHandle(this, left, top, ROTATION_0) | ||
| drawCornerHandle(this, right, top, ROTATION_90) | ||
| drawCornerHandle(this, right, bottom, ROTATION_180) | ||
| drawCornerHandle(this, left, bottom, ROTATION_270) | ||
| } | ||
| } | ||
|
|
||
| private fun drawCornerHandle(canvas: Canvas, cx: Float, cy: Float, rotationDegrees: Float) { | ||
| val handle = cornerHandleDrawable ?: return | ||
|
|
||
| canvas.withTranslation(cx, cy) { | ||
| withRotation(rotationDegrees) { | ||
| val halfSize = handleSizePx / 2 | ||
| handle.setBounds(-halfSize, -halfSize, halfSize, halfSize) | ||
| handle.draw(this) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val BOUNDING_BOX_STROKE_WIDTH = 3f | ||
| private val BOUNDING_BOX_COLOR = "#4FC3F7".toColorInt() | ||
| private const val HANDLE_SIZE_DP = 32 | ||
| private const val ROTATION_0 = 0f | ||
| private const val ROTATION_90 = 90f | ||
| private const val ROTATION_180 = 180f | ||
| private const val ROTATION_270 = 270f | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.