~ubuntu-branches/ubuntu/vivid/gcl/vivid

« back to all changes in this revision

Viewing changes to o/littleXwin.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2002-03-04 14:29:59 UTC
  • Revision ID: james.westby@ubuntu.com-20020304142959-dey14w08kr7lldu3
Tags: upstream-2.5.0.cvs20020219
ImportĀ upstreamĀ versionĀ 2.5.0.cvs20020219

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************/
 
2
 
 
3
#include <stdio.h>
 
4
#include <X11/Xlib.h>           /* the X library */
 
5
#include <X11/Xutil.h>          /* the X library */
 
6
 
 
7
   /* a few arbitary constants */
 
8
#define START_X         10
 
9
#define START_Y         20
 
10
#define WINDOW_WIDTH   225   
 
11
#define WINDOW_HEIGHT  400
 
12
#define BORDER_WIDTH     1
 
13
#define KEY_STR_LENGTH  20
 
14
 
 
15
Display *the_display;           /* the display that will be used */
 
16
int the_screen;                 /* the screen that will be used */
 
17
Window root_window;             /* the root window on the screen */
 
18
XSizeHints size_hints;          /* size hints for the window manager */
 
19
XEvent the_event;               /* the structure for the input event */
 
20
XSetWindowAttributes attributes;/* the windows attributes */
 
21
 
 
22
GC the_solid_GC,
 
23
   the_clear_GC;     /* the graphics contexts */
 
24
 
 
25
XGCValues the_solid_GC_values,
 
26
          the_clear_GC_values;
 
27
 
 
28
Colormap cmap;
 
29
XFontStruct *the_fontstruct;       /* the font info to be used */
 
30
 
 
31
Window open_window()
 
32
{
 
33
  Window the_window;              /* the window that will be opened */
 
34
  int i, stop;
 
35
 
 
36
  /* Set the display to be the default display (ie, your
 
37
     display as given in the environment variable DISPLAY). */
 
38
 
 
39
  if ((the_display = XOpenDisplay("")) == NULL)
 
40
    {
 
41
      printf("can't open display\n");
 
42
      return(-1);
 
43
    }
 
44
 
 
45
  /* A few useful values. */
 
46
 
 
47
  the_screen = DefaultScreen(the_display);
 
48
  root_window = RootWindow(the_display,the_screen);
 
49
 
 
50
  /* Set the size hints for the window manager. */
 
51
 
 
52
  size_hints.x = START_X;
 
53
  size_hints.y = START_Y;
 
54
  size_hints.width = WINDOW_WIDTH;
 
55
  size_hints.height = WINDOW_HEIGHT;
 
56
  size_hints.flags = PSize|PPosition;
 
57
 
 
58
  /* Create a window of fixed size, origin, and borderwidth.
 
59
     The window will have a black border and white background. */
 
60
 
 
61
  the_window = XCreateSimpleWindow(the_display,root_window,
 
62
                                   size_hints.x,size_hints.y,size_hints.width,
 
63
                                   size_hints.height,BORDER_WIDTH,
 
64
                                   BlackPixel(the_display,the_screen),
 
65
                                   WhitePixel(the_display,the_screen));
 
66
                                   
 
67
  XSetStandardProperties(the_display,the_window,"My Window","My Icon",
 
68
                         None,NULL,NULL,&size_hints);
 
69
 
 
70
  cmap = DefaultColormap(the_display, the_screen);
 
71
 
 
72
  the_solid_GC = XCreateGC(the_display, the_window, None, &the_solid_GC_values);
 
73
  the_clear_GC = XCreateGC(the_display, the_window, None, &the_clear_GC_values);
 
74
 
 
75
  /* for a sun */
 
76
  XSetBackground(the_display, the_solid_GC, BlackPixel(the_display,the_screen));
 
77
  XSetForeground(the_display, the_solid_GC, BlackPixel(the_display,the_screen));
 
78
 
 
79
  XSetBackground(the_display, the_clear_GC, WhitePixel(the_display,the_screen));
 
80
  XSetForeground(the_display, the_clear_GC, WhitePixel(the_display,the_screen));
 
81
 
 
82
  if ((the_fontstruct = XLoadQueryFont(the_display,"8x13")) == NULL)
 
83
    {
 
84
      printf("could not open font\n");
 
85
      return(-1);
 
86
    }
 
87
  /* Put the font into the graphics context for draw operations. */
 
88
  XSetFont(the_display, the_solid_GC, the_fontstruct->fid);
 
89
  XSetFont(the_display, the_clear_GC, the_fontstruct->fid);
 
90
 
 
91
  /* Tell the server to make the window visible. */
 
92
 
 
93
  XMapWindow(the_display,the_window);
 
94
 
 
95
  attributes.bit_gravity = NorthWestGravity;
 
96
  XChangeWindowAttributes(the_display, the_window, CWBitGravity, &attributes);
 
97
  XFlush(the_display);
 
98
  return(the_window);
 
99
}
 
100
 
 
101
int close_window(the_window)
 
102
  Window the_window;
 
103
{
 
104
  XDestroyWindow(the_display, the_window);
 
105
  XFlush(the_display);
 
106
  return(1);
 
107
}
 
108
 
 
109
int draw_line(the_window, x1, y1, x2, y2)
 
110
  Window the_window;
 
111
  int x1, y1, x2, y2;
 
112
{
 
113
  XDrawLine(the_display, the_window, the_solid_GC, x1, y1, x2, y2);
 
114
  XFlush(the_display);
 
115
  return(1);
 
116
}
 
117
 
 
118
int draw_arc(the_window, x, y, width, height, angle1, angle2)
 
119
  Window the_window;
 
120
  int x, y, width, height, angle1, angle2;
 
121
{
 
122
  XDrawArc(the_display, the_window, the_solid_GC,
 
123
           x, y, width, height, angle1, angle2);
 
124
  XFlush(the_display);
 
125
  return(1);
 
126
}
 
127
 
 
128
int fill_arc(the_window, x, y, width, height, angle1, angle2)
 
129
  Window the_window;
 
130
  int x, y, width, height, angle1, angle2;
 
131
{
 
132
  XFillArc(the_display, the_window, the_solid_GC,
 
133
           x, y, width, height, angle1, angle2);
 
134
  XFlush(the_display);
 
135
  return(1);
 
136
}
 
137
 
 
138
int clear_arc(the_window, x, y, width, height, angle1, angle2)
 
139
  Window the_window;
 
140
  int x, y, width, height, angle1, angle2;
 
141
{
 
142
  XFillArc(the_display, the_window, the_clear_GC,
 
143
           x, y, width, height, angle1, angle2);
 
144
  XFlush(the_display);
 
145
  return(1);
 
146
}
 
147
 
 
148
int set_arc_mode (pie_or_chord)
 
149
{
 
150
  if (pie_or_chord == 0) {
 
151
    XSetArcMode(the_display, the_solid_GC, ArcChord);
 
152
    XSetArcMode(the_display, the_clear_GC, ArcChord);
 
153
  }
 
154
  else {
 
155
    XSetArcMode(the_display, the_solid_GC, ArcPieSlice);
 
156
    XSetArcMode(the_display, the_clear_GC, ArcPieSlice);
 
157
  }
 
158
  return(1);
 
159
}
 
160
 
 
161
int erase_line(the_window, x1, y1, x2, y2)
 
162
  Window the_window;
 
163
  int x1, y1, x2, y2;
 
164
{
 
165
  XDrawLine(the_display, the_window, the_clear_GC, x1, y1, x2, y2);
 
166
  XFlush(the_display);
 
167
  return(1);
 
168
}
 
169
 
 
170
int draw_text(the_window, string, x, y)
 
171
  Window the_window;
 
172
  char *string;
 
173
  int x, y;
 
174
{
 
175
  XDrawString(the_display, the_window, the_solid_GC, x, y,
 
176
              string, strlen(string));
 
177
  XFlush(the_display);
 
178
  return(1);
 
179
}
 
180
 
 
181
int erase_text(the_window, string, x, y)
 
182
  Window the_window;
 
183
  char *string;
 
184
  int x, y;
 
185
{
 
186
  XDrawString(the_display, the_window, the_clear_GC, x, y,
 
187
              string, strlen(string));
 
188
  XFlush(the_display);
 
189
  return(1);
 
190
}
 
191
 
 
192
int clear_window(the_window)
 
193
  Window the_window;
 
194
{
 
195
  XClearWindow(the_display, the_window);
 
196
  XFlush(the_display);
 
197
  return(1);
 
198
}
 
199
 
 
200
int resize_window(the_window, width, height)
 
201
  Window the_window;
 
202
  int width, height;
 
203
{
 
204
  XResizeWindow(the_display, the_window, width, height);
 
205
  XFlush(the_display);
 
206
  return(1);
 
207
}
 
208
 
 
209
int raise_window(the_window)
 
210
  Window the_window;
 
211
{
 
212
  XRaiseWindow(the_display, the_window);
 
213
  XFlush(the_display);
 
214
  return(1);
 
215
}
 
216
 
 
217
int use_font (font_name)
 
218
  char *font_name;
 
219
{
 
220
  if ((the_fontstruct = XLoadQueryFont(the_display, font_name)) == NULL)
 
221
    return(-1);
 
222
 
 
223
  /* Put the font into the graphics context for draw operations. */
 
224
  XSetFont(the_display, the_solid_GC, the_fontstruct->fid);
 
225
  XSetFont(the_display, the_clear_GC, the_fontstruct->fid);
 
226
  XFlush(the_display);
 
227
  return(1);
 
228
}
 
229
 
 
230
 
 
231
 
 
232
int set_background (the_window, color_string)
 
233
  Window the_window;
 
234
  char *color_string;
 
235
{
 
236
  XColor color;
 
237
  int result;
 
238
 
 
239
  if (result = XParseColor(the_display, cmap, color_string, &color)) {
 
240
    if (result = XAllocColor(the_display, cmap, &color)) {
 
241
      XSetWindowBackground(the_display, the_window, color.pixel);
 
242
      XSetBackground(the_display, the_clear_GC, color.pixel);
 
243
      XSetForeground(the_display, the_clear_GC, color.pixel);
 
244
      XFlush(the_display);
 
245
    }
 
246
  }
 
247
  return(result);
 
248
}
 
249
 
 
250
int set_foreground (color_string)
 
251
  char *color_string;
 
252
{
 
253
  XColor color;
 
254
  int result;
 
255
 
 
256
  if (result = XParseColor(the_display, cmap, color_string, &color)) {
 
257
    if (result = XAllocColor(the_display, cmap, &color)) {
 
258
      XSetForeground(the_display, the_solid_GC, color.pixel);
 
259
      XSetBackground(the_display, the_solid_GC, color.pixel);
 
260
      XFlush(the_display);
 
261
      return(1);
 
262
    }
 
263
  }
 
264
}