Statistics
| Branch: | Tag: | Revision:

root / Client / Tools / UfrmHueSettings.pas @ 0:95bd93c28625

History | View | Annotate | Download (4.1 kB)

1
(*
2
 * CDDL HEADER START
3
 *
4
 * The contents of this file are subject to the terms of the
5
 * Common Development and Distribution License, Version 1.0 only
6
 * (the "License").  You may not use this file except in compliance
7
 * with the License.
8
 *
9
 * You can obtain a copy of the license at
10
 * http://www.opensource.org/licenses/cddl1.php.
11
 * See the License for the specific language governing permissions
12
 * and limitations under the License.
13
 *
14
 * When distributing Covered Code, include this CDDL HEADER in each
15
 * file and include the License file at
16
 * http://www.opensource.org/licenses/cddl1.php.  If applicable,
17
 * add the following below this CDDL HEADER, with the fields enclosed
18
 * by brackets "[]" replaced with your own identifying * information:
19
 *      Portions Copyright [yyyy] [name of copyright owner]
20
 *
21
 * CDDL HEADER END
22
 *
23
 *
24
 *      Portions Copyright 2007 Andreas Schneider
25
 *)
26
unit UfrmHueSettings;
27
28
{$mode objfpc}{$H+}
29
30
interface
31
32
uses
33
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
34
  LMessages, LCLIntf, UHue;
35
36
type
37
38
  { TfrmHueSettings }
39
40
  TfrmHueSettings = class(TForm)
41
    edHue: TEdit;
42
    lblHue: TLabel;
43
    lbHue: TListBox;
44
    procedure edHueEditingDone(Sender: TObject);
45
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
46
    procedure FormCreate(Sender: TObject);
47
    procedure FormDeactivate(Sender: TObject);
48
    procedure lbHueDrawItem(Control: TWinControl; Index: Integer; ARect: TRect;
49
      State: TOwnerDrawState);
50
    procedure lbHueSelectionChange(Sender: TObject; User: boolean);
51
  protected
52
    procedure MouseLeave(var msg: TLMessage); message CM_MouseLeave;
53
  public
54
    class procedure DrawHue(AHue: THue; ACanvas: TCanvas; ARect: TRect;
55
      ACaption: string);
56
  end; 
57
58
var
59
  frmHueSettings: TfrmHueSettings;
60
61
implementation
62
63
uses
64
  UGameResources, UGraphicHelper;
65
66
{ TfrmHueSettings }
67
68
procedure TfrmHueSettings.FormClose(Sender: TObject;
69
  var CloseAction: TCloseAction);
70
begin
71
  CloseAction := caHide;
72
end;
73
74
procedure TfrmHueSettings.edHueEditingDone(Sender: TObject);
75
var
76
  hueID: Integer;
77
begin
78
  if (not TryStrToInt(edHue.Text, hueID)) or (hueID >= lbHue.Items.Count) then
79
  begin
80
    edHue.Text := Format('$%x', [lbHue.ItemIndex]);
81
    MessageDlg('Invalid Hue', 'The hue you''ve entered is invalid.', mtWarning, [mbOK], 0);
82
  end else
83
    lbHue.ItemIndex := hueID;
84
end;
85
86
procedure TfrmHueSettings.FormCreate(Sender: TObject);
87
var
88
  i: Integer;
89
  hue: THue;
90
begin
91
  lbHue.Clear;
92
  lbHue.Items.Add('$0 (no hue)');
93
  for i := 1 to ResMan.Hue.Count do
94
  begin
95
    hue := ResMan.Hue.Hues[i-1];
96
    lbHue.Items.AddObject(Format('$%x (%s)', [i, hue.Name]), hue);
97
  end;
98
  lbHue.ItemIndex := 0;
99
end;
100
101
procedure TfrmHueSettings.FormDeactivate(Sender: TObject);
102
begin
103
  Close;
104
end;
105
106
procedure TfrmHueSettings.lbHueDrawItem(Control: TWinControl; Index: Integer;
107
  ARect: TRect; State: TOwnerDrawState);
108
var
109
  hue: THue;
110
begin
111
  if Index > 0 then
112
    hue := ResMan.Hue.Hues[Index-1]
113
  else
114
    hue := nil;
115
  DrawHue(hue, lbHue.Canvas, ARect, lbHue.Items.Strings[Index]);
116
end;
117
118
procedure TfrmHueSettings.lbHueSelectionChange(Sender: TObject; User: boolean);
119
begin
120
  edHue.Text := Format('$%x', [lbHue.ItemIndex]);
121
end;
122
123
procedure TfrmHueSettings.MouseLeave(var msg: TLMessage);
124
begin
125
  try
126
    if not PtInRect(ClientRect, ScreenToClient(Mouse.CursorPos)) then
127
      Close;
128
  except
129
    Close;
130
  end;
131
end;
132
133
class procedure TfrmHueSettings.DrawHue(AHue: THue; ACanvas: TCanvas; ARect: TRect;
134
  ACaption: string);
135
var
136
  hueColor: TColor;
137
  i: Integer;
138
begin
139
  ACanvas.Pen.Color := clWhite;
140
  ACanvas.Rectangle(ARect);
141
  if AHue <> nil then
142
    for i := 0 to 31 do
143
    begin
144
      hueColor := ARGB2RGB(AHue.ColorTable[i]);
145
      ACanvas.Pen.Color := hueColor;
146
      ACanvas.MoveTo(ARect.Left + 2 + i, ARect.Top + 1);
147
      ACanvas.LineTo(ARect.Left + 2 + i, ARect.Bottom - 1);
148
    end;
149
  ACanvas.TextOut(ARect.Left + 36, ARect.Top, ACaption);
150
end;
151
152
initialization
153
  {$I UfrmHueSettings.lrs}
154
155
end.
156