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
0 commit comments