drawSolidBackground seems to work :)
This commit is contained in:
parent
68a6fce53b
commit
25f0151154
6 changed files with 155 additions and 43 deletions
|
@ -102,4 +102,89 @@ void RenderControl::drawString(Surface& sf, const Font &font, int x, int y,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderControl::drawSolidBackground(Surface& sf,
|
||||||
|
const RenderTexture& texture) const
|
||||||
|
{
|
||||||
|
assert(_screen == sf._screen);
|
||||||
|
assert(_screen == texture.color().screen());
|
||||||
|
|
||||||
|
if (texture.parentRelative()) return;
|
||||||
|
|
||||||
|
sf.setPixmap(texture.color());
|
||||||
|
|
||||||
|
int width = sf.width(), height = sf.height();
|
||||||
|
int left = 0, top = 0, right = width - 1, bottom = height - 1;
|
||||||
|
|
||||||
|
if (texture.interlaced())
|
||||||
|
for (int i = 0; i < height; i += 2)
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.interlaceColor().gc(),
|
||||||
|
0, i, width, i);
|
||||||
|
|
||||||
|
switch (texture.relief()) {
|
||||||
|
case RenderTexture::Raised:
|
||||||
|
switch (texture.bevel()) {
|
||||||
|
case RenderTexture::Bevel1:
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||||
|
left, bottom, right, bottom);
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||||
|
right, bottom, right, top);
|
||||||
|
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||||
|
left, top, right, top);
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||||
|
left, bottom, left, top);
|
||||||
|
break;
|
||||||
|
case RenderTexture::Bevel2:
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||||
|
left + 1, bottom - 2, right - 2, bottom - 2);
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||||
|
right - 2, bottom - 2, right - 2, top + 1);
|
||||||
|
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||||
|
left + 1, top + 1, right - 2, top + 1);
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||||
|
left + 1, bottom - 2, left + 1, top + 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false); // unhandled RenderTexture::BevelType
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RenderTexture::Sunken:
|
||||||
|
switch (texture.bevel()) {
|
||||||
|
case RenderTexture::Bevel1:
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||||
|
left, bottom, right, bottom);
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||||
|
right, bottom, right, top);
|
||||||
|
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||||
|
left, top, right, top);
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||||
|
left, bottom, left, top);
|
||||||
|
break;
|
||||||
|
case RenderTexture::Bevel2:
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||||
|
left + 1, bottom - 2, right - 2, bottom - 2);
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||||
|
right - 2, bottom - 2, right - 2, top + 1);
|
||||||
|
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||||
|
left + 1, top + 1, right - 2, top + 1);
|
||||||
|
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||||
|
left + 1, bottom - 2, left + 1, top + 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false); // unhandled RenderTexture::BevelType
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RenderTexture::Flat:
|
||||||
|
if (texture.border())
|
||||||
|
XDrawRectangle(**display, sf.pixmap(), texture.borderColor().gc(),
|
||||||
|
left, top, right, bottom);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false); // unhandled RenderTexture::ReliefType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,18 +63,21 @@ protected:
|
||||||
|
|
||||||
RenderControl(int screen);
|
RenderControl(int screen);
|
||||||
|
|
||||||
|
virtual void drawSolidBackground(Surface& sf,
|
||||||
|
const RenderTexture& texture) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~RenderControl();
|
virtual ~RenderControl();
|
||||||
|
|
||||||
static RenderControl *getRenderControl(int screen);
|
static RenderControl *getRenderControl(int screen);
|
||||||
|
|
||||||
//! Draws a string onto a Surface
|
//! Draws a string onto a Surface
|
||||||
virtual void drawString(Surface& sf, const Font &font, int x, int y,
|
virtual void drawString(Surface& sf, const Font& font, int x, int y,
|
||||||
const Color &color, const ustring &string) const;
|
const Color& color, const ustring& string) const;
|
||||||
|
|
||||||
//! Draws a background onto a Surface, as specified by a RenderTexture
|
//! Draws a background onto a Surface, as specified by a RenderTexture
|
||||||
virtual void drawBackground(Surface &sf,
|
virtual void drawBackground(Surface& sf,
|
||||||
const RenderTexture &texture) const = 0;
|
const RenderTexture& texture) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,17 @@ int main(int argc, char **argv)
|
||||||
foo.resize(600, 500);
|
foo.resize(600, 500);
|
||||||
|
|
||||||
otk::RenderColor color(0, 0, 0xff, 0xff);
|
otk::RenderColor color(0, 0, 0xff, 0xff);
|
||||||
|
otk::RenderColor colord(0, 0, 0, 0);
|
||||||
|
otk::RenderColor colorl(0, 0xff, 0xff, 0xff);
|
||||||
otk::RenderTexture tex(false,
|
otk::RenderTexture tex(false,
|
||||||
otk::RenderTexture::Flat,
|
otk::RenderTexture::Raised,
|
||||||
|
otk::RenderTexture::Bevel1,
|
||||||
false,
|
false,
|
||||||
otk::RenderTexture::Solid,
|
otk::RenderTexture::Solid,
|
||||||
false,
|
false,
|
||||||
&color,
|
&color,
|
||||||
0,
|
&colord,
|
||||||
|
&colorl,
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
foo.setTexture(&tex);
|
foo.setTexture(&tex);
|
||||||
|
|
|
@ -35,6 +35,8 @@ private:
|
||||||
bool _parent_relative;
|
bool _parent_relative;
|
||||||
//! The relief type of the texture
|
//! The relief type of the texture
|
||||||
ReliefType _relief;
|
ReliefType _relief;
|
||||||
|
//! The way the bevel should be drawn
|
||||||
|
BevelType _bevel;
|
||||||
//! If a flat border is drawn on the outside, ignored for all ReliefType
|
//! If a flat border is drawn on the outside, ignored for all ReliefType
|
||||||
//! values except ReliefType::Flat
|
//! values except ReliefType::Flat
|
||||||
bool _border;
|
bool _border;
|
||||||
|
@ -47,33 +49,40 @@ private:
|
||||||
//! This must always be defined
|
//! This must always be defined
|
||||||
const RenderColor *_color;
|
const RenderColor *_color;
|
||||||
//! The shadow color for the bevel. This must be defined if
|
//! The shadow color for the bevel. This must be defined if
|
||||||
//! RenderTexture::relief is not RenderTexture::ReliefType::Flat
|
//! RenderTexture::_relief is not RenderTexture::ReliefType::Flat
|
||||||
const RenderColor *_bevel_dark_color;
|
const RenderColor *_bevel_dark_color;
|
||||||
//! The light color for the bevel. This must be defined if
|
//! The light color for the bevel. This must be defined if
|
||||||
//! RenderTexture::relief is not RenderTexture::ReliefType::Flat
|
//! RenderTexture::_relief is not RenderTexture::ReliefType::Flat
|
||||||
const RenderColor *_bevel_light_color;
|
const RenderColor *_bevel_light_color;
|
||||||
//! The color for the flat border if RenderTexture::border is true. This must
|
//! The color for the flat border if RenderTexture::_border is true. This
|
||||||
//! be defined if it is true
|
//! must be defined if it is true
|
||||||
const RenderColor *_border_color;
|
const RenderColor *_border_color;
|
||||||
|
//! The color for the interlace lines if RenderTexture. This must be defined
|
||||||
|
//! if it is true
|
||||||
|
const RenderColor *_interlace_color;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RenderTexture(bool parent_relative, ReliefType relief, bool border,
|
RenderTexture(bool parent_relative, ReliefType relief, BevelType bevel,
|
||||||
GradientType gradient, bool interlaced,
|
bool border, GradientType gradient, bool interlaced,
|
||||||
const RenderColor *color, const RenderColor *bevel_dark_color,
|
const RenderColor *color, const RenderColor *bevel_dark_color,
|
||||||
const RenderColor *bevel_light_color,
|
const RenderColor *bevel_light_color,
|
||||||
const RenderColor *border_color)
|
const RenderColor *border_color,
|
||||||
|
const RenderColor *interlace_color)
|
||||||
: _parent_relative(parent_relative),
|
: _parent_relative(parent_relative),
|
||||||
_relief(relief),
|
_relief(relief),
|
||||||
|
_bevel(bevel),
|
||||||
_border(border),
|
_border(border),
|
||||||
_gradient(gradient),
|
_gradient(gradient),
|
||||||
_interlaced(interlaced),
|
_interlaced(interlaced),
|
||||||
_color(color),
|
_color(color),
|
||||||
_bevel_dark_color(bevel_dark_color),
|
_bevel_dark_color(bevel_dark_color),
|
||||||
_bevel_light_color(bevel_light_color),
|
_bevel_light_color(bevel_light_color),
|
||||||
_border_color(border_color)
|
_border_color(border_color),
|
||||||
|
_interlace_color(interlace_color)
|
||||||
{
|
{
|
||||||
assert(_relief == Flat || (_bevel_dark_color && _bevel_light_color));
|
assert(_relief == Flat || (_bevel_dark_color && _bevel_light_color));
|
||||||
assert(!_border || _border_color);
|
assert(!_border || _border_color);
|
||||||
|
assert(!_interlaced || _interlace_color);
|
||||||
assert(_color);
|
assert(_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +90,8 @@ public:
|
||||||
inline bool parentRelative() const { return _parent_relative; }
|
inline bool parentRelative() const { return _parent_relative; }
|
||||||
//! The relief type of the texture
|
//! The relief type of the texture
|
||||||
inline ReliefType relief() const { return _relief; }
|
inline ReliefType relief() const { return _relief; }
|
||||||
|
//! The way the bevel should be drawn
|
||||||
|
inline BevelType bevel() const { return _bevel; }
|
||||||
//! If a flat border is drawn on the outside, ignored for all ReliefType
|
//! If a flat border is drawn on the outside, ignored for all ReliefType
|
||||||
//! values except ReliefType::Flat
|
//! values except ReliefType::Flat
|
||||||
inline bool border() const { return _border; }
|
inline bool border() const { return _border; }
|
||||||
|
@ -93,16 +104,20 @@ public:
|
||||||
//! This must always be defined
|
//! This must always be defined
|
||||||
inline const RenderColor& color() const { return *_color; }
|
inline const RenderColor& color() const { return *_color; }
|
||||||
//! The shadow color for the bevel. This must be defined if
|
//! The shadow color for the bevel. This must be defined if
|
||||||
//! RenderTexture::relief is not RenderTexture::ReliefType::Flat
|
//! RenderTexture::_relief is not RenderTexture::ReliefType::Flat
|
||||||
inline const RenderColor& bevelDarkColor() const
|
inline const RenderColor& bevelDarkColor() const
|
||||||
{ return *_bevel_dark_color; }
|
{ return *_bevel_dark_color; }
|
||||||
//! The light color for the bevel. This must be defined if
|
//! The light color for the bevel. This must be defined if
|
||||||
//! RenderTexture::relief is not RenderTexture::ReliefType::Flat
|
//! RenderTexture::)relief is not RenderTexture::ReliefType::Flat
|
||||||
inline const RenderColor& bevelLightColor() const
|
inline const RenderColor& bevelLightColor() const
|
||||||
{ return *_bevel_light_color; }
|
{ return *_bevel_light_color; }
|
||||||
//! The color for the flat border if RenderTexture::border is true. This must
|
//! The color for the flat border if RenderTexture::_border is true. This
|
||||||
//! be defined if it is true
|
//! must be defined if it is true
|
||||||
inline const RenderColor& borderColor() const { return *_border_color; }
|
inline const RenderColor& borderColor() const { return *_border_color; }
|
||||||
|
//! The color for the interlace lines if RenderTexture. This must be defined
|
||||||
|
//! if it is true
|
||||||
|
inline const RenderColor& interlaceColor() const
|
||||||
|
{ return *_interlace_color; }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,37 +102,42 @@ static inline void renderPixel(XImage *im, unsigned char *dp,
|
||||||
void TrueRenderControl::drawBackground(Surface& sf,
|
void TrueRenderControl::drawBackground(Surface& sf,
|
||||||
const RenderTexture &texture) const
|
const RenderTexture &texture) const
|
||||||
{
|
{
|
||||||
assert(sf._screen == _screen);
|
assert(_screen == sf._screen);
|
||||||
|
assert(_screen == texture.color().screen());
|
||||||
|
|
||||||
|
if (texture.gradient() == RenderTexture::Solid) {
|
||||||
|
drawSolidBackground(sf, texture);
|
||||||
|
} else {
|
||||||
|
int w = sf.width(), h = sf.height();
|
||||||
|
|
||||||
|
const ScreenInfo *info = display->screenInfo(_screen);
|
||||||
|
XImage *im = XCreateImage(**display, info->visual(), info->depth(),
|
||||||
|
ZPixmap, 0, NULL, w, h, 32, 0);
|
||||||
|
|
||||||
int w = sf.width(), h = sf.height();
|
unsigned char *data = new unsigned char[im->bytes_per_line * h];
|
||||||
|
unsigned char *dp = data;
|
||||||
|
unsigned int bytes_per_pixel = im->bits_per_pixel/8;
|
||||||
|
|
||||||
const ScreenInfo *info = display->screenInfo(_screen);
|
for (int y = 0; y < h/3; ++y)
|
||||||
XImage *im = XCreateImage(**display, info->visual(), info->depth(),
|
for (int x = 0; x < w; ++x, dp += bytes_per_pixel)
|
||||||
ZPixmap, 0, NULL, w, h, 32, 0);
|
renderPixel(im, dp, (255*x/w) >> _red_shift << _red_offset);
|
||||||
|
for (int y = 0; y < h/3; ++y)
|
||||||
unsigned char *data = new unsigned char[im->bytes_per_line * h];
|
for (int x = 0; x < w; ++x, dp += bytes_per_pixel)
|
||||||
unsigned char *dp = data;
|
renderPixel(im, dp, (255*x/w) >> _green_shift << _green_offset);
|
||||||
unsigned int bytes_per_pixel = im->bits_per_pixel/8;
|
for (int y = 0; y < h/3; ++y)
|
||||||
|
for (int x = 0; x < w; ++x, dp += bytes_per_pixel)
|
||||||
|
renderPixel(im, dp, (255*x/w) >> _blue_shift << _blue_offset);
|
||||||
|
|
||||||
for (int y = 0; y < h/3; ++y)
|
im->data = (char*) data;
|
||||||
for (int x = 0; x < w; ++x, dp += bytes_per_pixel)
|
|
||||||
renderPixel(im, dp, (255*x/w) >> _red_shift << _red_offset);
|
|
||||||
for (int y = 0; y < h/3; ++y)
|
|
||||||
for (int x = 0; x < w; ++x, dp += bytes_per_pixel)
|
|
||||||
renderPixel(im, dp, (255*x/w) >> _green_shift << _green_offset);
|
|
||||||
for (int y = 0; y < h/3; ++y)
|
|
||||||
for (int x = 0; x < w; ++x, dp += bytes_per_pixel)
|
|
||||||
renderPixel(im, dp, (255*x/w) >> _blue_shift << _blue_offset);
|
|
||||||
|
|
||||||
im->data = (char*) data;
|
|
||||||
|
|
||||||
// sf.setPixmap(im);
|
// sf.setPixmap(im);
|
||||||
sf.setPixmap(texture.color());
|
sf.setPixmap(texture.color());
|
||||||
// sf.setPixmap(RenderColor(_screen, 0xff, 0xff, 0));
|
// sf.setPixmap(RenderColor(_screen, 0xff, 0xff, 0));
|
||||||
|
|
||||||
delete [] im->data;
|
delete [] im->data;
|
||||||
im->data = NULL;
|
im->data = NULL;
|
||||||
XDestroyImage(im);
|
XDestroyImage(im);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -467,7 +467,7 @@ void Widget::setEventDispatcher(EventDispatcher *disp)
|
||||||
void Widget::exposeHandler(const XExposeEvent &e)
|
void Widget::exposeHandler(const XExposeEvent &e)
|
||||||
{
|
{
|
||||||
EventHandler::exposeHandler(e);
|
EventHandler::exposeHandler(e);
|
||||||
XClearArea(**display, _window, e.x, e.y, e.width, e.height, false);
|
// XClearArea(**display, _window, e.x, e.y, e.width, e.height, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::configureHandler(const XConfigureEvent &e)
|
void Widget::configureHandler(const XConfigureEvent &e)
|
||||||
|
|
Loading…
Reference in a new issue