eas now handles fill params for image. tile and offset of image to be filled

within an image object. just a conveneint tile & svcale and offset fill method
for programs.


SVN revision: 3109
This commit is contained in:
Carsten Haitzler 2000-08-13 22:45:48 +00:00
parent 95dbe50e98
commit fc068cdd82
3 changed files with 169 additions and 9 deletions

View File

@ -62,6 +62,10 @@ evas_add_image_from_file(Evas e, char *file)
o->current.y = 0;
o->current.w = (double)oo->current.image.w;
o->current.h = (double)oo->current.image.h;
oo->current.fill.x = 0;
oo->current.fill.y = 0;
oo->current.fill.w = (double)oo->current.image.w;
oo->current.fill.h = (double)oo->current.image.h;
imlib_free_image();
}
}
@ -113,6 +117,10 @@ evas_set_image_file(Evas e, Evas_Object o, char *file)
oo->current.image.h = imlib_image_get_height();
o->current.w = (double)oo->current.image.w;
o->current.h = (double)oo->current.image.h;
oo->current.fill.x = 0;
oo->current.fill.y = 0;
oo->current.fill.w = (double)oo->current.image.w;
oo->current.fill.h = (double)oo->current.image.h;
imlib_free_image();
}
else
@ -121,9 +129,14 @@ evas_set_image_file(Evas e, Evas_Object o, char *file)
oo->current.image.h = 0;
o->current.w = (double)oo->current.image.w;
o->current.h = (double)oo->current.image.h;
oo->current.fill.x = 0;
oo->current.fill.y = 0;
oo->current.fill.w = (double)oo->current.image.w;
oo->current.fill.h = (double)oo->current.image.h;
}
}
o->changed = 1;
e->changed = 1;
}
void
@ -135,6 +148,15 @@ evas_set_image_data(Evas e, Evas_Object o, void *data, Evas_Image_Format format,
void
evas_set_image_fill(Evas e, Evas_Object o, double x, double y, double w, double h)
{
Evas_Object_Image oo;
oo = o;
oo->current.fill.x = x;
oo->current.fill.y = y;
oo->current.fill.w = w;
oo->current.fill.h = h;
o->changed = 1;
e->changed = 1;
}
/* image query ops */

View File

@ -51,6 +51,7 @@ void
evas_update_rect(Evas e, int x, int y, int w, int h)
{
e->updates = imlib_update_append_rect(e->updates, x, y, w, h);
e->changed = 1;
}
#if 0
@ -85,7 +86,13 @@ evas_render(Evas e)
int (*func_image_get_width) (void *im);
int (*func_image_get_height) (void *im);
if ((!e->changed) || (!e->current.display) || (!e->current.drawable))
if ((!e->changed) ||
(!e->current.display) ||
(!e->current.drawable) ||
(e->current.drawable_width <= 0) ||
(e->current.drawable_height <= 0) ||
(e->current.viewport.w <= 0) ||
(e->current.viewport.h <= 0))
return;
switch (e->current.render_method)
@ -117,7 +124,6 @@ evas_render(Evas e)
default:
break;
}
e->changed = 0;
if ((e->current.viewport.x != e->previous.viewport.x) ||
(e->current.viewport.y != e->previous.viewport.y) ||
(e->current.viewport.w != e->previous.viewport.w) ||
@ -127,6 +133,7 @@ evas_render(Evas e)
e->current.drawable_width,
e->current.drawable_height);
e->changed = 0;
delete_objects = 0;
/* go thru layers & objects and add updates */
for (l = e->layers; l; l = l->next)
@ -311,8 +318,141 @@ evas_render(Evas e)
oo = o;
im = func_image_new_from_file(e->current.display, oo->current.file);
if (im)
{
int visx, visy, visw, vish;
int tilex, tiley, tilew, tileh;
struct _points
{
int out1, out2;
int in1, in2;
} *pointsx, *pointsy;
int xx, yy, ww, hh;
visx = x;
visw = w;
if (x < 0)
{
visx = 0;
visw += x;
}
if ((visx + visw) > e->current.drawable_width) visw = e->current.drawable_width - visx;
tilex = (-oo->current.fill.x * (double)e->current.drawable_width) / e->current.viewport.w;
tilew = (oo->current.fill.w * (double)e->current.drawable_width) / e->current.viewport.w;
if (tilew < 1) tilew = 1;
tilex = (((tilex - (x - visx)) % tilew) + tilew) % tilew;
if (tilex == 0) ww = 1 + (visw - 1) / tilew;
else ww = 1 + ((visw + tilex) / tilew);
pointsx = malloc(ww * sizeof(struct _points));
for (xx = 0; xx < ww; xx++)
{
if (xx == 0)
{
if (xx == (ww - 1)) /* | * | */
{
pointsx[xx].out1 = visx + 0;
pointsx[xx].out2 = visw;
pointsx[xx].in1 = (int)(((double)tilex * (double)oo->current.image.w * e->current.viewport.w) / ((double)e->current.drawable_width * (double)tilew));
pointsx[xx].in2 = (int)(((double)func_image_get_width(im) * (double)visw) / (double)tilew);
}
else /* | * | | | */
{
pointsx[xx].out1 = visx + 0;
pointsx[xx].out2 = tilew - tilex;
pointsx[xx].in1 = (int)(((double)tilex * (double)oo->current.image.w * e->current.viewport.w) / ((double)e->current.drawable_width * (double)tilew));
pointsx[xx].in2 = func_image_get_width(im) - pointsx[xx].in1;
}
}
else
{
if (xx == (ww - 1)) /* | | | * | */
{
pointsx[xx].out1 = visx + (xx * tilew) - tilex;
pointsx[xx].out2 = visw - (pointsx[xx].out1 - visx);
pointsx[xx].in1 = 0;
pointsx[xx].in2 = (int)(((double)pointsx[xx].out2 * (double)oo->current.image.w * e->current.viewport.w) / ((double)e->current.drawable_width * (double)tilew));
}
else /* | | * | | */
{
pointsx[xx].out1 = visx + (xx * tilew) - tilex;
pointsx[xx].out2 = tilew;
pointsx[xx].in1 = 0;
pointsx[xx].in2 = func_image_get_width(im);
}
}
}
visy = y;
vish = h;
if (y < 0)
{
visy = 0;
vish += y;
}
if ((visy + vish) > e->current.drawable_height) vish = e->current.drawable_height - visy;
tiley = (-oo->current.fill.y * (double)e->current.drawable_height) / e->current.viewport.h;
tileh = (oo->current.fill.h * (double)e->current.drawable_height) / e->current.viewport.h;
if (tileh < 1) tileh = 1;
tiley = (((tiley - (y - visy)) % tileh) + tileh) % tileh;
if (tiley == 0) hh = 1 + (vish - 1) / tileh;
else hh = 1 + ((vish + tiley) / tileh);
pointsy = malloc(hh * sizeof(struct _points));
for (yy = 0; yy < hh; yy++)
{
if (yy == 0)
{
if (yy == (hh - 1)) /* | * | */
{
pointsy[yy].out1 = visy + 0;
pointsy[yy].out2 = vish;
pointsy[yy].in1 = (int)(((double)tiley * (double)oo->current.image.h * e->current.viewport.h) / ((double)e->current.drawable_height * (double)tileh));
pointsy[yy].in2 = (int)(((double)func_image_get_height(im) * (double)vish) / (double)tileh);
}
else /* | * | | | */
{
pointsy[yy].out1 = visy + 0;
pointsy[yy].out2 = tileh - tiley;
pointsy[yy].in1 = (int)(((double)tiley * (double)oo->current.image.h * e->current.viewport.h) / ((double)e->current.drawable_height * (double)tileh));
pointsy[yy].in2 = func_image_get_height(im) - pointsy[yy].in1;
}
}
else
{
if (yy == (hh - 1)) /* | | | * | */
{
pointsy[yy].out1 = visy + (yy * tileh) - tiley;
pointsy[yy].out2 = vish - (pointsy[yy].out1 - visy);
pointsy[yy].in1 = 0;
pointsy[yy].in2 = (int)(((double)pointsy[yy].out2 * (double)oo->current.image.h * e->current.viewport.h) / ((double)e->current.drawable_height * (double)tileh));
}
else /* | | * | | */
{
pointsy[yy].out1 = visy + (yy * tileh) - tiley;
pointsy[yy].out2 = tileh;
pointsy[yy].in1 = 0;
pointsy[yy].in2 = func_image_get_height(im);
}
}
}
for (yy = 0; yy < hh; yy++)
{
for (xx = 0; xx < ww; xx++)
{
func_image_draw(im,
e->current.display,
e->current.drawable,
e->current.drawable_width,
e->current.drawable_height,
pointsx[xx].in1, pointsy[yy].in1,
pointsx[xx].in2, pointsy[yy].in2,
pointsx[xx].out1, pointsy[yy].out1,
pointsx[xx].out2, pointsy[yy].out2);
}
}
free(pointsx);
free(pointsy);
/* func_image_draw(im,
e->current.display,
e->current.drawable,
e->current.drawable_width,
@ -320,7 +460,7 @@ evas_render(Evas e)
0, 0,
func_image_get_width(im),
func_image_get_height(im),
x, y, w, h);
x, y, w, h);*/
func_image_free(im);
}
}

View File

@ -74,11 +74,13 @@ main(int argc, char **argv)
w /= 2;
h /= 2;
evas_show(e, o[1]);
for (i = 2 ; i < 128; i++)
{
o[i] = evas_add_image_from_file(e, "img/mush.png");
evas_show(e, o[i]);
}
evas_raise(e, o[1]);
evas_move(e, o[0], 0, 0);
evas_resize(e, o[0], win_w, win_h);
@ -124,10 +126,8 @@ main(int argc, char **argv)
mouse_x = ev.xmotion.x;
mouse_y = ev.xmotion.y;
if (down)
{
evas_move(e, o[1], mouse_x - w, mouse_y - h);
}
}
break;
case Expose:
{
@ -139,7 +139,6 @@ main(int argc, char **argv)
}
}
/* while (XPending(d));*/
for (i = 2; i < 128; i++)
{
int j, k;
@ -151,7 +150,6 @@ main(int argc, char **argv)
evas_set_image_file(e, o[i], imgs[(i) & 0x7]);
evas_move(e, o[i], x, y);
}
evas_render(e);
a++;
if (a >= 1000) a = 0;