more editor changes...

This commit is contained in:
zueuk 2005-09-26 12:07:57 +00:00
parent 6001fa0a64
commit 221f9a0ad9
3 changed files with 503 additions and 298 deletions

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,11 @@ const
// PixelCountMax = 32768; // PixelCountMax = 32768;
WM_PTHREAD_COMPLETE = WM_APP + 5438; WM_PTHREAD_COMPLETE = WM_APP + 5438;
crEditArrow = 20;
crEditMove = 21;
crEditRotate = 22;
crEditScale = 23;
type type
TEditForm = class(TForm) TEditForm = class(TForm)
GrphPnl: TPanel; GrphPnl: TPanel;
@ -155,6 +160,9 @@ type
ColorImage: TImage; ColorImage: TImage;
TabSheet4: TTabSheet; TabSheet4: TTabSheet;
vleVariables: TValueListEditor; vleVariables: TValueListEditor;
mnuReset: TMenuItem;
mnuResetAll: TMenuItem;
tbResetAll: TToolButton;
procedure ValidateVariable; procedure ValidateVariable;
procedure vleVariablesValidate(Sender: TObject; ACol, ARow: Integer; const KeyName, KeyValue: string); procedure vleVariablesValidate(Sender: TObject; ACol, ARow: Integer; const KeyName, KeyValue: string);
procedure vleVariablesKeyPress(Sender: TObject; var Key: Char); procedure vleVariablesKeyPress(Sender: TObject; var Key: Char);
@ -272,6 +280,8 @@ type
Shift: TShiftState); Shift: TShiftState);
procedure txtValidateValue(Sender: TObject); procedure txtValidateValue(Sender: TObject);
procedure txtValKeyPress(Sender: TObject; var Key: Char); procedure txtValKeyPress(Sender: TObject; var Key: Char);
procedure mnuResetClick(Sender: TObject);
procedure mnuResetAllClick(Sender: TObject);
private private
TriangleView: TCustomDrawControl; TriangleView: TCustomDrawControl;
@ -752,7 +762,7 @@ begin
end; end;
EditForm.StatusBar.Panels[2].Text := Format('Zoom: %f', [GraphZoom]); EditForm.StatusBar.Panels[2].Text := Format('Zoom: %f', [GraphZoom]);
TriangleView.Refresh; TriangleView.Invalidate;//Refresh;
end; end;
procedure TEditForm.UpdateFlameX; procedure TEditForm.UpdateFlameX;
@ -1063,7 +1073,9 @@ begin
a := ToScreen(Pivot.x - dy, Pivot.y + dx); a := ToScreen(Pivot.x - dy, Pivot.y + dx);
b := ToScreen(Pivot.x + dy, Pivot.y - dx); b := ToScreen(Pivot.x + dy, Pivot.y - dx);
c := ToScreen(Pivot.x, Pivot.y);
MoveTo(a.x, a.y); MoveTo(a.x, a.y);
LineTo(c.X, c.y); // not necessary but it looks better with it...
LineTo(b.X, b.y); LineTo(b.X, b.y);
end; end;
@ -1188,6 +1200,11 @@ procedure TEditForm.FormCreate(Sender: TObject);
var var
i: integer; i: integer;
begin begin
Screen.Cursors[crEditArrow] := LoadCursor(HInstance, 'CUR_ARROW');
Screen.Cursors[crEditMove] := LoadCursor(HInstance, 'CUR_MOVE');
Screen.Cursors[crEditRotate] := LoadCursor(HInstance, 'CUR_ROTATE');
Screen.Cursors[crEditScale] := LoadCursor(HInstance, 'CUR_SCALE');
// Custom control setup // Custom control setup
TriangleView := TCustomDrawControl.Create(self); TriangleView := TCustomDrawControl.Create(self);
TriangleView.TabStop := True; TriangleView.TabStop := True;
@ -1313,11 +1330,17 @@ begin
FoundCorner: FoundCorner:
end; end;
if (mouseOverTriangle >= 0) and if (mouseOverTriangle >= 0) or (SelectMode = false) or (oldMode <> modeNone) then
(SelectMode or (mouseOverTriangle = SelectedTriangle)) then case editMode of
TriangleView.Cursor := crHandPoint modeMove:
TriangleView.Cursor := crEditMove;
modeRotate:
TriangleView.Cursor := crEditRotate;
modeScale:
TriangleView.Cursor := crEditScale;
end
else else
TriangleView.Cursor := crArrow; TriangleView.Cursor := crEditArrow; //crDefault;
Shift := Shift - [ssLeft]; Shift := Shift - [ssLeft];
@ -2445,34 +2468,22 @@ end;
procedure TEditForm.ValidateVariation; procedure TEditForm.ValidateVariation;
var var
Allow: boolean;
i: integer; i: integer;
NewVal, OldVal: double; NewVal, OldVal: double;
begin begin
Allow := True;
i := VEVars.Row - 1; i := VEVars.Row - 1;
OldVal := Round6(cp.xform[SelectedTriangle].vars[i]); OldVal := Round6(cp.xform[SelectedTriangle].vars[i]);
{ Test that it's a valid floating point number }
try try
StrToFloat(VEVars.Values[VarNames(i)]);
except on Exception do
begin
{ It's not, so we restore the old value }
VEVars.Values[VarNames(i)] := Format('%.6g', [OldVal]);
Allow := False;
end;
end;
NewVal := Round6(StrToFloat(VEVars.Values[VarNames(i)])); NewVal := Round6(StrToFloat(VEVars.Values[VarNames(i)]));
VEVars.Values[VarNames(i)] := Format('%.6g', [NewVal]); except
VEVars.Values[VarNames(i)] := Format('%.6g', [OldVal]);
{ If it's not the same as the old value and it was valid } exit;
if (NewVal <> OldVal) and Allow then end;
if (NewVal <> OldVal) then
begin begin
MainForm.UpdateUndo; MainForm.UpdateUndo;
cp.xform[SelectedTriangle].vars[i] := NewVal; cp.xform[SelectedTriangle].vars[i] := NewVal;
VEVars.Values[VarNames(i)] := Format('%.6g', [cp.xform[SelectedTriangle].vars[i]]); VEVars.Values[VarNames(i)] := Format('%.6g', [NewVal]);
ShowSelectedInfo; ShowSelectedInfo;
UpdateFlame(True); UpdateFlame(True);
end; end;
@ -2517,7 +2528,7 @@ begin
begin begin
MainForm.UpdateUndo; MainForm.UpdateUndo;
values^[i] := NewVal; values^[i] := NewVal;
Sender.Values[VarNames(i)] := Format('%.6g', [values^[i]]); Sender.Values[VarNames(i)] := Format('%.6g', [NewVal]);
EditForm.ShowSelectedInfo; EditForm.ShowSelectedInfo;
EditForm.UpdateFlame(True); EditForm.UpdateFlame(True);
end; end;
@ -2877,17 +2888,23 @@ begin
VK_MENU: VK_MENU:
begin begin
editMode := modeRotate; editMode := modeRotate;
tbRotate.Down := true; // tbRotate.Down := true;
// if (mouseOverTriangle >= 0) or (SelectMode = false) then
TriangleView.Cursor := crEditRotate;
end; end;
VK_CONTROL: VK_CONTROL:
begin begin
editMode := modeScale; editMode := modeScale;
tbScale.Down := true; // tbScale.Down := true;
// if (mouseOverTriangle >= 0) or (SelectMode = false) then
TriangleView.Cursor := crEditScale;
end; end;
else //VK_SHIFT: else //VK_SHIFT:
begin begin
editMode := modeMove; editMode := modeMove;
tbMove.Down := true; // tbMove.Down := true;
// if (mouseOverTriangle >= 0) or (SelectMode = false) then
TriangleView.Cursor := crEditMove;
end; end;
end; end;
EditorToolBar.Refresh; EditorToolBar.Refresh;
@ -2927,9 +2944,13 @@ begin
begin begin
editMode := oldMode; editMode := oldMode;
oldMode := modeNone; oldMode := modeNone;
tbMove.Down := (editMode = modeMove); // tbMove.Down := (editMode = modeMove);
tbRotate.Down := (editMode = modeRotate); // tbRotate.Down := (editMode = modeRotate);
tbScale.Down := (editMode = modeScale); // tbScale.Down := (editMode = modeScale);
// hack: to generate MouseMove event
GetCursorPos(MousePos);
SetCursorPos(MousePos.x, MousePos.y);
end; end;
end; end;
@ -2939,9 +2960,9 @@ begin
begin begin
editMode := oldMode; editMode := oldMode;
oldMode := modeNone; oldMode := modeNone;
tbMove.Down := (editMode = modeMove); // tbMove.Down := (editMode = modeMove);
tbRotate.Down := (editMode = modeRotate); // tbRotate.Down := (editMode = modeRotate);
tbScale.Down := (editMode = modeScale); // tbScale.Down := (editMode = modeScale);
end; end;
mouseOverTriangle := -1; mouseOverTriangle := -1;
@ -3091,9 +3112,9 @@ procedure TEditForm.ColorImageMouseDown(Sender: TObject;
begin begin
if Button = mbLeft then if Button = mbLeft then
begin begin
colorDragX:=x; SetCaptureControl(ColorImage);
colorDragX:=0;
colorOldX:=x; colorOldX:=x;
// BackupPal:=Palette;
colorDrag:=true; colorDrag:=true;
colorChanged:=false; colorChanged:=false;
end; end;
@ -3104,10 +3125,9 @@ procedure TEditForm.ColorImageMouseMove(Sender: TObject;
var var
i, offset: integer; i, offset: integer;
begin begin
{ if colorDrag and (OldX<>x) then
if colorDrag and (oldX<>x) then
begin begin
oldX:=x; { oldX:=x;
offset := ( ((x - colorDragX) shl 8) div ColorImage.Width ) mod 256; offset := ( ((x - colorDragX) shl 8) div ColorImage.Width ) mod 256;
colorChanged := true; colorChanged := true;
@ -3122,14 +3142,13 @@ begin
cp.cmap := Palette; cp.cmap := Palette;
colorImage.Refresh; colorImage.Refresh;
end; } end;
}
end; end;
procedure TEditForm.ColorImageMouseUp(Sender: TObject; procedure TEditForm.ColorImageMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin begin
if colorDrag then if (Button = mbLeft) and colorDrag then
begin begin
colorDrag := false; colorDrag := false;
@ -3138,6 +3157,7 @@ begin
// cp.xxx := xxx; // cp.xxx := xxx;
// MainCP.copy(cp); // MainCP.copy(cp);
// UpdateXXXX; // UpdateXXXX;
SetCaptureControl(nil);
end; end;
end; end;
end; end;
@ -3152,31 +3172,22 @@ end;
procedure TEditForm.ValidateVariable; procedure TEditForm.ValidateVariable;
var var
Allow: boolean;
i: integer; i: integer;
NewVal, OldVal: double; NewVal, OldVal: double;
begin begin
Allow := True;
i := vleVariables.Row; i := vleVariables.Row;
cp.xform[SelectedTriangle].GetVariable(vleVariables.Keys[i], OldVal); cp.xform[SelectedTriangle].GetVariable(vleVariables.Keys[i], OldVal);
{ Test that it's a valid floating point number } { Test that it's a valid floating point number }
try try
StrToFloat(vleVariables.Values[vleVariables.Keys[i]]); NewVal := Round6(StrToFloat(vleVariables.Values[vleVariables.Keys[i]]));
except on Exception do except
begin
{ It's not, so we restore the old value } { It's not, so we restore the old value }
vleVariables.Values[vleVariables.Keys[i]] := Format('%.6g', [OldVal]); vleVariables.Values[vleVariables.Keys[i]] := Format('%.6g', [OldVal]);
Allow := False; exit;
end; end;
end;
NewVal := Round6(StrToFloat(vleVariables.Values[vleVariables.Keys[i]]));
vleVariables.Values[vleVariables.Keys[i]] := Format('%.6g', [NewVal]);
{ If it's not the same as the old value and it was valid } { If it's not the same as the old value and it was valid }
if (NewVal <> OldVal) and Allow then if (NewVal <> OldVal) then
begin begin
MainForm.UpdateUndo; MainForm.UpdateUndo;
cp.xform[SelectedTriangle].SetVariable(vleVariables.Keys[i], NewVal); cp.xform[SelectedTriangle].SetVariable(vleVariables.Keys[i], NewVal);
@ -3211,14 +3222,51 @@ begin
try try
t := StrToFloat(TComboBox(Sender).Text); t := StrToFloat(TComboBox(Sender).Text);
if t <> 0 then exit; if t <> 0 then exit;
finally except
TComboBox(Sender).ItemIndex := 1; TComboBox(Sender).ItemIndex := 1;
end; end;
end; end;
procedure TEditForm.txtValKeyPress(Sender: TObject; var Key: Char); procedure TEditForm.txtValKeyPress(Sender: TObject; var Key: Char);
begin begin
if key = #13 then txtValidateValue(Sender); if key <> #13 then exit;
key := #0;
txtValidateValue(Sender);
end;
procedure TEditForm.mnuResetClick(Sender: TObject);
begin
MainForm.UpdateUndo;
MainTriangles[SelectedTriangle] := MainTriangles[-1];
UpdateFlame(True);
end;
procedure TEditForm.mnuResetAllClick(Sender: TObject);
var
i: integer;
begin
MainForm.UpdateUndo;
for i := 2 to Transforms-1 do cp.xform[i].density := 0;
Transforms := 2;
SelectedTriangle := 1;
MainTriangles[0] := MainTriangles[-1];
cp.xform[0].density := 0.5;
cp.xform[0].vars[0] := 1;
MainTriangles[1] := MainTriangles[-1];
cp.xform[1].density := 0.5;
cp.xform[1].vars[0] := 1;
for i := 1 to NRVAR - 1 do
begin
cp.xform[0].vars[i] := 0;
cp.xform[1].vars[i] := 0;
end;
cbTransforms.clear;
cbTransforms.Items.Add('1');
cbTransforms.Items.Add('2');
AutoZoom;
UpdateFlame(True);
end; end;
end. end.

View File

@ -27,7 +27,7 @@ object MainForm: TMainForm
Left = 160 Left = 160
Top = 28 Top = 28
Width = 4 Width = 4
Height = 494 Height = 498
end end
object ToolBar: TToolBar object ToolBar: TToolBar
Left = 0 Left = 0
@ -112,6 +112,7 @@ object MainForm: TMainForm
Width = 40 Width = 40
Height = 21 Height = 21
Hint = 'Rendering quality|Rendering quality of the main window' Hint = 'Rendering quality|Rendering quality of the main window'
AutoComplete = False
ItemHeight = 13 ItemHeight = 13
ItemIndex = 0 ItemIndex = 0
TabOrder = 0 TabOrder = 0
@ -283,7 +284,7 @@ object MainForm: TMainForm
Left = 0 Left = 0
Top = 28 Top = 28
Width = 160 Width = 160
Height = 494 Height = 498
Align = alLeft Align = alLeft
Columns = < Columns = <
item item
@ -302,7 +303,7 @@ object MainForm: TMainForm
Left = 164 Left = 164
Top = 28 Top = 28
Width = 433 Width = 433
Height = 494 Height = 498
Align = alClient Align = alClient
BevelInner = bvLowered BevelInner = bvLowered
BevelOuter = bvNone BevelOuter = bvNone
@ -313,7 +314,7 @@ object MainForm: TMainForm
Left = 1 Left = 1
Top = 1 Top = 1
Width = 431 Width = 431
Height = 492 Height = 496
Align = alClient Align = alClient
AutoSize = True AutoSize = True
PopupMenu = DisplayPopup PopupMenu = DisplayPopup
@ -326,7 +327,7 @@ object MainForm: TMainForm
end end
object StatusBar: TStatusBar object StatusBar: TStatusBar
Left = 0 Left = 0
Top = 522 Top = 526
Width = 597 Width = 597
Height = 19 Height = 19
Panels = < Panels = <