Revision 3a4f3ae2
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/glow/GlowActivity.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
public class GlowActivity extends Activity implements SeekBar.OnSeekBarChangeListener |
34 | 34 |
{ |
35 |
private TextView textGlow;
|
|
35 |
private TextView textRadius, textAlpha;
|
|
36 | 36 |
|
37 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 38 |
|
... | ... | |
41 | 41 |
{ |
42 | 42 |
super.onCreate(savedState); |
43 | 43 |
setContentView(R.layout.glowlayout); |
44 |
textGlow = (TextView)findViewById(R.id.glowText); |
|
45 |
SeekBar bar = (SeekBar)findViewById(R.id.glowSeek); |
|
44 |
|
|
45 |
textRadius = (TextView)findViewById(R.id.glowTextRadius); |
|
46 |
SeekBar bar = (SeekBar)findViewById(R.id.glowSeekRadius); |
|
47 |
bar.setOnSeekBarChangeListener(this); |
|
48 |
bar.setProgress(50); |
|
49 |
|
|
50 |
textAlpha = (TextView)findViewById(R.id.glowTextAlpha); |
|
51 |
bar = (SeekBar)findViewById(R.id.glowSeekAlpha); |
|
46 | 52 |
bar.setOnSeekBarChangeListener(this); |
47 | 53 |
bar.setProgress(50); |
48 | 54 |
} |
... | ... | |
85 | 91 |
|
86 | 92 |
switch (bar.getId()) |
87 | 93 |
{ |
88 |
case R.id.glowSeek: int level = view.getRenderer().setGlow(progress); |
|
89 |
textGlow.setText(getString(R.string.glow_placeholder,level)); |
|
90 |
break; |
|
94 |
case R.id.glowSeekRadius: int radius = view.getRenderer().setGlowRadius(progress); |
|
95 |
textRadius.setText(getString(R.string.glow_radius_placeholder,radius)); |
|
96 |
break; |
|
97 |
case R.id.glowSeekAlpha : float alpha = view.getRenderer().setGlowAlpha(progress); |
|
98 |
textAlpha.setText(getString(R.string.glow_alpha_placeholder, alpha)); |
|
99 |
break; |
|
91 | 100 |
} |
92 | 101 |
} |
93 | 102 |
|
src/main/java/org/distorted/examples/glow/GlowRenderer.java | ||
---|---|---|
54 | 54 |
private int mRootW, mRootH; |
55 | 55 |
private Static3D mMove, mScale; |
56 | 56 |
private Static1D mRadius; |
57 |
private Static4D mColor; |
|
57 | 58 |
|
58 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
59 | 60 |
|
... | ... | |
68 | 69 |
mScale = new Static3D(1,1,1); |
69 | 70 |
mRadius= new Static1D(25); |
70 | 71 |
|
71 |
Static4D color = new Static4D(1.0f,1.0f,0.0f,0.5f); // half-transparent yellow
|
|
72 |
mColor = new Static4D(1.0f,1.0f,0.0f,0.5f); // half-transparent yellow
|
|
72 | 73 |
|
73 | 74 |
DistortedEffects effects = new DistortedEffects(); |
74 | 75 |
effects.apply(new MatrixEffectMove(mMove)); |
75 | 76 |
effects.apply(new MatrixEffectScale(mScale)); |
76 |
effects.apply(new PostprocessEffectGlow(mRadius,color));
|
|
77 |
effects.apply(new PostprocessEffectGlow(mRadius,mColor));
|
|
77 | 78 |
|
78 | 79 |
mScreen = new DistortedScreen(); |
79 | 80 |
mScreen.attach(mLeaf, effects, new MeshFlat(1,1) ); |
... | ... | |
81 | 82 |
|
82 | 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 84 |
|
84 |
int setGlow(int glow) |
|
85 |
int setGlowRadius(int glow)
|
|
85 | 86 |
{ |
86 | 87 |
int radius = glow/2; |
87 | 88 |
mRadius.set(radius); |
88 | 89 |
return radius; |
89 | 90 |
} |
90 | 91 |
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
float setGlowAlpha(float glow) |
|
95 |
{ |
|
96 |
float alpha = glow/100.0f; |
|
97 |
mColor.set4(alpha); |
|
98 |
return alpha; |
|
99 |
} |
|
100 |
|
|
91 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
92 | 102 |
|
93 | 103 |
public void onDrawFrame(GL10 glUnused) |
src/main/res/layout/glowlayout.xml | ||
---|---|---|
18 | 18 |
android:orientation="horizontal" > |
19 | 19 |
|
20 | 20 |
<TextView |
21 |
android:id="@+id/glowText" |
|
21 |
android:id="@+id/glowTextRadius"
|
|
22 | 22 |
android:layout_width="150dp" |
23 | 23 |
android:layout_height="wrap_content" |
24 | 24 |
android:layout_weight="0.5" |
25 | 25 |
android:gravity="center_vertical|center" |
26 |
android:text="@string/glow" |
|
26 |
android:text="@string/glow_radius"
|
|
27 | 27 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
28 | 28 |
|
29 | 29 |
<SeekBar |
30 |
android:id="@+id/glowSeek" |
|
30 |
android:id="@+id/glowSeekRadius"
|
|
31 | 31 |
android:layout_width="fill_parent" |
32 | 32 |
android:layout_height="wrap_content" |
33 | 33 |
android:layout_weight="1" |
34 | 34 |
android:paddingLeft="15dp" |
35 | 35 |
android:paddingRight="10dp" /> |
36 |
</LinearLayout> |
|
37 |
|
|
38 |
<LinearLayout |
|
39 |
android:id="@+id/linearLayout2" |
|
40 |
android:layout_width="fill_parent" |
|
41 |
android:layout_height="wrap_content" |
|
42 |
android:gravity="center|fill_horizontal" |
|
43 |
android:orientation="horizontal" > |
|
44 |
|
|
45 |
<TextView |
|
46 |
android:id="@+id/glowTextAlpha" |
|
47 |
android:layout_width="150dp" |
|
48 |
android:layout_height="wrap_content" |
|
49 |
android:layout_weight="0.5" |
|
50 |
android:gravity="center_vertical|center" |
|
51 |
android:text="@string/glow_alpha" |
|
52 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
36 | 53 |
|
54 |
<SeekBar |
|
55 |
android:id="@+id/glowSeekAlpha" |
|
56 |
android:layout_width="fill_parent" |
|
57 |
android:layout_height="wrap_content" |
|
58 |
android:layout_weight="1" |
|
59 |
android:paddingLeft="15dp" |
|
60 |
android:paddingRight="10dp" /> |
|
37 | 61 |
</LinearLayout> |
38 | 62 |
|
39 | 63 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
14 | 14 |
<string name="contrast">Contrast</string> |
15 | 15 |
<string name="swirl">Swirl</string> |
16 | 16 |
<string name="blur">Blur</string> |
17 |
<string name="glow">Glow</string> |
|
17 |
<string name="glow_radius">Radius</string> |
|
18 |
<string name="glow_alpha">Alpha</string> |
|
18 | 19 |
|
19 | 20 |
<string name="continu">Continue</string> |
20 | 21 |
<string name="rows">Rows</string> |
... | ... | |
85 | 86 |
<string name="near_placeholder">Near: %1$.2f</string> |
86 | 87 |
<string name="wind_placeholder">Wind: %1$d</string> |
87 | 88 |
<string name="blur_placeholder">Blur: %1$d</string> |
88 |
<string name="glow_placeholder">Glow: %1$d</string> |
|
89 |
<string name="glow_radius_placeholder">Radius: %1$d</string> |
|
90 |
<string name="glow_alpha_placeholder">Alpha: %1$.2f</string> |
|
89 | 91 |
|
90 | 92 |
<string name="example_monalisa">Mona Lisa</string> |
91 | 93 |
<string name="example_monalisa_subtitle">The basics of Distortions.</string> |
Also available in: Unified diff
Improve 'Glow' app.