【问题标题】:How do find the width of a Text Picture in gloss?如何在光泽度中找到文本图片的宽度?
【发布时间】:2020-04-07 18:26:25
【问题描述】:

在 Haskell Gloss 库中,使用 Picture 类型的 Text 构造函数绘制文本。但是,如何找到这样一张图片的宽度(和高度)?

【问题讨论】:

    标签: haskell gloss


    【解决方案1】:

    Here 的文本在 Gloss 中的呈现方式:

            Text str
             -> do
                    GL.blend        $= GL.Disabled
                    GL.preservingMatrix $ GLUT.renderString GLUT.Roman str
                    GL.blend        $= GL.Enabled
    

    这里的重点是它调用renderString。查看the documentation for renderString,我们立即看到另外两个有用的函数:stringWidthfontHeight。因此,您可以像这样获得宽度和高度:

    import Graphics.UI.GLUT.Fonts
    
    do
        width <- stringWidth Roman str
        height <- fontHeight Roman
    

    【讨论】:

    • 谢谢。但我认为 stringWidth 以像素为单位给出宽度 - 如何将结果转换为 Gloss 使用的 Float?
    • stringWidth 返回的GLInt 只是Int32 的类型同义词。可以使用 fromIntegral 将 Int32 转换为 Float
    猜你喜欢
    • 2017-01-09
    • 2016-06-23
    • 2020-05-09
    • 2018-02-05
    • 2012-12-25
    • 1970-01-01
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多