Debian Codegraph @

fontforgeexe/cvpointer.c

raw symbols SCIP
1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <fontforge-config.h>
29
30 #include "charview_private.h"
31 #include "cvundoes.h"
32 #include "fontforgeui.h"
33 #include "spiro.h"
34 #include "splinefit.h"
35 #include "splineutil.h"
36 #include "splineutil2.h"
37 #include "utype.h"
38
39 #include <math.h>
40 extern void BackTrace( const char* msg );
41
42 int stop_at_join = false;
43 extern int interpCPsOnMotion;
44
45 int CVAnySel(CharView *cv, int *anyp, int *anyr, int *anyi, int *anya) {
46 int anypoints = 0, anyrefs=0, anyimages=0, anyanchor=0;
47 SplinePointList *spl;
48 RefChar *rf;
49 ImageList *il;
50 AnchorPoint *ap;
51
52 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL && !anypoints; spl = spl->next ) {
53 anypoints = SplinePointListCheckSelected1(spl, cv->b.sc->inspiro && hasspiro(), NULL, true);
54 }
55 for ( rf=cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL && !anyrefs; rf=rf->next )
56 if ( rf->selected ) anyrefs = true;
57 if ( cv->b.drawmode==dm_fore ) {
58 if ( cv->showanchor && anya!=NULL )
59 for ( ap=cv->b.sc->anchor; ap!=NULL && !anyanchor; ap=ap->next )
60 if ( ap->selected ) anyanchor = true;
61 }
62 for ( il=cv->b.layerheads[cv->b.drawmode]->images; il!=NULL && !anyimages; il=il->next )
63 if ( il->selected ) anyimages = true;
64 if ( anyp!=NULL ) *anyp = anypoints;
65 if ( anyr!=NULL ) *anyr = anyrefs;
66 if ( anyi!=NULL ) *anyi = anyimages;
67 if ( anya!=NULL ) *anya = anyanchor;
68 return( anypoints || anyrefs || anyimages || anyanchor );
69 }
70
71 int CVAnySelPoints(CharView *cv) {
72 /* if there are any points selected */
73 SplinePointList *spl;
74 Spline *spline, *first;
75 int i;
76
77 for ( spl= cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl=spl->next ) {
78 if ( cv->b.sc->inspiro && hasspiro()) {
79 for ( i=0; i<spl->spiro_cnt-1; ++i )
80 if ( SPIRO_SELECTED(&spl->spiros[i]))
81 return( true );
82 } else {
83 if ( spl->first->selected )
84 return( true );
85 first = NULL;
86 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
87 if ( spline->to->selected )
88 return( true );
89 if ( first==NULL ) first = spline;
90 }
91 }
92 }
93 return( false );
94 }
95
96 GList_Glib*
97 CVGetSelectedPoints(CharView *cv)
98 {
99 GList_Glib* ret = 0;
100 /* if there are any points selected */
101 SplinePointList *spl;
102 Spline *spline, *first;
103 int i;
104
105 for ( spl= cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl=spl->next )
106 {
107 if ( cv->b.sc->inspiro && hasspiro())
108 {
109 for ( i=0; i<spl->spiro_cnt-1; ++i )
110 if ( SPIRO_SELECTED(&spl->spiros[i]))
111 ret = g_list_append( ret, &spl->spiros[i] );
112 }
113 else
114 {
115 if ( spl->first->selected )
116 ret = g_list_append( ret, spl->first );
117 first = NULL;
118 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next )
119 {
120 if ( spline->to->selected )
121 ret = g_list_append( ret, spline->to );
122 if ( first==NULL ) first = spline;
123 }
124 }
125 }
126 return ret;
127 }
128
129
130
131 int CVClearSel(CharView *cv) {
132 SplinePointList *spl;
133 int i;
134 Spline *spline, *first;
135 RefChar *rf;
136 ImageList *img;
137 int needsupdate = 0;
138 AnchorPoint *ap;
139
140 SplinePointListFree(cv->p.pretransform_spl);
141 cv->p.pretransform_spl = NULL;
142
143 cv->lastselpt = NULL; cv->lastselcp = NULL;
144 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next )
145 {
146 if ( spl->first->selected )
147 {
148 needsupdate = true;
149 spl->first->selected = false;
150 spl->first->nextcpselected = false;
151 spl->first->prevcpselected = false;
152 }
153 first = NULL;
154 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next )
155 {
156 if ( spline->to->selected )
157 {
158 needsupdate = true;
159 spline->to->selected = false;
160 spline->to->nextcpselected = false;
161 spline->to->prevcpselected = false;
162 }
163 if ( first==NULL )
164 first = spline;
165 }
166 for ( i=0 ; i<spl->spiro_cnt-1; ++i )
167 if ( SPIRO_SELECTED(&spl->spiros[i]))
168 {
169 needsupdate = true;
170 SPIRO_DESELECT(&spl->spiros[i]);
171 }
172 }
173 for ( rf=cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL; rf = rf->next )
174 if ( rf->selected )
175 {
176 needsupdate = true;
177 rf->selected = false;
178 }
179 if ( cv->b.drawmode == dm_fore )
180 for ( ap=cv->b.sc->anchor; ap!=NULL; ap = ap->next )
181 if ( ap->selected )
182 {
183 if ( cv->showanchor )
184 needsupdate = true;
185 ap->selected = false;
186 }
187 for ( img=cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img = img->next )
188 if ( img->selected )
189 {
190 needsupdate = true;
191 img->selected = false;
192 }
193 if ( cv->p.nextcp || cv->p.prevcp || cv->widthsel || cv->vwidthsel ||
194 cv->icsel || cv->tah_sel )
195 {
196 needsupdate = true;
197 }
198 cv->p.nextcp = cv->p.prevcp = false;
199 cv->widthsel = cv->vwidthsel = cv->lbearingsel = cv->icsel = cv->tah_sel = false;
200
201 needsupdate = 1;
202 return( needsupdate );
203 }
204
205 int CVSetSel(CharView *cv,int mask) {
206 SplinePointList *spl;
207 Spline *spline, *first;
208 RefChar *rf;
209 ImageList *img;
210 int needsupdate = 0;
211 AnchorPoint *ap;
212 RefChar *usemymetrics = HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv));
213 int i;
214
215 cv->lastselpt = NULL; cv->lastselcp = NULL;
216 if ( mask&1 ) {
217 if ( !cv->b.sc->inspiro || !hasspiro()) {
218 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
219 if ( !spl->first->selected ) { needsupdate = true; spl->first->selected = true; }
220 first = NULL;
221 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
222 if ( !spline->to->selected )
223 { needsupdate = true; spline->to->selected = true; }
224 cv->lastselpt = spline->to;
225 if ( first==NULL ) first = spline;
226 }
227 }
228 } else {
229 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
230 for ( i=0; i<spl->spiro_cnt-1; ++i ) {
231 if ( !SPIRO_SELECTED(&spl->spiros[i])) {
232 needsupdate = true;
233 SPIRO_SELECT(&spl->spiros[i]);
234 }
235 cv->lastselcp = &spl->spiros[i];
236 }
237 }
238 }
239 for ( rf=cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL; rf = rf->next )
240 if ( !rf->selected ) { needsupdate = true; rf->selected = true; }
241 for ( img=cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img = img->next )
242 if ( !img->selected ) { needsupdate = true; img->selected = true; }
243 }
244 if ( (mask&2) && cv->showanchor ) {
245 for ( ap=cv->b.sc->anchor; ap!=NULL; ap=ap->next )
246 if ( !ap->selected ) { needsupdate = true; ap->selected = true; }
247 }
248 if ( cv->p.nextcp || cv->p.prevcp )
249 needsupdate = true;
250 cv->p.nextcp = cv->p.prevcp = false;
251 if ( cv->showhmetrics && !cv->widthsel && (mask&4) && usemymetrics==NULL ) {
252 cv->widthsel = needsupdate = true;
253 cv->oldwidth = cv->b.sc->width;
254 }
255 if ( cv->showvmetrics && cv->b.sc->parent->hasvmetrics && !cv->vwidthsel && (mask&4) && usemymetrics==NULL ) {
256 cv->vwidthsel = needsupdate = true;
257 cv->oldvwidth = cv->b.sc->vwidth;
258 }
259 return( needsupdate );
260 }
261
262 void CVInvertSel(CharView *cv) {
263 SplinePointList *spl;
264 Spline *spline, *first;
265 RefChar *rf;
266 ImageList *img;
267 int i;
268
269 cv->lastselpt = NULL; cv->lastselcp = NULL;
270
271 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
272 if ( cv->b.sc->inspiro && hasspiro()) {
273 for ( i=0; i<spl->spiro_cnt-1; ++i )
274 spl->spiros[i].ty ^= 0x80;
275 } else {
276 spl->first->selected = !spl->first->selected;
277 first = NULL;
278 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
279 spline->to->selected = !spline->to->selected;
280 if ( spline->to->selected )
281 cv->lastselpt = spline->to;
282 if ( first==NULL ) first = spline;
283 }
284 /* in circular case, first point is toggled twice in above code */
285 /* so fix it here */
286 if ( spline==first && spline != NULL)
287 spl->first->selected = !spl->first->selected;
288 }
289 }
290 for ( rf=cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL; rf = rf->next )
291 rf->selected = !rf->selected;
292 for ( img=cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img = img->next )
293 img->selected = !img->selected;
294 cv->p.nextcp = cv->p.prevcp = false;
295 }
296
297 int CVAllSelected(CharView *cv) {
298 SplinePointList *spl;
299 Spline *spline, *first;
300 RefChar *rf;
301 ImageList *img;
302 int i;
303
304 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
305 if ( cv->b.sc->inspiro && hasspiro()) {
306 for ( i=0; i<spl->spiro_cnt-1; ++i )
307 if ( !SPIRO_SELECTED(&spl->spiros[i]))
308 return( false );
309 } else {
310 if ( !spl->first->selected )
311 return( false );
312 first = NULL;
313 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
314 if ( !spline->to->selected )
315 return( false );
316 if ( first==NULL ) first = spline;
317 }
318 }
319 }
320 for ( rf=cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL; rf = rf->next )
321 if ( !rf->selected )
322 return( false );
323 for ( img=cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img = img->next )
324 if ( !img->selected )
325 return( false );
326 return( true );
327 }
328
329 /* Expand (possibly empty) bounds rectangle to include another rectangle */
330 static void BoundsInclude(DBounds *bounds, bool *found, real minx, real miny,
331 real maxx, real maxy) {
332 if ( !*found ) {
333 bounds->minx = minx; bounds->miny = miny;
334 bounds->maxx = maxx; bounds->maxy = maxy;
335 *found = true;
336 return;
337 }
338 if ( minx<bounds->minx ) bounds->minx = minx;
339 if ( miny<bounds->miny ) bounds->miny = miny;
340 if ( maxx>bounds->maxx ) bounds->maxx = maxx;
341 if ( maxy>bounds->maxy ) bounds->maxy = maxy;
342 }
343
344 static bool SplineSetFindSelBounds(SplinePointList *spl, DBounds *bounds, int nosel, int inspiro) {
345 SplinePoint *sp, *first;
346 bool found = false;
347 int i;
348
349 for ( ; spl!=NULL; spl = spl->next ) {
350 if ( !inspiro ) {
351 first = NULL;
352 for ( sp = spl->first; sp!=first; sp = sp->next->to ) {
353 if ( nosel || sp->selected )
354 BoundsInclude(bounds, &found, sp->me.x, sp->me.y, sp->me.x, sp->me.y);
355 if ( first==NULL ) first = sp;
356 if ( sp->next==NULL ) break;
357 }
358 } else {
359 for ( i=0; i<spl->spiro_cnt-1; ++i )
360 if ( nosel || SPIRO_SELECTED(&spl->spiros[i]) )
361 BoundsInclude(bounds, &found, spl->spiros[i].x, spl->spiros[i].y,
362 spl->spiros[i].x, spl->spiros[i].y);
363 }
364 }
365 return( found );
366 }
367
368 /* Find bounds for selected objects, or all objects when nosel is set */
369 static bool CVSelectionBounds(CharView *cv, DBounds *bounds, bool nosel) {
370 bool found;
371 ImageList *img;
372
373 found = SplineSetFindSelBounds(cv->b.layerheads[cv->b.drawmode]->splines,
374 bounds, nosel, (cv->b.sc->inspiro && hasspiro()));
375 if ( cv->b.drawmode==dm_fore ) {
376 RefChar *rf;
377 for ( rf=cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL; rf=rf->next )
378 if ( nosel || rf->selected )
379 BoundsInclude(bounds, &found, rf->bb.minx, rf->bb.miny,
380 rf->bb.maxx, rf->bb.maxy);
381 }
382 for ( img=cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img=img->next )
383 if ( nosel || img->selected )
384 BoundsInclude(bounds, &found, img->bb.minx, img->bb.miny,
385 img->bb.maxx, img->bb.maxy);
386
387 return( found );
388 }
389
390 /* Find scale box bounds, treat no selection as 'all objects selected' */
391 bool CVScaleSelectionBounds(CharView *cv, DBounds *bounds) {
392 int anyp, anyr, anyi;
393
394 anyp = anyr = anyi = false;
395 CVAnySel(cv,&anyp,&anyr,&anyi,NULL);
396 return( CVSelectionBounds(cv, bounds, (!anyp && !anyr && !anyi)));
397 }
398
399 void CVFindCenter(CharView *cv, BasePoint *bp, int nosel) {
400 DBounds b;
401
402 if ( !CVSelectionBounds(cv, &b, nosel)) {
403 bp->x = bp->y = 0;
404 return;
405 }
406 bp->x = (b.minx+b.maxx)/2;
407 bp->y = (b.miny+b.maxy)/2;
408 }
409
410 static int OnBB(CharView *cv, DBounds *bb, real fudge) {
411
412 if ( cv->info.y < bb->miny-fudge || cv->info.y > bb->maxy+fudge ||
413 cv->info.x < bb->minx-fudge || cv->info.x > bb->maxx+fudge )
414 return( ee_none );
415
416 cv->expandorigin.x = (cv->info.x-bb->minx)<(bb->maxx-cv->info.x) ?
417 bb->maxx : bb->minx;
418 cv->expandorigin.y = (cv->info.y-bb->miny)<(bb->maxy-cv->info.y) ?
419 bb->maxy : bb->miny;
420 cv->expandwidth = cv->expandorigin.x==bb->maxx? bb->minx-bb->maxx : bb->maxx-bb->minx;
421 cv->expandheight = cv->expandorigin.y==bb->maxy? bb->miny-bb->maxy : bb->maxy-bb->miny;
422
423 if (( cv->info.x < bb->minx + fudge && cv->info.y < bb->miny+ 4*fudge ) ||
424 ( cv->info.x < bb->minx + 4*fudge && cv->info.y < bb->miny+ fudge )) {
425 return( ee_sw );
426 }
427 if (( cv->info.x < bb->minx + fudge && cv->info.y > bb->maxy- 4*fudge ) ||
428 ( cv->info.x < bb->minx + 4*fudge && cv->info.y > bb->maxy- fudge ))
429 return( ee_nw );
430 if (( cv->info.x > bb->maxx - fudge && cv->info.y < bb->miny+ 4*fudge ) ||
431 ( cv->info.x > bb->maxx - 4*fudge && cv->info.y < bb->miny+ fudge ))
432 return( ee_se );
433 if (( cv->info.x > bb->maxx - fudge && cv->info.y > bb->maxy- 4*fudge ) ||
434 ( cv->info.x > bb->maxx - 4*fudge && cv->info.y > bb->maxy- fudge ))
435 return( ee_ne );
436 if ( cv->info.x < bb->minx + fudge )
437 return( ee_right );
438 if ( cv->info.x > bb->maxx - fudge )
439 return( ee_left );
440 if ( cv->info.y < bb->miny + fudge )
441 return( ee_down );
442 if ( cv->info.y > bb->maxy - fudge )
443 return( ee_up );
444
445 return( ee_none );
446 }
447
448
449 /* Return exact bounds point represented by scale edge or corner handle */
450 void CVScaleHandlePoint(const DBounds *bb, enum expandedge edge, BasePoint *pt) {
451 real midx = (bb->minx+bb->maxx)/2;
452 real midy = (bb->miny+bb->maxy)/2;
453
454 pt->x = edge==ee_nw || edge==ee_sw || edge==ee_left ? bb->minx :
455 edge==ee_ne || edge==ee_se || edge==ee_right ? bb->maxx : midx;
456 pt->y = edge==ee_sw || edge==ee_se || edge==ee_down ? bb->miny :
457 edge==ee_nw || edge==ee_ne || edge==ee_up ? bb->maxy : midy;
458 }
459
460 /* Hit-test the scale box handles using current point-snapping tolerance */
461 static enum expandedge CVScaleHandleAt(real x, real y, real fudge, const DBounds *bb) {
462 int i;
463 static enum expandedge edges[] = { ee_nw, ee_ne, ee_se, ee_sw, // corners
464 ee_up, ee_right, ee_down, ee_left }; // edges
465
466 for ( i=0; i<sizeof(edges)/sizeof(edges[0]); ++i ) {
467 BasePoint pt;
468 CVScaleHandlePoint(bb,edges[i],&pt);
469 if ( x>=pt.x-fudge && x<=pt.x+fudge &&
470 y>=pt.y-fudge && y<=pt.y+fudge )
471 return( edges[i] );
472 }
473 return( ee_none );
474 }
475
476 /* Convert scale-handle click into transform press at that handle point */
477 bool CVScaleHandlePress(CharView *cv, real fudge) {
478 BasePoint pt;
479 DBounds bb;
480 enum expandedge edge;
481
482 if ( !CVScaleSelectionBounds(cv,&bb) ||
483 (edge = CVScaleHandleAt(cv->p.cx,cv->p.cy,fudge,&bb))==ee_none ) {
484 cv->expandedge = ee_none;
485 return( false );
486 }
487 cv->expandedge = edge;
488 CVScaleHandlePoint(&bb,edge,&pt);
489 cv->p.cx = pt.x;
490 cv->p.cy = pt.y;
491 cv->p.sp = NULL;
492 cv->p.spiro = NULL;
493 cv->p.spline = NULL;
494 cv->p.anysel = true;
495 return( true );
496 }
497
498 static void SetCur(CharView *cv) {
499 static GCursor cursors[ee_max];
500
501 if ( cursors[ee_nw]==0 ) {
502 cursors[ee_none] = ct_mypointer;
503 cursors[ee_nw] = cursors[ee_se] = ct_nwse; cursors[ee_ne] = cursors[ee_sw] = ct_nesw;
504 cursors[ee_left] = cursors[ee_right] = ct_leftright;
505 cursors[ee_up] = cursors[ee_down] = ct_updown;
506 }
507 GDrawSetCursor(cv->v,cursors[cv->expandedge]);
508 }
509
510 static int NearCaret(SplineChar *sc,real x,real fudge ) {
511 PST *pst;
512 int i;
513
514 for ( pst=sc->possub; pst!=NULL && pst->type!=pst_lcaret; pst=pst->next );
515 if ( pst==NULL )
516 return( -1 );
517 for ( i=0; i<pst->u.lcaret.cnt; ++i ) {
518 if ( x>pst->u.lcaret.carets[i]-fudge && x<pst->u.lcaret.carets[i]+fudge )
519 return( i );
520 }
521 return( -1 );
522 }
523
524 int CVNearRBearingLine( CharView* cv, real x, real fudge )
525 {
526 RefChar *usemymetrics = HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv));
527 return( cv->showhmetrics
528 && x>cv->b.sc->width-fudge
529 && x<cv->b.sc->width+fudge
530 && !cv->b.container
531 && !usemymetrics );
532 }
533 int CVNearLBearingLine( CharView* cv, real x, real fudge )
534 {
535 RefChar *usemymetrics = HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv));
536 return( cv->showhmetrics
537 && x>0-fudge
538 && x<0+fudge
539 && !cv->b.container && !usemymetrics );
540 }
541
542
543 void CVCheckResizeCursors(CharView *cv) {
544 CharViewTab* tab = CVGetActiveTab(cv);
545 RefChar *ref;
546 ImageList *img;
547 int old_ee = cv->expandedge;
548 real fudge = CVSCALE_HANDLE_FUDGE/tab->scale; // fudge factor for mouse proximity to resizer handles
549
550 cv->expandedge = ee_none;
551 /* Keep scale handle cursors active while scale is selected or dragging */
552 if ( cv->showing_tool==cvt_scale || cv->active_tool==cvt_scale || cv->b1_tool==cvt_scale ) {
553 /* Scale tool's mouse cursor driven by selection box handles */
554 DBounds bb;
555 if ( CVScaleSelectionBounds(cv,&bb) )
556 cv->expandedge = CVScaleHandleAt(cv->info.x, cv->info.y, fudge, &bb);
557
558 if ( cv->expandedge==ee_none ) // Empty scale-box area?
559 GDrawSetCursor(cv->v,ct_scale); // ..use "scale cursor", not "pointer cursor"
560 else if ( cv->expandedge!=old_ee ) // Hover changed?
561 SetCur(cv); // ..still use existing "resize cursor"
562 return;
563 }
564 if ( cv->b.drawmode!=dm_grid ) {
565 for ( ref=cv->b.layerheads[cv->b.drawmode]->refs; ref!=NULL; ref=ref->next ) if ( ref->selected ) {
566 if (( cv->expandedge = OnBB(cv,&ref->bb,fudge))!=ee_none )
567 break;
568 }
569 if ( cv->expandedge == ee_none ) {
570 RefChar *usemymetrics = HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv));
571 /* if ( cv->showhmetrics && cv->info.x > cv->b.sc->width-fudge && */
572 /* cv->info.x<cv->b.sc->width+fudge && cv->b.container==NULL && */
573 /* usemymetrics==NULL ) */
574 if ( cv->showhmetrics && NearCaret(cv->b.sc,cv->info.x,fudge)!=-1 &&
575 usemymetrics==NULL )
576 cv->expandedge = ee_right;
577 else if( CVNearRBearingLine( cv, cv->info.x, fudge ))
578 cv->expandedge = ee_right;
579 else if( CVNearLBearingLine( cv, cv->info.x, fudge ))
580 cv->expandedge = ee_left;
581 if ( cv->showvmetrics && cv->b.sc->parent->hasvmetrics && cv->b.container==NULL &&
582 cv->info.y > -cv->b.sc->vwidth - fudge + cv->b.sc->parent->ascent &&
583 cv->info.y < -cv->b.sc->vwidth + fudge + cv->b.sc->parent->ascent)
584 cv->expandedge = ee_down;
585 }
586 }
587 for ( img=cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img=img->next ) if ( img->selected ) {
588 if (( cv->expandedge = OnBB(cv,&img->bb,fudge))!=ee_none )
589 break;
590 }
591 if ( cv->expandedge!=old_ee )
592 SetCur(cv);
593 }
594
595 Undoes *CVPreserveMaybeState(CharView *cv, int isTState) {
596 if( isTState )
597 return CVPreserveTState( cv );
598 return CVPreserveState( &cv->b );
599 }
600
601 Undoes *CVPreserveTState(CharView *cv) {
602 int anyrefs;
603
604 cv->p.transany = CVAnySel(cv,NULL,&anyrefs,NULL,NULL);
605 cv->p.transanyrefs = anyrefs;
606
607 return( _CVPreserveTState(&cv->b,&cv->p));
608 }
609
610 void CVRestoreTOriginalState(CharView *cv) {
611 _CVRestoreTOriginalState(&cv->b,&cv->p);
612 }
613
614 void CVUndoCleanup(CharView *cv) {
615 _CVUndoCleanup(&cv->b,&cv->p);
616 }
617
618 static int ImgRefEdgeSelected(CharView *cv, FindSel *fs,GEvent *event) {
619 RefChar *ref;
620 ImageList *img;
621 int update;
622
623 cv->expandedge = ee_none;
624 /* Check the bounding box of references if meta is up, or if they didn't */
625 /* click on a reference edge. Point being to allow people to select */
626 /* macron or other reference which fills the bounding box */
627 if ( !(event->u.mouse.state&ksm_meta) ||
628 (fs->p->ref!=NULL && !fs->p->ref->selected)) {
629 for ( ref=cv->b.layerheads[cv->b.drawmode]->refs; ref!=NULL; ref=ref->next ) if ( ref->selected ) {
630 if (( cv->expandedge = OnBB(cv,&ref->bb,fs->fudge))!=ee_none ) {
631 ref->selected = false;
632 update = CVClearSel(cv);
633 ref->selected = true;
634 if ( update )
635 SCUpdateAll(cv->b.sc);
636 CVPreserveTState(cv);
637 cv->p.ref = ref;
638 SetCur(cv);
639 return( true );
640 }
641 }
642 }
643 for ( img=cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img=img->next ) if ( img->selected ) {
644 if (( cv->expandedge = OnBB(cv,&img->bb,fs->fudge))!=ee_none ) {
645 img->selected = false;
646 update = CVClearSel(cv);
647 img->selected = true;
648 if ( update )
649 SCUpdateAll(cv->b.sc);
650 CVPreserveTState(cv);
651 cv->p.img = img;
652 SetCur(cv);
653 return( true );
654 }
655 }
656 return( false );
657 }
658
659 void CVUnselectAllBCP( CharView *cv )
660 {
661 CVFindAndVisitSelectedControlPoints( cv, false,
662 FE_unselectBCP, 0 );
663
664 // This should happen, but it effects the single selection with mouse
665 // codepaths in bad ways as at 2013.Aug
666 /* cv->p.nextcp = 0; */
667 /* cv->p.prevcp = 0; */
668
669 }
670
671 void CVMouseDownPointer(CharView *cv, FindSel *fs, GEvent *event) {
672 int needsupdate = false;
673 int dowidth, dovwidth, doic, dotah, nearcaret;
674 int dolbearing;
675 RefChar *usemymetrics = HasUseMyMetrics(cv->b.sc,CVLayer((CharViewBase *) cv));
676 int i;
677
678 cv->p.splineAdjacentPointsSelected = 0;
679 if( cv->p.spline )
680 {
681 cv->p.splineAdjacentPointsSelected =
682 cv->p.spline->from && cv->p.spline->to
683 && cv->p.spline->from->selected && cv->p.spline->to->selected;
684 }
685
686 if ( cv->pressed==NULL )
687 cv->pressed = GDrawRequestTimer(cv->v,200,100,NULL);
688 cv->last_c.x = cv->info.x; cv->last_c.y = cv->info.y;
689 /* don't clear the selection if the things we clicked on were already */
690 /* selected, or if the user held the shift key down */
691 if ( ImgRefEdgeSelected(cv,fs,event))
692 return;
693 dowidth = CVNearRBearingLine( cv, cv->p.cx, fs->fudge );
694 dolbearing = CVNearLBearingLine( cv, cv->p.cx, fs->fudge );
695 doic = ( cv->showhmetrics && cv->b.sc->italic_correction!=TEX_UNDEF &&
696 cv->b.sc->italic_correction!=0 &&
697 cv->p.cx>cv->b.sc->width+cv->b.sc->italic_correction-fs->fudge &&
698 cv->p.cx<cv->b.sc->width+cv->b.sc->italic_correction+fs->fudge &&
699 cv->b.container==NULL );
700 dotah = ( cv->showhmetrics && cv->b.sc->top_accent_horiz!=TEX_UNDEF &&
701 cv->p.cx>cv->b.sc->top_accent_horiz-fs->fudge &&
702 cv->p.cx<cv->b.sc->top_accent_horiz+fs->fudge &&
703 cv->b.container==NULL );
704 dovwidth = ( cv->showvmetrics && cv->b.sc->parent->hasvmetrics && cv->b.container == NULL &&
705 cv->p.cy > -cv->b.sc->vwidth + cv->b.sc->parent->ascent - fs->fudge &&
706 cv->p.cy < -cv->b.sc->vwidth + cv->b.sc->parent->ascent + fs->fudge &&
707 usemymetrics==NULL );
708 cv->nearcaret = nearcaret = -1;
709 if ( cv->showhmetrics ) nearcaret = NearCaret(cv->b.sc,cv->p.cx,fs->fudge);
710 if ( (fs->p->sp==NULL || !fs->p->sp->selected) &&
711 (fs->p->spiro==NULL || !SPIRO_SELECTED(fs->p->spiro)) &&
712 (fs->p->ref==NULL || !fs->p->ref->selected) &&
713 (fs->p->img==NULL || !fs->p->img->selected) &&
714 (fs->p->ap==NULL || !fs->p->ap->selected) &&
715 (!dowidth || !cv->widthsel) &&
716 (!dolbearing || !cv->lbearingsel) &&
717 (!dovwidth || !cv->vwidthsel) &&
718 (!doic || !cv->icsel) &&
719 (!dotah || !cv->tah_sel) &&
720 !(event->u.mouse.state&ksm_shift))
721 {
722 needsupdate = CVClearSel(cv);
723 }
724
725 if ( !fs->p->anysel )
726 {
727 /* Nothing else... unless they clicked on the width line, check that */
728 if ( dowidth )
729 {
730 if ( event->u.mouse.state&ksm_shift )
731 cv->widthsel = !cv->widthsel;
732 else
733 cv->widthsel = true;
734 if ( cv->widthsel ) {
735 cv->oldwidth = cv->b.sc->width;
736 fs->p->cx = cv->b.sc->width;
737 CVInfoDraw(cv,cv->gw);
738 fs->p->anysel = true;
739 cv->expandedge = ee_right;
740 } else
741 cv->expandedge = ee_none;
742 SetCur(cv);
743 needsupdate = true;
744 }
745 if ( nearcaret!=-1 )
746 {
747 PST *pst;
748 for ( pst=cv->b.sc->possub; pst!=NULL && pst->type!=pst_lcaret; pst=pst->next );
749 cv->lcarets = pst;
750 cv->nearcaret = nearcaret;
751 cv->expandedge = ee_right;
752 SetCur(cv);
753 }
754 else if ( dolbearing )
755 {
756 if ( event->u.mouse.state&ksm_shift )
757 cv->lbearingsel = !cv->lbearingsel;
758 else
759 cv->lbearingsel = true;
760 if ( cv->lbearingsel ) {
761 // cv->oldlbearing = cv->b.sc->lbearing;
762 fs->p->cx = 0;
763 CVInfoDraw(cv,cv->gw);
764 fs->p->anysel = true;
765 cv->expandedge = ee_left;
766 } else
767 cv->expandedge = ee_none;
768 SetCur(cv);
769 needsupdate = true;
770 }
771 else if ( dovwidth )
772 {
773 if ( event->u.mouse.state&ksm_shift )
774 cv->vwidthsel = !cv->vwidthsel;
775 else
776 cv->vwidthsel = true;
777 if ( cv->vwidthsel ) {
778 cv->oldvwidth = cv->b.sc->vwidth;
779 fs->p->cy = /*cv->b.sc->parent->vertical_origin*/-cv->b.sc->vwidth;
780 CVInfoDraw(cv,cv->gw);
781 fs->p->anysel = true;
782 cv->expandedge = ee_down;
783 } else
784 cv->expandedge = ee_none;
785 SetCur(cv);
786 needsupdate = true;
787 }
788 else if ( doic )
789 {
790 if ( event->u.mouse.state&ksm_shift )
791 cv->icsel = !cv->icsel;
792 else
793 cv->icsel = true;
794 if ( cv->icsel ) {
795 cv->oldic = cv->b.sc->italic_correction+cv->b.sc->width;
796 fs->p->cx = cv->b.sc->italic_correction+cv->b.sc->width;
797 CVInfoDraw(cv,cv->gw);
798 fs->p->anysel = true;
799 cv->expandedge = ee_right;
800 } else
801 cv->expandedge = ee_none;
802 SetCur(cv);
803 needsupdate = true;
804 }
805 else if ( dotah )
806 {
807 if ( event->u.mouse.state&ksm_shift )
808 cv->tah_sel = !cv->tah_sel;
809 else
810 cv->tah_sel = true;
811 if ( cv->tah_sel ) {
812 cv->oldtah = cv->b.sc->top_accent_horiz;
813 fs->p->cx = cv->b.sc->top_accent_horiz;
814 CVInfoDraw(cv,cv->gw);
815 fs->p->anysel = true;
816 cv->expandedge = ee_right;
817 } else
818 cv->expandedge = ee_none;
819 SetCur(cv);
820 needsupdate = true;
821 }
822 }
823 else if ( event->u.mouse.clicks<=1 && !(event->u.mouse.state&ksm_shift))
824 {
825 /* printf("CVMouseDownPointer(2) not shifting\n"); */
826 /* printf("CVMouseDownPointer(2) cv->p.sp:%p\n", cv->p.sp ); */
827 /* printf("CVMouseDownPointer(2) n:%p p:%p sp:%p spline:%p ap:%p\n", */
828 /* fs->p->nextcp,fs->p->prevcp, fs->p->sp, fs->p->spline, fs->p->ap ); */
829 /* printf("CVMouseDownPointer(2) spl:%p\n", fs->p->spl ); */
830 /* SPLFirstVisit( fs->p->spl->first, SPLFirstVisitorDebugSelectionState, 0 ); */
831 CVUnselectAllBCP( cv );
832
833 if ( fs->p->nextcp || fs->p->prevcp ) {
834 CPStartInfo(cv,event);
835 /* Needs update to draw control points selected */
836 needsupdate = true;
837 } else if ( fs->p->sp!=NULL ) {
838 if ( !fs->p->sp->selected ) needsupdate = true;
839 fs->p->sp->selected = true;
840 } else if ( fs->p->spiro!=NULL ) {
841 if ( !SPIRO_SELECTED(fs->p->spiro) ) needsupdate = true;
842 SPIRO_SELECT( fs->p->spiro );
843 } else if ( fs->p->spline!=NULL && (!cv->b.sc->inspiro || !hasspiro())) {
844 if ( !fs->p->spline->to->selected &&
845 !fs->p->spline->from->selected ) needsupdate = true;
846 fs->p->spline->to->selected = true;
847 fs->p->spline->from->selected = true;
848 } else if ( fs->p->img!=NULL ) {
849 if ( !fs->p->img->selected ) needsupdate = true;
850 fs->p->img->selected = true;
851 } else if ( fs->p->ref!=NULL ) {
852 if ( !fs->p->ref->selected ) needsupdate = true;
853 fs->p->ref->selected = true;
854 } else if ( fs->p->ap!=NULL ) {
855 if ( !fs->p->ap->selected ) needsupdate = true;
856 fs->p->ap->selected = true;
857 }
858 }
859 else if ( event->u.mouse.clicks<=1 )
860 {
861 /* printf("CVMouseDownPointer(3) with shift... n:%p p:%p sp:%p spline:%p ap:%p\n", */
862 /* fs->p->nextcp,fs->p->prevcp, fs->p->sp, fs->p->spline, fs->p->ap ); */
863 /* printf("CVMouseDownPointer(3) spl:%p\n", fs->p->spl ); */
864 /* SPLFirstVisit( fs->p->spl->first, SPLFirstVisitorDebugSelectionState, 0 ); */
865
866 if ( fs->p->nextcp || fs->p->prevcp ) {
867 /* Needs update to draw control points selected */
868 needsupdate = true;
869 } else if ( fs->p->sp!=NULL ) {
870 needsupdate = true;
871 fs->p->sp->selected = !fs->p->sp->selected;
872 } else if ( fs->p->spiro!=NULL ) {
873 needsupdate = true;
874 fs->p->spiro->ty ^= 0x80;
875 } else if ( fs->p->spline!=NULL && (!cv->b.sc->inspiro || !hasspiro())) {
876 needsupdate = true;
877 fs->p->spline->to->selected = !fs->p->spline->to->selected;
878 fs->p->spline->from->selected = !fs->p->spline->from->selected;
879 } else if ( fs->p->img!=NULL ) {
880 needsupdate = true;
881 fs->p->img->selected = !fs->p->img->selected;
882 } else if ( fs->p->ref!=NULL ) {
883 needsupdate = true;
884 fs->p->ref->selected = !fs->p->ref->selected;
885 } else if ( fs->p->ap!=NULL ) {
886 needsupdate = true;
887 fs->p->ap->selected = !fs->p->ap->selected;
888 }
889 }
890 else if ( event->u.mouse.clicks==2 )
891 {
892 /* printf("mouse down click==2\n"); */
893 CPEndInfo(cv);
894 if ( fs->p->spl!=NULL ) {
895 if ( cv->b.sc->inspiro && hasspiro()) {
896 for ( i=0; i<fs->p->spl->spiro_cnt-1; ++i ) {
897 if ( !SPIRO_SELECTED(&fs->p->spl->spiros[i])) {
898 needsupdate = true;
899 SPIRO_SELECT(&fs->p->spl->spiros[i]);
900 }
901 }
902 } else {
903 Spline *spline, *first;
904 if ( !fs->p->spl->first->selected ) { needsupdate = true; fs->p->spl->first->selected = true; }
905 first = NULL;
906 for ( spline = fs->p->spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
907 if ( !spline->to->selected )
908 { needsupdate = true; spline->to->selected = true; }
909 if ( first==NULL ) first = spline;
910 }
911 }
912 } else if ( fs->p->ref!=NULL || fs->p->img!=NULL ) {
913 /* Double clicking on a referenced character doesn't do much */
914 } else if ( fs->p->ap!=NULL ) {
915 /* Select all Anchor Points at this location */
916 AnchorPoint *ap;
917 for ( ap=cv->b.sc->anchor; ap!=NULL; ap=ap->next )
918 if ( ap->me.x==fs->p->ap->me.x && ap->me.y==fs->p->ap->me.y )
919 if ( !ap->selected ) {
920 ap->selected = true;
921 needsupdate = true;
922 }
923 }
924 }
925 else if ( event->u.mouse.clicks==3 )
926 {
927 /* printf("mouse down click==3\n"); */
928 if ( CVSetSel(cv,1)) needsupdate = true;
929 /* don't select width or anchor points for three clicks */
930 /* but select all points, refs */
931 }
932 else
933 {
934 /* printf("mouse down ELSE\n"); */
935 /* Select everything */
936 if ( CVSetSel(cv,-1)) needsupdate = true;
937 }
938
939
940 if ( needsupdate )
941 SCUpdateAll(cv->b.sc);
942
943 /* lastselpt is set by our caller */
944 }
945
946 static int CVRectSelect(CharView *cv, real newx, real newy) {
947 int any=false;
948 DBounds old, new;
949 RefChar *rf;
950 ImageList *img;
951 Spline *spline, *first;
952 SplinePointList *spl;
953 BasePoint *bp;
954 AnchorPoint *ap;
955 DBounds bb;
956 int i;
957
958 if ( cv->p.cx<=cv->p.ex ) {
959 old.minx = cv->p.cx;
960 old.maxx = cv->p.ex;
961 } else {
962 old.minx = cv->p.ex;
963 old.maxx = cv->p.cx;
964 }
965 if ( cv->p.cy<=cv->p.ey ) {
966 old.miny = cv->p.cy;
967 old.maxy = cv->p.ey;
968 } else {
969 old.miny = cv->p.ey;
970 old.maxy = cv->p.cy;
971 }
972
973 if ( cv->p.cx<=newx ) {
974 new.minx = cv->p.cx;
975 new.maxx = newx;
976 } else {
977 new.minx = newx;
978 new.maxx = cv->p.cx;
979 }
980 if ( cv->p.cy<=newy ) {
981 new.miny = cv->p.cy;
982 new.maxy = newy;
983 } else {
984 new.miny = newy;
985 new.maxy = cv->p.cy;
986 }
987
988 for ( rf = cv->b.layerheads[cv->b.drawmode]->refs; rf!=NULL; rf=rf->next ) {
989 if (( rf->bb.minx>=old.minx && rf->bb.maxx<old.maxx &&
990 rf->bb.miny>=old.miny && rf->bb.maxy<old.maxy ) !=
991 ( rf->bb.minx>=new.minx && rf->bb.maxx<new.maxx &&
992 rf->bb.miny>=new.miny && rf->bb.maxy<new.maxy )) {
993 rf->selected = !rf->selected;
994 any = true;
995 }
996 }
997 if ( cv->b.drawmode==dm_fore ) {
998 if ( cv->showanchor ) for ( ap=cv->b.sc->anchor ; ap!=NULL; ap=ap->next ) {
999 bp = &ap->me;
1000 if (( bp->x>=old.minx && bp->x<old.maxx &&
1001 bp->y>=old.miny && bp->y<old.maxy ) !=
1002 ( bp->x>=new.minx && bp->x<new.maxx &&
1003 bp->y>=new.miny && bp->y<new.maxy )) {
1004 ap->selected = !ap->selected;
1005 any = true;
1006 }
1007 }
1008 }
1009
1010 for ( img = cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img=img->next ) {
1011 bb.minx = img->xoff;
1012 bb.miny = img->yoff;
1013 bb.maxx = img->xoff+GImageGetWidth(img->image)*img->xscale;
1014 bb.maxy = img->yoff+GImageGetHeight(img->image)*img->yscale;
1015 if (( bb.minx>=old.minx && bb.maxx<old.maxx &&
1016 bb.miny>=old.miny && bb.maxy<old.maxy ) !=
1017 ( bb.minx>=new.minx && bb.maxx<new.maxx &&
1018 bb.miny>=new.miny && bb.maxy<new.maxy )) {
1019 img->selected = !img->selected;
1020 any = true;
1021 }
1022 }
1023
1024 for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL; spl = spl->next ) {
1025 if ( !cv->b.sc->inspiro || !hasspiro()) {
1026 first = NULL;
1027 if ( spl->first->prev==NULL ) {
1028 bp = &spl->first->me;
1029 if (( bp->x>=old.minx && bp->x<old.maxx &&
1030 bp->y>=old.miny && bp->y<old.maxy ) !=
1031 ( bp->x>=new.minx && bp->x<new.maxx &&
1032 bp->y>=new.miny && bp->y<new.maxy )) {
1033 spl->first->selected = !spl->first->selected;
1034 if ( spl->first->selected )
1035 cv->lastselpt = spl->first;
1036 else if ( spl->first==cv->lastselpt )
1037 cv->lastselpt = NULL;
1038 any = true;
1039 }
1040 }
1041 for ( spline = spl->first->next; spline!=NULL && spline!=first; spline=spline->to->next ) {
1042 bp = &spline->to->me;
1043 if (( bp->x>=old.minx && bp->x<old.maxx &&
1044 bp->y>=old.miny && bp->y<old.maxy ) !=
1045 ( bp->x>=new.minx && bp->x<new.maxx &&
1046 bp->y>=new.miny && bp->y<new.maxy )) {
1047 spline->to->selected = !spline->to->selected;
1048 if ( spline->to->selected )
1049 cv->lastselpt = spline->to;
1050 else if ( spline->to==cv->lastselpt )
1051 cv->lastselpt = NULL;
1052 any = true;
1053 }
1054 if ( first==NULL ) first = spline;
1055 }
1056 } else {
1057 for ( i=0; i<spl->spiro_cnt-1; ++i ) {
1058 if (( spl->spiros[i].x>=old.minx && spl->spiros[i].x<old.maxx &&
1059 spl->spiros[i].y>=old.miny && spl->spiros[i].y<old.maxy ) !=
1060 ( spl->spiros[i].x>=new.minx && spl->spiros[i].x<new.maxx &&
1061 spl->spiros[i].y>=new.miny && spl->spiros[i].y<new.maxy )) {
1062 spl->spiros[i].ty ^= 0x80;
1063 if ( SPIRO_SELECTED(&spl->spiros[i]))
1064 cv->lastselcp = &spl->spiros[i];
1065 any = true;
1066 }
1067 }
1068 }
1069 }
1070 return( any );
1071 }
1072
1073 void CVAdjustControl(CharView *cv,BasePoint *cp, BasePoint *to) {
1074 SplinePoint *sp = cv->p.sp;
1075
1076 SPAdjustControl(sp,cp,to,cv->b.layerheads[cv->b.drawmode]->order2);
1077 CVSetCharChanged(cv,true);
1078 }
1079
1080 bool isSplinePointPartOfGuide( SplineFont *sf, SplinePoint *sp )
1081 {
1082 if( !sp || !sf )
1083 return 0;
1084 if( !sf->grid.splines )
1085 return 0;
1086
1087 SplinePointList* spl = sf->grid.splines;
1088 return SplinePointListContainsPoint( spl, sp );
1089 }
1090
1091 static void CVAdjustSpline(CharView *cv) {
1092 Spline *old = cv->p.spline;
1093 FitPoint fp[5];
1094 real t;
1095 Spline1D *oldx = &old->splines[0], *oldy = &old->splines[1];
1096 int oldfrompointtype, oldtopointtype;
1097
1098 if ( cv->b.layerheads[cv->b.drawmode]->order2 )
1099 return;
1100
1101 //
1102 // Click + drag on a guide moves the guide to where your mouse is at
1103 //
1104 if( cv->b.drawmode == dm_grid
1105 && isSplinePointPartOfGuide( cv->b.sc->parent, cv->p.spline->from )
1106 && isSplinePointPartOfGuide( cv->b.sc->parent, cv->p.spline->to ) )
1107 {
1108 if( 0 == cv->p.spline->splines[0].a
1109 && 0 == cv->p.spline->splines[0].b
1110 && 0 == cv->p.spline->splines[1].a
1111 && 0 == cv->p.spline->splines[1].b
1112 && ( (cv->p.spline->splines[0].c && cv->p.spline->from->me.y == cv->p.spline->to->me.y)
1113 || (cv->p.spline->splines[1].c && cv->p.spline->from->me.x == cv->p.spline->to->me.x )))
1114 {
1115 if( cv->p.spline->from->me.y == cv->p.spline->to->me.y )
1116 {
1117 int newy = cv->info.y;
1118 cv->p.spline->from->me.y = newy;
1119 cv->p.spline->to->me.y = newy;
1120 cv->p.spline->splines[1].d = newy;
1121 }
1122 else
1123 {
1124 int newx = cv->info.x;
1125 cv->p.spline->from->me.x = newx;
1126 cv->p.spline->to->me.x = newx;
1127 cv->p.spline->splines[0].d = newx;
1128 }
1129 CVSetCharChanged(cv,true);
1130 return;
1131 }
1132 }
1133
1134
1135 fp[0].p.x = cv->info.x; fp[0].p.y = cv->info.y; fp[0].t = cv->p.t;
1136 t = cv->p.t/10;
1137 fp[1].p.x = ((oldx->a*t+oldx->b)*t+oldx->c)*t + oldx->d;
1138 fp[1].p.y = ((oldy->a*t+oldy->b)*t+oldy->c)*t + oldy->d;
1139 fp[1].t = t;
1140 t = 1-(1-cv->p.t)/10;
1141 fp[2].p.x = ((oldx->a*t+oldx->b)*t+oldx->c)*t + oldx->d;
1142 fp[2].p.y = ((oldy->a*t+oldy->b)*t+oldy->c)*t + oldy->d;
1143 fp[2].t = t;
1144 fp[3] = fp[0]; /* Give more weight to this point than to the others */
1145 fp[4] = fp[0]; /* ditto */
1146 cv->p.spline = ApproximateSplineFromPoints(old->from,old->to,fp,5,old->order2);
1147
1148 /* don't change hvcurves to corners */
1149 oldfrompointtype = old->from->pointtype;
1150 oldtopointtype = old->to->pointtype;
1151 old->from->pointtype = old->to->pointtype = pt_corner;
1152 if ( oldfrompointtype == pt_hvcurve )
1153 SPChangePointType(old->from, pt_hvcurve);
1154 if ( oldtopointtype == pt_hvcurve )
1155 SPChangePointType(old->to, pt_hvcurve);
1156 //
1157 // dont go changing pt_curve points into pt_corner without explicit consent.
1158 //
1159 if( oldfrompointtype == pt_curve || oldfrompointtype == pt_tangent )
1160 {
1161 old->from->pointtype = oldfrompointtype;
1162 SPTouchControl( old->from, &old->from->nextcp, cv->b.layerheads[cv->b.drawmode]->order2 );
1163 }
1164 if( oldtopointtype == pt_curve || oldtopointtype == pt_tangent )
1165 {
1166 old->to->pointtype = oldtopointtype;
1167 SPTouchControl( old->to, &old->to->prevcp, cv->b.layerheads[cv->b.drawmode]->order2 );
1168 }
1169
1170 old->from->nextcpdef = old->to->prevcpdef = false;
1171 SplineFree(old);
1172 CVSetCharChanged(cv,true);
1173 }
1174
1175 static int Nearish(real a,real fudge) {
1176 return( a>-fudge && a<fudge );
1177 }
1178
1179 /* Are any of the selected points open (that is are they missing either a next*/
1180 /* or a prev spline so that at least one direction is free to make a new link)*/
1181 /* And did any of those selected points move on top of a point which was not */
1182 /* selected but which was also open? if so then merge all cases where this */
1183 /* happened (could be more than one) */
1184 /* However if two things merge we must start all over again because we will have */
1185 /* freed one of the splinesets in the merger */
1186 /* This is very similar for spiros (because start and end points of open contours */
1187 /* are the same in both representations). The only complication is checking */
1188 /* that they are selected */
1189 static int CVCheckMerges(CharView *cv ) {
1190 CharViewTab* tab = CVGetActiveTab(cv);
1191 SplineSet *activess, *mergess;
1192 real fudge = 2/tab->scale;
1193 int cnt= -1;
1194 int firstsel, lastsel;
1195 int mfirstsel, mlastsel;
1196 int inspiro = cv->b.sc->inspiro && hasspiro();
1197
1198 restart:
1199 ++cnt;
1200 for ( activess=cv->b.layerheads[cv->b.drawmode]->splines; activess!=NULL; activess=activess->next ) {
1201 if ( activess->first->prev!=NULL )
1202 continue; /* Closed contour, can't merge with anything */
1203 firstsel = (inspiro && SPIRO_SELECTED(&activess->spiros[0])) ||
1204 (!inspiro && activess->first->selected);
1205 lastsel = (inspiro && SPIRO_SELECTED(&activess->spiros[activess->spiro_cnt-2])) ||
1206 (!inspiro && activess->last->selected);
1207 if ( firstsel || lastsel ) {
1208 for ( mergess = cv->b.layerheads[cv->b.drawmode]->splines; mergess!=NULL; mergess=mergess->next ) {
1209 if ( mergess->first->prev!=NULL )
1210 continue; /* Closed contour, can't merge with anything */
1211 mfirstsel = (inspiro && SPIRO_SELECTED(&mergess->spiros[0])) ||
1212 (!inspiro && mergess->first->selected);
1213 mlastsel = (inspiro && SPIRO_SELECTED(&mergess->spiros[mergess->spiro_cnt-2])) ||
1214 (!inspiro && mergess->last->selected);
1215 if ( !mfirstsel || !mlastsel ) {
1216 if ( !mfirstsel && firstsel &&
1217 Nearish(mergess->first->me.x-activess->first->me.x,fudge) &&
1218 Nearish(mergess->first->me.y-activess->first->me.y,fudge)) {
1219 CVMergeSplineSets(cv,activess->first,activess,
1220 mergess->first,mergess);
1221 goto restart;
1222 }
1223 if ( !mlastsel && firstsel &&
1224 Nearish(mergess->last->me.x-activess->first->me.x,fudge) &&
1225 Nearish(mergess->last->me.y-activess->first->me.y,fudge)) {
1226 CVMergeSplineSets(cv,activess->first,activess,
1227 mergess->last,mergess);
1228 goto restart;
1229 }
1230 if ( !mfirstsel && lastsel &&
1231 Nearish(mergess->first->me.x-activess->last->me.x,fudge) &&
1232 Nearish(mergess->first->me.y-activess->last->me.y,fudge)) {
1233 CVMergeSplineSets(cv,activess->last,activess,
1234 mergess->first,mergess);
1235 goto restart;
1236 }
1237 if ( !mlastsel && lastsel &&
1238 Nearish(mergess->last->me.x-activess->last->me.x,fudge) &&
1239 Nearish(mergess->last->me.y-activess->last->me.y,fudge)) {
1240 CVMergeSplineSets(cv,activess->last,activess,
1241 mergess->last,mergess);
1242 goto restart;
1243 }
1244 }
1245 }
1246 }
1247 }
1248 return( cnt>0 && stop_at_join );
1249 }
1250
1251 static void adjustLBearing( CharView *cv, SplineChar *sc, real val )
1252 {
1253 DBounds bb;
1254 SplineCharFindBounds(sc,&bb);
1255 if ( val != 0 )
1256 {
1257 enum fvtrans_flags flags = fvt_alllayers | fvt_nopreserve;
1258 real transform[6];
1259 transform[0] = transform[3] = 1.0;
1260 transform[1] = transform[2] = transform[5] = 0;
1261 transform[4] = val;
1262 // With no recent change, assume CVPreserveState was called.
1263 // Remove it, as it doesn't preserve hints or other layers
1264 // Instead, delegate to FVTrans to do this.
1265 if (!cv->recentchange) {
1266 CVRemoveTopUndo(&cv->b);
1267 flags &= ~fvt_nopreserve;
1268 }
1269 // printf("adjustLBearing val:%f min:%f v-min:%f\n",val,bb.minx,(bb.minx+val));
1270 FVTrans( (FontViewBase *) cv->b.fv, sc, transform, NULL, flags );
1271 // We copy and adapt some code from FVTrans in order to adjust the CharView carets.
1272 // We omit the fvt_scalepstpos for FVTrans since other CharView code seems to skip updating the SplineChar.
1273 PST *pst;
1274 for ( pst = cv->b.sc->possub; pst!=NULL; pst=pst->next ) {
1275 if ( pst->type == pst_lcaret ) {
1276 int j;
1277 for ( j=0; j<pst->u.lcaret.cnt; ++j )
1278 pst->u.lcaret.carets[j] = rint(pst->u.lcaret.carets[j]+val);
1279 }
1280 }
1281 }
1282 }
1283
1284 /* Move the selection and return whether we did a merge */
1285 int CVMoveSelection(CharView *cv, real dx, real dy, uint32_t input_state) {
1286 CharViewTab* tab = CVGetActiveTab(cv);
1287 real transform[6];
1288 RefChar *refs;
1289 ImageList *img;
1290 AnchorPoint *ap;
1291 double fudge;
1292 extern float snapdistance;
1293 int i,j;
1294 int changed = false, outlinechanged = false;
1295 SplinePointList *spl;
1296 SplinePoint *sp;
1297
1298 transform[0] = transform[3] = 1.0;
1299 transform[1] = transform[2] = 0.0;
1300 transform[4] = dx; transform[5] = dy;
1301 if ( transform[4]==0 && transform[5]==0 )
1302 return(false);
1303 for ( spl=cv->b.layerheads[cv->b.drawmode]->splines; spl!=NULL && !outlinechanged; spl=spl->next ) {
1304 if ( cv->b.sc->inspiro && hasspiro()) {
1305 for ( i=0; i<spl->spiro_cnt-1; ++i )
1306 if ( SPIRO_SELECTED(&spl->spiros[i])) {
1307 outlinechanged = true;
1308 break;
1309 }
1310 } else {
1311 for ( sp=spl->first ;; ) {
1312 if ( sp->selected ) {
1313 outlinechanged = true;
1314 break;
1315 }
1316 if ( sp->next==NULL )
1317 break;
1318 sp = sp->next->to;
1319 if ( sp==spl->first )
1320 break;
1321 }
1322 }
1323 }
1324
1325 enum transformPointMask tpmask = 0;
1326 tpmask |= tpmask_dontFixControlPoints;
1327
1328 if ( cv->b.sc->inspiro && hasspiro())
1329 SplinePointListSpiroTransform(cv->b.layerheads[cv->b.drawmode]->splines,transform,false);
1330 else
1331 {
1332 bool interp = CVShouldInterpolateCPsOnMotion( cv );
1333
1334 SplinePointListTransformExtended(cv->b.layerheads[cv->b.drawmode]->splines,transform,
1335 interp ? tpt_OnlySelectedInterpCPs : tpt_OnlySelected,
1336 tpmask );
1337
1338 if( interp )
1339 {
1340 bool preserveState = false;
1341 CVVisitAllControlPoints( cv, preserveState,
1342 FE_touchControlPoint,
1343 (void*)(intptr_t)cv->b.layerheads[cv->b.drawmode]->order2 );
1344 }
1345 }
1346
1347
1348 for ( refs = cv->b.layerheads[cv->b.drawmode]->refs; refs!=NULL; refs=refs->next ) if ( refs->selected ) {
1349 refs->transform[4] += transform[4];
1350 refs->transform[5] += transform[5];
1351 refs->bb.minx += transform[4]; refs->bb.maxx += transform[4];
1352 refs->bb.miny += transform[5]; refs->bb.maxy += transform[5];
1353 for ( j=0; j<refs->layer_cnt; ++j )
1354 SplinePointListTransform(refs->layers[j].splines,transform,tpt_AllPoints);
1355 outlinechanged = true;
1356 }
1357 if ( CVLayer( (CharViewBase *) cv) > ly_back ) {
1358 if ( cv->showanchor ) {
1359 for ( ap=cv->b.sc->anchor; ap!=NULL; ap=ap->next ) if ( ap->selected ) {
1360 ap->me.x += transform[4];
1361 ap->me.y += transform[5];
1362 changed = true;
1363 }
1364 }
1365 }
1366 for ( img = cv->b.layerheads[cv->b.drawmode]->images; img!=NULL; img=img->next ) if ( img->selected ) {
1367 img->xoff += transform[4];
1368 img->yoff += transform[5];
1369 img->bb.minx += transform[4]; img->bb.maxx += transform[4];
1370 img->bb.miny += transform[5]; img->bb.maxy += transform[5];
1371 changed = true;
1372 }
1373 fudge = snapdistance/tab->scale/2;
1374 if ( cv->widthsel ) {
1375 if ( cv->b.sc->width+dx>0 && ((int16_t) (cv->b.sc->width+dx))<0 )
1376 cv->b.sc->width = 32767;
1377 else if ( cv->b.sc->width+dx<0 && ((int16_t) (cv->b.sc->width+dx))>0 )
1378 cv->b.sc->width = -32768;
1379 else
1380 cv->b.sc->width += dx;
1381 if ( cv->b.sc->width>=-fudge && cv->b.sc->width<fudge )
1382 cv->b.sc->width = 0;
1383 changed = true;
1384 }
1385 if ( cv->lbearingsel ) {
1386
1387 // printf("lbearing dx:%f\n", dx );
1388 adjustLBearing( cv, cv->b.sc, dx );
1389 changed = true;
1390 }
1391 if ( cv->vwidthsel ) {
1392 if ( cv->b.sc->vwidth-dy>0 && ((int16_t) (cv->b.sc->vwidth-dy))<0 )
1393 cv->b.sc->vwidth = 32767;
1394 else if ( cv->b.sc->vwidth-dy<0 && ((int16_t) (cv->b.sc->vwidth-dy))>0 )
1395 cv->b.sc->vwidth = -32768;
1396 else
1397 cv->b.sc->vwidth -= dy;
1398 if ( cv->b.sc->vwidth>=-fudge && cv->b.sc->vwidth<fudge )
1399 cv->b.sc->vwidth = 0;
1400 changed = true;
1401 }
1402 if ( cv->icsel ) {
1403 if ( cv->b.sc->italic_correction+dx>0 && ((int16_t) (cv->b.sc->italic_correction+dx))<0 )
1404 cv->b.sc->italic_correction = 32767-1;
1405 else if ( cv->b.sc->italic_correction+dx<0 && ((int16_t) (cv->b.sc->italic_correction+dx))>0 )
1406 cv->b.sc->italic_correction = -32768;
1407 else
1408 cv->b.sc->italic_correction += dx;
1409 if ( cv->b.sc->italic_correction>=-fudge && cv->b.sc->italic_correction<fudge )
1410 cv->b.sc->italic_correction = 0;
1411 changed = true;
1412 }
1413 if ( cv->tah_sel ) {
1414 if ( cv->b.sc->top_accent_horiz+dx>0 && ((int16_t) (cv->b.sc->top_accent_horiz+dx))<0 )
1415 cv->b.sc->top_accent_horiz = 32767-1;
1416 else if ( cv->b.sc->top_accent_horiz+dx<0 && ((int16_t) (cv->b.sc->top_accent_horiz+dx))>0 )
1417 cv->b.sc->top_accent_horiz = -32768;
1418 else
1419 cv->b.sc->top_accent_horiz += dx;
1420 if ( cv->b.sc->top_accent_horiz>=-fudge && cv->b.sc->top_accent_horiz<fudge )
1421 cv->b.sc->top_accent_horiz = 0;
1422 changed = true;
1423 }
1424 if ( outlinechanged )
1425 CVSetCharChanged(cv,true);
1426 else if ( changed )
1427 CVSetCharChanged(cv,2);
1428 if ( input_state&ksm_meta )
1429 return( false ); /* Don't merge if the meta key is down */
1430
1431 return( CVCheckMerges( cv ));
1432 }
1433
1434 static int CVExpandEdge(CharView *cv) {
1435 real transform[6];
1436 real xscale=1.0, yscale=1.0;
1437
1438 CVRestoreTOriginalState(cv);
1439 if ( cv->expandedge != ee_up && cv->expandedge != ee_down )
1440 xscale = (cv->info.x-cv->expandorigin.x)/cv->expandwidth;
1441 if ( cv->expandedge != ee_left && cv->expandedge != ee_right )
1442 yscale = (cv->info.y-cv->expandorigin.y)/cv->expandheight;
1443 transform[0] = xscale; transform[3] = yscale;
1444 transform[1] = transform[2] = 0;
1445 transform[4] = (1-xscale)*cv->expandorigin.x;
1446 transform[5] = (1-yscale)*cv->expandorigin.y;
1447 CVSetCharChanged(cv,true);
1448 CVTransFunc(cv,transform,false);
1449 return( true );
1450 }
1451
1452 static void touchControlPointsVisitor ( void* key,
1453 void* value,
1454 SplinePoint* sp,
1455 BasePoint *which,
1456 bool isnext,
1457 void* udata )
1458 {
1459 SPTouchControl( sp, which, (int)(intptr_t)udata );
1460 }
1461
1462 BasePoint nearest_point_on_line_segment(BasePoint p1, BasePoint p2, BasePoint p3) {
1463 double x_diff = p2.x - p1.x;
1464 double y_diff = p2.y - p1.y;
1465 double slope_1 = (p2.y - p1.y) / (p2.x - p1.x);
1466 double inverse_slope_1 = (p2.x - p1.x) / (p2.y - p1.y);
1467 BasePoint output_1;
1468 output_1.x = 0;
1469 output_1.y = 0;
1470 // Accuracy may be important, so we try to use the longer dimension.
1471 if (x_diff == 0) {
1472 // The line is vertical.
1473 output_1.x = p1.x;
1474 output_1.y = p3.y;
1475 } else if (y_diff == 0) {
1476 // The line is horizontal.
1477 output_1.x = p3.x;
1478 output_1.y = p1.y;
1479 } else {
1480 output_1.x = (p3.x/slope_1 + slope_1*p1.x + p3.y - p1.y)/(slope_1 + 1/slope_1);
1481 output_1.y = (p3.y/inverse_slope_1 + inverse_slope_1*p1.y + p3.x - p1.x)/(inverse_slope_1 + 1/inverse_slope_1);
1482 }
1483 // We are using the segment between p1 and p2, not the line through them, so we must crop.
1484 double min_x = MIN(p1.x, p2.x), max_x = MAX(p1.x, p2.x), min_y = MIN(p1.y, p2.y), max_y = MAX(p1.y, p2.y);
1485 if (output_1.x < min_x) output_1.x = min_x;
1486 if (output_1.x > max_x) output_1.x = max_x;
1487 if (output_1.y < min_y) output_1.y = min_y;
1488 if (output_1.y > max_y) output_1.y = max_y;
1489 // Note that it is not necessary to conform these points to the line since the corners of the box are on the line.
1490 return output_1;
1491 }
1492
1493 int CVMouseMovePointer(CharView *cv, GEvent *event) {
1494 extern float arrowAmount;
1495 int needsupdate = false;
1496 int did_a_merge = false;
1497 int touch_control_points = false;
1498 int no_prev_cp = false, no_next_cp = false;
1499
1500
1501 /* if we haven't moved from the original location (ever) then this is a noop */
1502 if ( !cv->p.rubberbanding && !cv->recentchange &&
1503 RealNear(cv->info.x,cv->p.cx) && RealNear(cv->info.y,cv->p.cy) )
1504 return( false );
1505
1506 /* This can happen if they depress on a control point, move it, then use */
1507 /* the arrow keys to move the point itself, and then try to move the cp */
1508 /* again (mouse still depressed) */
1509 if (( cv->p.nextcp || cv->p.prevcp ) && cv->p.sp==NULL )
1510 cv->p.nextcp = cv->p.prevcp = false;
1511
1512 /* I used to have special cases for moving width lines, but that's now */
1513 /* done by move selection */
1514 if ( cv->expandedge!=ee_none && !cv->widthsel && !cv->vwidthsel && !cv->lbearingsel
1515 && cv->nearcaret==-1 && !cv->icsel && !cv->tah_sel )
1516 {
1517 if( !cv->changedActiveGlyph )
1518 {
1519 needsupdate = CVExpandEdge(cv);
1520 }
1521 }
1522 else if ( cv->nearcaret!=-1 && cv->lcarets!=NULL ) {
1523 if ( cv->info.x!=cv->last_c.x ) {
1524 if ( !cv->recentchange ) SCPreserveLayer(cv->b.sc,CVLayer((CharViewBase *) cv),2);
1525 cv->lcarets->u.lcaret.carets[cv->nearcaret] += cv->info.x-cv->last_c.x;
1526 if ( cv->lcarets->u.lcaret.carets[cv->nearcaret]<0 )
1527 cv->lcarets->u.lcaret.carets[cv->nearcaret] = 0;
1528 needsupdate = true;
1529 CVSetCharChanged(cv,true);
1530 }
1531 } else if ( !cv->p.anysel ) {
1532 if ( !cv->p.rubberbanding ) {
1533 cv->p.ex = cv->p.cx;
1534 cv->p.ey = cv->p.cy;
1535 }
1536 needsupdate = CVRectSelect(cv,cv->info.x,cv->info.y);
1537 /* printf("moving2 cx:%g cy:%g\n", cv->p.cx, cv->p.cy ); */
1538 cv->p.ex = cv->info.x;
1539 cv->p.ey = cv->info.y;
1540 cv->p.rubberbanding = true;
1541 }
1542 else if ( cv->p.nextcp )
1543 {
1544 if ( !cv->recentchange )
1545 CVPreserveState(&cv->b);
1546
1547 FE_adjustBCPByDeltaData d;
1548 memset( &d, 0, sizeof(FE_adjustBCPByDeltaData));
1549 d.cv = cv;
1550 d.dx = (cv->info.x - cv->p.sp->nextcp.x) * arrowAmount;
1551 d.dy = (cv->info.y - cv->p.sp->nextcp.y) * arrowAmount;
1552 visitSelectedControlPointsVisitor func = FE_adjustBCPByDelta;
1553 /* printf("move sp:%p ncp:%p \n", */
1554 /* cv->p.sp, &(cv->p.sp->nextcp) ); */
1555 /* printf("move me.x:%f me.y:%f\n", cv->p.sp->me.x, cv->p.sp->me.y ); */
1556 /* printf("move ncp.x:%f ncp.y:%f ix:%f iy:%f\n", */
1557 /* cv->p.sp->nextcp.x, cv->p.sp->nextcp.y, */
1558 /* cv->info.x, cv->info.y ); */
1559 /* printf("move dx:%f dy:%f\n", d.dx, d.dy ); */
1560 /* printf("move dx:%f \n", cv->info.x - cv->p.sp->nextcp.x ); */
1561 if( cv->activeModifierAlt )
1562 func = FE_adjustBCPByDeltaWhilePreservingBCPAngle;
1563
1564 CVFindAndVisitSelectedControlPoints( cv, false, func, &d );
1565 CPUpdateInfo(cv,event);
1566 needsupdate = true;
1567 }
1568 else if ( cv->p.prevcp )
1569 {
1570 if ( !cv->recentchange )
1571 CVPreserveState(&cv->b);
1572
1573 FE_adjustBCPByDeltaData d;
1574 memset( &d, 0, sizeof(FE_adjustBCPByDeltaData));
1575 d.cv = cv;
1576 d.dx = (cv->info.x - cv->p.sp->prevcp.x) * arrowAmount;
1577 d.dy = (cv->info.y - cv->p.sp->prevcp.y) * arrowAmount;
1578 visitSelectedControlPointsVisitor func = FE_adjustBCPByDelta;
1579
1580 if( cv->activeModifierAlt )
1581 func = FE_adjustBCPByDeltaWhilePreservingBCPAngle;
1582
1583 CVFindAndVisitSelectedControlPoints( cv, false, func, &d );
1584 CPUpdateInfo(cv,event);
1585 needsupdate = true;
1586 }
1587 else if ( cv->p.spline
1588 && !cv->p.splineAdjacentPointsSelected
1589 && (!cv->b.sc->inspiro || !hasspiro()))
1590 {
1591 if ( !cv->recentchange )
1592 CVPreserveState(&cv->b);
1593
1594 CVAdjustSpline(cv);
1595 CVSetCharChanged(cv,true);
1596 needsupdate = true;
1597 touch_control_points = true;
1598 }
1599 else
1600 {
1601 if ( !cv->recentchange )
1602 CVPreserveState(&cv->b);
1603
1604 BasePoint tmpp1;
1605 BasePoint tmpp2;
1606 tmpp1.x = cv->info.x;
1607 tmpp1.y = cv->info.y;
1608 tmpp2.x = cv->info.x;
1609 tmpp2.y = cv->info.y;
1610 BasePoint cachecp1 = (cv->p.sp ? cv->p.sp->prevcp : (BasePoint){0, 0});
1611 BasePoint cachecp2 = (cv->p.sp ? cv->p.sp->nextcp : (BasePoint){0, 0});
1612 double xadj = cv->info.x-cv->last_c.x;
1613 double yadj = cv->info.y-cv->last_c.y;
1614 touch_control_points = true;
1615 // The modifier is wrong.
1616 if (cv->p.anysel && cv->p.sp && event->u.mouse.state & ksm_control) {
1617 touch_control_points = false;
1618 BasePoint prevref, nextref;
1619 if (cv->p.sp->noprevcp && cv->p.sp->prev) {
1620 no_prev_cp = true;
1621 prevref = cv->p.sp->prev->from->me;
1622 } else {
1623 prevref = cv->p.sp->prevcp;
1624 }
1625 if (cv->p.sp->nonextcp && cv->p.sp->next) {
1626 no_next_cp = true;
1627 nextref = cv->p.sp->next->to->me;
1628 } else {
1629 nextref = cv->p.sp->nextcp;
1630 }
1631 // Identify the individual point clicked. Find its control
1632 // points. Move the selected point on a line between those
1633 // control points.
1634 tmpp1 = nearest_point_on_line_segment(prevref, nextref, cv->info);
1635 // We also need to rebase the original point onto that line
1636 // segment so that the movement is exactly along the line
1637 // even if the original click is not.
1638 tmpp2 = nearest_point_on_line_segment(prevref, nextref, cv->last_c);
1639 xadj = tmpp1.x-tmpp2.x;
1640 yadj = tmpp1.y-tmpp2.y;
1641 }
1642
1643 did_a_merge = CVMoveSelection(cv,
1644 xadj,yadj,
1645 event->u.mouse.state);
1646 // Rather than create a new set of functions for moving points without
1647 // their control points, we instead just restore them if we did not want
1648 // them moved.
1649 if (cv->p.sp && touch_control_points == false) {
1650 if (no_prev_cp)
1651 cv->p.sp->prevcp = cv->p.sp->me;
1652 else
1653 cv->p.sp->prevcp = cachecp1;
1654 if (no_next_cp)
1655 cv->p.sp->nextcp = cv->p.sp->me;
1656 else
1657 cv->p.sp->nextcp = cachecp2;
1658 SplineRefigure(cv->p.sp->prev);
1659 SplineRefigure(cv->p.sp->next);
1660 // We presumably still trigger this in case we're dragging other
1661 // selected points along
1662 touch_control_points = true;
1663 // Don't think this is wanted or needed now AdjustControls(cv->p.sp);
1664 }
1665 needsupdate = true;
1666
1667 }
1668
1669
1670 if ( needsupdate )
1671 {
1672 SCUpdateAll(cv->b.sc);
1673 CVGridHandlePossibleFitChar( cv );
1674 }
1675
1676 if ( touch_control_points )
1677 {
1678 // We should really only need to visit the Adjacent CP
1679 // visiting all is a hammer left below in case it might be needed.
1680 CVVisitAdjacentToSelectedControlPoints( cv, false,
1681 touchControlPointsVisitor,
1682 (void*)(intptr_t)cv->b.layerheads[cv->b.drawmode]->order2 );
1683 /* CVVisitAllControlPoints( cv, false, */
1684 /* touchControlPointsVisitor, */
1685 /* (void*)cv->b.layerheads[cv->b.drawmode]->order2 ); */
1686
1687 GDrawRequestExpose(cv->v,NULL,false);
1688 } else if (!needsupdate) {
1689 // Needed to update the rubber rect
1690 GDrawRequestExpose(cv->v,NULL,false);
1691 }
1692
1693 cv->last_c.x = cv->info.x; cv->last_c.y = cv->info.y;
1694 return( did_a_merge );
1695 }
1696
1697
1698
1699
1700 void CVMouseUpPointer(CharView *cv ) {
1701 static char *buts[3];
1702 buts[0] = _("_Yes");
1703 buts[1] = _("_No");
1704 buts[2] = NULL;
1705
1706 if ( cv->widthsel )
1707 {
1708 if ( cv->b.sc->width<0 && cv->oldwidth>=0 ) {
1709 if ( gwwv_ask(_("Negative Width"), (const char **) buts, 0, 1, _("Negative character widths are not allowed in TrueType.\nDo you really want a negative width?") )==1 )
1710 cv->b.sc->width = cv->oldwidth;
1711 }
1712 SCSynchronizeWidth(cv->b.sc,cv->b.sc->width,cv->oldwidth,NULL);
1713 cv->expandedge = ee_none;
1714 GDrawSetCursor(cv->v,ct_mypointer);
1715 }
1716 if ( cv->lbearingsel )
1717 {
1718 // printf("oldlbearing:%f\n", cv->oldlbearing );
1719 cv->expandedge = ee_none;
1720 GDrawSetCursor(cv->v,ct_mypointer);
1721 }
1722 if ( cv->vwidthsel )
1723 {
1724 if ( cv->b.sc->vwidth<0 && cv->oldvwidth>=0 ) {
1725 if ( gwwv_ask(_("Negative Width"), (const char **) buts, 0, 1, _("Negative character widths are not allowed in TrueType.\nDo you really want a negative width?") )==1 )
1726 cv->b.sc->vwidth = cv->oldvwidth;
1727 }
1728 cv->expandedge = ee_none;
1729 GDrawSetCursor(cv->v,ct_mypointer);
1730 }
1731 if ( cv->nearcaret!=-1 && cv->lcarets!=NULL )
1732 {
1733 cv->nearcaret = -1;
1734 cv->expandedge = ee_none;
1735 cv->lcarets = NULL;
1736 GDrawSetCursor(cv->v,ct_mypointer);
1737 }
1738 if( cv->changedActiveGlyph )
1739 {
1740 cv->changedActiveGlyph = 0;
1741 }
1742 else
1743 {
1744 if ( cv->expandedge!=ee_none )
1745 {
1746 CVUndoCleanup(cv);
1747 cv->expandedge = ee_none;
1748 GDrawSetCursor(cv->v,ct_mypointer);
1749 }
1750 else if ( CVAllSelected(cv) && cv->b.drawmode==dm_fore && cv->p.spline==NULL
1751 && !cv->p.prevcp && !cv->p.nextcp && cv->info.y==cv->p.cy )
1752 {
1753 SCUndoSetLBearingChange(cv->b.sc,(int) rint(cv->info.x-cv->p.cx));
1754 SCSynchronizeLBearing(cv->b.sc,cv->info.x-cv->p.cx,CVLayer((CharViewBase *) cv));
1755 }
1756 }
1757 GDrawRequestExpose(cv->v, NULL, false);
1758 CPEndInfo(cv);
1759 }
1760
1761 /* ************************************************************************** */
1762 /* ************************** Select Point Dialog ************************* */
1763 /* ************************************************************************** */
1764
1765 static spiro_cp *SpiroClosest(BasePoint *base,spiro_cp *sp1, spiro_cp *sp2) {
1766 double dx1, dy1, dx2, dy2;
1767 if ( sp1==NULL )
1768 return( sp2 );
1769 if ( sp2==NULL )
1770 return( sp1 );
1771 if ( (dx1 = sp1->x-base->x)<0 ) dx1 = -dx1;
1772 if ( (dy1 = sp1->y-base->y)<0 ) dy1 = -dy1;
1773 if ( (dx2 = sp2->x-base->x)<0 ) dx2 = -dx2;
1774 if ( (dy2 = sp2->y-base->y)<0 ) dy2 = -dy2;
1775 if ( dx1+dy1 < dx2+dy2 )
1776 return( sp1 );
1777 else
1778 return( sp2 );
1779 }
1780
1781 static SplinePoint *Closest(BasePoint *base,SplinePoint *sp1, SplinePoint *sp2) {
1782 double dx1, dy1, dx2, dy2;
1783 if ( sp1==NULL )
1784 return( sp2 );
1785 if ( sp2==NULL )
1786 return( sp1 );
1787 if ( (dx1 = sp1->me.x-base->x)<0 ) dx1 = -dx1;
1788 if ( (dy1 = sp1->me.y-base->y)<0 ) dy1 = -dy1;
1789 if ( (dx2 = sp2->me.x-base->x)<0 ) dx2 = -dx2;
1790 if ( (dy2 = sp2->me.y-base->y)<0 ) dy2 = -dy2;
1791 if ( dx1+dy1 < dx2+dy2 )
1792 return( sp1 );
1793 else
1794 return( sp2 );
1795 }
1796
1797 static int SelectPointsWithin(CharView *cv, BasePoint *base, double fuzz, BasePoint *bounds) {
1798 SplineSet *ss;
1799 SplinePoint *sp;
1800 SplinePoint *any = NULL;
1801 int i;
1802 spiro_cp *anycp = NULL;
1803
1804 CVClearSel(cv);
1805 if ( cv->b.sc->inspiro && hasspiro()) {
1806 for ( ss= cv->b.layerheads[cv->b.drawmode]->splines; ss!=NULL; ss=ss->next ) {
1807 for ( i=0; i<ss->spiro_cnt-1; ++i ) {
1808 spiro_cp *cp = &ss->spiros[i];
1809 if ( bounds!=NULL ) {
1810 if ( cp->x >= base->x && cp->x <= base->x+bounds->x &&
1811 cp->y >= base->y && cp->y <= base->y+bounds->y ) {
1812 SPIRO_SELECT(cp);
1813 anycp = cp;
1814 }
1815 } else if ( fuzz>0 ) {
1816 if ( RealWithin(cp->x,base->x,fuzz) && RealWithin(cp->y,base->y,fuzz)) {
1817 SPIRO_SELECT(cp);
1818 anycp = SpiroClosest(base,anycp,cp);
1819 }
1820 } else {
1821 if ( RealNear(cp->x,base->x) && RealNear(cp->y,base->y)) {
1822 SPIRO_SELECT(cp);
1823 anycp = SpiroClosest(base,anycp,cp);
1824 goto cpdone;
1825 }
1826 }
1827 }
1828 }
1829 cpdone:
1830 if ( any==NULL ) {
1831 CVShowPoint(cv,base);
1832 GDrawBeep(NULL);
1833 } else {
1834 BasePoint here;
1835 here.x = anycp->x;
1836 here.y = anycp->y;
1837 CVShowPoint(cv,&here);
1838 }
1839 SCUpdateAll(cv->b.sc);
1840 return( anycp!=NULL );
1841 } else {
1842 for ( ss= cv->b.layerheads[cv->b.drawmode]->splines; ss!=NULL; ss=ss->next ) {
1843 for ( sp=ss->first; ; ) {
1844 if ( bounds!=NULL ) {
1845 if ( sp->me.x >= base->x && sp->me.x <= base->x+bounds->x &&
1846 sp->me.y >= base->y && sp->me.y <= base->y+bounds->y ) {
1847 sp->selected = true;
1848 any = sp;
1849 }
1850 } else if ( fuzz>0 ) {
1851 if ( RealWithin(sp->me.x,base->x,fuzz) && RealWithin(sp->me.y,base->y,fuzz)) {
1852 sp->selected = true;
1853 any = Closest(base,any,sp);
1854 }
1855 } else {
1856 if ( RealNear(sp->me.x,base->x) && RealNear(sp->me.y,base->y)) {
1857 sp->selected = true;
1858 any = Closest(base,any,sp);
1859 goto done;
1860 }
1861 }
1862 if ( sp->next==NULL )
1863 break;
1864 sp = sp->next->to;
1865 if ( sp==ss->first )
1866 break;
1867 }
1868 }
1869 done:
1870 if ( any==NULL ) {
1871 CVShowPoint(cv,base);
1872 GDrawBeep(NULL);
1873 } else
1874 CVShowPoint(cv,&any->me);
1875 SCUpdateAll(cv->b.sc);
1876 return( any!=NULL );
1877 }
1878 }
1879
1880 #define CID_X 1001
1881 #define CID_Y 1002
1882 #define CID_Width 1003
1883 #define CID_Height 1004
1884 #define CID_Fuzz 1005
1885 #define CID_Exact 1006
1886 #define CID_Within 1007
1887 #define CID_Fuzzy 1008
1888
1889 struct selpt {
1890 int done;
1891 CharView *cv;
1892 GWindow gw;
1893 };
1894
1895 static void SPA_DoCancel(struct selpt *pa) {
1896 pa->done = true;
1897 }
1898
1899 static int SPA_OK(GGadget *g, GEvent *e) {
1900 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1901 GWindow gw = GGadgetGetWindow(g);
1902 struct selpt *pa = GDrawGetUserData(gw);
1903 CharView *cv = pa->cv;
1904 BasePoint base, bounds;
1905 double fuzz;
1906 int err = false, ret;
1907
1908 /* GT: X is a coordinate */
1909 base.x = GetReal8(gw,CID_X,_("X"),&err);
1910 /* GT: Y is a coordinate */
1911 base.y = GetReal8(gw,CID_Y,_("Y"),&err);
1912 if ( err )
1913 return( true );
1914 if ( GGadgetIsChecked(GWidgetGetControl(gw,CID_Exact)) )
1915 ret = SelectPointsWithin(cv, &base, 0, NULL );
1916 else if ( GGadgetIsChecked(GWidgetGetControl(gw,CID_Fuzzy)) ) {
1917 fuzz = GetReal8(gw,CID_Fuzz,_("Search Radius"),&err);
1918 if ( err )
1919 return( true );
1920 ret = SelectPointsWithin(cv, &base, fuzz, NULL );
1921 } else {
1922 bounds.x = GetReal8(gw,CID_Width,_("Width"),&err);
1923 bounds.y = GetReal8(gw,CID_Height,_("Height"),&err);
1924 if ( err )
1925 return( true );
1926 if ( bounds.x<0 ) {
1927 base.x += bounds.x;
1928 bounds.x = -bounds.x;
1929 }
1930 if ( bounds.y<0 ) {
1931 base.y += bounds.y;
1932 bounds.y = -bounds.y;
1933 }
1934 ret = SelectPointsWithin(cv, &base, 0, &bounds );
1935 }
1936 pa->done = ret;
1937 }
1938 return( true );
1939 }
1940
1941 static int SPA_Cancel(GGadget *g, GEvent *e) {
1942 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1943 struct selpt *pa = GDrawGetUserData(GGadgetGetWindow(g));
1944 SPA_DoCancel(pa);
1945 }
1946 return( true );
1947 }
1948
1949 static int SPA_Radius(GGadget *g, GEvent *e) {
1950 if ( e->type==et_controlevent ) {
1951 GWindow gw = GGadgetGetWindow(g);
1952 GGadgetSetChecked(GWidgetGetControl(gw,CID_Fuzzy),true);
1953 }
1954 return( true );
1955 }
1956
1957 static int SPA_Rect(GGadget *g, GEvent *e) {
1958 if ( e->type==et_controlevent ) {
1959 GWindow gw = GGadgetGetWindow(g);
1960 GGadgetSetChecked(GWidgetGetControl(gw,CID_Within),true);
1961 }
1962 return( true );
1963 }
1964
1965 static int spa_e_h(GWindow gw, GEvent *event) {
1966 if ( event->type==et_close ) {
1967 SPA_DoCancel( GDrawGetUserData(gw));
1968 } else if ( event->type == et_char ) {
1969 return( false );
1970 }
1971 return( true );
1972 }
1973
1974 void CVSelectPointAt(CharView *cv) {
1975 GRect pos;
1976 GWindow gw;
1977 GWindowAttrs wattrs;
1978 GGadgetCreateData gcd[18];
1979 GTextInfo label[18];
1980 static struct selpt pa;
1981 int k;
1982 int first = false;
1983
1984 pa.done = false;
1985 pa.cv = cv;
1986
1987 if ( pa.gw==NULL ) {
1988 memset(&wattrs,0,sizeof(wattrs));
1989 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
1990 wattrs.event_masks = ~(1<<et_charup);
1991 wattrs.restrict_input_to_me = 1;
1992 wattrs.undercursor = 1;
1993 wattrs.cursor = ct_pointer;
1994 wattrs.utf8_window_title = _("Select Point(s) at...");
1995 wattrs.is_dlg = true;
1996 pos.x = pos.y = 0;
1997 pos.width = GGadgetScale(GDrawPointsToPixels(NULL,190));
1998 pos.height = GDrawPointsToPixels(NULL,175);
1999 pa.gw = gw = GDrawCreateTopWindow(NULL,&pos,spa_e_h,&pa,&wattrs);
2000
2001 memset(&label,0,sizeof(label));
2002 memset(&gcd,0,sizeof(gcd));
2003
2004 k = 0;
2005 label[k].text = (unichar_t *) _("_X:");
2006 label[k].text_is_1byte = true;
2007 label[k].text_in_resource = true;
2008 gcd[k].gd.label = &label[k];
2009 gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = 8+4;
2010 gcd[k].gd.flags = gg_enabled|gg_visible;
2011 gcd[k++].creator = GLabelCreate;
2012
2013 gcd[k].gd.pos.x = 30; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4; gcd[k].gd.pos.width = 40;
2014 gcd[k].gd.flags = gg_enabled|gg_visible;
2015 gcd[k].gd.cid = CID_X;
2016 gcd[k++].creator = GTextFieldCreate;
2017
2018 label[k].text = (unichar_t *) _("_Y:");
2019 label[k].text_is_1byte = true;
2020 label[k].text_in_resource = true;
2021 gcd[k].gd.label = &label[k];
2022 gcd[k].gd.pos.x = 80; gcd[k].gd.pos.y = gcd[k-2].gd.pos.y;
2023 gcd[k].gd.flags = gg_enabled|gg_visible;
2024 gcd[k++].creator = GLabelCreate;
2025
2026 gcd[k].gd.pos.x = 100; gcd[k].gd.pos.y = gcd[k-2].gd.pos.y; gcd[k].gd.pos.width = 40;
2027 gcd[k].gd.flags = gg_enabled|gg_visible;
2028 gcd[k].gd.cid = CID_Y;
2029 gcd[k++].creator = GTextFieldCreate;
2030
2031 label[k].text = (unichar_t *) _("_Exact");
2032 label[k].text_is_1byte = true;
2033 label[k].text_in_resource = true;
2034 gcd[k].gd.label = &label[k];
2035 gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+23;
2036 gcd[k].gd.flags = gg_enabled|gg_visible|gg_cb_on;
2037 gcd[k].gd.cid = CID_Exact;
2038 gcd[k++].creator = GRadioCreate;
2039
2040 label[k].text = (unichar_t *) _("_Around");
2041 label[k].text_is_1byte = true;
2042 label[k].text_in_resource = true;
2043 gcd[k].gd.label = &label[k];
2044 gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+13;
2045 gcd[k].gd.flags = gg_enabled|gg_visible;
2046 gcd[k].gd.cid = CID_Fuzzy;
2047 gcd[k++].creator = GRadioCreate;
2048
2049 label[k].text = (unichar_t *) _("W_ithin Rectangle");
2050 label[k].text_is_1byte = true;
2051 label[k].text_in_resource = true;
2052 gcd[k].gd.label = &label[k];
2053 gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+16+24;
2054 gcd[k].gd.flags = gg_enabled|gg_visible;
2055 gcd[k].gd.cid = CID_Within;
2056 gcd[k++].creator = GRadioCreate;
2057
2058 label[k].text = (unichar_t *) _("_Radius:");
2059 label[k].text_is_1byte = true;
2060 label[k].text_in_resource = true;
2061 gcd[k].gd.label = &label[k];
2062 gcd[k].gd.pos.x = 15; gcd[k].gd.pos.y = gcd[k-2].gd.pos.y+17+4;
2063 gcd[k].gd.flags = gg_enabled|gg_visible;
2064 gcd[k++].creator = GLabelCreate;
2065
2066 label[k].text = (unichar_t *) _("3");
2067 label[k].text_is_1byte = true;
2068 label[k].text_in_resource = true;
2069 gcd[k].gd.label = &label[k];
2070 gcd[k].gd.pos.x = 52; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4; gcd[k].gd.pos.width = 40;
2071 gcd[k].gd.flags = gg_enabled|gg_visible;
2072 gcd[k].gd.cid = CID_Fuzz;
2073 gcd[k].gd.handle_controlevent = SPA_Radius;
2074 gcd[k++].creator = GTextFieldCreate;
2075
2076 label[k].text = (unichar_t *) _("_Width:");
2077 label[k].text_is_1byte = true;
2078 label[k].text_in_resource = true;
2079 gcd[k].gd.label = &label[k];
2080 gcd[k].gd.pos.x = 15; gcd[k].gd.pos.y = gcd[k-3].gd.pos.y+17+4;
2081 gcd[k].gd.flags = gg_enabled|gg_visible;
2082 gcd[k++].creator = GLabelCreate;
2083
2084 gcd[k].gd.pos.x = 52; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4; gcd[k].gd.pos.width = 40;
2085 gcd[k].gd.flags = gg_enabled|gg_visible;
2086 gcd[k].gd.cid = CID_Width;
2087 gcd[k].gd.handle_controlevent = SPA_Rect;
2088 gcd[k++].creator = GTextFieldCreate;
2089
2090 label[k].text = (unichar_t *) _("_Height:");
2091 label[k].text_is_1byte = true;
2092 label[k].text_in_resource = true;
2093 gcd[k].gd.label = &label[k];
2094 gcd[k].gd.pos.x = 100; gcd[k].gd.pos.y = gcd[k-2].gd.pos.y;
2095 gcd[k].gd.flags = gg_enabled|gg_visible;
2096 gcd[k++].creator = GLabelCreate;
2097
2098 gcd[k].gd.pos.x = 138; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4; gcd[k].gd.pos.width = 40;
2099 gcd[k].gd.flags = gg_enabled|gg_visible;
2100 gcd[k].gd.cid = CID_Height;
2101 gcd[k].gd.handle_controlevent = SPA_Rect;
2102 gcd[k++].creator = GTextFieldCreate;
2103
2104 gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+28;
2105 gcd[k].gd.pos.width = GDrawPixelsToPoints(gw,pos.width)-10;
2106 gcd[k].gd.flags = gg_enabled|gg_visible;
2107 gcd[k++].creator = GLineCreate;
2108
2109 gcd[k].gd.pos.x = 20-3; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+8;
2110 gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0;
2111 gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_default;
2112 label[k].text = (unichar_t *) _("_OK");
2113 label[k].text_is_1byte = true;
2114 label[k].text_in_resource = true;
2115 gcd[k].gd.label = &label[k];
2116 gcd[k].gd.handle_controlevent = SPA_OK;
2117 gcd[k++].creator = GButtonCreate;
2118
2119 gcd[k].gd.pos.x = -20; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+3;
2120 gcd[k].gd.pos.width = -1; gcd[k].gd.pos.height = 0;
2121 gcd[k].gd.flags = gg_visible | gg_enabled | gg_but_cancel;
2122 label[k].text = (unichar_t *) _("_Cancel");
2123 label[k].text_is_1byte = true;
2124 label[k].text_in_resource = true;
2125 gcd[k].gd.label = &label[k];
2126 gcd[k].gd.handle_controlevent = SPA_Cancel;
2127 gcd[k++].creator = GButtonCreate;
2128
2129 gcd[k].gd.pos.x = 2; gcd[k].gd.pos.y = 2;
2130 gcd[k].gd.pos.width = pos.width-4; gcd[k].gd.pos.height = pos.height-4;
2131 gcd[k].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels;
2132 gcd[k++].creator = GGroupCreate;
2133
2134 GGadgetsCreate(gw,gcd);
2135 first = true;
2136 } else {
2137 GTextFieldSelect(GWidgetGetControl(pa.gw,CID_X),0,-1);
2138 }
2139 GWidgetIndicateFocusGadget(GWidgetGetControl(pa.gw,CID_X));
2140 GDrawSetVisible(pa.gw,true);
2141 GDrawProcessOneEvent(NULL);
2142 if ( first )
2143 GGadgetSetChecked(GWidgetGetControl(gw,CID_Exact),true);
2144 while ( !pa.done )
2145 GDrawProcessOneEvent(NULL);
2146 GDrawSetVisible(pa.gw,false);
2147
2148 }