Smalltalk 如何将图像插入多边形中?

Smalltalk 如何将图像插入多边形中?,smalltalk,squeak,morphic,Smalltalk,Squeak,Morphic,我需要得到一个纹理到一个多边形中,但这些似乎需要一个无限形式作为颜色/填充 InfiniteForm不是解决方案,因为我以后需要旋转多边形形状,移动多边形形状也会对显示的纹理产生副作用。 如果可以缩放插入的纹理,这将非常有用 如果不替换现有的多边形(或至少保持多边形的形状),您将如何做到这一点?以下是解决您问题的另一个方法。 该解决方案包括两个阶段 阶段1:(drawTextures)我们使用BitBlt用纹理瓷砖填充表单。表单存储在名为texturing的实例变量中。此表单在第2阶段被裁剪 第

我需要得到一个纹理到一个多边形中,但这些似乎需要一个无限形式作为颜色/填充

InfiniteForm不是解决方案,因为我以后需要旋转多边形形状,移动多边形形状也会对显示的纹理产生副作用。
如果可以缩放插入的纹理,这将非常有用


如果不替换现有的多边形(或至少保持多边形的形状),您将如何做到这一点?

以下是解决您问题的另一个方法。 该解决方案包括两个阶段

阶段1:(drawTextures)我们使用BitBlt用纹理瓷砖填充表单。表单存储在名为texturing的实例变量中。此表单在第2阶段被裁剪

第2阶段:(clipTextures)现在我们生成一个形状类似于多边形的多边形,带有多边形填充形式。然后我们从一个完全黑色的形式中减去它。现在我们得到了多边形的负形状。用这个我们剪辑纹理。现在,我们可以创建一个图像变形,并将其添加到多边形或我们想用它做的任何事情

不幸的是,filledForm实现无法处理凸面形状。因此,请注意多边形的外观

此解决方案速度非常快,也可以在运行时应用。我们每10秒更改一次多边形的形状,并对其进行精细渲染

!PgiTexturedMorph methodsFor: 'graphics' stamp: 'pre 2/12/2011 13:30:15.156'!
    drawTexture
        | textureForm aTexture aBitBlt |

        textureForm := Form extent: (self shape extent) depth: 32.
        aTexture := self baseImage deepCopy .
        textureForm := Form extent: (self shape extent) depth: 32.
        (0 to: ((textureForm extent x) / (aTexture extent x))) do: [ :eachX | 
            (0 to: ((textureForm extent y) / (aTexture extent y))) do: [ :eachY |
                aBitBlt := BitBlt   destForm: textureForm 
                                sourceForm: aTexture 
                                fillColor: nil
                                combinationRule: 7 
                                destOrigin: (eachX * (aTexture extent x))@(eachY *(aTexture extent y)) 
                                sourceOrigin: 0@0 
                                extent: (aTexture extent) 
                                clipRect: (textureForm computeBoundingBox).
                aBitBlt copyBits.
            ]].

        self texturing: textureForm.! !

    !PgiTexturedMorph methodsFor: 'graphics' stamp: 'pre!
    clipTextures
        | clippingForm aBitBlt |

        clippingForm := (Form extent: (self shape extent + (1@0))) fillBlack.
        aBitBlt := BitBlt   destForm: clippingForm 
                        sourceForm: (self shape filledForm) 
                        fillColor: nil
                        combinationRule: 6 
                        destOrigin: 0@0
                        sourceOrigin: 0@0 
                        extent: (self shape extent) 
                        clipRect: (clippingForm computeBoundingBox).
        aBitBlt copyBits.
        aBitBlt := BitBlt   destForm: (self texturing) 
                        sourceForm: (clippingForm ) 
                        fillColor: nil
                        combinationRule: 17 
                        destOrigin: 0@0
                        sourceOrigin: 0@0 
                        extent: (clippingForm  extent) 
                        clipRect: (self texturing computeBoundingBox).
        aBitBlt copyBits.

        self texturePart image: (self texturing).
        self texturePart changed.! !