FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add icons to the tabs on the footer · VRDate/processing@0357ddf · GitHub

Repository navigation

Commit 0357ddf

Browse files
committed
add icons to the tabs on the footer
1 parent 4a1fc71 commit 0357ddf

13 files changed

Lines changed: 99 additions & 15 deletions

File tree

‎app/src/processing/app/ui/Editor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public void processKeyEvent(KeyEvent evt) {
434434
public EditorFooter createFooter() {
435435
EditorFooter ef = new EditorFooter(this);
436436
console = new EditorConsole(this);
437-
ef.addPanel(Language.text("editor.footer.console"), console);
437+
ef.addPanel(console, Language.text("editor.footer.console"), "/lib/footer/console");
438438
return ef;
439439

440440
/*

‎app/src/processing/app/ui/EditorFooter.java‎

Lines changed: 89 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2013-15 The Processing Foundation
7-
Copyright (c) 2004-13 Ben Fry and Casey Reas
8-
Copyright (c) 2001-04 Massachusetts Institute of Technology
6+
Copyright (c) 2015 The Processing Foundation
97
108
This program is free software; you can redistribute it and/or modify
119
it under the terms of the GNU General Public License as published by
@@ -57,7 +55,11 @@ public class EditorFooter extends Box {
5755
// amount of extra space between individual tabs
5856
static final int TAB_BETWEEN = 3;
5957
// amount of margin on the left/right for the text on the tab
60-
static final int TEXT_MARGIN = 16;
58+
static final int MARGIN = 16;
59+
60+
static final int ICON_WIDTH = 14;
61+
static final int ICON_HEIGHT = 13;
62+
static final int ICON_TOP = 5;
6163

6264
Color[] textColor = new Color[2];
6365
Color[] tabColor = new Color[2];
@@ -102,8 +104,20 @@ public EditorFooter(Editor eddie) {
102104
}
103105

104106

105-
public void addPanel(String name, Component comp) {
106-
tabs.add(new Tab(name, comp));
107+
/** Add a panel with no icon. */
108+
public void addPanel(Component comp, String name) {
109+
addPanel(comp, name, null);
110+
}
111+
112+
113+
/**
114+
* Add a panel with a name and icon.
115+
* @param comp Component that will be shown when this tab is selected
116+
* @param name Title to appear on the tab itself
117+
* @param icon Prefix of the file name for the icon
118+
*/
119+
public void addPanel(Component comp, String name, String icon) {
120+
tabs.add(new Tab(comp, name, icon));
107121
cardPanel.add(name, comp);
108122
}
109123

@@ -237,21 +251,27 @@ private void placeTabs(int left, Graphics2D g) {
237251
int x = left;
238252

239253
for (Tab tab : tabs) {
240-
int state = tab.isCurrent() ? SELECTED : UNSELECTED;
241254
tab.left = x;
242-
x += TEXT_MARGIN;
243-
x += tab.textWidth + TEXT_MARGIN;
255+
x += MARGIN;
256+
if (tab.hasIcon()) {
257+
x += ICON_WIDTH + MARGIN;
258+
}
259+
x += tab.textWidth + MARGIN;
244260
tab.right = x;
245261

246262
// if drawing and not just placing
247263
if (g != null) {
264+
tab.draw(g);
265+
/*
266+
int state = tab.isCurrent() ? SELECTED : UNSELECTED;
248267
g.setColor(tabColor[state]);
249268
if (tab.notification) {
250269
g.setColor(errorColor);
251270
}
252-
drawTab(g, tab.left, tab.right, tab.isFirst(), tab.isLast());
271+
//drawTab(g, tab.left, tab.right, tab.isFirst(), tab.isLast());
272+
tab.draw(g);
253273
254-
int textLeft = tab.left + ((tab.right - tab.left) - tab.textWidth) / 2;
274+
int textLeft = tab.getTextLeft();
255275
if (tab.notification && state == UNSELECTED) {
256276
g.setColor(Color.LIGHT_GRAY);
257277
} else {
@@ -260,19 +280,22 @@ private void placeTabs(int left, Graphics2D g) {
260280
int tabHeight = TAB_BOTTOM - TAB_TOP;
261281
int baseline = TAB_TOP + (tabHeight + fontAscent) / 2;
262282
g.drawString(tab.name, textLeft, baseline);
283+
*/
263284
}
264285
x += TAB_BETWEEN;
265286
}
266287
}
267288

268289

290+
/*
269291
private void drawTab(Graphics g, int left, int right,
270292
boolean leftNotch, boolean rightNotch) {
271293
Graphics2D g2 = (Graphics2D) g;
272294
g2.fill(Toolkit.createRoundRect(left, TAB_TOP, right, TAB_BOTTOM, 0, 0,
273295
rightNotch ? CURVE_RADIUS : 0,
274296
leftNotch ? CURVE_RADIUS : 0));
275297
}
298+
*/
276299

277300

278301
public Dimension getPreferredSize() {
@@ -299,13 +322,26 @@ class Tab {
299322
Component comp;
300323
boolean notification;
301324

325+
Image enabledIcon;
326+
Image selectedIcon;
327+
302328
int left;
303329
int right;
304330
int textWidth;
305331

306-
Tab(String name, Component comp) {
307-
this.name = name;
332+
Tab(Component comp, String name, String icon) {
308333
this.comp = comp;
334+
this.name = name;
335+
336+
if (icon != null) {
337+
Mode mode = editor.getMode();
338+
final int res = Toolkit.highResDisplay() ? 2 : 1;
339+
enabledIcon = mode.loadImage(icon + "-enabled-" + res + "x.png");
340+
selectedIcon = mode.loadImage(icon + "-selected-" + res + "x.png");
341+
if (selectedIcon == null) {
342+
selectedIcon = enabledIcon; // use this as the default
343+
}
344+
}
309345
}
310346

311347
boolean contains(int x) {
@@ -323,5 +359,45 @@ boolean isFirst() {
323359
boolean isLast() {
324360
return tabs.get(tabs.size() - 1) == this;
325361
}
362+
363+
int getTextLeft() {
364+
int links = left;
365+
if (enabledIcon != null) {
366+
links += ICON_WIDTH;
367+
}
368+
return links + ((right - links) - textWidth) / 2;
369+
}
370+
371+
boolean hasIcon() {
372+
return enabledIcon != null;
373+
}
374+
375+
void draw(Graphics g) {
376+
int state = isCurrent() ? SELECTED : UNSELECTED;
377+
g.setColor(tabColor[state]);
378+
if (notification) {
379+
g.setColor(errorColor);
380+
}
381+
382+
Graphics2D g2 = (Graphics2D) g;
383+
g2.fill(Toolkit.createRoundRect(left, TAB_TOP, right, TAB_BOTTOM, 0, 0,
384+
isLast() ? CURVE_RADIUS : 0,
385+
isFirst() ? CURVE_RADIUS : 0));
386+
387+
if (hasIcon()) {
388+
Image icon = isCurrent() ? selectedIcon : enabledIcon;
389+
g.drawImage(icon, left + MARGIN, ICON_TOP, ICON_WIDTH, ICON_HEIGHT, null);
390+
}
391+
392+
int textLeft = getTextLeft();
393+
if (notification && state == UNSELECTED) {
394+
g.setColor(Color.LIGHT_GRAY);
395+
} else {
396+
g.setColor(textColor[state]);
397+
}
398+
int tabHeight = TAB_BOTTOM - TAB_TOP;
399+
int baseline = TAB_TOP + (tabHeight + fontAscent) / 2;
400+
g.drawString(name, textLeft, baseline);
401+
}
326402
}
327403
}
191 Bytes
LoadingViewer requires iframe.
322 Bytes
LoadingViewer requires iframe.
189 Bytes
LoadingViewer requires iframe.
320 Bytes
LoadingViewer requires iframe.
291 Bytes
LoadingViewer requires iframe.
540 Bytes
LoadingViewer requires iframe.
243 Bytes
LoadingViewer requires iframe.
473 Bytes
LoadingViewer requires iframe.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL