Recent

Author Topic: BGRAFlashProgressBar color  (Read 1211 times)

RDL

  • New member
  • *
  • Posts: 33
BGRAFlashProgressBar color
« on: August 06, 2018, 07:40:29 am »
hi.

How can I change the color black to any other?  :-[

Sorry for my english, google translation!

Handoko

  • Hero Member
  • *****
  • Posts: 2694
  • My goal: build my own game engine using Lazarus
Re: BGRAFlashProgressBar color
« Reply #1 on: August 06, 2018, 08:28:30 am »
No, you can't unless you manually edit the source. The color is hardcoded in TBGRAFlashProgressBar.Paint:

Code: Pascal  [Select]
  1. procedure TBGRAFlashProgressBar.Paint;
  2. var
  3.   content: TRect;
  4.   xpos, y, tx, ty: integer;
  5.   grayValue: integer;
  6.  
  7.   function ApplyLightness(c: TBGRAPixel; lightness: word): TBGRAPixel;
  8.   begin
  9.     Result := GammaCompression(SetLightness(GammaExpansion(c), lightness));
  10.   end;
  11.  
  12.   procedure DrawBar(bounds: TRect);
  13.   var
  14.     lCol: TBGRAPixel;
  15.   begin
  16.     lCol := Color;
  17.  
  18.     DoubleGradientAlphaFill(FBmp, bounds,
  19.       ApplyLightness(lCol, 37000), ApplyLightness(lCol, 29000),
  20.       ApplyLightness(lCol, 26000), ApplyLightness(lCol, 18000),
  21.       gdVertical, gdVertical, gdVertical, 0.53);
  22.  
  23.     InflateRect(bounds, -1, -1);
  24.  
  25.     DoubleGradientAlphaFill(FBmp, bounds,
  26.       ApplyLightness(lCol, 28000), ApplyLightness(lCol, 22000),
  27.       ApplyLightness(lCol, 19000), ApplyLightness(lCol, 11000),
  28.       gdVertical, gdVertical, gdVertical, 0.53);
  29.   end;
  30.  
  31. begin
  32.   tx := ClientWidth;
  33.   ty := ClientHeight;
  34.   if Assigned(FBmp) and ((FBmp.Width <> tx) or (FBmp.Height <> ty)) then
  35.     FreeAndNil(FBmp);
  36.  
  37.   if not Assigned(FBmp) then
  38.     FBmp := TBGRABitmap.Create(tx, ty)
  39.   else
  40.     FBmp.FillTransparent;
  41.  
  42.   FBmp.Rectangle(0, 0, tx, ty, BGRA(255, 255, 255, 6), dmSet);
  43.   if (tx > 2) and (ty > 2) then
  44.     FBmp.Rectangle(1, 1, tx - 1, ty - 1, BGRA(29, 29, 29), dmSet);
  45.  
  46.   if (tx > 4) and (ty > 4) then
  47.   begin
  48.     content  := Rect(2, 2, tx - 2, ty - 2);
  49.     randseed := FRandSeed;
  50.     for y := content.Top to content.Bottom - 1 do
  51.     begin
  52.       if y = content.Top then
  53.         grayValue := 33
  54.       else
  55.       if y = content.Top + 1 then
  56.         grayValue := 43
  57.       else
  58.         grayValue := 47 + random(50 - 47 + 1);
  59.       FBmp.SetHorizLine(content.Left, y, content.Right - 1, BGRA(
  60.         grayValue, grayValue, grayValue));
  61.     end;
  62.     if tx >= 6 then
  63.       FBmp.DrawVertLine(content.Right - 1, content.Top, content.Bottom - 1,
  64.         BGRA(0, 0, 0, 32));
  65.     if FMaxValue > FMinValue then
  66.     begin
  67.       xpos := round((FValue - FMinValue) / (FMaxValue - FMinValue) *
  68.         (content.right - content.left)) + content.left;
  69.       if xpos > content.left then
  70.       begin
  71.         DrawBar(rect(content.left, content.top, xpos, content.bottom));
  72.         if xpos < content.right then
  73.         begin
  74.           FBmp.SetPixel(xpos, content.top, BGRA(62, 62, 62));
  75.           FBmp.SetVertLine(xpos, content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
  76.         end;
  77.       end;
  78.     end;
  79.   end;
  80.   if Assigned(OnRedraw) then
  81.     OnRedraw(Self, FBmp, {%H-}xpos);
  82.   FBmp.Draw(Canvas, 0, 0, False);
  83. end;

In the example picture below, I modify the line #59, #60 to use red:
Code: Pascal  [Select]
  1.       FBmp.SetHorizLine(content.Left, y, content.Right - 1, BGRA(
  2.         200{grayValue}, grayValue, grayValue));

RDL

  • New member
  • *
  • Posts: 33
Re: BGRAFlashProgressBar color
« Reply #2 on: August 06, 2018, 08:41:21 am »
It is a pity that for this you need to edit the source code.
It would be great to be able to change the color without editing the source code.
Sorry for my english, google translation!

Handoko

  • Hero Member
  • *****
  • Posts: 2694
  • My goal: build my own game engine using Lazarus
Re: BGRAFlashProgressBar color
« Reply #3 on: August 06, 2018, 08:44:48 am »
You can submit a feature request. The developer is nice.

RDL

  • New member
  • *
  • Posts: 33
Re: BGRAFlashProgressBar color
« Reply #4 on: August 06, 2018, 08:48:33 am »
Handoko
Thanks for the help :)
Sorry for my english, google translation!

lainz

  • Hero Member
  • *****
  • Posts: 2923
    • Home
Re: BGRAFlashProgressBar color
« Reply #5 on: August 07, 2018, 03:51:53 am »
Hi, I will try to add the color feature soon.

lainz

  • Hero Member
  • *****
  • Posts: 2923
    • Home
Re: BGRAFlashProgressBar color
« Reply #6 on: August 09, 2018, 03:48:11 am »
Hi, I've added the BackgroundColor property in dev-bgracontrols branch, please test and see if it works for you. You can set the min and max intensity of the random lines as well, even disable these random lines to fill with a solid color.

RDL

  • New member
  • *
  • Posts: 33
Re: BGRAFlashProgressBar color
« Reply #7 on: August 10, 2018, 04:36:40 am »
lainz
Hi
I checked, it works.
Can you add the ability to enable or disable the display of frames?
« Last Edit: August 10, 2018, 04:41:34 am by RDL »
Sorry for my english, google translation!

lainz

  • Hero Member
  • *****
  • Posts: 2923
    • Home
Re: BGRAFlashProgressBar color
« Reply #8 on: August 10, 2018, 04:39:21 pm »
Hi. Yes that seems possible. I will try to do it.