| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,15 +58,19 @@ public class EditorHeader extends JComponent { | |||
| 58 | 58 | static final int UNSELECTED = 0; | |
| 59 | 59 | static final int SELECTED = 1; | |
| 60 | 60 | ||
| 61 | - static final String WHERE[] = { "left", "mid", "right", "menu" }; | ||
| 61 | + static final String WHERE[] = { "left", "mid", "right" }; //, "menu" }; | ||
| 62 | 62 | static final int LEFT = 0; | |
| 63 | 63 | static final int MIDDLE = 1; | |
| 64 | 64 | static final int RIGHT = 2; | |
| 65 | - static final int MENU = 3; | ||
| 65 | + // static final int MENU = 3; | ||
| 66 | 66 | ||
| 67 | 67 | static final int PIECE_WIDTH = 4; | |
| 68 | - | ||
| 68 | + static final int PIECE_HEIGHT = 33; | ||
| 69 | 69 | Image[][] pieces; | |
| 70 | + | ||
| 71 | + static final int ARROW_WIDTH = 6; | ||
| 72 | + static final int ARROW_HEIGHT = 6; | ||
| 73 | + Image tabArrow; | ||
| 70 | 74 | ||
| 71 | 75 | // | |
| 72 | 76 | ||
@@ -131,15 +135,39 @@ public void mouseMoved(MouseEvent e) { | |||
| 131 | 135 | } | |
| 132 | 136 | ||
| 133 | 137 | ||
| 138 | + protected String tabFile(int status, int where) { | ||
| 139 | + return "theme/tab-" + STATUS[status] + "-" + WHERE[where]; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + | ||
| 134 | 143 | public void updateMode() { | |
| 135 | 144 | 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 | + | ||
| 136 | 162 | 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); | ||
| 141 | 167 | } | |
| 142 | 168 | } | |
| 169 | + | ||
| 170 | + tabArrow = mode.loadImage("theme/tab-arrow"); | ||
| 143 | 171 | ||
| 144 | 172 | backgroundColor = mode.getColor("header.bgcolor"); | |
| 145 | 173 | textColor[SELECTED] = mode.getColor("header.text.selected.color"); | |
@@ -214,10 +242,9 @@ public void paintComponent(Graphics screen) { | |||
| 214 | 242 | visitOrder = new Tab[sketch.getCodeCount() - 1]; | |
| 215 | 243 | } | |
| 216 | 244 | ||
| 217 | - // int x = 6; // offset from left edge of the component | ||
| 218 | 245 | 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!! | ||
| 221 | 248 | int tabLeft = 6; | |
| 222 | 249 | int tabMax = menuLeft - tabLeft; | |
| 223 | 250 | ||
@@ -264,40 +291,9 @@ public void paintComponent(Graphics screen) { | |||
| 264 | 291 | // now actually draw the tabs | |
| 265 | 292 | placeTabs(tabLeft, tabMax, g); | |
| 266 | 293 | ||
| 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; | ||
| 298 | 294 | // 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); | ||
| 301 | 297 | ||
| 302 | 298 | screen.drawImage(offscreen, 0, 0, imageW, imageH, null); | |
| 303 | 299 | } | |
@@ -319,15 +315,15 @@ private boolean placeTabs(int left, int right, Graphics g) { | |||
| 319 | 315 | ||
| 320 | 316 | int state = (code == sketch.getCurrentCode()) ? SELECTED : UNSELECTED; | |
| 321 | 317 | 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); | ||
| 323 | 319 | } | |
| 324 | 320 | x += PIECE_WIDTH; | |
| 325 | 321 | ||
| 326 | 322 | int contentLeft = x; | |
| 327 | 323 | tab.left = x; | |
| 328 | 324 | for (int j = 0; j < pieceCount; j++) { | |
| 329 | 325 | 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); | ||
| 331 | 327 | } | |
| 332 | 328 | x += PIECE_WIDTH; | |
| 333 | 329 | } | |
@@ -344,7 +340,7 @@ private boolean placeTabs(int left, int right, Graphics g) { | |||
| 344 | 340 | } | |
| 345 | 341 | ||
| 346 | 342 | 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); | ||
| 348 | 344 | } | |
| 349 | 345 | x += PIECE_WIDTH - 1; // overlap by 1 pixel | |
| 350 | 346 | } | |
| 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-10 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 | |
@@ -89,6 +89,12 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList | |||
| 89 | 89 | JMenu modeMenu; | |
| 90 | 90 | ||
| 91 | 91 | 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; | ||
| 92 | 98 | ||
| 93 | 99 | ||
| 94 | 100 | public EditorToolbar(Editor editor, Base base) { //, JMenu menu) { | |
@@ -103,7 +109,8 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) { | |||
| 103 | 109 | bgcolor = mode.getColor("buttons.bgcolor"); | |
| 104 | 110 | statusFont = mode.getFont("buttons.status.font"); | |
| 105 | 111 | statusColor = mode.getColor("buttons.status.color"); | |
| 106 | - modeTitle = mode.getTitle().toUpperCase(); | ||
| 112 | + // modeTitle = mode.getTitle().toUpperCase(); | ||
| 113 | + modeTitle = mode.getTitle(); | ||
| 107 | 114 | modeTextFont = mode.getFont("mode.button.font"); | |
| 108 | 115 | modeButtonColor = mode.getColor("mode.button.color"); | |
| 109 | 116 | ||
@@ -123,20 +130,24 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) { | |||
| 123 | 130 | public Image[][] loadImages() { | |
| 124 | 131 | int res = Toolkit.isRetina() ? 2 : 1; | |
| 125 | 132 | ||
| 133 | + String suffix = null; | ||
| 126 | 134 | Image allButtons = null; | |
| 127 | 135 | // Some modes may not have a 2x version. If a mode doesn't have a 1x | |
| 128 | 136 | // version, this will cause an error... they should always have 1x. | |
| 129 | 137 | if (res == 2) { | |
| 130 | - allButtons = mode.loadImage("theme/buttons-2x.png"); | ||
| 138 | + suffix = "-2x.png"; | ||
| 139 | + allButtons = mode.loadImage("theme/buttons" + suffix); | ||
| 131 | 140 | if (allButtons == null) { | |
| 132 | 141 | res = 1; // take him down a notch | |
| 133 | 142 | } | |
| 134 | 143 | } | |
| 135 | 144 | if (res == 1) { | |
| 136 | - allButtons = mode.loadImage("theme/buttons.png"); | ||
| 145 | + suffix = ".png"; | ||
| 146 | + allButtons = mode.loadImage("theme/buttons" + suffix); | ||
| 137 | 147 | if (allButtons == null) { | |
| 138 | 148 | // 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); | ||
| 140 | 151 | } | |
| 141 | 152 | } | |
| 142 | 153 | ||
@@ -145,7 +156,6 @@ public Image[][] loadImages() { | |||
| 145 | 156 | ||
| 146 | 157 | for (int i = 0; i < count; i++) { | |
| 147 | 158 | for (int state = 0; state < 3; state++) { | |
| 148 | - // Image image = createImage(BUTTON_WIDTH*res, BUTTON_HEIGHT*res); | ||
| 149 | 159 | Image image = new BufferedImage(BUTTON_WIDTH*res, BUTTON_HEIGHT*res, BufferedImage.TYPE_INT_ARGB); | |
| 150 | 160 | Graphics g = image.getGraphics(); | |
| 151 | 161 | g.drawImage(allButtons, | |
@@ -155,6 +165,10 @@ public Image[][] loadImages() { | |||
| 155 | 165 | buttonImages[i][state] = image; | |
| 156 | 166 | } | |
| 157 | 167 | } | |
| 168 | + | ||
| 169 | + // Load the dropdown arrow, based on all the work done above | ||
| 170 | + modeArrow = mode.loadImage("theme/mode-arrow" + suffix); | ||
| 171 | + | ||
| 158 | 172 | return buttonImages; | |
| 159 | 173 | } | |
| 160 | 174 | ||
@@ -168,24 +182,6 @@ public void paintComponent(Graphics screen) { | |||
| 168 | 182 | init(); | |
| 169 | 183 | } | |
| 170 | 184 | ||
| 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 | - | ||
| 189 | 185 | Dimension size = getSize(); | |
| 190 | 186 | if ((offscreen == null) || | |
| 191 | 187 | (size.width != width) || (size.height != height)) { | |
@@ -254,34 +250,33 @@ public void paintComponent(Graphics screen) { | |||
| 254 | 250 | g.drawString(status, buttons.size() * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY); | |
| 255 | 251 | } | |
| 256 | 252 | ||
| 257 | - // Color modeButtonColor; | ||
| 258 | - // Font modeTextFont; | ||
| 259 | - // Color modeTextColor; | ||
| 260 | 253 | g.setFont(modeTextFont); | |
| 261 | 254 | 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; | ||
| 266 | 259 | 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; | ||
| 274 | 263 | g.setColor(modeButtonColor); | |
| 275 | 264 | 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); | ||
| 277 | 272 | ||
| 278 | 273 | screen.drawImage(offscreen, 0, 0, size.width, size.height, null); | |
| 279 | 274 | ||
| 280 | 275 | // 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 | + // } | ||
| 285 | 280 | } | |
| 286 | 281 | ||
| 287 | 282 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments