Recent

Author Topic: BGRA Controls FX v0.1.6.1  (Read 7995 times)

lainz

  • Hero Member
  • *****
  • Posts: 2912
    • Home
BGRA Controls FX v0.1.6.1
« on: October 24, 2016, 01:12:35 am »
New package!

Download: https://github.com/bgrabitmap/bgracontrolsfx/releases

BGRA Controls FX is a set of OpenGL Controls for Lazarus. It works with BGRAOpenGL. The controls are hybrid, so you can place them in FXContainer to get hardware acceleration or place them in a normal form to draw them with normal canvas.

Available controls:
* FXContainer
* FXButton
* FXNativeButton
* FXMaterialButton
* FXProgressBar
* FXRadialProgressBar

Available tests:
* test_hybrid
* test_multi_containers
* test_panel
* test_receive_and_lock_paint
« Last Edit: December 16, 2016, 08:31:24 pm by lainz »

circular

  • Hero Member
  • *****
  • Posts: 2782
    • Personal webpage
Re: BGRA Controls FX v0.1
« Reply #1 on: October 24, 2016, 01:01:09 pm »
Nice! Beautiful color themes :)

I would suggest a little change to avoid invalidating twice:
Code: Pascal  [Select]
  1. procedure TFXGraphicControl.FXInvalidate;
  2. begin
  3.   if (csDesigning in ComponentState) then
  4.     Invalidate else
  5.   begin
  6.     if Parent is TFXContainer then
  7.     begin
  8.       if TFXContainer(Parent).ReceivePaintFrom = nil then
  9.         Parent.Invalidate;
  10.     end
  11.     else
  12.       Invalidate;
  13.   end;
  14. end;

Also to make FXDraw virtual so that it would be possible to add some OpenGL extra rendering:
Code: [Select]
procedure FXDraw; virtual;
What I would also suggest is to use OpenGL ability to colorize. When doing BGLCanvas.PutImage, you can specify a color that will multiply the image. So in principle what you can do is to prepare a shape of a button in white, and then when the color changes, to draw it in the specified color without having to redraw the shape.

One need to take into account that the text may have another color, or that it would still need to be white and not colorised. So a way to do that would be to have layers instead of only one FBGRA. Basically you need a list of records with FBGRA, FTexture and FColor for each of the layers.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 2912
    • Home
Re: BGRA Controls FX v0.1
« Reply #2 on: October 24, 2016, 03:58:22 pm »
Thanks I will add the code for invalidate.

I get what you say. I must try that.

Edit: I've applied some of the suggestions you did, but it doesn't works anymore using a Record. Seems that's a problem accessing the Textrure from the record. I get a SIGSEGV. But this works in the normal canvas, so it's a problem with the texture, also If I remove the line that draws the texture it runs fine, but of course it displays nothing.
« Last Edit: October 24, 2016, 06:34:29 pm by lainz »

circular

  • Hero Member
  • *****
  • Posts: 2782
    • Personal webpage
Re: BGRA Controls FX v0.1
« Reply #3 on: October 24, 2016, 11:40:48 pm »
I think it comes from the fact that TFXLayer is a record and that it contains an interface variable FTexture. I suppose the problem is because of copying the content of the record. The reference count of the interface must be incremented/decremented each time the record is copied but in some cases it doesn't work.

So simply change TFXLayer to a class and that should be fine.

Some remark about the color. The neutral color when you do PutImage(..., Color) is white, because it has all its value to 1 so it doesn't change anything. So just initialise it to BGRAWhite and then you don't need to test its value, because PutImage with a white color will do exactly the same as PutImage without colorising.

When drawing on a regular canvas, of course you don't have Draw with color. This time you need to check if it is white because it will take some time to colorise it. To apply the color, create another bitmap and go through all pixels.
Code: Pascal  [Select]
  1. psource := Source.Data;
  2. pdest := Dest.Data;
  3. ec := GammaExpansion(c); //c is the color to apply
  4. for n := source.NbPixels-1 downto 0 do
  5. begin
  6.   pdest^.red := GammaCompressionTab[((GammaExpansionTab[psource^.red]*ec.red+65535) shr 16)];
  7.   pdest^.green := GammaCompressionTab[((GammaExpansionTab[psource^.green]*ec.green+65535) shr 16)];
  8.   pdest^.blue := GammaCompressionTab[((GammaExpansionTab[psource^.blue]*ec.blue+65535) shr 16)];
  9.   //pdest^.alpha := (pdest^.alpha*ec.alpha+255) shr 16;
  10.   pdest^.alpha := (psource^.alpha*ec.alpha+255) shr 16;
  11.   inc(pdest);
  12.   inc(psource);
  13. end;
« Last Edit: October 25, 2016, 12:13:15 pm by circular »
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 2912
    • Home
Re: BGRA Controls FX v0.1
« Reply #4 on: October 24, 2016, 11:52:56 pm »
Thanks now it's working.

About colorize, i'm adding it.

Edit: Done! Now it is very usable anyone can contribute controls from now or make their own controls because everything is working well.

I'm releasing the version 0.1.2 now, these are all changes from previous versions:

0.1.1:

Added new control FXNativeButton
A lot of fixes

0.1.2:

Added FXLayers support
Improved painting
Fix for resizing controls
Fix in FXNativeButton under Linux
Fix for buttons mouse click

Edit2: I've added the proper credits and more fixes on git, I missed the alpha value that was not colorizing well and updated the FXNativeButton, so now you can get a native button plus a color of your choice.
« Last Edit: October 25, 2016, 12:39:20 am by lainz »

circular

  • Hero Member
  • *****
  • Posts: 2782
    • Personal webpage
Re: BGRA Controls FX v0.1.2
« Reply #5 on: October 25, 2016, 12:14:52 pm »
Ah sorry I made a mistake in the alpha value. I corrected it.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 2912
    • Home
Re: BGRA Controls FX v0.1.2
« Reply #6 on: October 25, 2016, 03:43:30 pm »
Thankyou!

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 458
Re: BGRA Controls FX v0.1.2
« Reply #7 on: October 25, 2016, 05:53:33 pm »
Nice work. Will try ASAP.

I suggest renaming FXMaterialDesignButton to FXMaterialButton since is simpler, smaller and, at same time, makes clear its meaning.

Also for consistency, is FXNativeButton not FXNativeDesignButton


lainz

  • Hero Member
  • *****
  • Posts: 2912
    • Home
Re: BGRA Controls FX v0.1.3
« Reply #8 on: October 25, 2016, 06:19:32 pm »
Thanks. I will keep the naming for now. And for FXNativeButton is already that name.

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 458
Re: BGRA Controls FX v0.1.3
« Reply #9 on: October 25, 2016, 06:42:32 pm »
As for the native button name i mean that for consistency, keeping  the "Design" suffix, it should be FXNativeDesignButton, i.e.:

FXMaterialDesignButton and FXNativeDesignButton

or

FXMaterialButton and FXNativeButton

lainz

  • Hero Member
  • *****
  • Posts: 2912
    • Home
Re: BGRA Controls FX v0.1.3
« Reply #10 on: October 25, 2016, 06:52:29 pm »
I get it. I get that result in naming because by default the only material design colored control was the button with the ripple effect. The other was a normal button and a normal native button. Then i added the color kind property to use material design colors in both.

circular

  • Hero Member
  • *****
  • Posts: 2782
    • Personal webpage
Re: BGRA Controls FX v0.1.3
« Reply #11 on: October 25, 2016, 07:01:07 pm »
Yeah it is difficult to change a name after its published because people might have started using it. In this case, though it has been there for a few days, so a change could be ok.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 2912
    • Home
Re: BGRA Controls FX v0.1.3
« Reply #12 on: October 25, 2016, 07:11:25 pm »
Done. Now it's FXMaterialButton, FXButton, FXNativeButton and FXContainer.

I found that FXNativeButton doesn't works in Linux, it crashes somewhere and I can't find why.
« Last Edit: October 25, 2016, 07:14:40 pm by lainz »

lainz

  • Hero Member
  • *****
  • Posts: 2912
    • Home
Re: BGRA Controls FX v0.1.5
« Reply #13 on: October 26, 2016, 07:45:48 pm »
There are a lot of releases very often, is that I can't stop finding bugs, hope is because is a really new package  ::)

v0.1.5
* Added FXBaseButton class (Now you can create new buttons easily with this)
* Fixes in buttons (Font, AutoSize..)
* Fixes in shadow for FXMaterialButton
* Using FPGObjectList instead of FPGList to free automatically FXLayers objects

FXNativeButton still keeps crashing under Linux, but I don't have Lazarus + FPC trunk to test, only 1.6 + 3.0

circular

  • Hero Member
  • *****
  • Posts: 2782
    • Personal webpage
Re: BGRA Controls FX v0.1.5
« Reply #14 on: October 27, 2016, 01:27:50 pm »
I guess what matters most is that someone is taking care of the package. :)
Conscience is the debugger of the mind