more mess, font alignment issues

This commit is contained in:
Ben Fry
2013-06-01 13:31:46 -04:00
parent 551d9c1d56
commit 12d714cf75
5 changed files with 39 additions and 19 deletions
+2 -2
View File
@@ -53,8 +53,8 @@ public class Base {
// static private boolean RELEASE = false;
/** True if heavy debugging error/log messages are enabled */
// static public boolean DEBUG = false;
static public boolean DEBUG = true;
static public boolean DEBUG = false;
// static public boolean DEBUG = true;
static HashMap<Integer, String> platformNames =
new HashMap<Integer, String>();
+8 -11
View File
@@ -25,8 +25,6 @@ package processing.app;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.GeneralPath;
import java.util.Arrays;
@@ -63,7 +61,7 @@ public class EditorHeader extends JComponent {
Tab[] visitOrder;
Font font;
FontMetrics metrics;
// FontMetrics metrics;
int fontAscent;
JMenu menu;
@@ -236,15 +234,14 @@ public class EditorHeader extends JComponent {
Graphics g = offscreen.getGraphics();
g.setFont(font); // need to set this each time through
metrics = g.getFontMetrics();
fontAscent = metrics.getAscent();
// metrics = g.getFontMetrics();
// fontAscent = metrics.getAscent();
if (fontAscent == 0) {
fontAscent = (int) Toolkit.getAscent(g);
}
Graphics2D g2 = (Graphics2D) g;
FontRenderContext frc = g2.getFontRenderContext();
//fontAscent = (int) new TextLayout("H", font, frc).getAscent();
fontAscent = (int) new TextLayout("H", font, frc).getBounds().getHeight();
if (Toolkit.highResDisplay()) {
// scale everything 2x, will be scaled down when drawn to the screen
g2.scale(2, 2);
@@ -409,8 +406,8 @@ public class EditorHeader extends JComponent {
int baseline = top + (tabHeight + fontAscent) / 2;
//g.drawString(sketch.code[i].name, textLeft, baseline);
g.drawString(tab.text, textLeft, baseline);
g.drawLine(tab.left, baseline-fontAscent, tab.right, baseline-fontAscent);
g.drawLine(tab.left, baseline, tab.right, baseline);
// g.drawLine(tab.left, baseline-fontAscent, tab.right, baseline-fontAscent);
// g.drawLine(tab.left, baseline, tab.right, baseline);
}
}
+14 -4
View File
@@ -61,6 +61,7 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
protected Button rollover;
Font statusFont;
int statusAscent;
Color statusColor;
boolean shiftPressed;
@@ -68,6 +69,7 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
// what the mode indicator looks like
Color modeButtonColor;
Font modeTextFont;
int modeTextAscent;
Color modeTextColor;
String modeTitle;
int modeX1, modeY1;
@@ -226,6 +228,9 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
g.setColor(statusColor);
g.setFont(statusFont);
if (statusAscent == 0) {
statusAscent = (int) Toolkit.getAscent(g);
}
// If I ever find the guy who wrote the Java2D API, I will hurt him.
// Graphics2D g2 = (Graphics2D) g;
@@ -236,7 +241,8 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
// if (currentRollover != -1) {
if (rollover != null) {
int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
//int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
int statusY = (BUTTON_HEIGHT + statusAscent) / 2;
//String status = shiftPressed ? titleShift[currentRollover] : title[currentRollover];
String status = shiftPressed ? rollover.titleShift : rollover.title;
g.drawString(status, buttons.size() * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
@@ -244,19 +250,23 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
g.setFont(modeTextFont);
FontMetrics metrics = g.getFontMetrics();
int modeTextHeight = metrics.getAscent();
if (modeTextAscent == 0) {
modeTextAscent = (int) Toolkit.getAscent(g); //metrics.getAscent();
}
int modeTextWidth = metrics.stringWidth(modeTitle);
final int modeGapWidth = 8;
final int modeBoxHeight = 20;
modeX2 = getWidth() - 16;
modeX1 = modeX2 - (modeGapWidth + modeTextWidth + modeGapWidth + ARROW_WIDTH + modeGapWidth);
modeY1 = 8; //(getHeight() - modeBoxHeight) / 2;
// modeY1 = 8; //(getHeight() - modeBoxHeight) / 2;
modeY1 = (getHeight() - modeBoxHeight) / 2;
modeY2 = modeY1 + modeBoxHeight; //modeY1 + modeH + modeGapV*2;
g.setColor(modeButtonColor);
g.drawRect(modeX1, modeY1, modeX2 - modeX1, modeY2 - modeY1);
g.drawString(modeTitle,
modeX1 + modeGapWidth,
modeY1 + modeTextHeight + (modeBoxHeight - modeTextHeight) / 2);
modeY1 + (modeBoxHeight + modeTextAscent) / 2);
//modeY1 + modeTextAscent + (modeBoxHeight - modeTextAscent) / 2);
g.drawImage(modeArrow,
modeX2 - ARROW_WIDTH - modeGapWidth,
modeY1 + (modeBoxHeight - ARROW_HEIGHT) / 2,
+12
View File
@@ -25,11 +25,15 @@ import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.datatransfer.Clipboard;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
@@ -357,4 +361,12 @@ public class Toolkit {
input.close();
return font.deriveFont((float) size);
}
static double getAscent(Graphics g) { //, Font font) {
Graphics2D g2 = (Graphics2D) g;
FontRenderContext frc = g2.getFontRenderContext();
//return new TextLayout("H", font, frc).getBounds().getHeight();
return new TextLayout("H", g.getFont(), frc).getBounds().getHeight();
}
}
+3 -2
View File
@@ -18,7 +18,7 @@ header.text.selected.color = #000000
header.text.unselected.color = #ffffff
#header.text.font = SansSerif,plain,12
#header.text.font.macosx = Helvetica,plain,12
header.text.font = processing.sans,plain,16
header.text.font = processing.sans,plain,14
header.tab.selected.color = #a2afba
header.tab.unselected.color = #2a4159
@@ -43,7 +43,8 @@ buttons.status.color = #ffffff
#mode.button.font.macosx = Helvetica,plain,9
#mode.button.font = Monospaced,plain,11
#mode.button.font.macosx = Monaco,plain,10
mode.button.font = processing.mono,plain,12
#mode.button.font = processing.mono,plain,12
mode.button.font = processing.sans,plain,12
#mode.button.color = #4a545e
#mode.button.color = #9ca6b0
mode.button.color = #ffffff