feat: rounded corners for display
This commit is contained in:
parent
a47aee1561
commit
e4ad9cc2f1
23 changed files with 337 additions and 282 deletions
|
@ -1,40 +0,0 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SatorImaging.AppWindowUtility {
|
||||
public static class ResizeHelper {
|
||||
public static Vector2 GetDirection(Vector2 mousePosition, Vector2 screenSize) {
|
||||
float widthPercentage = mousePosition.x / screenSize.x;
|
||||
float heightPercentage = mousePosition.y / screenSize.y;
|
||||
|
||||
const float marginHeightPercentage = 30f / 1920f;
|
||||
const float marginWidthPercentage = 30f / 1280f;
|
||||
|
||||
if (widthPercentage < marginWidthPercentage) {
|
||||
if (heightPercentage > 1 - marginHeightPercentage)
|
||||
return new Vector2(-1, -1);
|
||||
if (heightPercentage < marginHeightPercentage)
|
||||
return new Vector2(-1, 1);
|
||||
|
||||
return new Vector2(-1, 0);
|
||||
}
|
||||
|
||||
if (widthPercentage > 1 - marginWidthPercentage) {
|
||||
if (heightPercentage > 1 - marginHeightPercentage)
|
||||
return new Vector2(1, -1);
|
||||
if (heightPercentage < marginHeightPercentage)
|
||||
return new Vector2(1, 1);
|
||||
|
||||
return new Vector2(1, 0);
|
||||
}
|
||||
|
||||
if (heightPercentage > 1 - marginHeightPercentage)
|
||||
return new Vector2(0, -1);
|
||||
|
||||
if (heightPercentage < marginHeightPercentage)
|
||||
return new Vector2(0, 1);
|
||||
|
||||
return Vector2.zero;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f5b1e31614e4b458c18c903a3934198
|
||||
timeCreated: 1713212603
|
|
@ -7,7 +7,6 @@ namespace SatorImaging.AppWindowUtility {
|
|||
|
||||
private bool _isDragging;
|
||||
private Vector2 _targetPosition = Vector2.zero;
|
||||
private Vector2 _resizeDirection = Vector2.zero;
|
||||
|
||||
private void Update() {
|
||||
#if UNITY_EDITOR
|
||||
|
@ -20,12 +19,10 @@ namespace SatorImaging.AppWindowUtility {
|
|||
|
||||
if (Input.GetMouseButtonDown((int)mouseButton)) {
|
||||
_targetPosition = Event.current.mousePosition;
|
||||
_resizeDirection =
|
||||
ResizeHelper.GetDirection(_targetPosition, new Vector2(Screen.width, Screen.height));
|
||||
_isDragging = true;
|
||||
}
|
||||
|
||||
if (_isDragging && Input.GetMouseButton((int)mouseButton) && _resizeDirection == Vector2.zero) {
|
||||
if (_isDragging && Input.GetMouseButton((int)mouseButton)) {
|
||||
// do NOT use Event.current.delta. it's sampled in local window coordinate.
|
||||
// and moving window while mouse dragging changes coordinate sample by sample.
|
||||
// just remove the gap between current mouse position and drag starting position.
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace SatorImaging.AppWindowUtility {
|
||||
public class WindowResizer : MonoBehaviour {
|
||||
public MouseButton mouseButton;
|
||||
|
||||
private bool _isResizing;
|
||||
private Vector2 _targetPosition = Vector2.zero;
|
||||
private Vector2 _resizeDirection = Vector2.zero;
|
||||
|
||||
[SerializeField] private Vector2 aspectRatio = new(10, 15);
|
||||
|
||||
private void Update() {
|
||||
#if UNITY_EDITOR
|
||||
if (_isResizing.Equals(_isResizing)) return; // to avoid CS0162 warning
|
||||
#endif
|
||||
|
||||
if (EventSystem.current?.currentSelectedGameObject) return;
|
||||
|
||||
if (Input.GetMouseButtonUp((int)mouseButton)) _isResizing = false;
|
||||
|
||||
if (Input.GetMouseButtonDown((int)mouseButton)) {
|
||||
_targetPosition = Event.current.mousePosition;
|
||||
_resizeDirection =
|
||||
ResizeHelper.GetDirection(_targetPosition, new Vector2(Screen.width, Screen.height));
|
||||
_isResizing = true;
|
||||
}
|
||||
|
||||
if (_isResizing && Input.GetMouseButton((int)mouseButton) && _resizeDirection != Vector2.zero) {
|
||||
float ratio = aspectRatio.x / aspectRatio.y;
|
||||
|
||||
Vector2 delta = new(
|
||||
Event.current.mousePosition.x - _targetPosition.x,
|
||||
Event.current.mousePosition.y - _targetPosition.y
|
||||
);
|
||||
|
||||
AppWindowUtility.ResizeWindowRelative(delta.x, delta.y, _resizeDirection, ratio);
|
||||
|
||||
_targetPosition = Event.current.mousePosition;
|
||||
|
||||
if (_resizeDirection.x < 0)
|
||||
_targetPosition.x -= delta.x;
|
||||
if (_resizeDirection.y > 0)
|
||||
_targetPosition.y -= delta.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0d779b53ae5c4644b516e84fdc31fcdc
|
||||
timeCreated: 1713211016
|
Loading…
Add table
Add a link
Reference in a new issue