public WindowOpenTk( IDiscardableNode parentDiscardable, IWindowArgs args, InputOpenTk input, Action onClose) { this.discardableImpl_ = parentDiscardable.CreateChild(); this.discardableImpl_.OnDiscard += _ => this.Discard_(); var initialWidth = args.Dimensions.Width; var initialHeight = args.Dimensions.Height; this.nativeWindow_ = new NativeWindow(initialWidth, initialHeight, "SimpleGame", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default); this.AttachToNativeInputEvents_(input); this.nativeWindow_.Closed += (_, _2) => onClose(); var windowInfo = this.nativeWindow_.WindowInfo; this.glContext_ = new GraphicsContext(GraphicsMode.Default, windowInfo, 1, 0, GraphicsContextFlags.Default); this.glContext_.MakeCurrent(windowInfo); ((IGraphicsContextInternal)this.glContext_).LoadAll(); //this.glContext_.SwapInterval = 0; this.windowBoundingBox_ = new MutableBoundingBox <int>(0, 0, initialWidth, initialHeight); var windowTopLeft = this.windowBoundingBox_.TopLeft; var windowDimensions = this.windowBoundingBox_.Dimensions; this.nativeWindow_.Move += (_, _2) => (windowTopLeft.X, windowTopLeft.Y) = (this.nativeWindow_.X, this.nativeWindow_.Y); this.nativeWindow_.Resize += (_, _2) => (windowDimensions.Width, windowDimensions.Height) = (this.nativeWindow_.Width, this.nativeWindow_.Height); this.viewport_.Push(new AggregationBoundingBox <int>( new ImmutableVector2 <int>(0, 0), this.windowBoundingBox_.Dimensions)); }
private void AttachToNativeInputEvents_(InputOpenTk input) { var keyboard = input.Keyboard; this.nativeWindow_.KeyDown += (_, args) => keyboard[KeyToKeyIdConverterOpenTk.Convert(args.Key)].Down(); this.nativeWindow_.KeyUp += (_, args) => keyboard[KeyToKeyIdConverterOpenTk.Convert(args.Key)].Up(); var cursor = input.Cursor; this.nativeWindow_.MouseMove += (_, args) => (cursor.Position.X, cursor.Position.Y) = (args.X, args.Y); this.nativeWindow_.MouseEnter += (_, _2) => cursor.Window = this; this.nativeWindow_.MouseLeave += (_, _2) => { if (cursor.Window == this) { cursor.Window = null; } }; this.nativeWindow_.MouseDown += (_, args) => { if (args.Button == MouseButton.Left) { cursor.LeftButton.Down(); } else if (args.Button == MouseButton.Right) { cursor.RightButton.Down(); } }; this.nativeWindow_.MouseUp += (_, args) => { if (args.Button == MouseButton.Left) { cursor.LeftButton.Up(); } else if (args.Button == MouseButton.Right) { cursor.RightButton.Up(); } }; }