summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_get_highlight_color.cxx
blob: 1e2ed894ba7ae5e7a5ef737d99cf6e8f24228b63 (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

#include <Xw_Extension.h>

	/* ifdef then trace on */
#ifdef TRACE
#define TRACE_GET_HIGHLIGHT_COLOR
#define TRACE_GET_HIGHLIGHT_PIXEL
#endif

/*
   XW_STATUS Xw_get_highlight_color(acolormap,r,g,b):
   XW_EXT_COLORMAP *acolormap	Colormap extension structure
   float *r,*g,*b ;		Returns Red,Green,Blue color value 0. >= x <= 1.

	Get R,G,B Highlight Color values from Default index .

	Returns ERROR if Extended Colormap Address is badly defined
	Returns SUCCESS if Successful      

   XW_STATUS Xw_get_highlight_pixel(acolormap,pixel):
   XW_EXT_COLORMAP *acolormap	Colormap extension structure
   unsigned long *pixel;	Returns HighLight pixel

*/

#ifdef XW_PROTOTYPE
XW_STATUS Xw_get_highlight_color (void* acolormap,
					float* r,float* g,float* b)
#else
XW_STATUS Xw_get_highlight_color (acolormap,r,g,b)
void *acolormap;
float *r,*g,*b ;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*)acolormap;
XColor color ;

	if ( !Xw_isdefine_colormap(pcolormap) ) {
	    /*ERROR*Bad EXTENDED Colormap ADDRESS*/
	    Xw_set_error(42,"Xw_get_highlight_color",pcolormap) ;
	    return (XW_ERROR) ;
	}

	switch ( _CCLASS ) {

	  case PseudoColor :
	  case StaticColor :
	    color.pixel = pcolormap->highpixel ;
	    XQueryColor(_CDISPLAY,_CINFO.colormap,&color) ;
	    *r = (float)color.red/0xFFFF ;
	    *g = (float)color.green/0xFFFF ;
	    *b = (float)color.blue/0xFFFF ;
	    break ;

	  case TrueColor :
            { unsigned long mask = _CVISUAL->map_entries-1 ;
              unsigned long red,green,blue ;
              unsigned long rmask = _CVISUAL->red_mask ;
              unsigned long gmask = _CVISUAL->green_mask ;
              unsigned long bmask = _CVISUAL->blue_mask ;

	      color.pixel = pcolormap->highpixel ;
              red = color.pixel & rmask ;
              while ( !(rmask & 0x01) ) { rmask >>= 1; red >>= 1; }
 
              green = color.pixel & gmask ;
              while ( !(gmask & 0x01) ) { gmask >>= 1; green >>= 1; }
 
              blue = color.pixel & bmask ;
              while ( !(bmask & 0x01) ) { bmask >>= 1; blue >>= 1; }
 
              *r = (float)red/mask ;
              *g = (float)green/mask ;
              *b = (float)blue/mask ;
	    }
	    break ;

            default :
              /*Unmatchable Visual class*/
              Xw_set_error(67,"Xw_get_highlight_color",&_CCLASS) ;
              return (XW_ERROR) ;
	}



#ifdef TRACE_GET_HIGHLIGHT_COLOR
if( Xw_get_trace() > 1 ) {
    printf(" Xw_get_highlight_color(%lx,%f,%f,%f)\n",(long ) pcolormap,*r,*g,*b) ;
}
#endif

	return (XW_SUCCESS);
}

#ifdef XW_PROTOTYPE
XW_STATUS Xw_get_highlight_pixel (void* acolormap,unsigned long *pixel)
#else
XW_STATUS Xw_get_highlight_pixel (acolormap,pixel)
void *acolormap;
unsigned long *pixel;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*)acolormap;
//XColor color ;

	if ( !Xw_isdefine_colormap(pcolormap) ) {
	    /*ERROR*Bad EXTENDED Colormap ADDRESS*/
	    Xw_set_error(42,"Xw_get_highlight_pixel",pcolormap) ;
	    return (XW_ERROR) ;
	}

	*pixel = pcolormap->highpixel ;

#ifdef TRACE_GET_HIGHLIGHT_PIXEL
if( Xw_get_trace() > 1 ) {
    printf(" Xw_get_highlight_pixel(%lx,%lx)\n",(long ) pcolormap,*pixel) ;
}
#endif

	return (XW_SUCCESS);
}