1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
19 #include <Xw_Extension.h>
21 /* ifdef then trace on */
23 #define TRACE_DEF_HIGHLIGHT_COLOR
27 STATUS Xw_def_highlight_color(acolormap,r,g,b):
28 XW_EXT_COLORMAP *acolormap
29 float r,g,b ; Red,Green,Blue color value 0. >= x <= 1.
31 Update Highlight Color index with the specified R,G,B values .
32 NOTE than highlight color is shared between all Windows
34 Returns ERROR if Extended Colormap is not properly defined
35 Returns SUCCESS if Successful
40 XW_STATUS Xw_def_highlight_color (void* acolormap,
41 float r,float g,float b)
43 XW_STATUS Xw_def_highlight_color (acolormap,r,g,b)
46 #endif /*XW_PROTOTYPE*/
48 XW_EXT_COLORMAP *pcolormap = (XW_EXT_COLORMAP*)acolormap ;
50 int i,cclass,index = -1,isapproximate ;
51 XW_STATUS status = XW_SUCCESS;
52 unsigned long highpixel;
54 if ( !Xw_isdefine_colormap(pcolormap) ) {
55 /*ERROR*Bad EXT_COLORMAP Address*/
56 Xw_set_error(42,"Xw_def_highlight_color",pcolormap) ;
60 if( pcolormap->mapping == Xw_TOM_READONLY ) {
69 Xw_get_color_pixel(pcolormap,r,g,b,&highpixel,&isapproximate) ;
73 if( pcolormap->mapping == Xw_TOM_COLORCUBE ) {
74 if( (_CGINFO.red_mult > 0) && (fabs(r-g) < 0.01) && (fabs(r-b) < 0.01) ) {
75 index = (int)(0.5+r*_CGINFO.red_max)*_CGINFO.red_mult;
76 if( _CINFO.red_max > 0 )
77 index += (_CINFO.red_max+1)*(_CINFO.green_max+1)*(_CINFO.blue_max+1);
78 } else if( _CINFO.red_mult > 0 ) {
79 index = ((int)(0.5+r*_CINFO.red_max))*_CINFO.red_mult+
80 ((int)(0.5+g*_CINFO.green_max))*_CINFO.green_mult+
81 ((int)(0.5+b*_CINFO.blue_max))*_CINFO.blue_mult;
82 } else if( _CGINFO.red_mult > 0 ) {
84 index = (int)(0.5+l*_CGINFO.red_max)*_CGINFO.red_mult;
88 highpixel = _CINFO.base_pixel + index ;
89 } else if( pcolormap->mapping == Xw_TOM_BESTRAMP ) {
90 color.red = (unsigned short) (r * 0xFFFF) ;
91 color.green = (unsigned short) (g * 0xFFFF) ;
92 color.blue = (unsigned short) (b * 0xFFFF) ;
93 color.flags = DoRed|DoGreen|DoBlue ;
94 for( i=0 ; i<pcolormap->maxcolor ; i++ ) {
95 if( (pcolormap->pixels[i] & 1) &&
96 ((pcolormap->define[i] == FREECOLOR) ||
97 (pcolormap->define[i] == HIGHCOLOR)) ) {
98 pcolormap->define[i] = HIGHCOLOR ;
99 color.pixel = pcolormap->pixels[i] ;
100 XStoreColor(_CDISPLAY,_CINFO.colormap,&color) ;
103 highpixel = pcolormap->pixels[1];
104 } else if( pcolormap->mapping == Xw_TOM_SIMPLERAMP ) {
105 Xw_get_color_index(pcolormap,r,g,b,&index) ;
106 highpixel = _CINFO.base_pixel + index ;
111 status = Xw_alloc_color(pcolormap,r,g,b,&highpixel,&isapproximate) ;
117 pcolormap->define[index] = HIGHCOLOR ;
119 pcolormap->highpixel = highpixel ;
121 Xw_reset_attrib(NULL) ;
125 #ifdef TRACE_DEF_HIGHLIGHT_COLOR
126 if( Xw_get_trace() ) {
127 printf(" %d = Xw_def_highlight_color(%lx,%f,%f,%f)\n",status,(long ) pcolormap,r,g,b) ;