Ferin wrote:Unfortunately i failed to achieve my goals with SelectAlphaChannel and SelectBrush functions. To illustrate what i try to get i've prepared an image:
Basicaly i want to make green brush called "MASK" to make orange brush with ID=1 invisible everywhere it is covered. Of course MASK brush is not visible (it's only here to illustrate the principle). Ideally would be nice to be able to assign as many IDs as required, so green MASK brush "covers" all of them with invisibility (full or partial) leaving everything else in tact.
I don't think it's possible at the moment but i may be wrong.
Hmm.. not completely sure how you would like to have it, but here are some examples what I quickly came up with. There are always other ways to do things too, but let's see where this goes with these
Code: Select all
@DISPLAY 1,{Color=$00A4FF}
; Let's create our main brush
original_brush = CreateBrush(Nil,200,100,$FF6400)
; Get text into it by selecting it as the output device
SelectBrush(original_brush)
SetFont(#SANS, 40)
TextOut(#CENTER,#CENTER,"Brush ID=1")
EndSelect()
; And display it in its whole glory
DisplayBrush(original_brush,50,10)
; Let's do all modifications to brush 1 now on and keep our original brush as a backup
CopyBrush(original_brush,1)
; Let's then create couple "mask" brushes, but let's use alpha channel instead of actual "on/off" masks (which would also be possible, and faster too)
fully_transparent_mask_brush = CreateBrush(Nil,200,100,#GREEN,{AlphaChannel=True,Clear=True})
semi_transparent_mask_brush = CreateBrush(Nil,200,100,#GREEN,{AlphaChannel=True})
ReduceAlphaChannel(semi_transparent_mask_brush,"50%")
; Vanilla copy copies mask brush alpha values as they are
SetAlphaIntensity(#VANILLACOPY)
; Let's select alpha channel of our brush as an output device and render our mask brush's alpha channel on it
SelectAlphaChannel(1)
DisplayBrush(fully_transparent_mask_brush,-100,50)
EndSelect()
; And show the result
DisplayBrush(1,50,120)
; Let's revert to our original brush. Of course other brushes could be used too.
CopyBrush(original_brush,1)
; And then do the same with our semi transparent mask brush
SelectAlphaChannel(1)
DisplayBrush(semi_transparent_mask_brush,-100,50)
EndSelect()
DisplayBrush(1,50,230)
; You could also draw directly to alpha channel without making a mask brush
CopyBrush(original_brush,1)
SelectAlphaChannel(1)
SetAlphaIntensity("50%")
SetFillStyle(#FILLCOLOR)
Box(0,50,100,100)
EndSelect()
DisplayBrush(1,350,10)
WaitLeftMouse
And that looks like this:
But that only works if you render the "mask" to each brush individially, and maybe do some calculations for positions if they have to be somehow connected.
If you want to have the mask to mask all underlying gfx, maybe you could render everything into one big brush or so.. or maybe use layers somehow like this:
Code: Select all
; Let's enable layers
@DISPLAY 1,{Color=$00A4FF, Layers=True}
; Let's create our main brush again
original_brush = CreateBrush(Nil,200,100,$FF6400)
SelectBrush(original_brush)
SetFont(#SANS, 40)
TextOut(#CENTER,#CENTER,"Brush ID=1")
EndSelect()
; And some kind of "mask" brush
fully_transparent_mask_brush = CreateBrush(Nil,200,100,#GREEN,{AlphaChannel=True,Clear=True})
; Let's create a single big layer where we do all our drawing operations
CreateLayer(0,0,GetAttribute(#DISPLAY,0,#ATTRWIDTH),GetAttribute(#DISPLAY,0,#ATTRHEIGHT),{AlphaChannel=True, Clear=True})
; Draw some graphics into it
SelectLayer(1,#SELMODE_COMBO)
DisplayBrush(original_brush,50,10)
DisplayBrush(original_brush,260,10)
DisplayBrush(original_brush,50,120)
DisplayBrush(original_brush,260,120)
EndSelect()
; And then modify alpha channel with our mask brush
SetAlphaIntensity(#VANILLACOPY)
SelectAlphaChannel(1,#LAYER)
DisplayBrush(fully_transparent_mask_brush,80,40)
EndSelect()
WaitLeftMouse
This looks like this:
But then, if you want it to be moving quickly around and not being static render, maybe something else should be figured out... there really are several ways to approach the issue and what's the best depends your exact goal
I don't know now if there's one single easy way to make everything under it transparent...
Or maybe with clipregion... although you can't do semi transparent areas, but fully transparent somehow like this:
Code: Select all
@DISPLAY 1,{Color=$00A4FF}
; Let's create our main brush again
original_brush = CreateBrush(Nil,200,100,$FF6400)
SelectBrush(original_brush)
SetFont(#SANS, 40)
TextOut(#CENTER,#CENTER,"Brush ID=1")
EndSelect()
; Let's create kind of a inverse clipregion, whole screen, but then small area where you can't draw
clipregion_brush = CreateBrush(Nil,GetAttribute(#DISPLAY,0,#ATTRWIDTH),GetAttribute(#DISPLAY,0,#ATTRHEIGHT),Nil,{Mask=True})
SetMaskMode(#MASKINVISIBLE)
SetFillStyle(#FILLCOLOR)
SelectMask(clipregion_brush)
Box(80,40,200,100)
EndSelect()
CreateClipRegion(1, #SHAPE, clipregion_brush, 0, 0)
SetClipRegion(1)
DisplayBrush(original_brush,50,10)
DisplayBrush(original_brush,260,10)
DisplayBrush(original_brush,50,120)
DisplayBrush(original_brush,260,120)
WaitLeftMouse
Which looks exactly the same as the previous example.
Another thing I'm struggling with is drawing single straight line with LineTo() function.
Whatever i try it says "Can't draw an empty path!"
I don't have any expericene with vector graphics yet, so no time to start learning and guessing now. Maybe someone else could help