mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Round dragged points and collision masks vertices of sprites (#5124)
This commit is contained in:
@@ -4,6 +4,7 @@ import { mapVector } from '../../../../Utils/MapFor';
|
||||
import useForceUpdate from '../../../../Utils/UseForceUpdate';
|
||||
import { dataObjectToProps } from '../../../../Utils/HTMLDataset';
|
||||
import {
|
||||
roundVertexToHalfPixel,
|
||||
findNearestEdgePoint,
|
||||
getMagnetizedVertexForDeletion,
|
||||
type NewVertexHintPoint,
|
||||
@@ -217,6 +218,7 @@ const CollisionMasksPreview = (props: Props) => {
|
||||
onPolygonsUpdated();
|
||||
onClickVertice(null);
|
||||
} else {
|
||||
roundVertexToHalfPixel(draggedVertex.vertex);
|
||||
onPolygonsUpdated();
|
||||
onClickVertice(draggedVertex.vertex.ptr);
|
||||
}
|
||||
|
@@ -3,6 +3,11 @@ import { mapFor, mapVector } from '../../../../Utils/MapFor';
|
||||
|
||||
const gd = global.gd;
|
||||
|
||||
export const roundVertexToHalfPixel = (vertex: gdVector2f) => {
|
||||
vertex.set_x(Math.round(vertex.get_x() * 2) / 2);
|
||||
vertex.set_y(Math.round(vertex.get_y() * 2) / 2);
|
||||
};
|
||||
|
||||
export const addVertexOnLongestEdge = (vertices: gdVectorVector2f) => {
|
||||
const verticesSize = vertices.size();
|
||||
if (verticesSize > 0) {
|
||||
|
@@ -29,6 +29,11 @@ const getPointName = (kind: PointKind, point: gdPoint): string =>
|
||||
? 'Center'
|
||||
: point.getName();
|
||||
|
||||
const roundPointToHalfPixel = (point: gdPoint) => {
|
||||
point.setX(Math.round(point.getX() * 2) / 2);
|
||||
point.setY(Math.round(point.getY() * 2) / 2);
|
||||
};
|
||||
|
||||
type Props = {|
|
||||
pointsContainer: gdSprite, // Could potentially be generalized to other things than Sprite in the future.
|
||||
imageWidth: number,
|
||||
@@ -101,8 +106,8 @@ const PointsPreview = (props: Props) => {
|
||||
|
||||
const onEndDragPoint = React.useCallback(
|
||||
() => {
|
||||
const draggingWasDone = !!state.draggedPoint;
|
||||
if (draggingWasDone) {
|
||||
if (state.draggedPoint) {
|
||||
roundPointToHalfPixel(state.draggedPoint);
|
||||
onPointsUpdated();
|
||||
// Select point at the end of the drag
|
||||
if (state.draggedPointKind && state.draggedPoint) {
|
||||
|
Reference in New Issue
Block a user