本文整理汇总了C#中MouseState.IsButtonDown方法的典型用法代码示例。如果您正苦于以下问题:C# MouseState.IsButtonDown方法的具体用法?C# MouseState.IsButtonDown怎么用?C# MouseState.IsButtonDown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MouseState
的用法示例。
在下文中一共展示了MouseState.IsButtonDown方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetermineMouseDownAction
/// <summary>
/// Decide which tool action is suitable for the current mouse state.
/// </summary>
private Action DetermineMouseDownAction(IDiagramPresenter diagramPresenter, MouseState mouseState)
{
if (mouseState.IsButtonDown(MouseButtonsDg.Left) || mouseState.IsButtonDown(MouseButtonsDg.Right)) {
// if left or right buttons are down, start a 'select' action. This will refine to an
// appropriate drag action later on (when mouse moving) based on the mouse button, otherwise
// it will (de)select the shape on mouseup
return Action.Select;
}
// Ignore other pressed mouse buttons
return CurrentAction;
}
示例2: DetermineMouseMoveAction
/// <summary>
/// Decide which tool action is suitable for the current mouse state.
/// </summary>
private Action DetermineMouseMoveAction(IDiagramPresenter diagramPresenter, MouseState mouseState,
ShapeAtCursorInfo shapeAtCursorInfo)
{
switch (CurrentAction) {
case Action.None:
case Action.MoveHandle:
case Action.MoveShape:
case Action.SelectWithFrame:
case Action.ConnectShapes:
// Do not change the current action
return CurrentAction;
case Action.Select:
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
// if we're doing something with the left mouse button, it will be a 'drag' style action
if (!IsDragActionFeasible(mouseState)) {
return CurrentAction;
}
// Check if cursor is over a control point and moving grips is feasible
if (selectedShapeAtCursorInfo.IsCursorAtGrip) {
if (IsMoveHandleFeasible(diagramPresenter, mouseState, selectedShapeAtCursorInfo))
return Action.MoveHandle;
else
return Action.SelectWithFrame;
}
else {
// If there is no shape under the cursor, start a SelectWithFrame action,
// otherwise start a MoveShape action
bool canMove = false;
if (!selectedShapeAtCursorInfo.IsEmpty) {
// If there are selected shapes, check these shapes...
canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, selectedShapeAtCursorInfo);
}
else {
// ... otherwise check the shape under the cursor as it will be selected
// before starting a move action
canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, shapeAtCursorInfo);
}
return canMove ? Action.MoveShape : Action.SelectWithFrame;
}
}
else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) {
if (IsConnectFromShapeFeasible(diagramPresenter, mouseState, shapeAtCursorInfo)) {
return Action.ConnectShapes;
}
}
return CurrentAction;
default:
throw new NShapeUnsupportedValueException(CurrentAction);
}
}
示例3: ProcessMouseClick
private bool ProcessMouseClick(IDiagramPresenter diagramPresenter, MouseState mouseState) {
Debug.Print("ProcessMouseClick");
bool result = false;
switch (CurrentAction) {
case Action.None:
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
if (diagramPresenter.SelectedShapes.Count > 0)
diagramPresenter.UnselectAll();
ShapeAtCursorInfo targetShapeInfo = FindShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, ControlPointCapabilities.Glue, diagramPresenter.ZoomedGripSize, false);
if (IsExtendLineFeasible(CurrentAction, targetShapeInfo.Shape, targetShapeInfo.ControlPointId)) {
if (diagramPresenter.Project.SecurityManager.IsGranted(Permission.Layout, targetShapeInfo.Shape)) {
ExtendLine(diagramPresenter, mouseState, targetShapeInfo);
result = true;
}
} else {
// If no other ToolAction is in Progress (e.g. drawing a line or moving a point),
// a normal MouseClick starts a new line in Point-By-Point mode
if (diagramPresenter.Project.SecurityManager.IsGranted(Permission.Insert, Template.Shape)) {
CreateLine(diagramPresenter, mouseState);
result = true;
}
}
} else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) {
Cancel();
result = true;
}
break;
case Action.CreateLine:
case Action.ExtendLine:
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
Invalidate(ActionDiagramPresenter);
bool doFinishLine = false;
// If the line has reached the MaxVertexCount limit, create it
if (PreviewLinearShape.VertexCount >= PreviewLinearShape.MaxVertexCount)
doFinishLine = true;
else {
// Check if it has to be connected to a shape or connection point
ShapeAtCursorInfo shapeAtCursorInfo = base.FindShapeAtCursor(ActionDiagramPresenter, mouseState.X, mouseState.Y, ControlPointCapabilities.Connect, diagramPresenter.ZoomedGripSize, false);
if (!shapeAtCursorInfo.IsEmpty && !shapeAtCursorInfo.IsCursorAtGluePoint)
doFinishLine = true;
else AddNewPoint(ActionDiagramPresenter, mouseState);
}
// Create line if necessary
if (doFinishLine) {
if (CurrentAction == Action.CreateLine)
FinishLine(ActionDiagramPresenter, mouseState, false);
else FinishExtendLine(ActionDiagramPresenter, mouseState, false);
while (IsToolActionPending)
EndToolAction();
OnToolExecuted(ExecutedEventArgs);
}
} else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) {
#if DEBUG_DIAGNOSTICS
Assert(PreviewShape != null);
#endif
// When creating a line, the new line has to have more than the minimum number of
// vertices because the last vertex (sticking to the mouse cursor) will not be created.
if (CurrentAction == Action.CreateLine) {
if (PreviewLinearShape.VertexCount <= PreviewLinearShape.MinVertexCount)
Cancel();
else FinishLine(ActionDiagramPresenter, mouseState, true);
} else {
// When extending a line, the new line has to have more than the minimum number of
// vertices and more than the original line because the last vertex will not be created.
if (PreviewLinearShape.VertexCount <= PreviewLinearShape.MinVertexCount
|| PreviewLinearShape.VertexCount - 1 == modifiedLinearShape.VertexCount)
Cancel();
else FinishExtendLine(ActionDiagramPresenter, mouseState, true);
}
while (IsToolActionPending)
EndToolAction();
OnToolExecuted(ExecutedEventArgs);
}
result = true;
break;
default: throw new NShapeUnsupportedValueException(CurrentAction);
}
Invalidate(diagramPresenter);
return result;
}
示例4: ProcessMouseUp
private bool ProcessMouseUp(IDiagramPresenter diagramPresenter, MouseState mouseState)
{
bool result = false;
if (!selectedShapeAtCursorInfo.IsEmpty &&
!diagramPresenter.SelectedShapes.Contains(selectedShapeAtCursorInfo.Shape))
selectedShapeAtCursorInfo.Clear();
switch (CurrentAction) {
case Action.None:
// do nothing
break;
case Action.Select:
// Perform selection, but only if it was with the left mouse button. If it was right mouse, ignore it. (Select is only
// initiated on right mouse earlier (in ProcessMouseDown) to allow it to 'refine' into other drag actions. If it's
// still a select by MouseUp, then we can ignore it.)
if (!mouseState.IsButtonDown(MouseButtonsDg.Right)) {
ShapeAtCursorInfo shapeAtCursorInfo = FindShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y,
ControlPointCapabilities.None, 0, false);
result = PerformSelection(ActionDiagramPresenter, mouseState, shapeAtCursorInfo);
SetSelectedShapeAtCursor(ActionDiagramPresenter, mouseState.X, mouseState.Y, ActionDiagramPresenter.ZoomedGripSize,
ControlPointCapabilities.All);
}
EndToolAction();
break;
case Action.SelectWithFrame:
// select all selectedShapes within the frame
result = PerformFrameSelection(ActionDiagramPresenter, mouseState);
while (IsToolActionPending)
EndToolAction();
break;
case Action.MoveHandle:
result = PerformMoveHandle(ActionDiagramPresenter);
while (IsToolActionPending)
EndToolAction();
break;
case Action.MoveShape:
result = PerformMoveShape(ActionDiagramPresenter);
while (IsToolActionPending)
EndToolAction();
break;
case Action.ConnectShapes:
result = FinishConnection(ActionDiagramPresenter);
while (IsToolActionPending)
EndToolAction();
break;
default:
throw new NShapeUnsupportedValueException(CurrentAction);
}
SetSelectedShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, diagramPresenter.ZoomedGripSize,
ControlPointCapabilities.All);
diagramPresenter.SetCursor(DetermineCursor(diagramPresenter, mouseState));
OnToolExecuted(ExecutedEventArgs);
return result;
}
示例5: IsDragActionFeasible
private bool IsDragActionFeasible(MouseState mouseState, MouseButtonsDg button) {
int dx = 0, dy = 0;
if (mouseState.IsButtonDown(button) && IsToolActionPending) {
// Check the minimum drag distance before switching to a drag action
dx = Math.Abs(mouseState.X - ActionStartMouseState.X);
dy = Math.Abs(mouseState.Y - ActionStartMouseState.Y);
}
return (dx >= MinimumDragDistance.Width || dy >= MinimumDragDistance.Height);
}
示例6: DetermineMouseMoveAction
/// <summary>
/// Decide which tool action is suitable for the current mouse state.
/// </summary>
private Action DetermineMouseMoveAction(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo) {
switch (CurrentAction) {
case Action.None:
case Action.MoveHandle:
case Action.MoveShape:
case Action.SelectWithFrame:
// Do not change the current action
return CurrentAction;
case Action.Select:
case Action.EditCaption:
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
// Check if cursor is over a control point and moving grips or rotating is feasible
if (SelectedShapeAtCursorInfo.IsCursorAtGrip) {
if (IsMoveHandleFeasible(diagramPresenter, SelectedShapeAtCursorInfo))
return Action.MoveHandle;
else if (IsRotatatingFeasible(diagramPresenter, SelectedShapeAtCursorInfo))
return Action.PrepareRotate;
else return Action.SelectWithFrame;
} else {
// If there is no shape under the cursor, start a SelectWithFrame action,
// otherwise start a MoveShape action
bool canMove = false;
if (!SelectedShapeAtCursorInfo.IsEmpty) {
// If there are selected shapes, check these shapes...
canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, SelectedShapeAtCursorInfo);
} else {
// ... otherwise check the shape under the cursor as it will be selected
// before starting a move action
canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, shapeAtCursorInfo);
}
if (canMove)
return Action.MoveShape;
else return Action.SelectWithFrame;
}
}
return CurrentAction;
case Action.PrepareRotate:
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
// If the mouse has left the min rotate range, start 'real' rotating
if (IsMinRotateRangeExceeded(diagramPresenter, mouseState))
return Action.Rotate;
else return CurrentAction;
} else return CurrentAction;
case Action.Rotate:
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
// If the mouse has entered the min rotate range, start showing rotating hint
if (!IsMinRotateRangeExceeded(diagramPresenter, mouseState))
return Action.PrepareRotate;
else return CurrentAction;
} else return CurrentAction;
default: throw new NShapeUnsupportedValueException(CurrentAction);
}
}
示例7: DetermineMouseDownAction
/// <summary>
/// Decide which tool action is suitable for the current mouse state.
/// </summary>
private Action DetermineMouseDownAction(IDiagramPresenter diagramPresenter, MouseState mouseState) {
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
if (!SelectedShapeAtCursorInfo.IsEmpty
&& IsEditCaptionFeasible(diagramPresenter, mouseState, SelectedShapeAtCursorInfo)) {
// If the cursor is not over a caption of a selected shape when clicking left mouse button,
// we assume the user wants to select something
// Same thing if no other action is granted.
return Action.EditCaption;
} else {
// Moving shapes and handles is initiated as soon as the user starts drag action (move mouse
// while mouse button is pressed)
// If the user does not start a drag action, this will result in (un)selecting shapes.
return Action.Select;
}
} else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) {
// Abort current action when clicking right mouse button
return Action.None;
} else {
// Ignore other pressed mouse buttons
return CurrentAction;
}
}
示例8: ProcessMouseMove
private bool ProcessMouseMove(IDiagramPresenter diagramPresenter, MouseState mouseState) {
bool result = true;
if (!SelectedShapeAtCursorInfo.IsEmpty &&
!diagramPresenter.SelectedShapes.Contains(SelectedShapeAtCursorInfo.Shape))
SelectedShapeAtCursorInfo.Clear();
Action newAction;
switch (CurrentAction) {
case Action.None:
result = false;
SetSelectedShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, diagramPresenter.ZoomedGripSize, ControlPointCapabilities.All);
Invalidate(diagramPresenter);
break;
case Action.Select:
case Action.EditCaption:
// Find unselected shape under the mouse cursor
ShapeAtCursorInfo shapeAtCursorInfo = ShapeAtCursorInfo.Empty;
newAction = CurrentAction;
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
if (IsDragActionFeasible(mouseState, MouseButtonsDg.Left)) {
// Determine new drag action
shapeAtCursorInfo = FindShapeAtCursor(ActionDiagramPresenter, ActionStartMouseState.X, ActionStartMouseState.Y, ControlPointCapabilities.None, 0, true);
newAction = DetermineMouseMoveAction(ActionDiagramPresenter, ActionStartMouseState, shapeAtCursorInfo);
}
} else newAction = DetermineMouseMoveAction(ActionDiagramPresenter, ActionStartMouseState, shapeAtCursorInfo);
// If the action has changed, prepare and start the new action
if (newAction != CurrentAction) {
switch (newAction) {
// Select --> SelectWithFrame
case Action.SelectWithFrame:
#if DEBUG_DIAGNOSTICS
Assert(CurrentAction == Action.Select);
#endif
StartToolAction(diagramPresenter, (int)newAction, ActionStartMouseState, true);
PrepareSelectionFrame(ActionDiagramPresenter, ActionStartMouseState);
break;
// Select --> (Select shape and) move shape
case Action.MoveShape:
case Action.MoveHandle:
case Action.PrepareRotate:
#if DEBUG_DIAGNOSTICS
Assert(CurrentAction == Action.Select || CurrentAction == Action.EditCaption);
#endif
if (SelectedShapeAtCursorInfo.IsEmpty) {
// Select shape at cursor before start dragging it
PerformSelection(ActionDiagramPresenter, ActionStartMouseState, shapeAtCursorInfo);
SetSelectedShapeAtCursor(diagramPresenter, ActionStartMouseState.X, ActionStartMouseState.Y, 0, ControlPointCapabilities.None);
#if DEBUG_DIAGNOSTICS
Assert(!SelectedShapeAtCursorInfo.IsEmpty);
#endif
}
// Init moving shape
#if DEBUG_DIAGNOSTICS
Assert(!SelectedShapeAtCursorInfo.IsEmpty);
#endif
CreatePreviewShapes(ActionDiagramPresenter);
StartToolAction(diagramPresenter, (int)newAction, ActionStartMouseState, true);
PrepareMoveShapePreview(ActionDiagramPresenter, ActionStartMouseState);
break;
// Select --> (Select shape and) rotate shape / edit shape caption
case Action.Rotate:
case Action.EditCaption:
case Action.None:
case Action.Select:
Debug.Fail("Unhandled change of CurrentAction.");
break;
default:
Debug.Fail(string.Format("Unexpected {0} value: {1}", CurrentAction.GetType().Name, CurrentAction));
break;
}
//currentToolAction = newAction;
}
Invalidate(ActionDiagramPresenter);
break;
case Action.SelectWithFrame:
PrepareSelectionFrame(ActionDiagramPresenter, mouseState);
break;
case Action.MoveHandle:
#if DEBUG_DIAGNOSTICS
Assert(IsMoveHandleFeasible(ActionDiagramPresenter, SelectedShapeAtCursorInfo));
#endif
PrepareMoveHandlePreview(ActionDiagramPresenter, mouseState);
break;
case Action.MoveShape:
PrepareMoveShapePreview(diagramPresenter, mouseState);
break;
case Action.PrepareRotate:
case Action.Rotate:
#if DEBUG_DIAGNOSTICS
Assert(IsRotatatingFeasible(ActionDiagramPresenter, SelectedShapeAtCursorInfo));
#endif
//.........这里部分代码省略.........
示例9: Update
public void Update()
{
state = OpenTK.Input.Mouse.GetState();
if(HWUpdate)
{
var p = gameWindow.PointToClient(new System.Drawing.Point(state.X, state.Y));
if(!lastHWUpdate)
{
var lastx = x;
var lasty = y;
offsetx = x - p.X;
offsety = y - p.Y;
}
x = p.X + offsetx;
y = p.Y + offsety;
}
else
{
x = gameWindow.Mouse.X;
y = gameWindow.Mouse.Y;
}
lastHWUpdate = HWUpdate;
var wheelValue = state.WheelPrecise;
wheel = state.WheelPrecise;
for(int i = 0; i < allButtons.Length; i++)
{
MouseButton button = allButtons[i];
if (state.IsButtonDown(button))
{
MouseDown(button);
}
else if(downButtons[button])
{
MouseUp(button);
}
}
}