Recent

Author Topic: Yet another question about the background color of a TSpeedButton \ TBitButton  (Read 3917 times)

devEric69

  • Hero Member
  • *****
  • Posts: 646
Hello,

I'm looking just for a TSpeedButton \ TGlyphButton that can display:
- a glyph;
- and can change its clientarea background-color at run-time.

I did a test with the " candy controls " using the TECSpeedBtn (it exposes, publishes its Canvas property) like below, but I can't repaint it in red:
Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.ECSpeedBtn1_OnRepeating(Sender: TObject);
  2. var
  3.   aRect: TRect;
  4. begin
  5.   TECSpeedBtn(Sender).Color:= clRed; // test 1: doesn't work
  6.  
  7.   aRect:= TECSpeedBtn(Sender).ClientRect;  // test 2: doesn't work neither
  8.   TECSpeedBtn(Sender).Canvas.Brush.Color:= clRed;
  9.   TECSpeedBtn(Sender).Canvas.Rectangle(aRect);
  10.   TECSpeedBtn(Sender).Canvas.FillRect(aRect);
  11. end;
   
I may be coding wrong because this control exposes very well its painting TCanvas, which is made for what I am looking to do, AFAIK. Any suggestions for using just such a TSpeedButton \ TGlyphButton that could be repainted over the OS theme (I'm on Linux)?
« Last Edit: November 07, 2021, 09:18:26 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

Fred vS

  • Hero Member
  • *****
  • Posts: 2544
    • StrumPract is the musicians best friend
Any suggestions for using just such a TSpeedButton \ TGlyphButton that could be repainted over the OS theme (I'm on Linux)?

MSEgui. ;)

Fre;D
« Last Edit: November 07, 2021, 02:56:11 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs

winni

  • Hero Member
  • *****
  • Posts: 3045
Hi!

Hardrock solution to get around the traps of the SpeedButton and the OS:

Create a BGRAbitmap from the glyph, which is a TBitmap
Paint on the BGRAbitmp as you need
Draw the BGRAbitmap on the Glyph.Canvas

Untested but should work

Winni

devEric69

  • Hero Member
  • *****
  • Posts: 646
Hi Fred,

Very nice buttons. I know you are working hard to refactor and maintain mseIDE. I allow myself to express a wish: it would be nice if we could create windows, either entirely build using MSEgui, or either entirely build using fpGUI, in the same X11 application. This is just an idea, may be crazy (I've no knowledge of mseIDE), but by making its message distribution loop "polymorphic" \ adaptable to MSEgui that I don't know :-[ , and fpGUI that I know 8-) - to make the two types of windows working together in an application - whether there is a real possibility, mseIDE would become THE MUST HAVE IDE-tool for X11 programming.


Hi Winni,

In fact, I've just tried to install libxst-dev + libl-dev Debian packages + bgrabitmappack.lpk + bgracontrols.lpk this morning ==> but unfortunately, I encountered some annoying messages after compiling and installing these packages:
- cannot load libGLU.so ;
- canot find opengl/src/glu.pp ;
- Lazarus stopped launching itself, then it hung up ;

That said, sooner or later, I will have to use BGRAbitmap with TeeChart (so, I will have to reinstall and really understand the above unwelcome messages). But for now, I have to finish quickly something else: I'll postpone to understand these messages. I've used SVN to clean everything up and put Lazarus back the way it was - renamming lazarusOld.elf towards lazarus.elf - before my trial to install the BGRA framework. Hence, my test with another controls framework (" candy controls ", which has funny shape controls, rather electronically oriented): I think it should be possible to override an OS theme with them (but I only started reading their source code since yesterday :-X ).
« Last Edit: November 07, 2021, 04:02:17 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

winni

  • Hero Member
  • *****
  • Posts: 3045
Hi!

Again Debian trouble .....

AFAIR libGLU is part of the package libglu1-mesa
Install this Debian Package.
And look for the next Debian trouble ...

Winni

Fred vS

  • Hero Member
  • *****
  • Posts: 2544
    • StrumPract is the musicians best friend
Hi Fred,
...

I allow myself to express a wish: it would be nice if we could create windows, either entirely build using MSEgui, or either entirely build using fpGUI, in the same X11 application. This is just an idea, may be crazy (I've no knowledge of mseIDE), but by making its message distribution loop "polymorphic" \ adaptable to MSEgui that I don't know :-[ , and fpGUI that I know 8-) - to make the two types of windows working together in an application - whether there is a real possibility, mseIDE would become THE MUST HAVE IDE-tool for X11 programming.

Hum, that would be difficult because fpGUI and MSEgui have totally different architectures.
They share both libX11.so.6 library but dont have the same interface.
So for all the graphic widgets at the moment I dont see solution to share for example a TMSEButton on a fpGUIForm and vice versa ).

But you may, of course, load-edit-debug-run fpGUI projects with MSEide ( the IDE for MSEgui ).
ideU ( a fork of MSEide ) has integration with fpGUI designer for example.

PS: A other advantage with fpGUI/MSEgui is: no more problems with all that dependencies  :-X

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs

devEric69

  • Hero Member
  • *****
  • Posts: 646
Again Debian trouble .....
AFAIK libGLU is part of the package libglu1-mesa
Install this Debian Package.
And look for the next Debian trouble ...

Thanks for the information, that's good to know.  I'll give it a try :-* .


They share both libX11.so.6 library but dont have the same interface.
So for all the graphic widgets at the moment I dont see solution to share for example a TMSEButton on a fpGUIForm and vice versa.

Of course, I knew - in fact - that my request was very complicated >:D .

But I thought very less complicated than what you're talking: just to create only pure MSEgui windows or only pure fpGUI windows. And at first, only MSEgui windows will understand \ talk each other, and only fpGUI windows will understand \ talk each other. In other words, initially the mseIDE loop messages would not send an fpGUI message towards an MSEGUI window, and vice versa (a MSEGUI message towards an fpGUI window). Anyway: it's just an idea.
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

Fred vS

  • Hero Member
  • *****
  • Posts: 2544
    • StrumPract is the musicians best friend
But I thought very less complicated than what you're talking: just to create only pure MSEgui windows or only pure fpGUI windows. And at first, only MSEgui windows will understand \ talk each other, and only fpGUI windows will understand \ talk each other. In other words, initially the mseIDE loop messages would not send an fpGUI message towards an MSEGUI window, and vice versa (a MSEGUI message towards an fpGUI window). Anyway: it's just an idea.

Hum, it is what ideU does.
For example if you edit a unit-form, when you press F12 the form-designer of fpGUI will be loaded for a fpGUI unit and the MSEgui designer for a MSEgui unit.
For both MSEgui and fpGUI designers, if you change something in design, it is changed in the code too.
Also if you change the code, for both MSEgui and fpGUI designers the change is done in design too.

In the release of ideU is included fpGUI Desinger_ext who is a fork of the original fpGUI UIDesinger but adapted for interaction with ideU.

I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs

winni

  • Hero Member
  • *****
  • Posts: 3045
Hi!

It is hard to draw  on the Speedbutton.glyph:
It remembers the transparent parts of the bitmap. If you want to get around that  you have to make changes in the Class TButtonGlyph.

But you can get around the glyph this way:

Do not put a bitmap inside the glyph.
Use another place for your icon (ImageList, Resource, HardDisk)
Load and/or draw on a Bitmap/BGRAbitmap
Draw it on the canvas oft the SpeedButton (NOT the glyph)
done

Example:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.SpeedButton5Paint(Sender: TObject);
  2. var tmp : TBGRAbitmap;
  3. begin
  4.   tmp := TBGRAbitmap.create (SpeedButton5.width,SpeedButton5.height, cssBlue);
  5.   tmp.DrawLineAntialias(0,0,tmp.width,tmp.height,cssRed,5);
  6.   tmp.Draw(SpeedButton5.canvas,0,0,true);
  7.   tmp.free;
  8. end;
  9.  


Winni

devEric69

  • Hero Member
  • *****
  • Posts: 646
Well, I think I'm going to write a pseudo-TBitButton composition (@Winni: thanks for the code examples. As already said, I will sooner or later use the BGRAbitmap framework to draw on TaChart; but I need a rapid embedded solution), i.e. a component following @wp's idea (found here...) i.e. encapsulating a TPanel with its small 16x16 [px] TBitmap image + its TLabel + the TPanel.onOver, etc..., events, all encapsulated in the said component-visual-control that will only publish, delegate the OnClik of the encapsulated TPanel. This is really the easiest way to do it quickly.

By the way, I was tired this morning: I've confused the TECSpeedBtn OnRepeating event with the OnRepainting one, which in fact doesn't exist :-[  ::) . Sorry. That said, it's a damage that most Lazarus controls don't add the possibility to override through the call of an external event at the end of their virtual Paint method. But hey, that's the way it is.

@Fred: my real respect for your ideU IT automatisation. I hope you'll find some magical inspiration to make the 2 types of application messages loops (those of MSEgui and those of fpGUI) cohabit in one more holistic and magically unifying messages loop  O:-).
« Last Edit: November 07, 2021, 09:14:12 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9993
  • FPC developer.
(Sometimes when native controls don't want to change color is because parentcolor/parentbackground is on.

I use something like this procedure to test if that is the case:
Code: Pascal  [Select][+][-]
  1. procedure zapcolor(t:twincontrol;col:tcolorref);
  2.  var i : integer;
  3.      x : TControl;
  4.  
  5. begin
  6.   if t is  tpanel then
  7.     begin
  8.       tpanel(t).parentcolor:=false;
  9.   //    {$ifndef fpc}
  10.       tpanel(t).parentbackground:=false;
  11. //      {$endif}
  12.       tpanel(t).color:=col;
  13.      end;
  14.   if t is  tform then
  15.     begin
  16.       {$ifndef fpc}
  17. //      tform(t).parentcolor:=false;
  18. //      tform(t).parentbackground:=false;
  19.       {$endif}
  20.       tform(t).color:=col;
  21.      end;
  22.   if t is tframe then
  23.     begin
  24.       tframe(t).parentcolor:=false;
  25.       tframe(t).parentbackground:=false;
  26.       tframe(t).Color:=col;
  27.     end;
  28.   for i:=0 to t.ControlCount-1  do
  29.     begin
  30.       x:=t.controls[i];
  31.       if x is tpanel then
  32.         begin
  33.           tpanel(x).parentcolor:=false;
  34.           tpanel(x).parentbackground:=false;
  35.           tpanel(x).color:=col;
  36.          end;
  37.        if x is tgroupbox then
  38.          begin
  39.            tgroupbox(x).parentcolor:=false;
  40.            tgroupbox(x).parentbackground:=false;
  41.            tgroupbox(x).color:=col;
  42.          end;
  43.      if x is twincontrol then
  44.        zapcolor(twincontrol(x),col);
  45.     end;
  46. end;
  47.  


)

devEric69

  • Hero Member
  • *****
  • Posts: 646
@marcov: thanks for the piece of code.

I'm posting a TMimicRollOverBitBtn (this kind of the 3 button's colours management is called a " web rollover button ", on the internet) graphic control (based on an idea from @wp). Not perfect, but it does what I want.
By the way, if someone can explain me how to assign the container TPanel caption to '' (empty string): I do this assignment (Self.Caption:= '';) in the constructor and in the Loaded, but a side-effect always rewrites the panel's name in its caption :-\ .

« Last Edit: November 11, 2021, 12:16:26 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

howardpc

  • Hero Member
  • *****
  • Posts: 3976
By the way, if someone can explain me how to assign the container TPanel caption to '' (empty string): I do this assignment (Self.Caption:= '';) in the constructor and in the Loaded, but a side-effect always rewrites the panel's name in its caption :-\ .
In the container's constructor include this line:
Code: Pascal  [Select][+][-]
  1. ControlStyle := ControlStyle - [csSetCaption];

devEric69

  • Hero Member
  • *****
  • Posts: 646
Okay, thanks: I've learned something (component uploaded with this tiny correction).
« Last Edit: November 12, 2021, 11:58:28 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

 

TinyPortal © 2005-2018