A basic PTCGraph app framework lazarus / 21-General ---------------------------------------------------------------------- TBMan · 2025-01-30 20:07 I decided to recreate a GUI I had coded back in the 90's, but I'm keeping it very simple. Here's the code for a demo which runs using PTCGraph, PTCCrt and PTCmouse units. I did two types of "pushbuttons" : one that looks kinda sortof like a Windows 11 button and a button similar to the old windows style from many moons ago. This time around I'm using a linked list for pushbuttons. When I wrote my original GUI I just used an array of pointers. Both the "taskbar" object and "app" objects can have their own "pushbuttons." The taskbar is "owned" by the "app" in my code.  I think I'm going to see what I can do about the ptcgraph palette, maybe a program that allows modifications and saves/loads the palettes for changes.    You might be wondering why don't I just write Windows apps. Good question, but I sort of like not having to figure out why I can't change the color of a control and other odds and ends that seems to give people problems here. If I code the controls, then I know what is going on.  Once I get this out of my "system" I'll start playing around with the Windows framework. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode ObjFPC}{$H+} program LG_Demo; uses  ptcgraph,  ptcmouse,  ptccrt; const    Event_Quit = 2;    Event_Nothing = 3; type   trect = record    x1, y1,    x2, y2: integer;  end;    PLg_Object = ^Lg_Object;   Lg_Object = object  private    BoundarySet: boolean;  public    DrawColor: byte;    x, y: integer;    boundary: Trect;    constructor init(xx, yy: integer);    procedure SetBoundary(w, d: integer);    procedure Paint; virtual;    function handleevent(mxx, myy, mbb: longint): integer; virtual;    destructor done;  end;   PLG_Button = ^LG_Button;   LG_Button = object(LG_Object)  public    event_code: integer;    Pressed: boolean;    Txt: string;    Next: Plg_Button;    constructor InitButton(xx, yy: integer; Name: string; Id: integer);    function Handleevent(mxx, myy, mbb: longint): integer; virtual;    procedure Paint; virtual;  end;    PLG_WindowsButton = ^LG_WindowsButton;   LG_WindowsButton = object(LG_Button)    procedure paint; virtual;  end;    { This is a taskbar at the bottom of the screen}  { buttons added to the task bar have their locations   modified to fit in the task bar and their x location   is automatically adjusted. A side bar can be created   from this object by changing the addbutton. Maybe have   an Xincrease and Yincrease setup and if horizontal then   Yincrease := 0 and Xincrease is set to the amount and   the opposite for a vertical bar. You'd have to check for   clipping though if vertical}   PLG_TaskBar = ^LG_Taskbar;   LG_Taskbar = object(lg_object)    CurrentButton, FirstButton, LastButton: PLG_Button;    Fillcolor, buttonx, buttony: integer;    constructor InitTaskBar(xx, yy, w, d: integer);    procedure paint; virtual;    procedure Addbutton(P: Plg_Button); virtual;    destructor done; virtual;    function handleevent(mxx, myy, mbb: longint): integer; virtual;  end;    PLG_App = ^LG_App;   LG_App = object(LG_object)    CurrentButton, FirstButton, LastButton: PLG_Button;    Filled: boolean;    FillColor: integer;    Taskbar: PLG_Taskbar;    constructor initapp(xx, yy, w, d: integer);    procedure Addbutton(P: Plg_Button);    procedure Paint; virtual;    procedure Run; virtual;      {see lg_app.run for notes}    destructor done; virtual;  end;  { misc housekeeping}   function PositionInRect(PX, PY: integer; Rect: Trect): boolean;  begin     PositionInRect := (Px >= Rect.X1) and (Px <= Rect.X2) and      (Py >= Rect.Y1) and (PY <= Rect.Y2);   end;    procedure SetTRect(var T: Trect; X, Y, XX, YY: integer);  begin    with T do    begin      X1 := X;      Y1 := Y;      X2 := XX;      Y2 := YY;     end;   end;    {**********   LG_Object *************************}   constructor LG_Object.Init(xx, yy: integer);  begin    x := xx;    y := yy;    Boundaryset := False;    DrawColor := 7;  end;   procedure LG_Object.SetBoundary(w, d: integer);  begin    Boundaryset := True;  setTrect(Boundary, x, y, x + w, y + d);  end;   procedure LG_Object.Paint;  begin    if boundaryset then    begin      Setcolor(Drawcolor);      with boundary do rectangle(x1, y1, x2, y2);    end    else      outtextxy(x, y, 'boundary not set');  end;   function lg_Object.handleEvent(mxx, myy, mbb: longint): integer;  begin    Result := 0;  end;   destructor lg_object.done;  begin   end;  {***********  end LG_Object ****************}   {*********** LG_Button *********************}   constructor LG_Button.InitButton(xx, yy: integer; Name: string; id: integer);  var    w, d: integer;  begin    inherited init(xx, yy);    event_code := id;    Pressed := False;    Txt := Name;    w := textwidth(Txt) + 8;    d := textheight(txt) + 4;    Setboundary(w, d);  end;   procedure LG_Button.Paint;  begin    if not pressed then    begin    with boundary do      begin        setfillstyle(solidfill, 7);        bar(x1, y1, x2, y2);        Setcolor(15);        Rectangle(x1, y1, x2, y2);        Setcolor(0);        Line(x2, y1, x2, y2);        Line(x1, y2, x2, y2);        OutTextXY(x1 + 3, y1 + 3, Txt);      end;    end  else    begin      with boundary do      begin        setfillstyle(solidfill, 8);        bar(x1, y1, x2, y2);        Setcolor(8);        Rectangle(x1, y1, x2, y2);        Setcolor(0);      Line(x1, y1, x2, y1);        Line(x1, y1, x1, y2);        Setcolor(7);        OutTextXY(x1 + 4, y1 + 4, Txt);      end;    end;  end;    function Lg_Button.HandleEvent(mxx, myy, mbb: longint): integer;  begin    if lpressed then      if positioninrect(mxx, myy, boundary) then      begin        pressed := True;        paint;      pressed := False;        while lpressed do        begin        end;      paint;        Result := event_code;      end      else        Result := 0;  end;   {***************** end LG_Button *****************}    {**************** LG_WindowsButton ***************}  procedure LG_WindowsButton.Paint;  begin    if not pressed then    begin      with boundary do      begin        setfillstyle(solidfill, 15);        bar(x1, y1, x2, y2);        Setcolor(1);        Rectangle(x1, y1, x2, y2);        Setcolor(0);      OutTextXY(x1 + 3, y1 + 3, Txt);      end;    end    else    begin    with boundary do      begin        setfillstyle(solidfill, 11);      bar(x1, y1, x2, y2);        Setcolor(1);        Rectangle(x1, y1, x2, y2);        Setcolor(0);        OutTextXY(x1 + 3, y1 + 3, Txt);    end;    end;  end;   {*************  end LG_WindowsButton *************************}    {************** LG_Taskbar ***********************************}   constructor LG_Taskbar.InitTaskBar(xx, yy, w, d: integer);  begin    inherited init(xx, yy);    Setboundary(w, d);    Fillcolor := 53;    ButtonX := Boundary.x1 + 4;    ButtonY := boundary.y2 - 16;  end;   procedure LG_Taskbar.paint;  begin    with boundary do    begin      setfillstyle(solidfill, fillcolor);      bar(x1, y1, x2, y2);      setcolor(7);      rectangle(x1, y1, x2, y2);      setcolor(8);      line(x1, y2, x2, y2);      line(x2, y1, x2, y2);    end;    if firstbutton <> nil then    begin      currentbutton := firstbutton;    repeat        currentbutton^.paint;        currentbutton := currentbutton^.Next;      until currentbutton = nil;    end;   end;   function lg_taskbar.handleevent(mxx, myy, mbb: longint): integer;  var    id: integer;  begin    id := 0;    if firstbutton <> nil then  begin      currentbutton := firstbutton;      repeat        if Lpressed then if positioninrect(mxx, myy, boundary) then            id := CurrentButton^.handleevent(mxx, myy, mbb);        CurrentButton := CurrentButton^.Next;      until (currentbutton = nil) or (id <> 0);  end;    Result := id;  end;   procedure LG_Taskbar.AddButton(P: PLG_Button);  var    bw, bd: integer;  begin    if FirstButton = nil then    begin      FirstButton := P;      CurrentButton := P;      with currentButton^ do      begin        bd := boundary.y2 - boundary.y1;        bw := boundary.x2 - boundary.x1;      end;      CurrentButton^.x := ButtonX;      CurrentButton^.y := ButtonY;      CurrentButton^.Setboundary(bw, bd);      Inc(buttonx, bw + 4);    end    else    begin      CurrentButton^.Next := P;      CurrentButton := P;      with currentButton^ do      begin        bd := boundary.y2 - boundary.y1;        bw := boundary.x2 - boundary.x1;      end;      CurrentButton^.x := ButtonX;      CurrentButton^.y := ButtonY;      CurrentButton^.Setboundary(bw, bd);      Inc(buttonx, bw + 4);    end;    CurrentButton^.Next := nil;    LastButton := CurrentButton;  LastButton^.Next := nil;  end;   destructor lg_taskbar.done;  var    p: Plg_button;  begin    if firstbutton <> nil then    begin      CurrentButton := Firstbutton;      repeat        p := currentbutton^.Next;        dispose(currentbutton, done);        Currentbutton := P;      until currentbutton = nil;    end;  end;   {************  end LG_Taskbar *********************}   {************  LG_App *****************************}  constructor LG_App.Initapp(xx, yy, w, d: integer);  begin    inherited init(xx, yy);    Setboundary(w, d);    CurrentButton := nil;    FirstButton := nil;    LastButton := nil;    Fillcolor := 0;    Filled := False;  end;   destructor LG_App.done;  var    p: Plg_Button;  begin    if taskbar <> nil then dispose(taskbar, done);    if firstbutton <> nil then    begin      CurrentButton := Firstbutton;      repeat        p := currentbutton^.Next;        dispose(currentbutton, done);        Currentbutton := P;      until currentbutton = nil;    end;   end;   {this procedure should be copied then modified for new programs}   procedure LG_App.run;   var    Event: integer;    mx, my, mb: longint;    key: char;  begin    Event := 0;    currentbutton := firstbutton;    repeat      key := '~';      GetMouseState(mx, my, mb);      {check the taskbar first}      if taskbar <> nil then      if lpressed then          Event := Taskbar^.Handleevent(mx, my, mb);       if Event = 0 then        if currentbutton <> nil then        begin          if lpressed then Event := currentbutton^.handleevent(mx, my, mb);          Currentbutton := currentbutton^.Next;          if CurrentButton = nil then currentbutton := firstbutton;        end;       {this is the area to add behavior}    {case event of       end;     }      {if no buttons have an escape}      if keypressed then key := readkey;      case key of        'q', 'Q': Event := Event_quit;      end;    until Event = Event_Quit;   end;    procedure LG_App.AddButton(P: PLG_Button);  begin    if FirstButton = nil then    begin      FirstButton := P;    CurrentButton := P;    end    else    begin      CurrentButton^.Next := P;      CurrentButton := P;    end;    CurrentButton^.Next := nil;     LastButton := CurrentButton;    LastButton^.Next := nil;  end;   procedure LG_App.Paint;  begin     if filled then    begin    setfillstyle(solidfill, FillColor);      with boundary do      begin      Bar(x1, y1, x2, y2);        setcolor(DrawColor);        Rectangle(x1, y1, x2, y2);      end;    end    else      with boundary do      begin        setcolor(DrawColor);        Rectangle(x1, y1, x2, y2);      end;    if firstbutton <> nil then    begin      currentbutton := firstbutton;      repeat        currentbutton^.paint;        currentbutton := currentbutton^.Next;    until currentbutton = nil;    end;    if taskbar <> nil then Taskbar^.paint;  end;   {*************** end LG_App **********************} var   gmode, gdriver: smallint;  P: Plg_Object;  App: PLG_App;   begin  gdriver := vesa;  Gmode := installusermode(640, 480, 256, 1, 8000, 6000);  WindowTitle := 'LG_Object Library Demo';  initgraph(gdriver, gmode, '');  SetColor(7);   App := New(plg_app, initapp(0, 0, getmaxx, getmaxy));  App^.Taskbar := New(Plg_Taskbar, inittaskbar(1, getmaxy - 22, getmaxx - 2, 20));   App^.taskbar^.addbutton(New(Plg_WindowsButton, initbutton(1, 1, 'Does nothing', event_Nothing)));   App^.taskbar^.Addbutton(New(Plg_Button, initbutton(1,1, 'More nothing', Event_Nothing)));  App^.Taskbar^.addbutton(New(Plg_WindowsButton, initbutton(1,1, 'Quit', Event_Quit)));  App^.Filled := True;  App^.fillcolor := 3;  App^.paint;  initmouse;  showmouse;  App^.run;  dispose(App, done);  closegraph; end. ---------------------------------------------------------------------- ginoo · 2025-01-31 08:23 ---------------------------------------------------------------------- Roland57 · 2025-01-31 11:20 Nice! Thank you for sharing. Works perfectly under Linux, with this small modification. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses{$IFDEF LINUX}  cthreads,{$ENDIF} Please continue this project! Quote from: TBMan on January 30, 2025, 09:07:49 pmYou might be wondering why don't I just write Windows apps. For me, I rather wonder why you would just write Windows apps. ---------------------------------------------------------------------- gidesa · 2025-01-31 11:35 Excellent! Work well also on Windows 11. ---------------------------------------------------------------------- TRon · 2025-01-31 19:52 Very nice TBMan ! Some modification proposals/suggestions: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test; // Title  : A basic PTCGraph app framework// Date   : jan 2025// Author : TBMan// Mods   : Roland57, TRon// Ref.   : https://forum.laza rus.freepascal.org/index.php/topic,70041.0.html {$mode objfpc}{$h+}{$define typesrect}  // use type TRect from unit Types{$define fix}        // fix some issues // As an alternative there is also a TRect object, see:// https://www.freepascal.org/docs- html/rtl/objects/trect.html// though Types.TRect is a better fit imho. uses  {$ifdef fix}   {$ifdef unix}   cthreads,         // *nix based platforms require this   {$endif}  sysutils,  {$endif}   {$ifdef typesrect}  types,  {$endif}  ptcgraph,  ptcmouse,  ptccrt; const    Event_Quit = 2;    Event_Nothing = 3; type {$ifndef typesrect}  trect = record    x1, y1,    x2, y2: integer;  end;{$endif}   PLg_Object = ^Lg_Object;   Lg_Object = object  private    BoundarySet: boolean;  public    DrawColor: byte;    x, y: integer;    boundary: Trect;    constructor init(xx, yy: integer);    procedure SetBoundary(w, d: integer);    procedure Paint; virtual;    function handleevent(mxx, myy, mbb: longint): integer; virtual;    destructor done;  end;   PLG_Button = ^LG_Button;   LG_Button = object(LG_Object)  public    event_code: integer;    Pressed: boolean;    Txt: string;    Next: Plg_Button;    constructor InitButton(xx, yy: integer; Name: string; Id: integer);    function Handleevent(mxx, myy, mbb: longint): integer; virtual;    procedure Paint; virtual;  end;    PLG_WindowsButton = ^LG_WindowsButton;   LG_WindowsButton = object(LG_Button)    procedure paint; virtual;  end;    { This is a taskbar at the bottom of the screen}  { buttons added to the task bar have their locations   modified to fit in the task bar and their x location   is automatically adjusted. A side bar can be created   from this object by changing the addbutton. Maybe have   an Xincrease and Yincrease setup and if horizontal then   Yincrease := 0 and Xincrease is set to the amount and   the opposite for a vertical bar. You'd have to check for   clipping though if vertical}   PLG_TaskBar = ^LG_Taskbar;   LG_Taskbar = object(lg_object)    CurrentButton, FirstButton, LastButton: PLG_Button;    Fillcolor, buttonx, buttony: integer;    constructor InitTaskBar(xx, yy, w, d: integer);    procedure paint; virtual;    procedure Addbutton(P: Plg_Button); virtual;    destructor done; virtual;    function handleevent(mxx, myy, mbb: longint): integer; virtual;  end;    PLG_App = ^LG_App;   LG_App = object(LG_object)    CurrentButton, FirstButton, LastButton: PLG_Button;    Filled: boolean;    FillColor: integer;    Taskbar: PLG_Taskbar;    constructor initapp(xx, yy, w, d: integer);    procedure Addbutton(P: Plg_Button);    procedure Paint; virtual;    procedure Run; virtual;      {see lg_app.run for notes}    destructor done; virtual;  end;  { misc housekeeping} {$ifndef typesrect}  function PositionInRect(PX, PY: integer; Rect: Trect): boolean;  begin     PositionInRect := (Px >= Rect.X1) and (Px <= Rect.X2) and    (Py >= Rect.Y1) and (PY <= Rect.Y2);   end;     procedure SetTRect(var T: Trect; X, Y, XX, YY: integer);  begin    with T do    begin      X1 := X;      Y1 := Y;      X2 := XX;      Y2 := YY;     end;   end;{$endif}   {**********   LG_Object *************************}   constructor LG_Object.Init(xx, yy: integer);  begin    x := xx;    y := yy;    Boundaryset := False;    DrawColor := 7;  end;   procedure LG_Object.SetBoundary(w, d: integer);  begin    Boundaryset := True;    {$ifdef typesrect}    Boundary :=  bounds(x, y, w, d);    {$else}    setTrect(Boundary, x, y, x + w, y + d);    {$endif}  end;   procedure LG_Object.Paint;  begin    if boundaryset then    begin      Setcolor(Drawcolor);      {$ifdef typesrect}      with boundary do rectangle(left, top, right, bottom);      {$else}      with boundary do rectangle(x1, y1, x2, y2);      {$endif}    end    else      outtextxy(x, y, 'boundary not set');  end;   function lg_Object.handleEvent(mxx, myy, mbb: longint): integer;  begin    Result := 0;  end;   destructor lg_object.done;  begin   end;  {***********  end LG_Object ****************}   {*********** LG_Button *********************}   constructor LG_Button.InitButton(xx, yy: integer; Name: string; id: integer);  var    w, d: integer;  begin    inherited init(xx, yy);    event_code := id;    Pressed := False;    Txt := Name;    w := textwidth(Txt) + 8;    d := textheight(txt) + 4;    Setboundary(w, d);  end;   procedure LG_Button.Paint;  begin    if not pressed then    begin    with boundary do      begin        {$ifdef typesrect}        setfillstyle(solidfill, 7);        bar(left, top, right, bottom);      Setcolor(15);        Rectangle(left, top, right, bottom);        Setcolor(0);        Line(right, top, right, bottom);        Line(left, bottom, right, bottom);        OutTextXY(left + 3, top + 3, Txt);      {$else}        setfillstyle(solidfill, 7);        bar(x1, y1, x2, y2);        Setcolor(15);        Rectangle(x1, y1, x2, y2);        Setcolor(0);        Line(x2, y1, x2, y2);        Line(x1, y2, x2, y2);        OutTextXY(x1 + 3, y1 + 3, Txt);        {$endif}      end;    end    else    begin      with boundary do      begin        {$ifdef typesrect}        setfillstyle(solidfill, 8);        bar(left, top, right, bottom);        Setcolor(8);        Rectangle(left, top, right, bottom);        Setcolor(0);        Line(left, top, right, top);      Line(left, top, left, bottom);        Setcolor(7);        OutTextXY(left + 4, top + 4, Txt);        {$else}        setfillstyle(solidfill, 8);        bar(x1, y1, x2, y2);        Setcolor(8);        Rectangle(x1, y1, x2, y2);        Setcolor(0);      Line(x1, y1, x2, y1);        Line(x1, y1, x1, y2);        Setcolor(7);        OutTextXY(x1 + 4, y1 + 4, Txt);        {$endif}    end;    end;  end;    function Lg_Button.HandleEvent(mxx, myy, mbb: longint): integer;  begin    if lpressed then      {$ifdef typesrect}      // alternative: PtInRect (https://docs.freepascal.org/docs- html/current/rtl/types/ptinrect.html)      if boundary.contains(point(mxx,myy)) then      {$else}      if positioninrect(mxx, myy, boundary) then      {$endif}      begin      pressed := True;        paint;        pressed := False;        while lpressed do        begin        end;        paint;        Result := event_code;      end      else        Result := 0;  end;   {***************** end LG_Button *****************}    {**************** LG_WindowsButton ***************}  procedure LG_WindowsButton.Paint;  begin    if not pressed then    begin      with boundary do      begin        {$ifdef typesrect}        setfillstyle(solidfill, 15);        bar(left, top, right, bottom);      Setcolor(1);        Rectangle(left, top, right, bottom);        Setcolor(0);        OutTextXY(left + 3, top + 3, Txt);        {$else}        setfillstyle(solidfill, 15);        bar(x1, y1, x2, y2);        Setcolor(1);        Rectangle(x1, y1, x2, y2);        Setcolor(0);      OutTextXY(x1 + 3, y1 + 3, Txt);        {$endif}      end;    end  else    begin      with boundary do      begin        {$ifdef typesrect}        setfillstyle(solidfill, 11);        bar(left, top, right, bottom);        Setcolor(1);        Rectangle(left, top, right, bottom);        Setcolor(0);        OutTextXY(left + 3, top + 3, Txt);        {$else}        setfillstyle(solidfill, 11);        bar(x1, y1, x2, y2);        Setcolor(1);        Rectangle(x1, y1, x2, y2);        Setcolor(0);        OutTextXY(x1 + 3, y1 + 3, Txt);      {$endif}      end;    end;  end;   {*************  end LG_WindowsButton *************************}    {************** LG_Taskbar ***********************************}   constructor LG_Taskbar.InitTaskBar(xx, yy, w, d: integer);  begin    inherited init(xx, yy);    Setboundary(w, d);    Fillcolor := 53;    {$ifdef typesrect}    ButtonX := Boundary.left + 4;    ButtonY := boundary.bottom - 16;    {$else}    ButtonX := Boundary.x1 + 4;    ButtonY := boundary.y2 - 16;    {$endif}  end;   procedure LG_Taskbar.paint;  begin    with boundary do    begin      {$ifdef typesrect}      setfillstyle(solidfill, fillcolor);      bar(left, top, right, bottom);      setcolor(7);      rectangle(left, top, right, bottom);      setcolor(8);      line(left, bottom, right, bottom);      line(right, top, right, bottom);      {$else}      setfillstyle(solidfill, fillcolor);      bar(x1, y1, x2, y2);      setcolor(7);      rectangle(x1, y1, x2, y2);      setcolor(8);      line(x1, y2, x2, y2);      line(x2, y1, x2, y2);      {$endif}    end;    if firstbutton <> nil then    begin      currentbutton := firstbutton;      repeat        currentbutton^.paint;        currentbutton := currentbutton^.Next;      until currentbutton = nil;    end;   end;   function lg_taskbar.handleevent(mxx, myy, mbb: longint): integer;  var    id: integer;  begin    id := 0;    if firstbutton <> nil then    begin      currentbutton := firstbutton;    repeat        {$ifdef typesrect}        // alternative: PtInRect (https://docs.freepascal.org/docs- html/current/rtl/types/ptinrect.html)        if Lpressed then if boundary.contains(point(mxx,myy)) then        {$else}        if Lpressed then if positioninrect(mxx, myy, boundary) then        {$endif}            id := CurrentButton^.handleevent(mxx, myy, mbb);      CurrentButton := CurrentButton^.Next;      until (currentbutton = nil) or (id <> 0);    end;    Result := id;  end;     procedure LG_Taskbar.AddButton(P: PLG_Button);  var    bw, bd: integer;  begin  if FirstButton = nil then    begin      FirstButton := P;      CurrentButton := P;      with currentButton^ do      begin        {$ifdef typesrect}        bd := boundary.height;        bw := boundary.width;        {$else}        bd := boundary.y2 - boundary.y1;        bw := boundary.x2 - boundary.x1;        {$endif}    end;      CurrentButton^.x := ButtonX;      CurrentButton^.y := ButtonY;      CurrentButton^.Setboundary(bw, bd);      Inc(buttonx, bw + 4);    end    else    begin      CurrentButton^.Next := P;      CurrentButton := P;      with currentButton^ do      begin        {$ifdef typesrect}        bd := boundary.height;        bw := boundary.width;        {$else}        bd := boundary.y2 - boundary.y1;        bw := boundary.x2 - boundary.x1;        {$endif}    end;      CurrentButton^.x := ButtonX;      CurrentButton^.y := ButtonY;      CurrentButton^.Setboundary(bw, bd);      Inc(buttonx, bw + 4);    end;    CurrentButton^.Next := nil;    LastButton := CurrentButton;    LastButton^.Next := nil;  end;   destructor lg_taskbar.done;  var    p: Plg_button;  begin    if firstbutton <> nil then    begin      CurrentButton := Firstbutton;      repeat      p := currentbutton^.Next;        dispose(currentbutton, done);      Currentbutton := P;      until currentbutton = nil;    end;  end;   {************  end LG_Taskbar *********************}   {************  LG_App *****************************}  constructor LG_App.Initapp(xx, yy, w, d: integer);  begin    inherited init(xx, yy);    Setboundary(w, d);    CurrentButton := nil;    FirstButton := nil;    LastButton := nil;    Fillcolor := 0;    Filled := False;  end;   destructor LG_App.done;  var    p: Plg_Button;  begin    if taskbar <> nil then dispose(taskbar, done);    if firstbutton <> nil then    begin      CurrentButton := Firstbutton;      repeat        p := currentbutton^.Next;        dispose(currentbutton, done);        Currentbutton := P;      until currentbutton = nil;    end;   end;   {this procedure should be copied then modified for new programs}   procedure LG_App.run;   var    Event: integer;    mx, my, mb: longint;    key: char;  begin    Event := 0;    currentbutton := firstbutton;    repeat      key := '~';      GetMouseState(mx, my, mb);      {check the taskbar first}      if taskbar <> nil then      if lpressed then          Event := Taskbar^.Handleevent(mx, my, mb);       if Event = 0 then        if currentbutton <> nil then        begin          if lpressed then Event := currentbutton^.handleevent(mx, my, mb);          Currentbutton := currentbutton^.Next;          if CurrentButton = nil then currentbutton := firstbutton;        end;       {this is the area to add behavior}    {case event of       end;     }       {if no buttons have an escape}      {$ifdef fix}  // prevent 'repeating' key buffer variable      if keypressed then      begin        key := readkey;      case key of          #0      :  // process extended keycodes        begin            // grab extended key            key := ReadKey;          case key of               #75 : WriteLn('example: left cursor key');               #77 : WriteLn('example: right cursor key');          end;          end;           #27 : Event := Event_quit; // escape key          'q', 'Q': Event := Event_quit;        end;      end;    {$else}      if keypressed then key := readkey;      case key of      'q', 'Q': Event := Event_quit;      end;      {$endif}       {$ifdef fix}      // prevent high CPU load      sleep(1);      {$endif}    until Event = Event_Quit;   end;    procedure LG_App.AddButton(P: PLG_Button);  begin    if FirstButton = nil then    begin      FirstButton := P;      CurrentButton := P;    end    else    begin    CurrentButton^.Next := P;      CurrentButton := P;    end;    CurrentButton^.Next := nil;     LastButton := CurrentButton;    LastButton^.Next := nil;  end;   procedure LG_App.Paint;  begin     if filled then    begin      setfillstyle(solidfill, FillColor);      with boundary do      begin        {$ifdef typesrect}        Bar(left, top, right, bottom);        setcolor(DrawColor);        Rectangle(left, top, right, bottom);        {$else}        Bar(x1, y1, x2, y2);        setcolor(DrawColor);        Rectangle(x1, y1, x2, y2);        {$endif}      end;    end    else      with boundary do    begin        setcolor(DrawColor);        {$ifdef typesrect}        Rectangle(left, top, right, bottom);        {$else}        Rectangle(x1, y1, x2, y2);        {$endif}      end;    if firstbutton <> nil then    begin      currentbutton := firstbutton;      repeat      currentbutton^.paint;        currentbutton := currentbutton^.Next;      until currentbutton = nil;    end;    if taskbar <> nil then Taskbar^.paint;  end;   {*************** end LG_App **********************} var   gmode, gdriver: smallint;  P: Plg_Object;  App: PLG_App;   begin  gdriver := vesa;  Gmode := installusermode(640, 480, 256, 1, 8000, 6000);  WindowTitle := 'LG_Object Library Demo';  initgraph(gdriver, gmode, '');  SetColor(7);   App := New(plg_app, initapp(0, 0, getmaxx, getmaxy));  App^.Taskbar := New(Plg_Taskbar, inittaskbar(1, getmaxy - 22, getmaxx - 2, 20));   App^.taskbar^.addbutton(New(Plg_WindowsButton, initbutton(1, 1, 'Does nothing', event_Nothing)));   App^.taskbar^.Addbutton(New(Plg_Button, initbutton(1,1, 'More nothing', Event_Nothing)));  App^.Taskbar^.addbutton(New(Plg_WindowsButton, initbutton(1,1, 'Quit', Event_Quit)));  App^.Filled := True;  App^.fillcolor := 3;  App^.paint;  initmouse;  showmouse;  App^.run;  dispose(App, done);  closegraph; end.