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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
| //---------------------------------------------------------------------------
#include <vcl.h>
#include <vcl\Math.hpp>
#include <vector>
#pragma hdrstop
#include "form.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
Graphics::TBitmap *bmpOriginal=new Graphics::TBitmap;
Graphics::TBitmap *bmpCopy = new Graphics::TBitmap;
Graphics::TBitmap * Bitmap = new Graphics::TBitmap;
std::vector <AnsiString> ImgList;
std::vector <AnsiString>::iterator it;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
NEdit->Clear();
if (WeAreAlone("I See You"));
else
{
ShowMessage("Ïðîãðàììà óæå çàïóùåíà");
exit(0);
}
k = 1;
num = 0;
SShow = false;
}
//---------------------------------------------------------------------------
//I can't explain how it work but its work.Well enough))
void TMainForm::ScanDirs( AnsiString Dir, TTreeNode* node )
{
Dir = IncludeTrailingPathDelimiter( Dir );
TSearchRec sr;
if ( !FindFirst( Dir + "*.*", faAnyFile, sr))
{
bool found = true;
while( found )
{
if ( sr.Attr & faDirectory && sr.Name != "." && sr.Name != ".." )
{
TTreeNode* pnode = DirTree->Items->AddChild( node, sr.Name );
ScanDirs( Dir + sr.Name, pnode );
}
found = FindNext( sr ) == 0;
}
}
FindClose(sr);
}
//---------------------------------------------------------------------------
//Function that search any files with *.bmp in this folder
void TMainForm::ScanFiles( AnsiString Dir )
{
Dir = IncludeTrailingPathDelimiter( Dir );
FileList->Items->BeginUpdate();
FileList->Items->Clear();
TSearchRec sr;
if ( !FindFirst( Dir + "*.bmp", 0, sr))
{
do
{
TListItem* item = FileList->Items->Add();
item->Caption = sr.Name;
item->SubItems->Add( IntToStr( sr.Size ) / 1024);
}while( FindNext( sr ) == 0 );
}
FindClose(sr);
FileList->Items->EndUpdate();
}
//---------------------------------------------------------------------------
//Directory tree with image
void __fastcall TMainForm::DirTreeChange(TObject *Sender, TTreeNode *Node)
{
if( DirTree->Selected )
{
ScanFiles( DirTree->Selected->Text );
}
}
//---------------------------------------------------------------------------
//If file in filelist selected then open this file
void __fastcall TMainForm::FileListSelectItem(TObject *Sender,
TListItem *Item, bool Selected)
{
if( Selected && Item )
{
Image->Picture->LoadFromFile( DirTree->Selected->Text + "\\" + Item->Caption );
bmpOriginal->LoadFromFile( DirTree->Selected->Text + "\\" + Item->Caption );
bmpCopy->LoadFromFile( DirTree->Selected->Text + "\\" + Item->Caption );
bmpOriginal->SaveToFile(("C:\\"+ExtractFileName(OPDialog->FileName) ).c_str());
}
}
//---------------------------------------------------------------------------
//Close form
void __fastcall TMainForm::N6Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
//Open image
void __fastcall TMainForm::N2Click(TObject *Sender)
{
if (OPDialog->Execute())
{
Image->Picture->LoadFromFile(OPDialog->FileName);
bmpOriginal->LoadFromFile(OPDialog->FileName);
CopyFile(OPDialog->FileName.c_str(),("C:\\"+ExtractFileName(OPDialog->FileName) ).c_str(),0);
bmpCopy->LoadFromFile(("C:\\"+ExtractFileName(OPDialog->FileName) ).c_str());
Image->Enabled = TRUE;
TTreeNode* pnode = DirTree->Items->AddChild( NULL, ExtractFilePath(OPDialog->FileName) );
ScanDirs( ExtractFilePath(OPDialog->FileName), pnode );
N3->Enabled = TRUE;
N13->Enabled = TRUE;
N5->Enabled = TRUE;
N8->Enabled = TRUE;
N9->Enabled = TRUE;
N10->Enabled = TRUE;
N12->Enabled = TRUE;
N4->Enabled = TRUE;
}
}
//---------------------------------------------------------------------------
//Turn image
void __fastcall TMainForm::N10Click(TObject *Sender)
{
bmpOriginal->LoadFromFile(("C:\\"+ExtractFileName(OPDialog->FileName) ).c_str());
bmpCopy->Width = bmpOriginal->Height;
bmpCopy->Height = bmpOriginal->Width;
int wOr = bmpOriginal->Width, hOr = bmpOriginal->Height;
for(int x = 0; x < wOr; x++)
{
for(int y = 0; y < hOr; y++)
{
bmpCopy->Canvas->Pixels[hOr - y][x] = bmpOriginal->Canvas->Pixels[x][y];
}
}
bmpCopy->SaveToFile(("C:\\"+ExtractFileName(OPDialog->FileName) ).c_str());
Image->Picture = NULL;
Image->Canvas->Draw(0,0,bmpCopy);
}
//---------------------------------------------------------------------------
//Zoom
void __fastcall TMainForm::N8Click(TObject *Sender)
{
k += 10;
Image->Picture=NULL;
Image->Canvas->StretchDraw(Rect(0, 0, bmpCopy->Width*k/100, bmpCopy->Height*k/100),bmpCopy);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::N9Click(TObject *Sender)
{
k -= 10;
Image->Picture=NULL;
Image->Canvas->StretchDraw(Rect(0, 0, bmpCopy->Width*k/100, bmpCopy->Height*k/100),bmpCopy);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormMouseWheelUp(TObject *Sender,
TShiftState Shift, TPoint &MousePos, bool &Handled)
{
N8Click(Image);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormMouseWheelDown(TObject *Sender,
TShiftState Shift, TPoint &MousePos, bool &Handled)
{
N9Click(Image);
}
//---------------------------------------------------------------------------
//Show and hide directory and filelist menu
void __fastcall TMainForm::N12Click(TObject *Sender)
{
if (DirTree->Visible == FALSE) DirTree->Visible = TRUE;
else
DirTree->Visible = FALSE;
if (FileList->Visible == FALSE) FileList->Visible = TRUE;
else
FileList->Visible = FALSE;
}
//---------------------------------------------------------------------------
//Destroy form and our job files
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
DeleteFile(("C:\\"+ExtractFileName(OPDialog->FileName) ).c_str());
delete bmpOriginal;
delete bmpCopy;
delete Bitmap;
}
//---------------------------------------------------------------------------
//Delete image
void __fastcall TMainForm::N5Click(TObject *Sender)
{
DeleteFile(OPDialog->FileName);
}
//---------------------------------------------------------------------------
//Save image as
void __fastcall TMainForm::N3Click(TObject *Sender)
{
if( SPDialog ->Execute())
{
Image->Picture->SaveToFile(SPDialog ->FileName + ".bmp");
}
}
//---------------------------------------------------------------------------
//Rename image
void __fastcall TMainForm::N13Click(TObject *Sender)
{
NEdit->Visible = TRUE;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::NEditKeyPress(TObject *Sender, char &Key)
{
if(Key == VK_RETURN)
{
AnsiString FName = NEdit->Text;
if(RenameFile(OPDialog->FileName,FName + ".bmp")) NEdit->Visible = FALSE;
}
}
//---------------------------------------------------------------------------
//About program ISeeYou
void __fastcall TMainForm::N11Click(TObject *Sender)
{
ShowMessage("Äàííàÿ ïðîãðàììà ÿâëÿåòñÿ êóðñîâûì ïðîåêòîì ñòóäåíòà 2-ãî êóðñà Ïàðèñòîâà Í.Ï. Åñëè êàêàÿ-ëèáî ôóíêöèÿ íå ðàáîòàåò,ïîñòàâüòå 5,è îíà çàðàáîòàåò.Óäà÷è â èñïîëüçîâàíèè!!!");
}
//---------------------------------------------------------------------------
//Window sens
void __fastcall TMainForm::wm_windowposchanging(TMessage &msg)
{
const int sensitivity = 10;
RECT rcWorkArea = {0};
if(SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, FALSE))
{
WINDOWPOS *wp = (WINDOWPOS*)msg.LParam;
if(abs(wp->x - rcWorkArea.left) <= sensitivity)
wp->x = rcWorkArea.left;
if(abs(wp->y - rcWorkArea.top) <= sensitivity)
wp->y = rcWorkArea.top;
if(abs(wp->cx + wp->x - rcWorkArea.right) <= sensitivity)
wp->x = rcWorkArea.right - wp->cx;
if(abs(wp->cy + wp->y - rcWorkArea.bottom) <= sensitivity)
wp->y = rcWorkArea.bottom - wp->cy;
}
TForm::Dispatch(&msg);
}
//---------------------------------------------------------------------------
//Slide show
void IndexFoto(AnsiString Dir, AnsiString PredDir, AnsiString ParentDir)
{
TSearchRec sr;
if (!FindFirst( Dir + "*.*", faAnyFile, sr))
{
bool found = false;
while( !found )
{
if ( sr.Name != "." && sr.Name != ".." )
{
if( (sr.Attr & faDirectory) )
{
AnsiString NewDir = Dir + sr.Name;
IndexFoto( NewDir , Dir, ParentDir);
}
AnsiString FileName = sr.Name;
if(Dir != ParentDir)
{
int len1 = ParentDir.Length();
int len2 = Dir.Length();
AnsiString str;
str = Dir.SubString(len1+2,len2);
str += FileName;
FileName = str;
str="";
}
if(sr.Name.Pos(".bmp") != NULL)
ImgList.push_back(FileName);
}
found = FindNext(sr);
}
}
FindClose(sr);
Dir = PredDir;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::PictureTimerTimer(TObject *Sender)
{
AnsiString CurrentPicture;
if(it != ImgList.end())
{
if(it != NULL)
{
CurrentPicture = PictureDir + *it;
Bitmap->LoadFromFile(CurrentPicture);
Bitmap->Assign(Image);
it++;
}
}
else
{
it = ImgList.begin();
CurrentPicture = PictureDir + *it;
Bitmap->LoadFromFile(CurrentPicture);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::N4Click(TObject *Sender)
{
ImgList.clear();
IndexFoto(ExtractFilePath(OPDialog->FileName),ExtractFilePath(OPDialog->FileName),ExtractFilePath(OPDialog->FileName));
MainForm->Top = 0;
MainForm->Left = 0;
MainForm->Width = Screen->Width;
MainForm->Height = Screen->Height;
x = Screen->Width/5;
y = Screen->Height/5;
it = ImgList.begin();
PictureTimer->Enabled = true;
SShow = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ImageClick(TObject *Sender)
{
if (SShow == true) Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MovingTimerTimer(TObject *Sender)
{
int oldx = x + Bitmap->Width;
int oldy = y + Bitmap->Height;
int oldx1 = x ;
int oldy1 = y ;
Image->Canvas->Draw(x,y, Bitmap);
int k = x + y;
if( k < 0 || k > Screen->Width - Screen->Width/6 )
y = Sign( -y ) * ( 10 + random ( 10 ));
else
x = k;
int dx = oldx-x;
if(dx > 0) Image->Canvas->FillRect(Rect(x + Bitmap->Width, y , oldx, oldy));
else
Image->Canvas->FillRect(Rect(oldx1, oldy1, oldx1 + dx, oldy));
}
//--------------------------------------------------------------------------- |