Initial Commit for v2 (Broken)
This commit is contained in:
parent
45aad42c39
commit
e8d3196e42
6 changed files with 93 additions and 27 deletions
|
@ -2,7 +2,8 @@ package bz.bronze.painter;
|
|||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class Context {
|
||||
|
@ -10,17 +11,22 @@ public class Context {
|
|||
|
||||
static Random rng = new Random();
|
||||
|
||||
static Graphics g;
|
||||
|
||||
static BufferedImage bufferedImage = new BufferedImage(1280, 720, BufferedImage.TYPE_INT_ARGB);
|
||||
static RenderedImage renderedImage;
|
||||
|
||||
public static void drawBorders(Graphics g)
|
||||
{
|
||||
g.drawLine(0, 0, 0, Window.height + 10);
|
||||
{
|
||||
g.fillRect(0, 0, 3, Window.height + 10);
|
||||
|
||||
Log.print("hit");
|
||||
|
||||
//g.dispose();
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
public static void draw(Graphics g, int x, int y)
|
||||
{
|
||||
public static void draw(int x, int y)
|
||||
{
|
||||
g = bufferedImage.createGraphics();
|
||||
|
||||
int size = Window.sizeSlider.getValue();
|
||||
Color c = new Color(rng.nextInt(256), rng.nextInt(256), rng.nextInt(256), Window.opacitySlider.getValue());
|
||||
|
||||
|
@ -29,9 +35,17 @@ public class Context {
|
|||
g.fillOval(x - size / 2, y - size / 2, size, size);
|
||||
|
||||
g.dispose();
|
||||
|
||||
Log.print("[PAINTER] Drawn at, " + "X: " + x + " Y: " + y);
|
||||
Log.print("[PAINTER] Color, " + "R: " + c.getRed() + " G: " + c.getGreen() + " B: " + c.getBlue());
|
||||
Log.print("[PAINTER] Opacity, " + Window.opacitySlider.getValue());
|
||||
|
||||
renderedImage = bufferedImage;
|
||||
|
||||
Log.print("[PAINTER] Drawn at " + "X: " + x + " Y: " + y);
|
||||
Log.print("[PAINTER] Color " + "R: " + c.getRed() + " G: " + c.getGreen() + " B: " + c.getBlue());
|
||||
Log.print("[PAINTER] Opacity " + Window.opacitySlider.getValue());
|
||||
}
|
||||
|
||||
public static void swapBuffers()
|
||||
{
|
||||
//Window.paintArea.repaint();
|
||||
Window.paintArea.print(bufferedImage.getGraphics());
|
||||
}
|
||||
}
|
|
@ -6,8 +6,8 @@ import java.awt.event.ActionListener;
|
|||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
public class Mouse {
|
||||
static boolean isDown;
|
||||
public class Input {
|
||||
static boolean mouseIsDown;
|
||||
|
||||
public static void listen()
|
||||
{
|
||||
|
@ -19,13 +19,13 @@ public class Mouse {
|
|||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
isDown = true;
|
||||
mouseIsDown = true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
isDown = false;
|
||||
mouseIsDown = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,12 +39,22 @@ public class Mouse {
|
|||
});
|
||||
|
||||
Window.clearButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Window.paintArea.repaint();
|
||||
}
|
||||
});
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Window.paintArea.repaint();
|
||||
Context.bufferedImage.flush();
|
||||
|
||||
Log.print("[PAINTER] Cleared!");
|
||||
}
|
||||
});
|
||||
Window.saveButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Save.saveImage();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static int getMouseX()
|
|
@ -8,7 +8,7 @@ public class Painter {
|
|||
public static void init()
|
||||
{
|
||||
Window w = new Window(title);
|
||||
//Context.drawBorders(Window.paintArea.getGraphics());
|
||||
Context.drawBorders(Window.paintArea.getGraphics());
|
||||
Tick refresh = new Tick();
|
||||
|
||||
Log.print("[INIT] Done!");
|
||||
|
|
20
Painter/src/bz/bronze/painter/Save.java
Normal file
20
Painter/src/bz/bronze/painter/Save.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package bz.bronze.painter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class Save {
|
||||
public static void saveImage()
|
||||
{
|
||||
Window.filePicker.showSaveDialog(Window.paintArea);
|
||||
|
||||
try
|
||||
{
|
||||
ImageIO.write(Context.renderedImage, "png", Window.filePicker.getSelectedFile());
|
||||
Log.print("[INFO] Image Saved!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,9 +14,19 @@ public class Tick implements Runnable {
|
|||
Window.opacitySliderLabel.setText("Opacity: " + Window.opacitySlider.getValue());
|
||||
Window.sizeSliderLabel.setText("Size: " + Window.sizeSlider.getValue());
|
||||
|
||||
if(Mouse.isDown)
|
||||
Context.drawBorders(Window.paintArea.getGraphics());
|
||||
|
||||
if(Input.mouseIsDown)
|
||||
{
|
||||
Context.draw(Window.paintArea.getGraphics(), Window.paintArea.getMousePosition().x, Window.paintArea.getMousePosition().y);
|
||||
try
|
||||
{
|
||||
Context.draw(Window.paintArea.getMousePosition().x, Window.paintArea.getMousePosition().y);
|
||||
} catch (Exception e)
|
||||
{
|
||||
Log.print("[ERROR] Mouse out of bounds!");
|
||||
}
|
||||
|
||||
Context.swapBuffers();
|
||||
//Window.paintArea.repaint();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,12 @@ import java.awt.BorderLayout;
|
|||
import java.awt.Dimension;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
|
||||
public class Window {
|
||||
public static int width = 1280;
|
||||
|
@ -24,6 +26,10 @@ public class Window {
|
|||
public static JSlider sizeSlider = new JSlider();
|
||||
|
||||
public static JButton clearButton = new JButton();
|
||||
public static JButton saveButton = new JButton();
|
||||
|
||||
public static JFileChooser filePicker = new JFileChooser();
|
||||
public static FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "png");
|
||||
|
||||
public Window(String windowName)
|
||||
{
|
||||
|
@ -39,6 +45,11 @@ public class Window {
|
|||
clearButton.setText("Clear");
|
||||
clearButton.setPreferredSize(new Dimension(100, 50));
|
||||
|
||||
saveButton.setText("Save");
|
||||
saveButton.setPreferredSize(new Dimension(100, 50));
|
||||
|
||||
//filePicker.setFileFilter(filter);
|
||||
|
||||
window.setLayout(new BorderLayout());
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
window.setSize(width, height);
|
||||
|
@ -49,7 +60,8 @@ public class Window {
|
|||
toolbox.add(sizeSliderLabel);
|
||||
toolbox.add(sizeSlider);
|
||||
toolbox.add(clearButton);
|
||||
toolbox.add(fpsLabel, BorderLayout.SOUTH);
|
||||
toolbox.add(saveButton);
|
||||
//toolbox.add(fpsLabel, BorderLayout.SOUTH);
|
||||
|
||||
window.add(paintArea);
|
||||
window.add(toolbox, BorderLayout.WEST);
|
||||
|
@ -60,7 +72,7 @@ public class Window {
|
|||
window.setResizable(false);
|
||||
window.setVisible(true);
|
||||
|
||||
Mouse.listen();
|
||||
Input.listen();
|
||||
|
||||
Log.print("[WINDOW] Created!");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue