Center image in group JavaFX - javafx-8

I'm trying to make some figures in JavaFX. I can create these figures with the Polygon class or in this case with the Circle class. But I want to add an image on top of it. So I'm using a group for this with 2 elements, the figure and the image in an ImageView. But if I use this group, the image isn't in the middle. I would like to center the image. I also would like to be able to drag and drop it with a mouse, so then it needs to stay in the middle. I've tried it with a circle and a polygon but in both cases the image was in the bottom right corner.
Edit: I just figured out that you can move your image with setX and setY, but this isn't an easy way to center the image.
Here's what I have at the moment:
public class Figure extends Group {
public Figure() {
Circle circle = new Circle(100);
ImageView imageView = new ImageView();
circle.setFill(Color.BLUE);
circle.setStroke(Color.BLACK);
Image image = new Image("images/blue/bike.png");
imageView.setImage(image);
imageView.setFitWidth(100);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
super.getChildren().addAll(circle, imageView);
}

The easiest solution would be to use a StackPane instead of a Group. That might give problems with clickability if you let them overlap: one of two Circles is then obscured by the other figure's StackPane.
Though a bit inelegant, I would do it with setX and setY as you propose.

Related

How would you create a ring of cells in flutter?

I would like to create a widget (I know it must be a CustomPainter) to draw something like this:
Notice that there are n concentric cell circles.
The main problem is that I need to access/paint each of this cells when needed to repaint it in different colors. I have been checking the CustomPainter canvas class and the only thing that could fit my needs is the draw arc thing. But, I can't provide a width for the arc (I tought I could draw a draw for every cell).
My last resort is using an image/sprite that would represent a cell. This way I could duplicate and transform it along a circle path to obtain something like the image. But I don't like the idea.
Has anybody accomplished this before in flutter?

Unity Scaling rect transform left right and scale x

I am having a problem in resizing a UI panel in unity on button click. I enter a negative value on the left but after I run it it doesn't read the "-" value and I also want to scale the size of the panel to 1.24 here is a picture of its default state, after I execute the code and what I want it to be like.
I'm sorry cause its hard for me to explain it in words so I just compile it in one picture.
PS. I've searched for codes that can resize the scale of the Rect but the Rect just disappear.
//Scaling left and right of the panel
DescriptionPanel.GetComponent<RectTransform>().offsetMax = new Vector2(-91.375f, -1);
DescriptionPanel.GetComponent<RectTransform>().offsetMin = new Vector2(76.295f, 0);
//Scaling x-axis of the panel when I include it in runtime my panel disappear so I did not include it in the picture below.
DescriptionPanel.GetComponent<RectTransform>().transform.localScale = new Vector2(1.24f, 1f);
UPDATE - Ive already fixed the Left and Right RectTransform problem.
The remaining problem is resizing the scale of the rectTransform.
When I execute this code my Panel disappears. I need to set the X axis to 1.24.
DescriptionPanel.GetComponent<RectTransform>().transform.localScale = new Vector2(1.24f, 1f);
You might have to use Vector3 when transforming a localscale, because Your DescriptionPanel might be moved over behind the canvas

KineticJS: drag a group from toolbar to stage

I already implemented a solution using KineticJS of drag and drop of items: from a toolbar (or an accordion, it doesn't matter) to a white area, a stage or canvas, the items are images and rectangles. The rectangles represent a room and the images are the equipments.
In all the examples I found after googling (until now) are basically about drawing a Kinetic.Group inside of a layer, adding shapes to that group and make it draggable in the stage.
The problem here is that I don't know how to make a rectangle to be a group, so that when I drag it over the canvas, the images will be dragged as well; ie when I drag a room that contains items, the whole group is dragged and dropped. I want to implement something like this: http://jsfiddle.net/tbYLe/2/ which performs as described above.
EDIT : this is what I have done until now http://jsfiddle.net/wQ8YA/15/
First of all, you should provide code you tried, that would help others help you.
The thing you are trying to do is create a group, which is between a layer and a shape, so you add shapes to the group and then you can drag the entire group.
The attributes a group can have are listed here: http://kineticjs.com/docs/Kinetic.Group.html
And here is an example of a group: http://www.html5canvastutorials.com/kineticjs/html5-canvas-drag-and-drop-a-group-with-kineticjs/
notice that there is no color or shape, but it can be thought of as a rectangle, much like a layer is a rectangle, and the canvas is a rectangle. A group is just a container, not a shape
So if you want a "room," I advise this approach.
function createGroup(width,height){
//create a group - define a size for it
var group = new Kinetic.Group({
draggable: true //make group draggable
});
//create a rectangle
//add rectangle to group - fill up entire group - this will be the visual representation for your group - this rectangle should not be draggable
//return group
}
// use of
var myRoom = createGroup(100, 200);
myRoom.add(new Kinetic.Circle({config})); // this new circle can be draggable

Getting the outer CGRect

I have two UIViews, both of which obviously have CGRects each. One UIView fills the screen whereas the other just fills part of it in the middle. I have the CGRect of the smaller UIView, but how can I get the CGRect of the one outside of it - excluding the size of the smaller one so that the background can be dimmed, but not the content of the inner UIView?
This is what my UIViewController looks like so you can get a better idea of what I'm trying to do:
I want to dim the outer UIView, not the inner one - but I don't have the CGRect of the outer one excluding the inner UIView so I've had to do it the other way around for now.
A CGRect is a square size. If you want to know the outer aria you need to compute 4 CGRects. The top, left, right and bottom space.
So, it looks to me like the outer view is responsible for drawing your content and the inner view is your selection rectangle right?
If so, then I think you are going to want to draw your content twice when you have this selection mode active. You will:
draw one pass dimmed - adjust the colors yourself (you can either draw the whole area or clip away the inner area using code from here)
draw the second inner pass with a clip rect setup so only your content inside the rect for your selection rectangle is drawn
Or
draw all your content like normal
set your clipping mask (using code from here so that just the outer area is rendered) and then draw a black rect with some degree of transparency over your whole scene

Find out which segment the image resides in objective c

I have created a rotating wheel of 5 images. What I would like to find out is which image ends up in the top right corner.
Is there any way I can realize which one is in the top right corner through coding?
Thanks :)
If your images are going to end up in specific spots, meaning you know exactly what will be the position of an image when it is in the 'top right corner', you can check the origin (of directly the frame) of that image view.
BOOL bingo = CGRectEqualToRect(imageViewRect, topRightCornerRect);
or
BOOL bingo = CGPointEqualToPoint(imageViewOrigin, topRightCornerRectOrigin);