event system works - callbakcs happen.. WOOHOO :)

SVN revision: 3193
This commit is contained in:
Carsten Haitzler 2000-08-20 21:49:41 +00:00
parent 5173a08776
commit e37fccc450
7 changed files with 226 additions and 43 deletions

View File

@ -34,7 +34,8 @@ typedef struct _Evas_Object_Gradient_Box * Evas_Object_Gradient_Box;
#define CALLBACK_MOUSE_OUT 1 #define CALLBACK_MOUSE_OUT 1
#define CALLBACK_MOUSE_DOWN 2 #define CALLBACK_MOUSE_DOWN 2
#define CALLBACK_MOUSE_UP 3 #define CALLBACK_MOUSE_UP 3
#define CALLBACK_FREE 4 #define CALLBACK_MOUSE_MOVE 4
#define CALLBACK_FREE 5
#define IMAGE_FORMAT_BGRA 0 #define IMAGE_FORMAT_BGRA 0
#define IMAGE_FORMAT_ARGB 1 #define IMAGE_FORMAT_ARGB 1
@ -331,7 +332,8 @@ Evas_Object evas_get_object_at_pos(Evas e, double x, double y);
/* data attachment ops */ /* data attachment ops */
void evas_put_data(Evas e, Evas_Object o, char *key, void *data); void evas_put_data(Evas e, Evas_Object o, char *key, void *data);
void *evas_get_data(Evas e, Evas_Object o, char *key); void *evas_get_data(Evas e, Evas_Object o, char *key);
void *evas_remove_data(Evas e, Evas_Object o, char *key);
/* events */ /* events */
void evas_event_button_down(Evas e, int x, int y, int b); void evas_event_button_down(Evas e, int x, int y, int b);
void evas_event_button_up(Evas e, int x, int y, int b); void evas_event_button_up(Evas e, int x, int y, int b);

View File

@ -9,7 +9,10 @@ _evas_callback_call(Evas e, Evas_Object o, Evas_Callback_Type callback,
int b, int x, int y) int b, int x, int y)
{ {
Evas_List l; Evas_List l;
static in_cb = 0;
if (in_cb) return;
in_cb = 1;
if (o->callbacks) if (o->callbacks)
{ {
for (l = o->callbacks; l; l = l->next) for (l = o->callbacks; l; l = l->next)
@ -20,8 +23,8 @@ _evas_callback_call(Evas e, Evas_Object o, Evas_Callback_Type callback,
if (cb->type == callback) if (cb->type == callback)
cb->callback(cb->data, e, o, b, x, y); cb->callback(cb->data, e, o, b, x, y);
} }
evas_list_free(o->callbacks);
} }
in_cb = 0;
} }
/* callbacks */ /* callbacks */

View File

@ -34,7 +34,8 @@ _evas_highest_object_at_point(Evas e, int x, int y)
ob = ll->data; ob = ll->data;
if (ob->current.visible) if (ob->current.visible)
{ {
if (_evas_point_in_object(e, ll->data, x, y)) o = ll->data; if (_evas_point_in_object(e, ob, x, y))
o = ob;
} }
} }
} }
@ -73,12 +74,18 @@ evas_event_button_down(Evas e, int x, int y, int b)
{ {
Evas_Object o; Evas_Object o;
if ((b > 1) || (b < 32)) return; if ((b < 1) || (b > 32)) return;
if (!e->mouse.buttons) e->mouse.button_object = o; if (!e->mouse.buttons)
{
o = _evas_highest_object_at_point(e, e->mouse.x, e->mouse.y);
e->mouse.button_object = o;
}
e->mouse.buttons |= (1 << (b - 1)); e->mouse.buttons |= (1 << (b - 1));
e->mouse.x = x; e->mouse.x = x;
e->mouse.y = y; e->mouse.y = y;
_evas_callback_call(e, e->mouse.object, CALLBACK_MOUSE_DOWN, b, x, y); if (e->mouse.button_object)
_evas_callback_call(e, e->mouse.button_object, CALLBACK_MOUSE_DOWN,
b, x, y);
} }
void void
@ -86,28 +93,57 @@ evas_event_button_up(Evas e, int x, int y, int b)
{ {
Evas_Object o; Evas_Object o;
if ((b > 1) || (b < 32)) return; if ((b < 1) || (b > 32)) return;
e->mouse.buttons &= ~(1 << (b - 1)); e->mouse.buttons &= ~(1 << (b - 1));
if (!e->mouse.buttons) e->mouse.button_object = NULL;
e->mouse.x = x; e->mouse.x = x;
e->mouse.y = y; e->mouse.y = y;
_evas_callback_call(e, e->mouse.object, CALLBACK_MOUSE_UP, b, x, y); if (e->mouse.button_object)
_evas_callback_call(e, e->mouse.button_object, CALLBACK_MOUSE_UP,
b, x, y);
if (!e->mouse.buttons) e->mouse.button_object = NULL;
} }
void void
evas_event_move(Evas e, int x, int y) evas_event_move(Evas e, int x, int y)
{ {
Evas_Object o; Evas_Object o;
if (!e->mouse.button_object)
{
o = _evas_highest_object_at_point(e, e->mouse.x, e->mouse.y);
if (o != e->mouse.object)
{
if (e->mouse.object)
{
_evas_callback_call(e, e->mouse.object, CALLBACK_MOUSE_MOVE,
e->mouse.buttons, e->mouse.x, e->mouse.y);
_evas_callback_call(e, e->mouse.object, CALLBACK_MOUSE_OUT,
e->mouse.buttons, e->mouse.x, e->mouse.y);
}
e->mouse.x = x;
e->mouse.y = y;
e->mouse.object = o;
if (e->mouse.object)
{
_evas_callback_call(e, e->mouse.object, CALLBACK_MOUSE_IN,
e->mouse.buttons, e->mouse.x, e->mouse.y);
_evas_callback_call(e, e->mouse.object, CALLBACK_MOUSE_MOVE,
e->mouse.buttons, e->mouse.x, e->mouse.y);
}
return;
}
e->mouse.x = x;
e->mouse.y = y;
if (e->mouse.object)
_evas_callback_call(e, e->mouse.object, CALLBACK_MOUSE_MOVE,
e->mouse.buttons, e->mouse.x, e->mouse.y);
return;
}
e->mouse.x = x; e->mouse.x = x;
e->mouse.y = y; e->mouse.y = y;
o = _evas_highest_object_at_point(e, e->mouse.x, e->mouse.y); if (e->mouse.button_object)
if (o != e->mouse.object) _evas_callback_call(e, e->mouse.button_object, CALLBACK_MOUSE_MOVE,
{ e->mouse.buttons, e->mouse.x, e->mouse.y);
_evas_callback_call(e, e->mouse.object, CALLBACK_MOUSE_OUT, e->mouse.buttons, x, y);
e->mouse.object = o;
_evas_callback_call(e, e->mouse.object, CALLBACK_MOUSE_IN, e->mouse.buttons, x, y);
}
} }
void void

View File

@ -312,12 +312,24 @@ void
evas_put_data(Evas e, Evas_Object o, char *key, void *data) evas_put_data(Evas e, Evas_Object o, char *key, void *data)
{ {
Evas_Data d; Evas_Data d;
Evas_List l;
if (!key) return; if (!key) return;
for (l = o->data; l; l = l->next)
{
Evas_Data d;
d = l->data;
if (!strcmp(d->key, key))
{
d->data = data;
return;
}
}
d = malloc(sizeof(struct _Evas_Data)); d = malloc(sizeof(struct _Evas_Data));
d->key = strdup(key); d->key = strdup(key);
d->data = data; d->data = data;
o->data = evas_list_append(o->data, d); o->data = evas_list_prepend(o->data, d);
} }
void * void *
@ -325,6 +337,7 @@ evas_get_data(Evas e, Evas_Object o, char *key)
{ {
Evas_List l; Evas_List l;
if (!key) return NULL;
for (l = o->data; l; l = l->next) for (l = o->data; l; l = l->next)
{ {
Evas_Data d; Evas_Data d;
@ -335,6 +348,31 @@ evas_get_data(Evas e, Evas_Object o, char *key)
return NULL; return NULL;
} }
void *
evas_remove_data(Evas e, Evas_Object o, char *key)
{
Evas_List l;
if (!key) return NULL;
for (l = o->data; l; l = l->next)
{
Evas_Data d;
d = l->data;
if (!strcmp(d->key, key))
{
void *data;
o->data = evas_list_remove(o->data, l->data);
data = d->data;
free(d->key);
free(d);
return data;
}
}
return NULL;
}
int int
evas_world_x_to_screen(Evas e, double x) evas_world_x_to_screen(Evas e, double x)
{ {

View File

@ -113,17 +113,17 @@ evas_set_layer(Evas e, Evas_Object o, int layer_num)
{ {
Evas_Layer layer; Evas_Layer layer;
Evas_List l; Evas_List l;
int removed;
if (layer_num == o->current.layer) return; if (layer_num == o->current.layer) return;
removed = 0;
o->changed = 1;
e->changed = 1;
for (l = e->layers; l; l = l->next) for (l = e->layers; l; l = l->next)
{ {
layer = l->data; layer = l->data;
if (layer->layer == o->current.layer) if (layer->layer == o->current.layer)
{ {
layer->objects = evas_list_remove(layer->objects, o); layer->objects = evas_list_remove(layer->objects, o);
removed = 1;
if (!layer->objects) if (!layer->objects)
{ {
e->layers = evas_list_remove(e->layers, layer); e->layers = evas_list_remove(e->layers, layer);
@ -132,6 +132,9 @@ evas_set_layer(Evas e, Evas_Object o, int layer_num)
break; break;
} }
} }
if (!removed) return;
o->changed = 1;
e->changed = 1;
o->current.layer = layer_num; o->current.layer = layer_num;
for (l = e->layers; l; l = l->next) for (l = e->layers; l; l = l->next)
{ {
@ -139,7 +142,7 @@ evas_set_layer(Evas e, Evas_Object o, int layer_num)
if (layer->layer == o->current.layer) if (layer->layer == o->current.layer)
{ {
layer->objects = evas_list_append(layer->objects, o); layer->objects = evas_list_append(layer->objects, o);
break; return;
} }
if (layer->layer > o->current.layer) if (layer->layer > o->current.layer)
{ {
@ -150,6 +153,9 @@ evas_set_layer(Evas e, Evas_Object o, int layer_num)
e->layers = evas_list_prepend_relative(e->layers, layer_new, layer); e->layers = evas_list_prepend_relative(e->layers, layer_new, layer);
layer_new->objects = evas_list_append(layer_new->objects, o); layer_new->objects = evas_list_append(layer_new->objects, o);
layer_new->layer = o->current.layer; layer_new->layer = o->current.layer;
if ((o->current.visible) &&
(_evas_point_in_object(e, o, e->mouse.x, e->mouse.y)))
evas_event_move(e, e->mouse.x, e->mouse.y);
return; return;
} }
} }
@ -159,6 +165,9 @@ evas_set_layer(Evas e, Evas_Object o, int layer_num)
e->layers = evas_list_append(e->layers, layer); e->layers = evas_list_append(e->layers, layer);
layer->objects = evas_list_append(layer->objects, o); layer->objects = evas_list_append(layer->objects, o);
layer->layer = o->current.layer; layer->layer = o->current.layer;
if ((o->current.visible) &&
(_evas_point_in_object(e, o, e->mouse.x, e->mouse.y)))
evas_event_move(e, e->mouse.x, e->mouse.y);
} }
void void
@ -182,6 +191,9 @@ evas_raise(Evas e, Evas_Object o)
layer->objects = evas_list_append(layer->objects, o); layer->objects = evas_list_append(layer->objects, o);
o->changed = 1; o->changed = 1;
e->changed = 1; e->changed = 1;
if ((o->current.visible) &&
(_evas_point_in_object(e, o, e->mouse.x, e->mouse.y)))
evas_event_move(e, e->mouse.x, e->mouse.y);
} }
} }
@ -198,6 +210,9 @@ evas_lower(Evas e, Evas_Object o)
layer->objects = evas_list_prepend(layer->objects, o); layer->objects = evas_list_prepend(layer->objects, o);
o->changed = 1; o->changed = 1;
e->changed = 1; e->changed = 1;
if ((o->current.visible) &&
(_evas_point_in_object(e, o, e->mouse.x, e->mouse.y)))
evas_event_move(e, e->mouse.x, e->mouse.y);
} }
} }
@ -214,6 +229,9 @@ evas_stack_above(Evas e, Evas_Object o, Evas_Object above)
layer->objects = evas_list_append_relative(layer->objects, o, above); layer->objects = evas_list_append_relative(layer->objects, o, above);
o->changed = 1; o->changed = 1;
e->changed = 1; e->changed = 1;
if ((o->current.visible) &&
(_evas_point_in_object(e, o, e->mouse.x, e->mouse.y)))
evas_event_move(e, e->mouse.x, e->mouse.y);
} }
} }
@ -230,6 +248,9 @@ evas_stack_below(Evas e, Evas_Object o, Evas_Object above)
layer->objects = evas_list_prepend_relative(layer->objects, o, above); layer->objects = evas_list_prepend_relative(layer->objects, o, above);
o->changed = 1; o->changed = 1;
e->changed = 1; e->changed = 1;
if ((o->current.visible) &&
(_evas_point_in_object(e, o, e->mouse.x, e->mouse.y)))
evas_event_move(e, e->mouse.x, e->mouse.y);
} }
} }
@ -237,21 +258,33 @@ evas_stack_below(Evas e, Evas_Object o, Evas_Object above)
void void
evas_move(Evas e, Evas_Object o, double x, double y) evas_move(Evas e, Evas_Object o, double x, double y)
{ {
int event_update = 0;
if ((o->type == OBJECT_LINE)) return; if ((o->type == OBJECT_LINE)) return;
if (_evas_point_in_object(e, o, e->mouse.x, e->mouse.y))
event_update = 1;
o->current.x = x; o->current.x = x;
o->current.y = y; o->current.y = y;
o->changed = 1; o->changed = 1;
e->changed = 1; e->changed = 1;
if ((_evas_point_in_object(e, o, e->mouse.x, e->mouse.y)) || event_update)
evas_event_move(e, e->mouse.x, e->mouse.y);
} }
void void
evas_resize(Evas e, Evas_Object o, double w, double h) evas_resize(Evas e, Evas_Object o, double w, double h)
{ {
int event_update = 0;
if ((o->type == OBJECT_TEXT) || (o->type == OBJECT_LINE)) return; if ((o->type == OBJECT_TEXT) || (o->type == OBJECT_LINE)) return;
if (_evas_point_in_object(e, o, e->mouse.x, e->mouse.y))
event_update = 1;
o->current.w = w; o->current.w = w;
o->current.h = h; o->current.h = h;
o->changed = 1; o->changed = 1;
e->changed = 1; e->changed = 1;
if ((_evas_point_in_object(e, o, e->mouse.x, e->mouse.y)) || event_update)
evas_event_move(e, e->mouse.x, e->mouse.y);
} }
void void
@ -271,6 +304,8 @@ evas_show(Evas e, Evas_Object o)
o->current.visible = 1; o->current.visible = 1;
o->changed = 1; o->changed = 1;
e->changed = 1; e->changed = 1;
if (_evas_point_in_object(e, o, e->mouse.x, e->mouse.y))
evas_event_move(e, e->mouse.x, e->mouse.y);
} }
void void
@ -279,4 +314,6 @@ evas_hide(Evas e, Evas_Object o)
o->current.visible = 0; o->current.visible = 0;
o->changed = 1; o->changed = 1;
e->changed = 1; e->changed = 1;
if (_evas_point_in_object(e, o, e->mouse.x, e->mouse.y))
evas_event_move(e, e->mouse.x, e->mouse.y);
} }

View File

@ -6,7 +6,7 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
static void void
_evas_object_get_current_translated_coords(Evas e, Evas_Object o, _evas_object_get_current_translated_coords(Evas e, Evas_Object o,
int *x, int *y, int *w, int *h) int *x, int *y, int *w, int *h)
{ {
@ -26,7 +26,7 @@ _evas_object_get_current_translated_coords(Evas e, Evas_Object o,
e->current.viewport.h); e->current.viewport.h);
} }
static void void
_evas_object_get_previous_translated_coords(Evas e, Evas_Object o, _evas_object_get_previous_translated_coords(Evas e, Evas_Object o,
int *x, int *y, int *w, int *h) int *x, int *y, int *w, int *h)
{ {
@ -522,18 +522,19 @@ evas_render(Evas e)
Evas_Object_Rectangle oo; Evas_Object_Rectangle oo;
oo = o; oo = o;
func_rectangle_draw(e->current.display, if (oo->current.a != 0)
e->current.drawable, func_rectangle_draw(e->current.display,
e->current.drawable_width, e->current.drawable,
e->current.drawable_height, e->current.drawable_width,
o->current.x, e->current.drawable_height,
o->current.y, o->current.x,
o->current.w, o->current.y,
o->current.h, o->current.w,
oo->current.r, o->current.h,
oo->current.g, oo->current.r,
oo->current.b, oo->current.g,
oo->current.a); oo->current.b,
oo->current.a);
} }
break; break;
case OBJECT_LINE: case OBJECT_LINE:

View File

@ -16,6 +16,55 @@ get_time(void)
return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000); return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
} }
/* callbacks for logo object */
void
mouse_down (void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y)
{
evas_put_data(_e, _o, "clicked", (void *)1);
evas_put_data(_e, _o, "x", (void *)_x);
evas_put_data(_e, _o, "y", (void *)_y);
evas_set_layer(_e, _o, 200);
}
void
mouse_up (void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y)
{
evas_remove_data(_e, _o, "clicked");
evas_set_layer(_e, _o, 50);
}
void
mouse_move (void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y)
{
if (evas_get_data(_e, _o, "clicked"))
{
double ox, oy;
int x, y;
evas_get_geometry(_e, _o, &ox, &oy, NULL, NULL);
x = evas_get_data(_e, _o, "x");
y = evas_get_data(_e, _o, "y");
evas_put_data(_e, _o, "x", (void *)_x);
evas_put_data(_e, _o, "y", (void *)_y);
evas_move(_e, _o, ox + _x - x, oy + _y - y);
}
}
void
mouse_in (void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y)
{
}
void
mouse_out (void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y)
{
}
/* done with callbacks */
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@ -88,6 +137,11 @@ main(int argc, char **argv)
evas_show(e, o[0]); evas_show(e, o[0]);
o[1] = evas_add_image_from_file(e, "img/logo001.png"); o[1] = evas_add_image_from_file(e, "img/logo001.png");
evas_get_image_size(e, o[1], &w, &h); evas_get_image_size(e, o[1], &w, &h);
evas_callback_add(e, o[1], CALLBACK_MOUSE_DOWN, mouse_down, NULL);
evas_callback_add(e, o[1], CALLBACK_MOUSE_UP, mouse_up, NULL);
evas_callback_add(e, o[1], CALLBACK_MOUSE_MOVE, mouse_move, NULL);
evas_callback_add(e, o[1], CALLBACK_MOUSE_IN, mouse_in, NULL);
evas_callback_add(e, o[1], CALLBACK_MOUSE_OUT, mouse_out, NULL);
w /= 2; w /= 2;
h /= 2; h /= 2;
evas_show(e, o[1]); evas_show(e, o[1]);
@ -111,12 +165,22 @@ main(int argc, char **argv)
evas_resize(e, o_rect, 200, 100); evas_resize(e, o_rect, 200, 100);
evas_set_color(e, o_rect, rand()&0xff, rand()&0xff, rand()&0xff, 120); evas_set_color(e, o_rect, rand()&0xff, rand()&0xff, rand()&0xff, 120);
evas_set_layer(e, o_rect, 150); evas_set_layer(e, o_rect, 150);
evas_callback_add(e, o_rect, CALLBACK_MOUSE_DOWN, mouse_down, NULL);
evas_callback_add(e, o_rect, CALLBACK_MOUSE_UP, mouse_up, NULL);
evas_callback_add(e, o_rect, CALLBACK_MOUSE_MOVE, mouse_move, NULL);
evas_callback_add(e, o_rect, CALLBACK_MOUSE_IN, mouse_in, NULL);
evas_callback_add(e, o_rect, CALLBACK_MOUSE_OUT, mouse_out, NULL);
o_line = evas_add_line(e); o_line = evas_add_line(e);
evas_show(e, o_line); evas_show(e, o_line);
evas_set_line_xy(e, o_line, 10, 20, 100, 50); evas_set_line_xy(e, o_line, 10, 20, 100, 50);
evas_set_color(e, o_line, rand()&0xff, rand()&0xff, rand()&0xff, 120); evas_set_color(e, o_line, rand()&0xff, rand()&0xff, rand()&0xff, 120);
evas_set_layer(e, o_rect, 150); evas_set_layer(e, o_rect, 150);
evas_callback_add(e, o_line, CALLBACK_MOUSE_DOWN, mouse_down, NULL);
evas_callback_add(e, o_line, CALLBACK_MOUSE_UP, mouse_up, NULL);
evas_callback_add(e, o_line, CALLBACK_MOUSE_MOVE, mouse_move, NULL);
evas_callback_add(e, o_line, CALLBACK_MOUSE_IN, mouse_in, NULL);
evas_callback_add(e, o_line, CALLBACK_MOUSE_OUT, mouse_out, NULL);
o_grad = evas_add_gradient_box(e); o_grad = evas_add_gradient_box(e);
evas_show(e, o_grad); evas_show(e, o_grad);
@ -129,6 +193,11 @@ main(int argc, char **argv)
evas_gradient_add_color(grad, 255, 0 , 0, 150, 8); evas_gradient_add_color(grad, 255, 0 , 0, 150, 8);
evas_gradient_add_color(grad, 0 , 0 , 0, 0, 8); evas_gradient_add_color(grad, 0 , 0 , 0, 0, 8);
evas_set_gradient(e, o_grad, grad); evas_set_gradient(e, o_grad, grad);
evas_callback_add(e, o_grad, CALLBACK_MOUSE_DOWN, mouse_down, NULL);
evas_callback_add(e, o_grad, CALLBACK_MOUSE_UP, mouse_up, NULL);
evas_callback_add(e, o_grad, CALLBACK_MOUSE_MOVE, mouse_move, NULL);
evas_callback_add(e, o_grad, CALLBACK_MOUSE_IN, mouse_in, NULL);
evas_callback_add(e, o_grad, CALLBACK_MOUSE_OUT, mouse_out, NULL);
o_fps = evas_add_text(e, "morpheus", 16, "FPS..."); o_fps = evas_add_text(e, "morpheus", 16, "FPS...");
evas_set_color(e, o_fps, 255, 255, 255, 120); evas_set_color(e, o_fps, 255, 255, 255, 120);
@ -162,8 +231,7 @@ main(int argc, char **argv)
button = ev.xbutton.button; button = ev.xbutton.button;
mouse_x = ev.xbutton.x; mouse_x = ev.xbutton.x;
mouse_y = ev.xbutton.y; mouse_y = ev.xbutton.y;
evas_move(e, o[1], mouse_x - w, mouse_y - h); evas_event_button_down(e, mouse_x, mouse_y, button);
evas_set_layer(e, o[1], 200);
} }
break; break;
case ButtonRelease: case ButtonRelease:
@ -174,8 +242,7 @@ main(int argc, char **argv)
button = ev.xbutton.button; button = ev.xbutton.button;
mouse_x = ev.xbutton.x; mouse_x = ev.xbutton.x;
mouse_y = ev.xbutton.y; mouse_y = ev.xbutton.y;
evas_move(e, o[1], mouse_x - w, mouse_y - h); evas_event_button_up(e, mouse_x, mouse_y, button);
evas_set_layer(e, o[1], 1);
} }
break; break;
case MotionNotify: case MotionNotify:
@ -184,8 +251,7 @@ main(int argc, char **argv)
mouse_x = ev.xmotion.x; mouse_x = ev.xmotion.x;
mouse_y = ev.xmotion.y; mouse_y = ev.xmotion.y;
if (down) evas_event_move(e, mouse_x, mouse_y);
evas_move(e, o[1], mouse_x - w, mouse_y - h);
} }
break; break;
case Expose: case Expose: