mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
RichEdit: Commit before refactoring DiagramEditor
This commit is contained in:
parent
0e1baf7ee9
commit
daad50c9e0
6 changed files with 57 additions and 64 deletions
|
|
@ -5,12 +5,9 @@ namespace Upp {
|
|||
void DiagramEditor::SetCursor(int i)
|
||||
{
|
||||
cursor = i;
|
||||
if(i < 0) {
|
||||
ink <<= Black();
|
||||
paper <<= Black();
|
||||
}
|
||||
else
|
||||
sel.FindAdd(i);
|
||||
if(i < 0)
|
||||
return;
|
||||
sel.FindAdd(i);
|
||||
GetAttrs();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ private:
|
|||
Image CapIcon(int start, int end);
|
||||
|
||||
|
||||
void FixPositions();
|
||||
void SetAttrs();
|
||||
void GetAttrs();
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ void DiagramEditor::LeftDown(Point p, dword keyflags)
|
|||
|
||||
SetCapture();
|
||||
|
||||
if(IsCursor()) {
|
||||
if(IsCursor()) { // resize
|
||||
Point h = GetHandle(cursor, p);
|
||||
if(h.x || h.y) {
|
||||
draghandle = h;
|
||||
|
|
@ -112,13 +112,9 @@ void DiagramEditor::LeftDown(Point p, dword keyflags)
|
|||
}
|
||||
}
|
||||
|
||||
if((keyflags & K_CTRL) == 0) {
|
||||
sel.Clear();
|
||||
cursor = -1;
|
||||
}
|
||||
newitem = false;
|
||||
int i = FindItem(p);
|
||||
if(i >= 0) {
|
||||
if(i >= 0) { // start moving selection
|
||||
SetCursor(i);
|
||||
dragfrom = GetCursorRect();
|
||||
if(dragfrom.Contains(p)) {
|
||||
|
|
@ -129,14 +125,15 @@ void DiagramEditor::LeftDown(Point p, dword keyflags)
|
|||
}
|
||||
}
|
||||
else
|
||||
if(mode < 0) {
|
||||
if(mode < 0) { // rectangular selection
|
||||
sel.Clear();
|
||||
doselection = true;
|
||||
}
|
||||
else {
|
||||
else { // add new item
|
||||
CancelSelection();
|
||||
DiagramItem& m = data.item.Add();
|
||||
m.p1 = m.p2 = p;
|
||||
m.shape = mode;
|
||||
dragstart = p;
|
||||
draghandle = Point(1, 1);
|
||||
newitem = true;
|
||||
|
|
@ -152,7 +149,7 @@ void DiagramEditor::MouseMove(Point p, dword keyflags)
|
|||
{
|
||||
Map(p);
|
||||
|
||||
if(HasCapture() && doselection) {
|
||||
if(HasCapture() && doselection) { // do rectangular selection
|
||||
dragcurrent = p;
|
||||
Rect r(dragstart, dragcurrent);
|
||||
r.Normalize();
|
||||
|
|
@ -170,7 +167,7 @@ void DiagramEditor::MouseMove(Point p, dword keyflags)
|
|||
DiagramItem& m = CursorItem();
|
||||
if(grid)
|
||||
p = m.IsLine() ? p / 16 * 16 : p / 8 * 8;
|
||||
if(IsNull(draghandle)) {
|
||||
if(IsNull(draghandle)) { // move selection
|
||||
Point offset = p - dragstart;
|
||||
Rect to = dragfrom.Offseted(offset);
|
||||
m.p1 = to.TopLeft();
|
||||
|
|
@ -179,6 +176,7 @@ void DiagramEditor::MouseMove(Point p, dword keyflags)
|
|||
int ii = sel[i];
|
||||
if(ii >= 0 && ii < data.item.GetCount() && i < sdragfrom.GetCount()) {
|
||||
(Point2 &)data.item[ii] = sdragfrom[i].Offseted(offset);
|
||||
data.item[ii].FixPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -187,7 +185,9 @@ void DiagramEditor::MouseMove(Point p, dword keyflags)
|
|||
(draghandle.x < 0 ? m.p1.x : m.p2.x) = p.x;
|
||||
if(draghandle.y)
|
||||
(draghandle.y < 0 ? m.p1.y : m.p2.y) = p.y;
|
||||
DDUMP(m.GetRect());
|
||||
}
|
||||
m.FixPosition();
|
||||
Sync();
|
||||
}
|
||||
}
|
||||
|
|
@ -197,56 +197,32 @@ void DiagramEditor::LeftUp(Point p, dword keyflags)
|
|||
Map(p);
|
||||
|
||||
Sync();
|
||||
if(!doselection && IsCursor() && newitem) {
|
||||
if(!doselection && IsCursor() && newitem) { // avoid empty items
|
||||
DiagramItem& m = CursorItem();
|
||||
if(Distance(m.p1, m.p2) < 4) {
|
||||
m.p1 -= Pointf(-10, -10);
|
||||
m.p2 += Pointf(10, 10);
|
||||
m.p1 -= Pointf(32, 32);
|
||||
m.p2 += Pointf(32, 32);
|
||||
m.FixPosition();
|
||||
}
|
||||
}
|
||||
doselection = false;
|
||||
Commit();
|
||||
if(Distance(dragstart, p) < 2 && CursorItem().IsTextClick(p) && !newitem) {
|
||||
StartText();
|
||||
return;
|
||||
if(Distance(dragstart, p) < 2) {
|
||||
if((keyflags & K_CTRL) == 0) {
|
||||
sel.Clear();
|
||||
sel.FindAdd(cursor);
|
||||
}
|
||||
if(CursorItem().IsTextClick(p) && !newitem)
|
||||
StartText();
|
||||
}
|
||||
newitem = false;
|
||||
if(mode >= 0) {
|
||||
mode = -1;
|
||||
SetBar();
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramEditor::RightDown(Point p, dword keyflags)
|
||||
{
|
||||
Map(p);
|
||||
|
||||
FinishText();
|
||||
DiagramItem s;
|
||||
s.p1 = Point(0, 0);
|
||||
s.p2 = Point(256, 64);
|
||||
if(IsCursor())
|
||||
s = CursorItem();
|
||||
else
|
||||
if(data.item.GetCount())
|
||||
s = data.item.Top();
|
||||
CancelSelection();
|
||||
DiagramItem& m = data.item.Add();
|
||||
m = s;
|
||||
Pointf pf = p;
|
||||
if(m.IsLine()) {
|
||||
m.p1 = pf + Pointf(-50, 0);
|
||||
m.p2 = m.p1 + Pointf(100, 0);
|
||||
}
|
||||
else {
|
||||
Sizef sz = m.GetRect().GetSize();
|
||||
m.p1 = p - sz / 2;
|
||||
if(grid)
|
||||
m.p1 = 8 * (Point)m.p1 / 8;
|
||||
m.p2 = m.p1 + s.GetRect().GetSize();
|
||||
}
|
||||
m.qtf.Clear();
|
||||
dragstart = p;
|
||||
SetCursor(data.item.GetCount() - 1);
|
||||
Sync();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,14 +20,16 @@ void DiagramEditor::SetAttrs()
|
|||
|
||||
void DiagramEditor::GetAttrs()
|
||||
{
|
||||
DiagramItem& m = CursorItem();
|
||||
shape_i <<= m.shape;
|
||||
line_start <<= m.line_start;
|
||||
line_end <<= m.line_end;
|
||||
line_width <<= m.width;
|
||||
line_dash <<= m.dash;
|
||||
ink <<= m.ink;
|
||||
paper <<= m.paper;
|
||||
if(IsCursor()) {
|
||||
DiagramItem& m = CursorItem();
|
||||
shape_i <<= m.shape;
|
||||
line_start <<= m.line_start;
|
||||
line_end <<= m.line_end;
|
||||
line_width <<= m.width;
|
||||
line_dash <<= m.dash;
|
||||
ink <<= m.ink;
|
||||
paper <<= m.paper;
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramEditor::MoveFrontBack(bool back)
|
||||
|
|
|
|||
|
|
@ -45,6 +45,20 @@ void Point2::Normalize()
|
|||
Swap(p1.y, p2.y);
|
||||
}
|
||||
|
||||
void DiagramItem::FixPosition()
|
||||
{
|
||||
double x = min(p1.x, p2.x);
|
||||
if(x < 0) {
|
||||
p1.x -= x;
|
||||
p2.x -= x;
|
||||
}
|
||||
double y = min(p1.y, p2.y);
|
||||
if(y < 0) {
|
||||
p1.y -= y;
|
||||
p2.y -= y;
|
||||
}
|
||||
}
|
||||
|
||||
bool DiagramItem::IsClick(Point p) const
|
||||
{
|
||||
if(IsLine())
|
||||
|
|
@ -307,6 +321,7 @@ void DiagramItem::Load(CParser& p)
|
|||
else
|
||||
p.Skip();
|
||||
}
|
||||
FixPosition();
|
||||
}
|
||||
|
||||
Size Diagram::GetSize() const
|
||||
|
|
@ -332,12 +347,12 @@ Size Diagram::GetSize() const
|
|||
|
||||
void Diagram::Paint(Painter& w, const Diagram::PaintInfo& p) const
|
||||
{
|
||||
w.Begin();
|
||||
/* w.Begin();
|
||||
if(img_hd)
|
||||
w.Scale(0.5);
|
||||
w.DrawImage(0, 0, img);
|
||||
w.End();
|
||||
for(int i = 0; i < item.GetCount(); i++) {
|
||||
*/ for(int i = 0; i < item.GetCount(); i++) {
|
||||
dword style = 0;
|
||||
if(i == p.cursor)
|
||||
style = Display::CURSOR;
|
||||
|
|
@ -357,13 +372,13 @@ void Diagram::Serialize(Stream& s)
|
|||
|
||||
void Diagram::Save(StringBuffer& r) const
|
||||
{
|
||||
if(!IsNull(img)) {
|
||||
/* if(!IsNull(img)) {
|
||||
r << "bk_image ";
|
||||
if(img_hd)
|
||||
r << "HD ";
|
||||
r << AsCString(Base64Encode(PNGEncoder().SaveString(img))) << ";\n";
|
||||
}
|
||||
for(const DiagramItem& m : item) {
|
||||
*/ for(const DiagramItem& m : item) {
|
||||
m.Save(r);
|
||||
r << '\n';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ struct DiagramItem : Point2 {
|
|||
bool IsTextClick(Point p) const;
|
||||
Rect GetTextEditRect() const;
|
||||
|
||||
void FixPosition();
|
||||
|
||||
void Serialize(Stream& s) { Point2::Serialize(s); s % shape % ink % paper % qtf % width % line_start % line_end % dash; }
|
||||
|
||||
void Reset();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue