Changeset 24


Ignore:
Timestamp:
May 8, 2013, 2:53:22 PM (11 years ago)
Author:
chronos
Message:
  • Fixed: Make only one form focused at once.
  • Modified: Enhanced TList generic class to support more methods.
Location:
branches/Xvcl
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/Xvcl/Applications/TestApplication.pas

    r23 r24  
    3333begin
    3434  Form1 := TForm.Create;
    35   Form1.Bounds := TRectangle.Create(50, 50, 100, 100);
     35  Form1.Bounds := TRectangle.Create(50, 80, 200, 120);
    3636  Form1.Name := 'Form1';
    3737  Form1.Caption := 'Test application';
    3838  Form1.Screen := Screen;
    3939  Form2 := TForm.Create;
    40   Form2.Bounds := TRectangle.Create(250, 150, 200, 150);
    41   Form2.Name := 'Form1';
    42   Form2.Caption := 'Test application';
     40  Form2.Bounds := TRectangle.Create(350, 150, 200, 150);
     41  Form2.Name := 'Form2';
     42  Form2.Caption := 'Some form';
    4343  Form2.Screen := Screen;
    4444  Button := TButton.Create;
     
    5151  Label1 := TLabel.Create;
    5252  Label1.Parent := Form1;
    53   Label1.Bounds := TRectangle.Create(50, 70, 60, 24);
     53  Label1.Bounds := TRectangle.Create(60, 80, 60, 24);
    5454  Label1.Visible := True;
    5555  Label1.Caption := '0';
    5656  Form1.Controls.Add(Label1);
    57   Form2.Controls.Add(Label1);
    5857  TScreen(Screen).Forms.Add(Form1);
     58  TScreen(Screen).Forms.Add(Form2);
    5959  TScreen(Screen).Paint;
    6060end;
  • branches/Xvcl/Drivers/Driver.VideoVCL.pas

    r23 r24  
    55uses
    66  Vcl.Forms, Vcl.Graphics, System.Types, UFormMain, Xvcl.Classes, Xvcl.Kernel,
    7   Xvcl.Graphics;
     7  Xvcl.Graphics, Generics.Collections;
    88
    99type
     
    6363    clSilver: Result := $c0c0c0;
    6464    clGray: Result := $808080;
    65     clLightBlue: Result := $ff8080;
    66     clLightRed: Result := $80ff80;
    67     clLightGreen: Result := $8080ff;
     65    clLightBlue: Result := $ffb0b0;
     66    clLightRed: Result := $b0ffb0;
     67    clLightGreen: Result := $b0b0ff;
    6868    clBrown: Result := $a52a2a;
    6969    clMagenta: Result := $ff00ff;
  • branches/Xvcl/Xvcl.Controls.pas

    r23 r24  
    125125  inherited;
    126126  Move := TControlMove.Create;
     127  FColor := clWhite;
    127128end;
    128129
     
    169170procedure TControl.Paint;
    170171begin
     172  with Canvas do begin
     173    Brush.Color := Color;
     174    FillRect(TRectangle.Create(0, 0, Bounds.Width, Bounds.Height));
     175  end;
    171176end;
    172177
     
    206211  inherited;
    207212  with Canvas do begin
    208     Brush.Color := Color;
    209     FillRect(TRectangle.Create(0, 0, Bounds.Width, Bounds.Height));
    210213    MoveTo(TPoint.Create(0, 0));
    211214    LineTo(TPoint.Create(Bounds.Width - 1, 0));
  • branches/Xvcl/Xvcl.Forms.pas

    r23 r24  
    6666  with TMessageMouseDown(Message) do begin
    6767    TitleBarBounds := TRectangle.Create(0, 0, Bounds.Width, TitleBarHeight);
     68    Focused := True;
    6869    if TitleBarBounds.Contains(ScreenToClient(Position)) then begin
    69       Focused := True;
    70       Result := True;
    7170      Move.StartControlPos := Bounds.TopLeft;
    7271      Move.StartMousePos := Position;
    7372      Move.Active := True;
     73     Result := True;
    7474    end;
    7575  end else
     
    9090procedure TForm.Paint;
    9191begin
     92  inherited;
    9293  with Canvas do begin
    93     Canvas.Brush.Color := clWhite;
    94     Canvas.FillRect(TRectangle.Create(0, TitleBarHeight, Size.X, Size.Y));
    9594    if Focused then Brush.Color := clLightBlue else
    9695      Brush.Color := clSilver;
     
    106105      (TitleBarHeight - GetTextSize(Caption).Y) div 2), Caption);
    107106  end;
    108   inherited;
    109107end;
    110108
    111109procedure TForm.SetFocused(const Value: Boolean);
    112110begin
    113   FFocused := Value;
    114   Paint;
     111  if FFocused <> Value then begin
     112    FFocused := Value;
     113    if Value then TScreen(Screen).FocusForm(Self);
     114  end;
    115115end;
    116116
  • branches/Xvcl/Xvcl.Generics.pas

    r23 r24  
    22
    33interface
     4
     5uses
     6  SysUtils;
    47
    58type
     
    2427    function GetEnumerator: TEnumerator;
    2528    function Add(Item: T): Integer;
    26     procedure Remove(Item: T);
     29    function Remove(Item: T): Integer;
     30    procedure Delete(Index: Integer);
     31    procedure Move(FromIndex, ToIndex: Integer);
     32    function IndexOf(Item: T): Integer;
     33    function Compare(Item1, Item2: T): Integer;
     34    procedure Exchange(Index1, Index2: Integer);
    2735    property Count: Integer read FCount write SetCount;
    2836    property Items[Index: Integer]: T read GetItem write SetItem; default;
     
    5563end;
    5664
     65function TList<T>.Compare(Item1, Item2: T): Integer;
     66begin
     67  if CompareMem(Pointer(@Item1), Pointer(@Item2), SizeOf(T)) then Result := 0
     68    else Result := -1;
     69end;
     70
     71procedure TList<T>.Delete(Index: Integer);
     72var
     73  I: Integer;
     74begin
     75  if (Index >= 0) and (Index < Count) then
     76  for I := Index to Count - 2 do
     77    Items[I] := Items[I + 1];
     78end;
     79
     80procedure TList<T>.Exchange(Index1, Index2: Integer);
     81var
     82  Temp: T;
     83begin
     84  Temp := Items[Index2];
     85  Items[Index2] := Items[Index1];
     86  Items[Index1] := Temp;
     87end;
     88
    5789function TList<T>.GetEnumerator: TEnumerator;
    5890begin
     
    6799end;
    68100
    69 procedure TList<T>.Remove(Item: T);
     101function TList<T>.IndexOf(Item: T): Integer;
     102var
     103  I: Integer;
    70104begin
     105  I := 0;
     106  while (I < Count) and (Compare(Items[I], Item) <> 0) do
     107    Inc(I);
     108  if I < Count then Result := I
     109    else Result := -1;
     110end;
    71111
     112procedure TList<T>.Move(FromIndex, ToIndex: Integer);
     113var
     114  I: Integer;
     115  Temp: T;
     116begin
     117  if (FromIndex >= 0) and (FromIndex < Count) and
     118  (ToIndex >= 0) and (ToIndex < Count) then begin
     119    if FromIndex > ToIndex then begin
     120      Temp := Items[ToIndex];
     121      for I := ToIndex to FromIndex - 1 do
     122        Items[I] := Items[I + 1];
     123      Items[FromIndex] := Temp;
     124    end else
     125    if FromIndex < ToIndex then begin
     126      Temp := Items[FromIndex];
     127      for I := FromIndex to ToIndex - 1 do
     128        Items[I] := Items[I + 1];
     129      Items[ToIndex] := Temp;
     130    end;
     131  end;
     132end;
     133
     134function TList<T>.Remove(Item: T): Integer;
     135begin
     136  Result := IndexOf(Item);
     137  if Result >= 0 then Delete(Result);
    72138end;
    73139
  • branches/Xvcl/Xvcl.Graphics.pas

    r23 r24  
    116116function TCanvas.GetVideoDevice: TVideoDevice;
    117117begin
    118   Result := FVideoDevice;
     118  Result := nil;
    119119end;
    120120
     
    139139begin
    140140  if Assigned(VideoDevice) then VideoDevice.SetPixel(Position, Color);
    141 end;
    142 
    143 procedure TCanvas.SetVideoDevice(const Value: TVideoDevice);
    144 begin
    145   FVideoDevice := Value;
    146141end;
    147142
  • branches/Xvcl/Xvcl.Kernel.pas

    r23 r24  
    3333
    3434  TScreen = class(TComponent)
    35     Canvas: TCanvas;
     35    Canvas: TScreenCanvas;
    3636    Size: TPoint;
    3737    Forms: TList<TForm>;
    3838    VideoDevice: TVideoDevice;
    3939    procedure Paint;
     40    procedure FocusForm(Form: TForm);
    4041    constructor Create; override;
    4142    destructor Destroy; override;
     
    152153  Forms := TList<TForm>.Create;
    153154  Canvas := TScreenCanvas.Create;
     155  Canvas.Screen := Self;
    154156end;
    155157
     
    159161  Forms.Destroy;
    160162  inherited;
     163end;
     164
     165procedure TScreen.FocusForm(Form: TForm);
     166var
     167  I: Integer;
     168  FormIndex: Integer;
     169begin
     170  FormIndex := Forms.IndexOf(Form);
     171  for I := 0 to Forms.Count - 1 do
     172    Forms[I].Focused := I = FormIndex;
     173
     174  Forms.Move(FormsIndex, Forms.Count - 1);
     175  Paint;
    161176end;
    162177
Note: See TracChangeset for help on using the changeset viewer.