• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

bezier/H03-May-2022-1,147586

creq/H03-May-2022-833498

demo1/H03-May-2022-641285

demo2/H03-May-2022-617268

demo3/H03-May-2022-567240

demo4/H03-May-2022-469240

docs/H22-Jan-1994-2,4901,774

draw_demo/H03-May-2022-362163

frac/H03-May-2022-529262

freq/H03-May-2022-1,039550

multireq/H03-May-2022-686394

skel/H03-May-2022-651242

src/H03-May-2022-5,5473,362

xmore/H03-May-2022-545278

HELPH A D06-Mar-19945 KiB12693

MakefileH A D02-Feb-19941.2 KiB6634

OTHERH A D03-Mar-1994439 148

READMEH A D21-Apr-199417.7 KiB381304

libsx_defsH A D03-May-20222.8 KiB8883

README

1		          -- Libsx v1.1 --
2			The Simple X library
3
4
5			        by
6			  Dominic Giamapolo
7			     dbg@sgi.com
8
9
10Introduction:
11
12--- What is libsx?
13
14     Libsx (the Simple X library) is a library of code that sits on
15top of and to the side of the Athena widget set.  Its purpose is to
16make writing X applications *much* easier.  To accomplish this, libsx
17encapsulates a large portion of the uglier details that arise while
18programming in X and it fills in some gaps that exist with the Athena
19Widget set (such as a widget for drawing graphics); libsx tries to
20simplify the common case down to a single function call with only a
21few arguments.
22
23     With libsx, writing a simple program that opens a window, has a
24few buttons and draws some graphics (lines, circles, bitmaps, etc) is
25a matter of 5-10 lines of code, including the drawing code.  Hello
26World is 2 lines.  More complicated programs that respond to mouse
27clicks, have buttons, scrollbars, etc, can be written in 25-50 lines
28of code.
29
30     Some libraries take the approach of completely hiding whatever
31they are layering on top of.  In contrast, libsx doesn't drastically
32alter the base abstractions of X, it just packages them in the way
33they get used most of the time, so that with one function call and a
34few arguments you get the effect of 10-20 lines of pure X code.
35Access to the underlying X objects (Window id's, Display pointers,
36etc) is also possible if necessary, but not required.
37
38     With libsx, the simple things are simple and the complex things
39are possible (where have I heard that before? :-).
40
41
42--- Building libsx
43
44     1. Edit the libsx_defs file in this directory and set the
45        compiler you'd like to use and any necessary compiler flags.
46	It is important that you take a look in this file and
47        edit things as appropriate.  By default it builds for an SGI
48        system (gee, I wonder why that is? :-)  If you are on a
49        DECstation, their standard compiler will _not_ work as it
50  	is not ANSI compliant (gcc works great though).
51
52     2. Type make.
53
54     This builds the libsx library in the src directory and all
55the demo programs in the other subdirectories.
56
57     If you're short on disk space, you can go into any particular
58directory and type make there.  For anything else to work, the
59libsx/src directory must be compiled first.
60
61     A word of caution.  On some suns that have motif installed from a
62third party, you'll get lots of warnings about symbols being
63re-defined when compiling libsx.  This is because of an
64incompatibility in the way the X header files get installed for the
65motif product (not sure who makes the one I encountered problems
66with).  Anyway, the warnings are innocuous but definitely annoying.
67Unfortunately I can't seem to make them go away.
68
69     The demo program that shows most of the features of the library
70is in the src directory (the executable is called `demo').  The other
71demo programs demonstrate various aspects of the library.  Feel free
72to use them as skeletons for your own programs.
73
74     The code has been compiled on wide variety of systems and
75compilers.  It should be mostly clean POSIX code, but I would
76appreciate hearing about any difficulties you have while compiling.  I
77have personally compiled it cleanly on Sun3's and 4's (SunOS 4.1.1
78mind you), SGI (Indigo's, PowerSeries, Onyx, etc), and DECstations
793100/5100's.  People on the net have told me that they've gotten it to
80work on HP-UX, Linux, SVR4.2, AIX 3.2, Sequent/ptx, and numerous other
81systems.  A while ago I compiled it cleanly on a DG Aviion running a
82very strict version of SVR4.  I've used gcc to compile it as well as
83the native compiler on most of the platforms.  The code is ANSI C, so
84if you don't have an ANSI compiler, sorry....
85
86     Libsx also requires the Athena widget set, which isn't as
87omni-present as I once thought.  I guess HP doesn't ship it on all of
88their systems.  I can't help you much there.  Bitch at your vendor and
89tell them to ship a version of the Athena widgets if you don't have
90it.
91
92     BTW, there's no Imakefile because I don't understand imake (nor
93have I made much of an attempt to understand it).  Imake seems like
94overkill for libsx.  If someone would like to write an Imakefile, I'd
95gladly include it in future releases, but it's not likely I'll do it
96myself.
97
98
99--- More details about libsx
100
101     The reason I wrote libsx was so that I could whip up simple X
102programs in not much time and not lots of X code.  Originally it
103started because I wanted an easy way to write programs to draw
104graphics, but libsx also grew to encapsulate most of the other Athena
105widgets making all sorts of GUI programs possible
106
107     The essential idea with libsx is that creating the user-interface
108should be simple and you should spend your time on the code that
109implements the logic of your program.  In libsx, the core functions
110that control your application are connected to user-interface elements
111as callback functions.  That is, when the user does something
112interesting with your interface, your callback function gets called.
113
114      All of the low level management details are handled for you.
115Each user interface item (buttons, scrollbars, drawing area's, text
116entry, etc) only requires one function call to create it.  One of the
117arguments to this creation routine is the name of a callback function
118that will be called each time an interesting event happens to that
119widget.  For example, when a button or menu item is clicked on/chosen,
120your callback routine gets called.  When a drawing area needs to be
121redrawn, your callback gets called.
122
123     The intent of libsx was to ease the common case.  For example,
124here is the code to create and manage a single line string entry
125with libsx:
126
127    void str_callback(Widget w, char *string, void *data)
128    {
129      printf("You pressed: %s\n", string);
130    }
131
132    void main()
133    {
134       ....
135      MakeStringEntry("preset text", 200, str_callback, NULL);
136    }
137
138     The first function is the callback function that gets called when
139the user presses return in the widget (and it just prints what the
140user entered).  The call to MakeStringEntry() builds the widget and
141takes care of setting all the necessary resources and translations for
142everything to work.  In comparison, the equivalent code in regular X
143calls is on the order of 20-25 lines of code (not counting the
144callback function which would be the same for both).
145
146     Another example is drawing graphics.  The plain Athena widget set
147does not provide a drawing area widget (like Motif does).  Libsx
148includes David Nedde's Athena drawing area widget and encapsulates it
149so that a simple program to open a window and draw some graphics is
150now reduced to only a few lines of code.  More complicated programs
151build upon the simple model and although creating the user interface
152may involve more lines of code, the basic model is the same.
153
154
155--- What exactly does libsx provide?
156
157     Libsx encapsulates the following interface components (all based
158on Athena widgets, except for the DrawingArea widget which belongs to
159David Nedde):
160
161       -- labels
162       -- buttons
163       -- radio button groups and toggle buttons
164       -- single line text entry
165       -- multi-line text entry (full text-edit box)
166       -- scrollbars (horizontal or vertical)
167       -- scrolling lists
168       -- menu buttons (buttons with pop-up menus)
169       -- drawing areas (you can draw in these and also receive
170                         mouse/keyboard events if you like)
171       -- multiple form widgets (more advanced, not normally used)
172
173After creating the interface components you need, you lay-out your
174display in a logical fashion.  The SetWidgetPos() function lets you
175specify what widgets are next-to or underneath (or both) other
176widgets.  This avoids hard-coding pixel positions and makes setting up
177a display pretty simple and quick (though to be fair, some more
178complicated displays involving centering and such can be difficult if
179not impossible).
180
181You can easily change widget attributes and use different fonts.
182There are some simple dialog box routines (for getting yes/no answers
183and getting a single string).  Libsx can also open multiple windows
184(even on different screens) and you can build your own dialog boxes
185(modal windows) if you like.
186
187Libsx also supports obtaining, managing and using colors (either
188individual colors or an entire 8-bit colormap).  Getting specific
189named colors or colors based on RGB values is as simple as calling a
190single function (no need to worry about colormaps, color cells, or any
191of the other junk X makes you worry about).  Grabbing the entire
192colormap is also very easy.
193
194Effectively, libsx maintains a lot of state for you; it manages all
195the grungy X details while providing a cleaner set of routines for
196your program to use.
197
198
199
200--- Has libsx traded complexity for functionality?
201
202     I don't think so.  While libsx makes it trivial to write simple
203programs (as mentioned before, hello world is 2 lines of code), it's
204also been used to write some fairly substantial programs.  I've
205written 3-D object editors and all sorts of wire-frame/shaded graphics
206previewers.  This afternoon I got fed up with XLess and wrote an
207equivalent replacement with a real file requestor in about an hour.
208Most of the time was spent working on the logic of how the program
209should behave, not the user interface.  A friend used it to write a
210complete 3-D modeling/rendering system.  I've written tons of small
211graphics programs with it (reaction-diffusion and iterated function
212system demos, etc).  I've used it for a contract application that
213required a simulation of a train set on screen (modeled correctly to
214scale, etc), and I've been kicking around ideas for some sort of word
215processor/editor.  Libsx is not some all-singing all-dancing type of
216library, but it does make writing common X applications substantially
217easier.  If you do need the extra confusionality, I mean functionality
218that X offers, all the standard X functions are available and you have
219access to the Widget id's, Display pointers, etc.  The point is that
220you don't have to worry about that if you don't want to.
221
222
223--- Where did libsx come from?
224
225     I developed libsx over the course of about 2 years while in
226graduate school at Worcester Polytech (in good ole Worcester, Mass.)
227It all started when I took the grad course in Computer Graphics. I
228wanted a nice library of routines to deal with all the X crap so I
229could concentrate on my graphics code.  Soon the library started
230evolving into a much more sophisticated thing and when I became the TA
231for the graphics course, I beefed it up a lot.  When you have 65
232undergrads beating on a library you've written, it's got to be solid.
233The next time that I was TA, I polished up some more rough edges in
234the library (the stuff the students complained about) and it went
235through the ringer a second time with about 45 more students.
236Finally, during the summer of 1993 I added a ton of more functionality
237to the library so a friend of mine could write his 3-D editor the way
238it should be written and so I could do some stuff I wanted to do.
239In September of 1993 I was hired at SGI and I've done a little bit more
240work on libsx since I've been here (mainly little cleanups and the
241rudimentary OpenGL support).  That is effectively what you see today.
242
243     I've spent a lot of time deciding how to structure libsx so it
244would be easy to use but still be open ended.  Libsx doesn't try to
245hide all of X, it just tries to make it more digestable.  The library
246has gotten pretty big at this point, but it should be sufficient to
247write most types of GUI programs without lots of fuss.
248
249     I've also spent a lot of time deciding what should and shouldn't
250be in libsx.  It's too easy to throw in everything just because it's
251easy to do so.  Unfortunately that's almost never the right reason to
252include something.  I've tried to pare the design down to the
253essentials needed to write a useful application.  Comments and
254critiques of the design/approach are welcome (I'd like to hear what
255others have to say about it or how they would have done it).
256
257
258--- Does libsx hurt performance?
259
260     I've never really noticed any problems and most of this code was
261developed originally on a Sun3 (so if it ran ok there it's almost
262guaranteed to run fine on anything else because a Sun3 is a pretty
263damn slow machine nowadays :-).
264
265     Seriously though, once you've created the interface and put up
266the display, there isn't much libsx code that gets in the way of your
267application.  Many calls go direct to your application and a few are
268routed through libsx code, but nothing fancy happens there.  Using
269libsx I was able to write programs that interactively manipulated
270three dimensional objects of up to several hundred vertices with the
271mouse on a Sparc IPC, so I don't consider performance to be a problem.
272
273
274--- What are the drawbacks to using libsx?
275
276     The single biggest drawback that I can think of is that some
277layouts of widgets are not possible because of limitations in the
278Athena Form widget.  For example, it's impossible to create a widget
279that is centered in a window (to the best of my knowledge the Form
280widget doesn't support this, example code to the contrary would be
281greatly appreciated).  This is a bit of an annoyance, but usually
282isn't too much of a problem.
283
284     Libsx also doesn't let you name your widgets individually, so
285customization through your .Xdefaults file is possible, but not as
286flexible as it could be. For example, within a single program, all
287button widgets get called "button", and all label widgets are called
288"label" which makes it impossible to invdividually identify widgets in
289your .Xdefaults file.  This means you can't use your .Xdefaults to
290specify that button X has green text with a purple background while
291button Y has orange text on a chartruse background with blue
292highlights.  Either all your buttons are purple with green text or
293they are chartruse with orange text, but not both (hopefully none of
294them are either :-).
295
296     This could be fixed by adding a name argument to the MakeXXX()
297functions, but I'd prefer not to add another argument to those
298routines.  It's also possible to add a SetWidgetName() type of
299function which is a nice way to do it, but then it really starts to
300make generating an interface a very complicated thing.  Maybe I'll add
301a SetWidgetName(), but for now I don't think so.  The customization
302thing hasn't been too much of a big deal for me (you can still
303customize, it's just not as infinitely flexible as the underlying X
304mechanisms).
305
306     Presently libsx doesn't offer much support for detecting double
307clicks.  This is because of two reasons.  First, X doesn't provide any
308way for a user to get/set their preferred double-click time (at least
309as far as I know, example code to the contrary is welcomed) Second,
310getting sub-second timer accuracy in a portable fashion turns out to
311be rather problematic.  I've just learned that the times() function
312can be used in a roundabout way to get sub-second timing, but POSIX
313isn't as well and cleanly supported as one might hope.
314
315     If you'd like to see code that checks for double-clicks, look in
316the freq directory at freq.c.  It uses times() and seems to work well.
317
318
319--- Where do I go from here?
320
321     If you haven't already done it, compile libsx.  This builds the
322library itself and numerous demo programs.  Then take a look at the
323demo programs and the code behind them.  The main demo program is in
324the libsx/src directory (and is called `demo').  It demonstrates most
325of the features of libsx.  The other directories contain demos of
326varying complexity and these are your best starting point for building
327your own applications.  The most complicated application would be
328`bezier' which lets you interactively play with bezier curves.  It's a
329good framework for handling user-interaction and what not, so have a
330look at the sources.  Feel free to use the demo sources as the basis
331for your own programs (but of course I'd appreciate it if you give
332credit where credit is due).
333
334     The directories freq, creq, and multireq contain code written by
335a friend of mine, Allen Martin (amartin@wpi.wpi.edu).  Freq contains a
336file requestor function based on libsx.  Freq provides a single
337function GetFile() that lets a user select a file while browsing
338through the directory hierarchy.  Creq is a color chooser utility that
339lets a user select a color using RGB or HSV values (with sliders and
340all that jazz).  Multi-req is a very nice way to do form-fillout
341dialogs.  Take a look at the sample code in these directories and you
342should be able to figure out how to make use of the functions.
343
344     The documentation is always a nice thing to read too (especially
345since I put so much time into it :-).  The documentation isn't in man
346page style format (yet), sorry about that.  It was easier to write
347this way.  The documentation tries to cover all the bases, and with
348the example code, it shouldn't be hard to figure out (heck, if second
349year college students can do it with little or no help.... :-).  If
350you have comments/criticism on the docs, let me know.  If you'd like
351to convert the docs into a man page format, I'd also like to know :-)
352
353     The documentation to start reading first is either libsx_intro or
354general.libsx.doc.  Those introduce you to the basics and then you can
355go look at the more specific doc files for each of the various areas
356in libsx.
357
358
359
360     Well, that about sums it up.  I hope you find libsx handy and
361that you can make some use of it.  Any comments, questions or other
362communication can be sent to:
363
364                                 Dominic Giampaolo
365				 dbg@sgi.com
366
367
368
369
370Have Fun!
371
372
373p.s. Oh yeah, I need a disclaimer:
374
375     This code was written by me, Dominic Giampaolo, and should not
376     be taken to represent Silicon Graphics in any way, shape or
377     form.  I've written it on my own time, and for my own purposes.
378     SGI has nothing to do with it, so don't bother them about it.
379     (does that sound legal enough? :-)
380
381