1 package com.badlogic.gdx.tools.flame; 2 3 import java.awt.GridBagConstraints; 4 import java.awt.Insets; 5 import java.awt.event.ActionEvent; 6 import java.awt.event.ActionListener; 7 8 import javax.swing.DefaultComboBoxModel; 9 import javax.swing.JCheckBox; 10 import javax.swing.JComboBox; 11 import javax.swing.JLabel; 12 import javax.swing.event.ChangeEvent; 13 import javax.swing.event.ChangeListener; 14 15 import com.badlogic.gdx.graphics.g3d.particles.ParticleShader.AlignMode; 16 import com.badlogic.gdx.graphics.g3d.particles.ParticleSorter; 17 import com.badlogic.gdx.graphics.g3d.particles.batches.BillboardParticleBatch; 18 19 /** @author Inferno */ 20 public class BillboardBatchPanel extends EditorPanel<BillboardParticleBatch> { 21 private enum AlignModeWrapper{ 22 Screen( AlignMode.Screen, "Screen"), 23 ViewPoint(AlignMode.ViewPoint, "View Point"); 24 //ParticleDirection( AlignMode.ParticleDirection, "Particle Direction"); 25 26 public String desc; 27 public AlignMode mode; 28 AlignModeWrapper(AlignMode mode, String desc){ 29 this.mode = mode; 30 this.desc = desc; 31 } 32 33 @Override 34 public String toString () { 35 return desc; 36 } 37 } 38 39 private enum SortMode{ 40 None( "None", new ParticleSorter.None()), 41 Distance("Distance", new ParticleSorter.Distance()); 42 43 public String desc; 44 public ParticleSorter sorter; 45 SortMode(String desc, ParticleSorter sorter){ 46 this.sorter = sorter; 47 this.desc = desc; 48 } 49 50 @Override 51 public String toString () { 52 return desc; 53 } 54 } 55 56 57 JComboBox alignCombo; 58 JCheckBox useGPUBox; 59 JComboBox sortCombo; 60 61 public BillboardBatchPanel (FlameMain particleEditor3D, BillboardParticleBatch renderer) { 62 super(particleEditor3D, "Billboard Batch", "Renderer used to draw billboards particles."); 63 initializeComponents(renderer); 64 setValue(renderer); 65 } 66 67 private void initializeComponents (BillboardParticleBatch renderer) { 68 //Align 69 alignCombo = new JComboBox(); 70 alignCombo.setModel(new DefaultComboBoxModel(AlignModeWrapper.values())); 71 alignCombo.setSelectedItem(getAlignModeWrapper(renderer.getAlignMode())); 72 alignCombo.addActionListener(new ActionListener() { 73 public void actionPerformed (ActionEvent event) { 74 AlignModeWrapper align = (AlignModeWrapper)alignCombo.getSelectedItem(); 75 editor.getBillboardBatch().setAlignMode(align.mode); 76 } 77 }); 78 79 //Cpu/Gpu 80 useGPUBox = new JCheckBox(); 81 useGPUBox.setSelected(renderer.isUseGPU()); 82 useGPUBox.addChangeListener(new ChangeListener() { 83 public void stateChanged (ChangeEvent event) { 84 editor.getBillboardBatch().setUseGpu(useGPUBox.isSelected()); 85 } 86 }); 87 88 //Sort 89 sortCombo = new JComboBox(); 90 sortCombo.setModel(new DefaultComboBoxModel(SortMode.values())); 91 sortCombo.setSelectedItem(getSortMode(renderer.getSorter())); 92 sortCombo.addActionListener(new ActionListener() { 93 public void actionPerformed (ActionEvent event) { 94 SortMode mode = (SortMode)sortCombo.getSelectedItem(); 95 editor.getBillboardBatch().setSorter(mode.sorter); 96 } 97 }); 98 99 int i =0; 100 contentPanel.add(new JLabel("Align"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, 101 new Insets(6, 0, 0, 0), 0, 0)); 102 contentPanel.add(alignCombo, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, 103 new Insets(6, 0, 0, 0), 0, 0)); 104 contentPanel.add(new JLabel("Use GPU"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, 105 new Insets(6, 0, 0, 0), 0, 0)); 106 contentPanel.add(useGPUBox, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, 107 new Insets(6, 0, 0, 0), 0, 0)); 108 contentPanel.add(new JLabel("Sort"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, 109 new Insets(6, 0, 0, 0), 0, 0)); 110 contentPanel.add(sortCombo, new GridBagConstraints(1, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, 111 new Insets(6, 0, 0, 0), 0, 0)); 112 } 113 114 private Object getSortMode (ParticleSorter sorter) { 115 Class type = sorter.getClass(); 116 for(SortMode wrapper : SortMode.values()){ 117 if(wrapper.sorter.getClass() == type) 118 return wrapper; 119 } 120 return null; 121 } 122 123 private Object getAlignModeWrapper (AlignMode alignMode) { 124 for(AlignModeWrapper wrapper : AlignModeWrapper.values()){ 125 if(wrapper.mode == alignMode) 126 return wrapper; 127 } 128 return null; 129 } 130 131 } 132