Recent

Author Topic: can't find a TColor Helper in the libs.  (Read 2919 times)

jamie

  • Hero Member
  • *****
  • Posts: 6131
can't find a TColor Helper in the libs.
« on: January 05, 2019, 04:43:13 pm »
This all started when looking for the color source for the canvas.Frame3d( rect,Framewidth, style), it obviously does not use the brush color or the canvas.brush given, unless this is some bug I have uncovered because I first paint the
surface with red and then use this function to draw a 3d look, but it uses a grey color for that instead?

 Where is this color coming from I don't know, since I first set the canvas.brush.color then do the canvas.FillRect.
etc... this works.
 
But the same canvas.Frame3e(Rect, width, style) uses some other color not related to the canvas I am using...

Maybe  bug who knows...

 --- getting back ---

  So I decided to use the Frame3D that specifies the upper and lower colors however, I need to calculate these
colors from the brush color I just used and found there is no ready made functions in the LCL/Graphics unit to
address levels for a TColor nor could did I see a Helper for the Tcolor..

 Did I miss something or is this a good time to make a TColor helper ?

The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: can't find a TColor Helper in the libs.
« Reply #1 on: January 05, 2019, 04:55:39 pm »
Is it canvas of some component or TBitmap.canvas?
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: can't find a TColor Helper in the libs.
« Reply #2 on: January 05, 2019, 05:00:38 pm »
Currently I am doing this with the Onpaint method of a TSpeedButton…

I do this in the method.
R := TControl(Sender).ClientRect;
 With TSpeedButton(Sender).Canvas do
 
  begin
   brush.color := clRed;
   FillRect(R);
   Then I do Fram3d.....
 End;

 In that block I use the Frame3d simple version after I fill the button with clRed but the frame3d issing
some source of grey.

Example:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.SpeedButton2Paint(Sender: TObject);
  2. Var
  3.   R:TRect;
  4. begin
  5.   With TSpeedbutton(Sender) do
  6. Begin
  7.   canvas.Brush.color := clRed;
  8.   R := ClientRect;
  9.   Canvas.FillRect(R);
  10.   Case Down of
  11.    True :canvas.Frame3d(R,2, bvLowered); //Does not use the brush color or Pen color..
  12.    False:Canvas.Frame3D(R,2, bvRaised);  //Same.
  13.   End;
  14.   End;
  15. end;              
  16.  
What did I do wrong?
« Last Edit: January 05, 2019, 05:12:41 pm by jamie »
The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: can't find a TColor Helper in the libs.
« Reply #3 on: January 05, 2019, 05:23:16 pm »
There are two Frame3D methods:
Code: Pascal  [Select][+][-]
  1. procedure Frame3d(var ARect: TRect; const FrameWidth: integer; const Style: TGraphicsBevelCut); virtual;
  2. procedure Frame3D(var ARect: TRect; TopColor, BottomColor: TColor; const FrameWidth: integer); overload;

The first is implemened like this:
Code: Pascal  [Select][+][-]
  1. procedure TCanvas.Frame3d(var ARect: TRect; const FrameWidth : integer; const Style : TGraphicsBevelCut);
  2. begin
  3.   Changing;
  4.   RequiredState([csHandleValid,csBrushValid,csPenValid]);
  5.   LCLIntf.Frame3d(FHandle, ARect, FrameWidth, Style);
  6.   Changed;
  7. end;
It is some native frame done by widgetset so you probably cannot change its colors. You need to use the second Frame3D.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: can't find a TColor Helper in the libs.
« Reply #4 on: January 05, 2019, 05:39:20 pm »
must be a bug then.... I just don't understand why you would use surrounding colors or theme colors for this
for which it seems like it is..

 getting back to the Tcolor Helper, I think I'll write a helper class for that one that has all sorts of different things
in it related to color conversions etc...

 I don't know if this is worth reporting ?
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: can't find a TColor Helper in the libs.
« Reply #5 on: January 05, 2019, 05:40:19 pm »
  So I decided to use the Frame3D that specifies the upper and lower colors however, I need to calculate these
colors from the brush color I just used and found there is no ready made functions in the LCL/Graphics unit to
address levels for a TColor nor could did I see a Helper for the Tcolor..

 Did I miss something or is this a good time to make a TColor helper ?

AFAIK there is no helper to do this for TColor but in unit GraphUtil you can find GetShadowColor() and GetHighLightColor() which seem made apropos for this.

must be a bug then.... I just don't understand why you would use surrounding colors or theme colors for this
for which it seems like it is..

It's not a bug, I think. It's probably intended to be used to draw controls derived from TGraphicControl, TCustomControl, etc.

Quote
getting back to the Tcolor Helper, I think I'll write a helper class for that one that has all sorts of different things
in it related to color conversions etc...

Look first in the help files and the sources. There are tons of ready made helper functions like those two I cited above.
« Last Edit: January 05, 2019, 05:45:18 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: can't find a TColor Helper in the libs.
« Reply #6 on: January 05, 2019, 05:58:04 pm »
Yes that is exactly what I need but I have no intensions of reinventing the wheel but to place a helper class
to inline existing functions if they exist, these two would be included of course.

 For others I can add to, maybe at some point put it in the graphUntil which I didn't know existed.

 I still think that Frame3D is buggy though..

 Thanks.


The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: can't find a TColor Helper in the libs.
« Reply #7 on: January 05, 2019, 06:48:41 pm »
I still think that Frame3D is buggy though..

Think of it this way: There is the normal, system-drawn Frame3D and another Frame3D which allows you to customize all parameters. No bug, just options.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: can't find a TColor Helper in the libs.
« Reply #8 on: January 05, 2019, 07:42:55 pm »
Point taken however, when using it from the Tcanvas……. it should be using the canvas.bush as the color.

as for the widget if that is what they want from the widget side that is fine but from within the canvas it
should be composing this short version using the longer version.
 
Oh well...
The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: can't find a TColor Helper in the libs.
« Reply #9 on: January 05, 2019, 08:22:05 pm »
Well, frame is drawn by lines, so here brush.color doens't have any effect. Line color depend on canvas.pen.color.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: can't find a TColor Helper in the libs.
« Reply #10 on: January 05, 2019, 09:21:08 pm »
True but that does not work ether..

 You can use the Pen API,  overwrite the existing one or even just set it from the canvas and it
makes no difference..
 
 It must be creating a new pen and using system colors instead and then restoring it via the
SelectObject and delete object etc..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018