Page 1 of 1

Paint

Posted: Sat May 17, 2003 8:17 am
by J. Baker
Is it possible to make a paint program or even a vector paint program in PB? If so, could someone show me a small snippet to get me started? Thanks to who ever replies. :D

Posted: Sat May 17, 2003 10:34 am
by patrick88
just the beginning... :oops:

patrick

#INFO = 1001
#BUT_LINE = 1100
#BUT_CIRCLE = 1101
#ENT_LINE = 20
#ENT_CIRCLE = 30
#DEFINITIF = 0
#ESQUISSE = 1

Structure stru_line
x1.w
y1.w
x2.w
y2.w
EndStructure

Structure stru_circle
x1.w
y1.w
r1.w
r2.w
EndStructure

; a revoir - ok pour les tests
Dim ent_Line.stru_line(1000)
Dim ent_circle.stru_circle(1000)

Global FlagDraw.w
Global nb_ent.w
Global WinW.w, WinH.w

FlagDraw = -1
WinW=450:WinH=200
nb_ent = 0

Procedure drawLocalLineAt(n.l,etat.b)
StartDrawing(WindowOutput())
If etat = #ESQUISSE
DrawingMode(2)
LineXY(ent_Line(n)\x1,ent_Line(n)\y1,ent_Line(n)\x2,ent_Line(n)\y2)
Delay(10)
Else
DrawingMode(0)
FrontColor(0,0,0)
EndIf
LineXY(ent_Line(n)\x1,ent_Line(n)\y1,ent_Line(n)\x2,ent_Line(n)\y2)
StopDrawing()
EndProcedure

Procedure drawLocalCircleAt(n.l,etat.b)
StartDrawing(WindowOutput())
If etat = #ESQUISSE
DrawingMode(2)
Circle(ent_circle(n)\x1,ent_circle(n)\y1,ent_circle(n)\r1)
Delay(10)
Else
DrawingMode(0)
FrontColor(0,0,0)
EndIf
Circle(ent_circle(n)\x1,ent_circle(n)\y1,ent_circle(n)\r1)
StopDrawing()
EndProcedure

Procedure drawLocalPointAs(cx.w,cy.w)
If StartDrawing(WindowOutput())
FrontColor($ff,0,0)
LineXY(cx-2,cy,cx+2,cy)
LineXY(cx,cy-2,cx,cy+2)
FrontColor(0,0,0)
StopDrawing()
EndIf
EndProcedure

DisableDebugger

If OpenWindow(1,0,0,WinW,WinH,#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget, "Draw86")
If CreateGadgetList(WindowID())
ButtonGadget(#BUT_LINE,0,0,50,20,"Ligne")
ButtonGadget(#BUT_CIRCLE,55,0,50,20,"Cercle")
TextGadget(#INFO,10,WindowHeight()-20,WindowWidth(),18,"")
EndIf


Repeat
Mx = WindowMouseX()-4 : My = WindowMouseY()-22

;Debug "FlagDraw :"+Str(FlagDraw )
Debug "Mx:"+Str(Mx)+" X1:"+Str(ent_circle(nb_ent)\x1)

EventID.l = WaitWindowEvent()
Select EventID
Case #WM_LButtonUp
Select FlagDraw
Case #ENT_LINE ; 1er point de la ligne
ent_Line(nb_ent)\x1 = Mx : ent_Line(nb_ent)\y1 = My
drawLocalPointAs(ent_Line(nb_ent)\x1,ent_Line(nb_ent)\y1)
FlagDraw = #ENT_LINE +1
Case #ENT_LINE +1 ; 2ème point de la ligne
ent_Line(nb_ent)\x2 = Mx : ent_Line(nb_ent)\y2 = My
drawLocalPointAs(ent_Line(nb_ent)\x2,ent_Line(nb_ent)\y2)
drawLocalLineAt(nb_ent,#DEFINITIF)
FlagDraw = #ENT_LINE
;nb_ent+1

Case #ENT_CIRCLE
ent_circle(nb_ent)\x1 = Mx : ent_circle(nb_ent)\y1 = My
drawLocalPointAs(ent_circle(nb_ent)\x1,ent_circle(nb_ent)\y1)
FlagDraw = #ENT_CIRCLE +1
Case #ENT_CIRCLE+1
If Mx>ent_circle(nb_ent)\x1
ent_circle(nb_ent)\r1=Mx-ent_circle(nb_ent)\x1
Else
ent_circle(nb_ent)\r1=ent_circle(nb_ent)\x1-Mx
EndIf
drawLocalCircleAt(nb_ent,#DEFINITIF)
drawLocalPointAs(ent_circle(nb_ent)\x1,ent_circle(nb_ent)\y1)
FlagDraw = #ENT_CIRCLE
;nb_ent+1

EndSelect

Case #WM_MOUSEMOVE
Select FlagDraw
Case #ENT_LINE +1 ; 2ème point de la ligne
ent_Line(nb_ent)\x2 = Mx : ent_Line(nb_ent)\y2 = My
drawLocalLineAt(nb_ent,#ESQUISSE)

Case #ENT_CIRCLE+1
If Mx>ent_circle(nb_ent)\x1
ent_circle(nb_ent)\r1=Mx-ent_circle(nb_ent)\x1
Else
ent_circle(nb_ent)\r1=ent_circle(nb_ent)\x1-Mx
EndIf
drawLocalCircleAt(nb_ent,#ESQUISSE)

EndSelect


Case #PB_EventGadget
Select EventGadgetID()
Case #BUT_LINE
FlagDraw = #ENT_LINE
Case #BUT_CIRCLE
FlagDraw = #ENT_CIRCLE
EndSelect

Case #PB_EventRepaint
ResizeGadget(#INFO,10,WindowHeight()-20,WindowWidth(),18)

Case #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1

EndSelect

SetGadgetText(#INFO,"X:"+Str(Mx)+" Y:"+Str(My)+" "+A$)

Until Quit = 1
EndIf

Posted: Sat May 17, 2003 6:53 pm
by J. Baker
thanks, that's a start. i had to change line 147 to this
ResizeGadget(#INFO,10,WindowHeight(),-20,WindowWidth())
in order for it to work though.

Posted: Sat May 17, 2003 7:36 pm
by patrick88
the exact line is :

Code: Select all

ResizeGadget(#INFO,10,WindowHeight()-20,WindowWidth(),18)
:wink:

Posted: Sat May 17, 2003 7:54 pm
by Andre
patrick88 wrote:the exact line is :
Better you had set the code flag in your post before.... :lol:
(You can still do this anyway.)