Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-03

Background colours etc.

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

On a form, I've got a TImage containing a star that changes colour to indicate the progress of a comms protocol I'm trying to get working. It normally shows a plain background, then a blue star showing that it's trying to connect, which changes to red or green depending on the result- and so on. The star images are coming from a bitmap in a TImageList on the same form.

I'm having a lot of hassle trying to get the background colour to match that of the form. I see from Google etc. that this has been an issue in the past: how should I be doing it, or should I give up and just use a square panel that changes colour?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Felipe Monteiro de Carvalho
to Mark Morgan Lloyd

There are 2 options:

1-> The default form color is very well defined, just use ColorToRGB(clForm) to get it

or

2-> You can also set a region for your TImage which matches the star shape, which will make the control non-rectangular. Use TWinControl.SetShape(Region). Use LCLIntf functions to create the region. setShape does not work before the form has been shown (so OnShow event) in LCL-Gtk2, because as always Gtk2 has issues. To make a star try something like CreatePolygonalRgn (or similar name)

Felipe Monteiro de Carvalho

Reply by email

Mark Morgan Lloyd
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 13 lines
There are 2 options: 1-> The default form color is very well defined, just use ColorToRGB(clForm) to get it or 2-> You can also set a region for your TImage which matches the star shape, which will make the control non-rectangular. Use TWinControl.SetShape(Region). Use LCLIntf functions to create the region. setShape does not work before the form has been shown (so OnShow event) in LCL-Gtk2, because as always Gtk2 has issues. To make a star try something like CreatePolygonalRgn (or similar name)

OK, but are you saying that I've got to start filling areas at runtime or drawing vectors? I was hoping to be able to use some "fire and forget" bitmaps, possibly with one colour being reserved for background/transparency.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Felipe Monteiro de Carvalho
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
OK, but are you saying that I've got to start filling areas at runtime or drawing vectors? I was hoping to be able to use some "fire and forget" bitmaps, possibly with one colour being reserved for background/transparency.

transparency is not supported currently in TWinControl descents. TWinControl.setShape(Bitmap) is the closest to what you want, but a lot of interfaces don't support it, and in general it is not a very portable method. If you really want that and don't want to use method 1 or method 2, then you can write a TGraphicControl descendent and paint there only your star without its background. By not painting the background it will be transparent. It will not be able to receive keyboard events as it is not a TWinControl. I don't know a ready component which will do that you might need to write one.

And about method 2, it is not vectorial drawing. It is a region shape setting. You can see an example here:

http://wiki.lazarus.freepascal.org/LazEyes

It allows for non-rectangular windows and controls. If all your starts have the same size you can set the shape once and forget. If they have different sizes you will need to reshape for each star size.

Felipe Monteiro de Carvalho

Reply by email

Mark Morgan Lloyd
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 25 lines
On Fri, Mar 2, 2012 at 11:46 PM, Mark Morgan Lloyd wrote: > OK, but are you saying that I've got to start filling areas at runtime or > drawing vectors? I was hoping to be able to use some "fire and forget" > bitmaps, possibly with one colour being reserved for > background/transparency. transparency is not supported currently in TWinControl descents. TWinControl.setShape(Bitmap) is the closest to what you want, but a lot of interfaces don't support it, and in general it is not a very portable method. If you really want that and don't want to use method 1 or method 2, then you can write a TGraphicControl descendent and paint there only your star without its background. By not painting the background it will be transparent. It will not be able to receive keyboard events as it is not a TWinControl. I don't know a ready component which will do that you might need to write one. And about method 2, it is not vectorial drawing. It is a region shape setting. You can see an example here: http://wiki.lazarus.freepascal.org/LazEyes It allows for non-rectangular windows and controls. If all your starts have the same size you can set the shape once and forget. If they have different sizes you will need to reshape for each star size.

Thanks, noted.

For something which is known not to have "holes", is there an easy way of doing a flood fill of the background colour to the TImageList?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email