UI objects on same position for every resolution - c#

There is a problem i created a button and text which is display correct on android resolution but when i change the resolution to free aspect it change the position of button and text like this
I tick the button component Image (Script) preserve aspect and changing the anchors of both object like this
but nothing happen i want to display these two on same position where it is when changing any resolution.

First of all, do not use Free Aspect to test different resolutions. Free aspect isn't really a resolution and often you can see bugs that you will not ever see on real devices.
For your problem anyway you have what's called Anchors in each UI element. An anchor defines where you want to "attach" your UI element and especially to what element or corner of the screen you want to attach it. For your example, on the Rect Transform, click on the square drawing (representing the anchors) and choose Bottom Left.
Your element will be moved, you can move it where you want to and it will always be attached to the bottom left corner of your screen:
If you want to know more about UI for multiple resolutions, you can go here: http://docs.unity3d.com/Manual/HOWTO-UIMultiResolution.html
Good luck!

Related

WPF Dynamic Cursor

I am creating a vector graphic editor in WPF. I am rendering the artwork using a D3DImage that has been customised using SharpDX so that I use it with Direct2D. When an item is selected, resize handles appear around the selected item. I want the cursor to change when the user hovers over these resize handles, but they are rendered in Direct2D and are not WPF elements. How do I accomplish this?
Well, if you’re doing your own rendering to D3DImage, you gotta do your own hit testing.
If your geometry’s relatively simple (boxes, circles, polylines, not too many of them), you can hit test these handles shapes in mouse move event handler. Either manually, or by using e.g. FillContainsPoint D2D APIs.
Or, if you aren’t doing something very color-sensitive like a desktop publishing, you can encode resize handles in the color of your shapes. Use a couple of least significant bits of the blue channel (human eyes are least sensitive to blue), read the color under the mouse, change cursor accordingly to the blue color value.
Or, you can switch to DXGI_FORMAT_R16G16B16A16_UNORM for your render target (looks like D2D supports that format), this way you can add much more per-pixel data to your image without any visible artifacts (use lower bytes of each of the 3 color channels). This however complicates rendering, you’ll need to do one more pass to convert the texture into A8R8G8B8 for the WPF.
P.S. I wonder why don’t you use WPF elements instead? 2D vector graphics there is rather advanced. You can easily create/manipulate/fill/outline these shapes programmatically (just place then on a canvas), this way WPF will handle all these hit tests, and rendering, and more.

Set the cursor to go to the other border of the screen if it goes into one in WPF

I'm currently developing a 3D viewer application in WPF, and for ergonomy reasons I want my mouse to go to the other border of the screen if it goes into one.
For example, if my mouse goes into the top screen border, set I set my mouse position to the bottom of my screen.
Same for left/right.
How can I actually detect my mouse position in WPF? The only position I can get is related to the software and not the entire screen.
Also, it would be great if it could support dual monitors. (So the mouse is re-set only if it goes into the second monitor)
based on the informative answers to the s.o. question here:
How do I get the current mouse screen coordinates in WPF?
I think the simpler way to go is the windows.forms method, unless your 3d graphics are updating a lot of computation and you don't want the extra .net unboxed loop performance margin hit. According to this msdn reference:
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx
the Cursor.Position property is settable, so should be settable from WPF app, although you want to do some research and testing before committing to a lot of code on that

Unable to pan a canvas - Silverlight

I have seen lot of posts which demonstrate how to move objects in a Canvas but what I need is, a way to move either
1. the entire canvas along with its every child
or
2. move every object manually (which is certainly not advisable)
I have put my Canvas in a ScrollViewer.
My actual issue is : I m trying to zoom the canvas using ScaleTransform but after zooming, i also need to move the scroll viewer to a point such that the clicked point is at the center after zooming.
I tried Canvas.SetLeft() and Canvas.SetTop() but bad luck..
Any idea?
Thanks in Advance..
You can communicate with the ScrollViewer to make it scroll its content to a particular offset by using ScrollToVerticalOffset and ScrollToHorizontalOffset.
You'll need to calculate the correct offset by taking into account the size of the "viewport" i.e. the area that you can see of the content, and the zoom level.
http://go4answers.webhost4life.com/Example/center-zoom-wpf-problem-159135.aspx
This might be useful for what you are doing:
http://autoscroller.codeplex.com/

auto-scaling size with anchors - overlapping controls

I'm having some trouble with resizing and scaling of controls in a windows form. I've set anchors up so that the controls stay in ratio with the form, which works great. However, perhaps i was expecting too much when i thought that the control origin points would also scale and change with the form scaling, but this is not the case and i'm finding my controls overlapping. here's some screenshots;
anyone know of an approach i can take to solve this problem? perhaps i need to set control origins to dynamic drawing points that scale, but then do these redraw on scaling the form, or only on creation?
edit 1: just found this question hidden amongst the internet, Problem: Anchored controls are overlapping perhaps i need to implement something like this, a resize event.
The preferred solution should be the TableLayoutPanel. Handling OnResize is going to be much more fragile.
I wonder if Anchor is really about scaling, it basically anchors the sides of a control to the container and scaling is a by product of this. For eg. if both left & right sides are anchored the control will scale in width because anchor will try to keep the location of left & right sides intact.
keeping that in mind you have to think what do you want when the form is increased in size and you have more space. In the case above you might want the list box lbLog to say remain same size but the panel Simulate take up any sapce created. For such a scenario you would anchor the panel on both left & Right side while you will anchor the list box only the right.
Basically if you want all your controls to proportionally scale (true scaling I would say as opposed to scaling in case of anchoring) then Anchoring is not the right solution.

How can I develop scale like measure it add on in Firefox

I want measuring tool in project that will be same as measure it in Firefox (add-on). How to do this?
To get such a think to work you'll need an application that runs as a tray icon or something like that. Then you open your application and tell him, that you'd like to measure.
Now, you'll go and put a transparent window onto the whole screen(s) and wait for a mouse move event. Within the mouse move event, you'll check the mouse button state. If it is going to be hit you know the starting position and you can draw some kind of user-control at this position and if the user releases the mouse button, you're going to stop the resizing of your user-control.
The user-control itself should be semi-transparent and checking for the resizing and/or paint events, to draw the ruler lines around the border.
Last but not least you can show some kind of tooltip or labelcontrol in relation to the position and size of your user-control and screen bounds to give some status informations.
To get a good starting point about how to get the transparent overlay part done, you can take a look into ObjectListView Overlay.
--EDIT--
One solution could be:
Create a separate transparent windows form
Upon certain key press, for instance Ctrl+Shift+R, show your app with lower transparency level; so that user can see the background.
Draw ruler upon form load
You may allow user to move the ruler window with mouse click.

Categories