Skip to content

Commit

Permalink
Vacuum Shader Editor
Browse files Browse the repository at this point in the history
* Use token marker cache for efficiency.
* Add missing localization tags.
* Remove precompile checkbox but leave in the model.
* ENIGMA plugin may still be depending on precompile in the model.
* Precompile was never supported by GMSv1.4 at all.
* Move shader type combo after name like GMSv1.4 for consistency.
  • Loading branch information
RobertBColton committed Jul 29, 2020
1 parent e8fd11e commit 475e6e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 71 deletions.
5 changes: 3 additions & 2 deletions org/lateralgm/components/MarkerCache.java
Expand Up @@ -47,7 +47,7 @@ public final class MarkerCache
* Get one of the cached markers or cache it if it doesn't exist.
*
* @param language
* One of available token markers, eg. "glsles", "glsl", "gml", "hlsl"
* One of available token markers, eg. "glsles", "glsl", "gml", "hlsl9", "hlsl11"
**/
public static DefaultTokenMarker getMarker(String language)
{
Expand All @@ -59,7 +59,8 @@ public static DefaultTokenMarker getMarker(String language)
{
case "glsles": marker = new GLESTokenMarker(); break;
case "glsl": marker = new GLSLTokenMarker(); break;
case "hlsl": marker = new HLSLTokenMarker(); break;
case "hlsl9": marker = new HLSLTokenMarker(); break;
case "hlsl11": marker = new HLSLTokenMarker(); break;
case "gml": marker = new GMLTokenMarker(); break;
}
markers.put(language,marker);
Expand Down
2 changes: 1 addition & 1 deletion org/lateralgm/main/LGM.java
Expand Up @@ -132,7 +132,7 @@

public final class LGM
{
public static final String version = "1.8.182"; //$NON-NLS-1$
public static final String version = "1.8.183"; //$NON-NLS-1$

// TODO: This list holds the class loader for any loaded plugins which should be
// cleaned up and closed when the application closes.
Expand Down
103 changes: 35 additions & 68 deletions org/lateralgm/subframes/ShaderFrame.java
Expand Up @@ -38,7 +38,6 @@

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
Expand All @@ -60,9 +59,6 @@
import org.lateralgm.joshedit.Code;
import org.lateralgm.joshedit.DefaultTokenMarker;
import org.lateralgm.joshedit.JoshText.LineChangeListener;
import org.lateralgm.joshedit.lexers.GLESTokenMarker;
import org.lateralgm.joshedit.lexers.GLSLTokenMarker;
import org.lateralgm.joshedit.lexers.HLSLTokenMarker;
import org.lateralgm.main.LGM;
import org.lateralgm.main.Prefs;
import org.lateralgm.main.Util;
Expand All @@ -82,9 +78,8 @@ public class ShaderFrame extends InstantiableResourceFrame<Shader,PShader>
public CodeTextArea fcode;
public JButton edit;
public JPanel status;
public JCheckBox precompileCB;
public JComboBox<String> typeCombo;
public String currentLang = "";
public String currentLang = ""; //$NON-NLS-1$

private ShaderEditor fragmentEditor;
private ShaderEditor vertexEditor;
Expand All @@ -95,8 +90,8 @@ public ShaderFrame(Shader res, ResNode node)
setSize(700,430);
setLayout(new BorderLayout());

vcode = new CodeTextArea((String) res.get(PShader.VERTEX),MarkerCache.getMarker("glsles"));
fcode = new CodeTextArea((String) res.get(PShader.FRAGMENT),MarkerCache.getMarker("glsles"));
vcode = new CodeTextArea((String) res.get(PShader.VERTEX),MarkerCache.getMarker("glsles")); //$NON-NLS-1$
fcode = new CodeTextArea((String) res.get(PShader.FRAGMENT),MarkerCache.getMarker("glsles")); //$NON-NLS-1$

editors = new JTabbedPane();
editors.addTab("Vertex",vcode);
Expand All @@ -115,7 +110,7 @@ public ShaderFrame(Shader res, ResNode node)
if (Prefs.useExternalScriptEditor) {
vcode.setEnabled(false);
edit = new JButton(LGM.getIconForKey("ShaderFrame.EDIT")); //$NON-NLS-1$
edit.setToolTipText(Messages.getString("ShaderFrame.EDIT"));
edit.setToolTipText(Messages.getString("ShaderFrame.EDIT")); //$NON-NLS-1$
edit.addActionListener(this);
tool.add(edit);

Expand All @@ -125,8 +120,14 @@ public ShaderFrame(Shader res, ResNode node)
this.addEditorButtons(tool);

tool.addSeparator();
tool.add(new JLabel(Messages.getString("ShaderFrame.TYPE")));
String[] typeOptions = { "GLSLES","GLSL","HLSL9","HLSL11" };
name.setColumns(13);
name.setMaximumSize(name.getPreferredSize());
tool.add(new JLabel(Messages.getString("ShaderFrame.NAME"))); //$NON-NLS-1$
tool.add(name);

tool.addSeparator();
tool.add(new JLabel(Messages.getString("ShaderFrame.TYPE"))); //$NON-NLS-1$
String[] typeOptions = { "GLSLES","GLSL","HLSL9","HLSL11" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
typeCombo = new JComboBox<String>(typeOptions);
typeCombo.setMaximumSize(typeCombo.getPreferredSize());
typeCombo.addItemListener(new ItemListener()
Expand All @@ -138,16 +139,6 @@ public void itemStateChanged(ItemEvent arg0)
});
typeCombo.setSelectedItem(res.getType());
tool.add(typeCombo);
precompileCB = new JCheckBox(Messages.getString("ShaderFrame.PRECOMPILE"));
precompileCB.setSelected(res.getPrecompile());
precompileCB.setOpaque(false);
tool.addSeparator();
tool.add(precompileCB);
tool.addSeparator();
name.setColumns(13);
name.setMaximumSize(name.getPreferredSize());
tool.add(new JLabel(Messages.getString("ShaderFrame.NAME"))); //$NON-NLS-1$
tool.add(name);

status = new JPanel(new FlowLayout());
BoxLayout layout = new BoxLayout(status,BoxLayout.X_AXIS);
Expand Down Expand Up @@ -182,31 +173,8 @@ private void updateLexer()
{
//TODO: This should be moved into the base CodeTextArea, as a feature of JoshEdit
String val = typeCombo.getSelectedItem().toString();
if (val.equals(currentLang))
{
return;
}
DefaultTokenMarker marker = null;
if (val.equals("GLSLES"))
{
marker = new GLESTokenMarker();
}
else if (val.equals("GLSL"))
{
marker = new GLSLTokenMarker();
}
else if (val.equals("HLSL9"))
{
marker = new HLSLTokenMarker();
}
else if (val.equals("HLSL11"))
{
marker = new HLSLTokenMarker();
}
else
{

}
if (val.equals(currentLang)) return;
DefaultTokenMarker marker = MarkerCache.getMarker(val);
//TODO: Both of these calls will utilize the same lexer, but they both
//will recompose the list of completions. Should possibly add an abstract
//GetCompletions() to the DefaultTokenMarker class, so that all code editors
Expand All @@ -223,7 +191,6 @@ public void commitChanges()
res.put(PShader.FRAGMENT,fcode.getTextCompat());
res.setName(name.getText());
res.put(PShader.TYPE,typeCombo.getSelectedItem());
res.put(PShader.PRECOMPILE,precompileCB.isSelected());
}

public void fireInternalFrameEvent(int id)
Expand Down Expand Up @@ -357,19 +324,19 @@ private JButton makeToolbarButton(String name)

public void addEditorButtons(JToolBar tb)
{
tb.add(makeToolbarButton("LOAD"));
tb.add(makeToolbarButton("SAVE"));
tb.add(makeToolbarButton("PRINT"));
tb.add(makeToolbarButton("LOAD")); //$NON-NLS-1$
tb.add(makeToolbarButton("SAVE")); //$NON-NLS-1$
tb.add(makeToolbarButton("PRINT")); //$NON-NLS-1$
tb.addSeparator();

tb.add(makeToolbarButton("CUT"));
tb.add(makeToolbarButton("COPY"));
tb.add(makeToolbarButton("PASTE"));
tb.add(makeToolbarButton("CUT")); //$NON-NLS-1$
tb.add(makeToolbarButton("COPY")); //$NON-NLS-1$
tb.add(makeToolbarButton("PASTE")); //$NON-NLS-1$
tb.addSeparator();

final JButton undoButton = makeToolbarButton("UNDO");
final JButton undoButton = makeToolbarButton("UNDO"); //$NON-NLS-1$
tb.add(undoButton);
final JButton redoButton = makeToolbarButton("REDO");
final JButton redoButton = makeToolbarButton("REDO"); //$NON-NLS-1$
tb.add(redoButton);
// need to set the default state unlike the component popup
undoButton.setEnabled(vcode.text.canUndo());
Expand Down Expand Up @@ -402,8 +369,8 @@ public void stateChanged(ChangeEvent e) {
fcode.text.addLineChangeListener(linelistener);
vcode.text.addLineChangeListener(linelistener);
tb.addSeparator();
tb.add(makeToolbarButton("FIND"));
tb.add(makeToolbarButton("GOTO"));
tb.add(makeToolbarButton("FIND")); //$NON-NLS-1$
tb.add(makeToolbarButton("GOTO")); //$NON-NLS-1$
}

public CodeTextArea getSelectedCode() {
Expand Down Expand Up @@ -456,15 +423,15 @@ else if (stab == 1)

CodeTextArea selectedCode = getSelectedCode();

if (com.equals("JoshText.LOAD"))
if (com.equals("JoshText.LOAD")) //$NON-NLS-1$
{
selectedCode.text.Load();
}
else if (com.equals("JoshText.SAVE"))
else if (com.equals("JoshText.SAVE")) //$NON-NLS-1$
{
selectedCode.text.Save();
}
else if (com.equals("JoshText.PRINT"))
else if (com.equals("JoshText.PRINT")) //$NON-NLS-1$
{
try
{
Expand All @@ -475,35 +442,35 @@ else if (com.equals("JoshText.PRINT"))
LGM.showDefaultExceptionHandler(e);
}
}
else if (com.equals("JoshText.UNDO"))
else if (com.equals("JoshText.UNDO")) //$NON-NLS-1$
{
selectedCode.text.Undo();
}
else if (com.equals("JoshText.REDO"))
else if (com.equals("JoshText.REDO")) //$NON-NLS-1$
{
selectedCode.text.Redo();
}
else if (com.equals("JoshText.CUT"))
else if (com.equals("JoshText.CUT")) //$NON-NLS-1$
{
selectedCode.text.Cut();
}
else if (com.equals("JoshText.COPY"))
else if (com.equals("JoshText.COPY")) //$NON-NLS-1$
{
selectedCode.text.Copy();
}
else if (com.equals("JoshText.PASTE"))
else if (com.equals("JoshText.PASTE")) //$NON-NLS-1$
{
selectedCode.text.Paste();
}
else if (com.equals("JoshText.FIND"))
else if (com.equals("JoshText.FIND")) //$NON-NLS-1$
{
selectedCode.text.ShowFind();
}
else if (com.equals("JoshText.GOTO"))
else if (com.equals("JoshText.GOTO")) //$NON-NLS-1$
{
selectedCode.aGoto();
}
else if (com.equals("JoshText.SELALL"))
else if (com.equals("JoshText.SELALL")) //$NON-NLS-1$
{
selectedCode.text.SelectAll();
}
Expand Down

0 comments on commit 475e6e6

Please sign in to comment.