konvajs - set background color for a layer - layer

How can I set the background color of a layer using Konva library?
I tried:
dashLayerA1.setAttr("fill", 'black');
but it does not seem to do the trick.
Only by-pass I found was to create a shape rect and assign a color to it, but not convenient for what I want to do.
Thanks.

You can't set the layer's background directly.
Creating a rectangle for the background is a valid solution, that I used by myself.
If you don't need to export that background, you can just style stage container with CSS:
stage.getContainer().style.backgroundColor = 'red';
For more info take a look here: https://konvajs.org/docs/sandbox/Canvas_Background.html

Related

Is there a way to set and update the background image in blender 2.8 2d animation workspace?

As the title suggests, Is there a way to set and update the background image in blender 2.8 2d animation workspace? I mean it's easy enough to add a background by dragging the image onto the viewport but then I can't seem to interact with it at all or change it to a different image.
Just to point out it's fairly easy to change background in a 3d project. What I'm asking for is updating the background image in a 2d project. I want this for a reference image.
Thanks!
2.80 no longer has "background images" like previous versions.
The Add->Image->Reference actually adds an empty that is set to display as an image. You can set the empties properties to adjust the display options which includes the image displayed, you can also move it around like any other object.
There is also now a background image settings for camera objects, this looks like the old background image settings, but is part of the camera settings and is only visible in camera view.

Transparent window and view using Apple's Metal

I want to create a window which is fully transparent and which can be used for drawing (On-Screen-Display). It's actually quite simple to create such a window, the one has to set the opaque property to false and fill the corresponding view with a clear color. After that the CGImage can be drawn using the graphical context to update the view and the corresponding regions with alpha channel will be transparent / semi-transparent.
I decided to make the same thing but using the Metal API, i.e. I replaced my view with a MTKView and used textures instead of CGImage to draw onto the window. I read the corresponding chapters from Apple Documentation, then I took one of the examples ("Basic Texturing") and decided to modify it in order to test if it would work:
I modifed the example by settings the opaque property of the window to NO.
In the first line of drawInMTKView function I changed the clearColor in the following way: view.clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 0.0); (as shown "Devices and Commands" tutorial from docs).
Then I changed the alpha channel value of the loaded image in AAPLImage.h from dstImageData[dstPixelIndex + 3] = 255; to dstImageData[dstPixelIndex + 3] = 125;.
After all these change, I would expect that my view is fully transparent (the clear color is a fully transparent color) and that the parts of the texture with the alpha channel would have the corresponding transparency level. However the view is black by default and I cannot make parts of the view (or the whole view) transparent.
I may assume that I have to add some additional configuration to the rendering pipeline in order to make it work. However it could be that such things are not possible with Metal, but I'm not sure about that.
Also I tried to follow the suggestions from Metal MTLTexture replaces semi-transparent areas with black when alpha values that aren't 1 or 0 , but unfortunately it did not help.
There is also an isOpaque property on the view class that may need to be false. In iOS (UIView), you can simply set it, but in macOS (NSView) you need to override it to return false.

UIProgressView: modify height for track line

Currently I'm able to customize my progress bar modifying the whole height, in this way:
let transformScale = CGAffineTransformMakeScale(1.0, newProgressbarHeight)
self.progressBar.transform = transformScale
There is a way to modify the height of track in order to obtain a progress bar like this?
As a workaround I was pondering of put a gray view under the progress bar track tint color to clear color.
Any ideas?
iOS 5 or later, UIProgressView could set its FrontProgress Image(Green Fat)
And its Background Image(Gray Slim).
You could set Two different picture to simulate this effect.
Front Image property: progressImage.
Background Image property: trackImage.
Or,
If you only like Pure Color to avoid wasting any resource, I think the method below will fit your demand.
1.Create two UIProgressView.Fat and Slim, Front and Behind.
2.Set the Front One's trackTintColor [UIColor clearColor].
The code and effect in simulator
I hope these could help you. Good Luck!

Objectivec set shadow to parent view

I want to set shadow to parent view. But I want child views to remain the same.
What I do now is
parentView.layer.shadowRadius = 0.8;
parentView.layer.shadowOpacity = 0.3;
parentView.layer.shadowOffset = CGSizeMake(1.0, 1.4);
However, if I do this, the child views are also changed. Is there a way to set the shadow but keep the child views the same.
Thank you
Is your parentView by any chance transparent? I've set up a simple project and used your code. I've changed some values to see a shadow a little better. This is how it looks:
As you can see - no shadow on the subview. parentView's background color is set to white. When I set it to clear color this is what happens. I added the border to prove that parentView is still there:
Apple Docs prove this:
Figure A-7 shows several different versions of the same sample layer
with a red shadow applied. The left and middle versions include a
background color so the shadow appears only around the border of the
layer. However, the version on the right does not include a background
color. In this case, the shadow is applied to the layer’s content,
border, and sublayers.

quartz making opacity like in paths

When I set opacity to 0.5,create path and draw it even on self-intersections of this path opacity is the same with other parts of this path. Is there any way to make this effect in other cases? for example when I draw 2 images of same color and opacity in their intersection there is that opacity too.
You might be able to get the effect you want by changing the blending mode before drawing the images into your context. You can use CGContextSetBlendMode to set the blending mode. You can find the list of blending modes in the CGContext Reference. I suggest trying kCGBlendModeDarken or kCGBlendModeLighten first. Try some others if neither of those does what you want.