Recent

Author Topic: changing how disabled (tbgra)button are visualized  (Read 14484 times)

lainz

  • Guest
Re: changing how disabled (tbgra)button are visualized
« Reply #15 on: October 17, 2011, 07:20:33 pm »
ok do it in your way.

I would like to do it :) but it tells me << Unit1.pas(2581,20) Error: Identifier not found "FMouseStage" >>

 :-[ :-[

You can't modify TBGRAButton disabled state if you don't modify the ConvertToGrayScale(ABGRA: TBGRABitmap);  procedure. In order to modify the procedure you have two ways:

* Create a new component. (For example creating a TCustomBGRAControl).
* Modify the existing component. (Editing the bgraimagebutton.pas).

If none of those ways are the thing you want you can try to use 'OnAfterPrepareBGRAButton', this allow to modify the bitmap when it needs to be updated (like OnPaint event of a form):

Code: [Select]
procedure TForm1.BGRAButton1AfterPrepareBGRAButton(Sender: TObject;
  const ABGRA: TBGRABitmap; ARect: TRect; AState: TBGRAButtonState);
begin
  if not BGRAButton1.Enabled then
    ABGRA.ApplyGlobalOpacity(100);
end;   

lainz

  • Guest
Re: changing how disabled (tbgra)button are visualized
« Reply #16 on: October 17, 2011, 07:24:26 pm »
Most bgracontrols are like examples of the things you can do with BGRABitmap, if you want some new feature or addapt one to fit with your needs you can improve the code because it's LGPL.

BTW contact Dibo if you really need that state, he is the author of that component.

There is no 'visual settings' for enabled / disabled. Look, for example, the Paint code in BGRAImageButton: if Enabled then... check and draw the current state (that's modified when you move the mouse, clic, etc) else (when it is disabled) draw the disabled state.

this is the solution I am tring to implement...

Code: [Select]
type

Tbgrabutton = class(BGRAButtons.TBGRAButton)
public
  procedure Paint; override;
end;


...


implementation

procedure TBGRAButton.Paint;
var
  bodya, bodyn: TBody;
  baserect: TRect;
begin
  //inherited Paint;
  { Mouse stage }
  case FMouseStage of
    msClicked: bodya := FBodyClicked;
    msHover: bodya := FBodyHover;
    msNormal: bodya := FBodyNormal;
  end;

  { Calculating base rect }
  baserect := ClientRect;
  Inc(baserect.Left, Round(FBorderWidth / 2));
  Inc(baserect.Top, Round(FBorderWidth / 2));
  Dec(baserect.Right, Round(FBorderWidth / 2) + 1);
  Dec(baserect.Bottom, Round(FBorderWidth / 2) + 1);

  { Clearing previous paint }
  FBGRA.Fill(BGRAPixelTransparent);

  { Drawing main button }
  if (FActiveButt = bbtButton) and (not FStaticButton) then
    bodyn := bodya
  else
    bodyn := FBodyNormal;

  DrawBasicBody(bodyn, Rect(baserect.Left, baserect.Top, baserect.Right -
    ifthen(FStyle = bbtDropDown, ARR_SPACE), baserect.Bottom));

  { Drop down arrow button }
  if FStyle = bbtDropDown then
  begin
    if (FActiveButt = bbtDropDown) and (not FStaticButton) then
      bodyn := bodya
    else
      bodyn := FBodyNormal;

    DrawBasicBody(bodyn, Rect(baserect.Right - ARR_SPACE, baserect.Top,
      baserect.Right, baserect.Bottom));
    { Drawing arrow }
    DrawArrow(bodyn, baserect);
  end;

  if FTextApplyGlobalOpacity then
  begin
    { Drawing text }
    DrawText(bodyn.FFont.Color, bodyn.FFont.Style, bodyn.FFont.Name);
    { Set global opacity }
   if Enabled then FBGRA.ApplyGlobalOpacity(FGlobalOpacity) else FBGRA.ApplyGlobalOpacity(100);
end
  else
  begin
    { Set global opacity }
    if Enabled then FBGRA.ApplyGlobalOpacity(FGlobalOpacity) else FBGRA.ApplyGlobalOpacity(100);
{ Drawing text }
    DrawText(bodyn.FFont.Color, bodyn.FFont.Style, bodyn.FFont.Name);
  end;

  { Convert to gray if not enabled }
  if not Enabled then
    ConvertToGrayScale;

  { Finally drawing on canvas }
  FBGRA.Draw(Self.Canvas, 0, 0, False);
end;



but when I try to compile I get the following errors:

Code: [Select]
Unit1.pas(2543,16)
Unit1.pas(2581,20) Error: Identifier not found "FMouseStage"
Unit1.pas(2582,14) Error: Identifier not found "msClicked"
Unit1.pas(2582,14) Error: Constant Expression expected
Unit1.pas(2582,37) Error: Identifier not found "FBodyClicked"
Unit1.pas(2583,12) Error: Identifier not found "msHover"
Unit1.pas(2583,12) Error: Constant Expression expected
Unit1.pas(2583,12) Error: duplicate case label
Unit1.pas(2583,33) Error: Identifier not found "FBodyHover"
Unit1.pas(2584,13) Error: Identifier not found "msNormal"
Unit1.pas(2584,13) Error: Constant Expression expected
Unit1.pas(2584,13) Error: duplicate case label
Unit1.pas(2584,35) Error: Identifier not found "FBodyNormal"
Unit1.pas(2589,41) Error: Identifier not found "FBorderWidth"
Unit1.pas(2589,3) Error: Incompatible types: got "untyped" expected "LongInt"
Unit1.pas(2590,40) Error: Identifier not found "FBorderWidth"
Unit1.pas(2590,3) Error: Incompatible types: got "untyped" expected "LongInt"
Unit1.pas(2591,42) Error: Identifier not found "FBorderWidth"
Unit1.pas(2591,3) Error: Incompatible types: got "untyped" expected "LongInt"
Unit1.pas(2592,43) Error: Identifier not found "FBorderWidth"
Unit1.pas(2592,3) Error: Incompatible types: got "untyped" expected "LongInt"
Unit1.pas(2595,8) Error: Identifier not found "FBGRA"
Unit1.pas(2595,34) Error: Identifier not found "BGRAPixelTransparent"
Unit1.pas(2598,19) Error: Identifier not found "FActiveButt"
Unit1.pas(2598,54) Error: Identifier not found "FStaticButton"
Unit1.pas(2601,25) Error: Identifier not found "FBodyNormal"
Unit1.pas(2603,16) Error: Identifier not found "DrawBasicBody"
Unit1.pas(2604,11) Error: Identifier not found "ifthen"
Unit1.pas(2604,19) Error: Identifier not found "FStyle"
Unit1.pas(2604,43) Error: Identifier not found "ARR_SPACE"
Unit1.pas(2607,13) Error: Identifier not found "FStyle"
Unit1.pas(2609,21) Error: Identifier not found "FActiveButt"
Unit1.pas(2609,58) Error: Identifier not found "FStaticButton"
Unit1.pas(2612,27) Error: Identifier not found "FBodyNormal"
Unit1.pas(2614,18) Error: Identifier not found "DrawBasicBody"
Unit1.pas(2614,57) Error: Identifier not found "ARR_SPACE"
Unit1.pas(2617,14) Error: Identifier not found "DrawArrow"
Unit1.pas(2620,30) Error: Identifier not found "FTextApplyGlobalOpacity"
Unit1.pas(2623,20) Error: identifier idents no member "FFont"
Unit1.pas(2623,39) Error: identifier idents no member "FFont"
Unit1.pas(2623,58) Error: identifier idents no member "FFont"
Unit1.pas(2625,26) Error: Identifier not found "FBGRA"
Unit1.pas(2625,60) Error: Identifier not found "FGlobalOpacity"
Unit1.pas(2625,72) Error: Identifier not found "FBGRA"
Unit1.pas(2630,26) Error: Identifier not found "FBGRA"
Unit1.pas(2630,60) Error: Identifier not found "FGlobalOpacity"
Unit1.pas(2630,72) Error: Identifier not found "FBGRA"
Unit1.pas(2632,20) Error: identifier idents no member "FFont"
Unit1.pas(2632,39) Error: identifier idents no member "FFont"
Unit1.pas(2632,58) Error: identifier idents no member "FFont"
Unit1.pas(2637,23) Error: Identifier not found "ConvertToGrayScale"
Unit1.pas(2637,23) Fatal: There were 50 errors compiling module, stopping

That's because you can't override in this way..

Code: [Select]
Tbgrabutton = class(BGRAButtons.TBGRAButton)
public
  procedure Paint; override;
end;

You CAN do in this way

Code: [Select]
Tcustombgrabutton = class(TBGRAButton)
public
  procedure Paint; override;
end;

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: changing how disabled (tbgra)button are visualized
« Reply #17 on: October 17, 2011, 09:12:33 pm »
That's because you can't override in this way..

Code: [Select]
Tbgrabutton = class(BGRAButtons.TBGRAButton)
public
  procedure Paint; override;
end;


since I already do
Code: [Select]
Tlabel = class(StdCtrls.TLabel)
public
  FromTop: integer; {distance from top}
  FCHeight: integer; {font client height}
  procedure Paint; override;
end;                 


in my code and it works...

could you please explain me the difference?

lainz

  • Guest
Re: changing how disabled (tbgra)button are visualized
« Reply #18 on: October 17, 2011, 09:40:31 pm »
could you please explain me the difference?

The difference is that the inherited declarations can't be accesed, try this code (it should not work):

Code: [Select]
Tlabel = class(StdCtrls.TLabel)
public
  FromTop: integer; {distance from top}
  FCHeight: integer; {font client height}
  procedure Paint; override;
end;

implementation

procedure Tlabel.Paint;
begin
// this works
  FromTop := 1;

// this not
  case FAlignment of
    taLeftJustify: Caption := 'Left';
    taRightJustify: Caption := 'Right';
    taCenter: Caption := 'Center';
  end;
  inherited Paint;
end; 

 

TinyPortal © 2005-2018