Codename One Drag and Drop - Target change background color on Drag Over - drag-and-drop

I have an Android application with some draggable elements.
There are some some labels that I want do drag over containers. The moment I drag over the container, I want the container background to change its colour.
I am unable to achieve this with DragOverListener from the API.
This is my code:
label.addDragOverListener(l -> {
container.getAllStyles().setBgColor(ColorUtil.YELLOW);
container.getAllStyles().setBgTransparency(255);
});
What happens is that as soon as I start dragging the label, the container changes the colour. But that's not what I want. I want the container to change the colour only when I drag over it.
Is there a way to achieve this?
Many thanks in advance.

The event delivers an X/Y location for the drag which you can use to determine whether to draw the color or not. Generally, this API is designed for refined drawing of this type e.g. drawing a square in the place the dropped component will occupy.

Related

Flutter how to know on which part from image was tapped

I have a car image and i want to make user enable to tap on apart of it then the tapped part name will be shown. How can i do it?
Like this image but i want to use car image not a map.
I think the way I'd do this, is use a Stack to overlay a GestureDetector on your image and see what the coordinates are. You could even use a CustomClipper with some custom shapes, or overlay multiple Positioned widgets with separate listeners on it, depending on your needs.
https://api.flutter.dev/flutter/widgets/GestureDetector-class.html
https://api.flutter.dev/flutter/rendering/CustomClipper-class.html

flutter make draggable widget also a drag target

By default in the picture above, the green box(drag target) is empty. When the red box(A) is dragged is stays in the green box and then this red box (now inside the green, also acts as a drag target). So that now the black box(B) can be dropped into it. How do I do this in flutter With Draggable and Drag target. Thanks in advance.
I think you need to use gesturedetector(tabdowndetails) to detect "x,y" while moving users finger across the screen. You can paint target rectangle(const dimensions) dynamically following users finger.
btw. where do you plan to drag the boxes(objects, picts)?

Custom Shaped Buttons Unity UI

Hi I am trying to create custom buttons on unity (trapeziums). I successfully created the visible area on Photoshop and imported it as Sprite 2D UI as per the following image:
The issue arises, when I'm trying to select one of the buttons in game, their border overlap each other, since the transparent area is still being considered as part of the clickable button area. How can I remove this?
EDIT:
Practically when I import I want the squared boxes to not be counted with the image. I need the edges of the orange area to be cut flush with that and not the entire area(i.e. including the transparent boxes).
You may achieve this by using Alpha Hit Test Minimum Threshold. Take a look at this nice video tutorial.
There is one extra step that is not shown in the video but mentioned in the comments: you have to change "Mesh Type" to "Full Rect" and not "Tight" as it is.
Hope that helps.
The clickable area is based on the Rect Transform component of the GameObject. Adjust the width and height to the clickable area you want. You may have to crop your image in photoshop accordingly. If you select 'Gizmos' in the editor you can toggle viewing the click region.

Unity3d new UI: How to set button's interactable zone bigger than the attached image?

I need it because the image is small and it's difficult to touch it on the mobile device. So I need to have bigger area of interactable zone but the image should stay small.
I believe the most proper way to make such button is like this:
Create a new Button, remove default child Text.
Set Width and Height of Button as you need for hitzone size.
Add Vertical Layout Group component to the Button.
Set Padding of the Vertical Layout Group to desirable difference between hitzone and visuals.
Remove default Image component. Set alpha of default Image component to zero.
Put your Image as child of Button.
Fix tint: drag (or otherwise set) the child Image to Target Graphic field of Button.
You need to set it up so that the image is inside a button object. Like this:
This way you can have the Button as big as you want and the Image can be any size. If you don't need the Button background image just make the color transparent in the image componenent of the Button object.
A surprisingly better way (in terms of ease and performance) is to add a text child element, even if you already have one. Leave the text empty and resize it however you like. It doesn't add any alpha.
Unity now have Raycast Padding property on Image component, edit these padding values will allow you to have more interactable zone for your button image. Note that you use negative value to extend the click zone.
Image raycast padding

How can I create a tile, overlay for a scene in Cocos2d?

I'm new to Cocos2d, but I can't seem to find the answer to this. I want to add an image that is mostly transparent as an overlay to my application. The image is overlayed on the app, and does not respond to screen taps. All gestures should "pass through" to the application.
The overlay image should actually be tiled. It's a small image that should repeat both horizontally and vertically.
How can I do this? In fact, this is an overlay that I would like to display for the duration of the entire application-- not just one specific scene. Is there a simple way to do this?
The point of my overlay is that I'd like to create a pseudo-scan line affect for a game which has an "8-bit" tone. The scan lines will be generated by applying the overlay to the game. The overlay is non-interactive and should always exist. So, this isn't a "tile based game", but I do need a tiling affect for this functionality.
You should be able to create a layer in each scene, set the zOrder to something large so that it overlays everything else, and set its isTouchEnabled attribute to NO. You can then add whatever you want to the layer, which could be your patterned image. To change the alpha, just set the opacity attribute of your image. The only issue that I can foresee is that the overlay might disable touch events for layers below it.