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

View File

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