better border support for stuff. add a borderColor resource, and allow borders with gradients. basically, they can only be used with flat stuff (not raised/lowered)

This commit is contained in:
Dana Jansens 2002-09-04 02:58:39 +00:00
parent 1f5dd220e7
commit 23aea9b42f
5 changed files with 94 additions and 40 deletions

View file

@ -107,54 +107,57 @@ Pixmap BImage::render_solid(const BTexture &texture) {
XDrawLine(display, pixmap, peninterlace.gc(), 0, i, width, i); XDrawLine(display, pixmap, peninterlace.gc(), 0, i, width, i);
} }
if (texture.texture() & BTexture::FlatBorder) { int left = 0, top = 0, right = width - 1, bottom = height - 1;
BPen penborder(texture.colorTo());
XDrawRectangle(display, pixmap, penborder.gc(), 0, 0, width-1, height-1); if (texture.texture() & BTexture::Border) {
BPen penborder(texture.borderColor());
XDrawRectangle(display, pixmap, penborder.gc(),
left, top, right, bottom);
} }
if (texture.texture() & BTexture::Bevel1) { if (texture.texture() & BTexture::Bevel1) {
if (texture.texture() & BTexture::Raised) { if (texture.texture() & BTexture::Raised) {
XDrawLine(display, pixmap, penshadow.gc(), XDrawLine(display, pixmap, penshadow.gc(),
0, height - 1, width - 1, height - 1); left, bottom, right, bottom);
XDrawLine(display, pixmap, penshadow.gc(), XDrawLine(display, pixmap, penshadow.gc(),
width - 1, height - 1, width - 1, 0); right, bottom, right, top);
XDrawLine(display, pixmap, penlight.gc(), XDrawLine(display, pixmap, penlight.gc(),
0, 0, width - 1, 0); left, top, right, top);
XDrawLine(display, pixmap, penlight.gc(), XDrawLine(display, pixmap, penlight.gc(),
0, height - 1, 0, 0); left, bottom, left, top);
} else if (texture.texture() & BTexture::Sunken) { } else if (texture.texture() & BTexture::Sunken) {
XDrawLine(display, pixmap, penlight.gc(), XDrawLine(display, pixmap, penlight.gc(),
0, height - 1, width - 1, height - 1); left, bottom, right, bottom);
XDrawLine(display, pixmap, penlight.gc(), XDrawLine(display, pixmap, penlight.gc(),
width - 1, height - 1, width - 1, 0); right, bottom, right, top);
XDrawLine(display, pixmap, penshadow.gc(), XDrawLine(display, pixmap, penshadow.gc(),
0, 0, width - 1, 0); left, top, right, top);
XDrawLine(display, pixmap, penshadow.gc(), XDrawLine(display, pixmap, penshadow.gc(),
0, height - 1, 0, 0); left, bottom, left, top);
} }
} else if (texture.texture() & BTexture::Bevel2) { } else if (texture.texture() & BTexture::Bevel2) {
if (texture.texture() & BTexture::Raised) { if (texture.texture() & BTexture::Raised) {
XDrawLine(display, pixmap, penshadow.gc(), XDrawLine(display, pixmap, penshadow.gc(),
1, height - 3, width - 3, height - 3); left + 1, bottom - 2, right - 2, bottom - 2);
XDrawLine(display, pixmap, penshadow.gc(), XDrawLine(display, pixmap, penshadow.gc(),
width - 3, height - 3, width - 3, 1); right - 2, bottom - 2, right - 2, top + 1);
XDrawLine(display, pixmap, penlight.gc(), XDrawLine(display, pixmap, penlight.gc(),
1, 1, width - 3, 1); left + 1, top + 1, right - 2, top + 1);
XDrawLine(display, pixmap, penlight.gc(), XDrawLine(display, pixmap, penlight.gc(),
1, height - 3, 1, 1); left + 1, bottom - 2, left + 1, top + 1);
} else if (texture.texture() & BTexture::Sunken) { } else if (texture.texture() & BTexture::Sunken) {
XDrawLine(display, pixmap, penlight.gc(), XDrawLine(display, pixmap, penlight.gc(),
1, height - 3, width - 3, height - 3); left + 1, bottom - 2, right - 2, bottom - 2);
XDrawLine(display, pixmap, penlight.gc(), XDrawLine(display, pixmap, penlight.gc(),
width - 3, height - 3, width - 3, 1); right - 2, bottom - 2, right - 2, top + 1);
XDrawLine(display, pixmap, penshadow.gc(), XDrawLine(display, pixmap, penshadow.gc(),
1, 1, width - 3, 1); left + 1, top + 1, right - 2, top + 1);
XDrawLine(display, pixmap, penshadow.gc(), XDrawLine(display, pixmap, penshadow.gc(),
1, height - 3, 1, 1); left + 1, bottom - 2, left + 1, top + 1);
} }
} }
@ -193,6 +196,8 @@ Pixmap BImage::render_gradient(const BTexture &texture) {
if (texture.texture() & BTexture::Bevel1) bevel1(); if (texture.texture() & BTexture::Bevel1) bevel1();
else if (texture.texture() & BTexture::Bevel2) bevel2(); else if (texture.texture() & BTexture::Bevel2) bevel2();
if (texture.texture() & BTexture::Border) border(texture);
if (inverted) invert(); if (inverted) invert();
return renderPixmap(); return renderPixmap();
@ -816,6 +821,46 @@ void BImage::bevel2(void) {
} }
void BImage::border(const BTexture &texture) {
register unsigned int i;
int r = texture.borderColor().red(),
g = texture.borderColor().green(),
b = texture.borderColor().blue();
unsigned char *pr, *pg, *pb;
// top line
pr = red;
pg = green;
pb = blue;
for (i = 0; i < width; ++i) {
*pr++ = r;
*pg++ = g;
*pb++ = b;
}
// left and right lines (pr,pg,pb are already lined up)
for (i = 1; i < height - 1; ++i) {
*pr = r;
*pg = g;
*pb = b;
pr += width - 1;
pg += width - 1;
pb += width - 1;
*pr++ = r;
*pg++ = g;
*pb++ = b;
}
// bottom line (pr,pg,pb are already lined up)
for (i = 0; i < width; ++i) {
*pr++ = r;
*pg++ = g;
*pb++ = b;
}
}
void BImage::invert(void) { void BImage::invert(void) {
register unsigned int i, j, wh = (width * height) - 1; register unsigned int i, j, wh = (width * height) - 1;
unsigned char tmp; unsigned char tmp;

View file

@ -66,6 +66,7 @@ private:
void invert(void); void invert(void);
void bevel1(void); void bevel1(void);
void bevel2(void); void bevel2(void);
void border(const BTexture &texture);
void dgradient(void); void dgradient(void);
void egradient(void); void egradient(void);
void hgradient(void); void hgradient(void);

View file

@ -2520,6 +2520,8 @@ BTexture BScreen::readDatabaseTexture(const string &rname,
texture.setColor(readDatabaseColor(rname + ".color", default_color, style)); texture.setColor(readDatabaseColor(rname + ".color", default_color, style));
texture.setColorTo(readDatabaseColor(rname + ".colorTo", default_color, texture.setColorTo(readDatabaseColor(rname + ".colorTo", default_color,
style)); style));
texture.setBorderColor(readDatabaseColor(rname + ".borderColor",
default_color, style));
return texture; return texture;
} }

View file

@ -46,14 +46,14 @@ using std::string;
BTexture::BTexture(const BaseDisplay * const _display, BTexture::BTexture(const BaseDisplay * const _display,
unsigned int _screen, BImageControl* _ctrl) unsigned int _screen, BImageControl* _ctrl)
: c(_display, _screen), ct(_display, _screen), : c(_display, _screen), ct(_display, _screen),
lc(_display, _screen), sc(_display, _screen), t(0), lc(_display, _screen), sc(_display, _screen), bc(_display, _screen), t(0),
dpy(_display), ctrl(_ctrl), scrn(_screen) { } dpy(_display), ctrl(_ctrl), scrn(_screen) { }
BTexture::BTexture(const string &d, const BaseDisplay * const _display, BTexture::BTexture(const string &d, const BaseDisplay * const _display,
unsigned int _screen, BImageControl* _ctrl) unsigned int _screen, BImageControl* _ctrl)
: c(_display, _screen), ct(_display, _screen), : c(_display, _screen), ct(_display, _screen),
lc(_display, _screen), sc(_display, _screen), t(0), lc(_display, _screen), sc(_display, _screen), bc(_display, _screen), t(0),
dpy(_display), ctrl(_ctrl), scrn(_screen) { dpy(_display), ctrl(_ctrl), scrn(_screen) {
setDescription(d); setDescription(d);
} }
@ -128,14 +128,15 @@ void BTexture::setDescription(const string &d) {
if (descr.find("sunken") != string::npos) if (descr.find("sunken") != string::npos)
addTexture(BTexture::Sunken); addTexture(BTexture::Sunken);
else if (descr.find("flatborder") != string::npos)
addTexture(BTexture::FlatBorder);
else if (descr.find("flat") != string::npos) else if (descr.find("flat") != string::npos)
addTexture(BTexture::Flat); addTexture(BTexture::Flat);
else else
addTexture(BTexture::Raised); addTexture(BTexture::Raised);
if (! (texture() & (BTexture::Flat | BTexture::FlatBorder))) { if (texture() & BTexture::Flat) {
if (descr.find("border") != string::npos)
addTexture(BTexture::Border);
} else {
if (descr.find("bevel2") != string::npos) if (descr.find("bevel2") != string::npos)
addTexture(BTexture::Bevel2); addTexture(BTexture::Bevel2);
else else
@ -160,6 +161,7 @@ void BTexture::setDisplay(const BaseDisplay * const _display,
ct.setDisplay(_display, _screen); ct.setDisplay(_display, _screen);
lc.setDisplay(_display, _screen); lc.setDisplay(_display, _screen);
sc.setDisplay(_display, _screen); sc.setDisplay(_display, _screen);
bc.setDisplay(_display, _screen);
} }
@ -168,6 +170,7 @@ BTexture& BTexture::operator=(const BTexture &tt) {
ct = tt.ct; ct = tt.ct;
lc = tt.lc; lc = tt.lc;
sc = tt.sc; sc = tt.sc;
bc = tt.bc;
descr = tt.descr; descr = tt.descr;
t = tt.t; t = tt.t;
dpy = tt.dpy; dpy = tt.dpy;

View file

@ -35,24 +35,25 @@ public:
enum Type { enum Type {
// bevel options // bevel options
Flat = (1l<<0), Flat = (1l<<0),
FlatBorder = (1l<<1), Sunken = (1l<<1),
Sunken = (1l<<2), Raised = (1l<<2),
Raised = (1l<<3),
// textures // textures
Solid = (1l<<4), Solid = (1l<<3),
Gradient = (1l<<5), Gradient = (1l<<4),
// gradients // gradients
Horizontal = (1l<<6), Horizontal = (1l<<5),
Vertical = (1l<<7), Vertical = (1l<<6),
Diagonal = (1l<<8), Diagonal = (1l<<7),
CrossDiagonal = (1l<<9), CrossDiagonal = (1l<<8),
Rectangle = (1l<<10), Rectangle = (1l<<9),
Pyramid = (1l<<11), Pyramid = (1l<<10),
PipeCross = (1l<<12), PipeCross = (1l<<11),
Elliptic = (1l<<13), Elliptic = (1l<<12),
// bevel types // bevel types
Bevel1 = (1l<<14), Bevel1 = (1l<<13),
Bevel2 = (1l<<15), Bevel2 = (1l<<14),
// flat border
Border = (1l<<15),
// inverted image // inverted image
Invert = (1l<<16), Invert = (1l<<16),
// parent relative image // parent relative image
@ -69,11 +70,13 @@ public:
void setColor(const BColor &_color); void setColor(const BColor &_color);
void setColorTo(const BColor &_colorTo) { ct = _colorTo; } void setColorTo(const BColor &_colorTo) { ct = _colorTo; }
void setBorderColor(const BColor &_borderColor) { bc = _borderColor; }
const BColor &color(void) const { return c; } const BColor &color(void) const { return c; }
const BColor &colorTo(void) const { return ct; } const BColor &colorTo(void) const { return ct; }
const BColor &lightColor(void) const { return lc; } const BColor &lightColor(void) const { return lc; }
const BColor &shadowColor(void) const { return sc; } const BColor &shadowColor(void) const { return sc; }
const BColor &borderColor(void) const { return bc; }
unsigned long texture(void) const { return t; } unsigned long texture(void) const { return t; }
void setTexture(const unsigned long _texture) { t = _texture; } void setTexture(const unsigned long _texture) { t = _texture; }
@ -98,7 +101,7 @@ public:
const Pixmap old = 0); const Pixmap old = 0);
private: private:
BColor c, ct, lc, sc; BColor c, ct, lc, sc, bc;
std::string descr; std::string descr;
unsigned long t; unsigned long t;
const BaseDisplay *dpy; const BaseDisplay *dpy;