Ajouté modes de sélection : pinceau (linéaire/ponctuel) + pot de

peinture (remplir)
This commit is contained in:
galaxyoyo 2015-01-13 15:39:12 +01:00
parent 9e98b7546b
commit 1c2d673bec
2 changed files with 83 additions and 25 deletions

View File

@ -21,6 +21,7 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; import java.awt.event.WindowListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JMenu; import javax.swing.JMenu;
@ -28,6 +29,7 @@ import javax.swing.JMenuBar;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
@ -51,6 +53,9 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
private final JMenuItem saveAs = new JMenuItem("Sauvegarder sous ..."); private final JMenuItem saveAs = new JMenuItem("Sauvegarder sous ...");
private final JMenuItem exit = new JMenuItem("Quitter"); private final JMenuItem exit = new JMenuItem("Quitter");
private final JMenu selectionMode = new JMenu("Mode de s\u00e9lection"); private final JMenu selectionMode = new JMenu("Mode de s\u00e9lection");
ButtonGroup group = new ButtonGroup();
private final JRadioButtonMenuItem pen = new JRadioButtonMenuItem("Pinceau");
private final JRadioButtonMenuItem pot = new JRadioButtonMenuItem("Pot de peinture");
private final JTabbedPane tabs = new JTabbedPane(); private final JTabbedPane tabs = new JTabbedPane();
private final JPanel tabEvents = new JPanel(); private final JPanel tabEvents = new JPanel();
private final CollidPanel tabColl; private final CollidPanel tabColl;
@ -103,6 +108,14 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
menuBar.add(fichier); menuBar.add(fichier);
pen.setSelected(true);
pen.addActionListener(this);
pot.addActionListener(this);
group.add(pen);
group.add(pot);
selectionMode.add(pen);
selectionMode.add(pot);
tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK); tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK);
tools.add(selectionMode); tools.add(selectionMode);
@ -204,6 +217,7 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
couche2.repaint(); couche2.repaint();
couche3.repaint(); couche3.repaint();
} }
public void resize() public void resize()
{ {
@ -313,6 +327,11 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene
} }
} }
public int getSelectedPaintingMode()
{
return pen.isSelected() ? 0 : pot.isSelected() ? 1 : -1;
}
@Override @Override
public void windowActivated(WindowEvent event) public void windowActivated(WindowEvent event)
{ {

View File

@ -25,34 +25,73 @@ public class MapMouseListener extends MouseAdapter
} }
@Override @Override
public void mouseReleased(MouseEvent event) public void mouseClicked(MouseEvent event)
{ {
Map map = getFrame().getMap(); if (frame.getSelectedPaintingMode() == 0)
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null;
if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2)
{ {
if (getFrame().getSelectedSprite() != null) Map map = getFrame().getMap();
int x = panel.getWidth() / 2 - map.getFont().getWidth();
int y = panel.getHeight() / 2 - map.getFont().getHeight();
Case c = null;
if ((c = map.getCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34)) != null && event.getX() - x >= 2 && event.getY() - y >= 2)
{ {
if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex()) if (getFrame().getSelectedSprite() != null)
return;
Case n;
switch (getFrame().getSelectedSprite().getCouche())
{ {
case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break; if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex())
case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break; return;
case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break;
default : n = c; break;
}
map.setCase((event.getX() - x + 2) / 34, (event.getY() - y + 2) / 34, n); Case n;
panel.repaint();
switch (getFrame().getSelectedSprite().getCouche())
{
case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break;
case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break;
case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break;
default : n = c; break;
}
map.setCase(n.getPosX(), n.getPosY(), n);
panel.repaint();
}
} }
} }
else if (frame.getSelectedPaintingMode() == 1)
{
for (Case c : getFrame().getMap().getAllCases())
{
Map map = getFrame().getMap();
if (getFrame().getSelectedSprite() != null)
{
if (getFrame().getSelectedSprite().getCouche() - 1 > getFrame().getSelectedLayerIndex())
return;
Case n;
switch (getFrame().getSelectedSprite().getCouche())
{
case 0 : n = Case.create(c.getPosX(), c.getPosY(), getFrame().getSelectedSprite().getSprite(), c.getCoucheTwo(), c.getCoucheThree(), c.getCollision()); break;
case 1 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), getFrame().getSelectedSprite().getSprite(), c.getCoucheThree(), c.getCollision()); break;
case 2 : n = Case.create(c.getPosX(), c.getPosY(), c.getCoucheOne(), c.getCoucheTwo(), getFrame().getSelectedSprite().getSprite(), c.getCollision()); break;
default : n = c; break;
}
map.setCase(n.getPosX(), n.getPosY(), n);
}
}
panel.repaint();
}
}
@Override
public void mouseDragged(MouseEvent event)
{
if (frame.getSelectedPaintingMode() == 0)
{
mouseClicked(event);
}
} }
} }