STLGOMB

Top  Previous  Next

{StellaMap komponens család

 

TStLButtons:

------------

TStellaMAP térkép rajzelemek láthatóságát érzékelő és beállító gombsorozat

}

 

unit Stlgomb;

 

interface

uses

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

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

 

 

Type

TPosition = (poHorizontal,poVertical);

 

TStLButtons = class(TPanel)

private

  FStellaMap       : TStMapW;

  FButtons         : array[1..4] of TSpeedButton;

  FPosition        : TPosition;

  procedure SetPosition(Value:TPosition);

  procedure SeTStMapW(Value:TStMapW);

protected

  ora : TTimer;

  procedure Resize; override;

  procedure Timer(Sender:TObject);

  procedure Notification(AComponent: TComponent;

    Operation: TOperation); override;

public

  constructor Create(AOwner:TComponent);override;

  destructor Destroy;override;

  procedure Click(Sender:TObject);

published

  Property StellaMapSource : TStMapW read FStellaMap write SeTStMapW ;

  Property Position : TPosition read FPosition write SetPosition ;

end;

 

Var

StLButtons: TStLButtons;

i: integer;

szam: array[1..4] of longint;

lathato : array[1..4] of boolean;  {Rajzelemek láthatósága}

 

implementation

 

Const

HintsName : array[1..4] of string = ('Pont', 'Vonal', 'Felirat','Jelkulcs');

 

constructor TStLButtons.Create(AOwner:TComponent);

const felirat: string[4] = 'PVFJ';

begin

   inherited Create(AOwner);

   FStellaMap:=nil;

   For i:=1 to 4 do begin

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

       FButtons[i].Parent:=Self;

       FButtons[i].Name := 'BUT'+IntToStr(i);

       FButtons[i].Caption := felirat[i];

       FButtons[i].Enabled := False;

       FButtons[i].GroupIndex := -1;

       FButtons[i].AllowAllUp := True;

       FButtons[i].Tag := i;

       FButtons[i].OnClick := Click;

       FButtons[i].Hint := HintsName[i];

   end;

   Width := 64;

   Height := 16;

   Font.Name := 'Courier New'; Font.Size:=8;

   Position:=poHorizontal;

   ora := TTimer.Create(Self);

   ora.OnTimer := Timer;

   ora.Interval:=100;

end;

 

destructor TStLButtons.Destroy;

begin

   ora.Free;

   inherited Destroy;

end;

 

procedure TStLButtons.Timer;

var i:integer;

begin

try

Caption := '';

For i:=1 to 4 do

    If StellaMapSource<>nil then begin

       FButtons[i].Down:=TVisibleRajzelem(i-1) in StellaMapSource.Latszik;

    end else FButtons[i].Down:=False;

except

ora.OnTimer := nil;

StellaMapSource:=nil;

end;

end;

 

procedure TStLButtons.Resize;

begin

 Position:=FPosition;

 Inherited Resize;

end;

 

procedure TStLButtons.SeTStMapW(Value:TStMapW);

var i:integer;

begin

   FStellaMap:=Value;

   ora.OnTimer := Timer;

   For i:=1 to 4 do FButtons[i].Enabled:=Value<>nil;

   Resize;

end;

 

procedure TStLButtons.SetPosition(Value:TPosition);

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

begin

If Fposition<>Value then

begin

  k:=Height; Height:=Width; Width:=k;

end;

FPosition := Value;

bw := Width - 2 * BevelWidth;

bh := Height - 2 * BevelWidth;

Case Value of

poHorizontal:

begin

   bw := bw div 4;

   For i:=1 to 4 do FButtons[i].SetBounds((i-1)*bw+BevelWidth,BevelWidth,bw,bh);

end;

poVertical  :

begin

   bh := bh div 4;

   For i:=1 to 4 do FButtons[i].SetBounds(BevelWidth,(i-1)*bh+BevelWidth,bw,bh);

end;

end;

end;

 

procedure TStLButtons.Click(Sender:TObject);

var lat: TVisibleRajzelem;

begin

 If StellaMapSource<>nil then begin

    tag := (Sender as TSpeedButton).Tag;

    lat := TVisibleRajzelem(Tag-1);

    If (Sender as TSpeedButton).Down then

         StellaMapSource.Latszik := FStellaMap.Latszik+[lat]

    else StellaMapSource.Latszik := StellaMapSource.Latszik-[lat];

 end;

end;

 

procedure TStLButtons.Notification(AComponent: TComponent;

Operation: TOperation);

begin

inherited Notification(AComponent, Operation);

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

then

    StellaMapSource := nil;

end;

 

end.