| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include <fontforge-config.h> |
| 29 |
|
| 30 |
#include "cvundoes.h" |
| 31 |
#include "fontforgeui.h" |
| 32 |
#include "nonlineartrans.h" |
| 33 |
#include <math.h> |
| 34 |
|
| 35 |
|
| 36 |
static void ScaleSetOppositeOrigin(CharView *cv) { |
| 37 |
BasePoint center; |
| 38 |
|
| 39 |
CVFindCenter(cv, ¢er, !CVAnySel(cv,NULL,NULL,NULL,NULL)); |
| 40 |
cv->expandorigin.x = 2*center.x - cv->p.cx; |
| 41 |
cv->expandorigin.y = 2*center.y - cv->p.cy; |
| 42 |
cv->expandwidth = cv->p.cx - cv->expandorigin.x; |
| 43 |
cv->expandheight = cv->p.cy - cv->expandorigin.y; |
| 44 |
} |
| 45 |
|
| 46 |
void CVMouseDownTransform(CharView *cv) { |
| 47 |
CVPreserveTState(cv); |
| 48 |
if ( cv->active_tool==cvt_scale ) |
| 49 |
ScaleSetOppositeOrigin(cv); |
| 50 |
} |
| 51 |
|
| 52 |
void CVMouseMoveTransform(CharView *cv) { |
| 53 |
CharViewTab* tab = CVGetActiveTab(cv); |
| 54 |
real transform[6]; |
| 55 |
|
| 56 |
CVRestoreTOriginalState(cv); |
| 57 |
if ( cv->info.x != cv->p.cx || cv->info.y != cv->p.cy ) { |
| 58 |
transform[0] = transform[3] = 1; |
| 59 |
transform[1] = transform[2] = 0; |
| 60 |
switch ( cv->active_tool ) { |
| 61 |
case cvt_rotate: { |
| 62 |
real angle = atan2(cv->info.y-cv->p.cy,cv->info.x-cv->p.cx); |
| 63 |
transform[0] = transform[3] = cos(angle); |
| 64 |
transform[2] = -(transform[1] = sin(angle)); |
| 65 |
} break; |
| 66 |
case cvt_flip: { |
| 67 |
real dx,dy; |
| 68 |
if (( dx = cv->info.x-cv->p.cx)<0 ) dx=-dx; |
| 69 |
if (( dy = cv->info.y-cv->p.cy)<0 ) dy=-dy; |
| 70 |
if ( dy>2*dx ) |
| 71 |
transform[0] = -1; |
| 72 |
else if ( dx>2*dy ) |
| 73 |
transform[3] = -1; |
| 74 |
else if ( (cv->info.x-cv->p.cx)*(cv->info.y-cv->p.cy)>0 ) { |
| 75 |
transform[0] = transform[3] = 0; |
| 76 |
transform[1] = transform[2] = -1; |
| 77 |
} else { |
| 78 |
transform[0] = transform[3] = 0; |
| 79 |
transform[1] = transform[2] = 1; |
| 80 |
} |
| 81 |
} break; |
| 82 |
case cvt_scale: { |
| 83 |
|
| 84 |
transform[0] = cv->expandwidth==0 ? 1 : (cv->info.x-cv->expandorigin.x)/cv->expandwidth; |
| 85 |
transform[3] = cv->expandheight==0 ? 1 : (cv->info.y-cv->expandorigin.y)/cv->expandheight; |
| 86 |
|
| 87 |
|
| 88 |
if ( cv->expandedge==ee_left || cv->expandedge==ee_right ) |
| 89 |
transform[3] = 1; |
| 90 |
else if ( cv->expandedge==ee_up || cv->expandedge==ee_down ) |
| 91 |
transform[0] = 1; |
| 92 |
} break; |
| 93 |
case cvt_skew: { |
| 94 |
real angle = atan2(cv->info.y-cv->p.cy,cv->info.x-cv->p.cx); |
| 95 |
transform[2] = sin(angle); |
| 96 |
} break; |
| 97 |
case cvt_3d_rotate: { |
| 98 |
real angle = atan2(cv->info.y-cv->p.cy,cv->info.x-cv->p.cx); |
| 99 |
|
| 100 |
real zangle = sqrt( (cv->info.x-cv->p.cx)*(cv->info.x-cv->p.cx) + |
| 101 |
(cv->info.y-cv->p.cy)*(cv->info.y-cv->p.cy) ) * tab->scale * |
| 102 |
FF_PI/180; |
| 103 |
real s = sin(angle), c = cos(angle); |
| 104 |
real cz = cos(zangle); |
| 105 |
transform[0] = c*c + s*s*cz; |
| 106 |
transform[3] = s*s + c*c*cz; |
| 107 |
transform[2] = transform[1] = c*s * (cz-1); |
| 108 |
} break; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
case cvt_perspective: { |
| 116 |
real angle = atan2(cv->p.cy,cv->p.cx); |
| 117 |
real s = sin(angle), c = cos(angle); |
| 118 |
transform[0] = transform[3] = c; |
| 119 |
transform[2] = -(transform[1] = -s); |
| 120 |
transform[4] = transform[5] = 0; |
| 121 |
CVTransFunc(cv,transform,false); |
| 122 |
CVYPerspective((CharViewBase *) cv, |
| 123 |
c*cv->info.x + s*cv->info.y, |
| 124 |
-s*cv->info.x + c*cv->info.y); |
| 125 |
transform[2] = -(transform[1] = s); |
| 126 |
} break; |
| 127 |
default: |
| 128 |
break; |
| 129 |
} |
| 130 |
if ( cv->active_tool==cvt_scale ) { |
| 131 |
|
| 132 |
transform[4] = (1-transform[0])*cv->expandorigin.x; |
| 133 |
transform[5] = (1-transform[3])*cv->expandorigin.y; |
| 134 |
} else if ( cv->active_tool!=cvt_perspective ) { |
| 135 |
|
| 136 |
transform[4] = -cv->p.cx*transform[0] - |
| 137 |
cv->p.cy*transform[2] + |
| 138 |
cv->p.cx; |
| 139 |
transform[5] = -cv->p.cy*transform[3] - |
| 140 |
cv->p.cx*transform[1] + |
| 141 |
cv->p.cy; |
| 142 |
} |
| 143 |
CVSetCharChanged(cv,true); |
| 144 |
|
| 145 |
CVTransFunc(cv, transform, cv->active_tool==cvt_scale && !CVAnySel(cv,NULL,NULL,NULL,NULL) |
| 146 |
? fvt_dontmovewidth : false); |
| 147 |
} |
| 148 |
SCUpdateAll(cv->b.sc); |
| 149 |
CVGridHandlePossibleFitChar(cv); |
| 150 |
} |
| 151 |
|
| 152 |
void CVMouseUpTransform(CharView *cv) { |
| 153 |
if ( cv->info.x == cv->p.cx && cv->info.y == cv->p.cy ) |
| 154 |
{ |
| 155 |
|
| 156 |
cv->needsrasterize = cv->recentchange = false; |
| 157 |
CVRemoveTopUndo(&cv->b); |
| 158 |
SCUpdateAll(cv->b.sc); |
| 159 |
CVGridHandlePossibleFitChar(cv); |
| 160 |
} |
| 161 |
else |
| 162 |
{ |
| 163 |
CVUndoCleanup(cv); |
| 164 |
} |
| 165 |
} |