Page 1 of 1

Draw Inside any Path

Posted: Sat Aug 21, 2021 5:49 am
by RASHAD
Hi
#1 :

Code: Select all

Procedure Draw()    
  x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
  y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
  If StartVectorDrawing(CanvasVectorOutput(0))      
    AddPathCircle(300, 300, 250)
    If IsInsidePath(x, y, #PB_Coordinate_Device)
      If StartDrawing(CanvasOutput(0))
        Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
        StopDrawing()
      EndIf
    EndIf 
    StopVectorDrawing()
  EndIf      
EndProcedure

If OpenWindow(0, 0, 0, 600, 600, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 600, 600)
  If StartVectorDrawing(CanvasVectorOutput(0))
    AddPathCircle(300, 300, 250)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(2)
    StopVectorDrawing()
  EndIf
  Repeat
    Event = WaitWindowEvent()
    
    If 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)
        draw()
      EndIf
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
  
EndIf


#2 :

Code: Select all

Procedure Draw()    
  x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
  y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
  If StartVectorDrawing(CanvasVectorOutput(0))      
    AddPathEllipse(200, 100, 150, 75)
    If IsInsidePath(x, y, #PB_Coordinate_Device)
      If StartDrawing(CanvasOutput(0))
        Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
        StopDrawing()
      EndIf
    EndIf 
    StopVectorDrawing()
  EndIf      
EndProcedure

If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 400, 200)
  If StartVectorDrawing(CanvasVectorOutput(0))
    AddPathEllipse(200, 100, 150, 75)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(2)
    StopVectorDrawing()
  EndIf
  Repeat
    Event = WaitWindowEvent()
    
    If 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)
        draw()
      EndIf
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
  
EndIf


Re: Draw Inside any Path

Posted: Sat Aug 21, 2021 7:01 am
by STARGÅTE
This is the first time I've seen code using StartDrawing in an open StartVectorDrawing block.
It seems to work, but I wonder that it works.
But what is the intention of using normal drawing inside a vector drawing scene?

Re: Draw Inside any Path

Posted: Sun Aug 22, 2021 2:34 pm
by RASHAD
Hi STARGÅTE
I do that most of the time :)
But no problem

Code: Select all

Global flag

Procedure Draw()    
  x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
  y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
  If StartVectorDrawing(CanvasVectorOutput(0))      
    AddPathCircle(300, 300, 250)
    If IsInsidePath(x, y, #PB_Coordinate_Device)
      flag = 1
    Else
      flag = 0
    EndIf 
    StopVectorDrawing()
  EndIf
  If flag = 1
    StartDrawing(CanvasOutput(0))
    Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
    StopDrawing()
  EndIf     
EndProcedure

If OpenWindow(0, 0, 0, 600, 600, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 600, 600)
  If StartVectorDrawing(CanvasVectorOutput(0))
    AddPathCircle(300, 300, 250)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(2)
    StopVectorDrawing()
  EndIf
  Repeat
    Event = WaitWindowEvent()
    If 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)
        draw()
      EndIf
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
  
EndIf