first attempt to replace GraphImage with new custom TriangleGraph

(Ronald, I hope you'll help me further ;)
This commit is contained in:
zueuk 2005-09-11 16:03:15 +00:00
parent 1c12e92a41
commit 5ff6758e7a
3 changed files with 135 additions and 72 deletions

View File

@ -1,10 +1,12 @@
object EditForm: TEditForm
Left = 305
Top = 166
Left = 377
Top = 179
Width = 586
Height = 590
Height = 600
Caption = 'Transform Editor'
Color = clBtnFace
Constraints.MinHeight = 400
Constraints.MinWidth = 200
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -11
@ -44,16 +46,13 @@ object EditForm: TEditForm
OnClose = FormClose
OnCreate = FormCreate
OnDestroy = FormDestroy
OnKeyDown = editKeyDown
OnKeyPress = editKeyPress
OnMouseWheel = editMouseWheel
OnResize = FormResize
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object StatusBar: TStatusBar
Left = 0
Top = 547
Top = 557
Width = 578
Height = 15
Panels = <
@ -325,14 +324,14 @@ object EditForm: TEditForm
Left = 0
Top = 24
Width = 578
Height = 523
Height = 533
Align = alClient
TabOrder = 1
object Splitter1: TSplitter
Left = 396
Top = 1
Width = 9
Height = 521
Height = 531
Align = alRight
AutoSnap = False
Beveled = True
@ -343,30 +342,17 @@ object EditForm: TEditForm
Left = 1
Top = 1
Width = 395
Height = 521
Height = 531
Align = alClient
BevelOuter = bvNone
Color = clBlack
Color = clAppWorkSpace
TabOrder = 0
object GraphImage: TImage
Tag = 1
Left = 0
Top = 0
Width = 395
Height = 521
Align = alClient
PopupMenu = EditPopup
OnDblClick = GraphImageDblClick
OnMouseDown = GraphImageMouseDown
OnMouseMove = GraphImageMouseMove
OnMouseUp = GraphImageMouseUp
end
end
object RightPanel: TPanel
Left = 405
Top = 1
Width = 172
Height = 521
Height = 531
Align = alRight
Alignment = taLeftJustify
BevelOuter = bvNone
@ -406,7 +392,7 @@ object EditForm: TEditForm
Left = 0
Top = 136
Width = 172
Height = 385
Height = 395
Align = alClient
TabOrder = 0
object lblTransform: TLabel
@ -441,8 +427,8 @@ object EditForm: TEditForm
Left = 1
Top = 26
Width = 170
Height = 358
ActivePage = tabVariations
Height = 368
ActivePage = TriangleTab
Align = alBottom
Anchors = [akLeft, akTop, akRight, akBottom]
MultiLine = True
@ -454,7 +440,7 @@ object EditForm: TEditForm
Left = 0
Top = 0
Width = 162
Height = 312
Height = 322
HorzScrollBar.Visible = False
VertScrollBar.Smooth = True
VertScrollBar.Style = ssFlat
@ -1299,7 +1285,7 @@ object EditForm: TEditForm
Left = 0
Top = 0
Width = 162
Height = 312
Height = 322
Align = alClient
ScrollBars = ssVertical
TabOrder = 0

View File

@ -23,7 +23,7 @@ interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, ComCtrls, Math, Menus, ToolWin, Registry, MyTypes,
ControlPoint, Render, cmap, Grids, ValEdit, Buttons, ImgList;
ControlPoint, Render, cmap, Grids, ValEdit, Buttons, ImgList, TriangleGraph;
const
// PixelCountMax = 32768;
@ -32,7 +32,6 @@ const
type
TEditForm = class(TForm)
GrphPnl: TPanel;
GraphImage: TImage;
StatusBar: TStatusBar;
ControlPanel: TPanel;
lblTransform: TLabel;
@ -268,6 +267,7 @@ type
Shift: TShiftState; X, Y: Integer);
private
TriangleGraph: TTriangleGraph;
bm: TBitmap;
cmap: TColorMap;
// cp1: TControlPoint;
@ -726,11 +726,11 @@ begin
gCentery := yminz + gylength / 2;
if gxlength >= gylength then
begin
GraphZoom := EditForm.GraphImage.Width / 60 / gxlength;
GraphZoom := TriangleGraph.Width / 60 / gxlength;
end
else
begin
GraphZoom := EditForm.GraphImage.Height / 60 / gylength;
GraphZoom := TriangleGraph.Height / 60 / gylength;
end;
EditForm.StatusBar.Panels[2].Text := Format('Zoom: %f', [GraphZoom]);
end;
@ -922,27 +922,27 @@ var
ix, iy, sc: double;
ax, ay, bx, by, cx, cy: integer;
Width, Height: integer;
BitMap: TBitMap;
// BitMap: TBitMap;
// --Z--
gridX1, gridX2, gridY1, gridY2, gi, gstep: double;
gp: TRoundToRange;
// TrgPoints: array[0..2] of TPoint;
label DrawCorner;
begin
// --Z-- hmmm:
if SelectedTriangle < 0 then SelectedTriangle := 0
else if SelectedTriangle >= Transforms then SelectedTriangle := Transforms-1;
BitMap := TBitMap.Create;
// BitMap := TBitMap.Create;
try
Width := GraphImage.Width;
Height := GraphImage.Height;
BitMap.Width := Width;
BitMap.Height := Height;
Width := TriangleGraph.Width;
Height := TriangleGraph.Height;
// BitMap.Width := Width;
// BitMap.Height := Height;
ix := Width / 2;
iy := Height / 2;
sc := 50 * GraphZoom;
with Bitmap.canvas do
// with Bitmap.canvas do
with TriangleGraph.Canvas do
begin
brush.Color := pnlBackColor.Color;
FillRect(rect(0, 0, Width, Height));
@ -1150,10 +1150,10 @@ begin
}
// --
end;
GraphImage.Picture.Graphic := Bitmap;
GraphImage.Refresh;
// GraphImage.Picture.Graphic := Bitmap;
// GraphImage.Refresh;
finally
BitMap.Free;
// BitMap.Free;
end;
end;
@ -1161,16 +1161,23 @@ procedure TEditForm.FormCreate(Sender: TObject);
var
i: integer;
begin
(*
Drawcntrl := TDrawingControl.Create(self);
Drawcntrl.TabStop := True;
Drawcntrl.Parent := GrphPnl;
Drawcntrl.Align := alClient;
Drawcntrl.Visible := True;
//
TriangleGraph := TTriangleGraph.Create(self);
TriangleGraph.TabStop := True;
TriangleGraph.Parent := GrphPnl;
TriangleGraph.Align := alClient;
TriangleGraph.Visible := True;
Drawcntrl.OnDblClick := GraphImageDblClick;
Drawcntrl.Onpaint := viewPaint;
*)
TriangleGraph.OnDblClick := GraphImageDblClick;
TriangleGraph.OnMouseDown := GraphImageMouseDown;
TriangleGraph.OnMouseMove := GraphImageMouseMove;
TriangleGraph.OnMouseUp := GraphImageMouseUp;
TriangleGraph.OnMouseWheel := EditMouseWheel;
TriangleGraph.OnKeyDown := EditKeyDown;
// TriangleGraph.PopupMenu := EditPopup;
// TriangleGraph.OnPaint :=
//
for i:= 0 to NRVAR - 1 do begin
VEVars.InsertRow(Varnames(i), '0', True);
@ -1219,7 +1226,7 @@ var
d: double;
label FoundCorner;
begin
Scale(fx, fy, x, y, EditForm.GraphImage.Width, EditForm.GraphImage.Height);
Scale(fx, fy, x, y, TriangleGraph.Width, TriangleGraph.Height);
// --Z--
StatusBar.Panels[0].Text := Format('X: %f', [fx]);
StatusBar.Panels[1].Text := Format('Y: %f', [fy]);
@ -1258,9 +1265,9 @@ FoundCorner:
if (mouseOverTriangle >= 0) and (SelectMode or (mouseOverTriangle = SelectedTriangle)) then
GraphImage.Cursor := crHandPoint
TriangleGraph.Cursor := crHandPoint
else
GraphImage.Cursor := crArrow;
TriangleGraph.Cursor := crArrow;
if graphDragMode then // graph panning
begin
@ -1395,7 +1402,7 @@ begin
CornerCaught := False;
TriangleCaught := False;
dragged := false; // --Z--
Scale(fx, fy, x, y, EditForm.GraphImage.Width, EditForm.GraphImage.Height);
Scale(fx, fy, x, y, TriangleGraph.Width, TriangleGraph.Height);
Shift := Shift - [ssLeft]; // --Z--
if Button = mbLeft then
begin
@ -1476,7 +1483,7 @@ begin
end
else if Button = mbRight then // graph panning
begin
SetCaptureControl(GraphImage);
SetCaptureControl(TriangleGraph);
Screen.Cursor := crSizeAll;
graphDragMode := true;
@ -2771,17 +2778,12 @@ var
coeff: double;
label goNext;
begin
//if VEVars.Focused then exit;
if Shift = [ssShift] then coeff := 10
else if Shift = [ssCtrl] then coeff := 0.1
else coeff := 1.0;
// if (key in [VK_LEFT,VK_RIGHT,VK_UP,VK_DOWN,VK_PRIOR,VK_NEXT,VK_HOME,VK_END]) and
// if VEVars.Focused = false then
// if FocusedControl = VEVars then
if (PageControl.TabIndex <> 2) or // variations
(PageControl.TabIndex <> 3) then // variables
// if (PageControl.TabIndex <> 2) or // variations
// (PageControl.TabIndex <> 3) then // variables
begin
// MainForm.UpdateUndo;
case key of
@ -2826,6 +2828,7 @@ goNext:
ShowSelectedInfo;
end;
VK_SPACE: EditForm.tbSelectClick(Sender);
Ord('Q'): EditForm.tbEditModeClick(tbMove);
Ord('W'): EditForm.tbEditModeClick(tbRotate);
Ord('E'): EditForm.tbEditModeClick(tbScale);
@ -2850,8 +2853,8 @@ end;
procedure TEditForm.editKeyPress(Sender: TObject; var Key: Char);
begin
if key_handled then key := #0
else if key in ['A'..'z'] then key := #0; // hmmm...
// if key_handled then key := #0 else
if key in ['A'..'z'] then key := #0; // hmmm...
end;
procedure TEditForm.splitterMoved(Sender: TObject);
@ -2873,7 +2876,7 @@ begin
StatusBar.Panels[2].Text := 'Select OFF';
end;
// hack:
// hack (to generate MouseMove event):
GetCursorPos(MousePos);
SetCursorPos(MousePos.x, MousePos.y);
end;
@ -2883,7 +2886,6 @@ procedure TEditForm.editMouseWheel(Sender: TObject; Shift: TShiftState;
begin
if WheelDelta > 0 then GraphZoom := GraphZoom * 1.25
else GraphZoom := GraphZoom * 0.8;
// if GraphZoom < 0 the GraphZoom := 0;
EditForm.StatusBar.Panels[2].Text := Format('Zoom: %f', [GraphZoom]);
DrawGraph;
@ -2965,8 +2967,6 @@ begin
v := cp.xform[SelectedTriangle].vars[varDragIndex];
v := RoundTo(v + ((x-varDragPos)*2)/1000.0, -3);
// someone keeps rounding my variation values... grrrr >:-((
varDragPos:=x;
SetCursorPos(MousePos.x, MousePos.y); // hmmm
varMM:=true;

View File

@ -0,0 +1,77 @@
unit TriangleGraph;
interface
uses
Classes, Controls, Messages, Windows, Graphics;
type
TTriangleGraph = class(TWinControl)
private
FOnPaint: TNotifyEvent;
FCanvas: TCanvas;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
protected
procedure PaintWindow(DC: HDC); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; virtual;
property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
property Canvas: TCanvas read FCanvas;
property OnDblClick;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
end;
implementation
constructor TTriangleGraph.Create(AOwner: TComponent);
begin
inherited;
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
end;
destructor TTriangleGraph.Destroy;
begin
FCanvas.Free;
inherited;
end;
procedure TTriangleGraph.Paint;
begin
if Assigned(FOnPaint) then FOnPaint(Self);
end;
procedure TTriangleGraph.PaintWindow(DC: HDC);
begin
FCanvas.Handle := DC;
try
Paint;
finally
FCanvas.Handle := 0;
end;
end;
procedure TTriangleGraph.WMPaint(var Message: TWMPaint);
begin
PaintHandler(Message);
end;
end.