我已经为此苦苦挣扎了一段时间,但没有找到解决方案。当用户将鼠标悬停在 PGraphics 对象侧面显示的特定标记上时,我正在尝试显示工具提示(具有不同颜色的矩形框,其中包含一些文本)。它是用 Java 编写的,并使用 PApplet 类作为 Java 小程序运行。
问题是,由于并非所有文本都位于其他图像之上,因此无法清楚地看到文本。尽管颜色已更改并保留为工具提示的颜色,但其他标记的边缘仍保持在顶部。
这是代码的一部分,可以更好地解释我正在尝试做的事情:
// Common piece of drawing method for markers;
// Note that you should implement this by making calls
// drawMarker and showTitle, which are abstract methods
// implemented in subclasses
public void draw(PGraphics pg, float x, float y) {
// For starter code just drawMaker(...)
if (!hidden) {
drawMarker(pg, x, y);
if (selected) {
showTitle(pg, x, y); // You will implement this in the subclasses
}
}
}
@Override
public void drawMarker(PGraphics pg, float x, float y) {
// TODO Auto-generated method stub
pg.pushStyle();
// IMPLEMENT: drawing triangle for each city
pg.fill(150, 30, 30);
pg.triangle(x, y-TRI_SIZE, x-TRI_SIZE, y+TRI_SIZE, x+TRI_SIZE, y+TRI_SIZE);
// Restore previous drawing style
pg.popStyle();
}
public void showTitle(PGraphics pg, float x, float y)
{
// TODO: Implement this method
pg.pushStyle();
pg.fill(255, 255, 202);
pg.rect(x+TRI_SIZE+1, y-TRI_SIZE, 150, 15);
pg.textAlign(PConstants.LEFT, PConstants.CENTER);
pg.fill(0,0,0);
pg.text(getCity()+", " + getCountry() + ", " + getPopulation(), x+TRI_SIZE+2, y);
// Restore previous drawing style
pg.popStyle();
}
是否可以删除某些标记的边缘以不显示或以其他方式确保工具提示始终保持在顶部?提前致谢