STESZK

Top  Previous  Next

 

{ StellaMAP komponens készlet:

 

TStEszTar:

----------

Rajzmód beállítás = Semmi, Nagyitó, Centralizáló, Keret, Orkereszt,

Textkenyszer, Terület  gombokkal

Property Position      : Vizszintes vagy függőleges megjelenítés

property VisibleButtons: A látható gombok halmaza

}

 

unit Steszk;

 

{$R-}

 

interface

uses

SysUtils, WinTypes, WinProcs, Messages, Classes, Buttons,

Graphics, Controls, Forms, Dialogs, ExtCtrls, StMap16w, StMap16, Almtype;

 

 

Type

TPosition = (poHorizontal,poVertical);

TEszkozButtons = (esNincs,esNagyito,esCentrum,esKeret,esOrkereszt,

                  esTextkenyszer,esTerulet);

TVisibleButtons = set of TEszkozButtons;

TButtonClickEvent = procedure(Sender: TObject; Button: TEszkozButtons;

                  MouseButton : TMouseButton; Shift: TShiftState) of object;

 

TEszkButton = class(TSpeedButton)

private

  FIndex: TEszkozButtons;

protected

  procedure MouseDown(Button: TMouseButton; Shift: TShiftState;

    X, Y: Integer); override;

  procedure ButtonMouseDown(Sender: TObject; Button: TMouseButton;

    Shift: TShiftState);

public

  property Index : TEszkozButtons read FIndex write FIndex;

  property Margin;

end;

 

TStEszTar = class(TCustomPanel)

private

  FStellaMap       : TStMapW;

  FEszkozBottons   : TEszkozButtons;

  FVisibleButtons  : TVisibleButtons;

  FButtonSize      : integer;

  FPosition        : TPosition;

  FOnButtonClick   : TButtonClickEvent;

  procedure SetPosition(Value:TPosition);

  procedure SetButtonSize(Value:integer);

  procedure SetStellaMap(Value:TStMapW);

  procedure SetVisibleButtons(Value:TVisibleButtons);

protected

  FButtons : array[TEszkozButtons] of TEszkButton;

  procedure Resize; override;

  procedure Notification(AComponent: TComponent;

    Operation: TOperation); override;

public

  constructor Create(AOwner:TComponent);override;

  destructor Destroy;override;

published

  Property StellaMapSource : TStMapW read FStellaMap write SetStellaMap ;

  Property Position : TPosition read FPosition write SetPosition ;

  property ButtonSize: integer read FButtonSize write SetButtonSize

            default 24;

  property VisibleButtons: TVisibleButtons read FVisibleButtons

           write SetVisibleButtons

           default [esNincs,esNagyito,esCentrum,esKeret,esOrkereszt,

                  esTextkenyszer,esTerulet];

  Property OnButtonClick: TButtonClickEvent read FOnButtonClick write FOnButtonClick;

  property ShowHint;

end;

 

Var

StLButtons: TStEszTar;

stm: TStMapW;

 

implementation

 

{$R STESZK}

 

Const

BtnTypeName : array[TEszkozButtons] of PChar = ('NINCS', 'NAGYITO', 'CENTRUM',

  'KERET', 'ORKERESZT', 'TERULET', 'TEXTKENYSZER');

HintsName : array[TEszkozButtons] of PChar = ('Nincs', 'Nagyító', 'Centrum',

  'Ablak', 'Őrkereszt', 'Terület', 'TEXTKényszer');

 

constructor TStEszTar.Create(AOwner:TComponent);

var i: TEszkozButtons;

  j: integer;

  ResName: array[0..40] of Char;

begin

   inherited Create(AOwner);

   j:=0;

   For i:=Low(FButtons) to High(FButtons) do begin

       FButtons[i]:=TEszkButton.Create(Self);

       FButtons[i].Index:= i;

       FButtons[i].Caption := '';

       FButtons[i].Enabled := False;

       FButtons[i].GroupIndex := 1;

       FButtons[i].AllowAllUp := True;

{         FButtons[i].OnMouseDown := ButtonMouseDown;}

       FButtons[i].Glyph.Handle := LoadBitmap(HInstance,

           StrFmt(ResName, '%s', [BtnTypeName[I]]));

       FButtons[i].NumGlyphs := 1;

       FButtons[i].Hint := strpas(HintsName[i]);

       FButtons[i].Parent:=Self;

       Inc(j);

   end;

   VisibleButtons :=[esNincs,esNagyito,esCentrum,esKeret,esOrkereszt,

                     esTextkenyszer,esTerulet];

   Position:=poHorizontal;

   ButtonSize:=24;

end;

 

destructor TStEszTar.Destroy;

var i: TEszkozButtons;

begin

   For i:=Low(FButtons) to High(FButtons) do FButtons[i].Free;

   inherited Destroy;

end;

 

procedure TStEszTar.SetStellaMap(Value:TStMapW);

var i: TEszkozButtons;

begin

If Value<>FStellaMap then begin

   FStellaMap:=Value;

   stm:=StellaMapSource;

   For i:=Low(FButtons) to High(FButtons) do

       FButtons[i].Enabled := Value<>nil;

       Case stm.Rajzmod of

       rmNincs   : FButtons[esNincs].Down:=True;

       rmNagyito : FButtons[esNagyito].Down:=True;

       rmCentrum : FButtons[esCentrum].Down:=True;

       rmAblak   : FButtons[esKeret].Down:=True;

       rmTer     : FButtons[esTerulet].Down:=True;

       end;

       FButtons[esOrkereszt].Down:=stm.Orkereszt;

       FButtons[esTextkenyszer].Down:=stm.Textkenyszer;

   Resize;

end;

end;

 

procedure TStEszTar.Resize;

var bw,bh: integer;   {ButtonWidth/height}

  i: TEszkozButtons;

  Count,x : integer;  {Látható gombok száma}

begin

 if (csLoading in ComponentState) then Exit;

 Count := 0;

 For i:=Low(FButtons) to High(FButtons) do

     If FButtons[i].Visible then Inc(Count);

 If Count=0 then Count:=1;

 Case Position of

 poHorizontal: begin

               Width := Count*buttonsize+2*BevelWidth;

               Height := buttonsize+2*BevelWidth;

               bw := Width - 2 * BevelWidth;

               bh := Height - 2 * BevelWidth;

               bw := bw div count;

               x := BevelWidth;

               For i:=Low(FButtons) to High(FButtons) do

                 If FButtons[i].Visible then begin

                   FButtons[i].SetBounds(x,BevelWidth,bw,bh);

                   Inc(X, BW);

                 end;

               end;

 poVertical  : begin

               Height := Count*buttonsize+2*BevelWidth;

               Width := buttonsize+2*BevelWidth;

               bw := Width - 2 * BevelWidth;

               bh := Height - 2 * BevelWidth;

               bh := bh div Count;

               x := BevelWidth;

               For i:=Low(FButtons) to High(FButtons) do

                 If FButtons[i].Visible then begin

                   FButtons[i].SetBounds(BevelWidth,x,bw,bh);

                   Inc(X, Bh);

                 end;

               end;

 end;

 Inherited Resize;

end;

 

procedure TStEszTar.SetPosition(Value:TPosition);

begin

If FPosition <> Value then begin

   FPosition := Value;

   Resize;

   Invalidate;

end;

end;

 

procedure TStEszTar.SetButtonSize(Value:integer);

begin

FButtonSize := Value;

Invalidate;

Resize;

end;

 

procedure TEszkButton.MouseDown(Button: TMouseButton; Shift: TShiftState;

    X, Y: Integer);

begin

 ButtonMouseDown(Self,Button,Shift);

 inherited MouseDown(Button, Shift, X, Y);

end;

 

procedure TEszkButton.ButtonMouseDown(Sender: TObject; Button: TMouseButton;

    Shift: TShiftState);

var i: TEszkozButtons;

begin

 i:=(Sender as TEszkButton).Index;

 If stm<>nil then begin

    Case Ord(i) of

    0: stm.Rajzmod:=rmNincs;

    1: stm.Rajzmod:=rmNagyito;

    2: stm.Rajzmod:=rmCentrum;

    3: stm.Rajzmod:=rmAblak;

    4: stm.Orkereszt:=not (Sender as TEszkButton).Down;

    5: stm.Rajzmod:=rmTer;

    6: stm.Textkenyszer:=not (Sender as TEszkButton).Down;

    end;

 end;

 If Assigned((Parent as TStEszTar).FOnButtonClick) then

    (Parent as TStEszTar).FOnButtonClick(Self,i,Button,Shift);

end;

 

procedure TStEszTar.SetVisibleButtons(Value:TVisibleButtons);

var i: TEszkozButtons;

begin

If FVisibleButtons<>Value then begin

   FVisibleButtons:=Value;

   For i:=Low(FButtons) to High(FButtons) do

       FButtons[i].Visible :=  I in FVisibleButtons;

   Resize;

end;

end;

 

procedure TStEszTar.Notification(AComponent: TComponent;

Operation: TOperation);

begin

inherited Notification(AComponent, Operation);

if (Operation = opRemove) and (AComponent = StellaMapSource)

then StellaMapSource := nil;

end;

 

end.