mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-22 22:04:00 -06:00
RichEdit: Developing Diagram
This commit is contained in:
parent
de0c179212
commit
ff64443ba6
6 changed files with 63 additions and 3 deletions
|
|
@ -224,6 +224,7 @@ void DiagramEditor::Commit()
|
|||
SetBar();
|
||||
Sync();
|
||||
}
|
||||
conns.Clear();
|
||||
}
|
||||
|
||||
String DiagramEditor::GetCurrent()
|
||||
|
|
|
|||
|
|
@ -60,8 +60,17 @@ private:
|
|||
bool grid = true; // snap to grid
|
||||
bool edit_text = false; // text editor is visible
|
||||
int zoom_percent = 100;
|
||||
|
||||
struct Cn : Moveable<Cn> {
|
||||
int mi; // item index
|
||||
int ci; // connection index
|
||||
int li; // line item index
|
||||
int pi; // point index
|
||||
};
|
||||
|
||||
Vector<Cn> conns; // connections, created at the drag start, updates line connections
|
||||
|
||||
BinUndoRedo undoredo;
|
||||
BinUndoRedo undoredo;
|
||||
|
||||
int tool = 0;
|
||||
ToolBar toolbar;
|
||||
|
|
@ -103,6 +112,8 @@ private:
|
|||
Image ShapeIcon(int i);
|
||||
Image CapIcon(int start, int end);
|
||||
Image DashIcon(int i);
|
||||
void PrepareConns();
|
||||
void UseConns();
|
||||
|
||||
|
||||
void FixPositions();
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ void DiagramEditor::LeftDouble(Point p, dword keyflags)
|
|||
|
||||
void DiagramEditor::LeftDown(Point p, dword keyflags)
|
||||
{
|
||||
conns.Clear();
|
||||
|
||||
Map(p);
|
||||
|
||||
FinishText();
|
||||
|
|
@ -110,6 +112,7 @@ void DiagramEditor::LeftDown(Point p, dword keyflags)
|
|||
if(h.x || h.y) {
|
||||
draghandle = h;
|
||||
Sync();
|
||||
PrepareConns();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -127,6 +130,7 @@ void DiagramEditor::LeftDown(Point p, dword keyflags)
|
|||
sdragfrom.SetCount(sel.GetCount());
|
||||
for(int i = 0; i < sel.GetCount(); i++)
|
||||
sdragfrom[i] = data.item[sel[i]];
|
||||
PrepareConns();
|
||||
draghandle = Null;
|
||||
}
|
||||
}
|
||||
|
|
@ -185,6 +189,7 @@ void DiagramEditor::MouseMove(Point p, dword keyflags)
|
|||
Do(draghandle.y, m.pt[0].y, m.pt[1].y, p.y);
|
||||
}
|
||||
m.FixPosition();
|
||||
UseConns();
|
||||
Sync();
|
||||
return;
|
||||
}
|
||||
|
|
@ -192,6 +197,8 @@ void DiagramEditor::MouseMove(Point p, dword keyflags)
|
|||
|
||||
void DiagramEditor::LeftUp(Point p, dword keyflags)
|
||||
{
|
||||
conns.Clear();
|
||||
|
||||
Map(p);
|
||||
|
||||
Sync();
|
||||
|
|
|
|||
|
|
@ -105,6 +105,47 @@ void DiagramEditor::Align(bool horz, int align)
|
|||
Commit();
|
||||
}
|
||||
|
||||
void DiagramEditor::PrepareConns()
|
||||
{
|
||||
conns.Clear();
|
||||
VectorMap<Pointf, Vector<Tuple<int, int>>> map;
|
||||
for(int pass = 0; pass < 2; pass++)
|
||||
for(int i = 0; i < data.item.GetCount(); i++) {
|
||||
const DiagramItem& m = data.item[i];
|
||||
if(m.IsLine() == pass) {
|
||||
Vector<Pointf> cp = m.GetConnections();
|
||||
for(int j = 0; j < cp.GetCount(); j++)
|
||||
map.GetAdd(cp[j]) << MakeTuple(i, j);
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < data.item.GetCount(); i++) {
|
||||
const DiagramItem& m = data.item[i];
|
||||
if(m.IsLine()) {
|
||||
for(int j = 0; j < 2; j++) {
|
||||
auto *q = map.FindPtr(m.pt[j]);
|
||||
if(q) {
|
||||
for(auto w : *q) {
|
||||
Cn& c = conns.Add();
|
||||
c.mi = w.a;
|
||||
c.ci = w.b;
|
||||
c.li = i;
|
||||
c.pi = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramEditor::UseConns()
|
||||
{
|
||||
for(const Cn& cn: conns)
|
||||
if(sel.Find(cn.li) < 0)
|
||||
data.item[cn.li].pt[cn.pi] = data.item[cn.mi].GetConnections()[cn.ci];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* TODO remove
|
||||
|
||||
struct SizeDlg : WithSizeLayout<TopWindow> {
|
||||
|
|
@ -32,7 +32,7 @@ file
|
|||
DiagramEditor.cpp,
|
||||
DiagramMouse.cpp,
|
||||
DiagramCursor.cpp,
|
||||
Ops.cpp,
|
||||
DiagramOps.cpp,
|
||||
ColumnPopUp.cpp,
|
||||
Bar.cpp,
|
||||
Text.cpp,
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ void DiagramItem::Paint(Painter& w, dword style) const
|
|||
|
||||
if(style & EDITOR)
|
||||
for(Pointf p : GetConnections())
|
||||
w.Circle(p, 4).Stroke(1, 128 * SColorHighlight());
|
||||
w.Circle(p, 4).Stroke(1, 190 * SColorHighlight());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue