Add text capabilities to Drawable
This commit is contained in:
		
							parent
							
								
									bb7b48e6e6
								
							
						
					
					
						commit
						da5b0fd5b3
					
				
					 2 changed files with 17 additions and 0 deletions
				
			
		|  | @ -75,6 +75,19 @@ public class Canvas extends JPanel { | |||
|                 r.run(); | ||||
|                 g.scale(1/scale, 1/scale); | ||||
|             } | ||||
| 
 | ||||
|             @Override | ||||
|             public void text(double x, double y, String text) { | ||||
|                 FontMetrics metrics = g.getFontMetrics(g.getFont()); | ||||
|                 int d = metrics.getAscent(); | ||||
|                 g.drawString(text, round(x), round(y) + d); | ||||
|             } | ||||
| 
 | ||||
|             @Override | ||||
|             public void textSize(int size) { | ||||
|                 var f = g.getFont(); | ||||
|                 g.setFont(new Font(f.getName(), Font.PLAIN, size)); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -23,4 +23,8 @@ public interface Drawable { | |||
|     void translated(double x, double y, Runnable r); | ||||
| 
 | ||||
|     void scaled(double scale, Runnable r); | ||||
| 
 | ||||
|     void text(double x, double y, String text); | ||||
| 
 | ||||
|     void textSize(int size); | ||||
| } | ||||
|  |  | |||
		Reference in a new issue