Changeset 20


Ignore:
Timestamp:
May 6, 2013, 12:16:30 AM (12 years ago)
Author:
chronos
Message:
  • Modified: Improved messages passing to controls.
  • Modified: Now TButton change background color during mouse click.
Location:
branches/Xvcl
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/Xvcl

    • Property svn:ignore
      •  

        old new  
        22*.local
        33Win32
         4__history
  • branches/Xvcl/Drivers

    • Property svn:ignore set to
      __history
  • branches/Xvcl/Drivers/Driver.MouseVCL.pas

    r19 r20  
    2424  Shift: TShiftState; X, Y: Integer);
    2525begin
    26   Kernel.Mouse.HandleClick(TPoint.Create(X, Y));
     26  Kernel.Mouse.HandleDown(TPoint.Create(X, Y));
    2727end;
    2828
     
    3030  Shift: TShiftState; X, Y: Integer);
    3131begin
    32 
     32  Kernel.Mouse.HandleUp(TPoint.Create(X, Y));
    3333end;
    3434
  • branches/Xvcl/Drivers/Driver.VideoVCL.pas

    r19 r20  
    44
    55uses
    6   Vcl.Forms, Vcl.Graphics, UFormMain, Xvcl.Classes, Xvcl.Kernel, Xvcl.Graphics;
     6  Vcl.Forms, Vcl.Graphics, System.Types, UFormMain, Xvcl.Classes, Xvcl.Kernel,
     7  Xvcl.Graphics;
    78
    89type
     
    1617    CanvasVCL: Vcl.Graphics.TCanvas;
    1718    function ColorToVCL(Color: TColor): Vcl.Graphics.TColor;
     19    procedure FillRect(Rect: TRectangle; Color: TColor); override;
    1820    procedure Line(Pos1, Pos2: TPoint; Color: TColor); override;
    1921    procedure TextOut(Position: TPoint; Text: string); override;
     
    6264end;
    6365
     66procedure TVideoDeviceVCL.FillRect(Rect: TRectangle; Color: TColor);
     67begin
     68  inherited;
     69  CanvasVCL.Brush.Color := ColorToVCL(Color);
     70  CanvasVCL.FillRect(System.Types.Rect(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom));
     71end;
     72
    6473function TVideoDeviceVCL.GetTextSize(Text: string): TPoint;
    6574begin
     
    7685procedure TVideoDeviceVCL.TextOut(Position: TPoint; Text: string);
    7786begin
     87  CanvasVCL.Brush.Color := clNone;
    7888  CanvasVCL.TextOut(Position.X, Position.Y, Text);
    7989end;
  • branches/Xvcl/Xvcl.Classes.pas

    r19 r20  
    2121    function GetBottomLeft: TPoint;
    2222    function GetBottomRight: TPoint;
    23     function GetLeftTop: TPoint;
    24     function GetRightTop: TPoint;
     23    function GetTopLeft: TPoint;
     24    function GetTopRight: TPoint;
     25    procedure SetTopLeft(const Value: TPoint);
     26    procedure SetBottomRight(const Value: TPoint);
     27    procedure SetBottom(const Value: Integer);
     28    procedure SetRight(const Value: Integer);
     29    procedure SetTopRight(const Value: TPoint);
    2530  public
    2631    Left: Integer;
     
    2833    Width: Integer;
    2934    Height: Integer;
    30     property Right: Integer read GetRight;
    31     property Bottom: Integer read GetBottom;
     35    property Right: Integer read GetRight write SetRight;
     36    property Bottom: Integer read GetBottom write SetBottom;
    3237    property Size: TPoint read GetSize;
    3338    property Position: TPoint read GetPosition;
    34     property LeftTop: TPoint read GetLeftTop;
    35     property BottomRight: TPoint read GetBottomRight;
    36     property RightTop: TPoint read GetRightTop;
     39    property TopLeft: TPoint read GetTopLeft write SetTopLeft;
     40    property BottomRight: TPoint read GetBottomRight write SetBottomRight;
     41    property TopRight: TPoint read GetTopRight write SetTopRight;
    3742    property BottomLeft: TPoint read GetBottomLeft;
    3843    constructor Create(Left, Top, Width, Height: Integer);
     
    8691end;
    8792
    88 function TRectangle.GetLeftTop: TPoint;
     93function TRectangle.GetTopLeft: TPoint;
    8994begin
    9095  Result := TPoint.Create(Left, Top);
     
    101106end;
    102107
    103 function TRectangle.GetRightTop: TPoint;
     108function TRectangle.GetTopRight: TPoint;
    104109begin
    105110  Result := TPoint.Create(Right, Top);
     111end;
     112
     113procedure TRectangle.SetBottom(const Value: Integer);
     114begin
     115  Height := Value - Top;
     116end;
     117
     118procedure TRectangle.SetBottomRight(const Value: TPoint);
     119begin
     120  Right := Value.X;
     121  Bottom := Value.Y;
     122end;
     123
     124procedure TRectangle.SetRight(const Value: Integer);
     125begin
     126  Width := Value - Left;
     127end;
     128
     129procedure TRectangle.SetTopLeft(const Value: TPoint);
     130begin
     131  Left := Value.X;
     132  Top := Value.Y;
     133end;
     134
     135procedure TRectangle.SetTopRight(const Value: TPoint);
     136begin
     137  Top := Value.X;
     138  Right := Value.Y;
    106139end;
    107140
  • branches/Xvcl/Xvcl.Controls.pas

    r19 r20  
    99  TControl = class;
    1010  TWinControl = class;
     11
     12  TMessage = class
     13    Number: Integer;
     14    Handled: Boolean;
     15  end;
     16
     17  TMouseButton = (mbLeft, mbRight, mbMiddle);
     18  TMouseButtonSet = set of TMouseButton;
     19  TMessageMouse = class(TMessage)
     20    Position: TPoint;
     21    Buttons: TMouseButtonSet;
     22  end;
     23  TMessageMouseDown = class(TMessageMouse);
     24  TMessageMouseUp = class(TMessageMouse);
     25
     26  TKeyState = (ksShift, ksAlt, ksOS);
     27  TKeyStateSet = set of TKeyState;
     28  TMessageKeyboard = class(TMessage)
     29    KeyCode: Integer;
     30    States: TKeyStateSet;
     31  end;
    1132
    1233  TControlCanvas = class(TCanvas)
     
    2546    FBounds: TRectangle;
    2647    FOnClick: TNotifyEvent;
     48    FColor: TColor;
     49    FOnMouseDown: TNotifyEvent;
     50    FOnMouseUp: TNotifyEvent;
    2751    function GetCanvas: TCanvas;
    2852    procedure SetParent(const Value: TWinControl); virtual;
     53    procedure SetColor(const Value: TColor);
    2954  protected
    3055    function GetVideoDevice: TVideoDevice; virtual;
    3156  public
    3257    Controls: TList<TControl>;
     58    function HandleMessage(Message: TMessage): Boolean; virtual;
    3359    function ClientToScreen(Position: TPoint): TPoint; virtual;
     60    function ScreenToClient(Position: TPoint): TPoint; virtual;
    3461    procedure Paint; virtual;
    3562    constructor Create; override;
     
    4067    property Parent: TWinControl read FParent write SetParent;
    4168    property VideoDevice: TVideoDevice read GetVideoDevice;
     69    property Color: TColor read FColor write SetColor;
    4270    property OnClick: TNotifyEvent read FOnClick write FOnClick;
     71    property OnMouseDown: TNotifyEvent read FOnMouseDown write FOnMouseDown;
     72    property OnMouseUp: TNotifyEvent read FOnMouseUp write FOnMouseUp;
    4373  end;
    4474
    4575  TWinControl = class(TControl)
     76  protected
     77  public
    4678    Controls: TList<TControl>;
    47     function HandleClick(Position: TPoint): Boolean;
     79    function HandleMessage(Message: TMessage): Boolean; override;
    4880    constructor Create; override;
    4981    destructor Destroy; override;
     
    5688  public
    5789    procedure Paint; override;
     90    constructor Create; override;
    5891    property Caption: string read FCaption write SetCaption;
    5992  end;
     
    75108function TControl.ClientToScreen(Position: TPoint): TPoint;
    76109begin
    77   Result := TPoint.Create(Bounds.Left + Position.X, Bounds.Top + Position.Y);
     110  Result := Position.Add(Bounds.TopLeft);
    78111  if Assigned(Parent) then Result := Parent.ClientToScreen(Result);
    79112end;
     
    107140end;
    108141
     142function TControl.HandleMessage(Message: TMessage): Boolean;
     143begin
     144  if Message is TMessageMouseDown then begin
     145    if Assigned(FOnMouseDown) then FOnMouseDown(Self);
     146    Color := clGray;
     147    Paint;
     148  end else
     149  if Message is TMessageMouseUp then begin
     150    if Assigned(FOnMouseUp) then FOnMouseUp(Self);
     151    Color := clSilver;
     152    Paint;
     153    if Assigned(FOnClick) then FOnClick(Self);
     154  end;
     155end;
     156
    109157procedure TControl.Paint;
    110158var
     
    112160begin
    113161  for C in Controls do C.Paint;
     162end;
     163
     164function TControl.ScreenToClient(Position: TPoint): TPoint;
     165begin
     166  Result := Position.Substract(Bounds.TopLeft);
     167  if Assigned(Parent) then Result := Parent.ClientToScreen(Result);
     168end;
     169
     170procedure TControl.SetColor(const Value: TColor);
     171begin
     172  if FColor <> Value then begin
     173    FColor := Value;
     174    Paint;
     175  end;
    114176end;
    115177
     
    125187{ TButton }
    126188
     189constructor TButton.Create;
     190begin
     191  inherited;
     192  FColor := clSilver;
     193end;
     194
    127195procedure TButton.Paint;
    128196begin
    129197  inherited;
    130198  with Canvas do begin
     199    Brush.Color := Color;
     200    FillRect(TRectangle.Create(0, 0, Bounds.Width, Bounds.Height));
    131201    MoveTo(TPoint.Create(0, 0));
    132202    LineTo(TPoint.Create(Bounds.Width - 1, 0));
     
    176246end;
    177247
    178 function TWinControl.HandleClick(Position: TPoint): Boolean;
     248function TWinControl.HandleMessage(Message: TMessage): Boolean;
    179249var
    180250  Control: TControl;
     
    182252  Result := False;
    183253  for Control in Controls do begin
    184     if Control.Bounds.Contains(Position) then begin
    185       if Control is TWinControl then begin
    186         if TWinControl(Control).HandleClick(Position.Substract(Bounds.LeftTop)) then begin
    187           Result := True;
    188           Break;
    189         end;
    190       end else
    191       if Assigned(Control.OnClick) then begin
    192         Control.OnClick(Self);
     254    if Message is TMessageMouse then
     255    with TMessageMouse(Message) do begin
     256    if Control.Bounds.Contains(ScreenToClient(Position)) then begin
     257      if TWinControl(Control).HandleMessage(Message) then begin
    193258        Result := True;
    194259        Break;
     
    196261    end;
    197262  end;
     263  end;
    198264end;
    199265
  • branches/Xvcl/Xvcl.Graphics.pas

    r19 r20  
    2525  TVideoDevice = class
    2626    Size: TPoint;
     27    procedure FillRect(Rect: TRectangle; Color: TColor); virtual;
    2728    procedure Line(Pos1, Pos2: TPoint; Color: TColor); virtual;
    2829    procedure SetPixel(Position: TPoint; Color: TColor); virtual;
     
    4950    procedure SetPixel(Position: TPoint; Color: TColor);
    5051    function GetPixel(Position: TPoint): TColor;
     52    procedure FillRect(Rect: TRectangle);
    5153    constructor Create;
    5254    destructor Destroy; override;
     
    9092  FPen.Destroy;
    9193  inherited;
     94end;
     95
     96procedure TCanvas.FillRect(Rect: TRectangle);
     97begin
     98  Rect.TopLeft := AdjustPos(Rect.TopLeft);
     99  if Assigned(VideoDevice) then VideoDevice.FillRect(Rect, Brush.Color);
    92100end;
    93101
     
    152160{ TVideoDevice }
    153161
     162procedure TVideoDevice.FillRect(Rect: TRectangle; Color: TColor);
     163begin
     164
     165end;
     166
    154167function TVideoDevice.GetPixel(Position: TPoint): TColor;
    155168begin
  • branches/Xvcl/Xvcl.Kernel.pas

    r19 r20  
    4545  TMouse = class
    4646    Kernel: TKernel;
    47     procedure HandleClick(Position: TPoint);
     47    procedure HandleDown(Position: TPoint);
     48    procedure HandleUp(Position: TPoint);
    4849  end;
    4950
     
    199200{ TMouse }
    200201
    201 procedure TMouse.HandleClick(Position: TPoint);
     202procedure TMouse.HandleDown(Position: TPoint);
    202203var
    203204  Form: TForm;
    204 begin
    205   for Form in Kernel.Screen.Forms do begin
    206     Form.HandleClick(Position.Substract(Form.Bounds.LeftTop));
     205  NewMessage: TMessageMouse;
     206begin
     207  NewMessage := TMessageMouseDown.Create;
     208  NewMessage.Position := Position;
     209  try
     210    for Form in Kernel.Screen.Forms do begin
     211      if Form.HandleMessage(NewMessage) then begin
     212        Break;
     213      end;
     214    end;
     215  finally
     216    NewMessage.Destroy;
     217  end;
     218end;
     219
     220procedure TMouse.HandleUp(Position: TPoint);
     221var
     222  Form: TForm;
     223  NewMessage: TMessageMouse;
     224begin
     225  NewMessage := TMessageMouseUp.Create;
     226  NewMessage.Position := Position;
     227  try
     228    for Form in Kernel.Screen.Forms do begin
     229      if Form.HandleMessage(NewMessage) then begin
     230        Break;
     231      end;
     232    end;
     233  finally
     234    NewMessage.Destroy;
    207235  end;
    208236end;
Note: See TracChangeset for help on using the changeset viewer.