public void KeyDown(object sender, KeyEventArgs e) { // NOTE: The only way for cursor key events (up,down,left,right) // to make it to this function is for the main form to implement // the following: // // protected override bool ProcessDialogKey ( Keys keyData ) // // and explicitly invoke this KeyDown() method with the // an appropriately formed KeyEventArgs instance. // ALSO, the KeyPreview property of the main Form must be set to // 'true' for that override method to be called. STUserInterface.HandleKeyPress ( STEngine.GetMainForm( ).mGRControl.GetGR( ), STEngine.GetMainForm( ).Handle, 0, 0, STEngine.GetGame( ), e.KeyCode, e.Shift, e.Control ); }
public void Paint(object sender, PaintEventArgs e) { if (null == sender) { return; } if (false == (sender is GRControl)) { return; } GRControl grControl = (sender as GRControl); GR gr = grControl.GetGR( ); int clientWidth = grControl.ClientRectangle.Width; int clientHeight = grControl.ClientRectangle.Height; if (clientWidth <= 0) { clientWidth = 1; } if (clientHeight <= 0) { clientHeight = 1; } // Viewport gr.glViewport(0, 0, clientWidth, clientHeight); // Clear the viewport gr.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gr.glClear(GR.GL_COLOR_BUFFER_BIT | GR.GL_DEPTH_BUFFER_BIT); // Basic rendering conditions gr.glEnable(GR.GL_DEPTH_TEST); gr.glDepthFunc(GR.GL_LEQUAL); gr.glEnable(GR.GL_CULL_FACE); gr.glCullFace(GR.GL_BACK); gr.glFrontFace(GR.GL_CCW); gr.glMatrixMode(GR.GL_PROJECTION); gr.glLoadIdentity( ); gr.gluOrtho2D(0.0, (double)clientWidth, 0.0, (double)clientHeight); gr.glMatrixMode(GR.GL_MODELVIEW); gr.glLoadIdentity( ); // TETRIS GAME ITERATION STUserInterface.PerformGameIterations ( STEngine.GetGame( ), grControl.GetPreviousFrameDurationSeconds( ) ); // TETRIS GAME DRAWING System.Drawing.Point controlRelativePoint = grControl.PointToClient(Cursor.Position); int clientRelativeCursorX = controlRelativePoint.X; int clientRelativeCursorY = controlRelativePoint.Y; STGameDrawing.DrawScreen ( clientWidth, clientHeight, clientRelativeCursorX, clientRelativeCursorY, gr, STEngine.GetGame( ), STEngine.GetConsole( ) ); // Flush all the current rendering and flip the back buffer to the front. gr.wglSwapBuffers(grControl.GetHDC( )); }