~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/dg/draghandlecmd.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
 
4
// (c) copyright 1995, Vrije Universiteit Amsterdam.
 
5
// Author: Frank Dehne (frank@cs.vu.nl).
 
6
//
 
7
// TCM is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// TCM is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with TCM; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
20
// 02111-1307, USA.
 
21
////////////////////////////////////////////////////////////////////////////////
 
22
#include "grafport.h"
 
23
#include "line.h"
 
24
#include "shapeview.h"
 
25
#include "diagramviewer.h"
 
26
#include "draghandlecmd.h"
 
27
 
 
28
DragHandleCmd::DragHandleCmd(Line *l, unsigned n): DragShapeCmd(l) {
 
29
        line = l;
 
30
        handleNr = n;
 
31
        oldPt = *(*line->GetLine())[handleNr];
 
32
}
 
33
 
 
34
void DragHandleCmd::CalcPoints() {
 
35
        oldPt = *(*line->GetLine())[handleNr];
 
36
        Point pt = oldPt;
 
37
        pt = pt + *GetDelta();
 
38
        if (pt.x <= 0)
 
39
                pt.x = Shape::HANDLE_WIDTH/2;
 
40
        if (pt.y <= 0)
 
41
                pt.y = Shape::HANDLE_WIDTH/2;
 
42
        GetView()->Snap(&pt);
 
43
        newPt = pt;
 
44
}
 
45
 
 
46
void DragHandleCmd::Erase() {
 
47
        line->Undraw();
 
48
        CalcPoints();
 
49
}
 
50
 
 
51
void DragHandleCmd::Redraw() {
 
52
        line->CalcPosition();
 
53
        line->Draw();
 
54
}
 
55
 
 
56
void DragHandleCmd::Execute() {
 
57
        CalcPoints();
 
58
        if (newPt == oldPt) {
 
59
                SayAborted();
 
60
                Abort();
 
61
                return;
 
62
        }
 
63
        Command::Execute();
 
64
        Executable();
 
65
}
 
66
 
 
67
void DragHandleCmd::Executable() {
 
68
        line->Undraw();
 
69
        line->SetPoint(&newPt, handleNr);
 
70
        line->CalcEndPoint(&newPt, handleNr);
 
71
        Redraw();
 
72
        if (Toolkit::EditorWithInterEdgeConnections(GetMainWindow()->GetTool()))
 
73
                line->GetView()->GetViewer()->ShapePositionUpdate(line);
 
74
}
 
75
 
 
76
void DragHandleCmd::UnExecute() {
 
77
        Command::UnExecute();
 
78
        ReverseDelta();
 
79
        line->Undraw();
 
80
        line->SetPoint(&oldPt, handleNr);
 
81
        line->CalcEndPoint(&oldPt, handleNr);
 
82
        Redraw();
 
83
        if (Toolkit::EditorWithInterEdgeConnections(GetMainWindow()->GetTool()))
 
84
                line->GetView()->GetViewer()->ShapePositionUpdate(line);
 
85
}
 
86
 
 
87
void DragHandleCmd::ReverseDelta() {
 
88
        Point virtualPt = Point (oldPt + *GetDelta());
 
89
        Point virtualDelta = newPt - virtualPt; 
 
90
        Point d = *GetDelta() + virtualDelta;
 
91
        d = -d;
 
92
        SetDelta(&d);
 
93
}
 
94
 
 
95
void DragHandleCmd::DrawLines(const Point *p1, const Point *p2, 
 
96
                                const Point *p3) {
 
97
        // feedback of handle
 
98
        GetGrafport()->SetLineStyle(LineStyle::DOTTED);
 
99
        GetGrafport()->SetLineWidth(1);
 
100
        GetGrafport()->SetForegroundColor("black");
 
101
        GetGrafport()->DrawRectangle(p1->x - Shape::HANDLE_WIDTH/2, 
 
102
                p1->y - Shape::HANDLE_WIDTH/2, 
 
103
                Shape::HANDLE_WIDTH, Shape::HANDLE_WIDTH);
 
104
        // feedback of lines
 
105
        GetGrafport()->DrawLine(p1->x, p1->y, p2->x, p2->y);
 
106
        GetGrafport()->DrawLine(p1->x, p1->y, p3->x, p3->y);
 
107
}
 
108
 
 
109
void DragHandleCmd::DrawOutLine(const Point *d) {
 
110
        Point p1 = oldPt + ScaleCorrect(d);
 
111
        GetView()->Snap(&p1);
 
112
        Point p2, p3;
 
113
        // get left and right line segments
 
114
        if (check(line->GetSegments(oldPt, &p2, &p3)))
 
115
                DrawLines(&p1, &p2, &p3);
 
116
}