home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / tpascal / hotmap / edit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-27  |  3.7 KB  |  148 lines

  1. unit Edit;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, VBXCtrl, Hotmap;
  8.  
  9. type
  10.   TEditForm = class(TForm)
  11.     Memo1: TMemo;
  12.     HotMap1: THotMap;
  13.     GroupBox1: TGroupBox;
  14.     GroupBox2: TGroupBox;
  15.     ListBox1: TListBox;
  16.     Edit1: TEdit;
  17.     Edit2: TEdit;
  18.     Label1: TLabel;
  19.     Button1: TButton;
  20.     Button2: TButton;
  21.     Button3: TButton;
  22.     Button4: TButton;
  23.     Edit3: TEdit;
  24.     Edit4: TEdit;
  25.     procedure UpdateList(Sender: TObject);
  26.     procedure FormCreate(Sender: TObject);
  27.     procedure FormShow(Sender: TObject);
  28.     procedure FormResize(Sender: TObject);
  29.     procedure Button1Click(Sender: TObject);
  30.     procedure Button2Click(Sender: TObject);
  31.     procedure Button3Click(Sender: TObject);
  32.     procedure Button4Click(Sender: TObject);
  33.     procedure ListBox1Click(Sender: TObject);
  34.     procedure HotMap1RegionMouseDown(Sender: TObject;
  35.       var RegionNum: Single; var Button: Integer);
  36.  
  37.   private
  38.      OffsetX: Integer;
  39.      OffsetY: Integer;
  40.     { Private declarations }
  41.   public
  42.     { Public declarations }
  43.   end;
  44.  
  45. var
  46.   EditForm: TEditForm;
  47.  
  48. implementation
  49.  
  50. {$R *.DFM}
  51.  
  52. procedure TEditForm.FormCreate(Sender: TObject);
  53. begin
  54.     HotMap1.FillType := 3;
  55.     Memo1.Text :=  'This form demonstrates DataFile and BmpName properties. You can read, save ';
  56.     Memo1.Text := Memo1.Text + 'and edit regions in run time. You can load any bitmap. The ''Open File'' ';
  57.     Memo1.Text := Memo1.Text + 'dialogs build-in into control. You can assocciate any text with any region.';
  58.  
  59. end;
  60.  
  61. procedure TEditForm.UpdateList(Sender: TObject);
  62.     var n: Integer;
  63. begin
  64.     ListBox1.Clear;
  65.  
  66.        For n := 0 To (HotMap1.NumOfRgns - 1) Do
  67.            ListBox1.Items.Add(HotMap1.RegionString[n]);
  68. end;
  69.  
  70. procedure TEditForm.FormShow(Sender: TObject);
  71. begin
  72.        OffsetX := (self.Width - HotMap1.Width);
  73.     OffsetY := (self.Height - HotMap1.Height);
  74. end;
  75.  
  76. procedure TEditForm.FormResize(Sender: TObject);
  77. begin
  78.     If self.WindowState <> wsMinimized Then
  79.         {Do not let user to make to small picture, to avoid loosing scaling}
  80.         If ((self.Width - OffsetX) > 50) And ((self.Height - OffsetY) > 50) Then
  81.         begin
  82.             HotMap1.Width := self.Width - OffsetX;
  83.             HotMap1.Height := self.Height - OffsetY;
  84.     end;
  85. end;
  86.  
  87. procedure TEditForm.Button1Click(Sender: TObject);
  88. begin
  89.     HotMap1.Action := 6;
  90.     If HotMap1.DataFile <> '' Then
  91.     begin
  92.         HotMap1.Action := 4;
  93.         HotMap1.CurrentRgn := 0;
  94.         Edit3.Text := HotMap1.DataFile;
  95.         Edit4.Text := HotMap1.BmpName;
  96.     end;
  97.  
  98.     UpdateList(Self);
  99. end;
  100.  
  101. procedure TEditForm.Button2Click(Sender: TObject);
  102. begin
  103.     HotMap1.DataFile := Edit3.Text;
  104.     HotMap1.Action := 3;
  105. end;
  106.  
  107. procedure TEditForm.Button3Click(Sender: TObject);
  108. begin
  109.     HotMap1.Action := 7;
  110.     UpdateList(Self);
  111. end;
  112.  
  113. procedure TEditForm.Button4Click(Sender: TObject);
  114. begin
  115.     HotMap1.Action := 5;
  116.     Edit4.Text := HotMap1.BmpName
  117. end;
  118.  
  119. procedure TEditForm.ListBox1Click(Sender: TObject);
  120.     var n:    Integer;
  121. begin
  122.     For n := 0 To (HotMap1.NumOfRgns - 1) Do
  123.     begin
  124.       If ListBox1.Items[ListBox1.ItemIndex] = HotMap1.RegionString[n] Then
  125.       begin
  126.         HotMap1.CurrentRgn := (n + 1);
  127.         HotMap1.Action := 1;
  128.         Exit;
  129.       end;
  130.     end;
  131. end;
  132.  
  133. procedure TEditForm.HotMap1RegionMouseDown(Sender: TObject;
  134.   var RegionNum: Single; var Button: Integer);
  135.   var Rn:    Integer;
  136. begin
  137.     Rn := Round(RegionNum);
  138.     Edit1.Text := IntToStr(Rn);
  139.     Case Rn of
  140.         0:
  141.             Edit2.Text := '';
  142.         else
  143.             Edit2.Text := HotMap1.RegionString[Rn - 1];
  144.     end;
  145. end;
  146.  
  147. end.
  148.