store the pixel32 data in the surface so it can be reused
This commit is contained in:
parent
e429ce39de
commit
58847af218
6 changed files with 60 additions and 49 deletions
|
@ -7,10 +7,11 @@ extern "C" {
|
|||
#include <X11/Xutil.h>
|
||||
}
|
||||
|
||||
#include "surface.hh"
|
||||
|
||||
namespace otk {
|
||||
|
||||
class ScreenInfo;
|
||||
class Surface;
|
||||
class RenderTexture;
|
||||
class Font;
|
||||
class RenderColor;
|
||||
|
|
|
@ -54,8 +54,8 @@ RenderStyle::RenderStyle(int screen, const std::string &stylefile)
|
|||
_file(stylefile)
|
||||
{
|
||||
// pick one..
|
||||
//#define FIERON
|
||||
#define MERRY
|
||||
#define FIERON
|
||||
//#define MERRY
|
||||
|
||||
#ifdef FIERON
|
||||
_root_color = new RenderColor(_screen, 0x272a2f);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
extern "C" {
|
||||
#include <X11/Xutil.h>
|
||||
#include <cstring>
|
||||
}
|
||||
|
||||
namespace otk {
|
||||
|
@ -16,6 +17,7 @@ namespace otk {
|
|||
Surface::Surface(int screen, const Size &size)
|
||||
: _screen(screen),
|
||||
_size(size),
|
||||
_pixel_data(new pixel32[size.width()*size.height()]),
|
||||
_pixmap(None),
|
||||
_xftdraw(0)
|
||||
{
|
||||
|
@ -24,6 +26,7 @@ Surface::Surface(int screen, const Size &size)
|
|||
Surface::~Surface()
|
||||
{
|
||||
destroyObjects();
|
||||
delete [] _pixel_data;
|
||||
}
|
||||
|
||||
void Surface::setPixmap(const RenderColor &color)
|
||||
|
@ -33,6 +36,15 @@ void Surface::setPixmap(const RenderColor &color)
|
|||
|
||||
XFillRectangle(**display, _pixmap, color.gc(), 0, 0,
|
||||
_size.width(), _size.height());
|
||||
|
||||
pixel32 val = 0; // XXX set this from the color and shift amounts!
|
||||
for (unsigned int i = 0, s = _size.width() * _size.height(); i < s; ++i) {
|
||||
unsigned char *p = (unsigned char*)&_pixel_data[i];
|
||||
*p = (unsigned char) (val >> 24);
|
||||
*++p = (unsigned char) (val >> 16);
|
||||
*++p = (unsigned char) (val >> 8);
|
||||
*++p = (unsigned char) val;
|
||||
}
|
||||
}
|
||||
|
||||
void Surface::setPixmap(XImage *image)
|
||||
|
|
|
@ -3,23 +3,41 @@
|
|||
#define __surface_hh
|
||||
|
||||
#include "size.hh"
|
||||
#include "truerendercontrol.hh"
|
||||
#include "pseudorendercontrol.hh"
|
||||
|
||||
extern "C" {
|
||||
#include <X11/Xlib.h>
|
||||
#define _XFT_NO_COMPAT_ // no Xft 1 API
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace otk {
|
||||
|
||||
class ScreenInfo;
|
||||
class RenderColor;
|
||||
class RenderControl;
|
||||
class TrueRenderControl;
|
||||
class PseudoRenderControl;
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
typedef uint32_t pixel32;
|
||||
typedef uint16_t pixel16;
|
||||
#else
|
||||
typedef u_int32_t pixel32;
|
||||
typedef u_int16_t pixel16;
|
||||
#endif /* HAVE_STDINT_H */
|
||||
|
||||
class Surface {
|
||||
int _screen;
|
||||
Size _size;
|
||||
pixel32 *_pixel_data;
|
||||
Pixmap _pixmap;
|
||||
XftDraw *_xftdraw;
|
||||
|
||||
|
@ -36,9 +54,11 @@ public:
|
|||
|
||||
inline int screen(void) const { return _screen; }
|
||||
|
||||
virtual const Size& size() const { return _size; }
|
||||
const Size& size() const { return _size; }
|
||||
|
||||
virtual Pixmap pixmap() const { return _pixmap; }
|
||||
Pixmap pixmap() const { return _pixmap; }
|
||||
|
||||
pixel32 *pixelData() { return _pixel_data; }
|
||||
|
||||
// The RenderControl classes use the internal objects in this class to render
|
||||
// to it. Noone else needs them tho, so they are private.
|
||||
|
|
|
@ -64,23 +64,24 @@ void TrueRenderControl::drawGradientBackground(
|
|||
XImage *im = XCreateImage(**display, info->visual(), info->depth(),
|
||||
ZPixmap, 0, NULL, w, h, 32, 0);
|
||||
im->byte_order = endian;
|
||||
pixel32 *data = new pixel32[h*w];
|
||||
pixel32 current;
|
||||
|
||||
switch (texture.gradient()) {
|
||||
case RenderTexture::Vertical:
|
||||
verticalGradient(sf, texture, data);
|
||||
verticalGradient(sf, texture);
|
||||
break;
|
||||
case RenderTexture::Diagonal:
|
||||
diagonalGradient(sf, texture, data);
|
||||
diagonalGradient(sf, texture);
|
||||
break;
|
||||
case RenderTexture::CrossDiagonal:
|
||||
crossDiagonalGradient(sf, texture, data);
|
||||
crossDiagonalGradient(sf, texture);
|
||||
break;
|
||||
default:
|
||||
printf("unhandled gradient\n");
|
||||
}
|
||||
|
||||
pixel32 *data = sf.pixelData();
|
||||
pixel32 current;
|
||||
|
||||
if (texture.relief() == RenderTexture::Flat && texture.border()) {
|
||||
r = texture.borderColor().red();
|
||||
g = texture.borderColor().green();
|
||||
|
@ -122,21 +123,20 @@ void TrueRenderControl::drawGradientBackground(
|
|||
}
|
||||
}
|
||||
|
||||
reduceDepth(im, data);
|
||||
reduceDepth(sf, im);
|
||||
|
||||
im->data = (char*) data;
|
||||
|
||||
sf.setPixmap(im);
|
||||
|
||||
delete [] im->data;
|
||||
im->data = NULL;
|
||||
XDestroyImage(im);
|
||||
}
|
||||
|
||||
void TrueRenderControl::verticalGradient(Surface &sf,
|
||||
const RenderTexture &texture,
|
||||
pixel32 *data) const
|
||||
const RenderTexture &texture) const
|
||||
{
|
||||
pixel32 *data = sf.pixelData();
|
||||
pixel32 current;
|
||||
float dr, dg, db;
|
||||
unsigned int r,g,b;
|
||||
|
@ -164,9 +164,9 @@ void TrueRenderControl::verticalGradient(Surface &sf,
|
|||
}
|
||||
|
||||
void TrueRenderControl::diagonalGradient(Surface &sf,
|
||||
const RenderTexture &texture,
|
||||
pixel32 *data) const
|
||||
const RenderTexture &texture) const
|
||||
{
|
||||
pixel32 *data = sf.pixelData();
|
||||
pixel32 current;
|
||||
float drx, dgx, dbx, dry, dgy, dby;
|
||||
unsigned int r,g,b;
|
||||
|
@ -196,10 +196,10 @@ void TrueRenderControl::diagonalGradient(Surface &sf,
|
|||
}
|
||||
}
|
||||
|
||||
void TrueRenderControl::crossDiagonalGradient(Surface &sf,
|
||||
const RenderTexture &texture,
|
||||
pixel32 *data) const
|
||||
void TrueRenderControl::crossDiagonalGradient(
|
||||
Surface &sf, const RenderTexture &texture) const
|
||||
{
|
||||
pixel32 *data = sf.pixelData();
|
||||
pixel32 current;
|
||||
float drx, dgx, dbx, dry, dgy, dby;
|
||||
unsigned int r,g,b;
|
||||
|
@ -229,11 +229,12 @@ void TrueRenderControl::crossDiagonalGradient(Surface &sf,
|
|||
}
|
||||
}
|
||||
|
||||
void TrueRenderControl::reduceDepth(XImage *im, pixel32 *data) const
|
||||
void TrueRenderControl::reduceDepth(Surface &sf, XImage *im) const
|
||||
{
|
||||
// since pixel32 is the largest possible pixel size, we can share the array
|
||||
int r, g, b;
|
||||
int x,y;
|
||||
pixel32 *data = sf.pixelData();
|
||||
pixel16 *p = (pixel16*) data;
|
||||
switch (im->bits_per_pixel) {
|
||||
case 32:
|
||||
|
|
|
@ -4,30 +4,10 @@
|
|||
|
||||
#include "rendercontrol.hh"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace otk {
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
typedef uint32_t pixel32;
|
||||
typedef uint16_t pixel16;
|
||||
#else
|
||||
typedef u_int32_t pixel32;
|
||||
typedef u_int16_t pixel16;
|
||||
#endif /* HAVE_STDINT_H */
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
const int default_red_shift=0;
|
||||
const int default_green_shift=8;
|
||||
|
@ -54,13 +34,10 @@ private:
|
|||
int _blue_offset;
|
||||
|
||||
inline void highlight(pixel32 *x, pixel32 *y, bool raised) const;
|
||||
void reduceDepth(XImage *im, pixel32 *data) const;
|
||||
void verticalGradient(Surface &sf, const RenderTexture &texture,
|
||||
pixel32 *data) const;
|
||||
void diagonalGradient(Surface &sf, const RenderTexture &texture,
|
||||
pixel32 *data) const;
|
||||
void crossDiagonalGradient(Surface &sf, const RenderTexture &texture,
|
||||
pixel32 *data) const;
|
||||
void reduceDepth(Surface &sf, XImage *im) const;
|
||||
void verticalGradient(Surface &sf, const RenderTexture &texture) const;
|
||||
void diagonalGradient(Surface &sf, const RenderTexture &texture) const;
|
||||
void crossDiagonalGradient(Surface &sf, const RenderTexture &texture) const;
|
||||
virtual void drawGradientBackground(Surface &sf,
|
||||
const RenderTexture &texture) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue