uses
  objects,
  iodrv,
  controls,
  grctrls,
  PCDrv,
  PCMCus,
  fonts,
  Foss16;

const hodnota :byte = 27;

var
  R  : TRect;
  ap : PApplication;
  pg : PPage;
  st : PStaticText;
  bt : PButton;
  pb : PProgressBar;

procedure skrtni( AControl: PControl; ACanvas: PCanvas ); far;
var
  r : TRect;
begin
  AControl^.GetExtent( R );
  with ACanvas^ do
  begin
    pen.color := clBlack;
    pen.style := psSolid;
    DrawLine( r.a.x, r.a.y, r.b.x, r.b.y);
    DrawLine( r.a.x, r.b.y, r.b.x, r.a.y);
  end;
end;

procedure zmensi( AControl: PControl; var AEvent: TEvent ); far;
begin
  if AEvent.code = evMouseDown then
  begin
    if hodnota > 0 then dec( hodnota );
    pb^.SetPosition( hodnota );
  end;
end;

procedure zvetsi( AControl: PControl; var AEvent: TEvent ); far;
begin
  if (AEvent.code = evMouseDown) then
  begin
    if hodnota < 100 then inc( hodnota );
    pb^.SetPosition( hodnota );
  end;
end;

procedure pbpaint( AControl: PControl; ACanvas: PCanvas ); far;
var
  r : trect;
  s : string;
begin
  with PProgressBar( AControl )^ do
  begin
    GetExtent( R );
    ACanvas^.ROP := ropXOR;
    str( hodnota, s );
    ACanvas^.DrawTextRect( R, s+'%', tfCenterX or tfCenterY );
  end;
end;

begin
  ap := new( PApplication, init(
          new( PInputDriver, init(
            new( PPCKeybDriver, init ),
            new( PPCMouseDriver, init )
          )),
          new( PVgaMonoDriver, init( 640, 480 )),
          nil
        ));
  ap^.Customize( ccApplication );
  ap^.SetFont( fidSS16 );

    R.Assign( 0, 0, 320, 240 );
    pg := new( PPage, Init( R ));
    pg^.Customize( ccPage );
{    pg^.AfterPaint := skrtni;}

      R.Assign( 1, 1, 319, 18 );
      st := new( PStaticText , init( R, 'Ahoj' ));
      st^.Customize( ccStaticText );
      st^.SetFlags( stfBorder, 0 );
      pg^.Insert( st );

      R.Assign( 120, 100, 200, 120 );
      bt := new( PButton, init( R, 'Stiskni', 0, 0 ));
      bt^.Customize( ccButton );
      bt^.AfterPaint := skrtni;
      pg^.Insert( bt );


      R.Assign( 80, 160, 240, 180 );
      pb := new( PProgressBar, init( R ));
      pb^.Customize( ccProgressBar );
      pb^.SetRange( 0, 100 );
      pb^.SetPosition( hodnota );
      pb^.AfterPaint := pbPaint;
      pg^.Insert( pb );

      R.Assign( 55, 160, 75, 180 );
      bt := new( PButton, init( R, '-', 0 ,0 ));
      bt^.Customize( ccButton );
      bt^.BeforeHandle := zmensi;
      pg^.insert( bt );

      R.Assign( 245, 160, 265, 180 );
      bt := new( PButton, init( R, '+', 0, 0 ));
      bt^.Customize( ccButton );
      bt^.BeforeHandle := zvetsi;
      pg^.insert( bt );


    ap^.Insert( pg );

  ap^.Run;
  dispose( ap, done );
end.