Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/linux-support-3' into combined-u…
Browse files Browse the repository at this point in the history
…pdate
  • Loading branch information
xpdota committed Jul 21, 2022
2 parents 6a761f3 + 14e1c0b commit a18cd3e
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.formdev.flatlaf.FlatDarculaLaf;
import gg.xp.xivsupport.gui.overlay.Scaled;
import gg.xp.xivsupport.persistence.Platform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -62,7 +63,6 @@ private static void doSetup() {
}
}
try {
// UIManager.setLookAndFeel(new DarculaLaf());
UIManager.setLookAndFeel(new FlatDarculaLaf());
}
catch (Throwable t) {
Expand Down
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();
}
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ExampleOverlayWithLotsOfButtons extends XivOverlay {
public ExampleOverlayWithLotsOfButtons(PersistenceProvider persistence, OverlayConfig oc) {
super("Example Overlay", "example-overlay2", oc, persistence);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(2, 2));
panel.setLayout(new GridLayout(3, 2));
JButton button1 = new JButton("Bigger");
button1.addActionListener(l -> {
setScale(getScale() * 1.1);
Expand All @@ -27,7 +27,10 @@ public ExampleOverlayWithLotsOfButtons(PersistenceProvider persistence, OverlayC
reset.addActionListener(l -> {
setScale(defaultScale);
});

panel.add(reset);
JButton nothing = new JButton("Nothing");
panel.add(nothing);
panel.setBackground(new Color(200, 100, 0, 255));
getPanel().add(panel);
JPanel topPanel = new JPanel();
Expand Down
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();
}
}
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();
}
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;
}
}
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;
}
}
Loading

0 comments on commit a18cd3e

Please sign in to comment.