| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ | |||
| 3 | 3 | /* | |
| 4 | 4 | Part of the Processing project - http://processing.org | |
| 5 | 5 | ||
| 6 | - Copyright (c) 2004-11 Ben Fry and Casey Reas | ||
| 6 | + Copyright (c) 2004-13 Ben Fry and Casey Reas | ||
| 7 | 7 | Copyright (c) 2001-04 Massachusetts Institute of Technology | |
| 8 | 8 | ||
| 9 | 9 | This program is free software; you can redistribute it and/or modify | |
@@ -25,6 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | 26 | import java.awt.*; | |
| 27 | 27 | import java.awt.event.*; | |
| 28 | + import java.awt.geom.GeneralPath; | ||
| 28 | 29 | import java.util.Arrays; | |
| 29 | 30 | ||
| 30 | 31 | import javax.swing.*; | |
@@ -34,8 +35,25 @@ | |||
| 34 | 35 | * Sketch tabs at the top of the editor window. | |
| 35 | 36 | */ | |
| 36 | 37 | public class EditorHeader extends JComponent { | |
| 38 | + // standard UI sizing (OS-specific, but generally consistent) | ||
| 39 | + static final int SCROLLBAR_WIDTH = 16; | ||
| 40 | + // amount of space on the left edge before the tabs start | ||
| 41 | + static final int MARGIN_WIDTH = 6; | ||
| 42 | + // distance from the righthand side of a tab to the drop-down arrow | ||
| 43 | + static final int ARROW_GAP_WIDTH = 8; | ||
| 44 | + // indent x/y for notch on the tab | ||
| 45 | + static final int NOTCH = 4; | ||
| 46 | + // how far to raise the tab from the bottom of this Component | ||
| 47 | + static final int TAB_HEIGHT = 27; | ||
| 48 | + // amount of margin on the left/right for the text on the tab | ||
| 49 | + static final int TEXT_MARGIN = 5; | ||
| 50 | + // width of the tab when no text visible | ||
| 51 | + // (total tab width will be this plus TEXT_MARGIN*2) | ||
| 52 | + static final int NO_TEXT_WIDTH = 10; | ||
| 53 | + | ||
| 37 | 54 | Color backgroundColor; | |
| 38 | 55 | Color textColor[] = new Color[2]; | |
| 56 | + Color tabColor[] = new Color[2]; | ||
| 39 | 57 | ||
| 40 | 58 | Editor editor; | |
| 41 | 59 | ||
@@ -68,8 +86,8 @@ public class EditorHeader extends JComponent { | |||
| 68 | 86 | static final int PIECE_HEIGHT = 33; | |
| 69 | 87 | Image[][] pieces; | |
| 70 | 88 | ||
| 71 | - static final int ARROW_WIDTH = 6; | ||
| 72 | - static final int ARROW_HEIGHT = 6; | ||
| 89 | + static final int ARROW_WIDTH = 14; | ||
| 90 | + static final int ARROW_HEIGHT = 14; | ||
| 73 | 91 | Image tabArrow; | |
| 74 | 92 | ||
| 75 | 93 | // | |
@@ -167,12 +185,15 @@ public void updateMode() { | |||
| 167 | 185 | } | |
| 168 | 186 | } | |
| 169 | 187 | ||
| 170 | - tabArrow = mode.loadImage("theme/tab-arrow"); | ||
| 188 | + tabArrow = mode.loadImage("theme/tab-arrow" + suffix); | ||
| 171 | 189 | ||
| 172 | 190 | backgroundColor = mode.getColor("header.bgcolor"); | |
| 173 | 191 | textColor[SELECTED] = mode.getColor("header.text.selected.color"); | |
| 174 | 192 | textColor[UNSELECTED] = mode.getColor("header.text.unselected.color"); | |
| 175 | 193 | font = mode.getFont("header.text.font"); | |
| 194 | + | ||
| 195 | + tabColor[SELECTED] = mode.getColor("header.tab.selected.color"); | ||
| 196 | + tabColor[UNSELECTED] = mode.getColor("header.tab.unselected.color"); | ||
| 176 | 197 | } | |
| 177 | 198 | ||
| 178 | 199 | ||
@@ -228,6 +249,15 @@ public void paintComponent(Graphics screen) { | |||
| 228 | 249 | // set the background for the offscreen | |
| 229 | 250 | g.setColor(backgroundColor); | |
| 230 | 251 | g.fillRect(0, 0, imageW, imageH); | |
| 252 | + | ||
| 253 | + // EditorToolbar toolbar = editor.toolbar; | ||
| 254 | + // if (toolbar != null && toolbar.backgroundImage != null) { | ||
| 255 | + // g.drawImage(toolbar.backgroundImage, | ||
| 256 | + // 0, -toolbar.getHeight(), | ||
| 257 | + // EditorToolbar.BACKGROUND_WIDTH, | ||
| 258 | + // EditorToolbar.BACKGROUND_HEIGHT, null); | ||
| 259 | + // } | ||
| 260 | + editor.getMode().drawBackground(g, EditorToolbar.BUTTON_HEIGHT); | ||
| 231 | 261 | ||
| 232 | 262 | // int codeCount = sketch.getCodeCount(); | |
| 233 | 263 | // if ((tabLeft == null) || (tabLeft.length < codeCount)) { | |
@@ -242,11 +272,10 @@ public void paintComponent(Graphics screen) { | |||
| 242 | 272 | visitOrder = new Tab[sketch.getCodeCount() - 1]; | |
| 243 | 273 | } | |
| 244 | 274 | ||
| 245 | - menuRight = sizeW - 16; | ||
| 275 | + // menuRight = sizeW - 16; | ||
| 246 | 276 | // menuLeft = menuRight - pieces[0][MENU].getWidth(this); | |
| 247 | - menuLeft = menuRight - 50; // FIXME!! | ||
| 248 | - int tabLeft = 6; | ||
| 249 | - int tabMax = menuLeft - tabLeft; | ||
| 277 | + // menuLeft = menuRight - 50; // FIXME!! | ||
| 278 | + int tabMax = menuLeft - (MARGIN_WIDTH + SCROLLBAR_WIDTH); | ||
| 250 | 279 | ||
| 251 | 280 | // reset all tab positions | |
| 252 | 281 | for (Tab tab : tabs) { | |
@@ -265,7 +294,7 @@ public void paintComponent(Graphics screen) { | |||
| 265 | 294 | } | |
| 266 | 295 | ||
| 267 | 296 | // make sure everything can fit | |
| 268 | - if (!placeTabs(tabLeft, tabMax, null)) { | ||
| 297 | + if (!placeTabs(MARGIN_WIDTH, tabMax, null)) { | ||
| 269 | 298 | //System.arraycopy(tabs, 0, visitOrder, 0, tabs.length); | |
| 270 | 299 | // always show the tab with the sketch's name | |
| 271 | 300 | // System.arraycopy(tabs, 1, visitOrder, 0, tabs.length - 1); | |
@@ -280,69 +309,103 @@ public void paintComponent(Graphics screen) { | |||
| 280 | 309 | // } | |
| 281 | 310 | // System.out.println(); | |
| 282 | 311 | ||
| 312 | + // Keep shrinking the tabs one-by-one until things fit properly | ||
| 283 | 313 | for (int i = 0; i < visitOrder.length; i++) { | |
| 284 | 314 | tabs[visitOrder[i].index].textVisible = false; | |
| 285 | - if (placeTabs(tabLeft, tabMax, null)) { | ||
| 315 | + if (placeTabs(MARGIN_WIDTH, tabMax, null)) { | ||
| 286 | 316 | break; | |
| 287 | 317 | } | |
| 288 | 318 | } | |
| 289 | 319 | } | |
| 290 | 320 | ||
| 291 | 321 | // now actually draw the tabs | |
| 292 | - placeTabs(tabLeft, tabMax, g); | ||
| 322 | + placeTabs(MARGIN_WIDTH, tabMax, g2); | ||
| 293 | 323 | ||
| 294 | 324 | // draw the dropdown menu target | |
| 325 | + menuLeft = tabs[tabs.length - 1].right + ARROW_GAP_WIDTH; | ||
| 326 | + menuRight = menuLeft + ARROW_WIDTH; | ||
| 327 | + int arrowY = (getHeight() - TAB_HEIGHT) + (TAB_HEIGHT - ARROW_HEIGHT)/2; | ||
| 328 | + g.drawImage(tabArrow, menuLeft, arrowY, | ||
| 329 | + ARROW_WIDTH, ARROW_HEIGHT, null); | ||
| 295 | 330 | // g.drawImage(pieces[popup.isVisible() ? SELECTED : UNSELECTED][MENU], | |
| 296 | 331 | // menuLeft, 0, null); | |
| 297 | 332 | ||
| 298 | 333 | screen.drawImage(offscreen, 0, 0, imageW, imageH, null); | |
| 299 | 334 | } | |
| 300 | 335 | ||
| 301 | 336 | ||
| 302 | - private boolean placeTabs(int left, int right, Graphics g) { | ||
| 337 | + private boolean placeTabs(int left, int right, Graphics2D g) { | ||
| 303 | 338 | Sketch sketch = editor.getSketch(); | |
| 304 | 339 | int x = left; | |
| 305 | 340 | ||
| 341 | + final int bottom = getHeight(); | ||
| 342 | + final int top = bottom - TAB_HEIGHT; | ||
| 343 | + GeneralPath path = null; | ||
| 344 | + | ||
| 306 | 345 | for (int i = 0; i < sketch.getCodeCount(); i++) { | |
| 307 | 346 | SketchCode code = sketch.getCode(i); | |
| 308 | 347 | Tab tab = tabs[i]; | |
| 309 | 348 | ||
| 310 | - int pieceCount = 2 + (tab.textWidth / PIECE_WIDTH); | ||
| 311 | - if (tab.textVisible == false) { | ||
| 312 | - pieceCount = 4; | ||
| 313 | - } | ||
| 314 | - int pieceWidth = pieceCount * PIECE_WIDTH; | ||
| 349 | + // int pieceCount = 2 + (tab.textWidth / PIECE_WIDTH); | ||
| 350 | + // if (tab.textVisible == false) { | ||
| 351 | + // pieceCount = 4; | ||
| 352 | + // } | ||
| 353 | + // int pieceWidth = pieceCount * PIECE_WIDTH; | ||
| 315 | 354 | ||
| 316 | 355 | int state = (code == sketch.getCurrentCode()) ? SELECTED : UNSELECTED; | |
| 317 | 356 | if (g != null) { | |
| 318 | - g.drawImage(pieces[state][LEFT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null); | ||
| 357 | + //g.drawImage(pieces[state][LEFT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null); | ||
| 358 | + path = new GeneralPath(); | ||
| 359 | + path.moveTo(x, bottom); | ||
| 360 | + path.lineTo(x, top + NOTCH); | ||
| 361 | + path.lineTo(x + NOTCH, top); | ||
| 319 | 362 | } | |
| 320 | - x += PIECE_WIDTH; | ||
| 321 | - | ||
| 322 | - int contentLeft = x; | ||
| 323 | 363 | tab.left = x; | |
| 324 | - for (int j = 0; j < pieceCount; j++) { | ||
| 325 | - if (g != null) { | ||
| 326 | - g.drawImage(pieces[state][MIDDLE], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null); | ||
| 327 | - } | ||
| 328 | - x += PIECE_WIDTH; | ||
| 329 | - } | ||
| 364 | + x += TEXT_MARGIN; | ||
| 365 | + // x += PIECE_WIDTH; | ||
| 366 | + | ||
| 367 | + // int contentLeft = x; | ||
| 368 | + // for (int j = 0; j < pieceCount; j++) { | ||
| 369 | + // if (g != null) { | ||
| 370 | + // g.drawImage(pieces[state][MIDDLE], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null); | ||
| 371 | + // } | ||
| 372 | + // x += PIECE_WIDTH; | ||
| 373 | + // } | ||
| 374 | + // if (g != null) { | ||
| 375 | + int drawWidth = tab.textVisible ? tab.textWidth : NO_TEXT_WIDTH; | ||
| 376 | + x += drawWidth + TEXT_MARGIN; | ||
| 377 | + // path.moveTo(x, top); | ||
| 378 | + // } | ||
| 330 | 379 | tab.right = x; | |
| 331 | 380 | ||
| 381 | + if (g != null) { | ||
| 382 | + path.lineTo(x - NOTCH, top); | ||
| 383 | + path.lineTo(x, top + NOTCH); | ||
| 384 | + path.lineTo(x, bottom); | ||
| 385 | + path.closePath(); | ||
| 386 | + g.setColor(tabColor[state]); | ||
| 387 | + g.fill(path); | ||
| 388 | + //g.drawImage(pieces[state][RIGHT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null); | ||
| 389 | + } | ||
| 390 | + | ||
| 332 | 391 | if (tab.textVisible) { | |
| 333 | - int textLeft = contentLeft + (pieceWidth - tab.textWidth) / 2; | ||
| 392 | + // int textLeft = contentLeft + (pieceWidth - tab.textWidth) / 2; | ||
| 334 | 393 | if (g != null) { | |
| 394 | + int textLeft = tab.left + ((tab.right - tab.left) - tab.textWidth) / 2; | ||
| 335 | 395 | g.setColor(textColor[state]); | |
| 336 | - int baseline = (sizeH + fontAscent) / 2; | ||
| 396 | + // int baseline = (int) Math.ceil((sizeH + fontAscent) / 2.0); | ||
| 397 | + int baseline = bottom - (TAB_HEIGHT - fontAscent)/2 - 1; | ||
| 337 | 398 | //g.drawString(sketch.code[i].name, textLeft, baseline); | |
| 338 | 399 | g.drawString(tab.text, textLeft, baseline); | |
| 400 | + // g.drawLine(tab.left, baseline-fontAscent, tab.right, baseline-fontAscent); | ||
| 339 | 401 | } | |
| 340 | 402 | } | |
| 341 | 403 | ||
| 342 | - if (g != null) { | ||
| 343 | - g.drawImage(pieces[state][RIGHT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null); | ||
| 344 | - } | ||
| 345 | - x += PIECE_WIDTH - 1; // overlap by 1 pixel | ||
| 404 | + // if (g != null) { | ||
| 405 | + // g.drawImage(pieces[state][RIGHT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null); | ||
| 406 | + // } | ||
| 407 | + // x += PIECE_WIDTH - 1; // overlap by 1 pixel | ||
| 408 | + x += 1; | ||
| 346 | 409 | } | |
| 347 | 410 | return x <= right; | |
| 348 | 411 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,7 +70,7 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList | |||
| 70 | 70 | // int which[]; // mapping indices to implementation | |
| 71 | 71 | ||
| 72 | 72 | // int x1[], x2[]; | |
| 73 | - static final int TOP = 0; | ||
| 73 | + static final int TOP = 2; | ||
| 74 | 74 | static final int BOTTOM = BUTTON_HEIGHT; | |
| 75 | 75 | ||
| 76 | 76 | Font statusFont; | |
@@ -94,8 +94,6 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList | |||
| 94 | 94 | static final int ARROW_HEIGHT = 6; | |
| 95 | 95 | Image modeArrow; | |
| 96 | 96 | ||
| 97 | - protected Image backgroundImage; | ||
| 98 | - | ||
| 99 | 97 | ||
| 100 | 98 | public EditorToolbar(Editor editor, Base base) { //, JMenu menu) { | |
| 101 | 99 | this.editor = editor; | |
@@ -168,6 +166,8 @@ public Image[][] loadImages() { | |||
| 168 | 166 | ||
| 169 | 167 | // Load the dropdown arrow, based on all the work done above | |
| 170 | 168 | modeArrow = mode.loadImage("theme/mode-arrow" + suffix); | |
| 169 | + // And the background image | ||
| 170 | + // backgroundImage = mode.loadImage("theme/mode" + suffix); | ||
| 171 | 171 | ||
| 172 | 172 | return buttonImages; | |
| 173 | 173 | } | |
@@ -224,6 +224,10 @@ public void paintComponent(Graphics screen) { | |||
| 224 | 224 | ||
| 225 | 225 | g.setColor(bgcolor); //getBackground()); | |
| 226 | 226 | g.fillRect(0, 0, width, height); | |
| 227 | + // if (backgroundImage != null) { | ||
| 228 | + // g.drawImage(backgroundImage, 0, 0, BACKGROUND_WIDTH, BACKGROUND_HEIGHT, null); | ||
| 229 | + // } | ||
| 230 | + mode.drawBackground(g, 0); | ||
| 227 | 231 | ||
| 228 | 232 | // for (int i = 0; i < buttonCount; i++) { | |
| 229 | 233 | // g.drawImage(stateImage[i], x1[i], y1, null); | |
@@ -254,11 +258,11 @@ public void paintComponent(Graphics screen) { | |||
| 254 | 258 | FontMetrics metrics = g.getFontMetrics(); | |
| 255 | 259 | int modeTextHeight = metrics.getAscent(); | |
| 256 | 260 | int modeTextWidth = metrics.stringWidth(modeTitle); | |
| 257 | - final int modeGapWidth = 6; | ||
| 261 | + final int modeGapWidth = 8; | ||
| 258 | 262 | final int modeBoxHeight = 20; | |
| 259 | 263 | modeX2 = getWidth() - 16; | |
| 260 | 264 | modeX1 = modeX2 - (modeGapWidth + modeTextWidth + modeGapWidth + ARROW_WIDTH + modeGapWidth); | |
| 261 | - modeY1 = (getHeight() - modeBoxHeight) / 2; | ||
| 265 | + modeY1 = 8; //(getHeight() - modeBoxHeight) / 2; | ||
| 262 | 266 | modeY2 = modeY1 + modeBoxHeight; //modeY1 + modeH + modeGapV*2; | |
| 263 | 267 | g.setColor(modeButtonColor); | |
| 264 | 268 | g.drawRect(modeX1, modeY1, modeX2 - modeX1, modeY2 - modeY1); | |
@@ -268,7 +272,7 @@ public void paintComponent(Graphics screen) { | |||
| 268 | 272 | g.drawImage(modeArrow, | |
| 269 | 273 | modeX2 - ARROW_WIDTH - modeGapWidth, | |
| 270 | 274 | modeY1 + (modeBoxHeight - ARROW_HEIGHT) / 2, | |
| 271 | - ARROW_WIDTH, ARROW_HEIGHT, this); | ||
| 275 | + ARROW_WIDTH, ARROW_HEIGHT, null); | ||
| 272 | 276 | ||
| 273 | 277 | screen.drawImage(offscreen, 0, 0, size.width, size.height, null); | |
| 274 | 278 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,26 @@ | |||
| 1 | + /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ | ||
| 2 | + | ||
| 3 | + /* | ||
| 4 | + Part of the Processing project - http://processing.org | ||
| 5 | + | ||
| 6 | + Copyright (c) 2013 The Processing Foundation | ||
| 7 | + Copyright (c) 2010-13 Ben Fry and Casey Reas | ||
| 8 | + | ||
| 9 | + This program is free software; you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU General Public License as published by | ||
| 11 | + the Free Software Foundation; either version 2 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + This program is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU General Public License | ||
| 20 | + along with this program; if not, write to the Free Software Foundation, | ||
| 21 | + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 22 | + */ | ||
| 23 | + | ||
| 1 | 24 | package processing.app; | |
| 2 | 25 | ||
| 3 | 26 | import java.awt.*; | |
@@ -59,6 +82,10 @@ public abstract class Mode { | |||
| 59 | 82 | */ | |
| 60 | 83 | protected ClassLoader classLoader; | |
| 61 | 84 | ||
| 85 | + static final int BACKGROUND_WIDTH = 580; | ||
| 86 | + static final int BACKGROUND_HEIGHT = 250; | ||
| 87 | + protected Image backgroundImage; | ||
| 88 | + | ||
| 62 | 89 | ||
| 63 | 90 | // public Mode(Base base, File folder) { | |
| 64 | 91 | // this(base, folder, base.getSketchbookLibrariesFolder()); | |
@@ -149,11 +176,22 @@ public void setupGUI() { | |||
| 149 | 176 | // other things that have to be set explicitly for the defaults | |
| 150 | 177 | theme.setColor("run.window.bgcolor", SystemColor.control); | |
| 151 | 178 | ||
| 179 | + String suffix = Toolkit.isRetina() ? "-2x.png" : ".png"; | ||
| 180 | + backgroundImage = loadImage("theme/mode" + suffix); | ||
| 181 | + | ||
| 152 | 182 | } catch (IOException e) { | |
| 153 | 183 | Base.showError("Problem loading theme.txt", | |
| 154 | 184 | "Could not load theme.txt, please re-install Processing", e); | |
| 155 | 185 | } | |
| 156 | 186 | } | |
| 187 | + | ||
| 188 | + | ||
| 189 | + public void drawBackground(Graphics g, int offset) { | ||
| 190 | + if (backgroundImage != null) { | ||
| 191 | + g.drawImage(backgroundImage, 0, -offset, | ||
| 192 | + BACKGROUND_WIDTH, BACKGROUND_HEIGHT, null); | ||
| 193 | + } | ||
| 194 | + } | ||
| 157 | 195 | ||
| 158 | 196 | ||
| 159 | 197 | public File getContentFile(String path) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,11 +11,15 @@ status.font = SansSerif,plain,12 | |||
| 11 | 11 | # GUI - TABS | |
| 12 | 12 | # settings for the tabs at the top | |
| 13 | 13 | # (tab images are stored in the lib/theme folder) | |
| 14 | - header.bgcolor = #818b95 | ||
| 15 | - header.text.selected.color = #1a1a00 | ||
| 14 | + #header.bgcolor = #818b95 | ||
| 15 | + header.bgcolor = #000000 | ||
| 16 | + #header.text.selected.color = #1a1a00 | ||
| 17 | + header.text.selected.color = #000000 | ||
| 16 | 18 | header.text.unselected.color = #ffffff | |
| 17 | - header.text.font = SansSerif,plain,12 | ||
| 19 | + header.text.font = SansSerif,plain,11 | ||
| 18 | 20 | #header.text.font.macosx = Helvetica,plain,12 | |
| 21 | + header.tab.selected.color = #a2afba | ||
| 22 | + header.tab.unselected.color = #2a4159 | ||
| 19 | 23 | ||
| 20 | 24 | # GUI - CONSOLE | |
| 21 | 25 | # font is handled by preferences, since size/etc is modifiable | |
| Back | FazBrowse Home | New Git URL |
0 commit comments