1 /* This file contains callback routines that drive the display.
2  *
3  * If you add a function to this file, you should also add a function
4  * prototype for it to the callbacks.h file (unless it is an internal
5  * function, then you should just add it down below where it says
6  * "internal prototypes").
7  *
8  *              --  This code is under the GNU copyleft  --
9  *
10  *   Dominic Giampaolo
11  *   dbg@sgi.com
12  */
13 
14 #include <stdio.h>
15 #include <ctype.h>
16 #include <math.h>
17 #include "libsx.h"
18 #include "main.h"
19 #include "callbacks.h"
20 
21 
22 
23 
quit(Widget w,void * data)24 void quit(Widget w, void *data)
25 {
26   /* Do any cleanup that is necessary for your program here */
27 
28   exit(0);
29 }
30 
31 
32 
next_cmap(Widget w,void * data)33 void next_cmap(Widget w, void *data)
34 {
35   MyProgram *me = (MyProgram *)data;
36 
37   me->cur_colormap++;
38   if (me->cur_colormap > 3)
39     me->cur_colormap = 0;
40 
41   SetColorMap(me->cur_colormap);
42 }
43 
44 
prev_cmap(Widget w,void * data)45 void prev_cmap(Widget w, void *data)
46 {
47   MyProgram *me = (MyProgram *)data;
48 
49   me->cur_colormap--;
50   if (me->cur_colormap < 0)
51     me->cur_colormap = 3;
52 
53   SetColorMap(me->cur_colormap);
54 }
55 
56 
57 
58 /* Here is where all redrawing will take place for your program.
59  * When the window needs to be redrawn, this function will be called.
60  * When your program starts up for the first time, this function will
61  * be called and you should draw anything you need to draw in here.
62  */
63 
redisplay(Widget w,int width,int height,void * data)64 void redisplay(Widget w, int width, int height, void *data)
65 {
66   MyProgram *me=data;
67   int i;
68 
69   ClearDrawArea();                   /* start with a clean slate */
70 
71   for(i=0; i < width; i++)           /* draw some pretty patterns */
72    {
73      SetColor(i);          /* this will step through the gradient of colors */
74      DrawLine(0,i, i,height);
75    }
76 
77   for(i=0; i < width; i++)
78    {
79      SetColor(i);
80     DrawLine(width,i, width-i,height);
81    }
82 
83   SetColor(RED);
84   DrawText("My Cool Program", (width/2)-50, height/2);
85 }
86 
87 
88 
89 
90