-- SELECT COLOR -- -- ---------------------------------------------------------------------- -- For use with the Paint behavior. -- -- Drop this on a rectangular graphic sprite which contains a display -- of colors. ---------------------------------------------------------------------- -- PROPERTY DECLARATIONS -- -- borders of this sprite property pLeft property pTop property pRight property pBottom -- EVENT HANDLERS -- on beginSprite(me) --------------------------------------------------- -- ACTION: Determines the minimum and maximum mouseH and mouseV to -- use with getPixel() in the stepFrame handler -------------------------------------------------------------------- tSprite = sprite(me.spriteNum) pLeft = tSprite.left pTop = tSprite.top pRight = tSprite.right - 1 pBottom = tSprite.bottom - 1 end beginSprite on mouseDown(me) ----------------------------------------------------- -- ACTION: Adds this instance to the actorList, to start tracking -- the position of the mouse on stepFrame -------------------------------------------------------------------- (the actorList).append(me) end mouseDown on stepFrame(me) ----------------------------------------------------- -- RECEIVED while the user is dragging the mouse to choose a color -- ACTION: Tells any Show Brush Color sprite to display the color -- under the mouse, and tells the Paint Behavior to adopt -- the new color on mouseUp -------------------------------------------------------------------- tMouseH = max(pLeft, min(the mouseH, pRight)) tMouseV = max(pTop, min(the mouseV, pBottom)) -- Determine the color of the pixel under the mouse tColorUnderMouse = (the stage).image.getPixel(tMouseH, tMouseV) if ilk(tColorUnderMouse) <> #color then -- The mouse is not currently over the stage exit end if if the mouseDown then -- Tell a Show Brush Color behavior to show color under mouse sendAllSprites(#Paint_ShowBrushColor, tColorUnderMouse) else -- Tell the Paint behavior to set the color of the brush sendAllSprites(#Paint_SetBrushColor, tColorUnderMouse) -- ... and stop tracking colors (the actorList).deleteOne(me) end if end stepFrame