Changeset 14 for trunk/Components/ButtonBase.pas
- Timestamp:
- Jan 7, 2017, 8:54:23 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/ButtonBase.pas
r10 r14 10 10 constructor Create(aOwner: TComponent); override; 11 11 protected 12 FDown, FPermanent: boolean;12 FDown, FPermanent: boolean; 13 13 FGraphic: TBitmap; 14 //FDownSound, FUpSound: string;14 // FDownSound, FUpSound: string; 15 15 ClickProc: TNotifyEvent; 16 16 DownChangedProc: TNotifyEvent; 17 17 procedure SetDown(x: boolean); 18 //procedure PlayDownSound;19 //procedure PlayUpSound;18 // procedure PlayDownSound; 19 // procedure PlayUpSound; 20 20 procedure MouseDown(Button: TMouseButton; Shift: TShiftState; 21 21 x, y: integer); override; … … 27 27 public 28 28 property Graphic: TBitmap read FGraphic write FGraphic; 29 //property DownSound: string read FDownSound write FDownSound;30 //property UpSound: string read FUpSound write FUpSound;29 // property DownSound: string read FDownSound write FDownSound; 30 // property UpSound: string read FUpSound write FUpSound; 31 31 published 32 32 property Visible; … … 34 34 property Permanent: boolean read FPermanent write FPermanent; 35 35 property OnClick: TNotifyEvent read ClickProc write ClickProc; 36 property OnDownChanged: TNotifyEvent read DownChangedProc write DownChangedProc; 36 property OnDownChanged: TNotifyEvent read DownChangedProc 37 write DownChangedProc; 37 38 end; 38 39 39 40 implementation 40 41 41 // uses42 // 42 // uses 43 // MMSystem; 43 44 44 constructor TButtonBase.Create( AOwner: TComponent);45 constructor TButtonBase.Create(aOwner: TComponent); 45 46 begin 46 47 inherited; 47 //FDownSound:=''; 48 //FUpSound:=''; 49 FGraphic:=nil; Active:=false; FDown:=false; FPermanent:=false; 50 ClickProc:=nil; 48 // FDownSound:=''; 49 // FUpSound:=''; 50 FGraphic := nil; 51 Active := false; 52 FDown := false; 53 FPermanent := false; 54 ClickProc := nil; 51 55 end; 52 56 53 57 procedure TButtonBase.MouseDown(Button: TMouseButton; Shift: TShiftState; 54 58 x, y: integer); 55 59 begin 56 Active :=true;57 MouseMove(Shift, x,y)60 Active := true; 61 MouseMove(Shift, x, y) 58 62 end; 59 63 60 64 procedure TButtonBase.MouseUp(Button: TMouseButton; Shift: TShiftState; 61 65 x, y: integer); 62 66 begin 63 if ssLeft in Shift then exit; 64 MouseMove(Shift,x,y); 67 if ssLeft in Shift then 68 exit; 69 MouseMove(Shift, x, y); 65 70 if Active and FDown then 66 71 begin 67 //PlayUpSound;68 Active:=false;69 if FDown<>FPermanent then72 // PlayUpSound; 73 Active := false; 74 if FDown <> FPermanent then 70 75 begin 71 FDown:=FPermanent; 72 Invalidate; 73 if @DownChangedProc<>nil then DownChangedProc(self); 76 FDown := FPermanent; 77 Invalidate; 78 if @DownChangedProc <> nil then 79 DownChangedProc(self); 74 80 end; 75 if (Button=mbLeft) and (@ClickProc<>nil) then ClickProc(self) 81 if (Button = mbLeft) and (@ClickProc <> nil) then 82 ClickProc(self) 76 83 end 77 else84 else 78 85 begin 79 //if FDown then PlayUpSound;80 Active:=false;81 if FDown then86 // if FDown then PlayUpSound; 87 Active := false; 88 if FDown then 82 89 begin 83 FDown:=false; 84 Invalidate; 85 if @DownChangedProc<>nil then DownChangedProc(self); 90 FDown := false; 91 Invalidate; 92 if @DownChangedProc <> nil then 93 DownChangedProc(self); 86 94 end; 87 95 end … … 90 98 procedure TButtonBase.MouseMove(Shift: TShiftState; x, y: integer); 91 99 begin 92 if Active then 93 if (x>=0) and (x<Width) and (y>=0) and (y<Height) then 94 if (ssLeft in Shift) and not FDown then 95 begin 96 {PlayDownSound;} 97 FDown:=true; 98 Paint; 99 if @DownChangedProc<>nil then DownChangedProc(self); 100 end 101 else else if FDown and not FPermanent then 102 begin 103 {PlayUpSound;} 104 FDown:=false; 105 Paint; 106 if @DownChangedProc<>nil then DownChangedProc(self); 107 end 100 if Active then 101 if (x >= 0) and (x < Width) and (y >= 0) and (y < Height) then 102 if (ssLeft in Shift) and not FDown then 103 begin 104 { PlayDownSound; } 105 FDown := true; 106 Paint; 107 if @DownChangedProc <> nil then 108 DownChangedProc(self); 109 end 110 else 111 else if FDown and not FPermanent then 112 begin 113 { PlayUpSound; } 114 FDown := false; 115 Paint; 116 if @DownChangedProc <> nil then 117 DownChangedProc(self); 118 end 108 119 end; 109 120 110 121 procedure TButtonBase.SetDown(x: boolean); 111 122 begin 112 FDown:=x;113 Invalidate123 FDown := x; 124 Invalidate 114 125 end; 115 126 116 // procedure TButtonBase.PlayDownSound;117 // begin118 // if DownSound<>'' then SndPlaySound(pchar(DownSound),SND_ASYNC)119 // end;127 // procedure TButtonBase.PlayDownSound; 128 // begin 129 // if DownSound<>'' then SndPlaySound(pchar(DownSound),SND_ASYNC) 130 // end; 120 131 121 // procedure TButtonBase.PlayUpSound;122 // begin123 // if UpSound<>'' then SndPlaySound(pchar(UpSound),SND_ASYNC)124 // end;132 // procedure TButtonBase.PlayUpSound; 133 // begin 134 // if UpSound<>'' then SndPlaySound(pchar(UpSound),SND_ASYNC) 135 // end; 125 136 126 137 end. 127
Note:
See TracChangeset
for help on using the changeset viewer.