//--------------------------------------------------------------------------- // CHESS FOUNDATION // // Each piece is a bitmap image (.bmp 36 by 36 pixels) // The chessboard is a JPEG image (.jpg 368 by 368 pixels) // The top left square starts at pixel 40, 40 and ends at pixel 76, 76 // // Top and Left appear at these eight positions: // 1 2 3 4 5 6 7 8 // 40 76 112 148 184 220 256 292 // // OnKeyDown event belongs to one or more Edits if they are enabled // If all Edits are disabled OnKeyDown belongs to the Form. //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //----------------------------------------------------------------- VARIABLES int object; //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { switch (object) { case 0: { if (Key == VK_UP) ShapeSquare->Top--; if (Key == VK_DOWN) ShapeSquare->Top++; if (Key == VK_LEFT) ShapeSquare->Left--; if (Key == VK_RIGHT) ShapeSquare->Left++; EditX->Text = ShapeSquare->Left; EditY->Text = ShapeSquare->Top; break; } case 1: { if (Key == VK_UP) ImageX->Top--; if (Key == VK_DOWN) ImageX->Top++; if (Key == VK_LEFT) ImageX->Left--; if (Key == VK_RIGHT) ImageX->Left++; EditX->Text = ImageX->Left; EditY->Text = ImageX->Top; break; } case 2: { if (Key == VK_UP) ImageMagenta->Top--; if (Key == VK_DOWN) ImageMagenta->Top++; if (Key == VK_LEFT) ImageMagenta->Left--; if (Key == VK_RIGHT) ImageMagenta->Left++; EditX->Text = ImageMagenta->Left; EditY->Text = ImageMagenta->Top; break; } } } //--------------------------------------------------------------------------- void __fastcall TForm1::EditXKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_UP) { ShapeSquare->Top--; } if (Key == VK_DOWN) { ShapeSquare->Top++; } if (Key == VK_LEFT) { ShapeSquare->Left--; } if (Key == VK_RIGHT) { ShapeSquare->Left++; } EditX->Text = ShapeSquare->Left; EditY->Text = ShapeSquare->Top; } //--------------------------------------------------------------------------- void __fastcall TForm1::EditYKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_UP) { ImageX->Top--; } if (Key == VK_DOWN) { ImageX->Top++; } if (Key == VK_LEFT) { ImageX->Left--; } if (Key == VK_RIGHT) { ImageX->Left++; } EditX->Text = ImageX->Left; EditY->Text = ImageX->Top; } //--------------------------------------------------------------------------- void __fastcall TForm1::ShapeSquareMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { object = 0; } //--------------------------------------------------------------------------- void __fastcall TForm1::ImageXClick(TObject *Sender) { object = 1; } //--------------------------------------------------------------------------- void __fastcall TForm1::ImageMagentaClick(TObject *Sender) { object = 2; } //---------------------------------------------------------------------------