首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PGraphics文本(工具提示)显示在图像顶部出现混乱

PGraphics文本(工具提示)显示在图像顶部出现混乱
EN

Stack Overflow用户
提问于 2016-05-10 07:28:46
回答 1查看 143关注 0票数 0

我与此斗争了一段时间,但没有找到解决办法。当用户将鼠标悬停在显示在PGraphics对象一侧的特定标记上时,我试图显示工具提示(一个颜色不同的矩形框,其中包含一些文本)。它是用java编写的,并使用PApplet类作为java运行。

问题是,文本没有被清晰地看到,因为并不是所有的文本都停留在其他图像之上。虽然颜色被更改并保留为工具提示的颜色,但其他标记的边缘仍然保持在顶部。

下面是代码的一部分,以更好地解释我要做的事情:

代码语言:javascript
复制
// 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();
    }

是否可以删除某些标记的边缘而不显示,或者另一种确保工具提示始终保持在顶部的方法?提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-02 16:30:15

我已经找到解决办法了。您必须做的是,只有在显示(绘制)其他图像/对象之后才显示(绘制)文本(工具提示)。这将使文本始终停留在停止,并显示清楚,没有问题。要做到这一点,您必须在绘制方法中的主类中这样做:

代码语言:javascript
复制
public void draw() {
        background(0);
        map.draw();
        addKey();

        if (lastSelected != null)
        {
            lastSelected.showToolTip(this,lastSelected.getScreenPosition(map).x,lastSelected.getScreenPosition(map).y);

        }

    } 

希望其他人发现这是有用的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37131924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档