diff options
author | Kenneth Russel <[email protected]> | 2005-06-30 19:30:25 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-06-30 19:30:25 +0000 |
commit | 0afd53cb292d371c562aac7bb0e162ee2ff40bac (patch) | |
tree | f1c260f62b6659b9fb5fa6d96e4c8723e4fc55d7 /src/demos/jrefract | |
parent | bfef7ff416742912f7859792475f202e257b3bce (diff) |
Fixed Issue 168: Add support for transparency in GLJPanel
Obey setOpaque() when selecting buffered image type. User must still
request alpha bits in the GLCapabilities. Not supported on all
back-end renderers; for example, Microsoft GDI renderer does not
implement alpha bits when rendering to DIB sections. Added examples of
use in JGears and JRefract demos.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@96 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/jrefract')
-rwxr-xr-x | src/demos/jrefract/JRefract.java | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/src/demos/jrefract/JRefract.java b/src/demos/jrefract/JRefract.java index f47cfda..e842eba 100755 --- a/src/demos/jrefract/JRefract.java +++ b/src/demos/jrefract/JRefract.java @@ -83,13 +83,16 @@ public class JRefract { inner.setClosable(true); inner.setVisible(true); - final GLJPanel canvas = GLDrawableFactory.getFactory().createGLJPanel(new GLCapabilities()); + GLCapabilities caps = new GLCapabilities(); + if (!bunny) { + caps.setAlphaBits(8); + } + final GLJPanel canvas = GLDrawableFactory.getFactory().createGLJPanel(caps); if (bunny) { canvas.addGLEventListener(new Listener()); } else { canvas.addGLEventListener(new GearRenderer()); } - canvas.setSize(512, 512); canvas.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { canvas.requestFocus(); @@ -106,12 +109,36 @@ public class JRefract { }); inner.getContentPane().setLayout(new BorderLayout()); - inner.getContentPane().add(canvas, BorderLayout.CENTER); - inner.getContentPane().add(new JButton("West"), BorderLayout.WEST); - inner.getContentPane().add(new JButton("East"), BorderLayout.EAST); - inner.getContentPane().add(new JButton("North"), BorderLayout.NORTH); - inner.getContentPane().add(new JButton("South"), BorderLayout.SOUTH); - inner.setSize(canvas.getSize()); + if (bunny) { + inner.getContentPane().add(canvas, BorderLayout.CENTER); + inner.getContentPane().add(new JButton("West"), BorderLayout.WEST); + inner.getContentPane().add(new JButton("East"), BorderLayout.EAST); + inner.getContentPane().add(new JButton("North"), BorderLayout.NORTH); + inner.getContentPane().add(new JButton("South"), BorderLayout.SOUTH); + } else { + // Provide control over transparency of gears background + canvas.setOpaque(false); + JPanel gradientPanel = new JPanel() { + public void paintComponent(Graphics g) { + ((Graphics2D) g).setPaint(new GradientPaint(0, 0, Color.WHITE, + getWidth(), getHeight(), Color.DARK_GRAY)); + g.fillRect(0, 0, getWidth(), getHeight()); + } + }; + gradientPanel.setLayout(new BorderLayout()); + inner.getContentPane().add(gradientPanel, BorderLayout.CENTER); + gradientPanel.add(canvas, BorderLayout.CENTER); + + final JCheckBox checkBox = new JCheckBox("Transparent", true); + checkBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + canvas.setOpaque(!checkBox.isSelected()); + } + }); + inner.getContentPane().add(checkBox, BorderLayout.SOUTH); + } + + inner.setSize(512, 512); desktop.add(inner); return inner; |