Browse CVS Repository
Contents of /gikonavigoeson/gikonavi/Gesture.pas
Parent Directory
| Revision Log
| Revision Graph
Revision 1.10 -
( show annotations)
( download)
( as text)
Mon Feb 11 13:46:13 2008 UTC
(16 years, 1 month ago)
by h677
Branch: MAIN
CVS Tags: v1_59_0_771, v1_59_0_770, v1_59_0_773, v1_59_0_772, v1_59_0_775, v1_59_0_774, v1_59_0_777, v1_59_0_776, v1_59_0_778, v1_63_1_819, v1_62_0_812, v1_59_1_765, v1_60_0_788, v1_60_0_789, v1_58_0_748, v1_58_0_745, v1_60_0_781, v1_60_0_782, v1_58_0_746, v1_60_0_784, v1_60_0_786, v1_60_0_787, v1_59_0_767, v1_59_1_778, v1_59_0_768, v1_59_0_769, v1_57_1_744, v1_58_0_752, v1_58_0_750, v1_58_0_751, v1_58_0_756, v1_58_0_757, v1_58_0_754, v1_58_0_755, v1_58_0_759, v1_61_0_796, v1_61_0_797, v1_61_0_795, v1_61_0_798, v1_61_0_799, v1_63_0_818, v1_63_0_817, v1_63_0_816, v1_63_0_815, v1_62_0_805, v1_62_0_804, v1_62_0_807, v1_62_0_806, v1_62_0_803, v1_62_0_802, v1_62_0_809, v1_60_0_780, v1_60_0_779, v1_62_0_810, v1_62_0_811, v1_58_0_747, v1_60_0_783, v1_59_2_785, v1_60_1_793, v1_58_0_763, v1_58_0_762, v1_58_0_761, v1_58_0_760, v1_62_1_813, v1_57_2_749, v1_57_0_742, v1_57_0_743, v1_57_0_740, v1_57_0_741, v1_57_0_744, v1_61_0_800, v1_60_0_793, v1_60_0_792, v1_60_0_791, v1_60_0_790, v1_60_2_794, v1_61_1_801, HEAD
Branch point for: Bb57, Bb62, Bb63, Bb60, Bb61, Bb59, Bb58
Changes since 1.9: +1 -1 lines
File MIME type: text/x-pascal
Hookの変数が、符号付整数だったので、符号無し整数に変更した。
| 1 |
unit Gesture; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 |
Dialogs, Math, StrUtils; |
| 8 |
|
| 9 |
type |
| 10 |
TMouseGesture = class(TObject) |
| 11 |
private |
| 12 |
FHook: Cardinal; |
| 13 |
FHandle: THandle; |
| 14 |
FGestureItemList: TStringList; |
| 15 |
FBeginGesture: Boolean; |
| 16 |
FCancelMode: Boolean; |
| 17 |
FLastTime: Cardinal; |
| 18 |
FStartPoint: TPoint; |
| 19 |
FLastPoint: TPoint; |
| 20 |
FMargin: Integer; |
| 21 |
FOnGestureStart: TNotifyEvent; |
| 22 |
FOnGestureMove: TNotifyEvent; |
| 23 |
FOnGestureEnd: TNotifyEvent; |
| 24 |
function GetGestureCount: Integer; |
| 25 |
function CheckAction(Message: Integer; x, y: Integer): Boolean; |
| 26 |
procedure AddAction(sx, sy: Integer); |
| 27 |
function AddGesture(Item: string): Integer; |
| 28 |
function Get(Index: integer): string; |
| 29 |
procedure Put(Index: integer; Item: string); |
| 30 |
public |
| 31 |
constructor Create; |
| 32 |
destructor Destroy; override; |
| 33 |
procedure SetHook(hWnd: THandle); |
| 34 |
procedure UnHook; |
| 35 |
property Items[Index: Integer]: string read Get write Put; default; |
| 36 |
property GestureCount: Integer read GetGestureCount; |
| 37 |
property Margin: Integer read FMargin write FMargin; |
| 38 |
function GetGestureStr: string; |
| 39 |
procedure Clear; |
| 40 |
property OnGestureStart: TNotifyEvent read FOnGestureStart write FOnGestureStart; |
| 41 |
property OnGestureMove: TNotifyEvent read FOnGestureMove write FOnGestureMove; |
| 42 |
property OnGestureEnd: TNotifyEvent read FOnGestureEnd write FOnGestureEnd; |
| 43 |
end; |
| 44 |
|
| 45 |
function GestureProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; |
| 46 |
|
| 47 |
var |
| 48 |
MouseGesture: TMouseGesture; |
| 49 |
|
| 50 |
implementation |
| 51 |
|
| 52 |
uses |
| 53 |
GikoSystem; |
| 54 |
|
| 55 |
constructor TMouseGesture.Create; |
| 56 |
begin |
| 57 |
inherited; |
| 58 |
FHook := 0; |
| 59 |
FCancelMode := False; |
| 60 |
FBeginGesture := False; |
| 61 |
FMargin := 15; |
| 62 |
FGestureItemList := TStringList.Create; |
| 63 |
end; |
| 64 |
|
| 65 |
destructor TMouseGesture.Destroy; |
| 66 |
begin |
| 67 |
UnHook; |
| 68 |
Clear; |
| 69 |
FGestureItemList.Free; |
| 70 |
inherited; |
| 71 |
end; |
| 72 |
|
| 73 |
//鐃?鐃?鐃?鐃?鐃?鐃? |
| 74 |
procedure TMouseGesture.SetHook(hWnd: THandle); |
| 75 |
begin |
| 76 |
if FHook <> 0 then |
| 77 |
Exit; |
| 78 |
FHandle := hWnd; |
| 79 |
UnHook; |
| 80 |
FHook := SetWindowsHookEx(WH_MOUSE, @GestureProc, 0{HInstance}, GetCurrentThreadId); |
| 81 |
end; |
| 82 |
|
| 83 |
//鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申 |
| 84 |
procedure TMouseGesture.UnHook; |
| 85 |
begin |
| 86 |
if FHook = 0 then |
| 87 |
Exit; |
| 88 |
UnhookWindowsHookEx(FHook); |
| 89 |
FHook := 0; |
| 90 |
end; |
| 91 |
|
| 92 |
//鐃?鐃?鐃?鐃?鐃緒申鐃?鐃?鐃緒申 |
| 93 |
function GestureProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; |
| 94 |
var |
| 95 |
mhs: PMouseHookStruct; |
| 96 |
begin |
| 97 |
if nCode = HC_ACTION then begin |
| 98 |
mhs := PMouseHookStruct(lParam); |
| 99 |
if MouseGesture.CheckAction(wParam, mhs^.pt.X, mhs^.pt.Y) then begin |
| 100 |
Result := 1; |
| 101 |
Exit; |
| 102 |
end; |
| 103 |
end; |
| 104 |
Result := CallNextHookEx(MouseGesture.FHook, nCode, wParam, lParam); |
| 105 |
end; |
| 106 |
|
| 107 |
function TMouseGesture.CheckAction(Message: Integer; x, y: Integer): Boolean; |
| 108 |
var |
| 109 |
dp: TPoint; |
| 110 |
sp: TPoint; |
| 111 |
hwnd: THandle; |
| 112 |
begin |
| 113 |
Result := False; |
| 114 |
case Message of |
| 115 |
WM_MOUSEMOVE: begin |
| 116 |
if FBeginGesture then begin |
| 117 |
//鐃緒申鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 118 |
hwnd := GetCapture; |
| 119 |
//鐃?鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申 |
| 120 |
if (hwnd <> 0) and (hwnd <> FHandle) then begin |
| 121 |
ReleaseCapture; |
| 122 |
SetCapture(FHandle); |
| 123 |
end; |
| 124 |
dp := Point(x - FLastPoint.X, y - FLastPoint.Y); |
| 125 |
sp := Point(Sign(dp.X), Sign(dp.Y)); |
| 126 |
if (dp.X * dp.X + dp.Y * dp.Y) > (FMargin * FMargin) then begin |
| 127 |
dp := Point(Abs(dp.X), Abs(dp.Y)); |
| 128 |
if dp.X > dp.Y div 3 then |
| 129 |
sp.Y := 0; |
| 130 |
if dp.Y > dp.X div 3 then |
| 131 |
sp.X := 0; |
| 132 |
AddAction(sp.X, sp.Y); |
| 133 |
FLastTime := GetTickCount; |
| 134 |
FLastPoint := Point(x, y); |
| 135 |
end; |
| 136 |
Result := True; |
| 137 |
end; |
| 138 |
end; |
| 139 |
WM_RBUTTONDOWN: begin |
| 140 |
if (not FCancelMode) then begin |
| 141 |
if ( GikoSys.Setting.GestureIgnoreContext ) then begin |
| 142 |
//鐃緒申鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 143 |
hwnd := GetCapture; |
| 144 |
//鐃?鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申 |
| 145 |
if (hwnd <> 0) and (hwnd <> FHandle) then begin |
| 146 |
Exit; |
| 147 |
end; |
| 148 |
end; |
| 149 |
FBeginGesture := True; |
| 150 |
FLastTime := 0; |
| 151 |
FLastPoint := Point(x, y); |
| 152 |
FStartPoint := Point(x, y); |
| 153 |
Result := True; |
| 154 |
SetCapture(FHandle); |
| 155 |
end; |
| 156 |
end; |
| 157 |
WM_RBUTTONUP: begin |
| 158 |
if FCancelMode then |
| 159 |
FCancelMode := False |
| 160 |
else if (FBeginGesture) then begin |
| 161 |
FBeginGesture := False; |
| 162 |
ReleaseCapture; |
| 163 |
if FGestureItemList.Count <> 0 then begin |
| 164 |
if Assigned(FOnGestureEnd) then begin |
| 165 |
FOnGestureEnd(Self); |
| 166 |
end else begin |
| 167 |
Clear; |
| 168 |
end; |
| 169 |
end else begin |
| 170 |
FCancelMode := True; |
| 171 |
//鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?DOWN,UP鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃? |
| 172 |
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_RIGHTDOWN, FStartPoint.X, FStartPoint.Y, 0, 0); |
| 173 |
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_RIGHTUP, x, y, 0, 0); |
| 174 |
end; |
| 175 |
end; |
| 176 |
end; |
| 177 |
end; |
| 178 |
end; |
| 179 |
|
| 180 |
//鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 181 |
procedure TMouseGesture.AddAction(sx, sy: Integer); |
| 182 |
var |
| 183 |
Direction: string; |
| 184 |
begin |
| 185 |
Direction := ''; |
| 186 |
if (sx > 0) and (sy = 0) then |
| 187 |
Direction := '鐃緒申' |
| 188 |
else if (sx < 0) and (sy = 0) then |
| 189 |
Direction := '鐃緒申' |
| 190 |
else if sy > 0 then |
| 191 |
Direction := '鐃緒申' |
| 192 |
else if sy < 0 then |
| 193 |
Direction := '鐃緒申' |
| 194 |
else |
| 195 |
Exit; |
| 196 |
if FGestureItemList.Count > 0 then begin |
| 197 |
if Items[FGestureItemList.Count - 1] = Direction then |
| 198 |
Exit; |
| 199 |
end else begin |
| 200 |
//鐃?鐃?鐃?鐃?鐃緒申鐃?鐃?鐃? |
| 201 |
if Assigned(FOnGestureStart) then |
| 202 |
FOnGestureStart(Self); |
| 203 |
end; |
| 204 |
AddGesture(Direction); |
| 205 |
if Assigned(FOnGestureMove) then |
| 206 |
FOnGestureMove(Self); |
| 207 |
end; |
| 208 |
|
| 209 |
//鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 210 |
function TMouseGesture.AddGesture(Item: string): Integer; |
| 211 |
begin |
| 212 |
Result := FGestureItemList.Add(Item); |
| 213 |
end; |
| 214 |
|
| 215 |
//鐃?鐃緒申鐃緒申鐃緒申鐃緒申index鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 216 |
function TMouseGesture.Get(Index: Integer): string; |
| 217 |
begin |
| 218 |
Result := FGestureItemList[Index]; |
| 219 |
end; |
| 220 |
|
| 221 |
//鐃?鐃緒申鐃緒申鐃緒申鐃緒申index鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 222 |
procedure TMouseGesture.Put(Index: Integer; Item: string); |
| 223 |
begin |
| 224 |
FGestureItemList[Index] := Item; |
| 225 |
end; |
| 226 |
|
| 227 |
//鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 228 |
function TMouseGesture.GetGestureStr: string; |
| 229 |
var |
| 230 |
i: Integer; |
| 231 |
begin |
| 232 |
Result := ''; |
| 233 |
for i := 0 to FGestureItemList.Count - 1 do |
| 234 |
Result := Result + Items[i]; |
| 235 |
end; |
| 236 |
|
| 237 |
//鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 238 |
function TMouseGesture.GetGestureCount: Integer; |
| 239 |
begin |
| 240 |
Result := FGestureItemList.Count; |
| 241 |
end; |
| 242 |
|
| 243 |
//鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申 |
| 244 |
procedure TMouseGesture.Clear; |
| 245 |
begin |
| 246 |
FGestureItemList.Clear; |
| 247 |
end; |
| 248 |
|
| 249 |
end. |
| |