Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-01

The Video unit

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sergey Ulanov

I want to draw box on the screen. Why does following code work well on linux console, but does not work in xterm ?

{$mode objfpc}
uses
  video;
procedure DrawChar(x,y:integer;c:char);
begin
  VideoBuf^[x+y*ScreenWidth] := $0700 + byte(c);
end;
procedure DrawBox(x,y,w,h:integer);
var
  i,j:integer;
begin
    DrawChar(x,y,#130);
    DrawChar(x+w-1,y,#131);
    DrawChar(x,y+h-1,#132);
    DrawChar(x+w-1,y+h-1,#133);
    for i:=1 to w-2 do begin
      DrawChar(x+i,y,#128);
      DrawChar(x+i,y+h-1,#128);
    end;
    for i:=1 to h-2 do begin
      DrawChar(x,y+i,#129);
      DrawChar(x+w-1,y+i,#129);
    end;
end;
begin
  InitVideo;
  DrawBox(5,5,20,10);
  UpdateScreen(true);
  readln;
  DoneVideo;
end.

Reply by email

Unknown author
to Sergey Ulanov
Sergey Ulanov wrote
I want to draw box on the screen. Why does following code work well on linux console, but does not work in xterm ?

It works well, but the terminal characters you use are wrong. I picked a new font, and changed the characters to IBM PC character set:

I spawned an x-term with a VGA font:
xterm -fn vga -fb vga -ls
and ran the modified program in it. It worked perfectly.

I suggest you use normal characters to draw boxes, such as - = + | and so on.

Michael.

Here is the modified program:
-----------------------------------------------------------------------

{$mode objfpc}
uses
  video;
procedure DrawChar(x,y:integer;c:char);
begin
  VideoBuf^[x+y*ScreenWidth] := $0700 + byte(c);
end;
procedure DrawBox(x,y,w,h:integer);
var
  i,j:integer;
begin
    DrawChar(x,y,#201);
    DrawChar(x+w-1 ,y,#187);
    DrawChar(x,y+h-1,#200);
    DrawChar(x+w-1,y+h-1,#188);
    for i:=1 to w-2 do begin
      DrawChar(x+i,y,#205);
      DrawChar(x+i,y+h-1,#205);
    end;
    for i:=1 to h-2 do begin
      DrawChar(x,y+i,#186);
      DrawChar(x+w-1,y+i,#186);
    end;
end;
begin
  InitVideo;
  DrawBox(5,5,20,10);
  UpdateScreen(true);
  readln;
  DoneVideo;
end.

Reply by email