How can i implement auto scale feature in nifty-gui? - nifty-gui

As I can see in this vimeo video there's a nice feature to scale the whole interface but I cannot find any documentation anywhere telling me how can I do it ( nor in the 1.3.2 manual ).

You enable it on the Nifty instance using a "base resolution". This "base resolution" will be used as the inital size of your gui and when it is enabled the actual gui will be scaled automatically to the actual screen resolution:
nifty.enableAutoScaling(1024, 768);
Another way to use it, is to set a "base resolution" and provide the scale factors for width and height directly:
nifty.enableAutoScaling(1024, 768, 2.0, 2.0);
See the Nifty class for reference and there is an example available as well.

Related

WPF blurry vector icons

I'm not able to get crisp icons in a WPF project. I've tried several solutions but the results are terrible when the icons are downscaled. The starting files are .ai (Illustrator) that I've exported to xaml code using Expression Design
Here is an example
blurry icons example
First of all, you can try to play with properties SnapsToDevicePixels and UseLayoutRounding.
Next, please check what coordinates your vector images use. In order to get the sharp lines, you must either move your coordinate system to (0.5, 0.5) or use half-integer coordinates (e.g. 0.5, 2.5, 11.5).
Please, have a look at this MSDN topic.
There is also a perfect article on this topic. It's in Russian, but you can try to use Google Translate for it.

Nine-Patch Image in Windows Phone

In Windows Phone UI Design Principle, MS recommended use solid color rectangle or coding-gradient for Control Background to avoid incompatible in multi-screen. But in many requirements, using image as Control Background is necessary. Then, 9-patch image technique is used. In Android and IOs, it was support in core, but in WP it is lacking. I try to use it in WP by 3 approaches:
Using 9-cells Grid: clip image into 9 patch and lay them into cells. It works ok, but i afraid app performance reduce when has many control.
Using Custom Brush: only custom Brush to draw 9-patch image as ImageBrush, but seem MS not allow for custom Brush.
Using FramworkElement: like Rectangle, Ellipse... i want to create a FrameworkElement can draw a 9-patch image. But, can't use low-level render.
How can i implement 2nd and 3th approach?
I created a lib for Windows Phone which do exactly as Android NinePatchDrawable. You just need to set a bitmap image.9.png, the width and heigh... And done!!! you have you new image scale to the size you want. Enjoy it :). In the future I will add more option :).
GitHub link
You can compensate for the lack of low-level rendering and custom brush by using a WriteableBitmap: http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap(v=vs.95).aspx
This way, you have complete control on how to render your background, then you can assign it to a single Image control. But it's way more complicated than the "use a grid with 9 image controls" method, and the performance improvement is probably insignificant.

Recreating <BevelBitmapEffect> in a Pixel Shader/Other Method in WPF

Now that <BevelBitmapEffect> (amongst other effects) has been depreciated, I'm looking to see how I could re-create the exact same thing in a Shader Effect (including it's properties of BevelWidth, EdgeProfile, LightAngle, Relief and Smoothness).
I'm somewhat familar with pixel shading, mostly just colors manipulation of the whole image/element in Shazzam, but how to create a bevel elludes me. Is this a vertex shader and if so, how would I get started? I have searched high and low on this but can't seem to find an inkling of information that would allow me to get started in reproducing <BevelBitmapEffect> in a custom Effect.
Or, based on a comment below, is this 3D in WPF and if so, are there code libraries out there for recreating a <BevelBitmapEffect> that mimics the one that came with previous versions of WPF?
To create the bevel you need to know the distance from the edge for each pixel (search in all directions until alpha=0). From this you can calculate the normal then shade it (see silverlight example). As you mentioned there isn't much content about bevels but there are some good resources if you search for bump mapping/normal mapping to which the shading is similar. In particular this thread has a Silverlight example using a pre-calculated normal map.
To do everything in hardware ideally you would use a multipass shader, WPF's built-in effects are multipass but it doesn't allow you to write your own.
To workaround this limitation:
You could create multiple shaders and nest your element in multiple controls applying a different effect to each one.
Target WPF 4.0 and use Pixel Shader 3.0, for the increased instruction count. Although this may be a too high a hardware requirement and there is no software fallback for PS 3.0
Do some or all of the steps in software.
Without doing one of these you'd be lucky to do a 3 or 4 pixel bevel before you reach the instruction limit as the loops needed to find the distance increase the instruction count quickly.
New Sample
Download. Here is an example that uses PixelShader 3.0. It uses one shader to find the distance (aka height) to the edge, another (based on the nvidia phong shaders) is used to shade it. Bevel profiles are created by adjusting input height either with code or a custom profile can be used by supplying a special texture. There are some other features to add but it seems easily performant enough to animate the properties. Its lacking in comments but I can explain parts if needed.
There's a great article by Rod Stephens on DevX that shows how to use System.Drawing to create the WPF effects (the ones that used to exist, such as Bevel) and more. You've gotta register to view the article though, it's at http://www.devx.com/DevXNet/Article/45039. Downloadable source code too.

Windows Forms resolution problem

I have developed a 1024 *780 resolution screen in Windows Forms, but some say that it does not fit properly at higher resolutions. Is there any way to handle this?
Is there a way to make Windows Forms applications look the same at ALL resolutions?
My recommendation is not so much to "make it look the same" on all screens, but rather to design the GUI so it scales up and down more gracefully. Layout managers, docking, and anchors are your friends in Winforms. The TableLayoutPanel is quite useful for this sort of thing. Splitters also help...
Finally, this is one of those problems that WPF sets out to solve. WPF makes extensive use of layout managers. It feels much more like Java or GTK than Winforms or even VB (old school VB).
This is the sort of thing that makes you say "there's got to be a better way."
My solution for this one time was to declare a global ScalingFactor variable that was tied to the current screen resolution. Then, the sizes of every visual element were multiplied by that factor.
So, if I designed my form for resolution A, and resolution B is 1.2x larger, the width of window A will be with * 1.2, the fonts will be fontSize * 1.2, the textbox dimensions will be dimensions * 1.2.
Not fun.
There may be 3rd party tools that you can buy and will perform this scaling.
One other thing to check before you run down any of these roads is whether it is actually the screen resolution or the dpi settings that are causing it to look bad. Usually a higher resolution will only make it look smaller, but an atypical dpi, such as when the user selects "large fonts" will wreak havoc.
You can use anchor property of item, and autoScaleMode property of form set it equals 'None'.

App Engine image resize without maintaining aspect ratio?

When I call resize on images using app engine, they maintain their aspect ratio - I don't end up with the size I ask for.
I'm trying to make rectangular pixel NTSC images from square pixel sources, so I don't want this behaviour
I want to take an image that is 720x540 and resize it to 720x480 but what I actually end up when ask for the resize is an image that is 640x480.
Is there any way round this?
Alas, while PIL per se could do it, that's not what App Engine's very simple images functionality is using (you may be confused by the fact that the SDK is indeed using PIL to implement that functionality's API on your development machine) -- in particular, resize always does respect the aspect ratio. Your chance to get higher functionality depends on asking for it on app engine's issue tracker, and hoping that many developers have that need!
Are you giving the resize method both a width and a height?
http://code.google.com/appengine/docs/python/images/functions.html
Adam McGrath wrote a great rescale function that crops an image to a specific width and height in his answer here.
Why not use the crop function?
The correct arguments to transform a 720x540 to a 720x480 image would be (presuming you want a center crop):
crop(bytestream, 0, 0.055, 1, 0.945, output)
The crop function takes its arguments as a proportion of the image width or height, specified as a float value from 0.0 to 1.0.

Resources