Flex Drag and Drop - apache-flex

I have an image that I show inside a canvas which I can zoom in on.
The problem is that when zoomed in, I try to drag the image, I can see the outline of the image in the foreground, (i.e.) outside the canvas boundary.
Is there anyway to tell the dragHandler to crop the "grabbed" image outside the canvas boundary?

In my experience using the built in drag/drop flex stuff is overkill for something that involves moving a component around in a canvas.
The easier way to do this (in my opinion) would be to listen for mouse down/up/move the image around in the canvas yourself.
When you detect a mouse down on your image, add a listener for mouse move (pro tip: make sure you set useCapture to true when calling addEventListener) and store the position of the mouse relative the origin of your image. Then whenever you get a mouse move, change the position of your image within your canvas taking into account the position of the mouse within the image (which you stored on mouse down). Keep doing this until mouse up occurs, then remove your mouse move listener.
There are some additional finer points to account for (what if the user drags outside of the canvas? Or outside of the browser window?), but this will get you started.
Hope that helps.

Related

How to increase the clickable area of a QPushButton in Qt?

The Back button in the top left corner of my touch user interface is a little hard to press on a resistive touchscreen, because the touch events are not so precise at the borders of the screen.
The visual size of the button can't really be increased because the screen space is needed for other things. Thus I would like to increase only the clickable area of the button. So when the user touches somewhere in the top left corner of the screen (as marked in red), the back button should be pressed. Note that the red area also overlaps another button. Ideally, the visual button state would also change to the "pressed" state.
Can anyone give me some pointers in the right direction? I have considered the following things, but I'm unsure which would work.
Overlaying the actual button with a larger, invisible button, painted with a transparent brush. But I have no idea how I could paint the smaller button as "pressed" when the user is pressing the invisible button.
Creating a new class based on QWidget, which has the size of the red area (with invisible background) and contains the actual button. Then relay touch events to the button so that it is pressed when the user touches the empty area.
Subclassing QPushButton and reimplementing QAbstractButton::hitButton to accept points outside of the button's area. But I guess that function would probably isn't even called when I touch outside the widget area.
To occupy more vertical space inside a layout, set buttons vertical policy to expanding.
To increase the clickable area without increasing the visual size, increase the margin.
To have the back button overlapping other buttons, don't put it to a layout. Instead set its parent directly and move it to the corner.
backButton = new QPushButton("< Back", mainWindow);
backButton->setStyleSheet("margin: 30;");
backButton->show();
backButton->resize(150, 90);
backButton->move(-30, -30);

Canvas Scrolling

I have a Canvas with a VGroup inside that is populated with objects of various types, some of which have mouseEvents such as MOUSE_OVER.
The problem I am having is getting the Canvas to scroll properly with the mouse wheel. It will only work if the mouse is over the scrollbars.
I tried faking it by listening for the mouse wheel on the stage, then manually scrolling the Canvas. But when the the Canvas scrolls to where an object moves under the mouse, things get screwey.
Any suggestions?
take care,
lee
UPdate:
Ok. I found that if I use the canvas without my addition, it scrolls only when the mouse is over an object inside it. If the mouse is in an empty area, it does not scroll.
When I say 'the mouse is over an object inside it', I mean text fields and other objects that have visual elements.
Ok. I've found a partial solution. If I intercept the mouseWHeel event on the VGroup, the scrolling works. However, when I get to a RichEditableText object in the VGroup, the scrolling stops. Before, it scrolled just fine.
Found an interesting solution here. The mouseWheel event is not triggered in a canvas unless it is over an InteractiveObject, i.e. text fields etc. However, as I was testing to make sure my mouse was actually in the canvas I discovered that the event is triggered in the 'white' space between objects if the canvas has it's backgroundColor property set. So, set that backgroundColor and, if you didn't want a background, then set backgroundAlpha to 0.

drag and drop in Canvas

I'm doing an application in flex where I draw different sprites inside a canvas. Depending of the dimensions, scrollbars can be appear. I would like to move the "image" with the movement of the mouse as you can see at the Adobe Reader when you are reading a document with zoom (hand mouse icon). In this way, you dont have to touch the scrollbar.
I'm start trying with drag and drop properties of the canvas, setting the position of the scrollbar according with the movement of the mouse but that is not as I expect.
Any ideas or suggestions?
Thanks in advance.
Recipe:
Listen for the mouseMove (MouseEvent.MOUSE_MOVE) event on the canvas
In event listener, examine event.localX, event.localY
Based on those values and the canvas's width and height, set the canvas's horizontalScrollPosition and verticalScrollPosition accordingly
Hope this helps.
What you can do is, change the position of the scrollbar , when the mouse reaches the last 20 pixels on the left or the right, or the top and bottom.
What you would really need to do is, have a mouseMove listener on the whole application, and when the mouse is within the end ranges of any of the sides, you can use the scroll.scrollTo function to move the scrollbars.

How to place an image by dragging and placing it in the drag proxy image position

I found examples in adobe site only to position the object where the mouse pointer is. But i have to place the image in the position of drag proxy image.
Have you considered creating a canvas that positions the image where you need and use the canvas as a drag proxy?

how can move the child only inside the parent?

Recently I worked in a project using Flex. Its a Photo editing project. I have took a Canvas and take a image in that canvas using the code canvas.addChild(image) . Now i can move the image freely by using moving code. The image move inside the canvas and outside the canvas. I want to move the image/child only inside the canvas not outside. How can i do this?
There are two ways to do this:
Bounding Rectangle
Scroll Rectangle (or Mask)
Assuming your "moving code" is something like an Event.ENTER_FRAME handler initialized onClick, you want to make it so the image can't leave the bounds of the parent Canvas.
The first case (bounding rectangle) will allow you to drag the image within the retangle but you will always be able to see the whole image. This is how Image croppers work.
To create a bounding rectangle, you'll have to write a fairly detailed method, but the idea behind it is simple. Just get the bounding rectangle from the canvas, and don't let the image.x go below 0 and don't let image.x + image.width go beyond canvas.width. Same with height. Here's a sample Image Cropper in Flex (and the source). Check out how they did it for details.
The second case (scroll rectangle) would allow you to create more of a pan/zoom like container like you see on this Flex Pan/Zoom Map (here's the source). Also, the large image in the Flex Image Cropper on the right is an example of this second case, but they don't have the dragging. That requires that you manipulate the position of the scrollRect property on the canvas. The scrollRect property is a flash.geom.Rectangle defining the Canvas' "viewport". You then change/update the verticalScrollPosition and horizontalScrollPosition properties, so it's backwards (compared to the Bounding Rectangle).
I think if you set clipAndEnableScrolling to true on the canvas, and you drag a child image around inside of it (and image.includeInLayout = true), it should clip the image to only show up inside the canvas. But I'm guessing you want case 1. Just search those properties and you'll find some good examples on google.
Good luck, should be a fun project.
Lance

Resources