Skip to content

Add scaling for themed fonts and graphics (hires displays) #2776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ static public void main(String args[]) throws Exception {

BaseNoGui.initParameters(args);

System.setProperty("swing.aatext", Preferences.get("editor.antialias", "true"));

BaseNoGui.initVersion();

// if (System.getProperty("mrj.version") != null) {
Expand Down Expand Up @@ -149,6 +147,7 @@ static public void main(String args[]) throws Exception {

// setup the theme coloring fun
Theme.init();
System.setProperty("swing.aatext", Preferences.get("editor.antialias", "true"));

// Set the look and feel before opening the window
try {
Expand Down Expand Up @@ -1525,9 +1524,11 @@ public void paint(Graphics g) {
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

g.setFont(new Font("SansSerif", Font.PLAIN, 11));
int scale = Theme.getInteger("gui.scalePercent");
Font f = new Font("SansSerif", Font.PLAIN, 11 * scale / 100);
g.setFont(f);
g.setColor(Color.white);
g.drawString(BaseNoGui.VERSION_NAME, 50, 30);
g.drawString(BaseNoGui.VERSION_NAME, 50 * scale / 100, 30 * scale / 100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PaulStoffregen PR doesn't merge any more because I've changed splashscreen and had to change version string position
When resolving merge, take your version and change
g.drawString(BaseNoGui.VERSION_NAME, 50 * scale / 100, 30 * scale / 100);
to
g.drawString(BaseNoGui.VERSION_NAME, 33 * scale / 100, 20 * scale / 100);

}
};
window.addMouseListener(new MouseAdapter() {
Expand Down Expand Up @@ -2176,13 +2177,25 @@ static public Image getLibImage(String name, Component who) {
Image image = null;
Toolkit tk = Toolkit.getDefaultToolkit();

int scale = Theme.getInteger("gui.scalePercent");
// TODO: create high-res enlarged copies and load those if
// the scale is more than 125%
File imageLocation = new File(getContentFile("lib"), name);
image = tk.getImage(imageLocation.getAbsolutePath());
MediaTracker tracker = new MediaTracker(who);
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) { }
if (scale != 100) {
int width = image.getWidth(null) * scale / 100;
int height = image.getHeight(null) * scale / 100;
image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
tracker.addImage(image, 1);
try {
tracker.waitForAll();
} catch (InterruptedException e) { }
}
return image;
}

Expand Down
11 changes: 7 additions & 4 deletions app/src/processing/app/EditorHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public class EditorHeader extends JComponent {

static final int PIECE_WIDTH = 4;

// value for the size bars, buttons, etc
static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;

static Image[][] pieces;

//
Expand Down Expand Up @@ -383,16 +386,16 @@ public Dimension getPreferredSize() {

public Dimension getMinimumSize() {
if (OSUtils.isMacOS()) {
return new Dimension(300, Preferences.GRID_SIZE);
return new Dimension(300, GRID_SIZE);
}
return new Dimension(300, Preferences.GRID_SIZE - 1);
return new Dimension(300, GRID_SIZE - 1);
}


public Dimension getMaximumSize() {
if (OSUtils.isMacOS()) {
return new Dimension(3000, Preferences.GRID_SIZE);
return new Dimension(3000, GRID_SIZE);
}
return new Dimension(3000, Preferences.GRID_SIZE - 1);
return new Dimension(3000, GRID_SIZE - 1);
}
}
2 changes: 1 addition & 1 deletion app/src/processing/app/EditorLineStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public EditorLineStatus(JEditTextArea textarea) {
background = Theme.getColor("linestatus.bgcolor");
font = Theme.getFont("linestatus.font");
foreground = Theme.getColor("linestatus.color");
high = Theme.getInteger("linestatus.height");
high = Theme.getInteger("linestatus.height") * Theme.getInteger("gui.scalePercent") / 100;

if (OSUtils.isMacOS()) {
resize = Base.getThemeImage("resize.gif", this);
Expand Down
7 changes: 5 additions & 2 deletions app/src/processing/app/EditorStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {

static final String NO_MESSAGE = "";

// value for the size bars, buttons, etc
static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;

Editor editor;

int mode;
Expand Down Expand Up @@ -524,11 +527,11 @@ public Dimension getPreferredSize() {
}

public Dimension getMinimumSize() {
return new Dimension(300, Preferences.GRID_SIZE);
return new Dimension(300, GRID_SIZE);
}

public Dimension getMaximumSize() {
return new Dimension(3000, Preferences.GRID_SIZE);
return new Dimension(3000, GRID_SIZE);
}


Expand Down
10 changes: 5 additions & 5 deletions app/src/processing/app/EditorToolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key

static final int BUTTON_COUNT = title.length;
/** Width of each toolbar button. */
static final int BUTTON_WIDTH = 27;
static final int BUTTON_WIDTH = 27 * Theme.getInteger("gui.scalePercent") / 100;
/** Height of each toolbar button. */
static final int BUTTON_HEIGHT = 32;
static final int BUTTON_HEIGHT = 32 * Theme.getInteger("gui.scalePercent") / 100;
/** The amount of space between groups of buttons on the toolbar. */
static final int BUTTON_GAP = 5;
static final int BUTTON_GAP = 5 * Theme.getInteger("gui.scalePercent") / 100;
/** Size of the button image being chopped up. */
static final int BUTTON_IMAGE_SIZE = 33;
static final int BUTTON_IMAGE_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;


static final int RUN = 0;
Expand Down Expand Up @@ -393,7 +393,7 @@ public Dimension getMinimumSize() {


public Dimension getMaximumSize() {
return new Dimension(3000, BUTTON_HEIGHT);
return new Dimension(3000 * Theme.getInteger("gui.scalePercent") / 100, BUTTON_HEIGHT);
}


Expand Down
5 changes: 0 additions & 5 deletions app/src/processing/app/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,6 @@ public String toString() {
*/
static public int BUTTON_HEIGHT = 24;

// value for the size bars, buttons, etc

static final int GRID_SIZE = 33;


// indents and spacing standards. these probably need to be modified
// per platform as well, since macosx is so huge, windows is smaller,
// and linux is all over the map
Expand Down
4 changes: 4 additions & 0 deletions app/src/processing/app/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ static public Font getFont(String attr) {
set(attr, value);
font = PreferencesHelper.getFont(table, attr);
}
int scale = getInteger("gui.scalePercent");
if (scale != 100) {
font = font.deriveFont((float)(font.getSize()) * (float)scale / (float)100.0);
}
return font;
}

Expand Down
3 changes: 3 additions & 0 deletions build/shared/lib/theme/theme.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# GUI - Scaling, edit this to scale to higher dots-per-inch displays
gui.scalePercent = 100

# GUI - STATUS
status.notice.fgcolor = #002325
status.notice.bgcolor = #17A1A5
Expand Down