~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/dg/sizeshapecmd.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 "nodeshape.h"
 
24
#include "shapeview.h"
 
25
#include "diagram.h"
 
26
#include "diagramviewer.h"
 
27
//#include "drawwindow.h"
 
28
#include "sizeshapecmd.h"
 
29
 
 
30
// dir = handle nr + 1
 
31
 
 
32
SizeShapeCmd::SizeShapeCmd(GShape *s, int dir)
 
33
        :Command(s->GetView()->GetViewer()->GetDiagram(), 
 
34
                s->GetView()->GetViewer()),
 
35
        fixpoint(*s->GetPosition()),
 
36
        centre(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0),
 
37
        corner(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 
38
{
 
39
        if ( ! (shape = dynamic_cast<NodeShape *>(s)) )
 
40
                error("Illegal use of size shape command");
 
41
        constrainX = False;
 
42
        constrainY = False;
 
43
        switch ( dir ) {
 
44
        case 5:
 
45
        case 6:
 
46
                constrainX = True; // only change height
 
47
                break;
 
48
        case 7:
 
49
        case 8:
 
50
                constrainY = True; // only change width
 
51
                break;
 
52
        }
 
53
        direction = dir;
 
54
        newCentre = oldCentre = *shape->GetPosition();
 
55
        newWidth = oldWidth = shape->GetWidth();
 
56
        newHeight = oldHeight = shape->GetHeight();
 
57
}
 
58
 
 
59
 
 
60
void SizeShapeCmd::TrackMouse(TrackType aPhase, Point * /* anchorPoint */,
 
61
        Point * /* previousPoint */, Point *nextPoint)
 
62
{
 
63
        switch(aPhase) {
 
64
                case TRACK_PRESS:
 
65
                        GetMainWindow()->SetSizeCursor(direction);
 
66
                        CalcSize(nextPoint);
 
67
                        Draw();
 
68
                        break;
 
69
                case TRACK_DRAG:
 
70
                        Undraw();
 
71
                        CalcSize(nextPoint);
 
72
                        Draw();
 
73
                        break;
 
74
                case TRACK_RELEASE:
 
75
                        Undraw();
 
76
                        GetMainWindow()->SetCursor(MouseCursor::LEFT_PTR);
 
77
                        break;
 
78
                default:
 
79
                        error("unknown track type\n");
 
80
                        break;
 
81
        }
 
82
}
 
83
 
 
84
 
 
85
void SizeShapeCmd::CalcSize(const Point *p) {
 
86
        double tw, th;
 
87
        newWidth = shape->GetWidth();
 
88
        newHeight = shape->GetHeight();
 
89
        tw = shape->GetName()->GetStringWidth();
 
90
        th = shape->GetName()->GetStringHeight();
 
91
        const DPoint c(ScaleCorrect(p->x), ScaleCorrect(p->y));
 
92
        corner.CalcScale(&c, fixpoint.x, fixpoint.y, &newWidth, &newHeight,
 
93
                tw, th, constrainX, constrainY);
 
94
        centre.CalcPoint(&newCentre, fixpoint.x, fixpoint.y,
 
95
                newWidth, newHeight, tw, th);
 
96
        shape->CorrectScale(&newWidth, &newHeight, constrainX, constrainY);
 
97
}
 
98
 
 
99
 
 
100
void SizeShapeCmd::Draw() {
 
101
        shape->DrawOutLine(newCentre.x, newCentre.y, newWidth, newHeight);
 
102
}
 
103
 
 
104
 
 
105
void SizeShapeCmd::Execute() {
 
106
        Command::Execute();
 
107
        Point pt(newCentre);
 
108
        shape->UpdatePosition(&pt);
 
109
        shape->UpdateSize(int(0.5 + newWidth), int(0.5 + newHeight));
 
110
        shape->GetView()->GetViewer()->ShapePositionUpdate(shape);
 
111
        GetMainWindow()->FitDocument();
 
112
}
 
113
 
 
114
 
 
115
void SizeShapeCmd::UnExecute() {
 
116
        Command::UnExecute();
 
117
        Point pt(oldCentre);
 
118
        shape->UpdatePosition(&pt);
 
119
        shape->UpdateSize(int(0.5 + oldWidth), int(0.5 + oldHeight));
 
120
        shape->GetView()->GetViewer()->ShapePositionUpdate(shape);      
 
121
}