本文整理汇总了Java中org.eclipse.swt.graphics.GC.drawString方法的典型用法代码示例。如果您正苦于以下问题:Java GC.drawString方法的具体用法?Java GC.drawString怎么用?Java GC.drawString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.graphics.GC
的用法示例。
在下文中一共展示了GC.drawString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawString
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
public static void drawString(GC gc, String str, float x, float y, float width, float height, int bgAlpha) {
if (str == null)
return;
org.eclipse.swt.graphics.Point size = gc.stringExtent(str);
int posX = Math.round(x + width / 2 - size.x / 2);
int posY = Math.round(y + height / 2 - size.y / 2);
if (bgAlpha >= 255) {
gc.drawString(str, posX, posY);
} else {
gc.drawString(str, posX, posY, true);
if (bgAlpha > 0) {
gc.setAlpha(bgAlpha);
gc.fillRectangle(posX, posY, size.x, size.y);
gc.setAlpha(255);
}
}
}
示例2: onPaint
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
/**
* Paint.
*/
protected void onPaint(GC gc) {
final Rectangle b = getBounds();
final TestStatus status = counter != null ? counter.getAggregatedStatus() : null;
if (status != null) {
final int total = Math.max(expectedTotal, counter.getTotal()); // this is our 100% value
final int value = counter.getTotal(); // current value
final int totalPx = b.width;
final int valuePx = Math.round(totalPx * (((float) value) / ((float) total)));
gc.setBackground(getColorForStatus(status));
gc.fillRectangle(0, 0, valuePx, b.height);
gc.setBackground(getBackground());
gc.fillRectangle(0 + valuePx, 0, b.width - valuePx, b.height);
} else {
// clear
gc.setBackground(getBackground());
gc.fillRectangle(b);
}
if (counter != null) {
final FontMetrics fm = gc.getFontMetrics();
gc.setForeground(getForeground());
final int pending = expectedTotal > 0 ? expectedTotal - counter.getTotal() : -1;
gc.drawString(counter.toString(true, pending, SWT.RIGHT),
4, b.height / 2 - fm.getHeight() / 2 - fm.getDescent(), true);
}
}