Skip to content

Commit f51a25f

Browse files
vogellaclaude
andcommitted
Migrate remaining OldSchoolEffect examples to GraphicsExample
Completes the migration tracked in #3189 by adding the remaining 11 effects plus Lake: Phase 2 (image-based): - Wobble (bu.jpg) - Wormhole (texture.png) - Dancing (with light) - Lake (ash.jpg) - reimplemented with direct pixel manipulation so the mirror/wave effect renders consistently on Linux, where GC.copyArea on image-backed GCs differed from Win32/Cocoa. Uses ImageData.transparentPixel for out-of-range reflection rows and a 10 px seam between image and mirror so ash.jpg's near-black edges don't show as moving dark bands. Phase 3 (complex): - RotoZoom (tux256256.png) - Tunnel (tunnelstonetex.png) - Voxel (heightmap1.gif + colormap.jpg) - Sine Scroll (font_classic_16x16.gif, Star as inner class) - Simple Scroll - Advanced Scroll - Star Wars Scroll (row-wise scaling for perspective) Polish applied across the tabs based on visual review: - Enlarge small renders via scale-on-draw: Twirl 3x, BlockEffect 3x, Sky/SineScroll/Ripple 2x. Enlarge Tunnel (640x480) and Voxel (640x400) render buffers. - Ripple: seed 6 ripples at startup, drop automatic ripples so the effect is visible without mouse input, overlay a hint telling the user to hover. - BlockEffect: hold the unblocked image for ~40 frames before starting to blockify again. - SimpleScroll / StarWarsScroll: credit Laurent Caron in the scrolling text. Closes #3189 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c312bcf commit f51a25f

24 files changed

Lines changed: 2082 additions & 23 deletions

examples/org.eclipse.swt.examples/src/examples_graphics.properties

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ StarPolygonDescription=This tab draws a polygon and shows the effects of setting
190190
AntialiasingTextDesc=This tab demonstrates antialiasing for text. Antialiasing is used for smoothing jagged edges in graphics. This tab allows the user to see the effects of different antialiasing values.
191191
Ripple=Ripple
192192
RippleDescription=This is a miscellaneous demonstration that uses a displacement map to simulate water ripples on an image. Move the mouse over the image to disturb the water.
193+
RippleHint=Move the mouse over the image to create ripples
193194

194195
Blob=Blob
195196
BlobDescription=This is a miscellaneous demonstration of an animated metaball effect where multiple blobs move randomly and blend together when overlapping.
@@ -256,3 +257,36 @@ UnlimitedBallsDescription=This is a miscellaneous demonstration of an animated u
256257

257258
Warp=Warp
258259
WarpDescription=This is a miscellaneous demonstration of an animated warp distortion effect that uses a precomputed distortion lookup table to render a texture with animated warping.
260+
261+
Wobble=Wobble
262+
WobbleDescription=This is a miscellaneous demonstration of an animated wobble distortion that warps a texture with rotating sine/cosine deformations.
263+
264+
Wormhole=Wormhole
265+
WormholeDescription=This is a miscellaneous demonstration of an animated wormhole effect produced by mapping a precomputed spoke pattern to a scrolling texture.
266+
267+
Lake=Lake
268+
LakeDescription=This is a miscellaneous demonstration of an animated lake reflection where the bottom half shows a wave-distorted mirror of the source image.
269+
270+
DancingLight=Dancing (with light)
271+
DancingLightDescription=This is a miscellaneous demonstration of an animated isometric dancing shape illuminated by a moving point light source.
272+
273+
RotoZoom=Roto Zoom
274+
RotoZoomDescription=This is a miscellaneous demonstration of an animated rotozoom effect where a tiling texture is rotated and zoomed using precomputed sine tables.
275+
276+
Tunnel=Tunnel
277+
TunnelDescription=This is a miscellaneous demonstration of an animated tunnel effect using a precomputed distance and angle lookup table mapped against a scrolling stone texture.
278+
279+
Voxel=Voxel
280+
VoxelDescription=This is a miscellaneous demonstration of an animated voxel terrain rendered by raycasting against a heightmap and colormap, with the camera automatically flying over the landscape.
281+
282+
SineScroll=Sine Scroll
283+
SineScrollDescription=This is a miscellaneous demonstration of an animated sine-scroller: a classic amiga-style banner text flying across a starfield and gradient bars along a sine curve.
284+
285+
SimpleScroll=Simple Scroll
286+
SimpleScrollDescription=This is a miscellaneous demonstration of a simple vertical text scroller that loops a block of centered lines from the bottom of the canvas upward.
287+
288+
AdvancedScroll=Advanced Scroll
289+
AdvancedScrollDescription=This is a miscellaneous demonstration of a vertical text scroller with top and bottom gradient fade effects so lines smoothly appear from the bottom and vanish into the top.
290+
291+
StarWarsScroll=Star Wars Scroll
292+
StarWarsScrollDescription=This is a miscellaneous demonstration of a Star Wars style scroller: text scrolls up the canvas and a row-wise scaling transform tapers the lines toward the horizon to give a perspective effect.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2018 Laurent Caron and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Laurent Caron (laurent.caron at gmail dot com) - Initial Contributor
13+
* IBM Corporation - adaptation to GraphicsExample
14+
*******************************************************************************/
15+
16+
package org.eclipse.swt.examples.graphics;
17+
18+
import org.eclipse.swt.SWT;
19+
import org.eclipse.swt.graphics.Font;
20+
import org.eclipse.swt.graphics.GC;
21+
import org.eclipse.swt.graphics.Point;
22+
23+
/**
24+
* This tab displays a vertical text scroller with top and bottom gradient fade
25+
* effects so lines smoothly appear from the bottom and vanish into the top.
26+
*/
27+
public class AdvancedScrollTab extends AnimatedGraphicsTab {
28+
29+
private static final int FONT_SIZE = 14;
30+
private static final int STEP = 1;
31+
private static final String[] LINES = {
32+
"SWT Graphics Example",
33+
"Advanced Scroll Effect",
34+
"",
35+
"Lines scroll up the screen",
36+
"with a gradient fade on",
37+
"the top and bottom edges.",
38+
"",
39+
"Enjoy the show!",
40+
};
41+
42+
private int y = -1;
43+
private int lastHeight;
44+
45+
public AdvancedScrollTab(GraphicsExample example) {
46+
super(example);
47+
}
48+
49+
@Override
50+
public String getCategory() {
51+
return GraphicsExample.getResourceString("Misc"); //$NON-NLS-1$
52+
}
53+
54+
@Override
55+
public String getText() {
56+
return GraphicsExample.getResourceString("AdvancedScroll"); //$NON-NLS-1$
57+
}
58+
59+
@Override
60+
public String getDescription() {
61+
return GraphicsExample.getResourceString("AdvancedScrollDescription"); //$NON-NLS-1$
62+
}
63+
64+
@Override
65+
public int getInitialAnimationTime() {
66+
return 10;
67+
}
68+
69+
@Override
70+
public void next(int width, int height) {
71+
if (y < 0 || height != lastHeight) {
72+
y = height + 10;
73+
lastHeight = height;
74+
}
75+
y -= STEP;
76+
}
77+
78+
@Override
79+
public void paint(GC gc, int width, int height) {
80+
if (y < 0) {
81+
y = height + 10;
82+
lastHeight = height;
83+
}
84+
85+
gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
86+
gc.fillRectangle(0, 0, width, height);
87+
88+
Font font = new Font(gc.getDevice(), "Lucida Sans", FONT_SIZE, SWT.NORMAL); //$NON-NLS-1$
89+
Font previous = gc.getFont();
90+
gc.setFont(font);
91+
gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
92+
gc.setAdvanced(true);
93+
gc.setAntialias(SWT.ON);
94+
95+
int currentY = y;
96+
for (String line : LINES) {
97+
Point ts = gc.stringExtent(line);
98+
int x = (width - ts.x) / 2;
99+
gc.drawString(line, x, currentY, true);
100+
currentY += (int) (ts.y * 1.5);
101+
}
102+
103+
if (currentY <= 0) {
104+
y = height + 10;
105+
}
106+
107+
gc.setFont(previous);
108+
font.dispose();
109+
110+
int maxSize = (int) (height * 0.1);
111+
if (maxSize > 0) {
112+
int step = 255 / maxSize;
113+
gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
114+
int alpha = 255;
115+
for (int i = 0; i < maxSize; i++) {
116+
gc.setAlpha(alpha);
117+
gc.drawLine(0, i, width, i);
118+
alpha -= step;
119+
}
120+
alpha = 255;
121+
for (int i = 0; i < maxSize; i++) {
122+
gc.setAlpha(alpha);
123+
gc.drawLine(0, height - 1 - i, width, height - 1 - i);
124+
alpha -= step;
125+
}
126+
gc.setAlpha(255);
127+
}
128+
}
129+
}

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/BlockEffectTab.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626
*/
2727
public class BlockEffectTab extends AnimatedGraphicsTab {
2828

29+
private static final int DISPLAY_SCALE = 3;
30+
2931
private ImageData sourceImage;
3032
private ImageData imageData;
3133
private Image outputImage;
3234
private int imgWidth, imgHeight;
3335
private int blockSize;
3436
private int direction;
37+
private int holdFrames;
3538

3639
public BlockEffectTab(GraphicsExample example) {
3740
super(example);
@@ -72,11 +75,20 @@ public void next(int width, int height) {
7275
}
7376

7477
imageData = filter(sourceImage, blockSize);
78+
79+
// Hold the unblocked (blockSize=1) state for ~40 frames so the real
80+
// image is visible before blocks start growing again.
81+
if (holdFrames > 0) {
82+
holdFrames--;
83+
return;
84+
}
85+
7586
blockSize += direction;
7687

7788
if (blockSize <= 1) {
7889
direction = 1;
7990
blockSize = 1;
91+
holdFrames = 40;
8092
}
8193

8294
if (blockSize >= imgWidth / 4) {
@@ -113,9 +125,11 @@ public void paint(GC gc, int width, int height) {
113125
}
114126
outputImage = new Image(gc.getDevice(), imageData);
115127

116-
int x = (width - imgWidth) / 2;
117-
int y = (height - imgHeight) / 2;
118-
gc.drawImage(outputImage, x, y);
128+
int dw = imgWidth * DISPLAY_SCALE;
129+
int dh = imgHeight * DISPLAY_SCALE;
130+
int x = (width - dw) / 2;
131+
int y = (height - dh) / 2;
132+
gc.drawImage(outputImage, 0, 0, imgWidth, imgHeight, x, y, dw, dh);
119133
}
120134

121135
private ImageData filter(ImageData src, int size) {

0 commit comments

Comments
 (0)