File: win.h

package info (click to toggle)
craft 3.5-10
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,000 kB
  • ctags: 1,602
  • sloc: cpp: 3,794; makefile: 2,319; ansic: 857; sh: 385
file content (351 lines) | stat: -rw-r--r-- 12,475 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#ifndef win_h
#define win_h

/*======================================================================*/
/*= CHANGES AND UPDATES                                                =*/
/*======================================================================*/
/*= date   person file       subject                                   =*/
/*=--------------------------------------------------------------------=*/
/*=                                                                    =*/
/*= 050293 hua    win.h      added enable                              =*/
/*=                                                                    =*/
/*= 110293 hua    win.h      added set_color                           =*/
/*=                                                                    =*/
/*======================================================================*/

/*======================================================================*/
/*                                                                      */
/* Includes                                                             */
/*                                                                      */
/*======================================================================*/
 
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "X11/Xlib.h"
#include "X11/Xutil.h"
#include "X11/cursorfont.h"

#include "io.h"
#include "bool.h"
#include "xmath.h"
#include "table.h"
#include "paramreader.h"

/*----------------------------------------------------------------------*/
/*  mouse modes                                                         */
/*----------------------------------------------------------------------*/

#define button1press    1
#define button2press    2
#define button3press    3
#define button1release -1
#define button2release -2
#define button3release -3
#define nobutton       -999

/*----------------------------------------------------------------------*/
/* colors                                                               */
/*----------------------------------------------------------------------*/

#define white        0
#define red          1
#define red1         2
#define red2         3
#define red3         4
#define red4         5
#define sienna       6
#define sienna1      7
#define sienna2      8
#define sienna3      9
#define sienna4     10
#define yellow      11
#define yellow1     12
#define yellow2     13
#define yellow3     14
#define yellow4     15
#define green       16
#define green1      17
#define green2      18
#define green3      19
#define green4      20
#define blue        21
#define blue1       22
#define blue2       23
#define blue3       24
#define blue4       25
#define slategray   26
#define slategray1  27
#define slategray2  28
#define slategray3  29
#define slategray4  30
#define darkgreen   31
#define seagreen    32
#define seagreen1   33
#define seagreen2   34
#define seagreen3   35
#define cyan        36
#define cyan1       37
#define cyan2       38
#define cyan3       39
#define cyan4       40
#define purple      41
#define purple1     42
#define purple2     43
#define purple3     44
#define purple4     45
#define gold        46
#define gold1       47
#define gold2       48
#define gold3       49
#define gold4       50
#define gray        51
#define gray10      52
#define gray20      53
#define gray30      54
#define gray40      55
#define gray50      56
#define gray60      57
#define gray70      58
#define gray80      59
#define gray90      60
#define gray100     61
#define navyblue    62
#define black       63

/*----------------------------------------------------------------------*/
/* FONTS                                                                */
/*----------------------------------------------------------------------*/

#define win_default_font  "-misc-*-*-*-*-*-*-*-*-*-*-*-*-*"

/*----------------------------------------------------------------------*/
/* ROUTINES bitmap size information (deklarations)                      */
/*----------------------------------------------------------------------*/

bool bitmap_size (char name [], int &dx, int &dy);

/*----------------------------------------------------------------------*/
/* ROUTINES text size information (deklarations)                        */
/*----------------------------------------------------------------------*/

void text_size (char s [], char font [], int &dx, int &dy, int &num_of_lines);

/*----------------------------------------------------------------------*/
/* Default Handler (deklarations)                                       */
/*----------------------------------------------------------------------*/

#define default_win_param_file_name "/home/hua/craft/.windefaults"

extern bool        win_handler_init;
extern paramreader *win_defaults;

int   win_default_i (int param, char default_name []);
int   win_default_i (char default_name []);
int   win_default_c (int param, char default_name []);
int   win_default_c (char default_name []);
char *win_default_s (char default_name []);
int   win_color     (char color_name   []);

/*----------------------------------------------------------------------*/
/* CLASS polyline (deklarations)                                        */
/*----------------------------------------------------------------------*/

#define max_poly_points 20

class polyline
  {public :

     int    n;
     XPoint p [max_poly_points];

          polyline  ();
          ~polyline ();

     void add       (int x, int y);
     void close     ();

  };

/*----------------------------------------------------------------------*/
/* CLASS win (deklarations)                                             */
/*----------------------------------------------------------------------*/

#define max_mouse_events 16
#define max_colors       64
#define by_user          -1
#define by_fix           -2
#define by_default       -3
#define keybuf_size      256

class win
  {public :

     Colormap      cmap;
     Display       *mydisplay;
     Window        mywindow;
     int           myscreen;
     GC            mygc;		
     unsigned long myforeground;
     unsigned long mybackground;
     XSizeHints    *myhint;
     XFontStruct   *font_info;

     long          event_mask;
     bool          is_enable;
     bool          is_alien;
     bool          with_fix;
     char          name [128];
     int           open_x;
     int           open_y;
     int           open_dx;
     int           open_dy;
     int           w_dx;
     int           w_dy;

     int           last_best_color;

     unsigned long last_pixel;
     int           last_r;
     int           last_g;
     int           last_b;
     bool          is_last_pixel;

     static char   fix_name [128];
     static char   fix_dir  [128];
     static bool   fix_initialized;

     int           colors  [max_colors];
     int           color_r [max_colors];
     int           color_g [max_colors];
     int           color_b [max_colors];
     int           num_colors;

     char          inbuffer   [keybuf_size];
     int           keybuffer  [keybuf_size];
     char          cntlbuffer [keybuf_size][32];
     int           keycount;
     int           act_key;
     int           press_cnt;

     bool          mouse_inside;
     int           mouse_x;
     int           mouse_y;

     bool          mouse_press [3];
     int           mouse_ex    [max_mouse_events];
     int           mouse_ey    [max_mouse_events];
     int           mouse_event [max_mouse_events];
     int           mouse_eid   [max_mouse_events];
     int           num_mouse_events;
     int           event_mark;
     int           event_id;

          win  (char title []);

          win  (char title [],
                char host  [],
                int  x,
                int  y, 
                int  dx,
                int  dy,
                bool enable        = true,
                bool resize_enable = false);
          win  (win  *parent,
                char title [],
                char host  [],
                int  x,
                int  y, 
                int  dx,
                int  dy,
                bool enable        = true,
                bool resize_enable = false);  
          ~win ();

     void   iconify          ();
     void   fix              ();
     void   fix_pos          (int &x,  int &y);
     void   fix_size         (int &dx, int &dy);
     void   set_cursor       (char name []);
     void   set_cursor       (int cursor);
     void   set_color        (int r, int g, int b);
     void   win_rgb          (int color, int &r, int &g, int b);
     int    win_color        (int r, int g, int b);
     void   set_color        (int color);
     void   set_background   (int color);
     void   function         (int func);
     void   shift            (int x1, int y1, int x2, int y2, int dx, int dy);
     void   pixel            (int x, int y);
     void   pixel            (Pixmap p, int x, int y);
     void   line             (int x1, int y1, int x2, int y2);
     void   box              (int x1, int y1, int x2, int y2);
     void   fill             (int x1, int y1, int dx, int dy);
     void   move             (int x,  int y,  int x1, int y1, int dx, int dy);
     bool   on               ();
     bool   mouse            (int &x, int &y, int &button);
     bool   mouse            (int &x, int &y, int &ex, int &ey, int &button);
     bool   mouse_is_pressed (int button);
     bool   is_mouse         (int &xe, int &ye, int &button);
     void   mark_mouse       ();
     void   scratch_mouse    ();
     void   clear            ();
     void   set_font         (char name []);
     void   text_size        (char string [], int &dx, int &dy);
     void   write            (int x, int y, char   string []);
     void   write            (int x, int y, double d);
     void   write            (int x, int y, int    i);
     void   set_clip         (int x, int y, int dx, int dy);
     void   show_map         (int x, int y, char name []);
     void   show_map         (int x, int y, Pixmap m, int dx, int dy);
     void   show_map         (int x, int y,
                              int s_x, int s_y, Pixmap m, int dx, int dy);
     void   show_map         (int x, int y, Pixmap m, int dx, int dy, 
                              Pixmap mask, int clip_x, int clip_y);
     void   show_map         (int x, int y, Pixmap m, int dx, int dy, 
                              Pixmap mask);
      void show_map          (Pixmap m,
                              Pixmap mask,
                              int    x_source,
                              int    y_source,
                              int    x_screen,
                              int    y_screen,
                              int    dx,
                              int    dy, 
                              int    x_mask,
                              int    y_mask);
     void   load_map         (char name [], Pixmap &m, int &dx, int &dy);
     void   store_map        (char name [], int x, int y, int dx, int dy);
     void   store_map        (Pixmap &p, int x, int y, int dx, int dy);
     void   store_map        (Pixmap &p, int x, int y, int dx, int dy,
                              Pixmap mask);
     void   create_map       (Pixmap &p, int dx, int dy);
     void   delete_map       (Pixmap &p);
     void   sync             ();
     void   idle             (bool mode);
     char   inchar           ();
     char   inchar           (int &key);
     char   inchar           (int &key, char *cntl);
     int    getkey           ();
     int    x                ();
     int    y                ();
     int    dx               ();
     int    dy               ();
     void   tick             (bool just_raised);
     void   tick             ();
     void   alloc_color      (char name [], int no);
     void   create_color_map ();
     void   draw             (polyline *p);
     void   fill             (polyline *p);
     void   xsync            ();

     Window grab             (Display *dsp, Window wnd, char name []);

     void   get_image        (XImage *&i, int x, int y, int dx, int dy);
     void   put_image        (XImage *i, int x, int y, int dx, int dy);
     void   get_color        (XImage *i, int x, int y, int &r, int &g, int &b);
     void   set_pixel        (XImage *i, int x, int y, int color);
     void   ppm              (char file_name [], int x, int y, int dx, int dy);

 };

#endif