1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Color functions for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-10-08 01:07:12 +04:00
|
|
|
/**
|
|
|
|
\file fl_color.cxx
|
|
|
|
\brief Color handling
|
|
|
|
*/
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
// Implementation of fl_color(i), fl_color(r,g,b).
|
|
|
|
|
|
|
|
#ifdef WIN32
|
2001-11-27 20:44:08 +03:00
|
|
|
# include "fl_color_win32.cxx"
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
# include "fl_color_mac.cxx"
|
1998-10-06 22:21:25 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
// Also code to look at the X visual and figure out the best way to turn
|
|
|
|
// a color into a pixel value.
|
|
|
|
|
|
|
|
// SGI compiler seems to have problems with unsigned char arguments
|
|
|
|
// being used to index arrays. So I always copy them to an integer
|
|
|
|
// before use.
|
|
|
|
|
2001-11-27 20:44:08 +03:00
|
|
|
# include "Fl_XColor.H"
|
|
|
|
# include <FL/Fl.H>
|
|
|
|
# include <FL/x.H>
|
|
|
|
# include <FL/fl_draw.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
// figure_out_visual() calculates masks & shifts for generating
|
|
|
|
// pixels in true-color visuals:
|
|
|
|
|
2008-10-28 01:58:49 +03:00
|
|
|
uchar fl_redmask; /**< color mask used in current color map handling */
|
|
|
|
uchar fl_greenmask; /**< color mask used in current color map handling */
|
|
|
|
uchar fl_bluemask; /**< color mask used in current color map handling */
|
|
|
|
|
|
|
|
int fl_redshift; /**< color shift used in current color map handling */
|
|
|
|
int fl_greenshift; /**< color shift used in current color map handling */
|
|
|
|
int fl_blueshift; /**< color shift used in current color map handling */
|
|
|
|
int fl_extrashift; /**< color shift used in current color map handling */
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
static uchar beenhere;
|
|
|
|
|
|
|
|
static void figure_out_visual() {
|
|
|
|
beenhere = 1;
|
|
|
|
if (!fl_visual->red_mask || !fl_visual->green_mask || !fl_visual->blue_mask){
|
2001-11-27 20:44:08 +03:00
|
|
|
# if USE_COLORMAP
|
1998-10-06 22:21:25 +04:00
|
|
|
fl_redmask = 0;
|
|
|
|
return;
|
2001-11-27 20:44:08 +03:00
|
|
|
# else
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl::fatal("Requires true color visual");
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the bit masks into a more useful form:
|
|
|
|
int i,j,m;
|
|
|
|
|
|
|
|
for (i = 0, m = 1; m; i++, m<<=1) if (fl_visual->red_mask & m) break;
|
|
|
|
for (j = i; m; j++, m<<=1) if (!(fl_visual->red_mask & m)) break;
|
|
|
|
fl_redshift = j-8;
|
|
|
|
fl_redmask = (j-i >= 8) ? 0xFF : 0xFF-(255>>(j-i));
|
|
|
|
|
|
|
|
for (i = 0, m = 1; m; i++, m<<=1) if (fl_visual->green_mask & m) break;
|
|
|
|
for (j = i; m; j++, m<<=1) if (!(fl_visual->green_mask & m)) break;
|
|
|
|
fl_greenshift = j-8;
|
|
|
|
fl_greenmask = (j-i >= 8) ? 0xFF : 0xFF-(255>>(j-i));
|
|
|
|
|
|
|
|
for (i = 0, m = 1; m; i++, m<<=1) if (fl_visual->blue_mask & m) break;
|
|
|
|
for (j = i; m; j++, m<<=1) if (!(fl_visual->blue_mask & m)) break;
|
|
|
|
fl_blueshift = j-8;
|
|
|
|
fl_bluemask = (j-i >= 8) ? 0xFF : 0xFF-(255>>(j-i));
|
|
|
|
|
|
|
|
i = fl_redshift;
|
|
|
|
if (fl_greenshift < i) i = fl_greenshift;
|
|
|
|
if (fl_blueshift < i) i = fl_blueshift;
|
|
|
|
if (i < 0) {
|
|
|
|
fl_extrashift = -i;
|
|
|
|
fl_redshift -= i; fl_greenshift -= i; fl_blueshift -= i;
|
|
|
|
} else
|
|
|
|
fl_extrashift = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
static unsigned fl_cmap[256] = {
|
2001-11-22 18:35:02 +03:00
|
|
|
#include "fl_cmap.h" // this is a file produced by "cmap.cxx":
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
};
|
|
|
|
|
2001-11-27 20:44:08 +03:00
|
|
|
# if HAVE_OVERLAY
|
2008-10-28 01:58:49 +03:00
|
|
|
/** HAVE_OVERLAY determines whether fl_xmap is one or two planes */
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
Fl_XColor fl_xmap[2][256];
|
2008-10-28 01:58:49 +03:00
|
|
|
/** HAVE_OVERLAY determines whether fl_overlay is variable or defined as 0 */
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
uchar fl_overlay;
|
|
|
|
Colormap fl_overlay_colormap;
|
|
|
|
XVisualInfo* fl_overlay_visual;
|
|
|
|
ulong fl_transparent_pixel;
|
2001-11-27 20:44:08 +03:00
|
|
|
# else
|
2008-10-28 01:58:49 +03:00
|
|
|
/** HAVE_OVERLAY determines whether fl_xmap is one or two planes */
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
Fl_XColor fl_xmap[1][256];
|
2008-10-28 01:58:49 +03:00
|
|
|
/** HAVE_OVERLAY determines whether fl_overlay is variable or defined as 0 */
|
2001-11-27 20:44:08 +03:00
|
|
|
# define fl_overlay 0
|
|
|
|
# endif
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
|
2010-03-21 11:26:40 +03:00
|
|
|
/** Current color for drawing operations */
|
|
|
|
Fl_Color fl_color_;
|
|
|
|
|
2010-05-27 21:20:18 +04:00
|
|
|
void Fl_Graphics_Driver::color(Fl_Color i) {
|
2010-03-21 11:26:40 +03:00
|
|
|
if (i & 0xffffff00) {
|
|
|
|
unsigned rgb = (unsigned)i;
|
|
|
|
fl_color((uchar)(rgb >> 24), (uchar)(rgb >> 16), (uchar)(rgb >> 8));
|
|
|
|
} else {
|
|
|
|
fl_color_ = i;
|
|
|
|
if(!fl_gc) return; // don't get a default gc if current window is not yet created/valid
|
|
|
|
XSetForeground(fl_display, fl_gc, fl_xpixel(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-27 21:20:18 +04:00
|
|
|
void Fl_Graphics_Driver::color(uchar r,uchar g,uchar b) {
|
2010-03-21 11:26:40 +03:00
|
|
|
fl_color_ = fl_rgb_color(r, g, b);
|
|
|
|
if(!fl_gc) return; // don't get a default gc if current window is not yet created/valid
|
|
|
|
XSetForeground(fl_display, fl_gc, fl_xpixel(r,g,b));
|
|
|
|
}
|
|
|
|
|
2009-01-20 14:10:29 +03:00
|
|
|
/** \addtogroup fl_attributes
|
|
|
|
@{ */
|
1998-10-06 22:21:25 +04:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
// Get an rgb color. This is easy for a truecolor visual. For
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
// colormapped it picks the closest color out of the cube in the
|
|
|
|
// fltk colormap. However if this color cube entry has been
|
|
|
|
// requested before, you will get the earlier requested color, and
|
|
|
|
// even this may be approximated if the X colormap was full.
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-10-28 01:58:49 +03:00
|
|
|
/**
|
|
|
|
Returns the X pixel number used to draw the given rgb color.
|
|
|
|
This is the X pixel that fl_color() would use.
|
|
|
|
\param[in] r,g,b color components
|
|
|
|
\return X pixel number
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
ulong fl_xpixel(uchar r,uchar g,uchar b) {
|
|
|
|
if (!beenhere) figure_out_visual();
|
2001-11-27 20:44:08 +03:00
|
|
|
# if USE_COLORMAP
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!fl_redmask) {
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
// find closest entry in the colormap:
|
|
|
|
Fl_Color i =
|
|
|
|
fl_color_cube(r*FL_NUM_RED/256,g*FL_NUM_GREEN/256,b*FL_NUM_BLUE/256);
|
|
|
|
Fl_XColor &xmap = fl_xmap[fl_overlay][i];
|
|
|
|
if (xmap.mapped) return xmap.pixel;
|
|
|
|
// if not black or white, change the entry to be an exact match:
|
|
|
|
if (i != FL_COLOR_CUBE && i != 0xFF)
|
|
|
|
fl_cmap[i] = (r<<24)|(g<<16)|(b<<8);
|
|
|
|
return fl_xpixel(i); // allocate an X color
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
return
|
|
|
|
(((r&fl_redmask) << fl_redshift)+
|
|
|
|
((g&fl_greenmask)<<fl_greenshift)+
|
|
|
|
((b&fl_bluemask)<< fl_blueshift)
|
|
|
|
) >> fl_extrashift;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
2009-07-01 11:32:14 +04:00
|
|
|
// Get a color out of the fltk colormap. Again for truecolor
|
1998-10-06 22:21:25 +04:00
|
|
|
// visuals this is easy. For colormap this actually tries to allocate
|
|
|
|
// an X color, and does a least-squares match to find the closest
|
|
|
|
// color if X cannot allocate that color.
|
|
|
|
|
|
|
|
// calculate what color is actually on the screen for a mask:
|
|
|
|
static inline uchar realcolor(uchar color, uchar mask) {
|
2001-11-27 20:44:08 +03:00
|
|
|
# if 0
|
1998-10-06 22:21:25 +04:00
|
|
|
// accurate version if the display has linear gamma, but fl_draw_image
|
|
|
|
// works better with the simpler version on most screens...
|
|
|
|
uchar m = mask;
|
|
|
|
uchar result = color&m;
|
|
|
|
for (;;) {
|
|
|
|
while (m&mask) {m>>=1; color>>=1;}
|
|
|
|
if (!m) break;
|
|
|
|
mask = m;
|
|
|
|
result |= color&m;
|
|
|
|
}
|
|
|
|
return result;
|
2001-11-27 20:44:08 +03:00
|
|
|
# else
|
2010-10-28 22:02:20 +04:00
|
|
|
return (color&mask) | ( (~mask)&(mask>>1) );
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2008-10-28 01:58:49 +03:00
|
|
|
/**
|
|
|
|
Returns the X pixel number used to draw the given FLTK color index.
|
|
|
|
This is the X pixel that fl_color() would use.
|
|
|
|
\param[in] i color index
|
|
|
|
\return X pixel number
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
ulong fl_xpixel(Fl_Color i) {
|
2002-05-16 06:16:17 +04:00
|
|
|
if (i & 0xffffff00) {
|
|
|
|
return fl_xpixel((i >> 24) & 255, (i >> 16) & 255, (i >> 8) & 255);
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_XColor &xmap = fl_xmap[fl_overlay][i];
|
|
|
|
if (xmap.mapped) return xmap.pixel;
|
|
|
|
|
|
|
|
if (!beenhere) figure_out_visual();
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
uchar r,g,b;
|
|
|
|
{unsigned c = fl_cmap[i]; r=uchar(c>>24); g=uchar(c>>16); b=uchar(c>>8);}
|
|
|
|
|
2001-11-27 20:44:08 +03:00
|
|
|
# if USE_COLORMAP
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
Colormap colormap = fl_colormap;
|
2001-11-27 20:44:08 +03:00
|
|
|
# if HAVE_OVERLAY
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
if (fl_overlay) colormap = fl_overlay_colormap; else
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
if (fl_redmask) {
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
// return color for a truecolor visual:
|
|
|
|
xmap.mapped = 2; // 2 prevents XFreeColor from being called
|
|
|
|
xmap.r = realcolor(r, fl_redmask);
|
|
|
|
xmap.g = realcolor(g, fl_greenmask);
|
|
|
|
xmap.b = realcolor(b, fl_bluemask);
|
|
|
|
return xmap.pixel =
|
|
|
|
(((r&fl_redmask) << fl_redshift)+
|
|
|
|
((g&fl_greenmask)<<fl_greenshift)+
|
|
|
|
((b&fl_bluemask)<< fl_blueshift)
|
|
|
|
) >> fl_extrashift;
|
2001-11-27 20:44:08 +03:00
|
|
|
# if USE_COLORMAP
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
}
|
2001-11-27 20:44:08 +03:00
|
|
|
# if HAVE_OVERLAY
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
static XColor* ac[2];
|
|
|
|
XColor*& allcolors = ac[fl_overlay];
|
|
|
|
static int nc[2];
|
|
|
|
int& numcolors = nc[fl_overlay];
|
2001-11-27 20:44:08 +03:00
|
|
|
# else
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
static XColor *allcolors;
|
|
|
|
static int numcolors;
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
// I don't try to allocate colors with XAllocColor once it fails
|
|
|
|
// with any color. It is possible that it will work, since a color
|
|
|
|
// may have been freed, but some servers are extremely slow and this
|
|
|
|
// avoids one round trip:
|
|
|
|
if (!numcolors) { // don't try after a failure
|
|
|
|
XColor xcol;
|
|
|
|
xcol.red = r<<8; xcol.green = g<<8; xcol.blue = b<<8;
|
|
|
|
if (XAllocColor(fl_display, colormap, &xcol)) {
|
|
|
|
xmap.mapped = 1;
|
|
|
|
xmap.r = xcol.red>>8;
|
|
|
|
xmap.g = xcol.green>>8;
|
|
|
|
xmap.b = xcol.blue>>8;
|
|
|
|
return xmap.pixel = xcol.pixel;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
// I only read the colormap once. Again this is due to the slowness
|
|
|
|
// of round-trips to the X server, even though other programs may alter
|
|
|
|
// the colormap after this and make decisions here wrong.
|
2001-11-27 20:44:08 +03:00
|
|
|
# if HAVE_OVERLAY
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
if (fl_overlay) numcolors = fl_overlay_visual->colormap_size; else
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
numcolors = fl_visual->colormap_size;
|
|
|
|
if (!allcolors) allcolors = new XColor[numcolors];
|
|
|
|
for (int p = numcolors; p--;) allcolors[p].pixel = p;
|
|
|
|
XQueryColors(fl_display, colormap, allcolors, numcolors);
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
// find least-squares match:
|
|
|
|
int mindist = 0x7FFFFFFF;
|
|
|
|
unsigned int bestmatch = 0;
|
|
|
|
for (unsigned int n = numcolors; n--;) {
|
2001-11-27 20:44:08 +03:00
|
|
|
# if HAVE_OVERLAY
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
if (fl_overlay && n == fl_transparent_pixel) continue;
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
XColor &a = allcolors[n];
|
|
|
|
int d, t;
|
|
|
|
t = int(r)-int(a.red>>8); d = t*t;
|
|
|
|
t = int(g)-int(a.green>>8); d += t*t;
|
|
|
|
t = int(b)-int(a.blue>>8); d += t*t;
|
|
|
|
if (d <= mindist) {bestmatch = n; mindist = d;}
|
|
|
|
}
|
|
|
|
XColor &p = allcolors[bestmatch];
|
|
|
|
|
|
|
|
// It appears to "work" to not call this XAllocColor, which will
|
|
|
|
// avoid another round-trip to the server. But then X does not
|
|
|
|
// know that this program "owns" this value, and can (and will)
|
|
|
|
// change it when the program that did allocate it exits:
|
|
|
|
if (XAllocColor(fl_display, colormap, &p)) {
|
|
|
|
xmap.mapped = 1;
|
|
|
|
xmap.pixel = p.pixel;
|
|
|
|
} else {
|
|
|
|
// However, if that XAllocColor fails, I have to give up and
|
2009-03-22 22:21:34 +03:00
|
|
|
// assume the pixel is ok for the duration of the program. This
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
// is due to bugs (?) in the Solaris X and some X terminals
|
|
|
|
// where XAllocColor *always* fails when the colormap is full,
|
|
|
|
// even if we ask for a color already in it...
|
|
|
|
xmap.mapped = 2; // 2 prevents XFreeColor from being called
|
|
|
|
xmap.pixel = bestmatch;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771)
Removed 8-bit colormap drawing code that was not doing anything in
fl_draw_image due to Mike's changes. I also made fl_color(r,g,b)
actually allocate the requested color rather than the nearest fltk
color-cube color (this is only done for the first color that maps to a
given entry in the fltk color cube), the result is that pixmaps with a
small number of colors are drawn much more accurately. The resulting
code seems to produce better images and is a good deal smaller!
Fixed makeinclude.in so CFLAGS are used for c source code instead of
CXXFLAGS. (bug 108694)
Better fix for gif files suggested by pauly (bug 108770)
Performance of Fl_Gl_Window may be improved on some types of OpenGL
implementations, in particular MESA or other software emulators, by
setting the GL_SWAP_TYPE environment variable. This variable
declares what is in the back buffer after you do a swapbuffers.
setenv GL_SWAP_TYPE COPY
This indicates that the back buffer is copied to the front buffer,
and still contains it's old data. This is true of many hardware
implementations. Setting this will speed up emulation of
overlays, and widgets that can do partial update can take
advantage of this as damage() will not be cleared to -1.
setenv GL_SWAP_TYPE NODAMAGE
This indicates that nothing changes the back buffer except drawing
into it. This is true of MESA and Win32 software emulation and
perhaps some hardware emulation on systems with lots of memory.
All other values for GL_SWAP_TYPE, and not setting the variable,
cause fltk to assumme that the back buffer must be completely
redrawn after a swap.
This is easily tested by running the gl_overlay demo program and
seeing if the display is correct when you drag another window over
it or if you drag the window off the screen and back on. You have to
exit and run the program again for it to see any changes to the
environment variable.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2000-07-07 12:38:58 +04:00
|
|
|
xmap.r = p.red>>8;
|
|
|
|
xmap.g = p.green>>8;
|
|
|
|
xmap.b = p.blue>>8;
|
|
|
|
return xmap.pixel;
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2008-10-16 01:38:38 +04:00
|
|
|
/**
|
2009-03-24 04:40:44 +03:00
|
|
|
Free color \p i if used, and clear mapping table entry.
|
2008-10-16 01:38:38 +04:00
|
|
|
\param[in] i color index
|
|
|
|
\param[in] overlay 0 for normal, 1 for overlay color
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void Fl::free_color(Fl_Color i, int overlay) {
|
2001-11-27 20:44:08 +03:00
|
|
|
# if HAVE_OVERLAY
|
|
|
|
# else
|
1998-10-06 22:21:25 +04:00
|
|
|
if (overlay) return;
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
if (fl_xmap[overlay][i].mapped) {
|
2001-11-27 20:44:08 +03:00
|
|
|
# if USE_COLORMAP
|
|
|
|
# if HAVE_OVERLAY
|
1998-10-06 22:21:25 +04:00
|
|
|
Colormap colormap = overlay ? fl_overlay_colormap : fl_colormap;
|
2001-11-27 20:44:08 +03:00
|
|
|
# else
|
1998-10-06 22:21:25 +04:00
|
|
|
Colormap colormap = fl_colormap;
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
if (fl_xmap[overlay][i].mapped == 1)
|
|
|
|
XFreeColors(fl_display, colormap, &(fl_xmap[overlay][i].pixel), 1, 0);
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
fl_xmap[overlay][i].mapped = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-16 01:38:38 +04:00
|
|
|
/**
|
2009-03-24 04:40:44 +03:00
|
|
|
Set color mapping table entry \p i to color \p c
|
2008-10-16 01:38:38 +04:00
|
|
|
\param[in] i color index
|
|
|
|
\param[in] c color
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void Fl::set_color(Fl_Color i, unsigned c) {
|
|
|
|
if (fl_cmap[i] != c) {
|
|
|
|
free_color(i,0);
|
2001-11-27 20:44:08 +03:00
|
|
|
# if HAVE_OVERLAY
|
1998-10-06 22:21:25 +04:00
|
|
|
free_color(i,1);
|
2001-11-27 20:44:08 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
fl_cmap[i] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-13 18:56:23 +03:00
|
|
|
#endif // end of X-specific code
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
2010-10-30 02:14:59 +04:00
|
|
|
Returns the RGB value(s) for the given FLTK color index.
|
|
|
|
|
|
|
|
This form returns the RGB values packed in a 32-bit unsigned
|
2008-09-14 02:33:03 +04:00
|
|
|
integer with the red value in the upper 8 bits, the green value
|
|
|
|
in the next 8 bits, and the blue value in bits 8-15. The lower
|
|
|
|
8 bits will always be 0.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
unsigned Fl::get_color(Fl_Color i) {
|
2001-10-29 06:44:33 +03:00
|
|
|
if (i & 0xffffff00) return (i);
|
|
|
|
else return fl_cmap[i];
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
|
|
|
Sets an entry in the fl_color index table. You can set it to
|
|
|
|
any 8-bit RGB color. The color is not allocated until fl_color(i)
|
|
|
|
is used.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void Fl::set_color(Fl_Color i, uchar red, uchar green, uchar blue) {
|
2001-10-29 06:44:33 +03:00
|
|
|
Fl::set_color((Fl_Color)(i & 255),
|
1998-10-06 22:21:25 +04:00
|
|
|
((unsigned)red<<24)+((unsigned)green<<16)+((unsigned)blue<<8));
|
|
|
|
}
|
2010-10-28 02:07:55 +04:00
|
|
|
/**
|
|
|
|
Returns the RGB value(s) for the given FLTK color index.
|
|
|
|
|
|
|
|
This form returns the red, green, and blue values
|
|
|
|
separately in referenced variables.
|
|
|
|
|
|
|
|
See also unsigned get_color(Fl_Color c)
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void Fl::get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue) {
|
2001-10-29 06:44:33 +03:00
|
|
|
unsigned c;
|
|
|
|
|
|
|
|
if (i & 0xffffff00) c = (unsigned)i;
|
|
|
|
else c = fl_cmap[i];
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
red = uchar(c>>24);
|
|
|
|
green = uchar(c>>16);
|
|
|
|
blue = uchar(c>>8);
|
|
|
|
}
|
|
|
|
|
2008-10-28 01:58:49 +03:00
|
|
|
/**
|
|
|
|
Returns the weighted average color between the two given colors.
|
2008-12-07 17:48:11 +03:00
|
|
|
The red, green and blue values are averages using the following formula:
|
2008-10-28 01:58:49 +03:00
|
|
|
\code
|
|
|
|
color = color1 * weight + color2 * (1 - weight)
|
|
|
|
\endcode
|
2009-03-24 04:40:44 +03:00
|
|
|
Thus, a \p weight value of 1.0 will return the first color, while a
|
2008-10-28 01:58:49 +03:00
|
|
|
value of 0.0 will return the second color.
|
|
|
|
\param[in] color1, color2 boundary colors
|
|
|
|
\param[in] weight weighting factor
|
|
|
|
*/
|
1999-01-25 23:43:05 +03:00
|
|
|
Fl_Color fl_color_average(Fl_Color color1, Fl_Color color2, float weight) {
|
2001-10-29 06:44:33 +03:00
|
|
|
unsigned rgb1;
|
|
|
|
unsigned rgb2;
|
1999-01-25 23:43:05 +03:00
|
|
|
uchar r, g, b;
|
|
|
|
|
2001-10-29 06:44:33 +03:00
|
|
|
if (color1 & 0xffffff00) rgb1 = color1;
|
|
|
|
else rgb1 = fl_cmap[color1 & 255];
|
|
|
|
|
|
|
|
if (color2 & 0xffffff00) rgb2 = color2;
|
|
|
|
else rgb2 = fl_cmap[color2 & 255];
|
|
|
|
|
1999-01-25 23:43:05 +03:00
|
|
|
r = (uchar)(((uchar)(rgb1>>24))*weight + ((uchar)(rgb2>>24))*(1-weight));
|
|
|
|
g = (uchar)(((uchar)(rgb1>>16))*weight + ((uchar)(rgb2>>16))*(1-weight));
|
|
|
|
b = (uchar)(((uchar)(rgb1>>8))*weight + ((uchar)(rgb2>>8))*(1-weight));
|
|
|
|
|
2001-10-29 06:44:33 +03:00
|
|
|
return fl_rgb_color(r, g, b);
|
1999-01-25 23:43:05 +03:00
|
|
|
}
|
|
|
|
|
2008-10-28 01:58:49 +03:00
|
|
|
/**
|
|
|
|
Returns the inactive, dimmed version of the given color
|
|
|
|
*/
|
2001-08-04 16:21:34 +04:00
|
|
|
Fl_Color fl_inactive(Fl_Color c) {
|
1999-01-25 23:43:05 +03:00
|
|
|
return fl_color_average(c, FL_GRAY, .33f);
|
1999-01-13 18:56:23 +03:00
|
|
|
}
|
|
|
|
|
2008-10-28 01:58:49 +03:00
|
|
|
/**
|
|
|
|
Returns a color that contrasts with the background color.
|
|
|
|
This will be the foreground color if it contrasts sufficiently with the
|
2009-03-24 04:40:44 +03:00
|
|
|
background color. Otherwise, returns \p FL_WHITE or \p FL_BLACK depending
|
2008-10-28 01:58:49 +03:00
|
|
|
on which color provides the best contrast.
|
|
|
|
\param[in] fg,bg foreground and background colors
|
|
|
|
\return contrasting color
|
|
|
|
*/
|
2001-08-04 16:21:34 +04:00
|
|
|
Fl_Color fl_contrast(Fl_Color fg, Fl_Color bg) {
|
2005-05-12 21:08:35 +04:00
|
|
|
unsigned c1, c2; // RGB colors
|
|
|
|
int l1, l2; // Luminosities
|
2001-10-29 06:44:33 +03:00
|
|
|
|
2005-05-12 21:08:35 +04:00
|
|
|
|
|
|
|
// Get the RGB values for each color...
|
2001-10-29 06:44:33 +03:00
|
|
|
if (fg & 0xffffff00) c1 = (unsigned)fg;
|
|
|
|
else c1 = fl_cmap[fg];
|
|
|
|
|
|
|
|
if (bg & 0xffffff00) c2 = (unsigned)bg;
|
|
|
|
else c2 = fl_cmap[bg];
|
|
|
|
|
2005-05-12 21:08:35 +04:00
|
|
|
// Compute the luminosity...
|
2007-03-20 12:52:51 +03:00
|
|
|
l1 = ((c1 >> 24) * 30 + ((c1 >> 16) & 255) * 59 + ((c1 >> 8) & 255) * 11) / 100;
|
|
|
|
l2 = ((c2 >> 24) * 30 + ((c2 >> 16) & 255) * 59 + ((c2 >> 8) & 255) * 11) / 100;
|
2005-05-12 21:08:35 +04:00
|
|
|
|
|
|
|
// Compare and return the contrasting color...
|
2007-05-16 15:46:07 +04:00
|
|
|
if ((l1 - l2) > 99) return fg;
|
|
|
|
else if ((l2 - l1) > 99) return fg;
|
2005-05-12 21:08:35 +04:00
|
|
|
else if (l2 > 127) return FL_BLACK;
|
|
|
|
else return FL_WHITE;
|
1999-01-13 18:56:23 +03:00
|
|
|
}
|
2009-01-20 14:10:29 +03:00
|
|
|
/**
|
|
|
|
@}
|
|
|
|
*/
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|