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

const
  cidZmensi = 101;
  cidZvetsi = 102;

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 MyNotify( var N: TNotification ); far;
begin
  case N.Control^.Id of
    cidZmensi: begin
                 if N.Code = nmClick then
                 begin
                   if hodnota > 0 then dec( hodnota );
                   pb^.SetPosition( hodnota );
                   ClearNotification( N );
                 end;
               end;
    cidZvetsi: begin
                 if N.Code = nmClick then
                 begin
                   if hodnota < 100 then inc( hodnota );
                   pb^.SetPosition( hodnota );
                   ClearNotification( N );
                 end;
               end;
  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^.AfterNotify := MyNotify;

      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^.Id := cidZmensi;
      bt^.Customize( ccButton );
      bt^.SetOptions( ofSelectable or ofShowFocus, 0 );
      pg^.insert( bt );

      R.Assign( 245, 160, 265, 180 );
      bt := new( PButton, init( R, '+', 0, 0 ));
      bt^.Id := cidZvetsi;
      bt^.Customize( ccButton );
      bt^.SetOptions( ofSelectable or ofShowFocus, 0 );
      pg^.insert( bt );


    ap^.Insert( pg );

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