STJKVIEW

Top  Previous  Next

unit StJkview;

 

interface

 

uses SysUtils, WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,

StdCtrls, Spin, Grids, ExtCtrls, AlmType, Stmap16;

 

type

{

TJelkulcsHeader = record

jkkod  : longint;

jkcim  : longint;

jkdb   : byte;

jknev  : string[20];

end;

 

TJelkulcsRecord = record

kod    : word;

x1,y1  : integer;

x2,y2  : integer;

szin   : TColor;

vastag : byte;

end;

}

TJKWiewForm = class(TForm)

  OKBtn: TBitBtn;

  Bevel1: TBevel;

  Label1: TLabel;

  Label2: TLabel;

  DrawGrid1: TStringGrid;

  procedure FormActivate(Sender: TObject);

  procedure DrawGrid1DrawCell(Sender: TObject; Col, Row: Longint;

    Rect: TRect; State: TGridDrawState);

  procedure DrawGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,

    Y: Integer);

  procedure DrawGrid1SelectCell(Sender: TObject; Col, Row: Longint;

    var CanSelect: Boolean);

private

public

end;

 

TStJelkulcsView = class(TComponent)

private

  FStellaMap    : TStellaMap;

  FJelkulcsFile: string;

  procedure SetJelkulcsFile(Value:string);

protected

  procedure Notification(AComponent: TComponent;

    Operation: TOperation); override;

public

  constructor Create(AOwner:TComponent);override;

  destructor Destroy;override;

  Function Execute(fn:string):longint;

published

  property StellaMapSource: TStellaMap read FStellaMap write FStellaMap;

  property JelkulcsFile: string read FJelkulcsFile write SetJelkulcsFile;

end;

 

var

JKWiewForm: TJKWiewForm;

stm: TStellaMap;

aktjelkulcs:Longint;

 

procedure Register;

 

implementation

 

{$R *.DFM}

 

procedure Register;

begin

   RegisterComponents('AL',[TStJelkulcsView]);

end;

 

Function TStJelkulcsView.Execute(fn:string):longint;

var i: integer;

begin

Try

Result:=-1;

If StellaMapSource<>nil then begin

   stm := StellaMapSource;

   fn:=stm.jelkulcsfile;

end else begin

   stm := TStellaMap.Create(Self);

end;

  Jelkulcsfile:=fn;

  JKWiewForm:=TJKWiewForm.Create(Self);

  JKWiewForm.ShowModal;

  Result:=aktjelkulcs;

finally

JKWiewForm.Free;

end;

end;

 

constructor TStJelkulcsView.Create(AOwner:TComponent);

begin

inherited Create(AOwner);

end;

 

destructor TStJelkulcsView.Destroy;

begin

inherited Destroy;

end;

 

procedure TStJelkulcsView.SetJelkulcsFile(Value:string);

begin

If FJelkulcsfile<>Value then begin

  If FileExists(Value) then begin

     stm.Jelkulcsfile:=Value;

     FJelkulcsfile:=Value;

  end;

end;

end;

 

procedure TStJelkulcsView.Notification(AComponent: TComponent;

Operation: TOperation);

begin

inherited Notification(AComponent, Operation);

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

then StellaMapSource := nil;

end;

 

procedure TJKWiewForm.FormActivate(Sender: TObject);

var

  fx,fy,i,ii,jj: integer; {a kis kép középpontja}

  x1,y1,x2,y2: integer;

  szorzo: single;

  cr: TRect;

begin

With DrawGrid1 do begin

   RowCount:=200;

   colcount:=6;

   For i:=0 to 199 do begin

      RowHeights[i]:=DefaultColWidth;

   end;

   Update;

end;

end;

 

procedure TJKWiewForm.DrawGrid1DrawCell(Sender: TObject; Col, Row: Longint;

Rect: TRect; State: TGridDrawState);

var fx,fy,i,ii,j: integer; {a kis kép középpontja}

  x1,y1,x2,y2: integer;

  szorzo: single;

  ro,co: longint;

  cr: TRect;

begin

ro:=Row; co:=col;

With DrawGrid1 do begin

   szorzo:=DefaultColWidth/256;

   fx:=DefaultColWidth div 2;

   fy:=DefaultColWidth div 2;

      stm.JelkulcsStream.Seek((6*Ro+co)*SizeOf(jelkHeader),0);

      stm.JelkulcsStream.Read(jelkHeader,SizeOf(jelkHeader));

      Label1.Caption:=jelkHeader.jknev;

      Label2.Caption:=IntToStr(jelkHeader.jkkod);

      stm.JelkulcsStream.Seek(jelkHeader.jkcim,0);

      cr:=Rect;

      Canvas.Brush.Color:=clWhite;

      Canvas.Brush.Style:=bsSolid;

      Canvas.FillRect(cr);

      Canvas.TextOut(cr.left+2,cr.top+2,jelkHeader.jknev);

      For ii:=1 to jelkHeader.jkdb do begin

          stm.JelkulcsStream.Read(jelkDATA,SizeOf(jelkDATA));

          With jelkDATA do begin

          x1:=Trunc(szorzo*jelkDATA.x1);

          y1:=Trunc(szorzo*jelkDATA.y1);

          x2:=Trunc(szorzo*jelkDATA.x2);

          y2:=Trunc(szorzo*jelkDATA.y2);

          end;

      Canvas.pen.color:=jelkDATA.szin;

      Canvas.pen.width:=2*jelkDATA.vastag;

      Case jelkDATA.kod of

      1: Canvas.Pixels[cr.left+fx+jelkDATA.x1,cr.top+fy+jelkDATA.y1]:=jelkDATA.szin;

      2: begin

         Canvas.MoveTo(cr.left+fx+jelkDATA.x1,cr.top+fy+jelkDATA.y1);

         Canvas.LineTo(cr.left+fx+jelkDATA.x2,cr.top+fy+jelkDATA.y2);

         end;

      3: Canvas.Ellipse(cr.left+fx+jelkDATA.x1,cr.top+fy+jelkDATA.y1,

         cr.left+fx+jelkDATA.x2,cr.top+fy+jelkDATA.y2);

      end;

   end;

end;

end;

 

procedure TJKWiewForm.DrawGrid1MouseMove(Sender: TObject;

Shift: TShiftState; X, Y: Integer);

var co,ro: Longint;

begin

   DrawGrid1.MouseToCell(x,y,co,ro);

   stm.JelkulcsStream.Seek((6*Ro+co)*SizeOf(jelkHeader),0);

   stm.JelkulcsStream.Read(jelkHeader,SizeOf(jelkHeader));

   Label1.Caption:=jelkHeader.jknev;

   Label2.Caption:=IntToStr(jelkHeader.jkkod);

end;

 

procedure TJKWiewForm.DrawGrid1SelectCell(Sender: TObject; Col,

Row: Longint; var CanSelect: Boolean);

begin

aktjelkulcs:= StrToInt(Label2.Caption);

end;

 

end.