mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
RichEdit: Diagram click test
This commit is contained in:
parent
8fb52d4835
commit
a42f6c875f
4 changed files with 34 additions and 8 deletions
|
|
@ -51,9 +51,10 @@ Point DiagramEditor::GetHandle(int i, Point p) const
|
|||
|
||||
int DiagramEditor::FindItem(Point p) const
|
||||
{
|
||||
for(int i = data.item.GetCount() - 1; i >= 0; i--)
|
||||
if(data.item[i].IsClick(p))
|
||||
return i;
|
||||
for(int pass = 0; pass < 2; pass++)
|
||||
for(int i = data.item.GetCount() - 1; i >= 0; i--)
|
||||
if(data.item[i].IsClick(p, data, pass))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -326,7 +327,7 @@ void DiagramEditor::RightDown(Point p, dword keyflags)
|
|||
Sync();
|
||||
return;
|
||||
}
|
||||
if(m.IsClick(p)) {
|
||||
if(m.IsClick(p, data)) {
|
||||
ColumnPopUp menu;
|
||||
menu.count = DiagramItem::DASH_COUNT;
|
||||
menu.columns = 4;
|
||||
|
|
|
|||
|
|
@ -73,12 +73,35 @@ void DiagramItem::FixPosition()
|
|||
pt[1].y = pt[0].y + 8;
|
||||
}
|
||||
|
||||
bool DiagramItem::IsClick(Point p) const
|
||||
bool DiagramItem::IsClick(Point p, const Diagram& diagram, bool relaxed) const
|
||||
{
|
||||
if(IsLine())
|
||||
return DistanceFromSegment(p, pt[0], pt[1]) < width + 10;
|
||||
else
|
||||
return GetRect().Inflated(5).Contains(p);
|
||||
Rectf rect = GetRect();
|
||||
if(!rect.Contains(p))
|
||||
return false;
|
||||
if(shape == SHAPE_IMAGE || relaxed)
|
||||
return true;
|
||||
Image test = MakeValue(
|
||||
[&] {
|
||||
return String((const char *)&shape, sizeof(shape));
|
||||
},
|
||||
[&](Value& v) {
|
||||
ImagePainter p(64, 64);
|
||||
p.Clear(RGBAZero());
|
||||
DiagramItem m = *this;
|
||||
m.paper = Blue();
|
||||
m.ink = Blue();
|
||||
m.pt[0] = Pointf(0, 0);
|
||||
m.pt[1] = Pointf(64, 64);
|
||||
m.Paint(p, diagram);
|
||||
Image img = p.GetResult();
|
||||
v = img;
|
||||
return img.GetLength() * sizeof(RGBA);
|
||||
}
|
||||
).To<Image>();
|
||||
return test[clamp(int(64 * (p.y - rect.top) / rect.GetHeight()), 0, 63)]
|
||||
[clamp(int(64 * (p.x - rect.left) / rect.GetWidth()), 0, 63)].a;
|
||||
}
|
||||
|
||||
bool DiagramItem::IsTextClick(Point p0) const
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ struct DiagramItem : Point2 {
|
|||
|
||||
Vector<Pointf> GetConnections() const;
|
||||
|
||||
bool IsClick(Point p) const;
|
||||
bool IsClick(Point p, const Diagram& diagram, bool relaxed = false) const;
|
||||
bool IsTextClick(Point p) const;
|
||||
Rect GetTextEditRect() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -141,6 +141,8 @@ void DiagramItem::Paint(Painter& w, const Diagram& diagram, dword style, const I
|
|||
if(style & (Display::CURSOR | Display::SELECT)) {
|
||||
w.RoundedRectangle(GetRect().Inflated(2), 5)
|
||||
.Stroke(6, (style & Display::SELECT ? 30 : 200) * sel1);
|
||||
w.RoundedRectangle(GetRect().Inflated(1), 2)
|
||||
.Stroke(2, Gray());
|
||||
}
|
||||
|
||||
Rectf r(pt[0], pt[1]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue