Voici une autre idée pour votre problème. La solution comprend 2 phases.
Phase 1: (drawTextures) Nous utilisons BitBlt pour remplir un formulaire avec nos carreaux de texture. Le formulaire est stocké dans une variable d'instance appelée texturing. Ce formulaire est découpé en phase 2
Phase 2: (clipTextures) Maintenant nous produisons une forme qui a la forme de notre polygone avec polygone rempli. Ensuite, nous soustrayons cela d'une forme complètement noire. Maintenant, nous avons une forme négative du polygone. Avec ceci nous découpons la texture. Maintenant, nous pouvons créer un Morph Image et l'ajouter au polygone ou à tout ce que nous voulons faire avec.
Malheureusement, l'implémentation de fillForm ne peut pas traiter les formes convec. Alors faites attention à la forme de votre polygone.
Cette solution est assez rapide et peut également être appliquée pendant l'exécution. Nous changeons la forme du polygone toutes les 10 ms et son rendu est correct.
!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: [email protected]
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 + ([email protected]))) fillBlack.
aBitBlt := BitBlt destForm: clippingForm
sourceForm: (self shape filledForm)
fillColor: nil
combinationRule: 6
destOrigin: [email protected]
sourceOrigin: [email protected]
extent: (self shape extent)
clipRect: (clippingForm computeBoundingBox).
aBitBlt copyBits.
aBitBlt := BitBlt destForm: (self texturing)
sourceForm: (clippingForm)
fillColor: nil
combinationRule: 17
destOrigin: [email protected]
sourceOrigin: [email protected]
extent: (clippingForm extent)
clipRect: (self texturing computeBoundingBox).
aBitBlt copyBits.
self texturePart image: (self texturing).
self texturePart changed.! !