creating a knob control ?

Blitz3D Forums/Blitz3D Programming/creating a knob control ?

dman(Posted 2010) [#1]
I want to know if the code is good or what I am doing wrong.

trying to get it to read a variable that would carry the value from the last click . in other words save the mouse y location and then update that location with a new one.

just look at the code to see what i am talking about and let me know if I am in the right track.




Midimaster(Posted 2010) [#2]
I'm not sure, that I understood you, and my english is not so good, but I can see, what the problem is:

You first have to calculate a relativ MouseY (Difference between first Click and following moves of the Mouse). There for you check MouseHit(), which only apears 1x each click and store the MouseY() into FirstMouseY%.

The you know the difference between this first position and actual MouseY() and store it in MouseDiff%. This you can add to the last knob position Range% to paint the current knob position.

When release the Mouse, you have to add this value MouseDiff% to Range%, make MouseDiff%=0 and FirstMouseY%=0 for the next event.

While Not KeyHit (1)

	mx = MouseX()
	my = MouseY()   
    mb = MouseDown(1)

	If MouseHit(1) Then
		FirstMouseY=My
	ElseIf (mb>0) And (mx > x_range-20) And (mx < x_range+20)
		MouseDiff = My - FirstMouseY
		RotateEntity knob,0,0,range+MouseDiff
	 Else 
		Range=range+MouseDiff
		MouseDiff=0
		FirstMouseY=0
	 EndIf
		
	RenderWorld
		Text 100,100, " Mouse relativ: " + MouseDiff + "    Old Range: " + Range + "  New Range:" + (range+MouseDiff)
	 Delay 15
	Flip 0
	
Wend


note 1: to save energy and not to stress the processor it is always recomended to add a Delay 15 and a Flip 0 during the testing phase.

note 2: You should use names for variables that say more about the use of the variable!

sw, mr, mm=r ???

does not say anything and it is difficult to help you.

mx, my, mb, Range

...maybe easy to remember for your, but XMouse%, YMouse%, MouseButton% and KnobValue% helps third person to have a fast overview about the codelines.


dman(Posted 2010) [#3]
HI, the code works great. Thank you. but there is another problem I can not get a value to set a range, a MIN and MAX. where it will stop rotating.

Then have a value to use from the MIN and MAX like 0 to 100.


Midimaster(Posted 2010) [#4]
But thats easy...

you have to check it in the code part...

...
    MouseDiff = My - FirstMouseY
    RotateEntity knob,0,0,range+MouseDiff
...  


I would suggest that 270° of max turn radius looks like a typical knob. So you have to take care that the sum of Range% and MouseDiff% does not run out of 0...270:
...
    MouseDiff = My - FirstMouseY
    If (MouseDiff+Range)>270 then
        MouseDiff=270-Range
    ElseIf (MouseDiff+Range)<0 then
        MouseDiff=-Range
    Endif
    RotateEntity knob,0,0,range+MouseDiff
...
  


The "value" of the knob is ValueMin + (ValueMax-ValueMin)/270*Range

For exampel, if you wish to have a knob for values between 40 and 140:

...
     Endif
    RotateEntity knob,0,0,range+MouseDiff
    KnobValue=40 + (140-40)/270.0*Range
...
  


Therefore I would suggest to declare the variables as FLOAT:

KnobValue#, Range#, etc...