cleaner use func pointers for rendering backend funcs - too much copy & paste

SVN revision: 3096
This commit is contained in:
Carsten Haitzler 2000-08-13 06:06:43 +00:00
parent cda8d8b1b8
commit a5ba53be87
10 changed files with 318 additions and 201 deletions

View File

@ -131,6 +131,7 @@ struct _Evas_Object_Any
int zoomscale;
int layer;
int visible;
int stacking;
} current, previous;
int changed;
@ -228,6 +229,7 @@ void evas_set_output(Evas e, Display *disp, Drawable d, Visual *v, Colormap c);
void evas_set_output_size(Evas e, int w, int h);
void evas_set_output_viewport(Evas e, double x, double y, double w, double h);
void evas_set_output_method(Evas e, Evas_Render_Method method);
void evas_set_scale_smoothness(Evas e, int smooth);
/* deleting objects */
void evas_del_object(Evas e, Evas_Object o);
@ -244,7 +246,6 @@ Evas_Object evas_add_bits(Evas e, char *file);
/* set object settings */
void evas_set_image_file(Evas e, Evas_Object o, char *file);
void evas_set_image_data(Evas e, Evas_Object o, void *data, Evas_Image_Format format, int w, int h);
void evas_set_image_scale_smoothness(Evas e, Evas_Object o, int smooth);
void evas_set_image_fill(Evas e, Evas_Object o, double x, double y, double w, double h);
void evas_set_bits_file(Evas e, Evas_Object o, char *file);
void evas_set_color(Evas e, Evas_Object o, int r, int g, int b, int a);
@ -265,8 +266,8 @@ void evas_gradient_add_color(Evas_Gradient grad, int r, int g, int b, int a, int
/* stacking within a layer */
void evas_raise(Evas e, Evas_Object o);
void evas_lower(Evas e, Evas_Object o);
void evas_stack_above(Evas e, Evas_Object o, int above);
void evas_stack_below(Evas e, Evas_Object o, int above);
void evas_stack_above(Evas e, Evas_Object o, Evas_Object above);
void evas_stack_below(Evas e, Evas_Object o, Evas_Object above);
/* object geoemtry */
void evas_move(Evas e, Evas_Object o, double x, double y);

View File

@ -8,7 +8,7 @@ MAINTAINERCLEANFILES = Makefile.in
LIBS_X = @x_ldflags@ @x_libs@
LIBS_IMLIB2 = -lImlib2 -lttf -ldl -lm
LIBS_DB = -ledb
LIBS_GL = -lGL -lGLU
LIBS_GL = -lGLU -lGL
LIBS_EXTRA = -L/usr/local/lib
CFLAGS_X = @x_cflags@

View File

@ -7,11 +7,30 @@
static void
_evas_free_image(Evas_Object o)
{
Evas_Object_Image oo;
oo = o;
if (o->callbacks) evas_list_free(o->callbacks);
if (oo->current.file) free(oo->current.file);
free(o);
}
static void
_evas_free_image_renderer_data(Evas e, Evas_Object o)
{
switch (e->current.render_method)
{
case RENDER_METHOD_ALPHA_SOFTWARE:
break;
case RENDER_METHOD_BASIC_HARDWARE:
break;
case RENDER_METHOD_3D_HARDWARE:
break;
case RENDER_METHOD_ALPHA_HARDWARE:
break;
default:
break;
}
}
/* adding objects */
@ -68,22 +87,49 @@ evas_add_image_from_file(Evas e, char *file)
Evas_Object
evas_add_image_from_data(Evas e, void *data, Evas_Image_Format format, int w, int h)
{
/* FIXME: not implimented */
return NULL;
}
/* set object settings */
void
evas_set_image_file(Evas e, Evas_Object o, char *file)
{
Evas_Object_Image oo;
oo = o;
if (oo->current.file)
free(oo->current.file);
oo->previous.file = NULL;
oo->current.file = strdup(file);
{
Imlib_Image im;
im = imlib_load_image(file);
if (im)
{
imlib_context_set_image(im);
oo->current.image.w = imlib_image_get_width();
oo->current.image.h = imlib_image_get_height();
o->current.w = (double)oo->current.image.w;
o->current.h = (double)oo->current.image.h;
imlib_free_image();
}
else
{
oo->current.image.w = 0;
oo->current.image.h = 0;
o->current.w = (double)oo->current.image.w;
o->current.h = (double)oo->current.image.h;
}
}
o->changed = 1;
}
void
evas_set_image_data(Evas e, Evas_Object o, void *data, Evas_Image_Format format, int w, int h)
{
}
void
evas_set_image_scale_smoothness(Evas e, Evas_Object o, int smooth)
{
/* FIXME: not implimented */
}
void
@ -95,4 +141,9 @@ evas_set_image_fill(Evas e, Evas_Object o, double x, double y, double w, double
void
evas_get_image_size(Evas e, Evas_Object o, int *w, int *h)
{
Evas_Object_Image oo;
oo = o;
if (w) *w = oo->current.image.w;
if (h) *h = oo->current.image.h;
}

View File

@ -1,10 +1,5 @@
#include "evas_imlib_routines.h"
#define SPANS_COMMON(x1, w1, x2, w2) \
(!((((x2) + (w2)) <= (x1)) || ((x2) >= ((x1) + (w1)))))
#define RECTS_INTERSECT(x, y, w, h, xx, yy, ww, hh) \
((SPANS_COMMON((x), (w), (xx), (ww))) && (SPANS_COMMON((y), (h), (yy), (hh))))
static void __evas_imlib_image_cache_flush(Display *disp);
static int __evas_anti_alias = 1;
static Evas_List drawable_list = NULL;

View File

@ -16,6 +16,11 @@
#include <Imlib2.h>
#define SPANS_COMMON(x1, w1, x2, w2) \
(!((((x2) + (w2)) <= (x1)) || ((x2) >= ((x1) + (w1)))))
#define RECTS_INTERSECT(x, y, w, h, xx, yy, ww, hh) \
((SPANS_COMMON((x), (w), (xx), (ww))) && (SPANS_COMMON((y), (h), (yy), (hh))))
typedef void Evas_Imlib_Image;
typedef void Evas_Imlib_Font;
typedef void Evas_Imlib_Graident;

View File

@ -4,6 +4,21 @@
#include <unistd.h>
#include <string.h>
Evas_Layer
_evas_get_object_layer(Evas e, Evas_Object o)
{
Evas_List l;
for (l = e->layers; l; l = l->next)
{
Evas_Layer layer;
layer = l->data;
if (layer->layer == o->current.layer) return layer;
}
return NULL;
}
void
_evas_real_del_object(Evas e, Evas_Object o)
{
@ -49,25 +64,65 @@ evas_set_layer_store(Evas e, int l, int store)
void
evas_raise(Evas e, Evas_Object o)
{
e->changed = 1;
Evas_Layer layer;
layer = _evas_get_object_layer(e, o);
if (layer)
{
o->current.stacking = 1;
layer->objects = evas_list_remove(layer->objects, o);
layer->objects = evas_list_append(layer->objects, o);
o->changed = 1;
e->changed = 1;
}
}
void
evas_lower(Evas e, Evas_Object o)
{
e->changed = 1;
Evas_Layer layer;
layer = _evas_get_object_layer(e, o);
if (layer)
{
o->current.stacking = 1;
layer->objects = evas_list_remove(layer->objects, o);
layer->objects = evas_list_prepend(layer->objects, o);
o->changed = 1;
e->changed = 1;
}
}
void
evas_stack_above(Evas e, Evas_Object o, int above)
evas_stack_above(Evas e, Evas_Object o, Evas_Object above)
{
e->changed = 1;
Evas_Layer layer;
layer = _evas_get_object_layer(e, o);
if (layer)
{
o->current.stacking = 1;
layer->objects = evas_list_remove(layer->objects, o);
layer->objects = evas_list_append_relative(layer->objects, o, above);
o->changed = 1;
e->changed = 1;
}
}
void
evas_stack_below(Evas e, Evas_Object o, int above)
evas_stack_below(Evas e, Evas_Object o, Evas_Object above)
{
e->changed = 1;
Evas_Layer layer;
layer = _evas_get_object_layer(e, o);
if (layer)
{
o->current.stacking = 1;
layer->objects = evas_list_remove(layer->objects, o);
layer->objects = evas_list_prepend_relative(layer->objects, o, above);
o->changed = 1;
e->changed = 1;
}
}
/* object geoemtry */

View File

@ -75,9 +75,47 @@ evas_render(Evas e)
{
Evas_List delete_objects;
Evas_List l, ll;
void (*func_draw_add_rect) (Display *disp, Window win, int x, int y, int w, int h);
void * (*func_image_new_from_file) (Display *disp, char *file);
void (*func_image_draw) (void *im, Display *disp, Window w, int win_w, int win_h, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h);
void (*func_image_free) (void *im);
void (*func_flush_draw) (Display *disp, Window w);
void (*func_init) (Display *disp, Window w);
int (*func_image_get_width) (void *im);
int (*func_image_get_height) (void *im);
if ((!e->changed) || (!e->current.display) || (!e->current.drawable))
return;
switch (e->current.render_method)
{
case RENDER_METHOD_ALPHA_SOFTWARE:
func_draw_add_rect = __evas_imlib_draw_add_rect;
func_image_new_from_file = __evas_imlib_image_new_from_file;
func_image_draw = __evas_imlib_image_draw;
func_image_free = __evas_imlib_image_free;
func_flush_draw = __evas_imlib_flush_draw;
func_init = __evas_imlib_init;
func_image_get_width = __evas_imlib_image_get_width;
func_image_get_height = __evas_imlib_image_get_height;
break;
case RENDER_METHOD_BASIC_HARDWARE:
break;
case RENDER_METHOD_3D_HARDWARE:
func_draw_add_rect = __evas_gl_draw_add_rect;
func_image_new_from_file = __evas_gl_image_new_from_file;
func_image_draw = __evas_gl_image_draw;
func_image_free = __evas_gl_image_free;
func_flush_draw = __evas_gl_flush_draw;
func_init = __evas_gl_init;
func_image_get_width = __evas_gl_image_get_width;
func_image_get_height = __evas_gl_image_get_height;
break;
case RENDER_METHOD_ALPHA_HARDWARE:
break;
default:
break;
}
e->changed = 0;
if ((e->current.viewport.x != e->previous.viewport.x) ||
(e->current.viewport.y != e->previous.viewport.y) ||
@ -216,53 +254,55 @@ evas_render(Evas e)
evas_list_free(delete_objects);
}
/* take all the update rects we've produced and render them */
switch (e->current.render_method)
{
case RENDER_METHOD_ALPHA_SOFTWARE:
Imlib_Updates up;
func_init(e->current.display, e->current.screen);
if (e->updates)
{
Imlib_Updates up;
__evas_imlib_init(e->current.display, e->current.screen);
if (e->updates)
up = imlib_updates_merge_for_rendering(e->updates,
e->current.drawable_width,
e->current.drawable_height);
e->updates = NULL;
if (up)
{
up = imlib_updates_merge_for_rendering(e->updates,
e->current.drawable_width,
e->current.drawable_height);
e->updates = NULL;
if (up)
Imlib_Updates u;
u = up;
while (u)
{
Imlib_Updates u;
int x, y, w, h;
u = up;
while (u)
imlib_updates_get_coordinates(u, &x, &y, &w, &h);
func_draw_add_rect(e->current.display,
e->current.drawable,
x, y, w, h);
u = imlib_updates_get_next(u);
}
imlib_updates_free(up);
/* draw all objects now */
for (l = e->layers; l; l = l->next)
{
Evas_Layer layer;
layer = l->data;
for (ll = layer->objects; ll; ll = ll->next)
{
int x, y, w, h;
Evas_Object_Any o;
imlib_updates_get_coordinates(u, &x, &y, &w, &h);
__evas_imlib_draw_add_rect(e->current.display,
e->current.drawable,
x, y, w, h);
u = imlib_updates_get_next(u);
}
imlib_updates_free(up);
/* draw all objects now */
for (l = e->layers; l; l = l->next)
{
Evas_Layer layer;
layer = l->data;
for (ll = layer->objects; ll; ll = ll->next)
o = ll->data;
if (o->current.visible)
{
Evas_Object_Any o;
int x, y, w, h;
o = ll->data;
if (o->current.visible)
_evas_object_get_current_translated_coords(e, o,
&x, &y,
&w, &h);
if (RECTS_INTERSECT(0, 0,
e->current.drawable_width,
e->current.drawable_height,
x, y, w, h))
{
int x, y, w, h;
_evas_object_get_current_translated_coords(e, o,
&x, &y,
&w, &h);
switch (o->type)
{
case OBJECT_IMAGE:
@ -271,21 +311,21 @@ evas_render(Evas e)
oo = o;
{
Evas_Imlib_Image *im;
void *im;
im = __evas_imlib_image_new_from_file(e->current.display, oo->current.file);
im = func_image_new_from_file(e->current.display, oo->current.file);
if (im)
{
__evas_imlib_image_draw(im,
e->current.display,
e->current.drawable,
e->current.drawable_width,
e->current.drawable_height,
0, 0,
__evas_gl_image_get_width(im),
__evas_gl_image_get_height(im),
x, y, w, h);
__evas_imlib_image_free(im);
func_image_draw(im,
e->current.display,
e->current.drawable,
e->current.drawable_width,
e->current.drawable_height,
0, 0,
func_image_get_width(im),
func_image_get_height(im),
x, y, w, h);
func_image_free(im);
}
}
}
@ -329,134 +369,10 @@ evas_render(Evas e)
}
}
}
__evas_imlib_flush_draw(e->current.display,
e->current.drawable);
}
func_flush_draw(e->current.display, e->current.drawable);
}
}
break;
case RENDER_METHOD_BASIC_HARDWARE:
break;
case RENDER_METHOD_3D_HARDWARE:
{
Imlib_Updates up;
__evas_gl_init(e->current.display, e->current.screen);
if (e->updates)
{
up = imlib_updates_merge_for_rendering(e->updates,
e->current.drawable_width,
e->current.drawable_height);
e->updates = NULL;
if (up)
{
Imlib_Updates u;
u = up;
while (u)
{
int x, y, w, h;
imlib_updates_get_coordinates(u, &x, &y, &w, &h);
__evas_gl_draw_add_rect(e->current.display,
e->current.drawable,
x, y, w, h);
u = imlib_updates_get_next(u);
}
imlib_updates_free(up);
/* draw all objects now */
for (l = e->layers; l; l = l->next)
{
Evas_Layer layer;
layer = l->data;
for (ll = layer->objects; ll; ll = ll->next)
{
Evas_Object_Any o;
o = ll->data;
if (o->current.visible)
{
int x, y, w, h;
_evas_object_get_current_translated_coords(e, o,
&x, &y,
&w, &h);
switch (o->type)
{
case OBJECT_IMAGE:
{
Evas_Object_Image oo;
oo = o;
{
Evas_GL_Image *im;
im = __evas_gl_image_new_from_file(e->current.display, oo->current.file);
if (im)
{
__evas_gl_image_draw(im,
e->current.display,
e->current.drawable,
e->current.drawable_width,
e->current.drawable_height,
0, 0,
__evas_gl_image_get_width(im),
__evas_gl_image_get_height(im),
x, y, w, h);
__evas_gl_image_free(im);
}
}
}
break;
case OBJECT_TEXT:
{
Evas_Object_Text oo;
oo = o;
}
break;
case OBJECT_RECTANGLE:
{
Evas_Object_Rectangle oo;
oo = o;
}
break;
case OBJECT_LINE:
{
Evas_Object_Line oo;
oo = o;
}
break;
case OBJECT_GRADIENT_BOX:
{
Evas_Object_Gradient_Box oo;
oo = o;
}
break;
case OBJECT_BITS:
{
Evas_Object_Bits oo;
oo = o;
}
break;
}
}
}
}
__evas_gl_flush_draw(e->current.display,
e->current.drawable);
}
}
}
break;
case RENDER_METHOD_ALPHA_HARDWARE:
break;
default:
break;
}
e->previous = e->current;
}
@ -539,3 +455,24 @@ evas_set_output_method(Evas e, Evas_Render_Method method)
e->current.render_method = method;
e->changed = 1;
}
void
evas_set_scale_smoothness(Evas e, int smooth)
{
switch (e->current.render_method)
{
case RENDER_METHOD_ALPHA_SOFTWARE:
__evas_imlib_image_set_smooth_scaling(smooth);
break;
case RENDER_METHOD_BASIC_HARDWARE:
break;
case RENDER_METHOD_3D_HARDWARE:
__evas_gl_image_set_smooth_scaling(smooth);
break;
case RENDER_METHOD_ALPHA_HARDWARE:
break;
default:
return 0;
break;
}
}

View File

@ -1,7 +1,7 @@
LIBS_X = @x_ldflags@ @x_libs@
LIBS_IMLIB2 = -lImlib2 -lttf -ldl -lm
LIBS_DB = -ledb
LIBS_GL = -lGL
LIBS_GL = -lGLU -lGL
LIBS_EXTRA = -L/usr/local/lib
CFLAGS_X = @x_cflags@

View File

@ -10,9 +10,21 @@ main(int argc, char **argv)
Colormap cmap;
Window win;
int win_w, win_h;
int i, a;
int i, a, w, h;
Evas e;
Evas_Object o[32];
Evas_Object o[128];
int down;
char *imgs[8] =
{
"img/mush.png",
"img/book.png",
"img/bulb.png",
"img/term.png",
"img/calc.png",
"img/worlds.png",
"img/spider.png",
"img/mouse.png"
};
win_w = 640; win_h = 480;
if (argc == 4)
@ -46,6 +58,8 @@ main(int argc, char **argv)
vis,
CWColormap | CWBorderPixel | CWEventMask,
&att);
XSelectInput(d, win, ButtonPressMask | ButtonReleaseMask |
PointerMotionMask | ExposureMask);
XMapWindow(d, win);
XSync(d, False);
}
@ -55,20 +69,78 @@ main(int argc, char **argv)
o[0] = evas_add_image_from_file(e, "img/sky001.png");
evas_show(e, o[0]);
for (i = 1 ; i < 32; i++)
o[1] = evas_add_image_from_file(e, "img/logo001.png");
evas_get_image_size(e, o[1], &w, &h);
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);
a = 0;
down = 0;
for (;;)
{
double x, y;
XEvent ev;
while (XPending(d))
/* do*/
{
XNextEvent(d, &ev);
switch(ev.type)
{
case ButtonPress:
{
int button, mouse_x, mouse_y;
down = 1;
button = ev.xbutton.button;
mouse_x = ev.xbutton.x;
mouse_y = ev.xbutton.y;
evas_move(e, o[1], mouse_x - w, mouse_y - h);
}
break;
case ButtonRelease:
{
int button, mouse_x, mouse_y;
down = 0;
button = ev.xbutton.button;
mouse_x = ev.xbutton.x;
mouse_y = ev.xbutton.y;
evas_move(e, o[1], mouse_x - w, mouse_y - h);
}
break;
case MotionNotify:
{
int mouse_x, mouse_y;
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:
{
evas_update_rect(e, ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height);
}
break;
default:
break;
}
}
/* while (XPending(d));*/
for (i = 1; i < 32; i++)
for (i = 2; i < 128; i++)
{
int j, k;
@ -76,12 +148,13 @@ main(int argc, char **argv)
k = (i * -60) - (i * 2);
x = (win_w + (cos((double)(a + j) * 2 * 3.141592654 / 1000) * (win_h - 100))) / 2;
y = (win_h + (sin((double)(a + k) * 2 * 3.141592654 / 1000) * (win_h - 100))) / 2;
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;
if (a >= 1000) a = 0;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 63 KiB