Linking graphically two gadgets .[Resolved]

Just starting out? Need help? Post your questions and find answers here.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: Linking graphically two gadgets .[Resolved]

Post by RASHAD »

KCC Hi
1- Press keyboard key 1 or 2 or 3 or 4 to choose the type of the link
2- Resize the gadget using mouse
3- You can use Sparkie dynamic move to move the link

Code: Select all

Enumeration
#Fenetre
#Image_0
#Image_1
#FondBlanc
#ImageGadget
EndEnumeration

Hauteur.i = 200
Largeur.i = 400
CreateImage(#Image_0, Largeur,Hauteur) 
CreateImage(#Image_1, Largeur,Hauteur)

Global flag
flag = 1

Procedure DessineFleche(x, y)
If x > 400
   x = 400
ElseIf x < 35
    x = 35
EndIf
If y > 200
   y = 200
ElseIf y < 35
    y = 35
EndIf
  
StartDrawing(ImageOutput(#Image_1))
  DrawImage(ImageID(#Image_0), 0, 0)
  If flag = 1
    LineXY(10, 10, x - 10, 10, RGB(226, 23, 29))
    LineXY(x - 10, 10, x - 10, y - 10, RGB(226, 23, 29)) ; Verticale
    LineXY(x - 10, y - 10, x - 15, y - 20, RGB(226, 23, 29))
    LineXY(x - 10, y - 10, x - 5, y - 20, RGB(226, 23, 29))
  ElseIf flag = 2
    LineXY(10, y - 10, x - 10, y - 10, RGB(226, 23, 29))
    LineXY(x-10, 10,x-10, y - 10, RGB(226, 23, 29)) ; Verticale
    LineXY(x - 10, 10, x - 15, 20, RGB(226, 23, 29))
    LineXY(x - 10, 10, x - 5, 20, RGB(226, 23, 29))
  ElseIf flag = 3
    LineXY(10,10, x - 10, 10, RGB(226, 23, 29))
    LineXY(10, 10, 10, y - 10, RGB(226, 23, 29)) ; Verticale
    LineXY(10, y - 10, 15, y - 20, RGB(226, 23, 29))
    LineXY(10, y - 10, 5, y - 20, RGB(226, 23, 29))
  ElseIf flag = 4
    LineXY(10, y-10, x - 10, y-10, RGB(226, 23, 29))
    LineXY(10, 10, 10, y - 10, RGB(226, 23, 29)) ; Verticale
    LineXY(10, 10, 15, 20, RGB(226, 23, 29))
    LineXY(10, 10, 5, 20, RGB(226, 23, 29))
  EndIf
StopDrawing()

      ResizeImage(#Image_1, x, y)
      ResizeImage(#Image_0, x, y)

SetGadgetState(#ImageGadget,ImageID(#Image_1))

EndProcedure

OpenWindow(#Fenetre, 417, 181, 600, 500, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
ImageGadget(#ImageGadget, 100, 100, 0, 0, ImageID(#Image_1))
StartDrawing(ImageOutput(#Image_0))
Box(0,0,400,200, RGB(255, 255, 255))
StopDrawing() 
DessineFleche(Largeur, Hauteur)
      
Repeat  

Evenement = WaitWindowEvent()

  Select Evenement
   
   Case #WM_MOUSEMOVE
   
      MouseX = WindowMouseX(#Fenetre)
      MouseY = WindowMouseY(#Fenetre)
      
      If GetAsyncKeyState_(#VK_LBUTTON) And MouseX > GadgetX(#ImageGadget) And MouseY > GadgetY(#ImageGadget)          
      
      DessineFleche(mousex - GadgetX(#ImageGadget), mousey - GadgetY(#ImageGadget))
            
      EndIf
      
   Case #WM_KEYDOWN
       If GetAsyncKeyState_(49) & $8000 = 32768
          flag = 1
        ElseIf GetAsyncKeyState_(50) & $8000 = 32768
          flag = 2
        ElseIf GetAsyncKeyState_(51) & $8000 = 32768
          flag = 3
        ElseIf GetAsyncKeyState_(52) & $8000 = 32768
          flag = 4
       EndIf
       ResizeImage(#Image_1,Largeur, Hauteur)
       ResizeImage(#Image_0,Largeur, Hauteur)
       DessineFleche(Largeur, Hauteur)  

   EndSelect

Until Evenement = #PB_Event_CloseWindow
Have fun
I hope that this is Ok for you
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Linking graphically two gadgets .[Resolved]

Post by Kwai chang caine »

Yes thank RASHAD 8)

It's already a good solution 8)
I have not think to resize simply the arrow by the other size :roll:

It's a good idea :D
I prefer to size the arrow by the end, but it's a solution.

Your solution is better that mine...because i have no solution :lol:
If i not found how resize it by the end, i use your solution :wink:

I thank you very much, for your precious help
ImageThe happiness is a road...
Not a destination
Post Reply