Layers - modify colour / transparency


#1

Hi all,
I am currently building a layer manager to allow the user to define layers of objects and modify the layers, including visility, layer number, modify objects in the layer etc. I would also like to set the colour of the objects in a layer and if possible set a transparency level. Is this possible (colour and or transparency), if so any advice / comments would be gratefully received.
cheers


#2

Color is a property of Pen and Brush objects which are properties of GoObjects such as GoShape. Colors are also properties of some objects such as GoText.
Transparency is controlled by setting the Alpha property of Colors.
So color/transparency isn’t something you can set on a GoLayer. But you could implement something like that by just iterating over all the objects in a layer and resetting their pens/brushes/text-colors.


#3

Hi
thanks for your reply, any thoughts on how I could modify colour / transparency for bitmap images used as the icons for gosimplenode and gogeneralnode??
many thanks


#4

It’s a little complicated–you’ll need to learn about ColorMatrix and Graphics.DrawImage. The following override of GoImage.Paint is untested but may give you an idea of how to do it. It won’t even compile because you need to decide how to specify the color/transparency you want:
public override void Paint(Graphics g, GoView view) {
Image img = this.Image;
if (img != null) {
ColorMatrix cm = new ColorMatrix();
cm.Matrix00 = 0;
cm.Matrix11 = 0;
cm.Matrix22 = 0;
cm.Matrix30 = color.R/255.0f;
cm.Matrix31 = color.G/255.0f;
cm.Matrix32 = color.B/255.0f;
cm.Matrix33 = color.A/255.0f;
ImageAttributes im = new ImageAttributes();
im.SetColorMatrix(cm);
g.DrawImage(img, this.Bounds, 0, 0, img.Size.Width, img.Size.Height, GraphicsUnit.Pixel, im);
}
}


#5

Hi,
many thanks for your reply(s), I can now modify the colors and transparanecy of the bitmaps used.
Just one final question, can a GoObject be in more than one layer??.
many thanks.


#6

Not simultaneously. But you can easily change layers for top-level objects by just adding it to the desired layer.


#7

Hi walter,
many thanks for your help so far, the paint method override works well but unfortunately it has created a problem in that it seems to incorrectly resize the bitmap image used in the gosimplenode and also the connection port is no longer visible. I add ports to the object by using the (overrided) Layoutchildren method. The piant override is called after layoutchildren function is called and seems to cause the above mentioned problems.
Any thoughts or suggestions,
many thanks
Gary Easom


#8

The GoObject.Paint method should have nothing to do with the GoGroup.LayoutChildren method (or with MoveChildren or RescaleChildren).
If you replace the implementation of your override of Paint with a call to base.Paint, thereby restoring the original painting behavior of GoImage, there should be no effect on how objects are sized and positioned by any implementation of GoGroup.LayoutChildren.