Beizer Curve - Need some advice to make it interactive

Everything else that doesn't fall into one of the other PB categories.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Beizer Curve - Need some advice to make it interactive

Post by ricardo »

Hi,

Im with drawing again, now drawig a beizer curve (if you don't know what it is run the code and you will recognize it).

Code: Select all

Structure PointAPI
x.l
y.l
EndStructure

Dim P.PointAPI(3)

Procedure CreateBezier() 
StartDrawing(WindowOutput())
Red = RGB(255,0,0)
Blue = RGB(0,0,255)
P(0)\x = 0
P(0)\y = 0
P(1)\x = 80
P(1)\y = 10
P(2)\x = 150
P(2)\y = 70
P(3)\x = 130
P(3)\y = 230

LineXY(P(0)\x+10,P(0)\y+10,P(1)\x+10,P(1)\y+10,Blue)
Box(P(0)\x+10,P(0)\y+10, 4, 4,Red) 
Box(P(1)\x+10,P(1)\y+10, 4, 4,Red)

LineXY(P(2)\x+10,P(2)\y+10,P(3)\x+10,P(3)\y+10,Blue)
Box(P(2)\x+10,P(2)\y+10, 4, 4,Red) 
Box(P(3)\x+10,P(3)\y+10, 4, 4,Red)
hDC = GetDC_(GadgetID(1)) 
PolyBezier_(hDC,@P(),4)
StopDrawing()
EndProcedure


If OpenWindow(0,100,150,450,300,#PB_Window_SystemMenu,"Create Beizer Curve")
  CreateGadgetList(WindowID())
  ImageGadget(1,10,10,255,255,LoadImage(0,""))
  ButtonGadget(3,300,140,50,25,"Curve")
  Repeat
    EventID=WaitWindowEvent()
    
    Select EventID
    
      Case #PB_EventGadget
        Select EventGadgetID()
            
          Case 3
            CreateBezier()

        EndSelect
    
    EndSelect
    
  Until EventID=#PB_EventCloseWindow
EndIf
Now i need 2 advises:

1.- I want to make it interactive, to let the user drag any of the 4 point to manipulate the curve ¿any idea of the best way to achieve it?

I need no flickering but need to save the result as BMP.

2.- I want to know all (or many) the points of the curve... :? ¿how to achieve it?

Thanks in advance if any BIG & charitative soul help me i will be greatefull forever :D
ARGENTINA WORLD CHAMPION
Magi
User
User
Posts: 25
Joined: Sun Apr 27, 2003 12:57 am
Location: Burlington, Canada

Post by Magi »

Ricardo:

Not exactly what you want, however, at some point you'll have to click and select the curve, for that you will need what is called " hit testing" so I thought you may be interested in the following docs:

http://msdn.microsoft.com/library/defau ... ttest2.asp

http://msdn.microsoft.com/library/defau ... vector.asp

I hope it helps and let me know if you find anything else, interesting subject :wink:

Marc 8)
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Magi wrote:Ricardo:

Not exactly what you want, however, at some point you'll have to click and select the curve, for that you will need what is called " hit testing" so I thought you may be interested in the following docs:

http://msdn.microsoft.com/library/defau ... ttest2.asp

http://msdn.microsoft.com/library/defau ... vector.asp

I hope it helps and let me know if you find anything else, interesting subject :wink:

Marc 8)
Hi,

Exactly what i was looking for!!!!!

The problem is to translate it to PB :?

Any idea?
ARGENTINA WORLD CHAMPION
Magi
User
User
Posts: 25
Joined: Sun Apr 27, 2003 12:57 am
Location: Burlington, Canada

Post by Magi »

ricardo wrote: Exactly what i was looking for!!!!!

The problem is to translate it to PB :?

Any idea?
If only I was that smart :? plus I don't speak any "C" :roll:

But this forum has a lot of "C Gurus"... :wink:

Marc 8)
Magi
User
User
Posts: 25
Joined: Sun Apr 27, 2003 12:57 am
Location: Burlington, Canada

Post by Magi »

Ricardo:

Just found some code in VB6. It's a 3K zip, if you want I can e-mail it to you direct.

Marc 8)
Cor
Enthusiast
Enthusiast
Posts: 124
Joined: Fri Apr 25, 2003 7:52 pm
Location: Netherlands
Contact:

Post by Cor »

@Ricardo,

Just curious,

Are you making some visual envelopes for editing sounds for a synth?
Cor de Visser

Registered PureBasic user

Author of ChordPlanet
Made with PureBasic
http://www.chordplanet.com
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Cor wrote:@Ricardo,

Just curious,

Are you making some visual envelopes for editing sounds for a synth?
Hi Cor,

No, im making some small app for manipulating some images and i want to be able to manipulate the bevel.

BTW, its not a bad idea about sounds!! :D :D Resolving the way to interact with the curve it can be used on many usefull ways!!
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Magi wrote:Ricardo:

Just found some code in VB6. It's a 3K zip, if you want I can e-mail it to you direct.

Marc 8)
Hi Magi,

I will be happy if you can send it to me. ricardoarias@yahoo.com

Thanks in advance :D :D :D
ARGENTINA WORLD CHAMPION
Magi
User
User
Posts: 25
Joined: Sun Apr 27, 2003 12:57 am
Location: Burlington, Canada

Post by Magi »

:!: Sent... Have fun :)
Tomcat
User
User
Posts: 15
Joined: Sat Apr 26, 2003 6:59 am
Location: Germany

Post by Tomcat »

Hello Ricardo,

if you want to know, how many points the bezier curve has, I think the easiest way is by creating the curve by yourself (so you can count the points and even set the accuracy). The hittest can also be done by yourself, since you know the coordinates of the points ;-)

I've already modified your code where the points are counted and where you're able to drag & drop the 4 points (the hittest is not accurate, but it gets the job done :-)

Code: Select all

Structure PointAPI 
x.l 
y.l 
EndStructure 

Dim P.PointAPI(4) 
P(0)\x = 0  :P(0)\y = 250
P(1)\x = 0  :P(1)\y = 0
P(2)\x = 250:P(2)\y = 0
P(3)\x = 250:P(3)\y = 250
    
Procedure CreateBezier()
  CreateImage(0,256,256)
  StartDrawing(ImageOutput())
    Box(0,0,256,256,RGB(160,160,160))
     
    Red = RGB(255,0,0) 
    Blue = RGB(0,0,255) 

    LineXY(P(0)\x,P(0)\y,P(1)\x,P(1)\y,Blue) 
    Box(P(0)\x,P(0)\y, 4, 4,Red) 
    Box(P(1)\x,P(1)\y, 4, 4,Red) 
    LineXY(P(2)\x,P(2)\y,P(3)\x,P(3)\y,Blue) 
    Box(P(2)\x,P(2)\y, 4, 4,Red) 
    Box(P(3)\x,P(3)\y, 4, 4,Red) 

    beziercount.w=2 ;+Start and Endpoint
    accuracy.f=(GetGadgetState(6)/100)
    u.f=0
    Repeat 
      xlast.f=x.f
      ylast.f=y.f
      x.f=p(0)\x*Pow((1-u),3)+p(1)\x*3*u*Pow((1-u),2)+p(2)\x*3*Pow(u,2)*(1-u)+p(3)\x*Pow(u,3)
      y.f=p(0)\y*Pow((1-u),3)+p(1)\y*3*u*Pow((1-u),2)+p(2)\y*3*Pow(u,2)*(1-u)+p(3)\y*Pow(u,3)
      If u.f>0
        LineXY(x,y,xlast,ylast)
      EndIf
      u.f+accuracy.f
      If u.f>1.0 And endpoint.b=0
        endpoint.b=1
        u.f=1.0
      EndIf
      If u.f>0.0 And u.f<1.0
        beziercount.w+1
      EndIf
    Until (u.f>1.0)
  StopDrawing()
  SetGadgetState(1,UseImage(0))
  SetGadgetText(4,"Bezier curve has "+Str(beziercount.w)+" Points")
EndProcedure

If OpenWindow(0,100,150,450,300,#PB_Window_SystemMenu,"Create Bezier Curve") 
  CreateGadgetList(WindowID())
  ImageGadget(1,10,10,256,256,LoadImage(0,""))
  ButtonGadget(3,300,140,100,25,"Reset Points")
  TextGadget(4,270,10,200,18,"")
  TextGadget(5,10,275,50,18,"Accuracy:")
  TrackBarGadget(6,60,270,206,30,1,50):SetGadgetState(6,10)
  
  createBezier()
  Repeat 
    EventID=WaitWindowEvent() 
    Select EventID
      Case #WM_LBUTTONDOWN
        leftmousebutton.b=1
      Case #WM_LBUTTONUP
        leftmousebutton.b=0
      Case #WM_MOUSEMOVE
        mousex=WindowMouseX()-15
        mousey=WindowMouseY()-33
        If leftmousebutton.b=0
          selectedPoint=-1
          For i=0 To 3
            If mousex>p(i)\x-5 And mousex<p(i)\x+5 And mousey>p(i)\y-5 And mousey<p(i)\y+5
              selectedPoint=i
            EndIf
          Next
          If selectedPoint<>-1
            setClassLong_(WindowID(),#GCL_HCURSOR,LoadCursor_(0,32649))
          Else
            setClassLong_(WindowID(),#GCL_HCURSOR,LoadCursor_(0,#IDC_ARROW))
          EndIf
        Else
          If selectedPoint<>-1
            P(selectedPoint)\x=mousex            
            P(selectedPoint)\y=mousey
            CreateBezier()
          EndIf
        EndIf        
      Case #PB_EventGadget 
        Select EventGadgetID() 
          Case 3          
            P(0)\x = 0  :P(0)\y = 250
            P(1)\x = 0  :P(1)\y = 0
            P(2)\x = 250:P(2)\y = 0
            P(3)\x = 250:P(3)\y = 250
            CreateBezier()
            leftmousebutton.b=0
          Case 6
            CreateBezier() 
            leftmousebutton.b=0
        EndSelect 
    EndSelect 
  Until EventID=#PB_EventCloseWindow
EndIf 
I hope this helps you a little bit.

Bye,
Tomek
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Tomcat wrote: I hope this helps you a little bit.
Wowwwwwww Its very very nice!!!

Only one question:

In XP the difference betwen the point and the place where it has to be drag it its different to win98 ¿any idea how to workout this?
ARGENTINA WORLD CHAMPION
Post Reply