Recent

Author Topic: How do I make speedbutton colors correctly bright?  (Read 843 times)

bd4kc

  • New Member
  • *
  • Posts: 46
How do I make speedbutton colors correctly bright?
« on: December 14, 2020, 02:02:10 pm »
I want to do a big, very visible button, acting as a warning in the process of controlling machinery. I set its color, clred, but the red is very dark, and then I use tpanel, the color is bright red.

winni

  • Hero Member
  • *****
  • Posts: 2219
Re: How do I make speedbutton colors correctly bright?
« Reply #1 on: December 14, 2020, 05:41:17 pm »
Hi!

If I set the SpeedButton.color this does not matter - it stays gray.
This is OS depenent.

Use this:
Code: Pascal  [Select][+][-]
  1.   With SpeedButton1.glyph do
  2.      begin
  3.        width := SpeedButton1.width;
  4.        height:= SpeedButton1.height;
  5.        canvas.brush.color := clRed;
  6.        canvas.fillrect(0,0,width,height);
  7.      end;                                    

Winni
« Last Edit: December 14, 2020, 05:42:57 pm by winni »

bd4kc

  • New Member
  • *
  • Posts: 46
Re: How do I make speedbutton colors correctly bright?
« Reply #2 on: December 14, 2020, 07:27:53 pm »
THX,I used speedbtn1.canvas.brush.color: =clred; speedbtn1.canvas.fillrect(speedbtn1.clientrect); still got a dark red, not bright red.

bd4kc

  • New Member
  • *
  • Posts: 46
Re: How do I make speedbutton colors correctly bright?
« Reply #3 on: December 14, 2020, 08:04:49 pm »
 :D
Your code is working properly. What was my mistake?

Code: Pascal  [Select][+][-]
  1. { TForm1 }
  2.  
  3. procedure TForm1.sb1Click(Sender: TObject);
  4. begin
  5.  sb1.Color:=clred; //no effect
  6.  sb1.Canvas.Brush.Color:=clred;
  7.  sb1.Glyph.Canvas.Brush.Color:=clred;
  8.  sb1.Canvas.FillRect(sb1.Canvas.ClipRect);
  9.  sb1.Glyph.Canvas.FillRect(sb1.Canvas.ClipRect);
  10. end;
  11.  
  12. procedure TForm1.Button1Click(Sender: TObject);
  13. begin
  14.   with sb1.Glyph  do     //winni taught me ,work well
  15. begin
  16. width:=sb1.Width;
  17.   height:=sb1.Height;
  18.   canvas.Brush.Color:=clred;
  19.   canvas.FillRect(0,0,width,height);
  20.   end;
  21. end;
  22.        
  23.  
  24.  
  25.  


Hi!

If I set the SpeedButton.color this does not matter - it stays gray.
This is OS depenent.

Use this:
Code: Pascal  [Select][+][-]
  1.   With SpeedButton1.glyph do
  2.      begin
  3.        width := SpeedButton1.width;
  4.        height:= SpeedButton1.height;
  5.        canvas.brush.color := clRed;
  6.        canvas.fillrect(0,0,width,height);
  7.      end;                                    

Winni

winni

  • Hero Member
  • *****
  • Posts: 2219
Re: How do I make speedbutton colors correctly bright?
« Reply #4 on: December 14, 2020, 08:05:18 pm »
Hi

What is your OS/Widgetset ???

I did this with Linux64/gtk2 and I got a clear clRed = $0000FF

Lack of color inside Windows?
Or is your screen hard out of calibration?

Winni


bd4kc

  • New Member
  • *
  • Posts: 46
Re: How do I make speedbutton colors correctly bright?
« Reply #5 on: December 14, 2020, 08:12:47 pm »
Oh, I see, glyph's width and height are 0 until you set them. %)

winni

  • Hero Member
  • *****
  • Posts: 2219
Re: How do I make speedbutton colors correctly bright?
« Reply #6 on: December 14, 2020, 08:17:45 pm »
Bravo! You got it!

And forget about the SpeedButton.color. On the most OS that does not work.

And dont rely on the metrics of the canvas.
It is some kind of fraggle code.
Delphi does not have that.

Take the dimensions either of the button itself or of the glyph.

Winni


 

bd4kc

  • New Member
  • *
  • Posts: 46
Re: How do I make speedbutton colors correctly bright?
« Reply #7 on: December 14, 2020, 09:48:26 pm »
Speedbutton still has the problem of caption being pushed aside. Looks like my usage - big buttons, not quite right. I'm going to download some industrial components and study how they're drawn.
I write code on two computers, win10 and ubuntu. Is used to debug a machine, my partner draws drawings, we go to the factory to make parts. It is equipped with 3 servo motors, some homemade circuit boards, many sensors, many microprocessor chips (I am familiar with hardware, circuits, microprocessor assembly language these things, and computer programming is very different) and so on. I made a communication interface with microchips, and then Wrote code on this side of the computer to communicate with them, debugging is more convenient, can work like an office. No one around me uses native code programming, everyone is passionate about web front-end programming or python, and young people don't want to do some bottom-level work, which can mess up their shirts. I can't find anyone around for advice, only warm-hearted friends here, even though the connection to foreign websites here is very slow and disconnects from time to time.

jamie

  • Hero Member
  • *****
  • Posts: 4214
Re: How do I make speedbutton colors correctly bright?
« Reply #8 on: December 14, 2020, 11:50:27 pm »
The cliprect in the canvas is not the be used that way... Its only there it mark an area for limiting the painting area

you want to use the ClientRect for your surface area when calculating because it reports exactly what is visible in the control even if you had scrollbars.

 IF you are every doing this with a control that does have scrollbars you also need to use the X,Y Pos of the scroll bars as an offset to your drawing points

 But here you are using a Speedbutton which has no scroll bars, so don't worry..

The only true wisdom is knowing you know nothing

winni

  • Hero Member
  • *****
  • Posts: 2219
Re: How do I make speedbutton colors correctly bright?
« Reply #9 on: December 15, 2020, 01:51:52 am »
Hi!

With a big button forget the caption. Put an empty string into it.

And then:

Code: Pascal  [Select][+][-]
  1. with Speedbutton.glyph.canvas do
  2.    begin
  3.    font.height := 32;
  4.    font.color :=  clBlue;
  5.    TextOut (1,1,'I am a real caption');
  6.    end;
  7.  

done

Winni


 

TinyPortal © 2005-2018