- Fixed TfrmToolWindow.FormDeactivate to check CanClose first

- Fixed TfrmDrawSettings and TfrmHueSettings to be shown non-modal (fixes #49)
This commit is contained in:
Andreas Schneider 2009-12-18 18:43:55 +01:00
parent e502321f35
commit 5d7c40d579
4 changed files with 357 additions and 333 deletions

View File

@ -1,120 +1,123 @@
inherited frmDrawSettings: TfrmDrawSettings inherited frmDrawSettings: TfrmDrawSettings
Left = 268 Left = 268
Height = 180 Height = 180
Top = 165 Top = 165
Width = 242 Width = 242
ActiveControl = rbTileList ActiveControl = rbTileList
Caption = 'Draw settings' Caption = 'Draw settings'
ClientHeight = 180 ClientHeight = 180
ClientWidth = 242 ClientWidth = 242
object rbTileList: TRadioButton[0] OnCreate = FormCreate
AnchorSideLeft.Control = Owner object rbTileList: TRadioButton[0]
AnchorSideTop.Control = Owner AnchorSideLeft.Control = Owner
Left = 8 AnchorSideTop.Control = Owner
Height = 19 Left = 8
Top = 8 Height = 22
Width = 125 Top = 8
BorderSpacing.Left = 8 Width = 146
BorderSpacing.Top = 8 BorderSpacing.Left = 8
BorderSpacing.Bottom = 4 BorderSpacing.Top = 8
Caption = 'Use tile from the list' BorderSpacing.Bottom = 4
Checked = True Caption = 'Use tile from the list'
State = cbChecked Checked = True
TabOrder = 0 State = cbChecked
end TabOrder = 0
object rbRandom: TRadioButton[1] end
AnchorSideLeft.Control = rbTileList object rbRandom: TRadioButton[1]
AnchorSideTop.Control = rbTileList AnchorSideLeft.Control = rbTileList
AnchorSideTop.Side = asrBottom AnchorSideTop.Control = rbTileList
Left = 8 AnchorSideTop.Side = asrBottom
Height = 19 Left = 8
Top = 31 Height = 22
Width = 184 Top = 34
BorderSpacing.Top = 4 Width = 213
Caption = 'Use tiles from the random pool' BorderSpacing.Top = 4
TabOrder = 1 Caption = 'Use tiles from the random pool'
TabStop = False TabOrder = 1
end TabStop = False
object gbHue: TGroupBox[2] end
AnchorSideLeft.Control = Owner object gbHue: TGroupBox[2]
AnchorSideTop.Control = seRandomHeight AnchorSideLeft.Control = Owner
AnchorSideTop.Side = asrBottom AnchorSideTop.Control = seRandomHeight
AnchorSideRight.Control = Owner AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom AnchorSideRight.Control = Owner
Left = 8 AnchorSideRight.Side = asrBottom
Height = 49 Left = 8
Top = 123 Height = 49
Width = 226 Top = 132
Anchors = [akTop, akLeft, akRight] Width = 226
BorderSpacing.Around = 8 Anchors = [akTop, akLeft, akRight]
Caption = 'Hue (Statics only)' BorderSpacing.Around = 8
ClientHeight = 31 Caption = 'Hue (Statics only)'
ClientWidth = 222 ClientHeight = 45
TabOrder = 2 ClientWidth = 222
object pbHue: TPaintBox TabOrder = 2
Cursor = crHandPoint object pbHue: TPaintBox
Left = 4 Cursor = crHandPoint
Height = 27 Left = 4
Top = 0 Height = 41
Width = 214 Top = 0
Align = alClient Width = 214
BorderSpacing.Left = 4 Align = alClient
BorderSpacing.Right = 4 BorderSpacing.Left = 4
BorderSpacing.Bottom = 4 BorderSpacing.Right = 4
OnClick = pbHueClick BorderSpacing.Bottom = 4
OnPaint = pbHuePaint OnClick = pbHueClick
end OnPaint = pbHuePaint
end end
object cbRandomHeight: TCheckBox[3] end
AnchorSideLeft.Control = cbForceAltitude object cbRandomHeight: TCheckBox[3]
AnchorSideTop.Control = cbForceAltitude AnchorSideLeft.Control = cbForceAltitude
AnchorSideTop.Side = asrBottom AnchorSideTop.Control = cbForceAltitude
Left = 8 AnchorSideTop.Side = asrBottom
Height = 19 Left = 8
Top = 93 Height = 22
Width = 135 Top = 102
BorderSpacing.Top = 12 Width = 149
Caption = 'Add Random Altitude' BorderSpacing.Top = 12
TabOrder = 3 Caption = 'Add Random Altitude'
end TabOrder = 3
object seRandomHeight: TSpinEdit[4] end
AnchorSideTop.Control = cbRandomHeight object seRandomHeight: TSpinEdit[4]
AnchorSideTop.Side = asrCenter AnchorSideTop.Control = cbRandomHeight
AnchorSideRight.Control = Owner AnchorSideTop.Side = asrCenter
AnchorSideRight.Side = asrBottom AnchorSideRight.Control = Owner
Left = 184 AnchorSideRight.Side = asrBottom
Height = 25 Left = 184
Top = 90 Height = 21
Width = 50 Top = 103
Anchors = [akTop, akRight] Width = 50
BorderSpacing.Right = 8 Anchors = [akTop, akRight]
TabOrder = 4 BorderSpacing.Right = 8
end TabOrder = 4
object cbForceAltitude: TCheckBox[5] end
AnchorSideLeft.Control = rbRandom object cbForceAltitude: TCheckBox[5]
AnchorSideTop.Control = rbRandom AnchorSideLeft.Control = rbRandom
AnchorSideTop.Side = asrBottom AnchorSideTop.Control = rbRandom
Left = 8 AnchorSideTop.Side = asrBottom
Height = 19 Left = 8
Top = 62 Height = 22
Width = 95 Top = 68
BorderSpacing.Top = 12 Width = 111
Caption = 'Force altitude:' BorderSpacing.Top = 12
TabOrder = 5 Caption = 'Force altitude:'
end TabOrder = 5
object seForceAltitude: TSpinEdit[6] end
AnchorSideTop.Control = cbForceAltitude object seForceAltitude: TSpinEdit[6]
AnchorSideTop.Side = asrCenter AnchorSideTop.Control = cbForceAltitude
AnchorSideRight.Control = Owner AnchorSideTop.Side = asrCenter
AnchorSideRight.Side = asrBottom AnchorSideRight.Control = Owner
Left = 184 AnchorSideRight.Side = asrBottom
Height = 25 Left = 184
Top = 59 Height = 21
Width = 50 Top = 69
Anchors = [akTop, akRight] Width = 50
BorderSpacing.Right = 8 Anchors = [akTop, akRight]
MaxValue = 127 BorderSpacing.Right = 8
MinValue = -128 MaxValue = 127
TabOrder = 6 MinValue = -128
end TabOrder = 6
end end
inherited tmClose: TTimer[7]
end
end

View File

@ -1,109 +1,129 @@
(* (*
* CDDL HEADER START * CDDL HEADER START
* *
* The contents of this file are subject to the terms of the * The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only * Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance * (the "License"). You may not use this file except in compliance
* with the License. * with the License.
* *
* You can obtain a copy of the license at * You can obtain a copy of the license at
* http://www.opensource.org/licenses/cddl1.php. * http://www.opensource.org/licenses/cddl1.php.
* See the License for the specific language governing permissions * See the License for the specific language governing permissions
* and limitations under the License. * and limitations under the License.
* *
* When distributing Covered Code, include this CDDL HEADER in each * When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at * file and include the License file at
* http://www.opensource.org/licenses/cddl1.php. If applicable, * http://www.opensource.org/licenses/cddl1.php. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed * add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying * information: * by brackets "[]" replaced with your own identifying * information:
* Portions Copyright [yyyy] [name of copyright owner] * Portions Copyright [yyyy] [name of copyright owner]
* *
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2009 Andreas Schneider * Portions Copyright 2009 Andreas Schneider
*) *)
unit UfrmDrawSettings; unit UfrmDrawSettings;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
interface interface
uses uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
Spin, ExtCtrls, LMessages, UfrmToolWindow; Spin, ExtCtrls, LMessages, UfrmToolWindow;
type type
{ TfrmDrawSettings } { TfrmDrawSettings }
TfrmDrawSettings = class(TfrmToolWindow) TfrmDrawSettings = class(TfrmToolWindow)
cbForceAltitude: TCheckBox; cbForceAltitude: TCheckBox;
cbRandomHeight: TCheckBox; cbRandomHeight: TCheckBox;
gbHue: TGroupBox; gbHue: TGroupBox;
pbHue: TPaintBox; pbHue: TPaintBox;
rbRandom: TRadioButton; rbRandom: TRadioButton;
rbTileList: TRadioButton; rbTileList: TRadioButton;
seForceAltitude: TSpinEdit; seForceAltitude: TSpinEdit;
seRandomHeight: TSpinEdit; seRandomHeight: TSpinEdit;
procedure pbHueClick(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure pbHuePaint(Sender: TObject); procedure pbHueClick(Sender: TObject);
procedure seForceAltitudeChange(Sender: TObject); procedure pbHuePaint(Sender: TObject);
procedure seRandomHeightChange(Sender: TObject); procedure seForceAltitudeChange(Sender: TObject);
public procedure seRandomHeightChange(Sender: TObject);
{ public declarations } private
end; FCanClose: Boolean;
function CanClose: Boolean; override;
var procedure OnHueClose(Sender: TObject; var ACloseAction: TCloseAction);
frmDrawSettings: TfrmDrawSettings; end;
implementation var
frmDrawSettings: TfrmDrawSettings;
uses
UGameResources, UHue, UfrmHueSettings; implementation
{ TfrmDrawSettings } uses
UGameResources, UHue, UfrmHueSettings;
procedure TfrmDrawSettings.pbHueClick(Sender: TObject);
var { TfrmDrawSettings }
msg: TLMessage;
begin procedure TfrmDrawSettings.pbHueClick(Sender: TObject);
frmHueSettings.Left := Mouse.CursorPos.x - 8; begin
frmHueSettings.Top := Mouse.CursorPos.y - 8; frmHueSettings.Left := Mouse.CursorPos.x - 8;
frmHueSettings.ShowModal; frmHueSettings.Top := Mouse.CursorPos.y - 8;
pbHue.Repaint; frmHueSettings.OnClose := @OnHueClose;
MouseLeave(msg); frmHueSettings.Show;
end; FCanClose := False;
end;
procedure TfrmDrawSettings.pbHuePaint(Sender: TObject);
var procedure TfrmDrawSettings.FormCreate(Sender: TObject);
hue: THue; begin
begin FCanClose := True;
if frmHueSettings <> nil then end;
begin
if frmHueSettings.lbHue.ItemIndex > 0 then procedure TfrmDrawSettings.pbHuePaint(Sender: TObject);
hue := ResMan.Hue.Hues[frmHueSettings.lbHue.ItemIndex - 1] var
else hue: THue;
hue := nil; begin
TfrmHueSettings.DrawHue(hue, pbHue.Canvas, pbHue.Canvas.ClipRect, if frmHueSettings <> nil then
frmHueSettings.lbHue.Items.Strings[frmHueSettings.lbHue.ItemIndex]); begin
end; if frmHueSettings.lbHue.ItemIndex > 0 then
end; hue := ResMan.Hue.Hues[frmHueSettings.lbHue.ItemIndex - 1]
else
procedure TfrmDrawSettings.seForceAltitudeChange(Sender: TObject); hue := nil;
begin TfrmHueSettings.DrawHue(hue, pbHue.Canvas, pbHue.Canvas.ClipRect,
cbForceAltitude.Checked := True; frmHueSettings.lbHue.Items.Strings[frmHueSettings.lbHue.ItemIndex]);
end; end;
end;
procedure TfrmDrawSettings.seRandomHeightChange(Sender: TObject);
begin procedure TfrmDrawSettings.seForceAltitudeChange(Sender: TObject);
cbRandomHeight.Checked := True; begin
end; cbForceAltitude.Checked := True;
end;
//TODO : canclose ---> hue settings
procedure TfrmDrawSettings.seRandomHeightChange(Sender: TObject);
initialization begin
{$I UfrmDrawSettings.lrs} cbRandomHeight.Checked := True;
end;
end.
function TfrmDrawSettings.CanClose: Boolean;
begin
Result := FCanClose and inherited CanClose;
end;
procedure TfrmDrawSettings.OnHueClose(Sender: TObject;
var ACloseAction: TCloseAction);
var
msg: TLMessage;
begin
FCanClose := True;
frmHueSettings.OnClose := nil;
pbHue.Repaint;
MouseLeave(msg);
end;
initialization
{$I UfrmDrawSettings.lrs}
end.

View File

@ -1,103 +1,104 @@
(* (*
* CDDL HEADER START * CDDL HEADER START
* *
* The contents of this file are subject to the terms of the * The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only * Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance * (the "License"). You may not use this file except in compliance
* with the License. * with the License.
* *
* You can obtain a copy of the license at * You can obtain a copy of the license at
* http://www.opensource.org/licenses/cddl1.php. * http://www.opensource.org/licenses/cddl1.php.
* See the License for the specific language governing permissions * See the License for the specific language governing permissions
* and limitations under the License. * and limitations under the License.
* *
* When distributing Covered Code, include this CDDL HEADER in each * When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at * file and include the License file at
* http://www.opensource.org/licenses/cddl1.php. If applicable, * http://www.opensource.org/licenses/cddl1.php. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed * add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying * information: * by brackets "[]" replaced with your own identifying * information:
* Portions Copyright [yyyy] [name of copyright owner] * Portions Copyright [yyyy] [name of copyright owner]
* *
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2009 Andreas Schneider * Portions Copyright 2009 Andreas Schneider
*) *)
unit UfrmToolWindow; unit UfrmToolWindow;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
LCLIntf, LMessages, ExtCtrls; LCLIntf, LMessages, ExtCtrls;
type type
{ TfrmToolWindow } { TfrmToolWindow }
TfrmToolWindow = class(TForm) TfrmToolWindow = class(TForm)
tmClose: TTimer; tmClose: TTimer;
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormDeactivate(Sender: TObject); virtual; procedure FormDeactivate(Sender: TObject); virtual;
procedure FormShow(Sender: TObject); virtual; procedure FormShow(Sender: TObject); virtual;
procedure tmCloseTimer(Sender: TObject); procedure tmCloseTimer(Sender: TObject);
protected protected
function CanClose: Boolean; virtual; function CanClose: Boolean; virtual;
procedure MouseLeave(var msg: TLMessage); message CM_MouseLeave; procedure MouseLeave(var msg: TLMessage); message CM_MouseLeave;
public public
{ public declarations } { public declarations }
end; end;
var var
frmToolWindow: TfrmToolWindow; frmToolWindow: TfrmToolWindow;
implementation implementation
{ TfrmToolWindow } { TfrmToolWindow }
procedure TfrmToolWindow.FormDeactivate(Sender: TObject); procedure TfrmToolWindow.FormDeactivate(Sender: TObject);
begin begin
Close; if CanClose then
end; Close;
end;
procedure TfrmToolWindow.FormClose(Sender: TObject;
var CloseAction: TCloseAction); procedure TfrmToolWindow.FormClose(Sender: TObject;
begin var CloseAction: TCloseAction);
CloseAction := caHide; begin
end; CloseAction := caHide;
end;
procedure TfrmToolWindow.FormShow(Sender: TObject);
begin procedure TfrmToolWindow.FormShow(Sender: TObject);
Top := Mouse.CursorPos.y - 8; begin
Left := Mouse.CursorPos.x - 8; Top := Mouse.CursorPos.y - 8;
Left := Mouse.CursorPos.x - 8;
OnDeactivate := nil;
tmClose.Enabled := True; OnDeactivate := nil;
end; tmClose.Enabled := True;
end;
procedure TfrmToolWindow.tmCloseTimer(Sender: TObject);
begin procedure TfrmToolWindow.tmCloseTimer(Sender: TObject);
tmClose.Enabled := False; begin
OnDeactivate := @FormDeactivate; tmClose.Enabled := False;
if CanClose then OnDeactivate := @FormDeactivate;
Close; if CanClose then
end; Close;
end;
function TfrmToolWindow.CanClose: Boolean;
begin function TfrmToolWindow.CanClose: Boolean;
Result := not PtInRect(ClientRect, ScreenToClient(Mouse.CursorPos)); begin
end; Result := not PtInRect(ClientRect, ScreenToClient(Mouse.CursorPos));
end;
procedure TfrmToolWindow.MouseLeave(var msg: TLMessage);
begin procedure TfrmToolWindow.MouseLeave(var msg: TLMessage);
if CanClose then begin
Close; if CanClose then
end; Close;
end;
initialization
{$I UfrmToolWindow.lrs} initialization
{$I UfrmToolWindow.lrs}
end.
end.

View File

@ -1084,7 +1084,7 @@ begin
acDraw.Checked := True; acDraw.Checked := True;
tbDrawTile.Down := True; tbDrawTile.Down := True;
mnuDraw.Checked := True; mnuDraw.Checked := True;
frmDrawSettings.ShowModal; frmDrawSettings.Show;
ProcessToolState; ProcessToolState;
end; end;