Skip to content

Commit e65b46e

Browse files
committed
Improving text fonts and cropping
1 parent ba76406 commit e65b46e

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

src/com/reveal/codetimemachine/Commits3DView.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,19 +1275,30 @@ private void draw_topBarText(Graphics g, Rectangle drawingRect)
12751275
g2.setClip(rectangleToDrawIn);
12761276
if(cIndex ==topLayerIndex)
12771277
{
1278-
g2.setFont(new Font("Courier", Font.BOLD, 10));
1278+
g2.setFont(new Font("Arial", Font.BOLD, 10));
12791279
text = getTopBarMessage();
12801280
//text = "I: "+cIndex+"Depth = "+ Float.toString(depth)+ "FontSize: -- "+ "Alpha: "+alpha;
1281-
DrawingHelper.drawStringCenter(g2, text, drawingRect.x+drawingRect.width/2, drawingRect.y+8);
1281+
DrawingHelper.drawStringCenter(g2, text, drawingRect.x+drawingRect.width/2, drawingRect.y+10);
12821282
String path = virtualFile.getPath();
1283-
path = fit(path, 70, g2);
1283+
int maxPossible = DrawingHelper.howManyCharFitsInWidth(g2,path, 2*drawingRect.width/3 /*in 2/3 width*/ );
1284+
if(maxPossible<path.length())
1285+
{
1286+
int extraCharacterCount = path.length() - maxPossible;
1287+
int cropFrom = path.indexOf('/', extraCharacterCount);
1288+
if(cropFrom!=-1)
1289+
path = "..."+path.substring(cropFrom);
1290+
else
1291+
// If window's width be little => maxPossible->0 => path.indexOf(..) found nothing: -1 => HERE
1292+
path = virtualFile.getName();
1293+
}
1294+
//path = fit(path, 70, g2);
12841295
text = new String(path);
1285-
DrawingHelper.drawStringCenter(g2, text, drawingRect.x+drawingRect.width/2, drawingRect.y+18);
1296+
DrawingHelper.drawStringCenter(g2, text, drawingRect.x+drawingRect.width/2, drawingRect.y+20);
12861297
}
12871298
else
12881299
{
12891300
float fontSize = 20.f/(MyRenderer.getInstance().BASE_DEPTH+depth);
1290-
g2.setFont(new Font("Courier", Font.BOLD, (int)fontSize));
1301+
g2.setFont(new Font("Arial", Font.BOLD, (int)fontSize));
12911302
text = getTopBarMessage();
12921303
//text = "I: "+cIndex+"Depth = "+ Float.toString(depth)+ "FontSize: "+fontSize + "Alpha: "+alpha;
12931304
DrawingHelper.drawStringCenter(g2, text, drawingRect.x+drawingRect.width/2, drawingRect.y+15);
@@ -1349,10 +1360,8 @@ private String getTopBarMessage()
13491360
private String fit(String s, int maxCharacterCount, Graphics g)
13501361
{
13511362
String result = s;
1352-
int extraCharacterCount = result.length() - maxCharacterCount;
1353-
int cropFrom = result.indexOf('/', extraCharacterCount);
1354-
result = result.substring(cropFrom);
1355-
result = "..."+result;
1363+
1364+
13561365
return result;
13571366
}
13581367

0 commit comments

Comments
 (0)