Do you know what is "the function" equivalent to :
Code: Select all
DrawingMode(#PB_2DDrawing_AlphaBlend)
What I would like to do ?
In my application Animatoon, I would like to add some special blendmode for the painting tool (not the blendmode of the layer, but when I paint on the image), to blend the stroke drawing :
- multiply, add, overlay...
Of course, I have tried the functions of blendmode I use for the layers, but unfortunately, it doesn't work.
It works with the layers, but not when I use it for paint. I think, its because, I add a colored box to use properly those blendmode for layers, but I cant add this box when drawing, because it's not the layer which change its blendmode, it's the drawing.
How I have coded the "painting" function :
it's very simple :
It's the same technic as the canvas example from purebasic :
Code: Select all
; first I draw on the sprite (for preview)
If StartDrawing(SpriteOutput(layer(LayerID)\sprite))
DrawingMode(#PB_2DDrawing_AlphaBlend)
; if I use a normal mode to paint on the layer
; X_result = the position of the point in X, With all parameters (scatter (random), centerX of sprite...).
; Y_result = the position of the point in Y, With all parameters (scatter (random), centerY of sprite...).
; Alpha = the result for the alpha, with all alpha parameters (pression tablet wacom, random, brush\alpha...)
DrawAlphaImage(ImageID(#BrushImageCopy), X_result, Y_result, Alpha)
StopDrawing()
EndIf
; Then I draw on the image (to save it because I need to update the sprite with image sometimes (when I change the blendmode for example, or if the sprite is erased)
If StartDrawing(ImageOutput(layer(LayerID)\Image))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(#BrushImageCopy), X_result, Y_result, Alpha)
StopDrawing()
EndIf
Code: Select all
DrawingMode(#PB_2DDrawing_AlphaBlend)
Like that :
Code: Select all
; first I draw on the sprite (for preview)
If StartDrawing(SpriteOutput(layer(LayerID)\sprite))
; set the blendmode for drawing the stroke
Select brush\blendmode
Case #bm_Normal
DrawingMode(#PB_2DDrawing_AlphaBlend)
Case #bm_multiply
DrawingMode(#PB_2DDrawing_CustomFilter)
CustomFilterCallback(@Painting_Multiply())
Case #bm_Add
DrawingMode(#PB_2DDrawing_CustomFilter)
CustomFilterCallback(@Painting_ADD())
EndSelect
; paint the stroke
DrawAlphaImage(ImageID(#BrushImageCopy), X_result, Y_result, Alpha)
StopDrawing()
EndIf
Code: Select all
Procedure bm_multiply(x, y, SourceColor, TargetColor)
ProcedureReturn RGBA((Red(SourceColor)*Red(TargetColor))/255,(Green(SourceColor)*Green(TargetColor))/255,(Blue(SourceColor)*Blue(TargetColor))/255, Alpha(SourceColor))
EndProcedure
So, do you an idea for a function to ahve the same result as
Code: Select all
DrawingMode(#PB_2DDrawing_AlphaBlend)
I have try that :
Code: Select all
; key A to change the painting blendmode
Procedure CallbackFiltre(X, Y, SourceColor, TargetColor)
If Alpha(SourceColor)=0 Or Alpha(TargetColor)=0
A=Alpha(SourceColor)+Alpha(TargetColor)
If A>255
A=255
EndIf
If Alpha(TargetColor) = 0
color = RGBA(Red(SourceColor),
Green(SourceColor),
Blue(SourceColor),
A)
Else
color = RGBA((Red(SourceColor)*Red(TargetColor))/255,
(Green(SourceColor)*Green(TargetColor))/255,
(Blue(SourceColor)*Blue(TargetColor))/255,
A)
EndIf
Else
A=(Alpha(SourceColor)*Alpha(TargetColor))/255
If A>255
A=255
EndIf
color = RGBA((Red(SourceColor)*Red(TargetColor))/255,
(Green(SourceColor)*Green(TargetColor))/255,
(Blue(SourceColor)*Blue(TargetColor))/255,
A)
EndIf
ProcedureReturn color
EndProcedure
UseJPEGImageDecoder()
w=600
h=400
If OpenWindow(0, 0, 0, w, h, "Blendmode painting", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateImage(0,w,h,32,#PB_Image_Transparent)
CreateImage(1,50,50,32,#PB_Image_Transparent)
; create the brush
If StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_AllChannels)
Circle(25, 25, 20, RGBA(205,150,150,255))
StopDrawing()
EndIf
AddKeyboardShortcut(0, #PB_Shortcut_A, 0)
CanvasGadget(0, 0, 0, w, h)
If StartDrawing(CanvasOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(), OutputHeight(),RGBA(200,200,200,255))
StopDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Menu
If EventMenu() = 0
blendmode = 1-blendmode
EndIf
ElseIf Event = #PB_Event_Gadget And EventGadget() = 0
If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
xx = GetGadgetAttribute(0, #PB_Canvas_MouseX)
yy = GetGadgetAttribute(0, #PB_Canvas_MouseY)
If StartDrawing(ImageOutput(0))
If blendmode =0
DrawingMode(#PB_2DDrawing_AlphaBlend)
Else
DrawingMode(#PB_2DDrawing_CustomFilter)
CustomFilterCallback(@CallbackFiltre())
EndIf
; it work with circle
; Circle(Xx, Yy, 10, RGBA(205,150,150,255))
; it doesn't works with image
DrawAlphaImage(ImageID(1),Xx-25, Yy-25)
StopDrawing()
EndIf
; update the canvas
If StartDrawing(CanvasOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(), OutputHeight(),RGBA(200,200,200,255))
DrawAlphaImage(ImageID(0),0,0)
StopDrawing()
EndIf
Else
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
If you have an idea how to fixe that, It will be great
thank you for your answers .