add DrawEx() method

This commit is contained in:
sillysagiri 2024-10-16 00:06:10 +07:00
parent ebf171b5d7
commit cc06f3c961

View File

@ -206,4 +206,58 @@ public class BMF {
} }
} }
public void DrawEx(Graphics g, String str, int x, int y, int anchor)
{
short[] rect = Measure(str);
switch (anchor) {
case (Graphics.TOP | Graphics.LEFT):
Draw(g, str, x, y);
break;
case (Graphics.TOP | Graphics.RIGHT):
Draw(g, str, x-rect[0], y);
break;
case (Graphics.BOTTOM | Graphics.LEFT):
Draw(g, str, x, y-rect[1]);
break;
case (Graphics.BOTTOM | Graphics.RIGHT):
Draw(g, str, x-rect[0], y-rect[1]);
break;
case (Graphics.VCENTER | Graphics.LEFT):
Draw(g, str, x, y-(rect[1]/2));
break;
case (Graphics.VCENTER | Graphics.RIGHT):
Draw(g, str, x-rect[0], y-(rect[1]/2));
break;
case (Graphics.TOP | Graphics.HCENTER):
Draw(g, str, x-(rect[0]/2), y);
break;
case (Graphics.BOTTOM | Graphics.HCENTER):
Draw(g, str, x-(rect[0]/2), y-rect[1]);
break;
case (Graphics.VCENTER | Graphics.HCENTER):
Draw(g, str, x-(rect[0]/2), y-(rect[1]/2));
break;
case (Graphics.BASELINE | Graphics.LEFT):
Draw(g, str, x, y+(lineHeight-base));
break;
case (Graphics.BASELINE | Graphics.RIGHT):
Draw(g, str, x-rect[0], y+(lineHeight-base));
break;
default:
Draw(g, str, x, y);
break;
}
}
} }