From 842031ebaaa85afee20b5f9600735231ed228b7e Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Mon, 14 Aug 2000 05:41:56 +0000 Subject: [PATCH] lines and rectangles work. woop! :) SVN revision: 3113 --- legacy/evas/src/Evas.h | 10 ++-- legacy/evas/src/evas_line.c | 98 +++++++++++++++++++++++++++++++- legacy/evas/src/evas_rectangle.c | 64 ++++++++++++++++++++- legacy/evas/src/evas_render.c | 48 +++++++++++++++- legacy/evas/test/evas_test.c | 43 ++++++++++---- 5 files changed, 240 insertions(+), 23 deletions(-) diff --git a/legacy/evas/src/Evas.h b/legacy/evas/src/Evas.h index ad1ea0e2a4..106720b0a3 100644 --- a/legacy/evas/src/Evas.h +++ b/legacy/evas/src/Evas.h @@ -215,8 +215,8 @@ void evas_update_rect(Evas e, int x, int y, int w, int h); void evas_render(Evas e); /* query for settings to use */ -Visual *evas_get_optimal_visual(Evas e, Display *disp); -Colormap evas_get_optimal_colormap(Evas e, Display *disp); +Visual *evas_get_optimal_visual(Evas e, Display *disp); +Colormap evas_get_optimal_colormap(Evas e, Display *disp); /* the output settings */ void evas_set_output(Evas e, Display *disp, Drawable d, Visual *v, Colormap c); @@ -232,8 +232,8 @@ void evas_del_object(Evas e, Evas_Object o); Evas_Object 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); Evas_Object evas_add_text(Evas e, char *font, int size, char *text); -Evas_Object evas_add_rectangle(Evas e, int r, int g, int b, int a); -Evas_Object evas_add_line(Evas e, int r, int g, int b, int a); +Evas_Object evas_add_rectangle(Evas e); +Evas_Object evas_add_line(Evas e); Evas_Object evas_add_gradient_box(Evas e); /* set object settings */ @@ -251,7 +251,7 @@ void evas_set_font_cache(Evas e, int size); int evas_get_font_cache(Evas e); void evas_flush_font_cache(Evas e); void evas_set_image_cache(Evas e, int size); -int evas_get_image_cache(Evas e); +int evas_get_image_cache(Evas e); void evas_flush_image_cache(Evas e); void evas_font_add_path(Evas e, char *path); void evas_font_del_path(Evas e, char *path); diff --git a/legacy/evas/src/evas_line.c b/legacy/evas/src/evas_line.c index 54f7aa89b2..647c1958c7 100644 --- a/legacy/evas/src/evas_line.c +++ b/legacy/evas/src/evas_line.c @@ -4,12 +4,106 @@ #include #include -Evas_Object -evas_add_line(Evas e, int r, int g, int b, int a) +static void +_evas_free_line(Evas_Object o) { + Evas_Object_Rectangle oo; + + oo = o; + if (o->callbacks) evas_list_free(o->callbacks); + free(o); +} + +static void +_evas_free_line_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; + } +} + +Evas_Object +evas_add_line(Evas e) +{ + Evas_Object_Line oo; + Evas_Object_Any o; + Evas_List l; + Evas_Layer layer; + + o = oo = malloc(sizeof(struct _Evas_Object_Line)); + memset(o, 0, sizeof(struct _Evas_Object_Line)); + o->type = OBJECT_LINE; + o->object_free = _evas_free_line; + o->object_renderer_data_free = _evas_free_line_renderer_data; + + oo->current.x1 = 0; + oo->current.y1 = 0; + oo->current.x2 = 0; + oo->current.y2 = 0; + + o->current.x = 0; + o->current.y = 0; + o->current.w = 1; + o->current.h = 1; + + for (l = e->layers; l; l = l->next) + { + layer = l->data; + if (layer->layer == o->current.layer) + { + layer->objects = evas_list_append(layer->objects, o); + return o; + } + } + + layer = malloc(sizeof(struct _Evas_Layer)); + memset(layer, 0, sizeof(struct _Evas_Layer)); + e->layers = evas_list_append(e->layers, layer); + layer->objects = evas_list_append(layer->objects, o); + + return o; } void evas_set_line_xy(Evas e, Evas_Object o, double x1, double y1, double x2, double y2) { + Evas_Object_Line oo; + + oo = (Evas_Object_Line)o; + oo->current.x1 = x1; + oo->current.y1 = y1; + oo->current.x2 = x2; + oo->current.y2 = y2; + if (x1 < x2) + { + o->current.x = x1; + o->current.w = (x2 - x1) + 1; + } + else + { + o->current.x = x2; + o->current.w = (x1 - x2) + 1; + } + if (y1 < y2) + { + o->current.y = y1; + o->current.h = (y2 - y1) + 1; + } + else + { + o->current.y = y2; + o->current.h = (y1 - y2) + 1; + } + o->changed = 1; + e->changed = 1; } diff --git a/legacy/evas/src/evas_rectangle.c b/legacy/evas/src/evas_rectangle.c index 8d23c4e19a..8b0ba87e74 100644 --- a/legacy/evas/src/evas_rectangle.c +++ b/legacy/evas/src/evas_rectangle.c @@ -4,7 +4,67 @@ #include #include -Evas_Object -evas_add_rectangle(Evas e, int r, int g, int b, int a) +static void +_evas_free_rectangle(Evas_Object o) { + Evas_Object_Rectangle oo; + + oo = o; + if (o->callbacks) evas_list_free(o->callbacks); + free(o); +} + +static void +_evas_free_rectangle_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; + } +} + +Evas_Object +evas_add_rectangle(Evas e) +{ + Evas_Object_Rectangle oo; + Evas_Object_Any o; + Evas_List l; + Evas_Layer layer; + + o = oo = malloc(sizeof(struct _Evas_Object_Rectangle)); + memset(o, 0, sizeof(struct _Evas_Object_Rectangle)); + o->type = OBJECT_RECTANGLE; + o->object_free = _evas_free_rectangle; + o->object_renderer_data_free = _evas_free_rectangle_renderer_data; + + o->current.x = 0; + o->current.y = 0; + o->current.w = 1; + o->current.h = 1; + + for (l = e->layers; l; l = l->next) + { + layer = l->data; + if (layer->layer == o->current.layer) + { + layer->objects = evas_list_append(layer->objects, o); + return o; + } + } + + layer = malloc(sizeof(struct _Evas_Layer)); + memset(layer, 0, sizeof(struct _Evas_Layer)); + e->layers = evas_list_append(e->layers, layer); + layer->objects = evas_list_append(layer->objects, o); + + return o; } diff --git a/legacy/evas/src/evas_render.c b/legacy/evas/src/evas_render.c index a7ddb152d3..dc35ee5a38 100644 --- a/legacy/evas/src/evas_render.c +++ b/legacy/evas/src/evas_render.c @@ -88,6 +88,8 @@ evas_render(Evas e) void * (*func_text_font_new) (Display *disp, char *font, int size); void (*func_text_font_free) (Evas_GL_Font *fn); void (*func_text_draw) (Evas_GL_Font *fn, Display *disp, Window win, int win_w, int win_h, int x, int y, char *text, int r, int g, int b, int a); + void (*func_rectangle_draw) (Display *disp, Window win, int win_w, int win_h, int x, int y, int w, int h, int r, int g, int b, int a); + void (*func_line_draw) (Display *disp, Window win, int win_w, int win_h, int x1, int y1, int x2, int y2, int r, int g, int b, int a); if ((!e->changed) || (!e->current.display) || @@ -112,6 +114,8 @@ evas_render(Evas e) func_text_font_new = __evas_imlib_text_font_new; func_text_font_free = __evas_imlib_text_font_free; func_text_draw = __evas_imlib_text_draw; + func_rectangle_draw = __evas_imlib_rectangle_draw; + func_line_draw = __evas_imlib_line_draw; break; case RENDER_METHOD_BASIC_HARDWARE: break; @@ -127,6 +131,8 @@ evas_render(Evas e) func_text_font_new = __evas_gl_text_font_new; func_text_font_free = __evas_gl_text_font_free; func_text_draw = __evas_gl_text_draw; + func_rectangle_draw = __evas_gl_rectangle_draw; + func_line_draw = __evas_gl_line_draw; break; case RENDER_METHOD_ALPHA_HARDWARE: break; @@ -216,7 +222,11 @@ evas_render(Evas e) Evas_Object_Rectangle oo; oo = o; - if (1) + if ((oo->current.r != oo->previous.r) || + (oo->current.g != oo->previous.g) || + (oo->current.b != oo->previous.b) || + (oo->current.a != oo->previous.a) + ) real_change = 1; oo->previous = oo->current; } @@ -226,7 +236,15 @@ evas_render(Evas e) Evas_Object_Line oo; oo = o; - if (1) + if ((oo->current.x1 != oo->previous.x1) || + (oo->current.y1 != oo->previous.y1) || + (oo->current.x2 != oo->previous.x2) || + (oo->current.y2 != oo->previous.y2) || + (oo->current.r != oo->previous.r) || + (oo->current.g != oo->previous.g) || + (oo->current.b != oo->previous.b) || + (oo->current.a != oo->previous.a) + ) real_change = 1; oo->previous = oo->current; } @@ -494,6 +512,19 @@ evas_render(Evas e) Evas_Object_Rectangle oo; oo = o; + func_rectangle_draw( + e->current.display, + e->current.drawable, + e->current.drawable_width, + e->current.drawable_height, + o->current.x, + o->current.y, + o->current.w, + o->current.h, + oo->current.r, + oo->current.g, + oo->current.b, + oo->current.a); } break; case OBJECT_LINE: @@ -501,6 +532,19 @@ evas_render(Evas e) Evas_Object_Line oo; oo = o; + func_line_draw( + e->current.display, + e->current.drawable, + e->current.drawable_width, + e->current.drawable_height, + oo->current.x1, + oo->current.y1, + oo->current.x2, + oo->current.y2, + oo->current.r, + oo->current.g, + oo->current.b, + oo->current.a); } break; case OBJECT_GRADIENT_BOX: diff --git a/legacy/evas/test/evas_test.c b/legacy/evas/test/evas_test.c index cdba6b51ad..2890e2aee1 100644 --- a/legacy/evas/test/evas_test.c +++ b/legacy/evas/test/evas_test.c @@ -1,9 +1,21 @@ #include #include #include +#include #include #include +double get_time(void); + +double +get_time(void) +{ + struct timeval timev; + + gettimeofday(&timev, NULL); + return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000); +} + int main(int argc, char **argv) { @@ -14,8 +26,9 @@ main(int argc, char **argv) int win_w, win_h; int i, a, w, h; Evas e; - Evas_Object o[128]; + Evas_Object o[128], o_rect; int down; + double t1, t2; char *imgs[8] = { "img/mush.png", @@ -91,6 +104,12 @@ main(int argc, char **argv) evas_show(e, o[i]); evas_set_layer(e, o[i], 100); } + o_rect = evas_add_rectangle(e); + evas_show(e, o_rect); + evas_move(e, o_rect, 100, 100); + evas_resize(e, o_rect, 200, 100); + evas_set_color(e, o_rect, rand()&0xff, rand()&0xff, rand()&0xff, 120); + evas_set_layer(e, o_rect, 150); evas_raise(e, o[1]); evas_move(e, o[0], 0, 0); @@ -98,6 +117,7 @@ main(int argc, char **argv) evas_set_image_fill(e, o[0], 0, 0, win_w, win_h); a = 0; down = 0; + t1 = get_time(); for (;;) { double x, y; @@ -167,7 +187,16 @@ main(int argc, char **argv) } evas_render(e); a++; - if (a >= 1000) a = 0; + if ((a % 25) == 0) + { + t2 = get_time() - t1; + t1 = get_time(); + printf("%3.3f fps\n", 25 / t2); + } + if (a >= 1000) + { + a = 0; + } } } @@ -284,16 +313,6 @@ main(int argc, char **argv) #if 0 #include "../src/evas_gl_routines.h" -double get_time(void); - -double -get_time(void) -{ - struct timeval timev; - - gettimeofday(&timev, NULL); - return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000); -} int main(int argc, char **argv)