The UIGUI Library

Confession of Flux: this library is an incomplete alpha-test product. It should stabilize once the C-friendly API catches up with the underlying Unicon runtime code, which is more or less release quality. Thank you for reporting problems, and for your patience and perseverance.

The UIGUI (Unicon-Idaho Graphical User Interface, pronounced "oowee gooey") library is a C variant of the Unicon graphics API. UIGUI allows C/C++ programmers to easily control screen output on X11 and Win32 platforms. UIGUI provides easy bitmap graphics, but omits many arcane features found in mainstream graphics API's. UIGUI is for intermediate C/C++ programmers, or people who do not have time to write a lot of native GUI code, nor a lot of time to learn complex GUI library API's.

UIGUI is open source code, derived from the implementation of the Icon and Unicon programming languages (see http://unicon.org), which offer similar graphics capabilities and much easier data structure and algorithm coding than C/C++. Although adapting Icon's graphics for C/C++ was originally suggested/requested 14 years ago by internet C++ celebrity Andrew Koenig, UIGUI finally came about for use in the University of Idaho's CS graphics course.

Installing UIGUI

If you are lucky, UIGUI is already installed for you by an instructor or system administrator. If you are not lucky, here are some notes. You will need a C/C++ compiler with header files and libraries for GUI development. UIGUI just simplifies the use of these libraries for you. Some compilers come bundled with the GUI development libraries and headers, while for others such as Linux you may have to separately install a package for GUI development such as "x11-devel" or "xlib". See your operating system and compiler documentation or ask an expert.

UIGUI works on top of either X11 (Xlib) or Win32 C API's. Other ports are in various stages of completion or obsolescence but are not supported at this time. UIGUI works on top of either gcc/g++ or Microsoft C++ (Visual Studio). Since gcc/g++ works on both UNIX/Linux and MS Windows (we use the "Mingw32" gcc), this section concentrates on gcc/g++ for starters.

To run UIGUI you need a uigui.h and a libuigui.a library, which you get by downloading and renaming the file for your platform. For example, on Solaris you would rename solaris-libuigui.a to libuigui.a

headermakefile Linux x86_64 Linux 32-bit Windows Solaris Mac(X11)
uigui.h makefile download download download ask ask

On Windows, one can either use the local library version or run an X11 server such as Xming, set one's SSH to do X11 port forwarding, and run remote clients on Linux or Solaris, with application windows magically opening on the client screen thanks to the miracle that is X11. It helps to be on a really fast network connection when you do this; graphics applications use a lot more bandwidth than text applications. It is not recommended over dialup connections.

Programming with UIGUI

whello

As a first toy example, here is a windowing hello world program, whello.c. It illustrates uigui's simplest capabilities. WOpen() initializes the "screen", or rather, the new window, and opens it. GotoRC(row,column) moves the cursor. writes() writes a string to the window at the cursor. Both text and (in later examples) pixels are drawn using a foreground color which defaults to black, on a window with a given background color, which defaults to white. See the reference section below for more functions.
#include "uigui.h"
int main()
{
   WOpen();
   GotoRC(5, 15);
   writes("hello, world");   
}
Compile this with:
solaris
  gcc -o whello whello.c libuigui.a -lz -lXpm -lX11 -lm -lsocket -lnsl
linux
  gcc -o whello whello.c libuigui.a -lz -lXpm -ljpeg -lGLU -lGL -lX11 -lm
windows
  gcc -mwindows -Xlinker --stack -Xlinker 8192000 -o whello.exe $(guiflags) whello.c libuigui.a ../gdbm/libgdbm.a ../libtp/libtp.a -lwinmm -lwsock32 -lodbc32 -lopengl32 -lglu32 -lkernel32 -luser32 -lgdi32 -lcomdlg32
You may have to install some packages in order for your C compiler to have the various graphics-related libraries; trust me, they are all useful for something. If your uigui library is installed in a standard location instead of the current working directory, say -lguicurses instead of libguicurses.a.

It would be possible to minimize this library set for public consumption, but these libraries allow a libuigui.a to be built from the EXACT SAME .o files used to build a full-blown Unicon, which has tactical advantages for the local developer/maintainer.

A simple graphics example

The following example provided by Terence Soule draws the chaotic portion of the logistic map. It illustrates uigui's simple graphics capabilities. DrawPoint(x,y) sets an individual pixel to the foreground color.
#include "uigui.h"
int main()
{
   float w;
   float y;
   int i;

   WOpen();
   for (w=2.9; w<=4; w+=0.002){
       y=0.5;
       for(i = 0; i < 300; i++){
           y = w*y*(1-y);
           if(i > 200)
             DrawPoint(((w-2.9)*450),(y*150));
       }
   }
}

Reference

The following comments on the uigui.h header file summarizes the uigui library at a glance.
Window
A data type which holds a reference to the window. You can use the default window stdscr and ignore this if you want. Functions that use the default window often have "twins" whose names prefix a "W" on the front, and take a Window parameter as a first argument. For example, there is DrawPoint(x,y) and WDrawPoint(w,x,y).
LINES
An integer that tells how many text lines the default window has.
COLS
An integer that tells how many text columns the default window has.
void Clip(x,y,wd,ht)
Set the clipping rectangle in the window. Same as WClip(stdscr,x,y,wd,ht)
int getch()
Return a character from the default window. Same as wgetch(stdscr).
int Event()
Return an event from the default window, or 0 for error. Values 1-127 (at least) are ASCII keyboard characters. Mouse events are returnes as special values less than 0. To be documented further.
char * WAttrib(s)
Get/set an attribute of the default window. Same as watt(stdscr,s). For example, att("fg=red") sets the foreground color to red. For a complete list of attributes see "Graphics Programming in Icon", by Griswold, Jeffery, and Townsend.
void WOpen();
Initialize the library and open the default window.
void WOpenN(int n, ...);
As in WOpen() but take an int n, and then n string attributes. (Brute force at moment, will get smarter later).
void WEnd();
Finalize the library and close the default window.
void DrawPoint(int x,int y);
Draw a single point on the default window.
void writec(char, Window);
Put a single character on a given window.
Window Wopen(char *s);
Open a window with title s.
void writes(char *s);
Write s to the default window.
void DrawRectangle(int x, int y, int wd, int ht);
Draws rectangle in current fg color to the default window.
void EraseArea(int x, int y, int wd, int ht);
Erases (draws rectangle in current bg color) the default window.
void DrawCurve(int n, ...);
Draw a curve with n vertices given by n*2 following integers.
char *Pixel(x,y,wd,ht);
Return an array of (wd*ht*3) unsigned bytes, with each 3 bytes giving the R,G,B values of the next pixel in the range 0-255.

More to Come

Are there more easy graphics primitives? Colors and fonts? 3D? Yes, yes, yes... We will roll out several expansions in Fall 2008 semester.