-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/linux-support-3' into combined-u…
…pdate
- Loading branch information
Showing
13 changed files
with
396 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
xivsupport/src/main/java/gg/xp/xivsupport/gui/overlay/ExampleJFrame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gg.xp.xivsupport.gui.overlay; | ||
|
||
import gg.xp.xivsupport.gui.CommonGuiSetup; | ||
import gg.xp.xivsupport.persistence.PersistenceProvider; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
//@ScanMe | ||
public class ExampleJFrame { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
CommonGuiSetup.setup(); | ||
JFrame frame = new JFrame("Foo"); | ||
|
||
JPanel panel = new JPanel(); | ||
panel.setLayout(new GridLayout(2, 2)); | ||
JButton button1 = new JButton("Bigger"); | ||
panel.add(button1); | ||
JButton button2 = new JButton("Smaller"); | ||
panel.add(button2); | ||
JButton reset = new JButton("Reset"); | ||
panel.add(reset); | ||
panel.setOpaque(false); | ||
panel.setBackground(new Color(200, 100, 0, 0)); | ||
|
||
frame.setContentPane(panel); | ||
frame.setUndecorated(true); | ||
frame.setBackground(new Color(200, 100, 0, 0)); | ||
frame.setSize(new Dimension(500, 500)); | ||
frame.setLocationRelativeTo(null); | ||
|
||
frame.setVisible(true); | ||
|
||
Thread.sleep(5000); | ||
frame.repaint(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
xivsupport/src/main/java/gg/xp/xivsupport/gui/overlay/ExampleJFrame2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package gg.xp.xivsupport.gui.overlay; | ||
|
||
import gg.xp.xivsupport.gui.CommonGuiSetup; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
//@ScanMe | ||
public class ExampleJFrame2 extends JFrame { | ||
|
||
public ExampleJFrame2() { | ||
super("Foo"); | ||
JPanel panel = new JPanel(); | ||
panel.setLayout(new GridLayout(2, 2)); | ||
JButton button1 = new JButton("Bigger"); | ||
panel.add(button1); | ||
JButton button2 = new JButton("Smaller"); | ||
panel.add(button2); | ||
JButton reset = new JButton("Reset"); | ||
panel.add(reset); | ||
panel.setOpaque(false); | ||
panel.setBackground(new Color(200, 100, 0, 0)); | ||
|
||
this.setContentPane(panel); | ||
this.setUndecorated(true); | ||
this.setBackground(new Color(200, 100, 0, 0)); | ||
this.setSize(new Dimension(500, 500)); | ||
this.setLocationRelativeTo(null); | ||
} | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
CommonGuiSetup.setup(); | ||
JFrame frame = new ExampleJFrame2(); | ||
frame.setVisible(true); | ||
|
||
Thread.sleep(5000); | ||
frame.repaint(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
xivsupport/src/main/java/gg/xp/xivsupport/gui/overlay/ExampleScalableJFrame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package gg.xp.xivsupport.gui.overlay; | ||
|
||
import gg.xp.xivsupport.gui.CommonGuiSetup; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
//@ScanMe | ||
public class ExampleScalableJFrame { | ||
|
||
public ExampleScalableJFrame() { | ||
} | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
CommonGuiSetup.setup(); | ||
ScalableJFrame frame = ScalableJFrameLinuxNoopImpl.construct("Foo"); | ||
|
||
JPanel panel = new JPanel() { | ||
// @Override | ||
// public void paintComponent(Graphics g) { | ||
// ((Graphics2D) g).setBackground(new Color(0, 255, 0, 0)); | ||
// g.clearRect(0, 0, getWidth(), getHeight()); | ||
// super.paintComponent(g); | ||
// } | ||
// | ||
}; | ||
|
||
panel.setLayout(new GridLayout(2, 2)); | ||
JButton button1 = new JButton("Bigger"); | ||
panel.add(button1); | ||
JButton button2 = new JButton("Smaller"); | ||
panel.add(button2); | ||
JButton reset = new JButton("Reset"); | ||
panel.add(reset); | ||
panel.setOpaque(false); | ||
panel.setBackground(new Color(200, 100, 0, 0)); | ||
|
||
frame.setContentPane(panel); | ||
frame.setUndecorated(true); | ||
frame.setBackground(new Color(200, 100, 0, 0)); | ||
frame.setSize(new Dimension(500, 500)); | ||
frame.setLocationRelativeTo(null); | ||
|
||
frame.setVisible(true); | ||
|
||
Thread.sleep(5000); | ||
frame.repaint(); | ||
} | ||
} |
73 changes: 4 additions & 69 deletions
73
xivsupport/src/main/java/gg/xp/xivsupport/gui/overlay/ScalableJFrame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,15 @@ | ||
package gg.xp.xivsupport.gui.overlay; | ||
|
||
import org.apache.commons.lang3.mutable.MutableDouble; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.geom.AffineTransform; | ||
|
||
public class ScalableJFrame extends JFrame implements Scaled { | ||
|
||
private final int numBuffers; | ||
private final MutableDouble scaleFactor; | ||
|
||
private ScalableJFrame(String title, MutableDouble scaleFactor, int numBuffers) throws HeadlessException { | ||
public abstract class ScalableJFrame extends JFrame implements Scaled { | ||
public ScalableJFrame(String title) throws HeadlessException { | ||
super(title); | ||
this.scaleFactor = scaleFactor; | ||
this.numBuffers = numBuffers; | ||
} | ||
|
||
public static ScalableJFrame construct(String title, double defaultScaleFactor, int numBuffers) { | ||
MutableDouble scaleFactor = new MutableDouble(defaultScaleFactor); | ||
return new ScalableJFrame(title, scaleFactor, numBuffers); | ||
} | ||
|
||
@Override | ||
public void setVisible(boolean b) { | ||
if (getBufferStrategy() == null && numBuffers != 0) { | ||
createBufferStrategy(numBuffers); | ||
} | ||
super.setVisible(b); | ||
} | ||
|
||
@Override | ||
public void paint(Graphics g) { | ||
super.paint(getGraphics()); | ||
} | ||
public abstract void setScaleFactor(double scaleFactor); | ||
|
||
@Override | ||
public void paintComponents(Graphics g) { | ||
super.paintComponents(getGraphics()); | ||
} | ||
|
||
@Override | ||
public void paintAll(Graphics g) { | ||
super.paintAll(getGraphics()); | ||
} | ||
|
||
@Override | ||
public Graphics getGraphics() { | ||
Graphics2D graphics = (Graphics2D) super.getGraphics(); | ||
AffineTransform transform = graphics.getTransform(); | ||
transform.scale(scaleFactor.getValue(), scaleFactor.getValue()); | ||
graphics.setTransform(transform); | ||
return graphics; | ||
} | ||
|
||
public void setScaleFactor(double scaleFactor) { | ||
this.scaleFactor.setValue(scaleFactor); | ||
pack(); | ||
Rectangle bounds = getBounds(); | ||
int newWidth; | ||
int newHeight; | ||
// Issues with border when scaling < 1 | ||
if (scaleFactor < 1.0) { | ||
scaleFactor = (5.0 + scaleFactor) / 6.0; | ||
} | ||
newWidth = (int) Math.round(bounds.width * scaleFactor); | ||
newHeight = (int) Math.round(bounds.height * scaleFactor); | ||
setBounds(bounds.x, bounds.y, newWidth, newHeight); | ||
if (isVisible()) { | ||
repaint(); | ||
} | ||
} | ||
|
||
@Override | ||
public double getScaleFactor() { | ||
return scaleFactor.getValue(); | ||
} | ||
|
||
public abstract double getScaleFactor(); | ||
} |
47 changes: 47 additions & 0 deletions
47
xivsupport/src/main/java/gg/xp/xivsupport/gui/overlay/ScalableJFrameLinuxNoopImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package gg.xp.xivsupport.gui.overlay; | ||
|
||
import java.awt.*; | ||
import java.awt.image.BufferStrategy; | ||
|
||
public final class ScalableJFrameLinuxNoopImpl extends ScalableJFrame { | ||
|
||
|
||
private ScalableJFrameLinuxNoopImpl(String title) throws HeadlessException { | ||
super(title); | ||
} | ||
|
||
public static ScalableJFrame construct(String title) { | ||
return new ScalableJFrameLinuxNoopImpl(title); | ||
} | ||
|
||
@Override | ||
public void setVisible(boolean b) { | ||
if (getBufferStrategy() == null) { | ||
createBufferStrategy(2); | ||
} | ||
super.setVisible(b); | ||
} | ||
|
||
@Override | ||
public void paint(Graphics g) { | ||
BufferStrategy buff = getBufferStrategy(); | ||
Graphics drawGraphics = buff.getDrawGraphics(); | ||
getContentPane().paint(drawGraphics); | ||
// super.paintComponents(drawGraphics); | ||
buff.show(); | ||
drawGraphics.dispose(); | ||
} | ||
|
||
|
||
public void setScaleFactor(double scaleFactor) { | ||
pack(); | ||
if (isVisible()) { | ||
repaint(); | ||
} | ||
} | ||
|
||
@Override | ||
public double getScaleFactor() { | ||
return 1.0; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
xivsupport/src/main/java/gg/xp/xivsupport/gui/overlay/ScalableJFrameLinuxRealImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package gg.xp.xivsupport.gui.overlay; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.geom.AffineTransform; | ||
import java.awt.image.BufferStrategy; | ||
|
||
import static java.awt.RenderingHints.KEY_ANTIALIASING; | ||
import static java.awt.RenderingHints.KEY_RENDERING; | ||
import static java.awt.RenderingHints.VALUE_ANTIALIAS_ON; | ||
import static java.awt.RenderingHints.VALUE_RENDER_QUALITY; | ||
|
||
public final class ScalableJFrameLinuxRealImpl extends ScalableJFrame { | ||
|
||
private final int numBuffers; | ||
private double scaleFactor; | ||
|
||
private ScalableJFrameLinuxRealImpl(String title, double scaleFactor, int numBuffers) throws HeadlessException { | ||
super(title); | ||
this.scaleFactor = scaleFactor; | ||
this.numBuffers = numBuffers; | ||
} | ||
|
||
public static ScalableJFrame construct(String title, double defaultScaleFactor, int numBuffers) { | ||
return new ScalableJFrameLinuxRealImpl(title, defaultScaleFactor, numBuffers); | ||
} | ||
|
||
@Override | ||
public void setVisible(boolean b) { | ||
super.setVisible(b); | ||
if (getBufferStrategy() == null) { | ||
createBufferStrategy(2); | ||
} | ||
} | ||
|
||
@Override | ||
public void paint(Graphics g) { | ||
BufferStrategy buff = getBufferStrategy(); | ||
Graphics drawGraphics = buff.getDrawGraphics(); | ||
Graphics2D g2d = ((Graphics2D) drawGraphics); | ||
AffineTransform t = g2d.getTransform(); | ||
t.scale(scaleFactor, scaleFactor); | ||
g2d.transform(t); | ||
g2d.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); | ||
// g2d.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BILINEAR); | ||
g2d.setRenderingHint(KEY_RENDERING, VALUE_RENDER_QUALITY); | ||
|
||
getContentPane().paint(drawGraphics); | ||
// super.paintComponents(drawGraphics); | ||
buff.show(); | ||
drawGraphics.dispose(); | ||
} | ||
|
||
|
||
public void setScaleFactor(double scaleFactor) { | ||
this.scaleFactor = scaleFactor; | ||
Dimension pref = getContentPane().getPreferredSize(); | ||
Rectangle bounds = getBounds(); | ||
int newWidth; | ||
int newHeight; | ||
// Issues with border when scaling < 1 | ||
if (scaleFactor < 1.0) { | ||
scaleFactor = (5.0 + scaleFactor) / 6.0; | ||
} | ||
newWidth = (int) Math.round(pref.width * scaleFactor); | ||
newHeight = (int) Math.round(pref.height * scaleFactor); | ||
// setVisible(wasVisible); | ||
SwingUtilities.invokeLater(() -> { | ||
setBounds(bounds.x, bounds.y, newWidth, newHeight); | ||
if (isVisible()) { | ||
// revalidate(); | ||
repaint(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public double getScaleFactor() { | ||
return scaleFactor; | ||
} | ||
} |
Oops, something went wrong.