1- using Silk . NET . Maths ;
1+ using Silk . NET . GLFW ;
2+ using Silk . NET . Input ;
3+ using Silk . NET . Maths ;
24using Silk . NET . OpenGL ;
35using Silk . NET . Windowing ;
6+ using Silk . NET . Windowing . Glfw ;
47
58namespace clmath ;
69
@@ -38,8 +41,8 @@ public sealed class GraphWindow : IDisposable
3841
3942 private uint ax_vao ;
4043 private uint ax_vbo ;
41- private readonly double scaleX = 15 ;
42- private readonly double scaleY = 6 ;
44+ private double scaleX = 15 ;
45+ private double scaleY = 6 ;
4346 private uint shaders ;
4447 private readonly Component [ ] x ;
4548
@@ -48,7 +51,7 @@ static GraphWindow()
4851 AssemblyDir = new FileInfo ( typeof ( GraphWindow ) . Assembly . Location ) . Directory ! ;
4952 }
5053
51- public GraphWindow ( params Component [ ] fx )
54+ public unsafe GraphWindow ( params Component [ ] fx )
5255 {
5356 if ( fx . Length > maxFuncs )
5457 {
@@ -58,7 +61,6 @@ public GraphWindow(params Component[] fx)
5861
5962 this . fx = fx . ToList ( ) ;
6063 window = Window . Create ( WindowOptions . Default ) ;
61- window . Title = "2D Graph" ;
6264
6365 var fxn = fx . Length ;
6466 ctx = new MathContext [ fxn ] ;
@@ -73,14 +75,35 @@ public GraphWindow(params Component[] fx)
7375 ctx [ i ] . var [ key ] = x [ i ] = new Component { type = Component . Type . Num , arg = ( double ) 0 } ;
7476 }
7577
78+ window . Title = "2D Graph" ;
7679 window . Load += Load ;
7780 window . FramebufferResize += Resize ;
7881 window . Render += Render ;
7982 window . Closing += Dispose ;
83+ window . Initialize ( ) ;
84+ foreach ( var keyboard in window . CreateInput ( ) . Keyboards )
85+ keyboard . KeyDown += KeyDown ;
8086 window . Run ( ) ;
8187 }
8288
89+ private void KeyDown ( IKeyboard keyboard , Key key , int _ )
90+ {
91+ if ( key == Key . Escape )
92+ window . Close ( ) ;
93+ const double delta = 0.5 ;
94+ if ( key == Key . Keypad2 && scaleY > delta )
95+ scaleY -= delta ;
96+ if ( key == Key . Keypad8 )
97+ scaleY += delta ;
98+ if ( key == Key . Keypad4 && scaleX > delta )
99+ scaleX -= delta ;
100+ if ( key == Key . Keypad6 )
101+ scaleX += delta ;
102+ InitGraphCurve ( ) ;
103+ }
104+
83105 private IWindow window { get ; }
106+
84107 private GL gl { get ; set ; }
85108
86109 public void Dispose ( )
0 commit comments