File: main0.c

package info (click to toggle)
libsx 2.08-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 2,668 kB
  • sloc: ansic: 8,739; sh: 8,603; makefile: 62
file content (158 lines) | stat: -rw-r--r-- 4,024 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * This is a simple demo program that shows how to use multiple form
 * widgets.  All you really have to do is create the first form widget
 * before you create any of the child widgets.  Then when you are done
 * creating all the widgets that will go in a particular form, lay them
 * out with calls to SetWidgetPos() if necessary.  Then make your next
 * form, specifying where it should go relative to the previous form. Next 
 * you create all of this new form's children, lay them out, etc.  You can
 * create as many form widgets as you like in this manner.
 *
 * Just keep in mind that every time you create a form widget, all future
 * calls to the MakeXXX() functions will put that widget in the current
 * form widget (current is defined as the most recent form created).
 *
 *               --  This code is under the GNU copyleft  --
 *
 *   Dominic Giampaolo
 *   dbg@sgi.com
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>

#include "libsx.h"             /* gets us in the door with libsx          */


/* define's */
#define X_SIZE 300     /* default window size, change as desired */
#define Y_SIZE 300




void quit(Widget w, void *junk)
{
  exit(0);
}


#include "foo.h"

void redisplay(Widget w, int width, int height, void *arg)
{
  int i,j;
  int colors[5];

  SetBgColor(w, WHITE);
  ClearDrawArea();
  
  colors[0] = BLACK; 
  colors[1] = GREEN; 
  colors[2] = RED; 
  colors[3] = BLUE; 
  colors[4] = YELLOW; 

  for(i=0; i < width; i+=foo_width)
    for(j=0; j < height; j+=foo_height)
     {
       int fg, bg;

       /* pick some colors to draw with (that aren't the same) */
       fg = colors[rand()%5];
       while((bg = colors[rand()%5]) == fg)
	 ;

       SetFgColor(w, fg);
       SetBgColor(w, bg);
       DrawBitmap(foo_bits, i,j, foo_width, foo_height);
     }
}


/*
 * This function sets up the display for us.
 */

int init_display(int argc, char **argv, void *junk)
{
  Widget w[25], form1, form2, form3;

  argc = OpenDisplay(argc, argv);
  if (argc == FALSE)
    return argc;


  form1 = MakeForm(TOP_LEVEL_FORM);
  SetWidgetPos(form1, NO_CARE, NULL, NO_CARE, NULL);

  w[0] = MakeButton("fufanu", NULL, NULL);
  w[1] = MakeButton("foo", NULL, NULL);
  w[2] = MakeButton("Long String", NULL, NULL);
  w[3] = MakeButton("Blah", NULL, NULL);
  w[4] = MakeButton("Bletchrl", NULL, NULL);
  w[5] = MakeButton("Quit", quit, NULL);
  
  SetWidgetPos(w[1], PLACE_UNDER, w[0], NO_CARE, NULL);
  SetWidgetPos(w[2], PLACE_UNDER, w[1], NO_CARE, NULL);
  SetWidgetPos(w[3], PLACE_UNDER, w[2], NO_CARE, NULL);
  SetWidgetPos(w[4], PLACE_UNDER, w[3], NO_CARE, NULL);
  SetWidgetPos(w[5], PLACE_UNDER, w[4], NO_CARE, NULL);
  

  SetForm(TOP_LEVEL_FORM);
  w[6] = MakeDrawArea(X_SIZE, Y_SIZE, redisplay, NULL);
  SetWidgetPos(w[6], PLACE_RIGHT, form1, NO_CARE, NULL);

  form2 = MakeForm(TOP_LEVEL_FORM);
  SetWidgetPos(form2, PLACE_RIGHT, form1, PLACE_UNDER, w[6]);
  w[7] = MakeButton("Button1", NULL, NULL);
  w[8] = MakeButton("Button2", NULL, NULL);
  w[9] = MakeButton("Button3", NULL, NULL);

  SetWidgetPos(w[8], PLACE_RIGHT, w[7], NO_CARE, NULL);
  SetWidgetPos(w[9], PLACE_RIGHT, w[8], NO_CARE, NULL);

  form3 = MakeForm(form2);
  SetWidgetPos(form3, PLACE_UNDER, w[7], NO_CARE, NULL);

  w[10] = MakeButton("Sub Button1", NULL, NULL);
  w[11] = MakeButton("Sub Button2", NULL, NULL);
  w[12] = MakeButton("Sub Button3", NULL, NULL);

  SetWidgetPos(w[11], PLACE_UNDER, w[10], NO_CARE, NULL);
  SetWidgetPos(w[12], PLACE_UNDER, w[11], NO_CARE, NULL);
  

  /*
   * Now actually put the display on the screen.
   */
  ShowDisplay();

  /*
   * Get some colors for drawing with.
   */
  GetStandardColors();

  SetBgColor(form1, BLUE);
  SetBgColor(form2, YELLOW);

  SetBorderColor(w[6], GREEN);

  return argc;
}


int main(int argc, char **argv)
{
  argc = init_display(argc, argv, NULL);    /* setup the display */
  if (argc == 0)
    exit(0);


  MainLoop();                                /* go right into the main loop */
  return 0;  
}