Manual
Graphic
 previous   up   next 

14. GRAPHIC LIBRARY

Seed7 provides a portable graphics library. Below is the graphic "hello world" program:

$ include "seed7_05.s7i";
  include "dialog.s7i";

const proc: main is func
  begin
    messageWindow("hello world");
  end func;

This program displays a popup window with the message "hello world". In the popup window there is an OK button, which ends the program. A program that creates an empty window and a message popup is:

$ include "seed7_05.s7i";
  include "dialog.s7i";

const proc: main is func
  begin
    screen(640, 480);
    messageWindow("hello world");
  end func;

The function screen(640, 480) opens window with a width of 640 and a height of 480. The window is assigned to the variable curr_win, which is used as default window by drawing functions.

Displaying an empty window without message box is done with:

$ include "seed7_05.s7i";
  include "draw.s7i";
  include "keybd.s7i";

const proc: main is func
  begin
    screen(640, 480);
    ignore(getc(GRAPH_KEYBOARD));
  end func;

This program waits until a key is pressed. The key is read from GRAPH_KEYBOARD Without reading from GRAPH_KEYBOARD the program would terminate immediately. Regarding the keyboard:

For that reason a graphic program should do the following assignment:

KEYBOARD := GRAPH_KEYBOARD;

Afterwards it should just use the variable KEYBOARD.

The program below clears the window with a color computed from the keys pressed:

$ include "seed7_05.s7i";
  include "draw.s7i";
  include "keybd.s7i";

const proc: main is func
  local
    var char: command is ' ';
  begin
    screen(640, 480);
    KEYBOARD := GRAPH_KEYBOARD;
    repeat
      command := getc(KEYBOARD);
      clear(color(1009 * ord(command) mod 65536,
                  4999 * ord(command) mod 65536,
                  9973 * ord(command) mod 65536));
    until command = KEY_ESC;
  end func;

The function color creates a color from red, green and blue lights in the additive color model. The red, green and blue lights are specified by integer values in the range 0 .. 65535.

Below is a "hello world" program that uses a Seed7 font:

$ include "seed7_05.s7i";
  include "draw.s7i";
  include "keybd.s7i";
  include "text.s7i";
  include "stdfont24.s7i";

const proc: main is func
  local
    var text: textWindow is text.value;
  begin
    screen(203, 45);
    textWindow := openPixmapFontFile(curr_win);
    setFont(textWindow, stdFont24);
    writeln(textWindow, " hello world");
    ignore(getc(GRAPH_KEYBOARD));
  end func;

The function screen opens a window with a width of 203 pixels and a height of 45 pixels. The window is stored in the global variable curr_win. The function openPixmapFontFile opens a pixmapFontFile for curr_win. Everything written to textWindow is displayed in the current window. The function setFont defines which font should be used. The font stdfont24.s7i is a bitmapFont with a cap-height of 24 pixels. The function writeln displays hello world to the current window with the specified font.

Seed7 fonts are not as perfect as professional fonts. They have the following properties:


 previous   up   next