procedure LogEventCursor(var Line: TString; Ev: PWindowEvent);
begin
  Line := Line + ' cursor.x=' + FloatToStr(Ev.GetCursor.X) +
                 ' cursor.y=' + FloatToStr(Ev.GetCursor.Y);
end;

procedure TWindowEvent.Log(_Eng: Pointer);
var
  Line: TString;
begin
  Line := '';
  if IsKeyDown then begin
    Line := TString('KeyDown') + ' key=' + IntToStr(Key);
  end else if IsKeyUp then begin
    Line := 'KeyUp' + ' key=' + IntToStr(Key);
  end else if IsChar then begin
    Line := 'Char' + ' key=' + IntToStr(Key);
  end else if IsCursorMove then begin
    Line := 'CursorMove';
  end else if IsLeftClickDown then begin
    Line := 'LeftClickDown';
  end else if IsLeftClickUp then begin
    Line := 'LeftClickUp';
  end else if IsRightClickDown then begin
    Line := 'RightClickDown';
  end else if IsRightClickUp then begin
    Line := 'RightClickUp';
  end else if IsMiddleClickDown then begin
    Line := 'MiddleClickDown';
  end else if IsMiddleClickUp then begin
    Line := 'MiddleClickUp';
  end else if IsDoubleLeftClick then begin
    Line := 'DoubleLeftClick';
  end else if IsMouseWheel then begin
    Line := 'MouseWheel' + ' wheel=' + IntToStr(MouseWheel);
  end;
  LogEventCursor(Line, @Self);
  TEngine(_Eng).PrintLogTagged('E', Line);
end;

{$IF Defined(DENG_DEMO_MODE)}
//{{{ TWindowEvent
function TWindowEvent.IsKeyDown: Boolean;
begin
  Result := EvLog.Name = 'KeyDown';
end;

function TWindowEvent.IsKeyDown(_Key: Integer): Boolean;
begin
  // TODO Need to remmap _Key to target platform
  Result := (EvLog.Name = 'KeyDown') and
            (StrToInt(EvLog.Get('key', '0')) = _Key);
end;

function TWindowEvent.IsKeyUp: Boolean;
begin
  Result := EvLog.Name = 'KeyUp';
end;

function TWindowEvent.IsKeyUp(_Key: Integer): Boolean;
begin
  // TODO Need to remmap _Key to target platform
  Result := (EvLog.Name = 'KeyUp') and
            (StrToInt(EvLog.Get('key', '0')) = _Key);
end;

function TWindowEvent.Key: Integer;
begin
  // TODO Need to remmap Key to host platform
  Result := StrToInt(EvLog.Get('key', '0'));
end;

function TWindowEvent.IsChar: Boolean;
begin
  Result := EvLog.Name = 'Char';
end;

function TWindowEvent.IsCursorMove: Boolean;
begin
  Result := EvLog.Name = 'CursorMove';
end;

function TWindowEvent.IsLeftClickDown: Boolean;
begin
  Result := EvLog.Name = 'LeftClickDown';
end;

function TWindowEvent.IsLeftClickUp: Boolean;
begin
  Result := EvLog.Name = 'LeftClickUp';
end;

function TWindowEvent.IsRightClickDown: Boolean;
begin
  Result := EvLog.Name = 'RightClickDown';
end;

function TWindowEvent.IsRightClickUp: Boolean;
begin
  Result := EvLog.Name = 'RightClickUp';
end;

function TWindowEvent.IsMiddleClickDown: Boolean;
begin
  Result := EvLog.Name = 'MiddleClickDown';
end;

function TWindowEvent.IsMiddleClickUp: Boolean;
begin
  Result := EvLog.Name = 'MiddleClickUp';
end;

function TWindowEvent.IsDoubleLeftClick: Boolean;
begin
  Result := EvLog.Name = 'DoubleLeftClick';
end;

function TWindowEvent.GetCursor: TVec2f;
// TODO put all cross-platform code to some generic function like WindowPos...
//var
//  Point: TPoint;
//  Rect: windows.TRect;
begin
  //GetCursorPos(@Point);
  //GetWindowRect(Handle, @Rect);
  //Point.X := Point.X - Rect.Left;
  //Point.Y := Point.Y - Rect.Top;
  Result := Vec2f(StrToFloat(EvLog.Get('cursor.x', '0')),
                  StrToFloat(EvLog.Get('cursor.y', '0')));
end;

function TWindowEvent.IsMouseWheel: Boolean;
begin
  Result := EvLog.Name = 'MouseWheel';
end;

function TWindowEvent.MouseWheel: Integer;
begin
  Result := StrToInt(EvLog.Get('wheel', '0'));
end;
//}}}
{$ENDIF}
