VgaGames4

VgaGames4 - window man-pages

[.. upper level ..]

# Window functions

Manage window.

- Enumerations and Structures
- VG_POSITIONS
- VG_WINDOW_SCALES
- VG_WINDOW_SIZES
- struct VG_Position
- struct VG_Rect
- Opening and closing
- vg4->window->open()
  Open window.
- vg4->window->reopen()
  Reopen window.
- vg4->window->close()
  Close window.
- Window properties
- vg4->window->size_extend()
  Switch on or off size-extension for opening window.
- vg4->window->getparameters()
  Get parameters of the window.
- vg4->window->getsize()
  Get virtual size of the window.
- vg4->window->getbrightness()
  Get common window brightness.
- vg4->window->setbrightness()
  Set common window brightness.
- vg4->window->getattr()
  Get window attributes.
- vg4->window->setattr()
  Set window attributes.
- vg4->window->scale_params()
  Set scaling parameters.
- Modifying window contents
- vg4->window->clear()
  Clear window.
- vg4->window->copy()
  Copy image onto window.
- vg4->window->fill()
  Fill window with a color.
- vg4->window->draw_point()
  Draw a pixel onto window.
- vg4->window->draw_points()
  Draw pixels onto window.
- vg4->window->draw_line()
  Draw a line onto window.
- vg4->window->draw_rect()
  Draw a rectangle onto window.
- vg4->window->draw_circle()
  Draw a circle onto window.
- Miscellaneous window functions
- vg4->window->flush()
  Flush contents to window.
- vg4->window->shake()
  Set a short shaking of the window
- vg4->window->clone()
  Clone window contents into image.
- vg4->window->screenshot()
  Save a screenshot of the actual window to a file.
- Environment variables
- VG_IO_LIBRARY
  IO-library to load, e.g. "SDL2". Currently supported libraries: - SDL2 - SDL3 If empty use first found IO-library.
- VG_RENDERER
  Renderer to use, e.g. "opengl" or "software". Defaults to a suitable accelerated renderer.
- VG_NO_INFO
  Whether print no info messages to stderr. Values: - 0: print (default) - 1: print not
- VG_NO_WARNING
  Whether print no warning messages to stderr. Values: - 0: print (default) - 1: print not
- Environment variables for debugging
- VG_DUMP_ON_EXIT
  Whether show dumps when calling VG_dest(). - 0: no (default) - 1: yes, to stdout - 2: yes, to stderr
- VG_FILM_DUMP
  Concerning playing films. Values: - 0: play film (default) - 1: dump and play film - 2: only dump film

## Example

    example.c

    /* open window and draw a circle, then again with window properties set to grey color */

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <errno.h>
    #include <vgagames4.h>

    int main(int argc, char **argv) {
      int winw, winh, radius;
      struct VG_ImagecopyAttrPixel wattr_pixel;

      (void)argc; (void)argv;

      /* initialize VgaGames library */
      if (!VG_init("window-example")) { exit(1); }

      /* open window with low size and best (integer) scaling */
      if (!vg4->window->open(VG_WINDOW_SIZE_LOW, VG_WINDOW_SCALE_BEST)) { VG_dest(); exit(1); }

      /* get (virtual) size of the window */
      vg4->window->getsize(&winw, &winh);

      /* +++ first draw a yellow circle onto a blue background +++ */

      /* clear window and fill it with blue color */
      vg4->window->clear();
      vg4->window->fill(VG_COLOR_BLUE);

      /* draw a yellow filled circle at the center of the window */
      radius = (winw > winh ? winh : winw) / 4;
      vg4->window->draw_circle(winw / 2, winh / 2, radius, VG_COLOR_YELLOW, VG_TRUE);

      /* flush window contents and wait 3 seconds */
      vg4->window->flush();
      sleep(3);

      /* +++ now set window to grey and draw the circle again +++ */

      /* set window attributes to grey color */
      VG_IMAGECOPY_ATTRPIXEL_DEFAULT(&wattr_pixel);
      wattr_pixel.pixelcolor = VG_PIXELCOLOR_GREY;
      vg4->window->setattr(&wattr_pixel);

      /* clear window and fill it with blue color */
      vg4->window->clear();
      vg4->window->fill(VG_COLOR_BLUE);

      /* draw a yellow filled circle at the center of the window */
      radius = (winw > winh ? winh : winw) / 4;
      vg4->window->draw_circle(winw / 2, winh / 2, radius, VG_COLOR_YELLOW, VG_TRUE);

      /* flush window contents and wait 3 seconds */
      vg4->window->flush();
      sleep(3);

      /* destroy and exit */
      VG_dest();
      exit(0);
    }

    Makefile

    CFLAGS = -W -Wall -O2
    VGAG_CFLAGS = `vgagames4-config --cflags`
    VGAG_LIBS = `vgagames4-config --libs`

    example: example.o
    	$(CC) $(CFLAGS) example.o $(VGAG_LIBS) -o example

    example.o: example.c
    	$(CC) $(CFLAGS) $(VGAG_CFLAGS) -c example.c

    clean:
    	rm -f example example.o