Forum > Lazarus Extra Components
Working on BGRAKnob features
SandyG:
I think the ability for the knob to display a value string should not be part of the basic knob. It's seems more like something that could be a composite component based on the BGRAKnob.
That being said where do you envision the value to be displayed if part of the actual BGRAKnob code?
I think 2 of the modes might be the same, i.e., mode 1 Angle would be the same as Mode 3 since the baseline value is an Angle and the position in degrees is always respected by the Min/Max. The only way this might work is if the knob has a StartAngle, EndAngle for setting the angular range, and a MinValue, MaxValue property for a numeric range (either angle, number range, or percent). Have to think about this, makes things more complicated :)
As an example -
Right now if the Min was 30, the angle and setting the value of the knob can never go lower then 30 degrees or read lower then 30, however in the Percent mode 30 degs in this case would be returning a value of 0% since the knob is all the way off.
Sandy
--- Quote from: KodeZwerg on April 26, 2024, 12:53:36 am ---
--- Quote from: SandyG on April 26, 2024, 12:04:25 am ---Not sure what you mean by 'value display' as the third option, please explain, might be easy.
--- End quote ---
Sure, I can do that.
I was thinking about 3 different display modes, mode1 would display current position as angle (0° to 360°), mode2 as percent (0% to 100%), mode3 as value (min to max).
Maybe this gets the idea started:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TKnobDisplay = (kdNone, kdAngle, kdPercent, kdValue);A property, maybe "Display" that uses TKnobDisplay as type.
In your actual paint method do a simple "case FKnobDisplay of" to prepare the correct string value.
I hope I was clear enough to describe it.
--- End quote ---
KodeZwerg:
Actually you should have for such control 3 variable properties that deal with the logic.
1. Min = that value will be the lower bound, can be positive or negative
2. Max = that value will be the higher bound, must at least 1 value higher than Min
3. Pos = that value will be in range of Min and Max including Min or Max
those above will always work same way and brings live to a knob
kdValue = current Integer position within Min and Max
kdPercent = Min is the 0%, Max is the 100%, Pos be current float position within
kdAngle = Min is the 0°, Max is the 360°, Pos be current float position within
kdPercent and kdAngle needs to be calculated by normalization/mapping/spanning (however its called) and will always deliver a positive float.
kdValue can also be negative.
And my suggestion was, depends on the TKnobDisplay to prepare a string with the correct value and simple draw it on knob (i assume it got a canvas) or as a second "Pos"-Property
SandyG:
Yes, I think most of that is right on the money. I think the confusion for me is that the base control is not a Fixed angle, ie, the Min and Max, are really not quite right. That is, it sets the angular minimum and angular max where the knob starts and stops. I think most of the other controls like that fix the angular rotation at something like 30-330 degrees, then set the scale from that fixed range. I think that is what was confusing me.
I will have to think if it's worth it to fix the 'swing' of the knob, but I would rather not if possible. I do like the idea of a range, especially something like -1 to 1 stuff like that.
So I think to keep the adjustable start and stop angle as well as what you have described might need an additionally startAngle and stopAngle properties besides the range properties. I may be making it too complicated at this point :)
Will think about if for a bit and see what I come up with
Thanks for all your input so far!
Sandy
--- Quote from: KodeZwerg on April 26, 2024, 04:20:44 am ---Actually you should have for such control 3 variable properties that deal with the logic.
1. Min = that value will be the lower bound, can be positive or negative
2. Max = that value will be the higher bound, must at least 1 value higher than Min
3. Pos = that value will be in range of Min and Max including Min or Max
those above will always work same way and brings live to a knob
kdValue = current Integer position within Min and Max
kdPercent = Min is the 0%, Max is the 100%, Pos be current float position within
kdAngle = Min is the 0°, Max is the 360°, Pos be current float position within
kdPercent and kdAngle needs to be calculated by normalization/mapping/spanning (however its called) and will always deliver a positive float.
kdValue can also be negative.
And my suggestion was, depends on the TKnobDisplay to prepare a string with the correct value and simple draw it on knob (i assume it got a canvas) or as a second "Pos"-Property
--- End quote ---
SandyG:
OK,
Did a first cut of the enhanced BGRA knob.
Added a KnobType to define the following
ktAngle - Returns number in a default range of 0-360
ktPercent - Retuns number in a of 0-100
ktRange - Returns numbers in any range as specified 0 to 100, 0 to 360, -5 to 10, -100 to 100, etc. May remove ktAngle and ktPercent as this does the same
ktSector - Changes knob into a 'sectored' type of switch. You can specify the number of sectors from 1 to 255
As mentioned ktAngle and ktPercent may be really useless since ktRange does the same, but allows for some presets I guess (Feedback needed)
NOTE : The range of the knob that is returned in the Value property is different from the StartAngle and EndAngle. So no matter what the StartAngle and StopAngle are set at, the range set by MinValue and MaxValue will always be returned.
An example might be a knob that starts at 0 and ends at 180 degrees, but can return a range of -100 to 0
MinValue/MaxValue Range is a returned value mapped across the span of the knob
StartAngle EndAngle are in degrees of how the knob will be set up.
Added a bunch of missing events, the original only had onValueChange.
Added Mouse wheel support for all knob types with an option to allow the mouse wheel to go past the ends of scale (wrap)
Added a 'Slow Snap' feature that will keep the position of the knob more stable when moving the mouse near endpoints and wrapping around
Also with some simple tricks the knob can be made to be continuous spinner wheel, but you will have to figure out how to track the way you need. Possibly may need to expose a new event for this, but not sure. You can try this with a StartAngle = 0 and EndAngle = 359.999
The attached zip has the sample project that can test a lot of the features, pretty self explanatory, look at the code if you need to know!
This is just the first (what I would say) working cut where things seem to work well, or so I think :)
To do build the project, it's a bit of a hack since I don't have the files set up correctly in github, so for now, unzip the file into a clean directory where you can build Lazarus projects, look in the folder for the BGRAKnob directory. You will need to rename you existing BGRAKnob.pas in the components directory (where ever that may be installed) and copy the BGRAKnob.pas into that directory.
Compile the BGRA Controls via the package manager, and then install (will rebuild Lazarus).
Testing was done with BGRA Controls v9.0 on Win11. Will test on Linux shortly
At this point bring up the project and compile. It might work...
A little more clean and testing is in order but getting close.
Sandy
lainz:
Hi, my first question is if this is retro compatible with the original knob and if it's not sure to change the name (if you already didn't do)..
You wish to add this to BGRAControls?
Navigation
[0] Message Index
[#] Next page
[*] Previous page