Implement Button and ClickableButton classes, added a button template,

grab input from gamepad.
dev
sigonasr2 7 years ago
parent afae9ca413
commit f281fb3fbf
  1. BIN
      sigIRCv2.jar
  2. 2
      src/sig/modules/ChatLog/ChatLogMessage.java
  3. 50
      src/sig/modules/Controller/Button.java
  4. 49
      src/sig/modules/Controller/ClickableButton.java
  5. 81
      src/sig/modules/ControllerModule.java
  6. 15
      src/sig/sigIRC.java

Binary file not shown.

@ -180,7 +180,7 @@ public class ChatLogMessage {
if (textWidth<maxWidth) { if (textWidth<maxWidth) {
marker = tempmarker+1; marker = tempmarker+1;
} }
System.out.println(msg.substring(0, marker)+" | "+textWidth); //System.out.println(msg.substring(0, marker)+" | "+textWidth);
} else { } else {
marker=msg.length(); marker=msg.length();
break; break;

@ -0,0 +1,50 @@
package sig.modules.Controller;
import java.awt.Color;
import java.awt.Graphics;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Controller;
import sig.modules.ControllerModule;
public class Button {
double pct_x = 0;
double pct_y = 0;
double pct_width = 0;
double pct_height = 0;
Identifier ident;
Controller parent_controller;
Color pressed_col;
ControllerModule parent;
boolean square;
public Button(double pct_x, double pct_width, double pct_y, double pct_height, Controller parent_controller, Identifier button_identifier, Color col, ControllerModule module) {
this(pct_x,pct_width,pct_y,pct_height,parent_controller,button_identifier,col,module,false);
}
public Button(double pct_x, double pct_width, double pct_y, double pct_height, Controller parent_controller, Identifier button_identifier, Color col, ControllerModule module, boolean square) {
this.pct_x = pct_x;
this.pct_y = pct_y;
this.pct_width=pct_width;
this.pct_height=pct_height;
this.parent_controller=parent_controller;
this.ident = button_identifier;
this.pressed_col=col;
this.parent = module;
this.square = square;
}
public void draw(Graphics g) {
if (parent_controller.getComponent(ident).getPollData()==1) {
Color col_identity = g.getColor();
g.setColor(pressed_col);
g.fillOval((int)(parent.getPosition().getX()
+parent.getPosition().getWidth()*pct_x)
,(int)(parent.getPosition().getY()
+parent.getPosition().getWidth()*pct_y)
,(int)(parent.getPosition().getWidth()*pct_width),
(int)(parent.getPosition().getWidth()*pct_height));
g.setColor(col_identity);
}
}
}

@ -0,0 +1,49 @@
package sig.modules.Controller;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import sig.sigIRC;
import sig.modules.ControllerModule;
import sig.utils.DrawUtils;
import sig.utils.TextUtils;
public class ClickableButton {
int x,y,width,height;
String label;
ControllerModule module;
public ClickableButton(Rectangle position, String button_label, ControllerModule parent_module) {
this.x = (int)position.getX();
this.y = (int)position.getY();
this.width = (int)position.getWidth();
this.height = (int)position.getHeight();
this.label=button_label;
this.module = parent_module;
}
public void onClickEvent(MouseEvent ev) {
if (mouseInsideBounds(ev)) {
System.out.println("Click performed!");
}
}
private boolean mouseInsideBounds(MouseEvent ev) {
return ev.getX()>=x && ev.getX()<=x+width &&
ev.getY()>=y && ev.getY()<=y+height;
}
public void draw(Graphics g) {
Color color_identity = g.getColor();
g.setColor(Color.WHITE);
g.drawRect((int)module.getPosition().getX()+x,
(int)module.getPosition().getY()+y, width, height);
g.setColor(Color.BLACK);
g.fillRect((int)module.getPosition().getX()+x+1,
(int)module.getPosition().getY()+y+1, width-1, height-1);
DrawUtils.drawTextFont(g, sigIRC.panel.userFont, module.getPosition().getX()+x-TextUtils.calculateStringBoundsFont(label, sigIRC.panel.userFont).getWidth()/2+width/2, module.getPosition().getY()+y+height-1, Color.WHITE, label);
g.setColor(color_identity);
}
}

@ -1,27 +1,106 @@
package sig.modules; package sig.modules;
import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import net.java.games.input.Component;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Controller; import net.java.games.input.Controller;
import net.java.games.input.Controller.Type;
import net.java.games.input.ControllerEnvironment; import net.java.games.input.ControllerEnvironment;
import sig.Module; import sig.Module;
import sig.sigIRC;
import sig.modules.Controller.Button;
import sig.modules.Controller.ClickableButton;
import sig.utils.DrawUtils;
import sig.utils.FileUtils;
public class ControllerModule extends Module{ public class ControllerModule extends Module{
public final static String CONTROLLERPATH = sigIRC.BASEDIR+"sigIRC/controller/";
List<Controller> controllers = new ArrayList<Controller>();
Image controller_img;
double imgratio = 1;
List<Button> buttons = new ArrayList<Button>();
List<ClickableButton> click_buttons = new ArrayList<ClickableButton>();
public ControllerModule(Rectangle2D bounds, String moduleName) { public ControllerModule(Rectangle2D bounds, String moduleName) {
super(bounds, moduleName); super(bounds, moduleName);
Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers(); Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
for (Controller c : ca) { for (Controller c : ca) {
System.out.println(c.getName()); if (c.getType()==Type.GAMEPAD) {
controllers.add(c);
System.out.println("Recognized "+c.getName()+": "+c.getType());
//System.out.println("Components: ");
/*for (Component cp : c.getComponents()) {
System.out.println(" "+cp.getName()+" ("+cp.getIdentifier().getName()+")");
}*/
}
//System.out.println(c.getName()+": "+c.getType());
}
try {
controller_img = ImageIO.read(new File(CONTROLLERPATH+"controller_template.png")).getScaledInstance((int)position.getWidth(), -1, 0);
} catch (IOException e) {
e.printStackTrace();
}
buttons.add(new Button(0.1,0.05,0.1,0.05,controllers.get(0),Identifier.Button._3,Color.RED,this));
click_buttons.add(new ClickableButton(new Rectangle(
0,0,96,20),"Test",this));
}
public void mousePressed(MouseEvent ev) {
super.mousePressed(ev);
for (ClickableButton cb : click_buttons) {
cb.onClickEvent(ev);
} }
} }
public Rectangle2D getPosition() {
return position;
}
public void run() { public void run() {
super.run(); super.run();
for (Controller c : controllers) {
//System.out.println("Data for "+c.getName()+" ("+c.getType()+"):");
c.poll();
/*for (Component cp : c.getComponents()) {
if (!cp.isAnalog()) {
if (cp.getPollData()!=0) {
//System.out.println("Button "+cp.getIdentifier()+" held down!");
FileUtils.logToFile("Button "+cp.getIdentifier()+" held down!", CONTROLLERPATH+"test");
}
}
}*/
}
} }
public void draw(Graphics g) { public void draw(Graphics g) {
super.draw(g); super.draw(g);
for (int i=0;i<controllers.get(0).getComponents().length;i++) {
Component cp = controllers.get(0).getComponents()[i];
if (!cp.isAnalog()) {
if (cp.getPollData()!=0) {
//System.out.println("Button "+cp.getIdentifier()+" held down!");
//DrawUtils.drawText(g,position.getX(),position.getY(),Color.BLACK,"Button "+cp.getIdentifier()+" held down!");
}
}
}
g.drawImage(controller_img, (int)(position.getX()+1), (int)(position.getY()+8), sigIRC.panel);
for (Button b : buttons) {
b.draw(g);
}
for (ClickableButton cb : click_buttons) {
cb.draw(g);
}
} }
} }

@ -266,11 +266,16 @@ public class sigIRC{
manager = new FileManager("update.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("update.png"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("backcolor.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("backcolor.png"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("drag_bar.png"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("drag_bar.png"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("jinput-dx8.dll"); manager.verifyAndFetchFileFromServer(); if (controllermodule_enabled) {
manager = new FileManager("jinput-dx8_64.dll"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("jinput-dx8.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("jinput-raw.dll"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("jinput-dx8_64.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("jinput-raw_64.dll"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("jinput-raw.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("jinput-wintab.dll"); manager.verifyAndFetchFileFromServer(); manager = new FileManager("jinput-raw_64.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("jinput-wintab.dll"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("libjinput-linux.so"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("libjinput-linux64.so"); manager.verifyAndFetchFileFromServer();
manager = new FileManager("libjinput-osx.jnilib"); manager.verifyAndFetchFileFromServer();
}
DownloadProgramUpdate(); DownloadProgramUpdate();
System.out.println("Downloaded Dependencies. "); System.out.println("Downloaded Dependencies. ");
} }

Loading…
Cancel
Save