0 / 0 / 0
Регистрация: 27.02.2015
Сообщений: 37
|
|
1
|
Перемещение Image
25.04.2015, 11:03. Показов 1527. Ответов 1
Нужно,чтобы шашки перемещались.
Файл cpp
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
| //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <pngimage.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "pngextra"
#pragma link "pngimage"
#pragma package(smart_init)
#pragma link "pngimage"
#pragma resource "*.dfm"
#define dyn_count 12
TForm1 *Form1;
TImage *dynImages[dyn_count];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
int pushedId = -1;
int x0, y0;
bool move;
void __fastcall TForm1::N8Click(TObject *Sender)
{
Form1->N8->Checked = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N9Click(TObject *Sender)
{
Form1->N9->Checked = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
for (int i = 2; i < dyn_count; i++)
{
dynImages[i] = new TImage(this);
dynImages[i]->Parent = this;
dynImages[i]->Tag = i;
dynImages[i]->OnMouseDown = XXX_MouseDown;
dynImages[i]->OnMouseUp = XXX_MouseUp;
dynImages[i]->OnMouseMove = XXX_MouseMove;
dynImages[i]->Cursor = crHandPoint;
}
Timer1->Enabled=true;
Form1->Color = StringToColor("0xFFFAFA");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::XXX_MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
pushedId = ((TImage*)Sender)->Tag;
move=true;
x0=X;
y0=Y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::XXX_MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if(move)
{
dynImages[pushedId]->Left += X - x0;
dynImages[pushedId]->Top += Y - y0;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::XXX_MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
move = false;
}
//--------------------------------------------------------------------------- |
|
Файл h
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
| //---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Menus.hpp>
#include <jpeg.hpp>
#include <DBGrids.hpp>
#include <Grids.hpp>
#include <Buttons.hpp>
#include "pngimage.hpp"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
TMainMenu *MainMenu1;
TImage *Image2;
TMenuItem *N1;
TMenuItem *N2;
TMenuItem *N3;
TMenuItem *N4;
TMenuItem *N5;
TMenuItem *N6;
TMenuItem *N7;
TMenuItem *N8;
TMenuItem *N9;
TMenuItem *N10;
TMenuItem *N11;
TMenuItem *N12;
TMenuItem *N13;
TComboBox *ComboBox1;
TDBGrid *DBGrid1;
TLabel *Label1;
TMemo *Memo1;
TLabel *Label2;
TTimer *Timer1;
TLabel *Label3;
TSpeedButton *SpeedButton1;
TSpeedButton *SpeedButton2;
TImage *Image3;
TImage *Image4;
TImage *Image5;
TImage *Image6;
TImage *Image7;
TImage *Image8;
TImage *Image9;
TImage *Image10;
TImage *Image11;
TImage *Image12;
TImage *Image13;
void __fastcall N8Click(TObject *Sender);
void __fastcall N9Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall XXX_MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall XXX_MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall XXX_MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif |
|
0
|