ggez resize window without distording drawn elements - rust

I use ggez and would like to resize the window. The only way I found is
graphics::set_drawable_size(&mut ctx, width, height);
However, when I use it, the white circle I drawn turns into a white ellipse, and a seemingly grey circle appears below. So is there another way of resizing window, one that doesn't distort what is drawn ?

use
graphics::set_screen_coordinates(ctx,rect)
right after declaring changing size with graphics::set_mode(ctx,windowmode) turns the ellipse back into a circle. The gray shape vanishes after reducing the window (this is a pretty obscure thing).

Related

How to check if ellipse is outside background Image drawn with Fabric.js

I can always check by looking at the co-ordinates and comparing with Image, of ellipse shape, but it fails when ellipse is at the corner.
I have tried using intersectWith method, it only works with bounding box, not the actual border of the shape.
This is the scenario I need it to work to be able to check if ellipse is outside of the background Image, not. bounding box.

How to clip vega-lite text inside a rect?

In a webpage created with node/webpack, vega-lite, and vegaEmbed, I have a layer with rect marks with short annotations inside them using text marks. I'd like to clip the text to its surrounding rect but haven't figured out a way to do this and hope someone can point me in the right direction.
I realize text has a limit property in pixel units. If I could determine the pixel units of my rect marks (I don't know how to do this), using limit seems like a reasonable approach.
Also, if I knew the pixel extents of my rectangle, I can then write code to align the text within the rect which would be desirable. Currently I just use the same x as the rect, with a dx offset.
I've read about background for text which is a similar problem, but not the same.

draw rectangle under stackview

I find myself in the situation of having to manually draw a rectangle with rounded edges as a background for a horizontal stack view. To create the classic ios "bubble" effect, such as whatsapp chats, where the text is surrounded by a green shape.
I am attaching the code:
var BackgroundStack = new UIView();
BackgroundStack.Frame = new CGRect(0, -20, TopSchedaStack.Bounds.Width,
TopSchedaStack.Layer.Bounds.Height+40);
BackgroundStack.BackgroundColor = UIColor.TertiarySystemGroupedBackgroundColor;
BackgroundStack.Layer.CornerRadius = 20;
TopSchedaStack.InsertSubview(BackgroundStack, 0);
the perplexity lies in "BackgroundStack.Frame ...", I need to wrap the generated element in the "TopSchedaStack" storyboard of the UIHorizontalStackView type, with a gray rectangle. So I create it with the CGRect function but when I have to position it precisely under the object it is horizontally and vertically constrained to the view and centered. I am struggling, I cannot get the width I expect from the stack. In the storyboard file it is positioned one way but when I go to recover its width with:
TopSchedaStack.Bounds.Width or TopSchedaStack.Frame.Width
The value obtained is not what I expect. I expect the stack to be long from the left edge to the right edge of the view, taking away the guidelines. therefore it is an object constrained to the right and left respectively at point 0.
I would like the gray rectangle to cover the portion of the blue rectangle depicted in the image containing the storyaboard project. I'm pretty much going randomly changing values until it comes back, I'm sure I'll succeed sooner or later but I'm convinced it's not the right way to do this. Can you help me?

Background rect of d3's brush control not taking the whole area of svg

I'm trying to use d3's brush control. All works good except the rect.background of the brush is not expanding to fill the whole SVG, thus not allowing me to use the brush on the most right and bottom areas of SVG (which are not covered with background).
This jsFiddle illustrates the problem (scroll to the right and try using brush there) I've outlined the .background rect with the border.
What is the reason of this? And how to make the brush control to work all over the SVG?

webgl: white border when using transparency (alpha)

When rendering textures that have an alpha-channel, a white border appears around the non-transparent part (the border seems to be the pixels that have an alpha > 0 and < 1):
The original texture is created in illustrator and exported as a png. here it is:
(well, seems stackoverflow altered the image, adjusting pixels that are not completely opaque/transparent, so here is a link)
it is probably the blending, though i dont know what is wrong with the setup:
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
[Update]
Here is a rendered version, where i added a alpha-gradient to the left part of the texture (so it is getting from 0 opacity to 1 until the half)
this texture is the only texture rendered at this position. it seems to be whitest around a=0.5. really weird. the background is just a cleared color:
gl.clearColor(0.603, 0.76, 0.804, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
// render objects here
the depth-function looks like:
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
any ideas? thanks a lot.
[Update 2]
Answering my own question: the effect occurs when the background-color of the canvas or the body of the html-page is white. I don't have an explanation, though.
Use premultiplied alpha and this problem will go away.
See: http://home.comcast.net/~tom_forsyth/blog.wiki.html#%5B%5BPremultiplied%20alpha%5D%5D
This is problem related to texturing linear interpolation. On borders, some interpolated pixels will take half white half green, and 0.5 alpha. You should modify your texture to extend your borders with one more green pixel, even if it is totally transparent.
What's your draw order? This looks like a depth buffering issue to me — you start with a white background, draw the thing with the border so that it's composited on the white, then draw the thing behind the thing with the border. Those areas where the border was blended with the original white background will have stored a value in the depth buffer equal to the depth of their plane, so when the object behind is subsequently drawn, its pixels are discarded in that area.
The general rule is to draw transparent objects after opaque objects, usually from back to front. If you're using additive blending then it's often good enough to disable the depth buffer after the opaque draw and draw them in any order.
When setting the FragColor in the shader, try multiplying the image RGB with the image alpha.

Resources