summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_set_line_attrib.cxx
blob: 81406ccd0dd9f98d19c1b629357a51b819e57372 (plain)
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

#include <Xw_Extension.h>

	/* ifdef then trace on */
#ifdef TRACE
#define TRACE_SET_LINE_ATTRIB
#define TRACE_GET_LINE_ATTRIB
#endif

/*
   XW_ATTRIB Xw_set_line_attrib (awindow,color,type,width,mode):
   XW_EXT_WINDOW *awindow
   int color ;		Color index to used 0 >= x < MAXCOLOR
   int type ;		Type index to used 0 >= x < MAXTYPE
   int width ;		Width index to used 0 >= x < MAXWIDTH
   XW_DRAWMODE mode ;	Draw Mode must be one of DRAWMODE enum 

	Set Line Color,Type and Width current graphic attrib .

	Returns Selected Line Graphic Attribute Index if successful 
	Returns 0 if Bad Color,Type or Width Index

*/

#ifdef XW_PROTOTYPE
XW_ATTRIB Xw_set_line_attrib (void *awindow,int color,int type,int width,XW_DRAWMODE mode)
#else
XW_ATTRIB Xw_set_line_attrib (awindow,color,type,width,mode)
void *awindow;
int color,type,width ;
XW_DRAWMODE mode ;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
XGCValues gc_values ;
XW_ATTRIB code ;
int i,j,k,function,mask = 0 ;
unsigned long planemask,hcolor ;

        if( !Xw_isdefine_window(pwindow) ) {
            /*ERROR*Bad EXT_WINDOW Address*/
            Xw_set_error(24,"Xw_set_line_attrib",pwindow) ;
            return (0) ;
        }

	if( _BINDEX > 0 ) return (1) ;

	if ( !Xw_isdefine_color(_COLORMAP,color) ) {
	    /*ERROR*Bad Defined Color*/
	    Xw_set_error(41,"Xw_set_line_attrib",&color) ;
	    return (0) ;
	}
	if ( !Xw_isdefine_type(_TYPEMAP,type) ) {
	    /*WARNING*Bad Defined Type*/
	    Xw_set_error(50,"Xw_set_line_attrib",&type) ;
	    type = 0 ;
	}
	if ( !Xw_isdefine_width(_WIDTHMAP,width) ) {
	    /*WARNING*Bad Defined Width*/
	    Xw_set_error(52,"Xw_set_line_attrib",&width) ;
	    width = 0 ;
	}

	if( !_TYPEMAP || !_TYPEMAP->types[type] ) type = 0 ;
	if( !_WIDTHMAP || (_WIDTHMAP->widths[width] <= 1) ) width = 0 ;

	code = QGCODE(color,type,width,mode) ;
	if( code == pwindow->qgline[pwindow->lineindex].code ) {
				/* The last index computed is already set*/
	    pwindow->qgline[pwindow->lineindex].count++ ;
	    return (pwindow->lineindex+1) ;	
	}

	for( i=j=0,k=MAXQG ; i<MAXQG ; i++ ) {
	     if( code == pwindow->qgline[i].code ) k = i ;
	     if( pwindow->qgline[i].count < pwindow->qgline[j].count ) j = i;
	}

	if( k < MAXQG ) {
				/* A GC index already exist,use it */
	    pwindow->lineindex = k ;
	    pwindow->qgline[k].count++ ;
	    return (k+1) ;	
	}
	
	pwindow->lineindex = j ;
	pwindow->qgline[j].count = 1 ;

	Xw_get_color_attrib(pwindow,mode,color,&hcolor,&function,&planemask);
	if( mode != QGMODE(pwindow->qgline[j].code) ) {
	    mask |= GCFunction | GCPlaneMask | GCForeground ;
	    gc_values.function = function ;
	    gc_values.plane_mask = planemask ;
       	    gc_values.foreground = hcolor ;
	} else if( color != QGCOLOR(pwindow->qgline[j].code) ) {  
	    mask |= GCForeground ;
            gc_values.foreground = hcolor ;
	}

   if( width != QGWIDTH(pwindow->qgline[j].code) ) {  
	    mask |= GCLineWidth ;
	    if( width > 0 ) {
	        gc_values.line_width = (_WIDTHMAP->widths[width] > 1) ?
						_WIDTHMAP->widths[width] : 0 ;
	    } else {
		gc_values.line_width = 0 ;
	    }
	}

	if( type != QGTYPE(pwindow->qgline[j].code) ) {
	    mask |= GCLineStyle ;
	    if( type > 0 ) { 
                gc_values.line_style = LineOnOffDash ; 
	        XSetDashes(_DISPLAY,pwindow->qgline[j].gc,0,
		(char*)_TYPEMAP->types[type],strlen((char*)_TYPEMAP->types[type])) ;
	    } else {
                gc_values.line_style = LineSolid ;
	    }
	}

	k = j+1 ;
	
	if( mask ) {
	    XChangeGC(_DISPLAY,pwindow->qgline[j].gc,mask,&gc_values) ;
            pwindow->qgline[j].code = code ; 

#ifdef  TRACE_SET_LINE_ATTRIB
if( Xw_get_trace() ) {
    printf(" %d = Xw_set_line_attrib(%lx,%d,%d,%d,%d)\n",
					k,(long ) pwindow,color,type,width,mode) ;
}
#endif
	}

	return (k) ;	
}

/*
   XW_ATTRIB Xw_get_poly_attrib (awindow,color,type,width,mode):
   XW_EXT_WINDOW *awindow
   int *color ;         Returns current Color index
   int *type ;          Returns current Type
   int *width ;         Returns current Width index
   DRAWMODE *mode ;     Returns current Draw Mode

        Returns Selected Polyline Attribute Index

*/

#ifdef XW_PROTOTYPE
XW_ATTRIB Xw_get_line_attrib (void *awindow,int *color,int *type,int *width,XW_DRAWMODE *mode)
#else
XW_ATTRIB Xw_get_line_attrib (awindow,color,type,width,mode)
void *awindow;
int *color,*width ;
int *type ;
XW_DRAWMODE *mode ;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
XW_ATTRIB code;
int j;

  j = pwindow->lineindex;

  code = pwindow->qgline[j].code;

  *color = QGCOLOR(code);
  *type = QGTYPE(code);
  *width = QGWIDTH(code); 
  *mode = (XW_DRAWMODE) QGMODE(code);

#ifdef  TRACE_GET_LINE_ATTRIB
if( Xw_get_trace() > 1 ) {
    printf(" %d = Xw_get_line_attrib(%lx,%d,%d,%d,%d)\n",
                                j+1,(long ) pwindow,*color,*type,*width,*mode) ;
}
#endif

  return code;
}