Changeset 21 for branches


Ignore:
Timestamp:
Dec 29, 2018, 10:12:23 PM (6 years ago)
Author:
chronos
Message:
  • Added: Adjustable form size by dragging its border.
  • Added: Basic controls inside form like button, edit, title.
Location:
branches/overos
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/overos

    • Property svn:ignore set to
      overos
      lib
      overos.lps
      overos.res
  • branches/overos/UFormMain.pas

    r20 r21  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    9   UWindow, USystem, UTypes, UMouse;
     9  UWindow, USystem, UTypes, UMouse, UGraphics, UControls;
    1010
    1111type
     
    8989begin
    9090  Caption := IntToStr(X) + ',' + IntToStr(Y);
    91   System.Mouse.Move(TPosition.Create(Mouse.CursorPos.X, Mouse.CursorPos.Y));
     91  System.Mouse.Move(TPosition.Create(X, Y));
    9292end;
    9393
     
    117117var
    118118  Window: TWindow;
     119  Button: TButton;
    119120begin
    120121  System := TSystem.Create;
     
    129130  Window.Rectangle.Position := TPosition.Create(100, 50);
    130131  Window.Rectangle.Size := TSize.Create(400, 200);
     132  Button := TButton.Create;
     133  Button.Rectangle := TRectangle.Create(TPosition.Create(10, 50), TSize.Create(100, 32));
     134  Button.ParentControl := Window;
     135  Button.Title := 'Click';
     136  Button.Visible := True;
    131137
    132138  Window := System.Screen.CreateWindow('Calculator');
  • branches/overos/UTypes.pas

    r20 r21  
    1616    Height: Integer;
    1717    function Create(Width, Height: Integer): TSize;
     18    class operator Add(A, B: TSize): TSize;
     19    class operator Subtract(A, B: TSize): TSize;
    1820  end;
    1921
     
    3638    function Contains(Position: TPosition): Boolean;
    3739  end;
    38 
    39   TColor = Integer;
    4040
    4141
     
    8686end;
    8787
     88class operator TSize.Add(A, B: TSize): TSize;
     89begin
     90  Result.Width := A.Width + B.Width;
     91  Result.Height := A.Height + B.Height;
     92end;
     93
     94class operator TSize.Subtract(A, B: TSize): TSize;
     95begin
     96  Result.Width := A.Width - B.Width;
     97  Result.Height := A.Height - B.Height;
     98end;
     99
    88100
    89101end.
  • branches/overos/UWindow.pas

    r20 r21  
    66
    77uses
    8   Classes, SysUtils, fgl, UTypes, UMouse;
     8  Classes, SysUtils, fgl, UTypes, UMouse, UControls, UGraphics;
    99
    1010type
    11   { TCanvas }
    12 
    13   TCanvas = class
    14     procedure DrawLine(P1, P2: TPosition; Color: TColor); virtual;
    15     procedure DrawFrame(Rect: TRectangle; Color: TColor); virtual;
    16     procedure DrawArea(Rect: TRectangle; Color: TColor); virtual;
    17     procedure DrawText(P: TPosition; Color: TColor; Text: string); virtual;
    18   end;
    19 
    2011  TScreen = class;
    2112  TWindow = class;
     
    3021  end;
    3122
     23  TWindowSide = (wsNone, wsLeft, wsTop, wsRight, wsBottom);
     24
    3225  { TWindow }
    3326
    34   TWindow = class
    35   private
    36     FVisible: Boolean;
    37     procedure MouseButtonDown(Pos: TPosition; Button: TMouseButton);
    38     procedure MouseButtonUp(Pos: TPosition; Button: TMouseButton);
    39     procedure MouseMove(Pos: TPosition);
    40     procedure SetVisible(AValue: Boolean);
     27  TWindow = class(TControl)
    4128  public
    42     Canvas: TCanvas;
     29  const
     30    TitleHeight = 32;
     31    BorderGrabWidth = 15;
     32  var
    4333    Title: string;
    44     Rectangle: TRectangle;
    4534    Screen: TScreen;
    4635    procedure Focus;
    47     procedure Paint;
     36    procedure Paint; override;
    4837    function Focused: Boolean;
    49     property Visible: Boolean read FVisible write SetVisible;
    50     constructor Create;
     38    constructor Create; override;
    5139    destructor Destroy; override;
    5240  end;
     
    5745  private
    5846    FMouse: TMouse;
     47    GrabActive: Boolean;
     48    GrabWindow: TWindow;
     49    GrabMousePosition: TPosition;
     50    GrabWindowRectangle: TRectangle;
     51    GrabWindowSide: TWindowSide;
    5952    procedure MouseButtonDown(Pos: TPosition; Button: TMouseButton);
    6053    procedure MouseButtonUp(Pos: TPosition; Button: TMouseButton);
     
    7265  end;
    7366
    74 const
    75   clBlack = $000000;
    76   clGray = $808080;
    77   clWhite = $ffffff;
    7867
    7968implementation
    80 
    81 { TCanvas }
    82 
    83 procedure TCanvas.DrawLine(P1, P2: TPosition; Color: TColor);
    84 begin
    85 end;
    86 
    87 procedure TCanvas.DrawFrame(Rect: TRectangle; Color: TColor);
    88 begin
    89   with Rect do begin
    90     DrawLine(Position, Position + TPosition.Create(Size.Width, 0), Color);
    91     DrawLine(Position + TPosition.Create(Size.Width, 0), Position + TPosition.Create(Size.Width, Size.Height), Color);
    92     DrawLine(Position + TPosition.Create(Size.Width, Size.Height), Position + TPosition.Create(0, Size.Height), Color);
    93     DrawLine(Position + TPosition.Create(0, Size.Height), Position, Color);
    94   end;
    95 end;
    96 
    97 procedure TCanvas.DrawArea(Rect: TRectangle; Color: TColor);
    98 begin
    99 end;
    100 
    101 procedure TCanvas.DrawText(P: TPosition; Color: TColor; Text: string);
    102 begin
    103 end;
    10469
    10570{ TCanvasWindow }
     
    12287
    12388{ TWindow }
    124 
    125 procedure TWindow.MouseButtonDown(Pos: TPosition; Button: TMouseButton);
    126 begin
    127   Focus;
    128 end;
    129 
    130 procedure TWindow.MouseButtonUp(Pos: TPosition; Button: TMouseButton);
    131 begin
    132 
    133 end;
    134 
    135 procedure TWindow.MouseMove(Pos: TPosition);
    136 begin
    137 
    138 end;
    139 
    140 procedure TWindow.SetVisible(AValue: Boolean);
    141 begin
    142   if FVisible = AValue then Exit;
    143   FVisible := AValue;
    144   Paint;
    145 end;
    14689
    14790procedure TWindow.Focus;
     
    15497
    15598procedure TWindow.Paint;
    156 const
    157   TitleHeight = 32;
    15899begin
    159100  Canvas.DrawArea(TRectangle.Create(TPosition.Create(0, 0), Rectangle.Size), clGray);
     
    162103    TPosition.Create(Rectangle.Size.Width, TitleHeight), clWhite);
    163104  Canvas.DrawText(TPosition.Create(8, 4), clWhite, Title);
     105  inherited;
    164106end;
    165107
     
    171113constructor TWindow.Create;
    172114begin
     115  inherited;
     116  Canvas.Free;
    173117  Canvas := TCanvasWindow.Create;
    174118  TCanvasWindow(Canvas).Window := Self;
     
    177121destructor TWindow.Destroy;
    178122begin
    179   Canvas.Free;
    180123  inherited Destroy;
    181124end;
     
    188131  Window: TWindow;
    189132begin
     133  for I := Windows.Count - 1 downto 0 do begin
     134    Window := Windows[I];
     135    if TRectangle.Create(Window.Rectangle.Position - TPosition.Create(Window.BorderGrabWidth div 2, 0),
     136    TSize.Create(Window.BorderGrabWidth, Window.Rectangle.Size.Height)).Contains(Pos) then begin
     137      GrabMousePosition := Pos;
     138      GrabWindowRectangle := Window.Rectangle;
     139      GrabWindow := Window;
     140      GrabWindowSide := wsLeft;
     141      GrabActive := True;
     142    end else
     143    if TRectangle.Create(Window.Rectangle.Position - TPosition.Create(0, Window.BorderGrabWidth div 2),
     144    TSize.Create(Window.Rectangle.Size.Width, Window.BorderGrabWidth)).Contains(Pos) then begin
     145      GrabMousePosition := Pos;
     146      GrabWindowRectangle := Window.Rectangle;
     147      GrabWindow := Window;
     148      GrabWindowSide := wsTop;
     149      GrabActive := True;
     150    end else
     151    if TRectangle.Create(Window.Rectangle.Position + TPosition.Create(Window.Rectangle.Size.Width, 0) - TPosition.Create(Window.BorderGrabWidth div 2, 0),
     152    TSize.Create(Window.BorderGrabWidth, Window.Rectangle.Size.Height)).Contains(Pos) then begin
     153      GrabMousePosition := Pos;
     154      GrabWindowRectangle := Window.Rectangle;
     155      GrabWindow := Window;
     156      GrabWindowSide := wsRight;
     157      GrabActive := True;
     158    end else
     159    if TRectangle.Create(Window.Rectangle.Position + TPosition.Create(0, Window.Rectangle.Size.Height) - TPosition.Create(0, Window.BorderGrabWidth div 2),
     160    TSize.Create(Window.Rectangle.Size.Width, Window.BorderGrabWidth)).Contains(Pos) then begin
     161      GrabMousePosition := Pos;
     162      GrabWindowRectangle := Window.Rectangle;
     163      GrabWindow := Window;
     164      GrabWindowSide := wsBottom;
     165      GrabActive := True;
     166    end else
     167    if TRectangle.Create(Window.Rectangle.Position, TSize.Create(Window.Rectangle.Size.Width, Window.TitleHeight)).Contains(Pos) then begin
     168      GrabMousePosition := Pos;
     169      GrabWindowRectangle := Window.Rectangle;
     170      GrabWindow := Window;
     171      GrabWindowSide := wsNone;
     172      GrabActive := True;
     173    end;
     174    if Window.Rectangle.Contains(Pos) then begin
     175      Window.Focus;
     176      Window.MouseButtonDown(Pos - Window.Rectangle.Position, Button);
     177      Break;
     178    end;
     179  end;
     180end;
     181
     182procedure TScreen.MouseButtonUp(Pos: TPosition; Button: TMouseButton);
     183var
     184  I: Integer;
     185  Window: TWindow;
     186begin
     187  if GrabActive then begin
     188    GrabActive := False;
     189    GrabWindow := nil;
     190  end;
    190191  for I := Windows.Count - 1 downto 0 do begin
    191192    Window := Windows[I];
    192193    if Window.Rectangle.Contains(Pos) then begin
    193       Window.MouseButtonDown(Pos - Window.Rectangle.Position, Button);
     194      Window.MouseButtonUp(Pos - Window.Rectangle.Position, Button);
    194195      Break;
    195196    end;
     
    197198end;
    198199
    199 procedure TScreen.MouseButtonUp(Pos: TPosition; Button: TMouseButton);
    200 var
    201   I: Integer;
    202 begin
    203   for I := Windows.Count - 1 downto 0 do begin
    204     if Windows[I].Rectangle.Contains(Pos) then begin
    205       Windows[I].MouseButtonUp(Pos - Windows[I].Rectangle.Position, Button);
    206       Break;
    207     end;
    208   end;
    209 end;
    210 
    211200procedure TScreen.MouseMove(Pos: TPosition);
    212201var
    213202  I: Integer;
    214203begin
     204  if GrabActive then begin
     205    if GrabWindowSide = wsNone then
     206      GrabWindow.Rectangle.Position := GrabWindowRectangle.Position + (Pos - GrabMousePosition)
     207    else if GrabWindowSide = wsLeft then
     208      GrabWindow.Rectangle := TRectangle.Create(GrabWindowRectangle.Position + TPosition.Create(Pos.Left - GrabMousePosition.Left, 0),
     209        GrabWindowRectangle.Size - TSize.Create(Pos.Left - GrabMousePosition.Left, 0))
     210    else if GrabWindowSide = wsTop then
     211      GrabWindow.Rectangle := TRectangle.Create(GrabWindowRectangle.Position + TPosition.Create(0, Pos.Top - GrabMousePosition.Top),
     212        GrabWindowRectangle.Size - TSize.Create(0, Pos.Top - GrabMousePosition.Top))
     213    else if GrabWindowSide = wsRight then
     214      GrabWindow.Rectangle := TRectangle.Create(GrabWindowRectangle.Position,
     215        GrabWindowRectangle.Size + TSize.Create(Pos.Left - GrabMousePosition.Left, 0))
     216    else if GrabWindowSide = wsBottom then
     217      GrabWindow.Rectangle := TRectangle.Create(GrabWindowRectangle.Position,
     218        GrabWindowRectangle.Size + TSize.Create(0, Pos.Top - GrabMousePosition.Top));
     219    Paint;
     220  end;
    215221  for I := Windows.Count - 1 downto 0 do begin
    216222    if Windows[I].Rectangle.Contains(Pos) then begin
  • branches/overos/overos.lpi

    r20 r21  
    2727      </Item1>
    2828    </RequiredPackages>
    29     <Units Count="6">
     29    <Units Count="8">
    3030      <Unit0>
    3131        <Filename Value="overos.lpr"/>
     
    5555        <IsPartOfProject Value="True"/>
    5656      </Unit5>
     57      <Unit6>
     58        <Filename Value="UControls.pas"/>
     59        <IsPartOfProject Value="True"/>
     60      </Unit6>
     61      <Unit7>
     62        <Filename Value="UGraphics.pas"/>
     63        <IsPartOfProject Value="True"/>
     64      </Unit7>
    5765    </Units>
    5866  </ProjectOptions>
  • branches/overos/overos.lpr

    r20 r21  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UFormMain, UWindow, UMouse, USystem, UTypes
     10  Forms, UFormMain, UWindow, UMouse, USystem, UTypes, UControls, UGraphics
    1111  { you can add units after this };
    1212
Note: See TracChangeset for help on using the changeset viewer.