Forum > General
Using the Mouse Wheel to Zoom
J-G:
Thanks for the input @jamie but since I only need to know the magnification factor - not width/height - I don't really see where your code has a benefit.
jamie:
You can't see the benefit ?
With only one line of code, I reduce the + or - down to a -1 or 1 which can be used following without checking for the < 1 and > 0 etc.
You can use your MAG multiplier afterwards on that same value.
Also, you should test the size of the DeltaWheel because it can change, and your program will be left acting like a clown. There is an API for that too.
Do whatever makes your boat float as I say.
dje:
Why not just add WheelDelta to TrackBar Position? First set the TrackBar's max to 1000. Then:
--- 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";}};} ---procedure TForm1.Panel1MouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: integer; MousePos: TPoint; var Handled: boolean);begin TrackBar1.Position := TrackBar1.Position + WheelDelta;end;
Setting TrackBar Position via code will trigger a OnChange event. Inside TTrackBar OnChange, calculate the percentage using:
--- 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";}};} ---TrackBar1.Position * 100 div TrackBar1.Max
J-G:
--- Quote from: jamie on August 14, 2022, 02:27:22 am ---You can't see the benefit ?
With only one line of code, I reduce the + or - down to a -1 or 1 which can be used following without checking for the < 1 and > 0 etc.
You can use your MAG multiplier afterwards on that same value.
Also, you should test the size of the DeltaWheel because it can change, and your program will be left acting like a clown. There is an API for that too.
Do whatever makes your boat float as I say.
--- End quote ---
Thanks @jamie but I'm obviously being a numbskull :-[ - - -
I've just tried what I think you are suggesting :
--- 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";}};} ---procedure TForm1.DisplayMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);begin WheelDelta := Sign(WheelDelta)+Abs(WheelDelta)-120; Mag := Mag*WheelDelta; if Mag < 0.1 then Mag := 0.1; if Mag > MaxZoom then Mag := MaxZoom; Zoom.Position := Round(Mag*100); Calc(self);end;...but the result of that is again 'Zooming Out' puts 'Mag' at minimum only.
I also don't understand what you mean by "test the size of the DeltaWheel" - Unless you are saying that 120 just happens to be the figure that my current mouse has and is not an industry standard - perfectly possible of course, I haven't previously had a need to investigate such things.
J-G:
@derek.john.evans
Depending upon many factors, the Maximum Zoom changes, and I currently set the Max TTrack Value once I know what the MaxZoom is :-
--- 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";}};} --- MaxZoom := 267/(Gear.OD*Scale-Gear.PCD*Scale)-0.1; Form1.Zoom.Max := Round(MaxZoom*100);
Gear.OD & Gear.PCD are variable (not cosistently) but the display space available between them is a maximum of 267px (on an 800px Panel). I could of course make it even more 'general' by using 'Panel.Height DIV 3' rather than the specific 267 - then I could vary the size of the Panel and it would still 'work' ;D
Navigation
[0] Message Index
[*] Previous page