summaryrefslogtreecommitdiff
path: root/uidesigner/vfdresizer.pas
blob: a01af27bb5020d88550e452a3faddc07c9e15b24 (plain)
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
{
    fpGUI  -  Free Pascal GUI Toolkit

    Copyright (C) 2006 - 2010 See the file AUTHORS.txt, included in this
    distribution, for details of the copyright.

    See the file COPYING.modifiedLGPL, included in this distribution,
    for details about redistributing fpGUI.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Description:
      The resizer widget used in the form designer.
}

unit vfdresizer;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  fpg_base,
  fpg_widget;

type
  TwgResizer = class(TfpgWidget)
  protected
    wgdesigner: TObject;
    procedure   HandlePaint; override;
    procedure   HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override;
    procedure   HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override;
    procedure   HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override;
  public
    direction: integer;
    FDragging: boolean;
    FDragPosX,
    FDragPosY: TfpgCoord;
    constructor Create(ACompDesigner: TObject; adirection: integer); reintroduce;
    procedure   Show;
  end;


implementation


uses
  vfddesigner,
  vfdmain;

{ TwgResizer }

procedure TwgResizer.HandlePaint;
begin
  Canvas.Clear(FBackgroundColor);
end;

procedure TwgResizer.HandleLMouseDown(x, y: integer; shiftstate: TShiftState);
begin
  inherited HandleLMouseDown(x, y, shiftstate);
  FDragging := True;
  FDragPosX := x;
  FDragPosy := y;
  CaptureMouse;
end;

procedure TwgResizer.HandleLMouseUp(x, y: integer; shiftstate: TShiftState);
begin
  inherited HandleLMouseUp(x, y, shiftstate);
  FDragging := False;
  ReleaseMouse;
end;

procedure TwgResizer.HandleMouseMove(x, y: integer; btnstate: word;
  shiftstate: TShiftState);
var
  dx,
  dy: integer;
  gridc: integer;
  wgd: TWidgetDesigner;
begin
//  inherited HandleMouseMove(x, y, btnstate, shiftstate);

  if (not FDragging) or ((btnstate and MOUSE_LEFT) = 0) then
    Exit;

  dx := x - FDragPosX;
  dy := y - FDragPosY;

  wgd   := TWidgetDesigner(wgdesigner);
  gridc := maindsgn.GridResolution;

  dx := dx - (dx mod gridc);
  dy := dy - (dy mod gridc);

  case direction of
    1: wgd.Widget.MoveAndResizeBy(dx, dy, -dx, -dy);
    2: wgd.Widget.MoveAndResizeBy(0, dy, 0, -dy);
    3: wgd.Widget.MoveAndResizeBy(0, dy, dx, -dy);
    4: wgd.Widget.MoveAndResizeBy(0, 0, dx, 0);
    5: wgd.Widget.MoveAndResizeBy(0, 0, dx, dy);
    6: wgd.Widget.MoveAndResizeBy(0, 0, 0, dy);
    7: wgd.Widget.MoveAndResizeBy(dx, 0, -dx, dy);
    8: wgd.Widget.MoveAndResizeBy(dx, 0, -dx, 0);
  end;
  wgd.UpdateResizerPositions;
  wgd.FormDesigner.UpdatePropWin;
end;

constructor TwgResizer.Create(ACompDesigner: TObject; adirection: integer);
begin
  inherited Create(TWidgetDesigner(aCompDesigner).Widget.Parent);
  FBackgroundColor := $404040;
  wgdesigner := aCompDesigner;
  FDragging := False;
  Width     := 5;
  Height    := 5;
  direction := adirection;
  case direction of
    1: MouseCursor := mcSizeSENW;   // top left
    2: MouseCursor := mcSizeNS;     // top
    3: MouseCursor := mcSizeSWNE;   // top right
    4: MouseCursor := mcSizeEW;     // right
    5: MouseCursor := mcSizeNWSE;   // bottom right
    6: MouseCursor := mcSizeNS;     // bottom
    7: MouseCursor := mcSizeNESW;   // bottom left
    8: MouseCursor := mcSizeEW;     // left
  end;
end;

procedure TwgResizer.Show;
begin
  HandleShow;
end;

end.