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_BACKGROUND_COLOR
27 XW_STATUS Xw_def_background_color(awindow,r,g,b):
28 XW_EXT_WINDOW *awindow
29 float r,g,b ; Red,Green,Blue color value 0. >= x <= 1.
31 Update Background Color index with the specified R,G,B values .
33 Returns ERROR if Extended Window or Colormap is wrong
34 Returns SUCCESS if Successful
39 XW_STATUS Xw_def_background_color (void* awindow,
40 float r,float g,float b)
42 XW_STATUS Xw_def_background_color (awindow,r,g,b)
45 #endif /*XW_PROTOTYPE*/
47 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
48 XW_EXT_COLORMAP *pcolormap ;
49 unsigned long backpixel,highpixel ;
51 int i,index,cclass,isapproximate ;
52 XW_STATUS status = XW_SUCCESS;
54 if ( !Xw_isdefine_window(pwindow) ) {
55 /*ERROR*Bad EXT_WINDOW Address*/
56 Xw_set_error(24,"Xw_def_background_color",pwindow) ;
60 if ( !Xw_isdefine_colormap(_COLORMAP) ) {
61 /*ERROR*Bad EXT_COLORMAP Address*/
62 Xw_set_error(42,"Xw_def_background_color",_COLORMAP) ;
66 pcolormap = _COLORMAP ;
68 index = pwindow->backindex ;
71 if( pcolormap->define[index] != BACKCOLOR ) {
72 for( i=0 ; i<pcolormap->maxcolor ; i++ ) {
73 if( pcolormap->define[i] == FREECOLOR ) break;
76 if( i < pcolormap->maxcolor ) {
78 pcolormap->define[i] = BACKCOLOR;
82 if( pcolormap->mapping == Xw_TOM_READONLY ) {
91 Xw_get_color_pixel(pcolormap,r,g,b,&backpixel,&isapproximate) ;
95 if( pcolormap->mapping == Xw_TOM_COLORCUBE ) {
96 if( (_CGINFO.red_mult > 0) && (fabs(r-g) < 0.01) && (fabs(r-b) < 0.01) ) {
97 index = (int)(0.5+r*_CGINFO.red_max)*_CGINFO.red_mult;
98 if( _CINFO.red_max > 0 )
99 index += (_CINFO.red_max+1)*(_CINFO.green_max+1)*(_CINFO.blue_max+1);
100 } else if( _CINFO.red_mult > 0 ) {
101 index = ((int)(0.5+r*_CINFO.red_max))*_CINFO.red_mult+
102 ((int)(0.5+g*_CINFO.green_max))*_CINFO.green_mult+
103 ((int)(0.5+b*_CINFO.blue_max))*_CINFO.blue_mult;
104 } else if( _CGINFO.red_mult > 0 ) {
105 float l = (r+g+b)/3.;
106 index = (int)(0.5+l*_CGINFO.red_max)*_CGINFO.red_mult;
110 backpixel = _CINFO.base_pixel = index;
111 } else if( pcolormap->define[index] == BACKCOLOR ) {
112 color.pixel = backpixel = pcolormap->pixels[index] ;
113 color.red = (unsigned short) (r * 0xFFFF) ;
114 color.green = (unsigned short) (g * 0xFFFF) ;
115 color.blue = (unsigned short) (b * 0xFFFF) ;
116 color.flags = DoRed|DoGreen|DoBlue ;
117 XStoreColor(_DISPLAY,_CINFO.colormap,&color) ;
122 status = Xw_alloc_color(pcolormap,r,g,b,&backpixel,&isapproximate) ;
127 pwindow->backindex = index ;
128 pcolormap->pixels[index] = backpixel ;
131 backpixel = pcolormap->backpixel ; /* Transparent window */
135 highpixel = pcolormap->highpixel ^ backpixel ;
136 XSetWindowBackground (_DISPLAY, _WINDOW, backpixel) ;
137 XSetBackground(_DISPLAY, pwindow->qgwind.gc, backpixel) ;
138 XSetBackground(_DISPLAY, pwindow->qgwind.gccopy, backpixel) ;
139 XSetBackground(_DISPLAY, pwindow->qgwind.gcclear, backpixel) ;
140 XSetBackground(_DISPLAY, pwindow->qgwind.gchigh, backpixel) ;
141 XSetForeground(_DISPLAY, pwindow->qgwind.gcclear, backpixel) ;
142 XSetForeground(_DISPLAY, pwindow->qgwind.gchigh, highpixel) ;
143 for( i=0 ; i<MAXQG ; i++ ) {
144 XSetBackground(_DISPLAY, pwindow->qgline[i].gc, backpixel);
145 XSetBackground(_DISPLAY, pwindow->qgpoly[i].gc, backpixel);
146 XSetBackground(_DISPLAY, pwindow->qgtext[i].gc, backpixel);
147 XSetBackground(_DISPLAY, pwindow->qgmark[i].gc, backpixel);
151 #ifdef TRACE_DEF_BACKGROUND_COLOR
152 if( Xw_get_trace() ) {
153 printf(" %d = Xw_def_background_color(%lx,%f,%f,%f)\n",status,(long ) pwindow,r,g,b) ;