mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-07-02 07:46:17 +00:00
Textbox HitTest fixed, new GetTextboxPoints optimised
This commit is contained in:
parent
dd9cd24b19
commit
43a64016f2
@ -117,7 +117,7 @@ BaseVertex.prototype.HitTest = function (pos)
|
|||||||
var lineFinish1 = relativePos.add(new Point(1000, 0));
|
var lineFinish1 = relativePos.add(new Point(1000, 0));
|
||||||
var lineFinish2 = relativePos.add(new Point(-1000, 0));
|
var lineFinish2 = relativePos.add(new Point(-1000, 0));
|
||||||
|
|
||||||
var pointsVertex1 = GetPointsForShape(shape, this.model.diameter + width);
|
var pointsVertex1 = GetPointsForShape(shape, this.model.diameter + width, this.mainText);
|
||||||
pointsVertex1.push(pointsVertex1[0]);
|
pointsVertex1.push(pointsVertex1[0]);
|
||||||
|
|
||||||
var hitNumber1 = 0;
|
var hitNumber1 = 0;
|
||||||
|
@ -70,32 +70,34 @@ function GetPentagonPoints(diameter)
|
|||||||
function GetTextboxPoints(diameter, text)
|
function GetTextboxPoints(diameter, text)
|
||||||
{
|
{
|
||||||
var res = [];
|
var res = [];
|
||||||
|
var width = diameter;
|
||||||
var tempContext = document.createElement('canvas').getContext('2d');
|
|
||||||
tempContext.font = "bold " + MainTextFontSize + DefaultFont;
|
|
||||||
var textWidth = tempContext.measureText(text).width + diameter / 2;
|
|
||||||
|
|
||||||
var height = diameter;
|
var height = diameter;
|
||||||
res.push(new Point(-textWidth / 2, -height / 2));
|
|
||||||
res.push(new Point(textWidth / 2, -height / 2));
|
if (text)
|
||||||
res.push(new Point(textWidth / 2, height / 2));
|
{
|
||||||
res.push(new Point(-textWidth / 2, height / 2));
|
var tempContext = document.createElement('canvas').getContext('2d');
|
||||||
|
tempContext.font = "bold " + MainTextFontSize + DefaultFont;
|
||||||
|
width = tempContext.measureText(text).width + diameter / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.push(new Point(-width / 2, -height / 2));
|
||||||
|
res.push(new Point(width / 2, -height / 2));
|
||||||
|
res.push(new Point(width / 2, height / 2));
|
||||||
|
res.push(new Point(-width / 2, height / 2));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetPointsForShape(shape, baseGraph)
|
function GetPointsForShape(shape, diameter, text=null)
|
||||||
{
|
{
|
||||||
var pointsVertex1 = null;
|
|
||||||
var diameter = baseGraph.model.diameter;
|
|
||||||
switch (parseInt(shape))
|
switch (parseInt(shape))
|
||||||
{
|
{
|
||||||
case VertexSquareShape: pointsVertex1 = GetSquarePoints(diameter); break;
|
case VertexSquareShape: return GetSquarePoints(diameter); break;
|
||||||
case VertexTriangleShape: pointsVertex1 = GetTrianglePoints(diameter); break;
|
case VertexTriangleShape: return GetTrianglePoints(diameter); break;
|
||||||
case VertexPentagonShape: pointsVertex1 = GetPentagonPoints(diameter); break;
|
case VertexPentagonShape: return GetPentagonPoints(diameter); break;
|
||||||
case VertextTextboxShape: pointsVertex1 = GetTextboxPoints(diameter, baseGraph.mainText); break;
|
case VertextTextboxShape: return GetTextboxPoints(diameter, text); break;
|
||||||
|
default: return null; break;
|
||||||
}
|
}
|
||||||
return pointsVertex1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetSizeForShape(shape, diameter)
|
function GetSizeForShape(shape, diameter)
|
||||||
@ -106,8 +108,8 @@ function GetSizeForShape(shape, diameter)
|
|||||||
case VertexTriangleShape: return diameter * 1.5; break;
|
case VertexTriangleShape: return diameter * 1.5; break;
|
||||||
case VertexPentagonShape: return diameter * 1.2; break;
|
case VertexPentagonShape: return diameter * 1.2; break;
|
||||||
case VertextTextboxShape: return diameter; break;
|
case VertextTextboxShape: return diameter; break;
|
||||||
|
default: return diameter; break;
|
||||||
}
|
}
|
||||||
return diameter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function BaseVertexStyle()
|
function BaseVertexStyle()
|
||||||
@ -342,7 +344,7 @@ BaseVertexDrawer.prototype.DrawShape = function(baseGraph)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var points = GetPointsForShape(this.currentStyle.shape, baseGraph);
|
var points = GetPointsForShape(this.currentStyle.shape, baseGraph.model.diameter, baseGraph.mainText);
|
||||||
|
|
||||||
this.context.moveTo(baseGraph.position.x + points[points.length - 1].x, baseGraph.position.y + points[points.length - 1].y);
|
this.context.moveTo(baseGraph.position.x + points[points.length - 1].x, baseGraph.position.y + points[points.length - 1].y);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user