Revision 3f07bedc
Added by Leszek Koltunski about 8 years ago
src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java | ||
---|---|---|
44 | 44 |
public class Effects2DActivity extends Activity implements AdapterView.OnItemSelectedListener |
45 | 45 |
{ |
46 | 46 |
private Spinner mAdd, mID, mName, mType; |
47 |
private static ArrayAdapter<String> mAdapterAdd, mAdapterName, mAdapterType; |
|
48 | 47 |
private static ArrayAdapter<Long> mAdapterID; |
49 | 48 |
|
50 | 49 |
private int mPosID, mPosName, mPosType; |
... | ... | |
85 | 84 |
|
86 | 85 |
String[] itemsType = new String[] {"VERTEX", "FRAGMENT"}; |
87 | 86 |
|
88 |
mAdapterAdd = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName); |
|
89 |
mAdapterAdd.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
90 |
mAdd.setAdapter(mAdapterAdd); |
|
91 | 87 |
|
92 | 88 |
mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID); |
93 | 89 |
mAdapterID.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
94 | 90 |
mID.setAdapter(mAdapterID); |
95 | 91 |
|
96 |
mAdapterName = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName);
|
|
97 |
mAdapterName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
98 |
mName.setAdapter(mAdapterName);
|
|
92 |
ArrayAdapter<String> adapterAdd = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName);
|
|
93 |
adapterAdd.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
94 |
mAdd.setAdapter(adapterAdd);
|
|
99 | 95 |
|
100 |
mAdapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsType); |
|
101 |
mAdapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
102 |
mType.setAdapter(mAdapterType); |
|
96 |
ArrayAdapter<String> adapterName = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName); |
|
97 |
adapterName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
98 |
mName.setAdapter(adapterName); |
|
99 |
|
|
100 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsType); |
|
101 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
102 |
mType.setAdapter(adapterType); |
|
103 | 103 |
|
104 | 104 |
mLayoutList = (TableLayout)findViewById(R.id.effects2dTableList); |
105 | 105 |
} |
... | ... | |
149 | 149 |
{ |
150 | 150 |
switch(parent.getId()) |
151 | 151 |
{ |
152 |
case R.id.effects2d_spinnerAdd : Effects2DSurfaceView.setEffect(pos); break; |
|
152 |
case R.id.effects2d_spinnerAdd : Effects2DSurfaceView v = (Effects2DSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
153 |
v.setEffect(pos); break; |
|
153 | 154 |
case R.id.effects2d_spinnerID : mPosID = pos; break; |
154 | 155 |
case R.id.effects2d_spinnerName: mPosName = pos; break; |
155 | 156 |
case R.id.effects2d_spinnerType: mPosType = pos; break; |
... | ... | |
168 | 169 |
{ |
169 | 170 |
Long currID = (Long)mID.getItemAtPosition(mPosID); |
170 | 171 |
|
171 |
Effects2DRenderer.mBackground.abortEffect(currID); |
|
172 |
Effects2DSurfaceView v = (Effects2DSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
173 |
v.getRenderer().mBackground.abortEffect(currID); |
|
172 | 174 |
} |
173 | 175 |
|
174 | 176 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
187 | 189 |
default: name = EffectNames.CONTRAST ; |
188 | 190 |
} |
189 | 191 |
|
190 |
Effects2DRenderer.mBackground.abortEffects(name); |
|
192 |
Effects2DSurfaceView v = (Effects2DSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
193 |
v.getRenderer().mBackground.abortEffects(name); |
|
191 | 194 |
} |
192 | 195 |
|
193 | 196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
203 | 206 |
default: type = EffectTypes.MATRIX; |
204 | 207 |
} |
205 | 208 |
|
206 |
Effects2DRenderer.mBackground.abortEffects(type); |
|
209 |
Effects2DSurfaceView v = (Effects2DSurfaceView) this.findViewById(R.id.effects2dSurfaceView); |
|
210 |
v.getRenderer().mBackground.abortEffects(type); |
|
207 | 211 |
} |
208 | 212 |
|
209 | 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/examples/effects2d/Effects2DRenderer.java | ||
---|---|---|
41 | 41 |
|
42 | 42 |
public class Effects2DRenderer implements GLSurfaceView.Renderer, EffectListener |
43 | 43 |
{ |
44 |
public static final int NUMLINES = 10;
|
|
45 |
public static final int BWID = 300;
|
|
46 |
public static final int BHEI = 400;
|
|
44 |
private static final int NUMLINES = 10;
|
|
45 |
static final int BWID = 300; |
|
46 |
static final int BHEI = 400; |
|
47 | 47 |
|
48 |
private GLSurfaceView mView; |
|
49 |
public static DistortedBitmap mBackground; |
|
48 |
private Effects2DSurfaceView mView; |
|
50 | 49 |
private Paint mPaint; |
51 | 50 |
private int texWidth, texHeight; |
52 |
|
|
51 |
|
|
52 |
DistortedBitmap mBackground; |
|
53 |
|
|
53 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 55 |
|
55 |
public Effects2DRenderer(GLSurfaceView v)
|
|
56 |
Effects2DRenderer(Effects2DSurfaceView v)
|
|
56 | 57 |
{ |
57 | 58 |
mPaint = new Paint(); |
58 | 59 |
mPaint.setAntiAlias(true); |
... | ... | |
103 | 104 |
mBackground.abortEffects(EffectTypes.MATRIX); |
104 | 105 |
mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) ); |
105 | 106 |
Distorted.onSurfaceChanged(width,height); |
106 |
Effects2DSurfaceView.setScreenSize(width,height);
|
|
107 |
mView.setScreenSize(width,height);
|
|
107 | 108 |
} |
108 | 109 |
|
109 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/examples/effects2d/Effects2DSurfaceView.java | ||
---|---|---|
39 | 39 |
public class Effects2DSurfaceView extends GLSurfaceView |
40 | 40 |
{ |
41 | 41 |
private Effects2DRenderer mRenderer; |
42 |
private static int mCurrentEffect; |
|
43 |
private static int mDuration; |
|
44 |
private static float mCount; |
|
45 |
private static int mScrW, mScrH; |
|
42 |
private int mCurrentEffect; |
|
43 |
private int mScrW, mScrH; |
|
46 | 44 |
|
47 |
private static Static4D region; |
|
48 |
private static Static2D point; |
|
49 |
|
|
50 |
private static Static4D mRegion; |
|
51 |
private static Dynamic1D mInterA, mInterB, mInterC, mInterS; |
|
52 |
|
|
53 |
private static Dynamic3D mInterD; |
|
54 |
private static Static3D v0, v1, v2, v3; |
|
45 |
private Static4D mRegionV, mRegionF; |
|
46 |
private Static2D mPoint; |
|
47 |
private Dynamic1D mInterA, mInterB, mInterC, mInterS; |
|
48 |
private Dynamic3D mInterD; |
|
55 | 49 |
|
56 | 50 |
private final static Static3D mRED = new Static3D(1,0,0); |
57 | 51 |
|
... | ... | |
61 | 55 |
{ |
62 | 56 |
super(c, attrs); |
63 | 57 |
|
64 |
mDuration = 10000; |
|
65 |
mCount = 1.0f; |
|
66 |
|
|
67 |
mInterD = new Dynamic3D(mDuration,mCount); |
|
68 |
|
|
58 |
int duration = 10000; |
|
59 |
float count = 1.0f; |
|
69 | 60 |
int h = 30; |
70 | 61 |
int r = 20; |
71 | 62 |
|
72 |
v0 = new Static3D( 0, r, h ); |
|
73 |
v1 = new Static3D(-r, 0, h ); |
|
74 |
v2 = new Static3D( 0,-r, h ); |
|
75 |
v3 = new Static3D( r, 0, h ); |
|
63 |
mInterD = new Dynamic3D(duration,count); |
|
76 | 64 |
|
77 |
mInterD.add(v0);
|
|
78 |
mInterD.add(v1);
|
|
79 |
mInterD.add(v2);
|
|
80 |
mInterD.add(v3);
|
|
65 |
mInterD.add(new Static3D( 0, r, h ));
|
|
66 |
mInterD.add(new Static3D(-r, 0, h ));
|
|
67 |
mInterD.add(new Static3D( 0,-r, h ));
|
|
68 |
mInterD.add(new Static3D( r, 0, h ));
|
|
81 | 69 |
|
82 |
mInterA = new Dynamic1D(mDuration,mCount);
|
|
70 |
mInterA = new Dynamic1D(duration,count);
|
|
83 | 71 |
mInterA.add(new Static1D(1)); |
84 | 72 |
mInterA.add(new Static1D(0)); |
85 | 73 |
|
86 |
mInterS = new Dynamic1D(mDuration,mCount);
|
|
74 |
mInterS = new Dynamic1D(duration,count);
|
|
87 | 75 |
mInterS.add(new Static1D(1.0f)); |
88 | 76 |
mInterS.add(new Static1D(0.3f)); |
89 | 77 |
|
90 |
mInterC = new Dynamic1D(mDuration,mCount);
|
|
78 |
mInterC = new Dynamic1D(duration,count);
|
|
91 | 79 |
mInterC.add(new Static1D(1)); |
92 | 80 |
mInterC.add(new Static1D(0)); |
93 | 81 |
|
94 |
mInterB = new Dynamic1D(mDuration,mCount);
|
|
82 |
mInterB = new Dynamic1D(duration,count);
|
|
95 | 83 |
mInterB.add(new Static1D(0)); |
96 | 84 |
mInterB.add(new Static1D(1)); |
97 | 85 |
|
... | ... | |
110 | 98 |
mRenderer = new Effects2DRenderer(this); |
111 | 99 |
setRenderer(mRenderer); |
112 | 100 |
|
113 |
point = new Static2D(0,0);
|
|
114 |
region= new Static4D(0,0,60,60);
|
|
115 |
mRegion = new Static4D(0,0,60,60);
|
|
101 |
mPoint = new Static2D(0,0);
|
|
102 |
mRegionV= new Static4D(0,0,60,60);
|
|
103 |
mRegionF= new Static4D(0,0,60,60);
|
|
116 | 104 |
|
117 | 105 |
setEffect(0); |
118 | 106 |
} |
... | ... | |
120 | 108 |
|
121 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
122 | 110 |
|
123 |
public static void setScreenSize(int width, int height) |
|
111 |
Effects2DRenderer getRenderer() |
|
112 |
{ |
|
113 |
return mRenderer; |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
public void setScreenSize(int width, int height) |
|
124 | 119 |
{ |
125 | 120 |
mScrW = width; |
126 | 121 |
mScrH = height; |
... | ... | |
128 | 123 |
|
129 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
130 | 125 |
|
131 |
public static void setEffect(int effect)
|
|
126 |
public void setEffect(int effect) |
|
132 | 127 |
{ |
133 | 128 |
mCurrentEffect = effect; |
134 | 129 |
} |
... | ... | |
143 | 138 |
|
144 | 139 |
switch(action) |
145 | 140 |
{ |
146 |
case MotionEvent.ACTION_DOWN: x = (int)event.getX()* Effects2DRenderer.BWID/mScrW;
|
|
147 |
y = (int)event.getY()* Effects2DRenderer.BHEI/mScrH;
|
|
148 |
point.set(x,y);
|
|
149 |
mRegion.set(x,y,60,60); |
|
141 |
case MotionEvent.ACTION_DOWN: x = (int)event.getX()* mRenderer.BWID/mScrW;
|
|
142 |
y = (int)event.getY()* mRenderer.BHEI/mScrH;
|
|
143 |
mPoint.set(x,y);
|
|
144 |
mRegionF.set(x,y,60,60);
|
|
150 | 145 |
Effects2DActivity act = (Effects2DActivity)getContext(); |
151 | 146 |
|
152 | 147 |
switch(mCurrentEffect) |
153 | 148 |
{ |
154 |
case 0: id = Effects2DRenderer.mBackground.distort(mInterD, point, region);
|
|
149 |
case 0: id = mRenderer.mBackground.distort(mInterD, mPoint, mRegionV);
|
|
155 | 150 |
act.effectAdded(id, EffectNames.DISTORT, EffectTypes.VERTEX); |
156 | 151 |
break; |
157 |
case 1: id = Effects2DRenderer.mBackground.sink(mInterS, point, region);
|
|
152 |
case 1: id = mRenderer.mBackground.sink(mInterS, mPoint, mRegionV);
|
|
158 | 153 |
act.effectAdded(id, EffectNames.SINK, EffectTypes.VERTEX); |
159 | 154 |
break; |
160 |
case 2: id = Effects2DRenderer.mBackground.alpha(mInterA, mRegion, true);
|
|
155 |
case 2: id = mRenderer.mBackground.alpha(mInterA, mRegionF, true);
|
|
161 | 156 |
act.effectAdded(id, EffectNames.ALPHA, EffectTypes.FRAGMENT); |
162 | 157 |
break; |
163 |
case 3: id = Effects2DRenderer.mBackground.saturation(mInterB, mRegion, false);
|
|
158 |
case 3: id = mRenderer.mBackground.saturation(mInterB, mRegionF, false);
|
|
164 | 159 |
act.effectAdded(id, EffectNames.SATURATION, EffectTypes.FRAGMENT); |
165 | 160 |
break; |
166 |
case 4: id = Effects2DRenderer.mBackground.chroma(mInterC, mRED, mRegion, true);
|
|
161 |
case 4: id = mRenderer.mBackground.chroma(mInterC, mRED, mRegionF, true);
|
|
167 | 162 |
act.effectAdded(id, EffectNames.CHROMA, EffectTypes.FRAGMENT); |
168 | 163 |
break; |
169 | 164 |
} |
Also available in: Unified diff
Tidy up the 'Effects3D'