Group2D FillOpacity and Visibility

Hi all,
Can anyone answer these two questions for me?

  1. Group2D.FillOpacity seems to do nothing. Is this as intended?
  2. Is there any way to toggle visibility of an Object2D without removing it from the rendering queue?

I have avoided using the 2d vector graphics for a long time. Now I don’t know why. This is great.

Thanks in advance.

Are you filling the group with a fillcolor?
Thats the only thing it would act upon

the online help still shows the API1 syntax (below) , where the opacity is the .Fill property, with values of 0 to 100

What does your code look like?

Var o As New OvalShape
o.Width = 60
o.Height = 120
o.FillColor = Color.RGB(127, 127, 255)

Var a As New Group2D
a.Rotation = 0.90
a.ArcAngle = 1.57
a.Border = 100
a.BorderColor = &c0000ff
a.BorderWidth = 2.75
a.Fill = 50
a.FillColor = Color.RGB(255, 0, 127)
g.DrawObject(a, 100, 100)

in terms of visibility, you could maybe set the x position to -9000 + (actual x position) and back again?

Yes.

You can just change the FillOpacity and the BorderOpacity to zero. And then back to the baseline value. You do not have to destroy and recreate the Object2D.

The term rendering queue is a little ambiguous to me. I have used various forms of “rendering queues” when dealing with Object2D’s that need to be painted.

I gave this a test with the following code


dim o As New OvalShape
o.Width = 60
o.Height = 120
o.FillColor = Color.RGB(255,0,0)

dim t as new stringshape
t.Text = "Hello"
t.X=60
t.y= 70


dim grp As New Group2D
grp.Append o
grp.append t

//the following are ignored on the group object
grp.Border = 100
grp.BorderColor = &c0000ff
grp.BorderWidth = 2.75
grp.Fill = 0
grp.FillColor = &cff0000
//======================


g.DrawObject(grp, 40,40)

You’ll see I apply opacity and fill color to the group, but unless it contains objects, it draws nothing at all.
(eg remove the .append lines and you will get nothing on screen)

1 Like

The online example code doesn’t event append the arcshape, and needs fixing

taken from : Group2D — Xojo documentation

This code rotates the arc 0.9 radians.

Var o As New OvalShape
o.Width = 60
o.Height = 120
o.FillColor = Color.RGB(127, 127, 255)

Var a As New Group2D
a.Rotation = 0.90
a.ArcAngle = 1.57
a.Border = 100
a.BorderColor = &c0000ff
a.BorderWidth = 2.75
a.Fill = 50
a.FillColor = Color.RGB(255, 0, 127)
g.DrawObject(a, 100, 100)

You’ll see I apply opacity and fill color to the group, but unless it contains objects, it draws nothing at all.

I think the documentation should be more explicit, but I agree that

grp.BorderOpacity = 100
grp.BorderColor = &c0000ff
etc.

do nothing.

Object2D is the parent class for Group2D so it ends up having these properties like BorderColor but they do nothing. One might imagine that if there were two objects inside the Group2D, as in your example, grp.BorderColor = &c0000ff might make the BorderColor of both these Object2D = &c0000ff but that is not the case. If you want to achieve this result, you have to set up a for loop.

Var grp As New Group2D
Var lastIndex As Integer = grp.Count - 1
For nIndex As Integer = 0 To lastIndex
  grp.Item(nIndex).BorderColor = &c0000ff
  grp.Item(nIndex).BorderOpacity = 100
Next nIndex

As for the example you cite:

The online example code doesn’t event append the OvalShape, and needs fixing

I would heartily agree. Even if you did remember to add the OvalShape, I believe that the lines of code like

a.BorderOpacity = 100
a.BorderColor = &c0000ff

accomplish nothing. I suspect that the Rotation would do something.

Var o As New OvalShape
o.Width = 60
o.Height = 120
o.FillColor = Color.RGB(127, 127, 255)

Var a As New Group2D
a.AddObject(o)

a.Rotation = 0.90
a.ArcAngle = 1.57
a.BorderOpacity = 100
a.BorderColor = &c0000ff
a.BorderWidth = 2.75
a.Fill = 50
a.FillColor = Color.RGB(255, 0, 127)
g.DrawObject(a, 100, 100)

Thanks all.
This came about because had a strange design need.
Basically one element looks like a round-rectangle with only rounded corners on one side. I built this by making a round rectangle with a rectangle covering the corners on the other side.
The rub was that I needed to adjust the opacity. When I did so the overlapping area “multiplied”.

I thought if I combined them in a group and set the group’s opacity to X% that the two would render and then reduce opacity based on the sum of the original (solid) appearance.

So I need another approach.

You probably want to use a figureshape

You might be able to achieve the desired result with a couple of extra steps:
1.Code your Group2D with fully opaque colours
2.Create a temporary picture that has the required dimensions and an alpha channel
3.Draw the Group2D into the temporary picture
4.Set the Transparency property of the target Graphics object
5.Draw your temporary picture into the target Graphics object

Actually, that sounds fine. Was it just that they had a border of a different color?

Nope.
They had to overlap and the width of the corner. That small band of overlap doubled opacity.

Ah… two partialy transparent items. Got it. Yes, you need a figureshape… you can construct a shape of joined lines and curves. Not simple, but possible

1 Like