Page 1 of 1
SetBrushTransparency after RotateBrush problem
Posted: Sun Jan 27, 2013 6:41 pm
by Mazze
Doing SetBrushTransparency after RotateBrush causes some corruption:
Code: Select all
@DISPLAY 1, {Color = #SILVER}
CreateBrush(1, 50, 50)
SelectBrush(1)
Line(0, 25, 50, 25, #RED,{ Thickness = 10})
Line(0, 0, 50, 50, #RED,{ Thickness = 10})
EndSelect
DisplayBrush(1, 0, 0)
RotateBrush(1, 45)
DisplayBrush(1, 50, 0)
;DeleteMask(1)
SetBrushTransparency(1, #BLACK)
DisplayBrush(1, 150,0)
WaitLeftMouse()
Am I doing something wrong or is this a bug?
Re: SetBrushTransparency after RotateBrush problem
Posted: Tue Jan 29, 2013 5:15 pm
by airsoftsoftwair
That's not a bug.
SetBrushTransparency() generates a completely new mask for the brush, taking all pixels into account (visible and invisible pixels). After
RotateBrush() returns, invisible pixels may contain random colors. That's why you get the graphical glitches. To workaround this you need to create another brush with a static background color (i.e. black), draw the rotated brush onto it, and then call
SetBrushTransparency() on this new brush. I agree that this is a little bit of overhead. Maybe I'll add an optional argument to
SetBrushTransparency() that allows you to specify whether invisible pixels should be taken into account as well or not.
Re: SetBrushTransparency after RotateBrush problem
Posted: Tue Jan 29, 2013 9:31 pm
by Mazze
Got it. Here's how my "make all pixels in background color transparent" is implemented in HollyPaint:
Code: Select all
Function Brush.p_DoTransparent()
DebugPrint("***** Brush.p_DoTransparent")
If Brush.have = True
If GetAttribute(#BRUSH, Brush.brush, #ATTRHASMASK)
; rotation of a brush adds a mask where the unmasked
; bits have random values. We need a workaround
; to clean the brush.
Local width = GetAttribute(#BRUSH, Brush.brush, #ATTRWIDTH)
Local height = GetAttribute(#BRUSH, Brush.brush, #ATTRHEIGHT)
Local newbrush = CreateBrush(Nil, width, height, Canvas.backcolor)
SelectBrush(newbrush)
DisplayBrush(Brush.brush, 0, 0)
EndSelect
FreeBrush(Brush.brush)
Brush.brush = newbrush
EndIf
SetBrushTransparency(Brush.brush, Canvas.backcolor)
Else
mui.Request("HollyPaint", "No brush available to set transparency.", "Ok")
EndIf
EndFunction