reindent the file....
but while i'm at it: - add support for bevels/borders on solid textures. - reverse the colors in the rectangle gradient, the pipecross and pyramid ones may need to be reversed as well.
This commit is contained in:
parent
13f701bdb1
commit
895cd9f43d
1 changed files with 429 additions and 362 deletions
|
@ -151,21 +151,27 @@ void gradient_diagonal(Surface *sf, int w, int h)
|
|||
int x, y;
|
||||
|
||||
for (y = 0; y < h; ++y) {
|
||||
drx = (float)(sf->data.planar.secondary->r - sf->data.planar.primary->r);
|
||||
drx = (float)(sf->data.planar.secondary->r -
|
||||
sf->data.planar.primary->r);
|
||||
dry = drx/(float)h;
|
||||
drx/= (float)w;
|
||||
|
||||
dgx = (float)(sf->data.planar.secondary->g - sf->data.planar.primary->g);
|
||||
dgx = (float)(sf->data.planar.secondary->g -
|
||||
sf->data.planar.primary->g);
|
||||
dgy = dgx/(float)h;
|
||||
dgx/= (float)w;
|
||||
|
||||
dbx = (float)(sf->data.planar.secondary->b - sf->data.planar.primary->b);
|
||||
dbx = (float)(sf->data.planar.secondary->b -
|
||||
sf->data.planar.primary->b);
|
||||
dby = dbx/(float)h;
|
||||
dbx/= (float)w;
|
||||
for (x = 0; x < w; ++x, ++data) {
|
||||
r = sf->data.planar.primary->r + ((int)(drx * x) + (int)(dry * y))/2;
|
||||
g = sf->data.planar.primary->g + ((int)(dgx * x) + (int)(dgy * y))/2;
|
||||
b = sf->data.planar.primary->b + ((int)(dbx * x) + (int)(dby * y))/2;
|
||||
r = sf->data.planar.primary->r +
|
||||
((int)(drx * x) + (int)(dry * y))/2;
|
||||
g = sf->data.planar.primary->g +
|
||||
((int)(dgx * x) + (int)(dgy * y))/2;
|
||||
b = sf->data.planar.primary->b +
|
||||
((int)(dbx * x) + (int)(dby * y))/2;
|
||||
current = (r << default_red_offset)
|
||||
+ (g << default_green_offset)
|
||||
+ (b << default_blue_offset);
|
||||
|
@ -183,21 +189,27 @@ void gradient_crossdiagonal(Surface *sf, int w, int h)
|
|||
int x, y;
|
||||
|
||||
for (y = 0; y < h; ++y) {
|
||||
drx = (float)(sf->data.planar.secondary->r - sf->data.planar.primary->r);
|
||||
drx = (float)(sf->data.planar.secondary->r -
|
||||
sf->data.planar.primary->r);
|
||||
dry = drx/(float)h;
|
||||
drx/= (float)w;
|
||||
|
||||
dgx = (float)(sf->data.planar.secondary->g - sf->data.planar.primary->g);
|
||||
dgx = (float)(sf->data.planar.secondary->g -
|
||||
sf->data.planar.primary->g);
|
||||
dgy = dgx/(float)h;
|
||||
dgx/= (float)w;
|
||||
|
||||
dbx = (float)(sf->data.planar.secondary->b - sf->data.planar.primary->b);
|
||||
dbx = (float)(sf->data.planar.secondary->b -
|
||||
sf->data.planar.primary->b);
|
||||
dby = dbx/(float)h;
|
||||
dbx/= (float)w;
|
||||
for (x = w; x > 0; --x, ++data) {
|
||||
r = sf->data.planar.primary->r + ((int)(drx * (x-1)) + (int)(dry * y))/2;
|
||||
g = sf->data.planar.primary->g + ((int)(dgx * (x-1)) + (int)(dgy * y))/2;
|
||||
b = sf->data.planar.primary->b + ((int)(dbx * (x-1)) + (int)(dby * y))/2;
|
||||
r = sf->data.planar.primary->r +
|
||||
((int)(drx * (x-1)) + (int)(dry * y))/2;
|
||||
g = sf->data.planar.primary->g +
|
||||
((int)(dgx * (x-1)) + (int)(dgy * y))/2;
|
||||
b = sf->data.planar.primary->b +
|
||||
((int)(dbx * (x-1)) + (int)(dby * y))/2;
|
||||
current = (r << default_red_offset)
|
||||
+ (g << default_green_offset)
|
||||
+ (b << default_blue_offset);
|
||||
|
@ -224,9 +236,9 @@ void highlight(pixel32 *x, pixel32 *y, gboolean raised)
|
|||
g += g >> 1;
|
||||
b = (*up >> default_blue_offset) & 0xFF;
|
||||
b += b >> 1;
|
||||
if (r > 255) r = 255;
|
||||
if (g > 255) g = 255;
|
||||
if (b > 255) b = 255;
|
||||
if (r > 0xFF) r = 0xFF;
|
||||
if (g > 0xFF) g = 0xFF;
|
||||
if (b > 0xFF) b = 0xFF;
|
||||
*up = (r << default_red_offset) + (g << default_green_offset)
|
||||
+ (b << default_blue_offset);
|
||||
|
||||
|
@ -240,12 +252,42 @@ void highlight(pixel32 *x, pixel32 *y, gboolean raised)
|
|||
+ (b << default_blue_offset);
|
||||
}
|
||||
|
||||
static void create_bevel_colors(Appearance *l)
|
||||
{
|
||||
int r, g, b;
|
||||
|
||||
/* light color */
|
||||
r = l->surface.data.planar.primary->r;
|
||||
r += r >> 1;
|
||||
g = l->surface.data.planar.primary->g;
|
||||
g += g >> 1;
|
||||
b = l->surface.data.planar.primary->b;
|
||||
b += b >> 1;
|
||||
if (r > 0xFF) r = 0xFF;
|
||||
if (g > 0xFF) g = 0xFF;
|
||||
if (b > 0xFF) b = 0xFF;
|
||||
g_assert(!l->surface.data.planar.bevel_light);
|
||||
l->surface.data.planar.bevel_light = color_new(r, g, b);
|
||||
color_allocate_gc(l->surface.data.planar.bevel_light);
|
||||
|
||||
/* dark color */
|
||||
r = l->surface.data.planar.primary->r;
|
||||
r = (r >> 1) + (r >> 2);
|
||||
g = l->surface.data.planar.primary->g;
|
||||
g = (g >> 1) + (g >> 2);
|
||||
b = l->surface.data.planar.primary->b;
|
||||
b = (b >> 1) + (b >> 2);
|
||||
g_assert(!l->surface.data.planar.bevel_dark);
|
||||
l->surface.data.planar.bevel_dark = color_new(r, g, b);
|
||||
color_allocate_gc(l->surface.data.planar.bevel_dark);
|
||||
}
|
||||
|
||||
void gradient_solid(Appearance *l, int x, int y, int w, int h)
|
||||
{
|
||||
pixel32 pix;
|
||||
int i, a, b;
|
||||
PlanarSurface *sp = &l->surface.data.planar;
|
||||
int left = x, top = y, right = w - 1, bottom = h - 1;
|
||||
int left = x, top = y, right = x + w - 1, bottom = y + h - 1;
|
||||
|
||||
if (sp->primary->gc == None)
|
||||
color_allocate_gc(sp->primary);
|
||||
|
@ -257,84 +299,93 @@ void gradient_solid(Appearance *l, int x, int y, int w, int h)
|
|||
for (b = 0; b < l->area.height; b++)
|
||||
sp->pixel_data[a + b*l->area.width] = pix;
|
||||
|
||||
XFillRectangle(ob_display, l->pixmap, sp->primary->gc
|
||||
, x, y, w, h);
|
||||
XFillRectangle(ob_display, l->pixmap, sp->primary->gc,
|
||||
x, y, w, h);
|
||||
|
||||
if (l->surface.data.planar.interlaced) {
|
||||
if (sp->interlaced) {
|
||||
if (sp->secondary->gc == None)
|
||||
color_allocate_gc(sp->secondary);
|
||||
for (i = y; i < h; i += 2)
|
||||
XDrawLine(ob_display, l->pixmap, sp->secondary->gc,
|
||||
x, i, w, i);
|
||||
}
|
||||
/*
|
||||
switch (texture.relief()) {
|
||||
case RenderTexture::Raised:
|
||||
switch (texture.bevel()) {
|
||||
case RenderTexture::Bevel1:
|
||||
XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
|
||||
|
||||
switch (sp->relief) {
|
||||
case Raised:
|
||||
if (!sp->bevel_dark)
|
||||
create_bevel_colors(l);
|
||||
|
||||
switch (sp->bevel) {
|
||||
case Bevel1:
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc,
|
||||
left, bottom, right, bottom);
|
||||
XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc,
|
||||
right, bottom, right, top);
|
||||
|
||||
XDrawLine(ob_display, l->pixmap, texture.bevelLightColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc,
|
||||
left, top, right, top);
|
||||
XDrawLine(ob_display, l->pixmap, texture.bevelLightColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc,
|
||||
left, bottom, left, top);
|
||||
break;
|
||||
case RenderTexture::Bevel2:
|
||||
XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
|
||||
case Bevel2:
|
||||
XDrawLine(ob_display, l->pixmap,
|
||||
sp->bevel_dark->gc,
|
||||
left + 1, bottom - 2, right - 2, bottom - 2);
|
||||
XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap,
|
||||
sp->bevel_dark->gc,
|
||||
right - 2, bottom - 2, right - 2, top + 1);
|
||||
|
||||
XDrawLine(ob_display, l->pixmap, texture.bevelLightColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap,
|
||||
sp->bevel_light->gc,
|
||||
left + 1, top + 1, right - 2, top + 1);
|
||||
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap,
|
||||
sp->bevel_light->gc,
|
||||
left + 1, bottom - 2, left + 1, top + 1);
|
||||
break;
|
||||
default:
|
||||
assert(false); // unhandled RenderTexture::BevelType
|
||||
g_assert_not_reached(); /* unhandled BevelType */
|
||||
}
|
||||
break;
|
||||
case RenderTexture::Sunken:
|
||||
switch (texture.bevel()) {
|
||||
case RenderTexture::Bevel1:
|
||||
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||
case Sunken:
|
||||
if (!sp->bevel_dark)
|
||||
create_bevel_colors(l);
|
||||
|
||||
switch (sp->bevel) {
|
||||
case Bevel1:
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc,
|
||||
left, bottom, right, bottom);
|
||||
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc,
|
||||
right, bottom, right, top);
|
||||
|
||||
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc,
|
||||
left, top, right, top);
|
||||
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc,
|
||||
left, bottom, left, top);
|
||||
break;
|
||||
case RenderTexture::Bevel2:
|
||||
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||
case Bevel2:
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc,
|
||||
left + 1, bottom - 2, right - 2, bottom - 2);
|
||||
XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc,
|
||||
right - 2, bottom - 2, right - 2, top + 1);
|
||||
|
||||
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc,
|
||||
left + 1, top + 1, right - 2, top + 1);
|
||||
XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
|
||||
XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc,
|
||||
left + 1, bottom - 2, left + 1, top + 1);
|
||||
|
||||
break;
|
||||
default:
|
||||
assert(false); // unhandled RenderTexture::BevelType
|
||||
g_assert_not_reached(); /* unhandled BevelType */
|
||||
}
|
||||
break;
|
||||
case RenderTexture::Flat:
|
||||
if (texture.border())
|
||||
XDrawRectangle(**display, sf.pixmap(), texture.borderColor().gc(),
|
||||
case Flat:
|
||||
if (sp->border)
|
||||
XDrawRectangle(ob_display, l->pixmap, sp->border_color->gc,
|
||||
left, top, right, bottom);
|
||||
break;
|
||||
default:
|
||||
assert(false); // unhandled RenderTexture::ReliefType
|
||||
g_assert_not_reached(); /* unhandled ReliefType */
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void gradient_pyramid(Surface *sf, int inw, int inh)
|
||||
|
@ -346,21 +397,27 @@ void gradient_pyramid(Surface *sf, int inw, int inh)
|
|||
unsigned int r,g,b;
|
||||
int x, y, h=(inh/2) + 1, w=(inw/2) + 1;
|
||||
for (y = 0; y < h; ++y) {
|
||||
drx = (float)(sf->data.planar.secondary->r - sf->data.planar.primary->r);
|
||||
drx = (float)(sf->data.planar.secondary->r -
|
||||
sf->data.planar.primary->r);
|
||||
dry = drx/(float)h;
|
||||
drx/= (float)w;
|
||||
|
||||
dgx = (float)(sf->data.planar.secondary->g - sf->data.planar.primary->g);
|
||||
dgx = (float)(sf->data.planar.secondary->g -
|
||||
sf->data.planar.primary->g);
|
||||
dgy = dgx/(float)h;
|
||||
dgx/= (float)w;
|
||||
|
||||
dbx = (float)(sf->data.planar.secondary->b - sf->data.planar.primary->b);
|
||||
dbx = (float)(sf->data.planar.secondary->b -
|
||||
sf->data.planar.primary->b);
|
||||
dby = dbx/(float)h;
|
||||
dbx/= (float)w;
|
||||
for (x = 0; x < w; ++x, data) {
|
||||
r = sf->data.planar.primary->r + ((int)(drx * x) + (int)(dry * y))/2;
|
||||
g = sf->data.planar.primary->g + ((int)(dgx * x) + (int)(dgy * y))/2;
|
||||
b = sf->data.planar.primary->b + ((int)(dbx * x) + (int)(dby * y))/2;
|
||||
r = sf->data.planar.primary->r +
|
||||
((int)(drx * x) + (int)(dry * y))/2;
|
||||
g = sf->data.planar.primary->g +
|
||||
((int)(dgx * x) + (int)(dgy * y))/2;
|
||||
b = sf->data.planar.primary->b +
|
||||
((int)(dbx * x) + (int)(dby * y))/2;
|
||||
current = (r << default_red_offset)
|
||||
+ (g << default_green_offset)
|
||||
+ (b << default_blue_offset);
|
||||
|
@ -384,25 +441,30 @@ void gradient_rectangle(Surface *sf, int inw, int inh)
|
|||
int x, y, h=(inh/2) + 1, w=(inw/2) + 1;
|
||||
int val;
|
||||
|
||||
g_message("rectangle");
|
||||
|
||||
for (y = 0; y < h; ++y) {
|
||||
drx = (float)(sf->data.planar.secondary->r - sf->data.planar.primary->r);
|
||||
drx = (float)(sf->data.planar.primary->r -
|
||||
sf->data.planar.secondary->r);
|
||||
dry = drx/(float)h;
|
||||
drx/= (float)w;
|
||||
|
||||
dgx = (float)(sf->data.planar.secondary->g - sf->data.planar.primary->g);
|
||||
dgx = (float)(sf->data.planar.primary->g -
|
||||
sf->data.planar.secondary->g);
|
||||
dgy = dgx/(float)h;
|
||||
dgx/= (float)w;
|
||||
|
||||
dbx = (float)(sf->data.planar.secondary->b - sf->data.planar.primary->b);
|
||||
dbx = (float)(sf->data.planar.primary->b -
|
||||
sf->data.planar.secondary->b);
|
||||
dby = dbx/(float)h;
|
||||
dbx/= (float)w;
|
||||
for (x = 0; x < w; ++x, data) {
|
||||
if ((float)x/(float)w < (float)y/(float)h) val = (int)(drx * x);
|
||||
else val = (int)(dry * y);
|
||||
|
||||
r = sf->data.planar.primary->r + val;
|
||||
g = sf->data.planar.primary->g + val;
|
||||
b = sf->data.planar.primary->b + val;
|
||||
r = sf->data.planar.secondary->r + val;
|
||||
g = sf->data.planar.secondary->g + val;
|
||||
b = sf->data.planar.secondary->b + val;
|
||||
current = (r << default_red_offset)
|
||||
+ (g << default_green_offset)
|
||||
+ (b << default_blue_offset);
|
||||
|
@ -426,16 +488,21 @@ void gradient_pipecross(Surface *sf, int inw, int inh)
|
|||
int x, y, h=(inh/2) + 1, w=(inw/2) + 1;
|
||||
int val;
|
||||
|
||||
g_message("pipecross");
|
||||
|
||||
for (y = 0; y < h; ++y) {
|
||||
drx = (float)(sf->data.planar.secondary->r - sf->data.planar.primary->r);
|
||||
drx = (float)(sf->data.planar.secondary->r -
|
||||
sf->data.planar.primary->r);
|
||||
dry = drx/(float)h;
|
||||
drx/= (float)w;
|
||||
|
||||
dgx = (float)(sf->data.planar.secondary->g - sf->data.planar.primary->g);
|
||||
dgx = (float)(sf->data.planar.secondary->g -
|
||||
sf->data.planar.primary->g);
|
||||
dgy = dgx/(float)h;
|
||||
dgx/= (float)w;
|
||||
|
||||
dbx = (float)(sf->data.planar.secondary->b - sf->data.planar.primary->b);
|
||||
dbx = (float)(sf->data.planar.secondary->b -
|
||||
sf->data.planar.primary->b);
|
||||
dby = dbx/(float)h;
|
||||
dbx/= (float)w;
|
||||
for (x = 0; x < w; ++x, data) {
|
||||
|
|
Loading…
Reference in a new issue