~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipelets/move/move.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2009-12-11 21:22:35 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091211212235-5iio4nzpra64snab
Tags: 7.0.10-1
* New upstream.  Closes: #551192.
  - New build-depends: libcairo2-dev, liblua5.1-0-dev, gsfonts
  - patches/config.diff: Remove.  Upstream build system replaced.
  - Runtime lib package changed to libipe7.0.10 from libipe1c2a
  - Devel package renamed to libipe-dev (from libipe1-dev)
  - Package ipe depends on lua5.1 due to ipe-update-master.

* rules: Re-write to use dh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// --------------------------------------------------------------------
2
 
// Ipelet  for moving objekts in small steps,
3
 
// best used with shortcuts
4
 
// --------------------------------------------------------------------
5
 
/*
6
 
 
7
 
    This file is part of the extensible drawing editor Ipe.
8
 
    Copyright (C) 1993-2007  Otfried Cheong
9
 
 
10
 
    Ipe is free software; you can redistribute it and/or modify it
11
 
    under the terms of the GNU General Public License as published by
12
 
    the Free Software Foundation; either version 2 of the License, or
13
 
    (at your option) any later version.
14
 
 
15
 
    As a special exception, you have permission to link Ipe with the
16
 
    CGAL library and distribute executables, as long as you follow the
17
 
    requirements of the Gnu General Public License in regard to all of
18
 
    the software in the executable aside from CGAL.
19
 
 
20
 
    Ipe is distributed in the hope that it will be useful, but WITHOUT
21
 
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22
 
    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
23
 
    License for more details.
24
 
 
25
 
    You should have received a copy of the GNU General Public License
26
 
    along with Ipe; if not, you can find it at
27
 
    "http://www.gnu.org/copyleft/gpl.html", or write to the Free
28
 
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29
 
 
30
 
*/
31
 
 
32
 
#include "ipelib.h"
33
 
 
34
 
// --------------------------------------------------------------------
35
 
 
36
 
static const char *aboutText = "Written by Gunter Schenck";
37
 
 
38
 
class MoveIpelet : public Ipelet {
39
 
public:
40
 
  virtual int IpelibVersion() const { return IPELIB_VERSION; }
41
 
  virtual int NumFunctions() const { return 24; }
42
 
  virtual const char *Label() const { return "Move"; }
43
 
  virtual const char *SubLabel(int function) const;
44
 
  virtual void Run(int function, IpePage *page, IpeletHelper *helper);
45
 
  virtual const char *About() const { return aboutText; }
46
 
};
47
 
 
48
 
// --------------------------------------------------------------------
49
 
 
50
 
const char * const sublabel[] = {
51
 
  "right 1pt",
52
 
  "left 1pt",
53
 
  "up 1pt",
54
 
  "down 1pt",
55
 
  "right-up 1pt",
56
 
  "left-up 1pt",
57
 
  "right-down 1pt",
58
 
  "left-down 1pt",
59
 
  "right 0.1pt",
60
 
  "left 0.1pt",
61
 
  "up 0.1pt",
62
 
  "down 0.1pt",
63
 
  "right-up 0.1pt",
64
 
  "left-up 0.1pt",
65
 
  "right-down 0.1pt",
66
 
  "left-down 0.1pt",
67
 
  "right 10pt",
68
 
  "left 10pt",
69
 
  "up 10pt",
70
 
  "down 10pt",
71
 
  "right-up 10pt",
72
 
  "left-up 10pt",
73
 
  "right-down 10pt",
74
 
  "left-down 10pt"
75
 
 };
76
 
 
77
 
const char *MoveIpelet::SubLabel(int function) const
78
 
{
79
 
  return sublabel[function];
80
 
}
81
 
 
82
 
// --------------------------------------------------------------------
83
 
 
84
 
const double dpmm = 72.0 / 25.4;
85
 
 
86
 
// --------------------------------------------------------------------
87
 
 
88
 
void MoveIpelet::Run(int function, IpePage *page, IpeletHelper *helper)
89
 
{
90
 
  if (!page->HasSelection()) {
91
 
    helper->Message("Nothing selected");
92
 
    return;
93
 
  }
94
 
 
95
 
  IpeVector v;
96
 
 
97
 
  switch (function) {
98
 
// 1px
99
 
  case 0: //right
100
 
        v = IpeVector( 1, 0 );
101
 
    break;
102
 
  case 1: //left
103
 
        v = IpeVector( -1, 0 );
104
 
    break;
105
 
  case 2: //up
106
 
        v = IpeVector( 0, 1 );
107
 
    break;
108
 
  case 3: //down
109
 
        v = IpeVector( 0, -1 );
110
 
    break;
111
 
  case 4: // right-up 1pt
112
 
        v = IpeVector( 1, 1 );
113
 
    break;
114
 
  case 5: //left-up
115
 
        v = IpeVector( -1, 1 );
116
 
    break;
117
 
  case 6: //right-down
118
 
        v = IpeVector( 1, -1 );
119
 
    break;
120
 
  case 7: //left-down
121
 
        v = IpeVector( -1, -1 );
122
 
    break;
123
 
// 0.1px
124
 
  case 8: //right
125
 
        v = IpeVector( .1, 0 );
126
 
    break;
127
 
  case 9: //left
128
 
        v = IpeVector( -.1, 0 );
129
 
    break;
130
 
  case 10: //up
131
 
        v = IpeVector( 0, .1 );
132
 
    break;
133
 
  case 11: //down
134
 
        v = IpeVector( 0, -.1 );
135
 
    break;
136
 
  case 12: // right-up 1pt
137
 
        v = IpeVector( .1, .1 );
138
 
    break;
139
 
  case 13: //left-up
140
 
        v = IpeVector( -.1, .1 );
141
 
    break;
142
 
  case 14: //right-down
143
 
        v = IpeVector( .1, -.1 );
144
 
    break;
145
 
  case 15: //left-down
146
 
        v = IpeVector( -.1, -.1 );
147
 
    break;
148
 
// 10px
149
 
  case 16: //right
150
 
        v = IpeVector( 10, 0 );
151
 
    break;
152
 
  case 17: //left
153
 
        v = IpeVector( -10, 0 );
154
 
    break;
155
 
  case 18: //up
156
 
        v = IpeVector( 0, 10 );
157
 
    break;
158
 
  case 19: //down
159
 
        v = IpeVector( 0, -10 );
160
 
    break;
161
 
  case 20: // right-up 1pt
162
 
        v = IpeVector( 10, 10 );
163
 
    break;
164
 
  case 21: //left-up
165
 
        v = IpeVector( -10, 10 );
166
 
    break;
167
 
  case 22: //right-down
168
 
        v = IpeVector( 10, -10 );
169
 
    break;
170
 
  case 23: //left-down
171
 
        v = IpeVector( -10, -10 );
172
 
    break;
173
 
  default:
174
 
    return;
175
 
  }
176
 
  for (IpePage::iterator it = page->begin(); it != page->end(); ++it) {
177
 
    if (it->Select())
178
 
      it->Transform(IpeMatrix(v));
179
 
  }
180
 
}
181
 
 
182
 
// --------------------------------------------------------------------
183
 
 
184
 
IPELET_DECLARE Ipelet *NewIpelet()
185
 
{
186
 
  return new MoveIpelet;
187
 
}
188
 
 
189
 
// --------------------------------------------------------------------