GithubHelp home page GithubHelp logo

pskink / matrix_gesture_detector Goto Github PK

View Code? Open in Web Editor NEW
134.0 134.0 98.0 159 KB

A gesture detector mapping translation/rotation/scale gestures to a Matrix4 object.

License: Other

Java 1.01% Objective-C 2.09% Dart 95.41% Shell 1.49%

matrix_gesture_detector's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

matrix_gesture_detector's Issues

One component at a time inside stack

I want to move/scale/translate only the component which have been currently touched & rest other should stay at the same place. How can i achieve this?

Please find attached video representing the bug

video.zip

Callback that fires when gesture ends?

Love the library! Clear, concise, efficient, flexible, and great comments!

I have implemented a pinch-to-crop feature and I'm saving the final translation and scale to local storage so images can be displayed later according to a user-specified crop. Right now I'm writing out these values every time onMatrixUpdate() executes, but this understandably causes some lag.

I really only need to write the values when each gesture ends. Is there a convenient way to do this or will I need to expose it by customizing matrix_gesture_detector?

Thanks!
Mike

Does rotation work for Linux (Ubuntu)?

Thanks for your dedication!
On Android, I can use 2 fingers to rotate and pan normally but I cannot do rotate in the desktop app (Ubuntu 20). I tried both right clicks, holding "shift", and "ctrl" but still does not work.

[Question] Using external widget like icon button to control matrix rotation and scaling.

This is working great, wanted to know if it's possible to use some external button that will be dragged and will scale and rotate the matrix.

Use case:

The widget that is scaled and rotated with a matrix gesture detector will have a small icon button widget at the corner. That corner button will be used with a single touch to scale the main widget inwards and outwards and rotate it.

Set max and min scale

How to set max and min scale of the widget?
I want to set max_scale = 3 and min_scale = 1 the same as when the widget is initialized.

Get xy , width and rotation angle

I am using this widget in video editing app. I have implemented it successfully but not getting how to get left,top, width and roatation angle to save video with watermark. This is my code:

MatrixGestureDetector(
onMatrixUpdate: (m, tm, sm, rm) {
controller.matrix = MatrixGestureDetector.compose(m, tm, sm, rm);
notifier.value++;
},
child: AspectRatio(
aspectRatio: controller.aspectRatio.value != 0.0 ? controller.aspectRatio.value : controller.controller.video.value.aspectRatio,
child: AnimatedBuilder(
animation: notifier,
builder: (ctx, child) {
return Transform(
transform: controller.matrix,
child: MeasureSize(
onChange: (Size size) { controller.size = size; },
child: FittedBox(
fit: BoxFit.contain,
child: controller.icon == null ? CustomPaint(
painter: DottedBorderPainter(),
child: Obx(() => Container(
color: Color(controller.bgColor.value != 0 ? controller.bgColor.value : Colors.transparent.value),
margin: const EdgeInsets.all(4),
padding: const EdgeInsets.all(4),
child: Center(
child: Text(key: controller.textKey, controller.text,
style: TextStyle(fontSize: 33.5,
color: Color(controller.textColor.value != 0 ? controller.textColor.value : Colors.black.value))),
),
)),
)
: Container(key: controller.key, child: Image.network(controller.icon!))
),
),
);
},
),
),
)

and I have used :
var x = MatrixUtils.transformRect(matrix, key.currentContext!.findRenderObject()!.paintBounds).left;
var y = MatrixUtils.transformRect(matrix, key.currentContext!.findRenderObject()!.paintBounds).top;

   var width = MatrixUtils.transformRect(matrix, key.currentContext!.findRenderObject()!.paintBounds).width;

to get corrdinates and width and not sure about rotation but these are not working

Different screen size issue

I placed a box at the top right corner of the screen, saved the matrix and used to it place that box at the saved position. It works fine when viewed on the same screen size at which it was created, but when viewed on different screen sizes which were relatively smaller or larger than the original one, the box does not appear to be at the top right corner of the screen.
How can solve this issue with different screen sizes ?

coordinates by reverse use of matrix to get original value

After scaling and translating, i tap on the screen. I use the values from MatrixDecompose (translation , scale) to go back to the 'real world without translation and scale' coordinates. They value are always off in Y by the same amount. I am fairly sure it is caused by the AppBar distance. When I remove the AppBar values work.
My problem is I I am not completely sure what is happening, so I might get it wrong on different devices. Also, I would prefer to be able to use the Appbar. I can not find a solution of finding AppBar height. Any Suggestions? What have others done with this problem?

null safety

Will this package be upgraded to null safety at any point in the future?

Resetting the matrix

Is there a way to reset the matrix to Matrix4.identity()?

I'm currently trying to do this by setting the Matrix4 variable matrix, which is assigned to a Transform widget, to setState(() => matrix = Matrix4.identity()); on the press of a button.

This seems to work but once I try to move the transform widget is jumps and starts it's transformation from the pre-reset state.

How to scale only in 1 direction ?

I want to scale only in x direction but currently the scale gesture scales in both x and y like zooming. But i want stretch operation. How to solve this issue ?

Use with multiple children, just one at a time!

It may be some simple code to fix this, but as for now please read my answer to this topic:

https://stackoverflow.com/questions/60803481/move-zoom-and-resize-positioned-widget-inside-stack-widget-in-flutter/63042850#63042850

I made some changes so that many widgets could have its own matrix transformer..
But if you pinch or do any gesture which touches another children, both of them get transformed.. It should be just the one which is nearest to the pinch movement.

Do you know how can this be achieved?

Btf, awesome lib! Thanks for it!

How to reset the matrix

Using info from Resetting the Matrix#8, I got the matrix to reset correcting when using CustomPaint (basically the same code as the example with CustomPaint). But I have no idea why it is working. I seem to have replaced notifier.value = m, with notifier.value = matrix; when normal zoom, offset and rotation.

It seems to work, but I do not understand. Is it possible my code will give memory leaks or anything? Is it the best way for CustomPaint?

My Code:
class _CustomPainterDemoState extends State {
Matrix4 matrix = Matrix4.identity();
ValueNotifier notifier;
bool resetMatrix = false;

@OverRide
void initState() {
super.initState();
notifier = ValueNotifier(matrix);
.....
in the build
body: MatrixGestureDetector(
onMatrixUpdate: (m, tm, sm, rm) {
if(resetMatrix) {
matrix = MatrixGestureDetector.compose(matrix, tm, sm, rm);
//above appears to reset all matrices
}
notifier.value = matrix; //original code had notifier.value = m
},

I then have child: CustomPaint, exactly like the example
At the bottom, I have a floating Action Button to reset the screen
floatingActionButton: FloatingActionButton(
onPressed:(){
setState(() {
matrix = Matrix4.identity();
notifier = ValueNotifier(matrix);
resetMatrix = true;
});
}
),

How do I know if the user uses 1 finger or 2 fingers?

HI, thank you for the awesome package.
What I want to achieve is that I only want to Pan and Zoom whenever the user uses two fingers to do it. Because I have other needs for the single finger. So how can I detect whether it is a single finger touch or two fingers touch?

Thanks

Preventing zoom out

Hey, is there a way to prevent scaling the widget smaller than it's initial size?

The matrix does not maintain its position on the screen after setState.

I am using the sample code TransformDemo2, with an example floating button, that executes a setState. I move and scale the object with my fingers to a certain position on the screen. But when I run setState, the position of the matrix is not maintained. Are there any suspicions of what may be happening?

Initial matrix

It is pretty common to be able to edit an already transformed image.

For this use case, it would be needed to initialize the widget with an initial transform.

MatrixGestureDetector(
    initialMatrix: myMatrix
    onMatrixUpdate: ...
    child: ...
  )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.