-
Notifications
You must be signed in to change notification settings - Fork 1
/
uCaptureMain.pas
536 lines (466 loc) · 13.2 KB
/
uCaptureMain.pas
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
unit uCaptureMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Buttons, uCapture,
Vcl.ComCtrls, Vcl.ToolWin, Vcl.ImgList, uTextArea, System.ImageList, System.Generics.Collections; //, System.ImageList; //, System.ImageList;
type
TEnumZeichnungType = (ztNone, ztKreis, ztPfeil, ztTextEingeben);
{
Class für Zeichnung eines Pfeiles
}
TPfeil = class(TShape)
strict private
FLeft: Integer;
FTop: Integer;
protected
procedure Paint; override;
procedure Draw(const pCanvas: TCanvas);
public
procedure DrawTo(const X, Y: Integer; const pCanvas: TCanvas);
end;
TfrmSnipping = class(TForm)
scbCapture: TScrollBox;
pnFooter: TPanel;
ImageList1: TImageList;
lbStartX: TLabel;
lbStartY: TLabel;
lbEndX: TLabel;
lbEndY: TLabel;
lbX: TLabel;
lbY: TLabel;
imgCapture: TImage;
tbMenu: TToolBar;
btnCopieren: TSpeedButton;
btnCapture: TSpeedButton;
btnSchreiben: TSpeedButton;
btnPfeil: TSpeedButton;
btnKreis: TSpeedButton;
lbEditingMode: TLabel;
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure imgCaptureMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure imgCaptureMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure imgCaptureMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure btnCapture1Click(Sender: TObject);
procedure btnKreisClick(Sender: TObject);
procedure btnPfeilClick(Sender: TObject);
procedure btnCopierenClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnSchreiben1Click(Sender: TObject);
procedure imgCaptureClick(Sender: TObject);
procedure scbCaptureAlignPosition(Sender: TWinControl; Control: TControl;
var NewLeft, NewTop, NewWidth, NewHeight: Integer; var AlignRect: TRect;
AlignInfo: TAlignInfo);
private
{ Private declarations }
FShape: TShape;
FPfeil: TPfeil;
FTextArea: TTextArea;
FDrawing: Boolean;
FSchreiben: Boolean;
FStartX, FStartY, FEndX, FEndY: Integer;
FMaxRight, FMaxBottom: Integer;
FZeichnungType: TEnumZeichnungType;
FImageList : TImageList;
FTextAreaList: TObjectList<TTextArea>;
function BitmapCapture(const aLeft, aTop, aRight, aBottom: Integer): TBitmap;
procedure ConfirmTextAreas;
procedure FooterRefresh(const X, Y: Integer);
procedure ButtonsZeigen;
procedure ChangeButtonDown;
public
{ Public declarations }
end;
var
frmSnipping: TfrmSnipping;
const
cEnumZeichnungTypeStr: array [0..3] of string = ('', 'Kreis', 'Pfeil', 'Text Eingeben');
implementation
uses
Clipbrd;
{$R *.dfm}
procedure TfrmSnipping.btnCapture1Click(Sender: TObject);
var
frmCapture: TfrmCapture;
oCapturedBitmap: TBitmap;
begin
if Assigned(FImageList) then
FImageList.Free;
imgCapture.Picture.Assign(nil);
Self.Visible := False;
frmCapture := TfrmCapture.Create(nil);
try
frmCapture.ShowModal;
if Assigned(frmCapture.FPrint) then
begin
FImageList := TImageList.Create(Self);
oCapturedBitmap := frmCapture.FPrint;
imgCapture.Picture.Bitmap := frmCapture.FPrint;
imgCapture.Width := Screen.Width;
imgCapture.Height := Screen.Height;
imgCapture.Picture.Bitmap.Width := Screen.Width;
imgCapture.Picture.Bitmap.Height := Screen.Height;
FMaxRight := oCapturedBitmap.Width;
FMaxBottom := oCapturedBitmap.Height;
Self.Width := 650;
if oCapturedBitmap.Width > Self.Width then
Self.Width := Round(oCapturedBitmap.Width * 2);
if oCapturedBitmap.Height > Self.Height - tbMenu.Height - 40 then
Self.Height := Round((oCapturedBitmap.Height * 2) + Self.Height);
if Self.Width > Screen.Width then
Self.Width := Screen.Width;
if Self.Height > Screen.Height then
Self.Height := Screen.Height - 30;
FImageList.Add(oCapturedBitmap, oCapturedBitmap);
BringToFront;
end;
finally
frmCapture.Free;
Self.Visible := True;
end;
Self.ChangeButtonDown;
end;
procedure TfrmSnipping.btnCopierenClick(Sender: TObject);
var
oBitmap: TBitmap;
oRect: TRect;
begin
oRect := imgCapture.BoundsRect;
oBitmap := TBitmap.Create;
try
// Hier wird auch copiert wo gezeichnet wurde, deswegen werden die vars FMaxRight und FMaxBottom verwendet
oBitmap.Assign(BitmapCapture(oRect.Left, oRect.Top, FMaxRight, FMaxBottom));
Clipboard.Assign(oBitmap);
finally
oBitmap.Free;
end;
end;
procedure TfrmSnipping.btnKreisClick(Sender: TObject);
begin
FZeichnungType := ztKreis;
Self.ChangeButtonDown;
end;
procedure TfrmSnipping.btnPfeilClick(Sender: TObject);
begin
FZeichnungType := ztPfeil;
Self.ChangeButtonDown;
end;
procedure TfrmSnipping.btnSchreiben1Click(Sender: TObject);
begin
FZeichnungType := ztTextEingeben;
Self.ChangeButtonDown;
end;
procedure TfrmSnipping.ButtonsZeigen;
var
bEditing: Boolean;
begin
bEditing := FImageList <> nil;
// Es muss in diese Ordnung sein um die Komponenten in der richtige Ordnung zu zeigen
btnKreis.Visible := bEditing;
btnPfeil.Visible := bEditing;
btnSchreiben.Visible := bEditing;
btnCopieren.Visible := bEditing;
scbCapture.Visible := bEditing;
pnFooter.Visible := bEditing;
end;
procedure TfrmSnipping.ChangeButtonDown;
begin
btnKreis.Transparent := FZeichnungType <> ztKreis;
btnPfeil.Transparent := FZeichnungType <> ztPfeil;
btnSchreiben.Transparent := FZeichnungType <> ztTextEingeben;
end;
procedure TfrmSnipping.ConfirmTextAreas;
var
oTextArea: TTextArea;
begin
for oTextArea in FTextAreaList do
begin
oTextArea.DrawTo(imgCapture.Canvas);
end;
FTextAreaList.Clear;
FTextAreaList.Free;
FTextAreaList := nil;
end;
procedure TfrmSnipping.imgCaptureClick(Sender: TObject);
begin
if FZeichnungType = ztTextEingeben then
FSchreiben := True;
end;
procedure TfrmSnipping.imgCaptureMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if FZeichnungType <> ztNone then
begin
FDrawing := True;
FStartX := X;
FStartY := Y;
FEndX := X;
FEndY := Y;
Self.FooterRefresh(0, 0);
case FZeichnungType of
ztPfeil:
begin
with imgCapture.Canvas do
begin
FPfeil := TPfeil.Create(scbCapture);
FPfeil.Left := FStartX;
FPfeil.Top := FStartY;
FPfeil.Width := 0;
FPfeil.Height := 0;
FPfeil.SetParentComponent(scbCapture);
end;
end;
ztKreis:
begin
FShape := TShape.Create(scbCapture);
FShape.Shape := TShapeType.stEllipse;
FShape.Align := TAlign.alNone;
FShape.Width := 0;
FShape.Height := 0;
FShape.Left := FStartX;
FShape.Top := FStartY;
FShape.Brush.Style := TBrushStyle.bsClear;
FShape.Pen.Style := TPenStyle.psSolid;
FShape.Pen.Color := clRed;
FShape.Pen.Width := 2;
FShape.Margins.SetBounds(0, 0, 0, 0);
FShape.SetParentComponent(scbCapture);
end;
ztTextEingeben:
begin
FTextArea := TTextArea.Create(scbCapture);
FTextArea.Align := alNone;
FTextArea.Width := 0;
FTextArea.Height := 0;
FTextArea.Left := FStartX;
FTextArea.Top := FStartY;
FTextArea.SetParentComponent(scbCapture);
FTextArea.Editing := True;
end;
end;
end;
end;
procedure TfrmSnipping.imgCaptureMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
Self.FooterRefresh(X, Y);
if FDrawing then
begin
with imgCapture.Canvas do
begin
case FZeichnungType of
ztKreis:
begin
FShape.Width := X - FStartX;
FShape.Height := Y - FStartY;
FShape.Repaint;
end;
ztPfeil:
begin
FPfeil.Width := X - FStartX;
FPfeil.Height := Y - FStartY;
FPfeil.Repaint;
end;
ztTextEingeben:
begin
FTextArea.Width := X - FStartX;
FTextArea.Height := Y - FStartY;
FTextArea.Repaint;
end;
end;
end;
FEndX := X;
FEndY := Y;
if FMaxRight < X then
FMaxRight := X;
if FMaxBottom < Y then
FMaxBottom := Y;
end;
end;
procedure TfrmSnipping.imgCaptureMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
oRect: TRect;
begin
Self.FooterRefresh(X, Y);
if FDrawing then
begin
with imgCapture.Canvas do
begin
case FZeichnungType of
ztPfeil:
begin
FPfeil.DrawTo(FStartX, FStartY, imgCapture.Canvas);
FPfeil.Free;
end;
ztKreis:
begin
if Assigned(FShape) then
FShape.Free;
Pen.Width := 2;
Pen.Color := clRed;
Brush.Style := bsClear;
Ellipse(FStartX, FStartY, FEndX, FEndY);
Ellipse(FStartX, FStartY, X, Y);
Repaint;
end;
ztTextEingeben:
begin
if not Assigned(FTextAreaList) then
FTextAreaList := TObjectList<TTextArea>.Create;
if (FTextArea.Width > 0) and (FTextArea.Height > 0) then
FTextAreaList.Add(FTextArea);
end;
end;
Brush.Color := clBlack;
Pen.Color := clRed;
Pen.Width := 2;
end;
FDrawing := False;
end
else
if FSchreiben then
begin
//TextOut()
oRect := Rect(X, Y, 100, 100);
imgCapture.Canvas.Brush.Color := clWhite;
//imgCapture.Canvas.Brush.Style := bsClear;
imgCapture.Canvas.Pen.Color := clRed;
imgCapture.Canvas.TextRect(oRect, X, Y, 'TESTE');
//imgCapture.Canvas.FrameRect(oRect);
FSchreiben := False;
end;
end;
procedure TfrmSnipping.FooterRefresh(const X, Y: Integer);
begin
lbStartX.Caption := 'StartX: ' + IntToStr(FStartX);
lbStartX.Repaint;
lbStartY.Caption := 'StartY: ' + IntToStr(FStartY);
lbStartY.Repaint;
lbEndX.Caption := 'EndX: ' + IntToStr(FEndX);
lbEndX.Repaint;
lbEndY.Caption := 'EndY: ' + IntToStr(FEndY);
lbEndY.Repaint;
lbX.Caption := 'X: ' + IntToStr(X);
lbX.Repaint;
lbY.Caption := 'Y: ' + IntToStr(Y);
lbY.Repaint;
lbEditingMode.Caption := 'Bearbeitung: ' + cEnumZeichnungTypeStr[Integer(FZeichnungType)];
lbEditingMode.Repaint;
end;
procedure TfrmSnipping.FormCreate(Sender: TObject);
begin
Self.Height := scbCapture.Top + 39;
Self.Width := 300;
FZeichnungType := ztNone;
with imgCapture.Canvas do
begin
Brush.Color := clBlack;
Pen.Color := clRed;
Pen.Width := 2;
end;
end;
procedure TfrmSnipping.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_ESCAPE then
Close;
end;
procedure TfrmSnipping.FormShow(Sender: TObject);
begin
ButtonsZeigen();
Self.Left := 0;
Self.Top := 0;
imgCapture.Top := 0;
imgCapture.Left := 0;
end;
procedure TfrmSnipping.scbCaptureAlignPosition(Sender: TWinControl; Control: TControl;
var NewLeft, NewTop, NewWidth, NewHeight: Integer; var AlignRect: TRect;
AlignInfo: TAlignInfo);
begin
imgCapture.SetBounds(NewLeft, NewTop, NewWidth, NewHeight);
end;
function TfrmSnipping.BitmapCapture(const aLeft, aTop, aRight, aBottom: Integer): TBitmap;
begin
ConfirmTextAreas();
Result := TBitmap.Create;
Result.PixelFormat := TPixelFormat.pf32bit;
Result.Width := aRight - aLeft;
Result.Height := aBottom - aTop;
Result.Canvas.CopyMode := cmSrcCopy;
Result.Canvas.CopyRect(
Rect(0, 0, Result.Width, Result.Height),
imgCapture.Canvas,
Rect(aLeft, aTop, aRight, aBottom));
end;
{ TPfeil }
{
Dieses procedure zeichnet einen Pfeil auf dem Canvas
@Param pCanvas Canvas wo gezeichnet wird
}
procedure TPfeil.Draw(const pCanvas: TCanvas);
var
y1, y2, y3, y4, y5: Integer;
x1 : Integer;
begin
with pCanvas do
begin
// y4
// **
// * *
// y1 *************** *
// * x1 *
// * * y3
// * x1 *
// y2 *************** *
// * *
// **
// y5
if FLeft = 0 then
FLeft := 1;
Pen.Color := clRed;
pen.Width := 2;
y1 := Round((Height / 11) * 4);
y2 := Round((Height / 11) * 7);
y3 := Round((y2 - y1) / 2) + y1;
y4 := Round((Height / 11) * 2);
y5 := Round((Height / 11) * 9);
x1 := Round((Width / 10) * 7);
y1 := y1 + FTop;
y2 := y2 + FTop;
y3 := y3 + FTop;
y4 := y4 + FTop;
y5 := y5 + FTop;
x1 := x1 + FLeft;
MoveTo(FLeft, y1);
LineTo(FLeft, y2);
LineTo(x1, y2);
MoveTo(FLeft, y1);
LineTo(x1, y1);
LineTo(x1, y4);
LineTo(FLeft + Width, y3);
MoveTo(x1, y2);
LineTo(x1, y5);
LineTo(FLeft + Width, y3);
end;
end;
{
Dieses procedure zeichet dem Pfeil in eine genaue Koordinate
@Param X Achse X wo gezeichnet wird
@Param Y Achse Y wo gezeichnet wird
@Param pCanvas Canvas wo gezeichnet wird
}
procedure TPfeil.DrawTo(const X, Y: Integer; const pCanvas: TCanvas);
begin
FLeft := X;
FTop := Y;
Self.Draw(pCanvas);
end;
procedure TPfeil.Paint;
begin
Self.Draw(Self.Canvas);
end;
end.