Skip to content

Commit

Permalink
Merge pull request #20 from adamhutchings/ui
Browse files Browse the repository at this point in the history
Fix button stuff
  • Loading branch information
adamhutchings committed Aug 25, 2020
2 parents 59248fd + 344bea3 commit 74effc0
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 80 deletions.
80 changes: 1 addition & 79 deletions src/org/qme/vis/QInputScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ConcurrentModificationException;

import javax.swing.JFrame;
Expand All @@ -22,7 +20,7 @@
* @see org.qme.vis.QRenderScreen
*/
@SuppressWarnings("serial")
public class QInputScreen extends JFrame implements KeyListener, MouseListener {
public class QInputScreen extends JFrame implements KeyListener {

QApplication app;

Expand Down Expand Up @@ -73,79 +71,12 @@ public QInputScreen(QApplication qa) {
setVisible(true);
pack();
super.setDefaultCloseOperation(EXIT_ON_CLOSE);
addMouseListener(this);
addKeyListener(this);
xOffset = 0;
yOffset = 0;
setResizable(false);
app = qa;
}

@Override
/**
* This method dispatches click events to all the
* UIComponent objects.
* @author adamhutchings
* @since pre0
*/
public void mousePressed(MouseEvent e) {

UIComponent uc; // For internal use
Point p; // same as above

try {

for (QObject qo : a.objects) {
if (qo instanceof UIComponent && qo.active) {

uc = (UIComponent) qo;

p = app.qrscreen.getMousePosition();

if (uc.clickIsIn(
p.x, p.y
)) {
qo.clicked = true;
uc.mouseClickOn();
}

}
}
} catch (ConcurrentModificationException cme) {}

}

@Override
/**
* This method dispatches click events to all the
* UIComponent objects.
* @author adamhutchings
* @since pre0
*/
public void mouseReleased(MouseEvent e) {

UIComponent uc; // For internal use

try {

for (QObject qo : a.objects) {
if (qo instanceof UIComponent && qo.active) {

uc = (UIComponent) qo;

if (qo.clicked) {
qo.clicked = false;
uc.mouseClickOff();
}

}
}

} catch (ConcurrentModificationException cme) {

}

}

/**
* This method dispatches hovers to all the
Expand Down Expand Up @@ -233,15 +164,6 @@ public void keyPressed(KeyEvent e) {

// Useless stub methods

@Override
public void mouseClicked(MouseEvent e) {}

@Override
public void mouseEntered(MouseEvent e) {}

@Override
public void mouseExited(MouseEvent e) {}

@Override
public void keyTyped(KeyEvent e) {}

Expand Down
81 changes: 80 additions & 1 deletion src/org/qme/vis/QRenderScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ConcurrentModificationException;

import javax.swing.JPanel;

import org.qme.main.QApplication;
import org.qme.main.QObject;
import org.qme.vis.ui.UIComponent;

/**
* This represents where objects get drawn onto
Expand All @@ -16,7 +20,7 @@
* @see org.qme.main.QApplication
*/
@SuppressWarnings("serial")
public class QRenderScreen extends JPanel {
public class QRenderScreen extends JPanel implements MouseListener {

/**
* The "owner" of this object.
Expand All @@ -31,6 +35,7 @@ public class QRenderScreen extends JPanel {
*/
public QRenderScreen(QApplication a) {
app = a;
addMouseListener(this);
}

/**
Expand All @@ -54,5 +59,79 @@ public void paint(Graphics g) {
}

}

@Override
/**
* This method dispatches click events to all the
* UIComponent objects.
* @author adamhutchings
* @since pre0
*/
public void mousePressed(MouseEvent e) {

UIComponent uc; // For internal use

try {

for (QObject qo : app.objects) {
if (qo instanceof UIComponent && qo.active) {

uc = (UIComponent) qo;

if (uc.clickIsIn(
e.getX(), e.getY()
)) {
qo.clicked = true;
uc.mouseClickOn();
}

}
}
} catch (ConcurrentModificationException cme) {}

}

@Override
/**
* This method dispatches click events to all the
* UIComponent objects.
* @author adamhutchings
* @since pre0
*/
public void mouseReleased(MouseEvent e) {

UIComponent uc; // For internal use

try {

for (QObject qo : app.objects) {
if (qo instanceof UIComponent && qo.active) {

uc = (UIComponent) qo;

if (qo.clicked) {
qo.clicked = false;
uc.mouseClickOff();
}

}
}

} catch (ConcurrentModificationException cme) {

}

}

// Useless stub methods

@Override
public void mouseClicked(MouseEvent e) {}

@Override
public void mouseEntered(MouseEvent e) {}

@Override
public void mouseExited(MouseEvent e) {}

}

0 comments on commit 74effc0

Please sign in to comment.