Draw rectangle on image in Avalonia - avaloniaui

Problem : I have an image with zoom and pan attached. I need to draw rectangles over it.
What I have done : I created a Canvas as an overlay over the image and made rectangle the children of canvas. Everything works well with zoom and pan etc but if the user resizes my the window then the added rectangles starts moving from their places because the rectangle position is set with respect to top and left of canvas.
I am thinking of drawing rectangles over the image and overriding the render. Any suggestions how can I achieve it easily?

Related

Multiple Stages on Same screen with different viewport LIBGDX

I am trying to scale my application to work similar on various aspect ratios.
I read about viewport and camera. And came to a conclusion that I should use FitViewport for my game stage so that no asset is being stretched. And I will use some background image to fill the black bars caused by fitviewport. But the problem is, whenever I use any other viewport than FitViewport for background image, the whole stage (both background and main stage) are being stretched, is there a way we can get away from black/white bar of FitViewport? I tried all the viewports for background namely StretchViewport, ScreenViewport, FillViewport.
Am I missing something very trivial? or is setting up multiple different viewport on same screen possible.
ps I was able to setup two same viewports with different size on same screen.
Here is the screen, I am getting after fitviewport. Notice the white bars on top and bottom which I am trying to eliminate.
this answer worked for me. Just for reference
You would need a second viewport, probably ExtendViewport with the
same virtual dimensions as your FitViewport.
//create:
fitViewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
extendViewport = new ExtendViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
//resize:
fitViewport.update(width, height);
extendViewport.update(width, height);
//render:
fitViewport.apply();
batch.setProjectionMatrix(fitViewport.getCamera().combined);
batch.begin();
//draw game
batch.end();
extendViewport.apply();
batch.setProjectionMatrix(extendViewport.getCamera().combined);
batch.begin();
//draw stuff in border
batch.end();
If you want to be sure the border stuff doesn't overlap your game, you
could swap the draw order above.
Or you could just use ExtendViewport to begin with for everything.

OS X chat app with resizable bubbles

I'm building chat application for Mac OS, similar to iMessage. I wonder, how can I implement resizable text views in bubbles. I mean, when I resize chat window bubbles with text will resize to. Any ideas, links will be very useful. Thank you for help)
For text resizing, you use auto layout. If you have an NSScrollView containing MYBubbleViews containing NSTextViews, you can add NSLayoutConstraints using the leftAnchor and rightAnchor properties of the scroll view's content view and those of the bubble view, and add constraints between all edges of the text view and bubble view. Then pin the bubble views to the top/prev view.
Also make sure you set the NSTextView to wrap. The width of the intrinsic size of the text view will be set so that it fills the width and the intrinsic height will be set to fit the whole text.
I previously thought it was about drawing the bubbles, so I first gave this answer:
If you look at Messages.app, you'll see that they're not circular bubbles. They are basically composed of several shapes overlaid on each other. A rectangle with rounded corners, plus a bezier path of the tip.
So you should be able to take a NSTextView for the text, make it a subview of a custom view that draws a rounded rectangle and the tip in its drawRect method, and then use auto layout constraints to make your bubble view resize with the text view and the text view to the window width.
You could probably also have the bubble view host a CALayer with fill and rounded corners, plus one with an image for the tip (or aCAShapeLayer for the tip), but drawRect is the easier approach.

Objective C: Creating rotated Image inside square?

For an arduino drawing robot i want to rotate an image by 45 degrees in an iOS app, so that the new (rotated image) is inside a white box. Imagine the blue rectangle in the picture was the original image, and the image. As you can see it is rotated an inside a white square. How could I do this? It is important not only to have a rotated image, or a rotated image which has a white box behind it on the screen. It actually has to be a new image, so that if i get the color of pixel (1,1) it is white.
You can try to do this with having a white UIView superview, and blue UIView subview. And then do:
subview.transform = CGAffineTransformMakeRotation(M_PI/4);
superview.bound = subview.frame;
I think it should work.

Keep text on an image readable while rotating the image

I have an image view that looks like a wheel. This view detects touch events on each of the colored sections.
The problem I have is that when I rotate this wheel, the UILabels on top of the view need to also be rotated so that the text is still horizontal and human readable.
What is the best way to rotate the labels while the parent view is being rotated?
This is what I am trying now and it does not rotate correctly...
CGAffineTransform textTransform = CGAffineTransformRotate(newTransform, newAngle * -1);
Presumably you are applying a rotation transform to rotate the wheel. If the labels are subviews of the wheel view, their centers are pinned in the right places to the wheel (because a view is located in its superview by its center), and they will travel around with it. At the same time, apply the inverse rotation transform to the labels. The rotation takes place around the center of each label. So each label stays in the right place and stays upright.
An afterthought - also make sure you're not using autolayout on these labels. Autolayout breaks view transforms.

Cropped rectangle doesn't work as expected

I have an NSView to draw a rectangle to crop image, and one NSImageView to be webcam (camera preview window).
I want to put the NSView on the NSImageView.
When I take a picture, it can produce a cropped image automatically.
The problem is that when I don't start the camera preview window, the crop rectangle can drag and resize normally, but when I start the camera preview window, the crop rectangle out of control.
I've implemented drag and resize function by mouse event.
How can I resolve this problem?
8/19 update: My code and program video.
code: gist.github.com/536831
video: http://www.youtube.com/watch?v=DLjuBGHh3f8
Thanks!!
Hmm, maybe one of the views has User Interaction Enabled set to NO (default value for UIImageView, for example)?