Skip to content

Commit 296729b

Browse files
committed
working to get new mode layout working
1 parent 7c874d0 commit 296729b

26 files changed

+87
-92
lines changed

app/src/processing/app/EditorHeader.java

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,19 @@ public class EditorHeader extends JComponent {
5858
static final int UNSELECTED = 0;
5959
static final int SELECTED = 1;
6060

61-
static final String WHERE[] = { "left", "mid", "right", "menu" };
61+
static final String WHERE[] = { "left", "mid", "right" }; //, "menu" };
6262
static final int LEFT = 0;
6363
static final int MIDDLE = 1;
6464
static final int RIGHT = 2;
65-
static final int MENU = 3;
65+
// static final int MENU = 3;
6666

6767
static final int PIECE_WIDTH = 4;
68-
68+
static final int PIECE_HEIGHT = 33;
6969
Image[][] pieces;
70+
71+
static final int ARROW_WIDTH = 6;
72+
static final int ARROW_HEIGHT = 6;
73+
Image tabArrow;
7074

7175
//
7276

@@ -131,15 +135,39 @@ public void mouseMoved(MouseEvent e) {
131135
}
132136

133137

138+
protected String tabFile(int status, int where) {
139+
return "theme/tab-" + STATUS[status] + "-" + WHERE[where];
140+
}
141+
142+
134143
public void updateMode() {
135144
Mode mode = editor.getMode();
145+
int res = Toolkit.isRetina() ? 2 : 1;
146+
147+
String suffix = "-2x.png"; // wishful thinking
148+
// Some modes may not have a 2x version. If a mode doesn't have a 1x
149+
// version, this will cause an error... they should always have 1x.
150+
if (res == 2) {
151+
if (!mode.getContentFile(tabFile(0, 0) + suffix).exists()) {
152+
res = 1;
153+
}
154+
}
155+
if (res == 1) {
156+
suffix = ".png";
157+
if (!mode.getContentFile(tabFile(0, 0) + suffix).exists()) {
158+
suffix = ".gif";
159+
}
160+
}
161+
136162
pieces = new Image[STATUS.length][WHERE.length];
137-
for (int i = 0; i < STATUS.length; i++) {
138-
for (int j = 0; j < WHERE.length; j++) {
139-
String filename = "theme/tab-" + STATUS[i] + "-" + WHERE[j] + ".gif";
140-
pieces[i][j] = mode.loadImage(filename);
163+
for (int status = 0; status < STATUS.length; status++) {
164+
for (int where = 0; where < WHERE.length; where++) {
165+
//String filename = "theme/tab-" + STATUS[i] + "-" + WHERE[j] + ".gif";
166+
pieces[status][where] = mode.loadImage(tabFile(status, where) + suffix);
141167
}
142168
}
169+
170+
tabArrow = mode.loadImage("theme/tab-arrow");
143171

144172
backgroundColor = mode.getColor("header.bgcolor");
145173
textColor[SELECTED] = mode.getColor("header.text.selected.color");
@@ -214,10 +242,9 @@ public void paintComponent(Graphics screen) {
214242
visitOrder = new Tab[sketch.getCodeCount() - 1];
215243
}
216244

217-
// int x = 6; // offset from left edge of the component
218245
menuRight = sizeW - 16;
219-
menuLeft = menuRight - pieces[0][MENU].getWidth(this);
220-
// int tabMax = menuLeft - x;
246+
// menuLeft = menuRight - pieces[0][MENU].getWidth(this);
247+
menuLeft = menuRight - 50; // FIXME!!
221248
int tabLeft = 6;
222249
int tabMax = menuLeft - tabLeft;
223250

@@ -264,40 +291,9 @@ public void paintComponent(Graphics screen) {
264291
// now actually draw the tabs
265292
placeTabs(tabLeft, tabMax, g);
266293

267-
// for (int i = 0; i < sketch.getCodeCount(); i++) {
268-
// SketchCode code = sketch.getCode(i);
269-
// Tab tab = tabs[i];
270-
//
271-
// int pieceCount = 2 + (tab.textWidth / PIECE_WIDTH);
272-
// int pieceWidth = pieceCount * PIECE_WIDTH;
273-
//
274-
// int state = (code == sketch.getCurrentCode()) ? SELECTED : UNSELECTED;
275-
// g.drawImage(pieces[state][LEFT], x, 0, null);
276-
// x += PIECE_WIDTH;
277-
//
278-
// int contentLeft = x;
279-
// tab.left = x;
280-
// for (int j = 0; j < pieceCount; j++) {
281-
// g.drawImage(pieces[state][MIDDLE], x, 0, null);
282-
// x += PIECE_WIDTH;
283-
// }
284-
// tab.right = x;
285-
// int textLeft = contentLeft + (pieceWidth - tab.textWidth) / 2;
286-
//
287-
// g.setColor(textColor[state]);
288-
// int baseline = (sizeH + fontAscent) / 2;
289-
// //g.drawString(sketch.code[i].name, textLeft, baseline);
290-
// g.drawString(tab.text, textLeft, baseline);
291-
//
292-
// g.drawImage(pieces[state][RIGHT], x, 0, null);
293-
// x += PIECE_WIDTH - 1; // overlap by 1 pixel
294-
// }
295-
296-
// menuLeft = sizeW - (16 + pieces[0][MENU].getWidth(this));
297-
// menuRight = sizeW - 16;
298294
// draw the dropdown menu target
299-
g.drawImage(pieces[popup.isVisible() ? SELECTED : UNSELECTED][MENU],
300-
menuLeft, 0, null);
295+
// g.drawImage(pieces[popup.isVisible() ? SELECTED : UNSELECTED][MENU],
296+
// menuLeft, 0, null);
301297

302298
screen.drawImage(offscreen, 0, 0, imageW, imageH, null);
303299
}
@@ -319,15 +315,15 @@ private boolean placeTabs(int left, int right, Graphics g) {
319315

320316
int state = (code == sketch.getCurrentCode()) ? SELECTED : UNSELECTED;
321317
if (g != null) {
322-
g.drawImage(pieces[state][LEFT], x, 0, null);
318+
g.drawImage(pieces[state][LEFT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
323319
}
324320
x += PIECE_WIDTH;
325321

326322
int contentLeft = x;
327323
tab.left = x;
328324
for (int j = 0; j < pieceCount; j++) {
329325
if (g != null) {
330-
g.drawImage(pieces[state][MIDDLE], x, 0, null);
326+
g.drawImage(pieces[state][MIDDLE], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
331327
}
332328
x += PIECE_WIDTH;
333329
}
@@ -344,7 +340,7 @@ private boolean placeTabs(int left, int right, Graphics g) {
344340
}
345341

346342
if (g != null) {
347-
g.drawImage(pieces[state][RIGHT], x, 0, null);
343+
g.drawImage(pieces[state][RIGHT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
348344
}
349345
x += PIECE_WIDTH - 1; // overlap by 1 pixel
350346
}

app/src/processing/app/EditorToolbar.java

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2004-10 Ben Fry and Casey Reas
6+
Copyright (c) 2004-13 Ben Fry and Casey Reas
77
Copyright (c) 2001-04 Massachusetts Institute of Technology
88
99
This program is free software; you can redistribute it and/or modify
@@ -89,6 +89,12 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
8989
JMenu modeMenu;
9090

9191
protected ArrayList<Button> buttons;
92+
93+
static final int ARROW_WIDTH = 6;
94+
static final int ARROW_HEIGHT = 6;
95+
Image modeArrow;
96+
97+
protected Image backgroundImage;
9298

9399

94100
public EditorToolbar(Editor editor, Base base) { //, JMenu menu) {
@@ -103,7 +109,8 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) {
103109
bgcolor = mode.getColor("buttons.bgcolor");
104110
statusFont = mode.getFont("buttons.status.font");
105111
statusColor = mode.getColor("buttons.status.color");
106-
modeTitle = mode.getTitle().toUpperCase();
112+
// modeTitle = mode.getTitle().toUpperCase();
113+
modeTitle = mode.getTitle();
107114
modeTextFont = mode.getFont("mode.button.font");
108115
modeButtonColor = mode.getColor("mode.button.color");
109116

@@ -123,20 +130,24 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) {
123130
public Image[][] loadImages() {
124131
int res = Toolkit.isRetina() ? 2 : 1;
125132

133+
String suffix = null;
126134
Image allButtons = null;
127135
// Some modes may not have a 2x version. If a mode doesn't have a 1x
128136
// version, this will cause an error... they should always have 1x.
129137
if (res == 2) {
130-
allButtons = mode.loadImage("theme/buttons-2x.png");
138+
suffix = "-2x.png";
139+
allButtons = mode.loadImage("theme/buttons" + suffix);
131140
if (allButtons == null) {
132141
res = 1; // take him down a notch
133142
}
134143
}
135144
if (res == 1) {
136-
allButtons = mode.loadImage("theme/buttons.png");
145+
suffix = ".png";
146+
allButtons = mode.loadImage("theme/buttons" + suffix);
137147
if (allButtons == null) {
138148
// use the old (pre-2.0b9) file name
139-
allButtons = mode.loadImage("theme/buttons.gif");
149+
suffix = ".gif";
150+
allButtons = mode.loadImage("theme/buttons" + suffix);
140151
}
141152
}
142153

@@ -145,7 +156,6 @@ public Image[][] loadImages() {
145156

146157
for (int i = 0; i < count; i++) {
147158
for (int state = 0; state < 3; state++) {
148-
// Image image = createImage(BUTTON_WIDTH*res, BUTTON_HEIGHT*res);
149159
Image image = new BufferedImage(BUTTON_WIDTH*res, BUTTON_HEIGHT*res, BufferedImage.TYPE_INT_ARGB);
150160
Graphics g = image.getGraphics();
151161
g.drawImage(allButtons,
@@ -155,6 +165,10 @@ public Image[][] loadImages() {
155165
buttonImages[i][state] = image;
156166
}
157167
}
168+
169+
// Load the dropdown arrow, based on all the work done above
170+
modeArrow = mode.loadImage("theme/mode-arrow" + suffix);
171+
158172
return buttonImages;
159173
}
160174

@@ -168,24 +182,6 @@ public void paintComponent(Graphics screen) {
168182
init();
169183
}
170184

171-
// this data is shared by all EditorToolbar instances
172-
// if (buttonImages == null) {
173-
// loadButtons();
174-
// }
175-
176-
// this happens once per instance of EditorToolbar
177-
// if (stateImage == null) {
178-
// state = new int[buttonCount];
179-
// stateImage = new Image[buttonCount];
180-
// for (int i = 0; i < buttonCount; i++) {
181-
// setState(i, INACTIVE, false);
182-
// }
183-
// y1 = 0;
184-
// y2 = BUTTON_HEIGHT;
185-
// x1 = new int[buttonCount];
186-
// x2 = new int[buttonCount];
187-
// }
188-
189185
Dimension size = getSize();
190186
if ((offscreen == null) ||
191187
(size.width != width) || (size.height != height)) {
@@ -254,34 +250,33 @@ public void paintComponent(Graphics screen) {
254250
g.drawString(status, buttons.size() * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
255251
}
256252

257-
// Color modeButtonColor;
258-
// Font modeTextFont;
259-
// Color modeTextColor;
260253
g.setFont(modeTextFont);
261254
FontMetrics metrics = g.getFontMetrics();
262-
int modeH = metrics.getAscent();
263-
int modeW = metrics.stringWidth(modeTitle);
264-
final int modeGapH = 6;
265-
final int modeGapV = 3;
255+
int modeTextHeight = metrics.getAscent();
256+
int modeTextWidth = metrics.stringWidth(modeTitle);
257+
final int modeGapWidth = 6;
258+
final int modeBoxHeight = 20;
266259
modeX2 = getWidth() - 16;
267-
modeX1 = modeX2 - (modeGapH + modeW + modeGapH);
268-
modeY1 = (getHeight() - modeH)/2 - modeGapV;
269-
modeY2 = modeY1 + modeH + modeGapV*2;
270-
// g.setColor(modeButtonColor);
271-
// g.fillRect(modeX1, modeY1, modeX2 - modeX1, modeY2 - modeY1);
272-
// g.setColor(modeTextColor);
273-
// g.drawString(modeTitle, modeX1 + modeGapH, modeY2 - modeGapV);
260+
modeX1 = modeX2 - (modeGapWidth + modeTextWidth + modeGapWidth + ARROW_WIDTH + modeGapWidth);
261+
modeY1 = (getHeight() - modeBoxHeight) / 2;
262+
modeY2 = modeY1 + modeBoxHeight; //modeY1 + modeH + modeGapV*2;
274263
g.setColor(modeButtonColor);
275264
g.drawRect(modeX1, modeY1, modeX2 - modeX1, modeY2 - modeY1);
276-
g.drawString(modeTitle, modeX1 + modeGapH, modeY2 - modeGapV);
265+
g.drawString(modeTitle,
266+
modeX1 + modeGapWidth,
267+
modeY1 + modeTextHeight + (modeBoxHeight - modeTextHeight) / 2);
268+
g.drawImage(modeArrow,
269+
modeX2 - ARROW_WIDTH - modeGapWidth,
270+
modeY1 + (modeBoxHeight - ARROW_HEIGHT) / 2,
271+
ARROW_WIDTH, ARROW_HEIGHT, this);
277272

278273
screen.drawImage(offscreen, 0, 0, size.width, size.height, null);
279274

280275
// dim things out when not enabled (not currently in use)
281-
if (!isEnabled()) {
282-
screen.setColor(new Color(0, 0, 0, 100));
283-
screen.fillRect(0, 0, getWidth(), getHeight());
284-
}
276+
// if (!isEnabled()) {
277+
// screen.setColor(new Color(0, 0, 0, 100));
278+
// screen.fillRect(0, 0, getWidth(), getHeight());
279+
// }
285280
}
286281

287282

java/theme/menu-2x.png

-173 Bytes
Binary file not shown.

java/theme/mode-arrow-2x.png

2.79 KB
Loading

java/theme/tab-arrow-2x.png

494 Bytes
Loading

java/theme/tab-arrow.png

247 Bytes
Loading

java/theme/tab-sel-left-2x.png

158 Bytes
Loading

java/theme/tab-sel-left.gif

-62 Bytes
Binary file not shown.

java/theme/tab-sel-left.png

143 Bytes
Loading

0 commit comments

Comments
 (0)