public static void SetCursorFromVector3(Vector2 currentPosition, Vector2 lastPosition) { Vector3 delta = currentPosition - lastPosition; float angle = Mathf.Rad2Deg * Mathf.Atan2(delta.y, delta.x); while (angle < 0) { angle += 180; } while (angle > 180) { angle -= 180; } if (angle >= 67.5f && angle < 112.5f) { activeCursor = MouseCursor.ResizeVertical; } else if (angle >= 112.5f && angle < 157.5f) { activeCursor = MouseCursor.ResizeUpLeft; } else if (angle >= 22.5f && angle < 67.5f) { activeCursor = MouseCursor.ResizeUpRight; } else { activeCursor = MouseCursor.ResizeHorizontal; } }
public DisplayProvider() { this.mouseCursor = new MouseCursor(); this.screenshot = new Screenshot(); this.tracker = new BoundsTracker(); this.waterMark = new WaterMark(); }
public ControlTransformer(Service service) { uiMouseCursor = new MouseCursor(service) { UpdatePriority = Priority.First }; isTransforming = false; Messenger.Default.Register<string>(this, "SetDefaultCursor", SetDefaultCursor); Messenger.Default.Register<string>(this, "AllowChangeOfCursor", AllowChangeOfCursor); canChangeCursor = false; }
public void Start() { cur_mode = iMode.MODE_IDENTIFY; scr_mouse = GameObject.Find("Main Camera").GetComponent<MouseCursor>(); UpdateCursor(); }
public static CursorChangeToken ChangeCursor(this IView view, MouseCursor cursor) { Verify.Argument.IsNotNull(view, "view"); var oldCursor = view.MouseCursor; view.MouseCursor = cursor; return new CursorChangeToken(view, oldCursor); }
private static Vector2 ScaleSlider(int id, Vector2 pos, MouseCursor cursor, Rect cursorRect) { Vector2 vector2_1 = (Vector2) Handles.matrix.MultiplyPoint((Vector3) pos); Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (current.button == 0 && cursorRect.Contains(Event.current.mousePosition) && !current.alt) { int num = id; GUIUtility.keyboardControl = num; GUIUtility.hotControl = num; SpriteEditorHandles.s_CurrentMousePosition = current.mousePosition; SpriteEditorHandles.s_DragStartScreenPosition = current.mousePosition; SpriteEditorHandles.s_DragScreenOffset = SpriteEditorHandles.s_CurrentMousePosition - vector2_1; current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); break; } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) { GUIUtility.hotControl = 0; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); break; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { SpriteEditorHandles.s_CurrentMousePosition += current.delta; Vector2 vector2_2 = pos; pos = (Vector2) Handles.s_InverseMatrix.MultiplyPoint((Vector3) SpriteEditorHandles.s_CurrentMousePosition); if (!Mathf.Approximately((vector2_2 - pos).magnitude, 0.0f)) GUI.changed = true; current.Use(); break; } break; case EventType.KeyDown: if (GUIUtility.hotControl == id && current.keyCode == KeyCode.Escape) { pos = (Vector2) Handles.s_InverseMatrix.MultiplyPoint((Vector3) (SpriteEditorHandles.s_DragStartScreenPosition - SpriteEditorHandles.s_DragScreenOffset)); GUIUtility.hotControl = 0; GUI.changed = true; current.Use(); break; } break; case EventType.Repaint: EditorGUIUtility.AddCursorRect(cursorRect, cursor, id); break; } return pos; }
public static void CustomActionField(Rect fieldRect, Action action, bool showCursorPredicate, bool clickPredicate, MouseCursor cursor) { if (showCursorPredicate) AddCursorRect(fieldRect, cursor); if (fieldRect.Contains(Event.current.mousePosition)) { if (clickPredicate) action(); } }
public CursorHighlightOptions() { InitializeComponent(); // this.mouseCursor = new MouseCursor(); // this.tbRadious.Minimum = minRadious; this.tbRadious.Maximum = maxRadious; this.Color = Color.FromName(defaultColorString); this.Radious = defaultRadious; }
internal static Vector2 PointSlider(Vector2 pos, MouseCursor cursor, GUIStyle dragDot, GUIStyle dragDotActive) { int controlId = GUIUtility.GetControlID("Slider1D".GetHashCode(), FocusType.Keyboard); Vector2 vector2 = (Vector2) Handles.matrix.MultiplyPoint((Vector3) pos); Rect rect = new Rect(vector2.x - dragDot.fixedWidth * 0.5f, vector2.y - dragDot.fixedHeight * 0.5f, dragDot.fixedWidth, dragDot.fixedHeight); if (Event.current.GetTypeForControl(controlId) == EventType.Repaint) { if (GUIUtility.hotControl == controlId) dragDotActive.Draw(rect, GUIContent.none, controlId); else dragDot.Draw(rect, GUIContent.none, controlId); } return SpriteEditorHandles.ScaleSlider(pos, cursor, rect); }
/// <summary> /// Creates a <see cref="MouseCursor"/> based on the specified image /// </summary> /// <param name="cursorUri">The <see cref="Uri"/> of the image</param> /// <returns>A <see cref="MouseCursor"/></returns> public static MouseCursor FromUri(Uri cursorUri) { Stream bitmapStream; Bitmap bitmap; OpenTK.MouseCursor cursorObject; MouseCursor cursor; bitmapStream = Application.GetResourceStream(cursorUri); bitmap = new Bitmap(bitmapStream); var data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, 32, 32), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); cursorObject = new OpenTK.MouseCursor(0,0,32, 32, data.Scan0); bitmap.UnlockBits(data); cursor = new MouseCursor(cursorObject); return cursor; }
public MoveMouseCursorToNearbyCell(MouseInput mouse, MouseCursor cursor) { this.mouse = mouse; this.cursor = cursor; }
public bool ProcessEvent(Event e) { if (e.rawType == EventType.MouseUp) { IsDragging = false; } if (e.rawType == EventType.MouseDown || e.rawType == EventType.MouseUp || e.rawType == EventType.MouseMove) { Vector2 mPos = Utils.GetMousePosition(); if (mPos.x > transform.position.x && mPos.y > transform.position.y && mPos.x < transform.position.x + 176 && mPos.y < transform.position.y + 158) { mPos -= new Vector2(transform.position.x, transform.position.y); // check cursor specifically int mapLeft = 8; int mapTop = 8; float sW = MapLogic.Instance.Width - 16; float sH = MapLogic.Instance.Height - 16; float aspect = sW / sH; float w = 128; float h = 128; // handle uneven map sizes if (sW > sH) { h /= aspect; } else if (sH > sW) { w *= aspect; } float cX = 90 - w / 2; float cY = 83 - h / 2; float cXCur = 90 - 64; float cYCur = 83 - 64; RectInt vrec = MapView.Instance.UnpaddedVisibleRect; vrec.x -= mapLeft; vrec.y -= mapTop; MouseCursor.SetCursor(MouseCursor.CurDefault); if (mPos.x >= cXCur && mPos.x < cXCur + 128 && mPos.y >= cYCur && mPos.y < cYCur + 128) { MouseCursor.SetCursor(MouseCursor.CurSmallDefault); if (e.rawType == EventType.MouseDown) { IsDragging = true; } if (IsDragging) { // find map coordinates from cursor float offsX = Mathf.Round((mPos.x - cX) / w * sW + 8 - vrec.width / 2); float offsY = Mathf.Round((mPos.y - cY) / h * sH + 8 - vrec.height / 2); MapView.Instance.SetScroll((int)offsX, (int)offsY); } } return(true); } } return(false); }
public void Cursor(Rect rect, MouseCursor mouse) { EditorGUIUtility.AddCursorRect(rect, mouse); }
public MainWindow() { InitializeComponent(); Instance = this; #region Init Timer DTimer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, (s, e) => { Seconds++; if (Seconds == 60) { Seconds = 0; Minutes++; } // If Capture Duration is set if (Duration > 0 && (Minutes * 60 + Seconds >= Duration)) { StopRecording(); SystemSounds.Exclamation.Play(); // SystemTray Notification if (SystemTray.Visible) { SystemTray.ShowBalloonTip(3000, "Capture Completed", string.Format("Capture Completed in {0} seconds", OtherSettings.CaptureDuration), System.Windows.Forms.ToolTipIcon.None); } } TimeManager.Content = string.Format("{0:D2}:{1:D2}", Minutes, Seconds); }, TimeManager.Dispatcher) { IsEnabled = false }; #endregion //Populate Available Codecs, Audio and Video Sources ComboBoxes Refresh(); #region Command Bindings CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, (s, e) => { var dlg = new FolderBrowserDialog() { SelectedPath = OutPath.Text, Title = "Select Output Folder" }; if (dlg.ShowDialog().Value) { OutPath.Text = dlg.SelectedPath; Settings.Default.OutputPath = dlg.SelectedPath; Settings.Default.Save(); } })); CommandBindings.Add(new CommandBinding(ApplicationCommands.New, (s, e) => StartRecording(), (s, e) => e.CanExecute = ReadyToRecord)); CommandBindings.Add(new CommandBinding(ApplicationCommands.Stop, (s, e) => StopRecording(), (s, e) => e.CanExecute = !ReadyToRecord)); CommandBindings.Add(new CommandBinding(NavigationCommands.Refresh, (s, e) => Refresh())); CommandBindings.Add(new CommandBinding(PauseCommand, (s, e) => { Recorder.Pause(); DTimer.Stop(); PauseButton.Command = ResumeCommand; RotationEffect.Angle = 90; Status.Content = "Paused"; PauseButton.ToolTip = "Pause"; }, (s, e) => e.CanExecute = !ReadyToRecord && Recorder != null)); CommandBindings.Add(new CommandBinding(ResumeCommand, (s, e) => { Recorder.Start(); DTimer.Start(); PauseButton.Command = PauseCommand; RotationEffect.Angle = 0; Status.Content = "Recording..."; PauseButton.ToolTip = "Resume"; }, (s, e) => e.CanExecute = !ReadyToRecord && Recorder != null)); #endregion #region SystemTray SystemTray = new NotifyIcon() { Visible = false, Text = "Captura", Icon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location) }; SystemTray.Click += (s, e) => { SystemTray.Visible = false; Show(); WindowState = WindowState.Normal; }; StateChanged += (s, e) => { if (WindowState == WindowState.Minimized && OtherSettings.MinimizeToSysTray) { Hide(); SystemTray.Visible = true; } }; #endregion #region KeyHook KeyHook = new KeyboardHookList(this); KeyHook.Register(KeyCode.R, ModifierKeyCodes.Control | ModifierKeyCodes.Shift | ModifierKeyCodes.Alt, () => Dispatcher.Invoke(() => ToggleRecorderState())); KeyHook.Register(KeyCode.S, ModifierKeyCodes.Control | ModifierKeyCodes.Shift | ModifierKeyCodes.Alt, () => Dispatcher.Invoke(() => CaptureScreenShot())); #endregion // If Output Dircetory is not set. Set it to Documents\Captura\ if (string.IsNullOrWhiteSpace(OutPath.Text)) { OutPath.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura\\"); } // Create the Output Directory if it does not exist if (!Directory.Exists(OutPath.Text)) { Directory.CreateDirectory(OutPath.Text); } Settings.Default.OutputPath = OutPath.Text; Settings.Default.Save(); Closed += (s, e) => App.Current.Shutdown(); cursor = new MouseCursor(OtherSettings.IncludeCursor); OtherSettings.Instance.PropertyChanged += (s, e) => { if (e.PropertyName == "_IncludeCursor") { cursor.Include = OtherSettings.IncludeCursor; } }; }
public AreaManipulator(GUIStyle style) { m_Style = style; m_Cursor = MouseCursor.Arrow; }
private static extern void Internal_AddCursorRect(Rect r, MouseCursor m, int controlID);
bool TryRotateButton(Vector3 position, float size) { size *= HandleUtility.GetHandleSize(position); var dist = Vector3.Distance(mousePosition, position); var buffer = size / 4; if (dist < size + buffer && dist > size - buffer) { if (e.type == EventType.MouseDown) return true; else { mouseCursor = MouseCursor.RotateArrow; Handles.color = Color.green; } } else Handles.color = Color.white; Handles.CircleCap(0, position, inverseRotation, size - buffer / 2); Handles.CircleCap(0, position, inverseRotation, size + buffer / 2); return false; }
void OnPreRender() { MouseCursor.OnPreRenderCursor(); }
public static Vector2 HandlePointMovement(int controlId, Vector2 point, float maxDistance, Action <Vector2, bool, bool> draw, MouseCursor mouseCursor = MouseCursor.Arrow) { /*if(mouseCursor != MouseCursor.Arrow) * { * for (int i = 1; i < 5; i++) * { * EditorGUIUtility.AddCursorRect(GetInscriptRect(point, maxDistance, 90*i/5f), mouseCursor, controlId); * } * }*/ var cursorRect = new Rect(0, 0, maxDistance * 1.5f, maxDistance * 1.5f) { center = point }; EditorGUIUtility.AddCursorRect(cursorRect, mouseCursor, controlId); var isOver = (point - Event.current.mousePosition).magnitude < maxDistance; var isActive = GUIUtility.hotControl == controlId; switch (Event.current.type) { case EventType.Repaint: draw(point, isOver, isActive); break; case EventType.MouseDown: if (isOver) { GUIUtility.hotControl = controlId; Event.current.Use(); } break; case EventType.MouseDrag: if (isActive) { point.x += Event.current.delta.x; point.y += Event.current.delta.y; GUI.changed = true; Event.current.Use(); } break; case EventType.MouseUp: if (isActive) { GUIUtility.hotControl = 0; Event.current.Use(); } break; } return(point); }
public static void ChangeCursor(MouseCursor cursor) { Mouse.SetCursor(cursor); }
void DoPointPlacement() { Event evt = Event.current; EventType eventType = evt.type; if (m_PlacingPoint) { Ray ray = HandleUtility.GUIPointToWorldRay(evt.mousePosition); if (eventType == EventType.MouseDrag) { float hitDistance = Mathf.Infinity; if (plane.Raycast(ray, out hitDistance)) { evt.Use(); polygon.m_Points[m_SelectedIndex] = GetPointInLocalSpace(ray.GetPoint(hitDistance)); RebuildPolyShapeMesh(false); SceneView.RepaintAll(); } } if (eventType == EventType.MouseUp || eventType == EventType.Ignore || eventType == EventType.KeyDown || eventType == EventType.KeyUp) { evt.Use(); m_PlacingPoint = false; m_SelectedIndex = -1; SceneView.RepaintAll(); } } else if (polygon.polyEditMode == PolyShape.PolyEditMode.Path) { if (eventType == EventType.MouseDown && HandleUtility.nearestControl == m_ControlId) { if (polygon.m_Points.Count < 1) { SetupInputPlane(evt.mousePosition); } float hitDistance = Mathf.Infinity; Ray ray = HandleUtility.GUIPointToWorldRay(evt.mousePosition); if (plane.Raycast(ray, out hitDistance)) { UndoUtility.RecordObject(polygon, "Add Polygon Shape Point"); Vector3 hit = ray.GetPoint(hitDistance); if (polygon.m_Points.Count < 1) { // this monstrosity exists so that grid and incremental snap work when possible, and // incremental is enabled when grid is not available. polygon.transform.position = m_Polygon.isOnGrid ? EditorSnapping.MoveSnap(hit) : EditorSnapping.snapMode == SnapMode.Relative ? ProBuilderSnapping.Snap(hit, EditorSnapping.incrementalSnapMoveValue) : hit; Vector3 cameraFacingPlaneNormal = plane.normal; if (Vector3.Dot(cameraFacingPlaneNormal, SceneView.lastActiveSceneView.camera.transform.forward) > 0f) { cameraFacingPlaneNormal *= -1; } polygon.transform.rotation = Quaternion.LookRotation(cameraFacingPlaneNormal) * Quaternion.Euler(new Vector3(90f, 0f, 0f)); } Vector3 point = GetPointInLocalSpace(hit); if (polygon.m_Points.Count > 2 && Math.Approx3(polygon.m_Points[0], point)) { m_NextMouseUpAdvancesMode = true; return; } polygon.m_Points.Add(point); m_PlacingPoint = true; m_SelectedIndex = polygon.m_Points.Count - 1; RebuildPolyShapeMesh(polygon); evt.Use(); } } else { float hitDistance = Mathf.Infinity; Ray ray = HandleUtility.GUIPointToWorldRay(evt.mousePosition); if (plane.Raycast(ray, out hitDistance)) { Vector3 hit = ray.GetPoint(hitDistance); m_CurrentPosition = GetPointInLocalSpace(hit); } } } else if (polygon.polyEditMode == PolyShape.PolyEditMode.Edit) { if (polygon.m_Points.Count < 3) { SetPolyEditMode(PolyShape.PolyEditMode.Path); return; } if (m_DistanceFromHeightHandle > PreferenceKeys.k_MaxPointDistanceFromControl) { // point insertion Vector2 mouse = evt.mousePosition; Ray ray = HandleUtility.GUIPointToWorldRay(mouse); float hitDistance = Mathf.Infinity; if (plane.Raycast(ray, out hitDistance)) { Vector3 hit = ray.GetPoint(hitDistance); Vector3 point = GetPointInLocalSpace(hit); int polyCount = polygon.m_Points.Count; float distToLineInGUI; int index; Vector3 pInGUI = EditorHandleUtility.ClosestPointToPolyLine(polygon.m_Points, out index, out distToLineInGUI, true, polygon.transform); Vector3 aToPoint = point - polygon.m_Points[index - 1]; Vector3 aToB = polygon.m_Points[index % polyCount] - polygon.m_Points[index - 1]; float ratio = Vector3.Dot(aToPoint, aToB.normalized) / aToB.magnitude; Vector3 wp = Vector3.Lerp(polygon.m_Points[index - 1], polygon.m_Points[index % polyCount], ratio); wp = polygon.transform.TransformPoint(wp); Vector2 aInGUI = HandleUtility.WorldToGUIPoint(polygon.transform.TransformPoint(polygon.m_Points[index - 1])); Vector2 bInGUI = HandleUtility.WorldToGUIPoint(polygon.transform.TransformPoint(polygon.m_Points[index % polyCount])); float distanceToVertex = Mathf.Min(Vector2.Distance(mouse, aInGUI), Vector2.Distance(mouse, bInGUI)); if (distanceToVertex > PreferenceKeys.k_MaxPointDistanceFromControl && distToLineInGUI < PreferenceKeys.k_MaxPointDistanceFromControl) { m_MouseCursor = MouseCursor.ArrowPlus; if (evt.type == EventType.Repaint) { Handles.color = Color.green; Handles.DotHandleCap(-1, wp, Quaternion.identity, HandleUtility.GetHandleSize(wp) * k_HandleSize, evt.type); } if (evt.type == EventType.MouseDown && HandleUtility.nearestControl == m_ControlId) { evt.Use(); UndoUtility.RecordObject(polygon, "Insert Point"); polygon.m_Points.Insert(index, point); m_SelectedIndex = index; m_PlacingPoint = true; RebuildPolyShapeMesh(true); OnBeginVertexMovement(); } Handles.color = Color.white; } if (evt.type != EventType.Repaint) { SceneView.RepaintAll(); } } } } }
/// <summary> /// Implements the PolyShapeTool in the Unity Editor. This method is called when the PolyShapeTool is activated. /// </summary> /// <param name="window">The window calling the tool (SceneView).</param> public override void OnToolGUI(EditorWindow window) { Event evt = Event.current; // todo refactor overlays to use `Overlay` class #pragma warning disable 618 SceneViewOverlay.Window(m_OverlayTitle, OnOverlayGUI, 0, SceneViewOverlay.WindowDisplayOption.OneWindowPerTitle); #pragma warning restore 618 if (polygon == null) { return; } if (polygon.polyEditMode == PolyShape.PolyEditMode.None) { return; } // used when finishing a loop by clicking the first created point if (m_NextMouseUpAdvancesMode && evt.type == EventType.MouseUp) { evt.Use(); m_NextMouseUpAdvancesMode = false; if (SceneCameraIsAlignedWithPolyUp()) { SetPolyEditMode(PolyShape.PolyEditMode.Edit); } else { SetPolyEditMode(PolyShape.PolyEditMode.Height); } } if (m_IsModifyingVertices && ( evt.type == EventType.MouseUp || evt.type == EventType.Ignore || evt.type == EventType.KeyDown || evt.type == EventType.KeyUp)) { OnFinishVertexMovement(); } if (evt.type == EventType.KeyDown) { HandleKeyEvent(evt); } //The user can press a key to exit editing mode, //leading to null polygon at this point if (polygon == null) { return; } if (EditorHandleUtility.SceneViewInUse(evt)) { return; } m_ControlId = GUIUtility.GetControlID(FocusType.Passive); if (evt.type == EventType.Layout) { HandleUtility.AddDefaultControl(m_ControlId); } if (polygon.polyEditMode == PolyShape.PolyEditMode.Path && !m_PlacingPoint) { m_MouseCursor = MouseCursor.ArrowPlus; } else if ((GUIUtility.hotControl != 0) || m_PlacingPoint) { m_MouseCursor = MouseCursor.MoveArrow; } else { m_MouseCursor = MouseCursor.Arrow; } if (evt.type == EventType.MouseMove) { SceneView.RepaintAll(); } DoPointPlacement(); DoExistingPointsGUI(); if (evt.type == EventType.Repaint) { DoExistingLinesGUI(); Rect sceneViewRect = window.position; sceneViewRect.x = 0; sceneViewRect.y = 0; SceneView.AddCursorRect(sceneViewRect, m_MouseCursor); } }
private void Awake() { instance = this; }
private void OnDestroy() { instance = null; }
//Update state State UpdateState() { switch (state) { //Hovering case State.Hover: DrawNearestLineAndSplit(); if (Tools.current == Tool.Move && TryDragSelected()) { return(State.DragSelected); } if (Tools.current == Tool.Rotate && TryRotateSelected()) { return(State.RotateSelected); } if (Tools.current == Tool.Scale && TryScaleSelected()) { return(State.ScaleSelected); } if (Tools.current == Tool.Move && TryExtrude()) { return(State.Extrude); } if (TrySelectAll()) { return(State.Hover); } if (TrySplitLine()) { return(State.Hover); } if (TryDeleteSelected()) { return(State.Hover); } if (TryHoverCurvePoint(out dragIndex) && TryDragCurvePoint(dragIndex)) { return(State.Drag); } if (TryHoverKeyPoint(out dragIndex) && TryDragKeyPoint(dragIndex)) { return(State.Drag); } if (TryBoxSelect()) { return(State.BoxSelect); } break; //Dragging case State.Drag: mouseCursor = MouseCursor.MoveArrow; DrawCircle(keyPoints[dragIndex], clickRadius); if (draggingCurve) { MoveCurvePoint(dragIndex, mousePosition - clickPosition); } else { MoveKeyPoint(dragIndex, mousePosition - clickPosition); } if (TryStopDrag()) { return(State.Hover); } break; //Box Selecting case State.BoxSelect: if (TryBoxSelectEnd()) { return(State.Hover); } break; //Dragging selected case State.DragSelected: mouseCursor = MouseCursor.MoveArrow; MoveSelected(mousePosition - clickPosition); if (TryStopDrag()) { return(State.Hover); } break; //Rotating selected case State.RotateSelected: mouseCursor = MouseCursor.RotateArrow; RotateSelected(); if (TryStopDrag()) { return(State.Hover); } break; //Scaling selected case State.ScaleSelected: mouseCursor = MouseCursor.ScaleArrow; ScaleSelected(); if (TryStopDrag()) { return(State.Hover); } break; //Extruding case State.Extrude: mouseCursor = MouseCursor.MoveArrow; MoveSelected(mousePosition - clickPosition); if (doExtrudeUpdate && mousePosition != clickPosition) { UpdatePoly(false, false); doExtrudeUpdate = false; } if (TryStopDrag()) { return(State.Hover); } break; } return(state); }
public void OnGUI() { Event guiEvent = Event.current; if (guiEvent.isScrollWheel) { overrideAction = ActionType.ViewZoom; } else if (guiEvent.type == EventType.MouseDown) { mouseDownPosition = guiEvent.mousePosition; mouseDownTime = Time.time; mouseIsDown = true; } else if (guiEvent.type == EventType.MouseUp) { mouseIsDown = false; } else if (guiEvent.type != EventType.Repaint) { overrideAction = ActionType.None; if (guiEvent.alt) { if (guiEvent.control) { overrideAction = ActionType.ViewZoom; } else { overrideAction = ActionType.ViewPan; } } } UpdateMouseToShape(); Rect toolRect = new Rect(0, 0, this.position.width, toolAreaHeight); Rect toolbarRect = new Rect(toolbarPadding * 2, toolbarPadding, toolbarWidth * (toolIcons.Length + 1) + toolbarPadding, toolbarHeight); OnToolbarArea(guiEvent, toolbarRect); Rect separatorRect = new Rect(toolbarRect.xMax + toolbarPadding, 0, separatorWidth, toolRect.height); GUI.DrawTexture(separatorRect, separatorTexture); Rect infoRect = new Rect(separatorRect.xMax, 0, toolRect.width - separatorRect.xMax, toolRect.height); switch (activeTool) { case ToolSet.View: OnInfoAreaView(guiEvent, infoRect); baseAction = ActionType.ViewPan; break; case ToolSet.Select: OnInfoAreaSelect(guiEvent, infoRect); baseAction = ActionType.SelectNormal; break; case ToolSet.Brush: OnInfoAreaBrush(guiEvent, infoRect); baseAction = ActionType.LineEdit; break; case ToolSet.Shape: OnInfoAreaShape(guiEvent, infoRect); baseAction = ActionType.ShapeEdit; break; } Rect viewRect = new Rect(0, toolRect.yMax, this.position.width, this.position.height - toolRect.yMax); MouseCursor activeCursor = MouseCursor.Arrow; switch (action) { case ActionType.ViewPan: activeCursor = MouseCursor.Pan; break; case ActionType.ViewZoom: activeCursor = MouseCursor.Zoom; break; } EditorGUIUtility.AddCursorRect(viewRect, activeCursor); bool handled = false; if (guiEvent.type == EventType.Repaint) { renderUtil.BeginPreview(viewRect, GUIStyle.none); renderUtil.camera.backgroundColor = backgroundColor; foreach (VectorShape shape in shapes) { renderUtil.DrawMesh(shape.ShapeMesh, Matrix4x4.identity, renderMaterial, 0); } renderUtil.Render(); Handles.SetCamera(renderUtil.camera); VectorShape.handleDrawSize = HandleUtility.GetHandleSize(Vector3.zero) * viewRect.height / viewRect.width; foreach (VectorShape selected in selection) { selected.DrawEditorHandles(true, (selected == focusedShape)); } if (selectionRect != Rect.zero) { Color outlineColor = Handles.color; Color fillColor = new Color(outlineColor.r, outlineColor.g, outlineColor.b, 0.2f); Handles.DrawSolidRectangleWithOutline(selectionRect, fillColor, outlineColor); } renderUtil.EndAndDrawPreview(viewRect); Vector2 originLoc = mouseToShapeMatrix.Inverse().MultiplyPoint(Vector2.zero); if (viewRect.Contains(originLoc)) { GUIStyle originPivot = "U2D.pivotDot"; if (originPivot != null) { Rect pivotRect = new Rect(0f, 0f, originPivot.fixedWidth, originPivot.fixedHeight); pivotRect.center = originLoc; originPivot.Draw(pivotRect, false, false, false, false); } } if (showSnap) { Vector2 snapLoc = mouseToShapeMatrix.Inverse().MultiplyPoint(snapPosition); if (viewRect.Contains(snapLoc)) { GUIStyle snapPivot = "U2D.dragDot"; if (snapPivot != null) { Rect pivotRect = new Rect(0f, 0f, snapPivot.fixedWidth, snapPivot.fixedHeight); pivotRect.center = snapLoc; snapPivot.Draw(pivotRect, false, false, false, false); } } } } else if (guiEvent.isScrollWheel && (EditorWindow.mouseOverWindow == this)) { float zoomFactor = HandleUtility.niceMouseDeltaZoom; float orthographicSize = renderUtil.camera.orthographicSize * (1 - zoomFactor * .02f); SetCameraSize(orthographicSize); handled = true; } else if (guiEvent.isMouse) { // Update mouse position mousePosition = guiEvent.mousePosition; mouseInContent = (viewRect.Contains(mousePosition)); switch (action) { case ActionType.ViewPan: case ActionType.ViewZoom: handled = OnViewToolMouse(guiEvent); break; case ActionType.SelectNormal: case ActionType.SelectAdditive: case ActionType.SelectSubtractive: handled = OnSelectToolMouse(guiEvent); break; case ActionType.LineEdit: case ActionType.CurveEdit: handled = OnBrushToolMouse(guiEvent); break; case ActionType.ShapeEdit: handled = OnShapeToolMouse(guiEvent); break; case ActionType.SetOrigin: handled = OnSetOriginMouse(guiEvent); break; //case ActionType.ChangeScale: //handled = OnChangeScaleMouse(guiEvent); //break; } if (!handled) { Vector2 delta = guiEvent.delta; guiEvent.mousePosition = MouseToShapePoint(mousePosition); guiEvent.delta = guiEvent.delta * new Vector2(mouseToShapeScale, -mouseToShapeScale); foreach (VectorShape selected in selection) { handled |= selected.HandleEditorEvent(guiEvent, true); } guiEvent.mousePosition = mousePosition; guiEvent.delta = delta; } } else if (guiEvent.type == EventType.ValidateCommand) { switch (guiEvent.commandName) { case Cmd_Delete: if (selection.Count > 0) { handled = true; } break; case Cmd_SelectAll: if (shapes.Count > 0) { handled = true; } break; } } else if (guiEvent.type == EventType.ExecuteCommand) { switch (guiEvent.commandName) { case Cmd_Delete: foreach (VectorShape selected in selection) { shapes.Remove(selected); } selection.Clear(); handled = true; break; case Cmd_SelectAll: foreach (VectorShape selected in shapes) { selection.Add(selected); } handled = true; break; case Cmd_ModifierKeysChanged: Repaint(); handled = true; break; } } if (action == ActionType.ChangeScale) { handled = OnChangeScaleGUI(guiEvent); } if (handled) { guiEvent.Use(); } }
//Update state State UpdateState() { switch (state) { //Hovering case State.Hover: DrawNearestLineAndSplit(); if (Tools.current == Tool.Move && TryDragSelected()) return State.DragSelected; if (Tools.current == Tool.Rotate && TryRotateSelected()) return State.RotateSelected; if (Tools.current == Tool.Scale && TryScaleSelected()) return State.ScaleSelected; if (Tools.current == Tool.Move && TryExtrude()) return State.Extrude; if (TrySelectAll()) return State.Hover; if (TrySplitLine()) return State.Hover; if (TryDeleteSelected()) return State.Hover; if (TryHoverCurvePoint(out dragIndex) && TryDragCurvePoint(dragIndex)) return State.Drag; if (TryHoverKeyPoint(out dragIndex) && TryDragKeyPoint(dragIndex)) return State.Drag; if (TryBoxSelect()) return State.BoxSelect; break; //Dragging case State.Drag: mouseCursor = MouseCursor.MoveArrow; DrawCircle(keyPoints[dragIndex], clickRadius); if (draggingCurve) MoveCurvePoint(dragIndex, mousePosition - clickPosition); else MoveKeyPoint(dragIndex, mousePosition - clickPosition); if (TryStopDrag()) return State.Hover; break; //Box Selecting case State.BoxSelect: if (TryBoxSelectEnd()) return State.Hover; break; //Dragging selected case State.DragSelected: mouseCursor = MouseCursor.MoveArrow; MoveSelected(mousePosition - clickPosition); if (TryStopDrag()) return State.Hover; break; //Rotating selected case State.RotateSelected: mouseCursor = MouseCursor.RotateArrow; RotateSelected(); if (TryStopDrag()) return State.Hover; break; //Scaling selected case State.ScaleSelected: mouseCursor = MouseCursor.ScaleArrow; ScaleSelected(); if (TryStopDrag()) return State.Hover; break; //Extruding case State.Extrude: mouseCursor = MouseCursor.MoveArrow; MoveSelected(mousePosition - clickPosition); if (doExtrudeUpdate && mousePosition != clickPosition) { UpdatePoly(false, false); doExtrudeUpdate = false; } if (TryStopDrag()) return State.Hover; break; } return state; }
public static void AssignCursorForPreviousRect(MouseCursor cursor) { EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), cursor); }
public bool ProcessEvent(Event e) { if (e.rawType == EventType.MouseDown || e.rawType == EventType.MouseUp || e.rawType == EventType.MouseMove) { Vector2 mPos = Utils.GetMousePosition(); Vector2 mPosLocal = new Vector2(mPos.x - transform.position.x, mPos.y - transform.position.y); // global check if mouse is inside any of child components if (!new Rect(0, 0, HBackR.width + HBackL.width, HBackR.height).Contains(mPosLocal) && !new Rect(0, TBackRObject.transform.localPosition.y, TBackR.width + TBackL.width, TBackR.height).Contains(mPosLocal) && (ExtraRObject == null || !new Rect(0, ExtraRObject.transform.localPosition.y, ExtraR.width + ExtraL.width, ExtraR.height).Contains(mPosLocal)) && (BlackQuad == null || !new Rect(BlackQuad.transform.localPosition.x, BlackQuad.transform.localPosition.y, TBackR.width, MainCamera.Height - transform.localPosition.y).Contains(mPosLocal))) { return(false); } MouseCursor.SetCursor(MouseCursor.CurDefault); // if (e.rawType == EventType.MouseDown) { if (BHumanModeObject != null) { if (new Rect(BHumanModeObject.transform.localPosition.x, BHumanModeObject.transform.localPosition.y, BHumanMode.width, BHumanMode.height).Contains(mPosLocal)) { // switch to textmode IsHumanMode = !IsHumanMode; } } if (BPackOpenObject != null) { if (new Rect(BPackOpenObject.transform.localPosition.x, BPackOpenObject.transform.localPosition.y, BPackOpen.width, BPackOpen.height).Contains(mPosLocal)) { // switch to open inventory. MapView.Instance.InventoryVisible = !MapView.Instance.InventoryVisible; } } if (BBookOpenObject != null) { if (new Rect(BBookOpenObject.transform.localPosition.x, BBookOpenObject.transform.localPosition.y, BBookOpen.width, BBookOpen.height).Contains(mPosLocal)) { // switch to open spellbook MapView.Instance.SpellbookVisible = !MapView.Instance.SpellbookVisible; } } } // check if event was inside view pic if (new Rect(HBackL.width, 0, HBackR.width, HBackR.height).Contains(mPosLocal)) // right side of humanback { if (_Viewer != null) { _Viewer.ProcessEventPic(e, mPosLocal.x - HBackL.width, mPosLocal.y); } } else if (new Rect(TBackL.width, TBackRObject.transform.localPosition.y, TBackR.width, TBackR.height).Contains(mPosLocal)) { if (_Viewer != null) { _Viewer.ProcessEventInfo(e, mPosLocal.x - TBackL.width, mPosLocal.y - TBackRObject.transform.localPosition.y); } } return(true); } else if (e.type == EventType.KeyDown) { if (e.keyCode == KeyCode.Tab && BHumanModeObject != null) { IsHumanMode = !IsHumanMode; return(true); } } return(false); }
public static void AssignCursor(Rect r, MouseCursor cursor) { EditorGUIUtility.AddCursorRect(r, cursor); }
public AreaManipulator(GUIStyle style, MouseCursor cursor) { m_Style = style; m_Cursor = cursor; }
void Cursor() { MouseCursor cursor = Mouse.Instance.Cursor; Assert.NotNull(cursor); }
/// <summary> /// Initialize new <see cref="CursorInfo"/>. /// </summary> /// <param name="texture">Cursor texture.</param> /// <param name="hotspot">Active point of cursor.</param> public CursorInfo(Texture2D texture, Vector2 hotspot) { this.Type = MouseCursor.CustomCursor; this.Texture = texture; this.Hotspot = hotspot; }
internal static Vector2 PointSlider(Vector2 pos, MouseCursor cursor, GUIStyle dragDot, GUIStyle dragDotActive) { int controlID = GUIUtility.GetControlID("Slider1D".GetHashCode(), FocusType.Keyboard); Vector2 vector = Handles.matrix.MultiplyPoint((Vector3) pos); Rect position = new Rect(vector.x - (dragDot.fixedWidth * 0.5f), vector.y - (dragDot.fixedHeight * 0.5f), dragDot.fixedWidth, dragDot.fixedHeight); if (Event.current.GetTypeForControl(controlID) == EventType.Repaint) { if (GUIUtility.hotControl == controlID) { dragDotActive.Draw(position, GUIContent.none, controlID); } else { dragDot.Draw(position, GUIContent.none, controlID); } } return ScaleSlider(pos, cursor, position); }
private void HandleBorderPointSlider(ref float x, ref float y, MouseCursor mouseCursor, bool isHidden, GUIStyle dragDot, GUIStyle dragDotActive, Color color) { Color color2 = GUI.color; if (isHidden) { GUI.color = new Color(0f, 0f, 0f, 0f); } else { GUI.color = color; } Vector2 vector = SpriteEditorHandles.PointSlider(new Vector2(x, y), mouseCursor, dragDot, dragDotActive); x = vector.x; y = vector.y; GUI.color = color2; }
private static Vector2 ScaleSlider(int id, Vector2 pos, MouseCursor cursor, Rect cursorRect) { Vector2 vector = Handles.matrix.MultiplyPoint((Vector3) pos); Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (((current.button == 0) && cursorRect.Contains(Event.current.mousePosition)) && !current.alt) { int num = id; GUIUtility.keyboardControl = num; GUIUtility.hotControl = num; s_CurrentMousePosition = current.mousePosition; s_DragStartScreenPosition = current.mousePosition; s_DragScreenOffset = s_CurrentMousePosition - vector; current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); } return pos; case EventType.MouseUp: if ((GUIUtility.hotControl == id) && ((current.button == 0) || (current.button == 2))) { GUIUtility.hotControl = 0; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); } return pos; case EventType.MouseMove: case EventType.KeyUp: case EventType.ScrollWheel: return pos; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { s_CurrentMousePosition += current.delta; Vector2 vector2 = pos; pos = Handles.s_InverseMatrix.MultiplyPoint((Vector3) s_CurrentMousePosition); Vector2 vector3 = vector2 - pos; if (!Mathf.Approximately(vector3.magnitude, 0f)) { GUI.changed = true; } current.Use(); } return pos; case EventType.KeyDown: if ((GUIUtility.hotControl == id) && (current.keyCode == KeyCode.Escape)) { pos = Handles.s_InverseMatrix.MultiplyPoint((Vector3) (s_DragStartScreenPosition - s_DragScreenOffset)); GUIUtility.hotControl = 0; GUI.changed = true; current.Use(); } return pos; case EventType.Repaint: EditorGUIUtility.AddCursorRect(cursorRect, cursor, id); return pos; } return pos; }
public void LastCursor(MouseCursor mouse) { Cursor(LastRect, mouse); }
public bool ProcessEvent(Event e) { if (e.rawType == EventType.MouseDown || e.rawType == EventType.MouseUp || e.rawType == EventType.MouseMove) { int lw = 64 + View.InvWidth * 80; int lh = 90; Vector2 mPos = Utils.GetMousePosition(); Vector2 mPosLocal = mPos - new Vector2(transform.position.x, transform.position.y); if (mPosLocal.x < 0 || mPosLocal.y < 0 || mPosLocal.x > lw || mPosLocal.y > lh) { if (ArrowHovered != 0) { ArrowHovered = 0; UpdateMaterials(); } return(false); } // process hover if (e.rawType == EventType.MouseMove) { if (mPosLocal.x < 32) { ArrowHovered = 1; } else if (mPosLocal.x >= lw - 32) { ArrowHovered = 2; } else { ArrowHovered = 0; } UpdateMaterials(); } else if (e.rawType == EventType.MouseDown) { if (ArrowClicked != ArrowHovered) { ArrowClicked = ArrowHovered; UpdateMaterials(); } } else if (e.rawType == EventType.MouseUp) { if (ArrowClicked != 0) { ArrowClicked = 0; UpdateMaterials(); } } MouseCursor.SetCursor(MouseCursor.CurDefault); return(true); } return(false); }
static IntPtr CreateEmptyCursor(X11WindowInfo window) { IntPtr cursor = IntPtr.Zero; using (new XLock(window.Display)) { XColor black, dummy; IntPtr cmap = Functions.XDefaultColormap(window.Display, window.Screen); Functions.XAllocNamedColor(window.Display, cmap, "black", out black, out dummy); IntPtr bmp_empty = Functions.XCreateBitmapFromData(window.Display, window.Handle, new byte[,] { { 0 } }); cursor = Functions.XCreatePixmapCursor(window.Display, bmp_empty, bmp_empty, ref black, ref black, 0, 0); } return cursor; }
public override void AddCursorRect(Rect position, MouseCursor cursor) { }
internal static Vector2 ScaleSlider(Vector2 pos, MouseCursor cursor, Rect cursorRect) { return ScaleSlider(GUIUtility.GetControlID("Slider1D".GetHashCode(), FocusType.Keyboard), pos, cursor, cursorRect); }
public static void CustomActionField(Action action, bool showCursorPredicate, bool clickPredicate, MouseCursor cursor) { CustomActionField(GetLastRect(), action, showCursorPredicate, clickPredicate, cursor); }
void UpdateInput() { if (!MapLogic.Instance.IsLoaded) { return; } // update mouse x/y int oldMouseCellX = MouseCellX; int oldMouseCellY = MouseCellY; Vector3 mPos = Utils.GetMousePosition(); mPos.x += ScrollX * 32; mPos.y += ScrollY * 32; float cXFrac = (mPos.x / 32) - Mathf.Floor(mPos.x / 32); _MouseCellX = (int)(mPos.x / 32); _MouseCellY = 0; for (int y = (int)_VisibleRect.yMin; y <= _VisibleRect.yMax; y++) { float h1 = y * 32 - GetHeightAt(_MouseCellX, y); float h2 = y * 32 - GetHeightAt(_MouseCellX + 1, y); float h = h1 * (1f - cXFrac) + h2 * cXFrac; if (mPos.y < h) { _MouseCellY = y - 1; break; } } _MouseCellX = Mathf.Clamp(_MouseCellX, 0, MapLogic.Instance.Width - 1); _MouseCellY = Mathf.Clamp(_MouseCellY, 0, MapLogic.Instance.Height - 1); //Debug.Log(string.Format("mouse = {0} {1} (from {2} {3})", _MouseCellX, _MouseCellY, mPos.x, mPos.y)); // temporary! if (MapLogic.Instance.ConsolePlayer == null) // mostly if we're server { if (oldMouseCellX != MouseCellX || oldMouseCellY != MouseCellY) { MapLogic.Instance.SetTestingVisibility(MouseCellX, MouseCellY, 5); } } // PERMANENT (x2) // check currently hovered object MapNode[,] nodes = MapLogic.Instance.Nodes; MapObject o = null; float oZ = 0; for (int y = (int)_VisibleRect.yMin; y <= _VisibleRect.yMax; y++) { for (int x = (int)_VisibleRect.xMin; x <= _VisibleRect.xMax; x++) { foreach (MapObject mobj in nodes[x, y].Objects) { if (mobj.GameObject == null || mobj.GameScript == null) { continue; } // if (!(mobj.GameScript is IMapViewSelectable) || !((IMapViewSelectable)mobj.GameScript).IsSelected((int)mPos.x, (int)mPos.y)) { continue; } if (mobj.GameObject.transform.position.z < oZ) { o = mobj; oZ = mobj.GameObject.transform.position.z; } } } } MouseCursor.SetCursor(MouseCursor.CurDefault); bool hoveringDarkness = (nodes[MouseCellX, MouseCellY].Flags & MapNodeFlags.Visible) == 0; if (o != null && (o.GameScript is IMapViewSelfie)) { Infowindow.Viewer = (IMapViewSelfie)o.GameScript; } else if (SelectedObject != null && (SelectedObject.GameScript is IMapViewSelfie)) { Infowindow.Viewer = (IMapViewSelfie)SelectedObject.GameScript; } else { Infowindow.Viewer = null; } HoveredObject = o; if (GetCastSpell() != Spell.Spells.NoneSpell) { MouseCursor.SetCursor(MouseCursor.CurCast); return; } if (!hoveringDarkness && HoveredObject != null && (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move || Commandbar.CurrentCommand == 0)) { // hovered usable buildings have different cursor picture. if (HoveredObject.GetObjectType() == MapObjectType.Structure && ((MapStructure)HoveredObject).Class.Usable) { MouseCursor.SetCursor(MouseCursor.CurSelectStructure); } else { MouseCursor.SetCursor(MouseCursor.CurSelect); } } else if (SelectedObject != null && SelectedObject is IPlayerPawn) { Player sp = ((IPlayerPawn)SelectedObject).GetPlayer(); if (sp == MapLogic.Instance.ConsolePlayer) { if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move) { MouseCursor.SetCursor(MouseCursor.CurMove); } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Attack) { MouseCursor.SetCursor(MouseCursor.CurAttack); } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.MoveAttack) { MouseCursor.SetCursor(MouseCursor.CurMoveAttack); } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Pickup) { MouseCursor.SetCursor(MouseCursor.CurPickup); } } } }
public static void SelectField(UnityObject obj, MouseCursor cursor = MouseCursor.Link) { SelectField(GetLastRect(), obj, cursor); }
internal Cursor(string fileName, Bitmap image) { FileName = fileName; Image = image; var thisAssembly = Assembly.GetExecutingAssembly(); using (var stream = thisAssembly.GetManifestResourceStream("OpenBve.plus.png")) { if (stream != null) { Bitmap Plus = new Bitmap(stream); using (var g = Graphics.FromImage(Plus)) { g.DrawImage(image, 0.0f, 0.0f, image.Width, image.Height); var data = Plus.LockBits(new Rectangle(0, 0, Plus.Width, Plus.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); MyCursorPlus = new MouseCursor(5, 0, data.Width, data.Height, data.Scan0); Plus.UnlockBits(data); } } else { Bitmap Plus = new Bitmap(OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder(), "Cursors\\Symbols\\plus.png")); using (var g = Graphics.FromImage(Plus)) { g.DrawImage(image, 0.0f, 0.0f, image.Width, image.Height); var data = Plus.LockBits(new Rectangle(0, 0, Plus.Width, Plus.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); MyCursorPlus = new MouseCursor(5, 0, data.Width, data.Height, data.Scan0); Plus.UnlockBits(data); } } } using (var stream = thisAssembly.GetManifestResourceStream("OpenBve.minus.png")) { if (stream != null) { Bitmap Minus = new Bitmap(stream); using (var g = Graphics.FromImage(Minus)) { g.DrawImage(image, 0.0f, 0.0f, image.Width, image.Height); var data = Minus.LockBits(new Rectangle(0, 0, Minus.Width, Minus.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); MyCursorMinus = new MouseCursor(5, 0, data.Width, data.Height, data.Scan0); Minus.UnlockBits(data); } } else { Bitmap Minus = new Bitmap(OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder(), "Cursors\\Symbols\\minus.png")); using (var g = Graphics.FromImage(Minus)) { g.DrawImage(image, 0.0f, 0.0f, image.Width, image.Height); var data = Minus.LockBits(new Rectangle(0, 0, Minus.Width, Minus.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); MyCursorMinus = new MouseCursor(5, 0, data.Width, data.Height, data.Scan0); Minus.UnlockBits(data); } } } { var data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); MyCursor = new MouseCursor(5, 0, data.Width, data.Height, data.Scan0); image.UnlockBits(data); } }
public static void SelectField(Rect fieldRect, UnityObject obj, MouseCursor cursor = MouseCursor.Link) { SelectField(fieldRect, obj, IsLMBMouseDown(), cursor); }
void Update() { lastMouseDown += Time.unscaledDeltaTime; if (lastMouseChange >= 0) { lastMouseChange += Time.unscaledDeltaTime; } bool mouse1Clicked = Input.GetMouseButton(0); GotProcessors = false; EnumerateObjects(); // get all custom events. lock (CustomEvents) { while (CustomEvents.Count > 0) { CustomEvent ce = CustomEvents.Dequeue(); for (int i = Processors.Count - 1; i >= 0; i--) { // check if processor's renderer is enabled. implicitly don't give any events to invisible objects. if (!ce.IsForced && !ProcessorsEnabled[i]) { continue; } if (((IUiEventProcessor)Processors[i]).ProcessCustomEvent(ce) && !ce.IsGlobal) { break; } } } } // get all events. Event e = new Event(); while (Event.PopEvent(e)) { // pressing PrintScreen or Alt+S results in screenshot unconditionally. if (e.type == EventType.KeyDown && (e.keyCode == KeyCode.Print || e.keyCode == KeyCode.SysReq || (e.keyCode == KeyCode.S && e.alt))) { MainCamera.Instance.TakeScreenshot(); return; } if (e.rawType == EventType.MouseDown) { if (lastMouseDown > 0.25f) { lastMouseDown = 0; } else { e.commandName = "double"; lastMouseDown = 1; } } // reverse iteration bool EventIsGlobal = (e.type == EventType.KeyUp || e.rawType == EventType.MouseUp); for (int i = Processors.Count - 1; i >= 0; i--) { // check if processor's renderer is enabled. implicitly don't give any events to invisible objects. if (!ProcessorsEnabled[i]) { continue; } if (((IUiEventProcessor)Processors[i]).ProcessEvent(e) && !EventIsGlobal) { break; } } } // also fake mouse event for each processor bool doStartDrag = false; float doStartDragX = lastMouseX; float doStartDragY = lastMouseY; Vector2 mPos = Utils.GetMousePosition(); Object mProcessor = null; /*if (mPos.x != lastMouseX || * mPos.y != lastMouseY)*/ { Event ef = new Event(); ef.type = EventType.MouseMove; if (lastMouseChange > 0.5f && !Input.GetMouseButton(0) && !Input.GetMouseButton(1) && !Input.GetMouseButton(2)) { ef.commandName = "tooltip"; lastMouseChange = -1; } for (int i = Processors.Count - 1; i >= 0; i--) { // check if processor's renderer is enabled. implicitly don't give any events to invisible objects. if (!ProcessorsEnabled[i]) { continue; } if (((IUiEventProcessor)Processors[i]).ProcessEvent(ef)) { mProcessor = Processors[i]; break; } } if (lastMouseX != mPos.x || lastMouseY != mPos.y) { lastMouseX = mPos.x; lastMouseY = mPos.y; doStartDrag = (DragItem == null) ? mouse1Clicked : false; lastMouseChange = 0; lastMouseDown = 1; // disable doubleclick if drag started UnsetTooltip(); } } CheckMouseOver((IUiEventProcessor)mProcessor); // process drag-drop for items. // first ask every element if they can process the drop. bool dragProcessed = false; //for (int i = Processors.Count - 1; i >= 0; i--) if (mProcessor != null && mProcessor is IUiItemDragger) { _CurrentDragDragger = (IUiItemDragger)mProcessor; // start dragging if coordinates changed with mouse button pressed. // don't call doStartDrag further if one of the widgets has processed it. if (doStartDrag && _CurrentDragDragger.ProcessStartDrag(doStartDragX, doStartDragY)) { doStartDrag = false; dragProcessed = true; _CurrentDragDragger = null; goto NoDrag; } // process already done dragging (if any) if (DragItem != null && _CurrentDragDragger.ProcessDrag(DragItem, mPos.x, mPos.y)) { dragProcessed = true; // check drop. if drop is done and processed, we should complete dragging. // make new item. // it's the duty of _DragDragger to delete the old item based on drag count. if (!mouse1Clicked) { // if parent has changed, then it probably doesn't belong to the original pack anymore and thus can't be moved. Item newItem = _DragDragger.ProcessVerifyEndDrag(); if (newItem == null) { CancelDrag(); _CurrentDragDragger = null; goto NoDrag; } if (_CurrentDragDragger.ProcessDrop(newItem, mPos.x, mPos.y)) { _DragDragger.ProcessEndDrag(); DragItem = null; DragItemCount = 0; _DragCallback = null; _DragDragger = null; } } } _CurrentDragDragger = null; } NoDrag: if (DragItem != null) { // cancel drop if we tried to drop on a bad place. // DropItem != null && !mouse1Clicked means that it didnt process drop. if (!mouse1Clicked) { CancelDrag(); } else { DragItem.Class.File_Pack.UpdateSprite(); if (!dragProcessed) // set mouse cursor { MouseCursor.SetCursor(MouseCursor.CurCantPut); } else { MouseCursor.SetCursor(DragItem.Class.File_Pack.File); } } } }
public static void SelectField(UnityObject obj, bool clickPredicate, MouseCursor cursor = MouseCursor.Link) { CustomActionField(() => EditorHelper.SelectObject(obj), obj != null, clickPredicate, cursor); }
void OnSceneGUI() { if (target == null) { return; } if (KeyPressed(editKey)) { editing = !editing; } // Using a static flag, because static seems to survive the undo/redo process if (UNDO_WHILE_EDIT) { editing = true; UNDO_WHILE_EDIT = false; } if (editing) { //Update lists if (keyPoints == null) { keyPoints = new List <Vector3>(polyMesh.keyPoints); curvePoints = new List <Vector3>(polyMesh.curvePoints); isCurve = new List <bool>(polyMesh.isCurve); } //Load handle matrix Handles.matrix = polyMesh.transform.localToWorldMatrix; //Draw points and lines DrawAxis(); Handles.color = Color.white; for (int i = 0; i < keyPoints.Count; i++) { Handles.color = nearestLine == i ? Color.green : Color.white; DrawSegment(i); if (selectedIndices.Contains(i)) { Handles.color = Color.green; DrawCircle(keyPoints[i], 0.08f); } else { Handles.color = Color.white; } DrawKeyPoint(i); if (isCurve[i]) { Handles.color = (draggingCurve && dragIndex == i) ? Color.white : Color.blue; DrawCurvePoint(i); } } //Quit on tool change if (e.type == EventType.KeyDown) { switch (e.keyCode) { case KeyCode.Q: case KeyCode.W: case KeyCode.E: case KeyCode.R: return; } } //Quit if panning or no camera exists if (Tools.current == Tool.View || (e.isMouse && e.button > 0) || Camera.current == null || e.type == EventType.ScrollWheel) { return; } //Quit if laying out if (e.type == EventType.Layout) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); return; } //Cursor rectangle EditorGUIUtility.AddCursorRect(new Rect(0, 0, Camera.current.pixelWidth, Camera.current.pixelHeight), mouseCursor); mouseCursor = MouseCursor.Arrow; //Extrude key state if (e.keyCode == extrudeKey) { if (extrudeKeyDown) { if (e.type == EventType.KeyUp) { extrudeKeyDown = false; } } else if (e.type == EventType.KeyDown) { extrudeKeyDown = true; } } //Update matrices and snap worldToLocal = polyMesh.transform.worldToLocalMatrix; inverseRotation = Quaternion.Inverse(polyMesh.transform.rotation) * Camera.current.transform.rotation; snap = gridSnap; //Update mouse position screenMousePosition = new Vector3(e.mousePosition.x, Camera.current.pixelHeight - e.mousePosition.y); var plane = new Plane(-polyMesh.transform.forward, polyMesh.transform.position); var ray = Camera.current.ScreenPointToRay(screenMousePosition); float hit; if (plane.Raycast(ray, out hit)) { mousePosition = worldToLocal.MultiplyPoint(ray.GetPoint(hit)); } else { return; } //Update nearest line and split position nearestLine = NearestLine(out splitPosition); //Update the state and repaint var newState = UpdateState(); if (state != newState) { SetState(newState); } HandleUtility.Repaint(); } }
public static void PingField(UnityObject obj, MouseCursor cursor = MouseCursor.Zoom) { PingField(GetLastRect(), obj, cursor); }
internal static extern void SetCurrentViewCursor(Texture2D texture, Vector2 hotspot, MouseCursor type);
public static void PingField(Rect fieldRect, UnityObject obj, MouseCursor cursor = MouseCursor.Zoom) { PingField(fieldRect, obj, obj != null, IsLMBMouseDown(), cursor); }
void OnSceneGUI() { if (target == null) return; if (KeyPressed(editKey)) editing = !editing; if (editing) { //Update lists if (keyPoints == null) { keyPoints = new List<Vector3>(polyMesh.keyPoints); curvePoints = new List<Vector3>(polyMesh.curvePoints); isCurve = new List<bool>(polyMesh.isCurve); } //Crazy hack to register undo if (undoCallback == null) { undoCallback = typeof(EditorApplication).GetField("undoRedoPerformed", BindingFlags.NonPublic | BindingFlags.Static); if (undoCallback != null) undoCallback.SetValue(null, new EditorApplication.CallbackFunction(OnUndoRedo)); } //Load handle matrix Handles.matrix = polyMesh.transform.localToWorldMatrix; //Draw points and lines DrawAxis(); Handles.color = Color.white; for (int i = 0; i < keyPoints.Count; i++) { Handles.color = nearestLine == i ? Color.green : Color.white; DrawSegment(i); if (selectedIndices.Contains(i)) { Handles.color = Color.green; DrawCircle(keyPoints[i], 0.08f); } else Handles.color = Color.white; DrawKeyPoint(i); if (isCurve[i]) { Handles.color = (draggingCurve && dragIndex == i) ? Color.white : Color.blue; DrawCurvePoint(i); } } //Quit on tool change if (e.type == EventType.KeyDown) { switch (e.keyCode) { case KeyCode.Q: case KeyCode.W: case KeyCode.E: case KeyCode.R: return; } } //Quit if panning or no camera exists if (Tools.current == Tool.View || (e.isMouse && e.button > 0) || Camera.current == null || e.type == EventType.ScrollWheel) return; //Quit if laying out if (e.type == EventType.Layout) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); return; } //Cursor rectangle EditorGUIUtility.AddCursorRect(new Rect(0, 0, Camera.current.pixelWidth, Camera.current.pixelHeight), mouseCursor); mouseCursor = MouseCursor.Arrow; //Extrude key state if (e.keyCode == extrudeKey) { if (extrudeKeyDown) { if (e.type == EventType.KeyUp) extrudeKeyDown = false; } else if (e.type == EventType.KeyDown) extrudeKeyDown = true; } //Update matrices and snap worldToLocal = polyMesh.transform.worldToLocalMatrix; inverseRotation = Quaternion.Inverse(polyMesh.transform.rotation) * Camera.current.transform.rotation; snap = gridSnap; //Update mouse position screenMousePosition = new Vector3(e.mousePosition.x, Camera.current.pixelHeight - e.mousePosition.y); var plane = new Plane(-polyMesh.transform.forward, polyMesh.transform.position); var ray = Camera.current.ScreenPointToRay(screenMousePosition); float hit; if (plane.Raycast(ray, out hit)) mousePosition = worldToLocal.MultiplyPoint(ray.GetPoint(hit)); else return; //Update nearest line and split position nearestLine = NearestLine(out splitPosition); //Update the state and repaint var newState = UpdateState(); if (state != newState) SetState(newState); HandleUtility.Repaint(); e.Use(); } }
public static void PingField(Rect fieldRect, UnityObject obj, bool showPredicate, bool clickPredicate, MouseCursor cursor = MouseCursor.Zoom) { CustomActionField(fieldRect, () => EditorHelper.PingObject(obj), showPredicate, clickPredicate, cursor); }
bool TryHoverCurvePoint(out int index) { if (TryHover(curvePoints, Color.white, out index)) { mouseCursor = MouseCursor.MoveArrow; return true; } return false; }
public static void PingField(UnityObject obj, bool showPredicate, bool clickPredicate, MouseCursor cursor = MouseCursor.Zoom) { PingField(GetLastRect(), obj, showPredicate, clickPredicate, cursor); }
bool TryScaleButton(Vector3 position, float size) { size *= HandleUtility.GetHandleSize(position); if (Vector3.Distance(mousePosition, position) < size) { if (e.type == EventType.MouseDown) return true; else { mouseCursor = MouseCursor.ScaleArrow; Handles.color = Color.green; } } else Handles.color = Color.white; var buffer = size / 4; Handles.DrawLine(new Vector3(position.x - size - buffer, position.y), new Vector3(position.x - size + buffer, position.y)); Handles.DrawLine(new Vector3(position.x + size - buffer, position.y), new Vector3(position.x + size + buffer, position.y)); Handles.DrawLine(new Vector3(position.x, position.y - size - buffer), new Vector3(position.x, position.y - size + buffer)); Handles.DrawLine(new Vector3(position.x, position.y + size - buffer), new Vector3(position.x, position.y + size + buffer)); Handles.RectangleCap(0, position, Quaternion.identity, size); return false; }
public static void PingField(UnityObject obj, bool showPredicate, MouseCursor cursor = MouseCursor.Zoom) { PingField(obj, showPredicate, IsLMBMouseDown(), cursor); }
/// <summary> /// Set the mouse cursor rectangle, refreshing the screen when it gets changed. /// </summary> static public void SetCursorRect (Rect rect, MouseCursor cursor) { EditorGUIUtility.AddCursorRect(rect, cursor); if (Event.current.type == EventType.MouseMove) { if (mCursor != cursor) { mCursor = cursor; Event.current.Use(); } } }
public static void SetCursor(MouseCursor cursor) { pendingCursor = cursor; }