package sig; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.Vector; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.SwingUtilities; import sig.utils.DrawUtils; import sig.utils.TextUtils; import sig.windows.ProgramWindow; public class Module extends JFrame implements ComponentListener, WindowListener, KeyListener{ public ListenerPanel panel; public Rectangle position; protected boolean enabled; protected String name; public static BufferedImage IMG_DRAGBAR; public static BufferedImage MSG_SEPARATOR; public static boolean inDragZone=false; final public static int WINDOW_EXTRA_BORDER = 32; //Number of pixels that the border takes up (Reduces the size of the window) final protected int titleHeight; Point dragOffset; boolean dragging=false; public static boolean DRAGGING=false; public Graphics myGraphics; long lasttime = System.currentTimeMillis(); float avgfps = sigIRC.framerate; int counter = 0; int avgcount = 10; int[] sum = new int[10]; int windowUpdateCounter = 30; public Module(Rectangle bounds, String moduleName) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } this.addComponentListener(this); this.addWindowListener(this); this.addKeyListener(this); this.position = bounds; System.out.println(position); this.name = moduleName; this.enabled=true; this.setTitle(moduleName); panel = new ListenerPanel(this){ public void paintComponent(Graphics g) { super.paintComponent(g); draw(g); } }; this.setLocation((int)position.getX(), (int)position.getY()); this.titleHeight = (int)TextUtils.calculateStringBoundsFont(this.name, sigIRC.userFont).getHeight(); this.setSize(new Dimension((int)position.getWidth(), (int)position.getHeight())); panel.setSize(this.getSize()); //System.out.println("Module "+moduleName+": "+position); this.add(panel); //this.pack(); repaint(); this.setVisible(true); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); scheduler.scheduleWithFixedDelay(()->{ run(); panel.repaint(); },(long)((1d/(sigIRC.framerate+1))*1000),(long)((1d/(sigIRC.framerate+1))*1000),TimeUnit.MILLISECONDS); } public Module(Rectangle bounds, String moduleName, boolean enabled) { this(bounds, moduleName); this.enabled=enabled; } public void updateFPSCounter() { float val = 1000f/(System.currentTimeMillis()-lasttime); sum[counter++ % sum.length] = (int)val; avgfps = (float)sum(sum)/sum.length; this.setTitle(name+" - "+(int)Math.round(avgfps)+" FPS"); lasttime=System.currentTimeMillis(); } private int sum(int[] array) { int val = 0; for (int i=0;i